Skip to content

Commit 22a609f

Browse files
committed
refactor(mwc): consolidate openWallet calls through _ensureWalletOpen
1 parent 9dd3d96 commit 22a609f

1 file changed

Lines changed: 9 additions & 44 deletions

File tree

lib/wallets/wallet/impl/mimblewimblecoin_wallet.dart

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ class MimblewimblecoinWallet extends Bip39Wallet {
109109
if (password == null) {
110110
throw Exception('Wallet password not found');
111111
}
112-
final opened = await libMwc.openWallet(
113-
config: config,
114-
password: password,
115-
);
112+
final opened = await libMwc
113+
.openWallet(config: config, password: password)
114+
.timeout(
115+
const Duration(seconds: 60),
116+
onTimeout: () => throw TimeoutException('openWallet timed out'),
117+
);
116118
await secureStorageInterface.write(
117119
key: '${walletId}_wallet',
118120
value: opened,
@@ -914,17 +916,7 @@ class MimblewimblecoinWallet extends Bip39Wallet {
914916
);
915917

916918
//Open wallet
917-
encodedWallet = await _walletOpenMutex.protect(() async {
918-
final opened = await libMwc.openWallet(
919-
config: stringConfig,
920-
password: password,
921-
);
922-
await secureStorageInterface.write(
923-
key: '${walletId}_wallet',
924-
value: opened,
925-
);
926-
return opened;
927-
});
919+
encodedWallet = await _ensureWalletOpen();
928920
//Store MwcMqs address info
929921
await _generateAndStoreReceivingAddressForIndex(0);
930922

@@ -949,25 +941,7 @@ class MimblewimblecoinWallet extends Bip39Wallet {
949941
);
950942
} else {
951943
try {
952-
final config = await _getRealConfig();
953-
//if (!_logsInitialized) {
954-
// await libMwc.initLogs(config: config);
955-
// _logsInitialized = true; // Set flag to true after initializing
956-
//}
957-
final password = await secureStorageInterface.read(
958-
key: '${walletId}_password',
959-
);
960-
961-
await _walletOpenMutex.protect(() async {
962-
final walletOpen = await libMwc.openWallet(
963-
config: config,
964-
password: password!,
965-
);
966-
await secureStorageInterface.write(
967-
key: '${walletId}_wallet',
968-
value: walletOpen,
969-
);
970-
});
944+
await _ensureWalletOpen();
971945

972946
await updateNode();
973947
} catch (e, s) {
@@ -1169,16 +1143,7 @@ class MimblewimblecoinWallet extends Bip39Wallet {
11691143
);
11701144

11711145
//Open Wallet
1172-
await _walletOpenMutex.protect(() async {
1173-
final walletOpen = await libMwc.openWallet(
1174-
config: stringConfig,
1175-
password: password,
1176-
);
1177-
await secureStorageInterface.write(
1178-
key: '${walletId}_wallet',
1179-
value: walletOpen,
1180-
);
1181-
});
1146+
await _ensureWalletOpen();
11821147

11831148
await _generateAndStoreReceivingAddressForIndex(
11841149
mimblewimblecoinData.receivingIndex,

0 commit comments

Comments
 (0)