This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func fetchJSON() -> Promise<[Photo]> { | |
return Promise { seal in | |
Alamofire.request(photosURL, method: .get).validate().responseData { (data) in | |
guard let data = data.result.value else { | |
seal.reject(PhotoError.ConvertToData) | |
return | |
} | |
guard let photos = try? JSONDecoder().decode([Photo].self, from: data) else { | |
seal.reject(PhotoError.PhotoDecoding) | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func downloadPhotos(photos: [Photo]) -> Promise<[UIImage]> { | |
return Promise { seal in | |
var count = 0 | |
for photo in photos { | |
guard let photoUrl = URL(string: photo.url) else { | |
seal.reject(PhotoError.downloadPhotoUrl) | |
return | |
} | |
guard let photoData = try? Data(contentsOf: photoUrl) else { | |
seal.reject(PhotoError.downloadPhotoConvertToData) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let backgroundQueue = DispatchQueue.global(qos: .background) | |
firstly { | |
showLoader() | |
}.then(on: backgroundQueue) { | |
self.fetchJSON() | |
}.then(on: backgroundQueue) { (photos) in | |
self.downloadPhotos(photos: Array(photos.prefix(40))) | |
}.done(on: DispatchQueue.main, flags: nil) { _ in | |
self.hideLoader() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@main | |
struct WalletWidget: Widget { | |
private let kind: String = "WalletWidget" | |
public var body: some WidgetConfiguration { | |
StaticConfiguration(kind: kind, provider: Provider()) { entry in | |
WalletWidgetEntryView(entry: entry) | |
} | |
.configurationDisplayName("Wallet Widget") | |
.description("Description for the Wallet app widget.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct WalletWidgetEntryView : View { | |
var entry: Provider.Entry | |
@Environment(\.widgetFamily) var family | |
@ViewBuilder | |
var body: some View { | |
//Text(entry.date, style: .time) | |
switch family { | |
case .systemSmall: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func snapshot(with context: Context, completion: @escaping (WalletWidgetEntry) -> ()) { | |
let entry = WalletWidgetEntry(date: Date()) | |
completion(entry) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) { | |
// Generate a timeline consisting of one entry with reload policy after 1 min. | |
let currentDate = Date() | |
let nextUpdateDate = Calendar.current.date(byAdding: .minute, | |
value: 1, | |
to: currentDate)! | |
let entry = WalletWidgetEntry(date: currentDate) | |
let timeline = Timeline(entries: [entry], policy: .after(nextUpdateDate)) | |
completion(timeline) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Provider: TimelineProvider { | |
public typealias Entry = WalletWidgetEntry | |
public func placeholder(in context: Context) -> Entry { | |
let entry = WalletWidgetEntry(date: Date()) | |
return entry | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ForEach(self.transactions, id: \.self) { transaction in | |
Link(destination: URL(string: transaction.stringId)!) { | |
VStack { | |
HStack { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State var transactionId: String = "Not set yet!" | |
var body: some View { | |
NavigationView { | |
WWidgetPreview(transaction: Helper.getTransaction(from: transactionId)) | |
.onOpenURL(perform: { (transactionId) in | |
self.transactionId = transactionId.absoluteString | |
}) |