From 22015eb1e19e314c35c5d5c2ee83be8507a17c66 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 31 Jul 2026 00:05:18 +0200 Subject: [PATCH] fix: add reconnection logic to hardware wallet flow to handle tap-backs (#3458) --- lib/buy/dfx/dfx_buy_provider.dart | 25 ++++++++++++------ lib/buy/robinhood/robinhood_buy_provider.dart | 23 ++++++++++------ lib/new-ui/pages/send_page.dart | 7 +++++ .../widgets/swap_page/swap_confirm_sheet.dart | 26 ++++++++++++------- 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/lib/buy/dfx/dfx_buy_provider.dart b/lib/buy/dfx/dfx_buy_provider.dart index 104d66325..282ed7698 100644 --- a/lib/buy/dfx/dfx_buy_provider.dart +++ b/lib/buy/dfx/dfx_buy_provider.dart @@ -336,14 +336,23 @@ class DFXBuyProvider extends BuyProvider { String? countryCode}) async { if (wallet.isHardwareWallet) { if (!hardwareWalletVM!.isConnected(wallet.walletInfo.type)) { - await Navigator.of(context).pushNamed(Routes.connectDevices, - arguments: ConnectDevicePageParams( - walletType: wallet.walletInfo.type, - hardwareWalletType: wallet.walletInfo.hardwareWalletType!, - onConnectDevice: (context, hwwVM) { - hwwVM.initWallet(wallet); - Navigator.of(context).pop(); - })); + await Navigator.of(context).pushNamed( + Routes.connectDevices, + arguments: ConnectDevicePageParams( + walletType: wallet.walletInfo.type, + hardwareWalletType: wallet.walletInfo.hardwareWalletType!, + onConnectDevice: (context, hwwVM) { + hwwVM.initWallet(wallet); + Navigator.of(context).pop(); + }, + isReconnect: false, + ), + ); + + // Recheck to handle tap-backs + if (!hardwareWalletVM!.isConnected(wallet.walletInfo.type)) { + return; + } } else { hardwareWalletVM!.initWallet(wallet); } diff --git a/lib/buy/robinhood/robinhood_buy_provider.dart b/lib/buy/robinhood/robinhood_buy_provider.dart index f56fc8c1b..651dc6b84 100644 --- a/lib/buy/robinhood/robinhood_buy_provider.dart +++ b/lib/buy/robinhood/robinhood_buy_provider.dart @@ -174,14 +174,21 @@ class RobinhoodBuyProvider extends BuyProvider { String? countryCode}) async { if (wallet.isHardwareWallet) { if (!hardwareWalletVM!.isConnected(wallet.walletInfo.type)) { - await Navigator.of(context).pushNamed(Routes.connectDevices, - arguments: ConnectDevicePageParams( - walletType: wallet.walletInfo.type, - hardwareWalletType: wallet.walletInfo.hardwareWalletType!, - onConnectDevice: (context, hwwVM) { - hwwVM.initWallet(wallet); - Navigator.of(context).pop(); - })); + await Navigator.of(context).pushNamed( + Routes.connectDevices, + arguments: ConnectDevicePageParams( + walletType: wallet.walletInfo.type, + hardwareWalletType: wallet.walletInfo.hardwareWalletType!, + onConnectDevice: (context, hwwVM) { + hwwVM.initWallet(wallet); + Navigator.of(context).pop(); + }, + isReconnect: false, + ), + ); + if (!hardwareWalletVM!.isConnected(wallet.walletInfo.type)) { + return; + } } else { hardwareWalletVM!.initWallet(wallet); } diff --git a/lib/new-ui/pages/send_page.dart b/lib/new-ui/pages/send_page.dart index 721e21840..7e386807c 100644 --- a/lib/new-ui/pages/send_page.dart +++ b/lib/new-ui/pages/send_page.dart @@ -823,8 +823,15 @@ class _NewSendPageState extends State { widget.sendViewModel.hardwareWalletViewModel!.initWallet(widget.sendViewModel.wallet); Navigator.of(context).pop(); }, + isReconnect: false, ), ); + + // Recheck to handle tap-backs + if (!widget.sendViewModel.hardwareWalletViewModel! + .isConnected(widget.sendViewModel.walletType)) { + return; + } } else { await widget.sendViewModel.hardwareWalletViewModel!.initWallet(widget.sendViewModel.wallet); } diff --git a/lib/new-ui/widgets/swap_page/swap_confirm_sheet.dart b/lib/new-ui/widgets/swap_page/swap_confirm_sheet.dart index 6a7f49900..c948d6b12 100644 --- a/lib/new-ui/widgets/swap_page/swap_confirm_sheet.dart +++ b/lib/new-ui/widgets/swap_page/swap_confirm_sheet.dart @@ -47,15 +47,23 @@ class _SwapConfirmSheetState extends State { if (sendVM.wallet.isHardwareWallet) { if (!sendVM.hardwareWalletViewModel!.isConnected(sendVM.walletType)) { - await Navigator.of(context).pushNamed(Routes.connectDevices, - arguments: ConnectDevicePageParams( - walletType: sendVM.walletType, - hardwareWalletType: sendVM.wallet.walletInfo.hardwareWalletType!, - onConnectDevice: (context, _) { - sendVM.hardwareWalletViewModel!.initWallet(sendVM.wallet); - Navigator.of(context).pop(); - }, - )); + await Navigator.of(context).pushNamed( + Routes.connectDevices, + arguments: ConnectDevicePageParams( + walletType: sendVM.walletType, + hardwareWalletType: sendVM.wallet.walletInfo.hardwareWalletType!, + onConnectDevice: (context, _) { + sendVM.hardwareWalletViewModel!.initWallet(sendVM.wallet); + Navigator.of(context).pop(); + }, + isReconnect: false, + ), + ); + + // Recheck to handle tap-backs + if (!sendVM.hardwareWalletViewModel!.isConnected(sendVM.walletType)) { + return; + } } else { sendVM.hardwareWalletViewModel!.initWallet(sendVM.wallet); }