Skip to content

Commit f462f0a

Browse files
authored
tentative fix for evm wallet creation issue after backup restore (#3316)
1 parent 879eb91 commit f462f0a

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

lib/src/screens/wallet_connect/services/walletkit_service.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ abstract class WalletKitServiceBase with Store {
132132
debugPrint('Intializing walletKit');
133133
if (!isInitialized) {
134134
try {
135-
await _walletKit.init();
135+
await _walletKit.init().timeout(
136+
const Duration(seconds: 8),
137+
onTimeout: () => throw TimeoutException('walletKit init timed out'),
138+
);
136139
debugPrint('Initialized');
137140
isInitialized = true;
138141
} catch (e) {
@@ -206,7 +209,7 @@ abstract class WalletKitServiceBase with Store {
206209
name: 'accountsChanged',
207210
data: [chain.publicKey],
208211
),
209-
);
212+
).timeout(const Duration(seconds: 3));
210213
}
211214
} on ReownSignError catch (e) {
212215
if (e.code == 6) {

lib/store/app_store.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:cake_wallet/core/amount_parsing_proxy.dart';
24
import 'package:cake_wallet/di.dart';
35
import 'package:cake_wallet/entities/preferences_key.dart';
@@ -6,6 +8,7 @@ import 'package:cake_wallet/src/screens/wallet_connect/services/walletkit_servic
68
import 'package:cake_wallet/themes/core/theme_store.dart';
79
import 'package:cake_wallet/utils/exception_handler.dart';
810
import 'package:cw_core/transaction_info.dart';
11+
import 'package:cw_core/utils/print_verbose.dart';
912
import 'package:cw_core/wallet_type.dart';
1013
import 'package:mobx/mobx.dart';
1114
import 'package:cw_core/balance.dart';
@@ -63,13 +66,22 @@ abstract class AppStoreBase with Store {
6366
this.wallet!.setExceptionHandler(ExceptionHandler.onError);
6467

6568
if (isWalletConnectCompatibleChain(wallet.type)) {
66-
await getIt.get<WalletKitService>().onDispose();
67-
getIt.get<WalletKitService>().create();
68-
await getIt.get<WalletKitService>().init();
69+
unawaited(_setupWalletConnect());
6970
}
7071
await getIt.get<SharedPreferences>().setString(PreferencesKey.currentWalletName, wallet.name);
7172
await getIt
7273
.get<SharedPreferences>()
7374
.setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type));
7475
}
76+
77+
Future<void> _setupWalletConnect() async {
78+
try {
79+
final wcService = getIt.get<WalletKitService>();
80+
await wcService.onDispose();
81+
wcService.create();
82+
await wcService.init();
83+
} catch (e, s) {
84+
printV('WalletConnect setup failed: $e\n$s');
85+
}
86+
}
7587
}

0 commit comments

Comments
 (0)