wallet: refactor a few things
This commit is contained in:
@@ -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) {
|
if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) {
|
||||||
UIApplication.shared.open(url)
|
UIApplication.shared.open(url)
|
||||||
} else {
|
} else {
|
||||||
if let url = URL(string: wallet.appStoreLink), UIApplication.shared.canOpenURL(url) {
|
guard let store_link = wallet.appStoreLink else {
|
||||||
UIApplication.shared.open(url)
|
// 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ enum Wallet: String, CaseIterable, Identifiable {
|
|||||||
var tag: String
|
var tag: String
|
||||||
var displayName : String
|
var displayName : String
|
||||||
var link : String
|
var link : String
|
||||||
var appStoreLink : String
|
var appStoreLink : String?
|
||||||
var image: 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")
|
appStoreLink: "https://apps.apple.com/sv/app/bitcoin-beach-wallet/id1531383905", image: "bbw")
|
||||||
case .blixtwallet:
|
case .blixtwallet:
|
||||||
return .init(index: 11, tag: "blixtwallet", displayName: NSLocalizedString("Blixt Wallet", comment: "Dropdown option label for Lightning wallet, Blixt Wallet"), link: "blixtwallet:lightning:",
|
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:
|
case .river:
|
||||||
return .init(index: 12, tag: "river", displayName: NSLocalizedString("River", comment: "Dropdown option label for Lightning wallet, River"), link: "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")
|
appStoreLink: "https://apps.apple.com/us/app/river-buy-mine-bitcoin/id1536176542", image: "river")
|
||||||
|
|||||||
@@ -38,14 +38,8 @@ struct SelectWalletView: View {
|
|||||||
Section("Select a lightning wallet"){
|
Section("Select a lightning wallet"){
|
||||||
List{
|
List{
|
||||||
Button() {
|
Button() {
|
||||||
let walletModel = user_settings.default_wallet.model
|
let wallet_model = user_settings.default_wallet.model
|
||||||
if let url = URL(string: "\(walletModel.link)\(invoice)"), UIApplication.shared.canOpenURL(url) {
|
open_with_wallet(wallet: wallet_model, invoice: invoice)
|
||||||
openURL(url)
|
|
||||||
} else {
|
|
||||||
if let url = URL(string: walletModel.appStoreLink), UIApplication.shared.canOpenURL(url) {
|
|
||||||
openURL(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
HStack {
|
HStack {
|
||||||
Text("Default Wallet").font(.body).foregroundColor(.blue)
|
Text("Default Wallet").font(.body).foregroundColor(.blue)
|
||||||
@@ -54,13 +48,7 @@ struct SelectWalletView: View {
|
|||||||
List($allWalletModels) { $wallet in
|
List($allWalletModels) { $wallet in
|
||||||
if wallet.index >= 0 {
|
if wallet.index >= 0 {
|
||||||
Button() {
|
Button() {
|
||||||
if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) {
|
open_with_wallet(wallet: wallet, invoice: invoice)
|
||||||
openURL(url)
|
|
||||||
} else {
|
|
||||||
if let url = URL(string: wallet.appStoreLink), UIApplication.shared.canOpenURL(url) {
|
|
||||||
openURL(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} label: {
|
} label: {
|
||||||
HStack {
|
HStack {
|
||||||
Image(wallet.image).resizable().frame(width: 32.0, height: 32.0,alignment: .center).cornerRadius(5)
|
Image(wallet.image).resizable().frame(width: 32.0, height: 32.0,alignment: .center).cornerRadius(5)
|
||||||
|
|||||||
Reference in New Issue
Block a user