Skip to content

Commit 4bab656

Browse files
committed
Fix alert chaining and use pushRoute for watch-only wallet upgrade flow
Wrap alert-to-alert state changes in DispatchQueue.main.async on iOS to prevent SwiftUI's dismiss binding from overwriting the new alert state. Use pushRoute instead of loadAndReset so users can swipe back to the wallet after starting an import flow, on both iOS and Android.
1 parent cc6acac commit 4bab656

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

android/app/src/main/java/org/bitcoinppl/cove/MainActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ private fun GlobalAlertDialog(
732732
Column {
733733
TextButton(onClick = {
734734
onDismiss()
735-
app.loadAndReset(Route.NewWallet(NewWalletRoute.ColdWallet(ColdWalletRoute.QR_CODE)))
735+
app.pushRoute(Route.NewWallet(NewWalletRoute.ColdWallet(ColdWalletRoute.QR_CODE)))
736736
}) { Text("QR Code") }
737737
TextButton(onClick = {
738738
onDismiss()
@@ -777,19 +777,19 @@ private fun GlobalAlertDialog(
777777
Column {
778778
TextButton(onClick = {
779779
onDismiss()
780-
app.loadAndReset(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWENTY_FOUR, ImportType.QR))))
780+
app.pushRoute(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWENTY_FOUR, ImportType.QR))))
781781
}) { Text("Scan QR") }
782782
TextButton(onClick = {
783783
onDismiss()
784-
app.loadAndReset(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWENTY_FOUR, ImportType.NFC))))
784+
app.pushRoute(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWENTY_FOUR, ImportType.NFC))))
785785
}) { Text("NFC") }
786786
TextButton(onClick = {
787787
onDismiss()
788-
app.loadAndReset(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWELVE, ImportType.MANUAL))))
788+
app.pushRoute(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWELVE, ImportType.MANUAL))))
789789
}) { Text("12 Words") }
790790
TextButton(onClick = {
791791
onDismiss()
792-
app.loadAndReset(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWENTY_FOUR, ImportType.MANUAL))))
792+
app.pushRoute(Route.NewWallet(NewWalletRoute.HotWallet(HotWalletRoute.Import(NumberOfBip39Words.TWENTY_FOUR, ImportType.MANUAL))))
793793
}) { Text("24 Words") }
794794
}
795795
},

ios/Cove/CoveApp.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct CoveApp: App {
9090
}
9191

9292
Button("Use as Watch Only", role: .cancel) {
93-
app.alertState = .init(.confirmWatchOnly)
93+
DispatchQueue.main.async { app.alertState = .init(.confirmWatchOnly) }
9494
}
9595
case .confirmWatchOnly:
9696
Button("I Understand", role: .destructive) {
@@ -170,18 +170,18 @@ struct CoveApp: App {
170170
Button("Cancel", role: .cancel) { app.alertState = .none }
171171
case .cantSendOnWatchOnlyWallet:
172172
Button("Import Hardware Wallet") {
173-
app.alertState = .init(.watchOnlyImportHardware)
173+
DispatchQueue.main.async { app.alertState = .init(.watchOnlyImportHardware) }
174174
}
175175
Button("Import Words") {
176-
app.alertState = .init(.watchOnlyImportWords)
176+
DispatchQueue.main.async { app.alertState = .init(.watchOnlyImportWords) }
177177
}
178178
Button("Cancel", role: .cancel) {
179179
app.alertState = .none
180180
}
181181
case .watchOnlyImportHardware:
182182
Button("QR Code") {
183183
app.alertState = .none
184-
app.loadAndReset(to: .newWallet(.coldWallet(.qrCode)))
184+
app.pushRoute(.newWallet(.coldWallet(.qrCode)))
185185
}
186186
Button("NFC") {
187187
app.alertState = .none
@@ -195,9 +195,11 @@ struct CoveApp: App {
195195
let wallet = try Wallet.newFromXpub(xpub: text)
196196
try app.rust.selectWallet(id: wallet.id())
197197
} catch {
198-
app.alertState = .init(
199-
.errorImportingHardwareWallet(message: error.localizedDescription)
200-
)
198+
DispatchQueue.main.async {
199+
app.alertState = .init(
200+
.errorImportingHardwareWallet(message: error.localizedDescription)
201+
)
202+
}
201203
}
202204
}
203205
Button("Cancel", role: .cancel) {
@@ -206,19 +208,19 @@ struct CoveApp: App {
206208
case .watchOnlyImportWords:
207209
Button("Scan QR") {
208210
app.alertState = .none
209-
app.loadAndReset(to: .newWallet(.hotWallet(.import(.twentyFour, .qr))))
211+
app.pushRoute(.newWallet(.hotWallet(.import(.twentyFour, .qr))))
210212
}
211213
Button("NFC") {
212214
app.alertState = .none
213-
app.loadAndReset(to: .newWallet(.hotWallet(.import(.twentyFour, .nfc))))
215+
app.pushRoute(.newWallet(.hotWallet(.import(.twentyFour, .nfc))))
214216
}
215217
Button("12 Words") {
216218
app.alertState = .none
217-
app.loadAndReset(to: .newWallet(.hotWallet(.import(.twelve, .manual))))
219+
app.pushRoute(.newWallet(.hotWallet(.import(.twelve, .manual))))
218220
}
219221
Button("24 Words") {
220222
app.alertState = .none
221-
app.loadAndReset(to: .newWallet(.hotWallet(.import(.twentyFour, .manual))))
223+
app.pushRoute(.newWallet(.hotWallet(.import(.twentyFour, .manual))))
222224
}
223225
Button("Cancel", role: .cancel) {
224226
app.alertState = .none

0 commit comments

Comments
 (0)