Skip to content

Commit f007eac

Browse files
authored
feat: testnet4
1 parent 6b83010 commit f007eac

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

BDKSwiftExampleWallet/Resources/Localizable.xcstrings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@
700700
}
701701
}
702702
}
703+
},
704+
"Testnet4" : {
705+
703706
},
704707
"To" : {
705708
"extractionState" : "stale",

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,21 @@ private class BDKService {
2424
self.keyClient = keyClient
2525
let storedNetworkString = try? keyClient.getNetwork() ?? Network.signet.description
2626
self.network = Network(stringValue: storedNetworkString ?? "") ?? .signet
27-
self.esploraURL =
28-
try! keyClient.getEsploraURL() ?? Constants.Config.EsploraServerURLNetwork.Signet.mutiny
27+
28+
switch self.network {
29+
case .bitcoin:
30+
self.esploraURL = Constants.Config.EsploraServerURLNetwork.Bitcoin.allValues.first ?? ""
31+
case .testnet:
32+
self.esploraURL = Constants.Config.EsploraServerURLNetwork.Testnet.allValues.first ?? ""
33+
case .regtest:
34+
self.esploraURL = Constants.Config.EsploraServerURLNetwork.Regtest.allValues.first ?? ""
35+
case .signet:
36+
self.esploraURL = Constants.Config.EsploraServerURLNetwork.Signet.allValues.first ?? ""
37+
case .testnet4:
38+
self.esploraURL =
39+
Constants.Config.EsploraServerURLNetwork.Testnet4.allValues.first ?? ""
40+
}
41+
2942
self.esploraClient = EsploraClient(url: self.esploraURL)
3043
}
3144

@@ -188,8 +201,19 @@ private class BDKService {
188201
} else {
189202
}
190203

191-
let baseUrl =
192-
try keyClient.getEsploraURL() ?? Constants.Config.EsploraServerURLNetwork.Signet.mutiny
204+
let baseUrl: String
205+
switch self.network {
206+
case .bitcoin:
207+
baseUrl = Constants.Config.EsploraServerURLNetwork.Bitcoin.allValues.first ?? ""
208+
case .testnet:
209+
baseUrl = Constants.Config.EsploraServerURLNetwork.Testnet.allValues.first ?? ""
210+
case .regtest:
211+
baseUrl = Constants.Config.EsploraServerURLNetwork.Regtest.allValues.first ?? ""
212+
case .signet:
213+
baseUrl = Constants.Config.EsploraServerURLNetwork.Signet.allValues.first ?? ""
214+
case .testnet4:
215+
baseUrl = Constants.Config.EsploraServerURLNetwork.Testnet4.allValues.first ?? ""
216+
}
193217

194218
guard let descriptorString = descriptor, !descriptorString.isEmpty else {
195219
throw WalletError.walletNotFound

BDKSwiftExampleWallet/View/Activity/TransactionListView.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ struct TransactionListView: View {
4141
if let mutinyFaucetURL,
4242
let signetFaucetURL,
4343
viewModel.getNetwork() != Network.testnet.description
44+
&& viewModel.getNetwork() != Network.testnet4.description
4445
{
45-
4646
Button {
4747
UIApplication.shared.open(
4848
viewModel.getEsploraURL()
@@ -59,7 +59,27 @@ struct TransactionListView: View {
5959
.underline()
6060
}
6161
.buttonStyle(.plain)
62+
}
63+
64+
let testnet4FaucetURL = URL(string: "https://mempool.space/testnet4/faucet")
6265

66+
if let testnet4FaucetURL,
67+
viewModel.getNetwork() == Network.testnet4.description
68+
{
69+
Button {
70+
UIApplication.shared.open(
71+
testnet4FaucetURL
72+
)
73+
} label: {
74+
HStack(spacing: 2) {
75+
Text("Get sats from faucet")
76+
Image(systemName: "arrow.right")
77+
}
78+
.font(.caption)
79+
.foregroundStyle(.secondary)
80+
.underline()
81+
}
82+
.buttonStyle(.plain)
6383
}
6484

6585
}

BDKSwiftExampleWallet/View/OnboardingView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct OnboardingView: View {
114114
Picker("Network", selection: $viewModel.selectedNetwork) {
115115
Text("Signet").tag(Network.signet)
116116
Text("Testnet").tag(Network.testnet)
117+
Text("Testnet4").tag(Network.testnet4)
117118
}
118119
.pickerStyle(.automatic)
119120
.tint(.primary)

0 commit comments

Comments
 (0)