From f462f0a2d73a66b0b5c5330e1ec5587413ea54ba Mon Sep 17 00:00:00 2001 From: David Adegoke <64401859+Blazebrain@users.noreply.github.com> Date: Mon, 8 Jun 2026 23:01:44 +0100 Subject: [PATCH] tentative fix for evm wallet creation issue after backup restore (#3316) --- .../services/walletkit_service.dart | 7 +++++-- lib/store/app_store.dart | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/src/screens/wallet_connect/services/walletkit_service.dart b/lib/src/screens/wallet_connect/services/walletkit_service.dart index 7d5a0ca67..a758b8b9c 100644 --- a/lib/src/screens/wallet_connect/services/walletkit_service.dart +++ b/lib/src/screens/wallet_connect/services/walletkit_service.dart @@ -132,7 +132,10 @@ abstract class WalletKitServiceBase with Store { debugPrint('Intializing walletKit'); if (!isInitialized) { try { - await _walletKit.init(); + await _walletKit.init().timeout( + const Duration(seconds: 8), + onTimeout: () => throw TimeoutException('walletKit init timed out'), + ); debugPrint('Initialized'); isInitialized = true; } catch (e) { @@ -206,7 +209,7 @@ abstract class WalletKitServiceBase with Store { name: 'accountsChanged', data: [chain.publicKey], ), - ); + ).timeout(const Duration(seconds: 3)); } } on ReownSignError catch (e) { if (e.code == 6) { diff --git a/lib/store/app_store.dart b/lib/store/app_store.dart index dd41fe948..70ff844d8 100644 --- a/lib/store/app_store.dart +++ b/lib/store/app_store.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:cake_wallet/core/amount_parsing_proxy.dart'; import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; @@ -6,6 +8,7 @@ import 'package:cake_wallet/src/screens/wallet_connect/services/walletkit_servic import 'package:cake_wallet/themes/core/theme_store.dart'; import 'package:cake_wallet/utils/exception_handler.dart'; import 'package:cw_core/transaction_info.dart'; +import 'package:cw_core/utils/print_verbose.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_core/balance.dart'; @@ -63,13 +66,22 @@ abstract class AppStoreBase with Store { this.wallet!.setExceptionHandler(ExceptionHandler.onError); if (isWalletConnectCompatibleChain(wallet.type)) { - await getIt.get().onDispose(); - getIt.get().create(); - await getIt.get().init(); + unawaited(_setupWalletConnect()); } await getIt.get().setString(PreferencesKey.currentWalletName, wallet.name); await getIt .get() .setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type)); } + + Future _setupWalletConnect() async { + try { + final wcService = getIt.get(); + await wcService.onDispose(); + wcService.create(); + await wcService.init(); + } catch (e, s) { + printV('WalletConnect setup failed: $e\n$s'); + } + } }