Browse Source

wallet: refactor a few things

post-button-style
William Casarin 2 years ago
parent
commit
4adb26e784
  1. 15
      damus/Components/InvoiceView.swift
  2. 4
      damus/Models/Wallet.swift
  3. 18
      damus/Views/SelectWalletView.swift

15
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)
}
}

4
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")

18
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)

Loading…
Cancel
Save