diff --git a/BDKSwiftExampleWallet/Resources/Localizable.xcstrings b/BDKSwiftExampleWallet/Resources/Localizable.xcstrings index 97539308..94bdee9f 100644 --- a/BDKSwiftExampleWallet/Resources/Localizable.xcstrings +++ b/BDKSwiftExampleWallet/Resources/Localizable.xcstrings @@ -700,6 +700,9 @@ } } } + }, + "Testnet4" : { + }, "To" : { "extractionState" : "stale", diff --git a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift index 005675f7..14880023 100644 --- a/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift +++ b/BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift @@ -24,8 +24,21 @@ private class BDKService { self.keyClient = keyClient let storedNetworkString = try? keyClient.getNetwork() ?? Network.signet.description self.network = Network(stringValue: storedNetworkString ?? "") ?? .signet - self.esploraURL = - try! keyClient.getEsploraURL() ?? Constants.Config.EsploraServerURLNetwork.Signet.mutiny + + switch self.network { + case .bitcoin: + self.esploraURL = Constants.Config.EsploraServerURLNetwork.Bitcoin.allValues.first ?? "" + case .testnet: + self.esploraURL = Constants.Config.EsploraServerURLNetwork.Testnet.allValues.first ?? "" + case .regtest: + self.esploraURL = Constants.Config.EsploraServerURLNetwork.Regtest.allValues.first ?? "" + case .signet: + self.esploraURL = Constants.Config.EsploraServerURLNetwork.Signet.allValues.first ?? "" + case .testnet4: + self.esploraURL = + Constants.Config.EsploraServerURLNetwork.Testnet4.allValues.first ?? "" + } + self.esploraClient = EsploraClient(url: self.esploraURL) } @@ -188,8 +201,19 @@ private class BDKService { } else { } - let baseUrl = - try keyClient.getEsploraURL() ?? Constants.Config.EsploraServerURLNetwork.Signet.mutiny + let baseUrl: String + switch self.network { + case .bitcoin: + baseUrl = Constants.Config.EsploraServerURLNetwork.Bitcoin.allValues.first ?? "" + case .testnet: + baseUrl = Constants.Config.EsploraServerURLNetwork.Testnet.allValues.first ?? "" + case .regtest: + baseUrl = Constants.Config.EsploraServerURLNetwork.Regtest.allValues.first ?? "" + case .signet: + baseUrl = Constants.Config.EsploraServerURLNetwork.Signet.allValues.first ?? "" + case .testnet4: + baseUrl = Constants.Config.EsploraServerURLNetwork.Testnet4.allValues.first ?? "" + } guard let descriptorString = descriptor, !descriptorString.isEmpty else { throw WalletError.walletNotFound diff --git a/BDKSwiftExampleWallet/View/Activity/TransactionListView.swift b/BDKSwiftExampleWallet/View/Activity/TransactionListView.swift index 5e340335..55ee27e7 100644 --- a/BDKSwiftExampleWallet/View/Activity/TransactionListView.swift +++ b/BDKSwiftExampleWallet/View/Activity/TransactionListView.swift @@ -41,8 +41,8 @@ struct TransactionListView: View { if let mutinyFaucetURL, let signetFaucetURL, viewModel.getNetwork() != Network.testnet.description + && viewModel.getNetwork() != Network.testnet4.description { - Button { UIApplication.shared.open( viewModel.getEsploraURL() @@ -59,7 +59,27 @@ struct TransactionListView: View { .underline() } .buttonStyle(.plain) + } + + let testnet4FaucetURL = URL(string: "https://mempool.space/testnet4/faucet") + if let testnet4FaucetURL, + viewModel.getNetwork() == Network.testnet4.description + { + Button { + UIApplication.shared.open( + testnet4FaucetURL + ) + } label: { + HStack(spacing: 2) { + Text("Get sats from faucet") + Image(systemName: "arrow.right") + } + .font(.caption) + .foregroundStyle(.secondary) + .underline() + } + .buttonStyle(.plain) } } diff --git a/BDKSwiftExampleWallet/View/OnboardingView.swift b/BDKSwiftExampleWallet/View/OnboardingView.swift index 37941607..62ac3a9e 100644 --- a/BDKSwiftExampleWallet/View/OnboardingView.swift +++ b/BDKSwiftExampleWallet/View/OnboardingView.swift @@ -114,6 +114,7 @@ struct OnboardingView: View { Picker("Network", selection: $viewModel.selectedNetwork) { Text("Signet").tag(Network.signet) Text("Testnet").tag(Network.testnet) + Text("Testnet4").tag(Network.testnet4) } .pickerStyle(.automatic) .tint(.primary)