Skip to content

Commit d218cb7

Browse files
committed
refactor(activity): compare networks as enums
1 parent cdd7b46 commit d218cb7

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

BDKSwiftExampleWallet/View Model/Activity/TransactionDetailViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TransactionDetailViewModel {
1616

1717
var esploraError: EsploraError?
1818
var esploraURL: String?
19-
var network: String?
19+
var network: Network?
2020
var showingTransactionDetailsViewErrorAlert = false
2121
var transactionDetailsError: AppError?
2222

@@ -30,13 +30,13 @@ class TransactionDetailViewModel {
3030
let savedEsploraURL = bdkClient.getEsploraURL()
3131

3232
switch network {
33-
case "signet":
33+
case .signet:
3434
if savedEsploraURL == Constants.Networks.Signet.Regular.esploraServers.first {
3535
self.esploraURL = "https://mempool.space/signet"
3636
} else {
3737
self.esploraURL = "https://mutinynet.com"
3838
}
39-
case "testnet":
39+
case .testnet:
4040
if savedEsploraURL == Constants.Networks.Testnet.esploraServers.last {
4141
self.esploraURL = "https://blockstream.info/testnet"
4242
} else {
@@ -48,7 +48,7 @@ class TransactionDetailViewModel {
4848
}
4949

5050
func getNetwork() {
51-
self.network = bdkClient.getNetwork().description
51+
self.network = bdkClient.getNetwork()
5252
}
5353

5454
}

BDKSwiftExampleWallet/View Model/Activity/TransactionListViewModel.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ class TransactionListViewModel {
4040
return savedEsploraURL
4141
}
4242

43-
func getNetwork() -> String {
44-
let savedNetwork = bdkClient.getNetwork().description
45-
return savedNetwork
43+
func getNetwork() -> Network {
44+
bdkClient.getNetwork()
4645
}
4746

4847
}

BDKSwiftExampleWallet/View/Activity/TransactionDetailView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct TransactionDetailView: View {
105105
Spacer()
106106

107107
HStack {
108-
if viewModel.network != Network.regtest.description {
108+
if viewModel.network != .regtest {
109109
Button {
110110
if let esploraURL = viewModel.esploraURL {
111111
let urlString =

BDKSwiftExampleWallet/View/Activity/TransactionListView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ struct TransactionListView: View {
5050
let signetNetwork = Constants.Config.SignetNetwork.from(
5151
esploraURL: viewModel.getEsploraURL()
5252
)
53+
let network = viewModel.getNetwork()
5354

54-
if viewModel.getNetwork() != Network.testnet.description
55-
&& viewModel.getNetwork() != Network.testnet4.description
55+
if network != .testnet
56+
&& network != .testnet4
5657
{
5758
Button {
5859
if let faucetURL = signetNetwork.defaultFaucet {
@@ -73,7 +74,7 @@ struct TransactionListView: View {
7374
let testnet4FaucetURL = Constants.Networks.Testnet4.Faucet.mempool.url
7475

7576
if let testnet4FaucetURL,
76-
viewModel.getNetwork() == Network.testnet4.description
77+
network == .testnet4
7778
{
7879
Button {
7980
UIApplication.shared.open(

0 commit comments

Comments
 (0)