Skip to content

Commit 7b7e2ab

Browse files
committed
added .live
1 parent 59e039e commit 7b7e2ab

15 files changed

+29
-86
lines changed

BDKSwiftExampleWallet/App/BDKSwiftExampleWalletApp.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ struct BDKSwiftExampleWalletApp: App {
2020
if value != nil && !isOnboarding {
2121
HomeView(
2222
viewModel: .init(
23-
bdkClient: .esplora
23+
bdkClient: .live
2424
),
2525
navigationPath: $navigationPath
2626
)
2727
} else {
2828
OnboardingView(
2929
viewModel: .init(
30-
bdkClient: .esplora
30+
bdkClient: .live
3131
)
3232
)
3333
}
3434
}
3535
.onChange(of: isOnboarding) { oldValue, newValue in
36-
BDKClient.esplora.setNeedsFullScan(true)
36+
BDKClient.live.setNeedsFullScan(true)
3737
navigationPath = NavigationPath()
3838
}
3939
}

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ class BDKService {
1212
static var shared: BDKService = BDKService()
1313

1414
private var syncMode: SyncMode?
15-
private var service: BDKClient {
16-
switch try? keyClient.getSyncMode() {
17-
case .kyoto:
18-
return .kyoto
19-
default:
20-
return .esplora
21-
}
22-
}
23-
private let keyClient: KeyClient
15+
let keyClient: KeyClient
2416
private var needsFullScan: Bool = false
2517
private(set) var network: Network
2618
private(set) var esploraURL: String
@@ -111,67 +103,18 @@ struct BDKClient {
111103
}
112104

113105
extension BDKClient {
114-
// MARK: - live
115-
// static let live = Self(
116-
// loadWallet: { try BDKService.shared.loadWalletFromBackup() },
117-
// deleteWallet: { try BDKService.shared.deleteWallet() },
118-
// createWalletFromSeed: { words in try BDKService.shared.createWallet(words: words) },
119-
// createWalletFromDescriptor: { descriptor in
120-
// try BDKService.shared.createWallet(descriptor: descriptor)
121-
// },
122-
// createWalletFromXPub: { xpub in
123-
// try BDKService.shared.createWallet(xpub: xpub)
124-
// },
125-
// getBalance: { try BDKService.shared.getBalance() },
126-
// transactions: { try BDKService.shared.transactions() },
127-
// listUnspent: { try BDKService.shared.listUnspent() },
128-
// syncScanWithSyncScanProgress: { progress in
129-
// try await BDKService.shared.syncWithInspector(progress: progress)
130-
// },
131-
// fullScanWithFullScanProgress: { progress in
132-
// try await BDKService.shared.fullScanWithInspector(progress: progress)
133-
// },
134-
// getAddress: { try BDKService.shared.getAddress() },
135-
// send: { (address, amount, feeRate) in
136-
// Task {
137-
// try await BDKService.shared.send(address: address, amount: amount, feeRate: feeRate)
138-
// }
139-
// },
140-
// calculateFee: { tx in try BDKService.shared.calculateFee(tx: tx) },
141-
// calculateFeeRate: { tx in try BDKService.shared.calculateFeeRate(tx: tx) },
142-
// sentAndReceived: { tx in try BDKService.shared.sentAndReceived(tx: tx) },
143-
// buildTransaction: { (address, amount, feeRate) in
144-
// try BDKService.shared.buildTransaction(
145-
// address: address,
146-
// amount: amount,
147-
// feeRate: feeRate
148-
// )
149-
// },
150-
// getBackupInfo: { try BDKService.shared.getBackupInfo() },
151-
// needsFullScan: { BDKService.shared.needsFullScanOfWallet() },
152-
// setNeedsFullScan: { value in BDKService.shared.setNeedsFullScan(value) },
153-
// getNetwork: {
154-
// BDKService.shared.network
155-
// },
156-
// getEsploraURL: {
157-
// BDKService.shared.esploraURL
158-
// },
159-
// updateNetwork: { newNetwork in
160-
// BDKService.shared.updateNetwork(newNetwork)
161-
// },
162-
// updateEsploraURL: { newURL in
163-
// BDKService.shared.updateEsploraURL(newURL)
164-
// },
165-
// stop: {
166-
// try await BDKService.shared.stop()
167-
// },
168-
// upateSyncMode: { mode in
169-
// BDKService.shared.updateSyncMode(mode)
170-
// },
171-
// getSyncMode: {
172-
// BDKService.shared.getSyncMode()
173-
// }
174-
// )
106+
static var live: BDKClient {
107+
do {
108+
let syncMode = try BDKService.shared.keyClient.getSyncMode()
109+
if syncMode == .kyoto {
110+
return .kyoto
111+
} else {
112+
return .esplora
113+
}
114+
} catch {
115+
return .esplora
116+
}
117+
}
175118
}
176119

177120
#if DEBUG

BDKSwiftExampleWallet/View Model/Activity/ActivityListViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ActivityListViewModel {
3939
}
4040

4141
init(
42-
bdkClient: BDKClient = .esplora,
42+
bdkClient: BDKClient = .live,
4343
transactions: [CanonicalTx] = [],
4444
walletSyncState: WalletSyncState = .notStarted
4545
) {

BDKSwiftExampleWallet/View Model/Activity/TransactionDetailViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TransactionDetailViewModel {
2323
var transactionDetailsError: AppError?
2424

2525
init(
26-
bdkClient: BDKClient = .esplora
26+
bdkClient: BDKClient = .live
2727
) {
2828
self.bdkClient = bdkClient
2929
}

BDKSwiftExampleWallet/View Model/Activity/TransactionListViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TransactionListViewModel {
1717
var walletTransactionsViewError: AppError?
1818

1919
init(
20-
bdkClient: BDKClient = .esplora
20+
bdkClient: BDKClient = .live
2121
) {
2222
self.bdkClient = bdkClient
2323
}

BDKSwiftExampleWallet/View Model/HomeViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class HomeViewModel: ObservableObject {
1717
var isWalletLoaded = false
1818
var showingHomeViewErrorAlert = false
1919

20-
init(bdkClient: BDKClient = .esplora) {
20+
init(bdkClient: BDKClient = .live) {
2121
self.bdkClient = bdkClient
2222
}
2323

BDKSwiftExampleWallet/View Model/Receive/ReceiveViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ReceiveViewModel: NSObject, NFCNDEFReaderSessionDelegate {
2020
var receiveViewError: AppError?
2121
var showingReceiveViewErrorAlert = false
2222

23-
init(bdkClient: BDKClient = .esplora) {
23+
init(bdkClient: BDKClient = .live) {
2424
self.bdkClient = bdkClient
2525
}
2626

BDKSwiftExampleWallet/View Model/Send/AmountViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AmountViewModel {
1818
var balanceTotal: UInt64?
1919
var showingAmountViewErrorAlert = false
2020

21-
init(bdkClient: BDKClient = .esplora) {
21+
init(bdkClient: BDKClient = .live) {
2222
self.bdkClient = bdkClient
2323
}
2424

BDKSwiftExampleWallet/View Model/Send/BuildTransactionViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BuildTransactionViewModel {
1919
var showingBuildTransactionViewErrorAlert = false
2020

2121
init(
22-
bdkClient: BDKClient = .esplora
22+
bdkClient: BDKClient = .live
2323
) {
2424
self.bdkClient = bdkClient
2525
}

BDKSwiftExampleWallet/View Model/Send/FeeViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FeeViewModel {
3737
var recommendedFees: RecommendedFees?
3838
var showingFeeViewErrorAlert = false
3939

40-
init(feeClient: FeeClient = .live, bdkClient: BDKClient = .esplora) {
40+
init(feeClient: FeeClient = .live, bdkClient: BDKClient = .live) {
4141
self.feeClient = feeClient
4242
self.bdkClient = bdkClient
4343
}

0 commit comments

Comments
 (0)