Skip to content

Commit

Permalink
Use statvoo API to fetch favicons. (trustwallet#445)
Browse files Browse the repository at this point in the history
* Use `statvoo` API to fetch favicons.

* Use `guard` instead of coalescing operator for `host`

* Add new `linkURL` to `Bookmark`

* Return .none when host is empty
  • Loading branch information
vkoskiv authored and vikmeup committed Mar 11, 2018
1 parent c0d940b commit 1738dfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Trust/Browser/Coordinators/BrowserCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class BrowserCoordinator: Coordinator {
}

func openBookmark(bookmark: Bookmark) {
guard let url = URL(string: bookmark.url) else { return }
guard let url = bookmark.linkURL else { return }
rootViewController.goTo(url: url)
}

Expand Down
4 changes: 4 additions & 0 deletions Trust/Browser/Types/Bookmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Bookmark: Object {
self.id = incrementID()
}

var linkURL: URL? {
return URL(string: url)
}

override class func primaryKey() -> String? {
return "id"
}
Expand Down
5 changes: 4 additions & 1 deletion Trust/Browser/ViewModel/BookmarkViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct BookmarkViewModel {
return bookmark.title
}
var imageURL: URL? {
return URL(string: "\(bookmark.url)favicon.ico")
guard let host = bookmark.linkURL?.host else {
return .none
}
return URL(string: "https://api.statvoo.com/favicon/?url=\(host)")
}
}

0 comments on commit 1738dfb

Please sign in to comment.