damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 4adb26e784b21f2d3ba53409d3af1ffd3e0b3f74
parent 707f31fca1173176e835da54e7e5bd679c3f0abc
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  2 Jan 2023 08:33:02 -0800

wallet: refactor a few things

Diffstat:
Mdamus/Components/InvoiceView.swift | 15+++++++++++++--
Mdamus/Models/Wallet.swift | 4++--
Mdamus/Views/SelectWalletView.swift | 18+++---------------
3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/damus/Components/InvoiceView.swift b/damus/Components/InvoiceView.swift @@ -11,9 +11,20 @@ func open_with_wallet(wallet: Wallet.Model, invoice: String) { if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) } else { - if let url = URL(string: wallet.appStoreLink), UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url) + guard let store_link = wallet.appStoreLink else { + // TODO: do something here if we don't have an appstore link + return } + + guard let url = URL(string: store_link) else { + return + } + + guard UIApplication.shared.canOpenURL(url) else { + return + } + + UIApplication.shared.open(url) } } diff --git a/damus/Models/Wallet.swift b/damus/Models/Wallet.swift @@ -16,7 +16,7 @@ enum Wallet: String, CaseIterable, Identifiable { var tag: String var displayName : String var link : String - var appStoreLink : String + var appStoreLink : String? var image: String } @@ -75,7 +75,7 @@ enum Wallet: String, CaseIterable, Identifiable { appStoreLink: "https://apps.apple.com/sv/app/bitcoin-beach-wallet/id1531383905", image: "bbw") case .blixtwallet: return .init(index: 11, tag: "blixtwallet", displayName: NSLocalizedString("Blixt Wallet", comment: "Dropdown option label for Lightning wallet, Blixt Wallet"), link: "blixtwallet:lightning:", - appStoreLink: "null", image: "blixt-wallet") + appStoreLink: nil, image: "blixt-wallet") case .river: return .init(index: 12, tag: "river", displayName: NSLocalizedString("River", comment: "Dropdown option label for Lightning wallet, River"), link: "river://", appStoreLink: "https://apps.apple.com/us/app/river-buy-mine-bitcoin/id1536176542", image: "river") diff --git a/damus/Views/SelectWalletView.swift b/damus/Views/SelectWalletView.swift @@ -38,14 +38,8 @@ struct SelectWalletView: View { Section("Select a lightning wallet"){ List{ Button() { - let walletModel = user_settings.default_wallet.model - if let url = URL(string: "\(walletModel.link)\(invoice)"), UIApplication.shared.canOpenURL(url) { - openURL(url) - } else { - if let url = URL(string: walletModel.appStoreLink), UIApplication.shared.canOpenURL(url) { - openURL(url) - } - } + let wallet_model = user_settings.default_wallet.model + open_with_wallet(wallet: wallet_model, invoice: invoice) } label: { HStack { Text("Default Wallet").font(.body).foregroundColor(.blue) @@ -54,13 +48,7 @@ struct SelectWalletView: View { List($allWalletModels) { $wallet in if wallet.index >= 0 { Button() { - if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) { - openURL(url) - } else { - if let url = URL(string: wallet.appStoreLink), UIApplication.shared.canOpenURL(url) { - openURL(url) - } - } + open_with_wallet(wallet: wallet, invoice: invoice) } label: { HStack { Image(wallet.image).resizable().frame(width: 32.0, height: 32.0,alignment: .center).cornerRadius(5)