diff --git a/cw_monero/lib/api/wallet_manager.dart b/cw_monero/lib/api/wallet_manager.dart index ad21e55a8..b75f3c9db 100644 --- a/cw_monero/lib/api/wallet_manager.dart +++ b/cw_monero/lib/api/wallet_manager.dart @@ -32,13 +32,14 @@ void createWalletSync( required String language, int nettype = 0}) { txhistory = null; - wptr = monero.WalletManager_createWallet(wmPtr, + final newWptr = monero.WalletManager_createWallet(wmPtr, path: path, password: password, language: language, networkType: 0); - final status = monero.Wallet_status(wptr!); + final status = monero.Wallet_status(newWptr); if (status != 0) { - throw WalletCreationException(message: monero.Wallet_errorString(wptr!)); + throw WalletCreationException(message: monero.Wallet_errorString(newWptr)); } + wptr = newWptr; monero.Wallet_store(wptr!, path: path); openedWalletsByPath[path] = wptr!; @@ -58,7 +59,7 @@ void restoreWalletFromSeedSync( int nettype = 0, int restoreHeight = 0}) { txhistory = null; - wptr = monero.WalletManager_recoveryWallet( + final newWptr = monero.WalletManager_recoveryWallet( wmPtr, path: path, password: password, @@ -68,12 +69,13 @@ void restoreWalletFromSeedSync( networkType: 0, ); - final status = monero.Wallet_status(wptr!); + final status = monero.Wallet_status(newWptr); if (status != 0) { - final error = monero.Wallet_errorString(wptr!); + final error = monero.Wallet_errorString(newWptr); throw WalletRestoreFromSeedException(message: error); } + wptr = newWptr; monero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.passphrase", value: passphrase); @@ -90,7 +92,7 @@ void restoreWalletFromKeysSync( int nettype = 0, int restoreHeight = 0}) { txhistory = null; - wptr = monero.WalletManager_createWalletFromKeys( + final newWptr = monero.WalletManager_createWalletFromKeys( wmPtr, path: path, password: password, @@ -101,12 +103,14 @@ void restoreWalletFromKeysSync( nettype: 0, ); - final status = monero.Wallet_status(wptr!); + final status = monero.Wallet_status(newWptr); if (status != 0) { throw WalletRestoreFromKeysException( - message: monero.Wallet_errorString(wptr!)); + message: monero.Wallet_errorString(newWptr)); } + wptr = newWptr; + openedWalletsByPath[path] = wptr!; } @@ -131,7 +135,7 @@ void restoreWalletFromSpendKeySync( // ); txhistory = null; - wptr = monero.WalletManager_createDeterministicWalletFromSpendKey( + final newWptr = monero.WalletManager_createDeterministicWalletFromSpendKey( wmPtr, path: path, password: password, @@ -141,14 +145,16 @@ void restoreWalletFromSpendKeySync( restoreHeight: restoreHeight, ); - final status = monero.Wallet_status(wptr!); + final status = monero.Wallet_status(newWptr); if (status != 0) { - final err = monero.Wallet_errorString(wptr!); + final err = monero.Wallet_errorString(newWptr); print("err: $err"); throw WalletRestoreFromKeysException(message: err); } + wptr = newWptr; + monero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed); storeSync(); @@ -206,15 +212,16 @@ void loadWallet( }); } txhistory = null; - wptr = monero.WalletManager_openWallet(wmPtr, + final newWptr = monero.WalletManager_openWallet(wmPtr, path: path, password: password); _lastOpenedWallet = path; - final status = monero.Wallet_status(wptr!); + final status = monero.Wallet_status(newWptr); if (status != 0) { - final err = monero.Wallet_errorString(wptr!); + final err = monero.Wallet_errorString(newWptr); print(err); throw WalletOpeningException(message: err); } + wptr = newWptr; openedWalletsByPath[path] = wptr!; } } diff --git a/cw_wownero/lib/api/wallet_manager.dart b/cw_wownero/lib/api/wallet_manager.dart index 839dea277..4c3b67217 100644 --- a/cw_wownero/lib/api/wallet_manager.dart +++ b/cw_wownero/lib/api/wallet_manager.dart @@ -32,13 +32,14 @@ void createWalletSync( required String language, int nettype = 0}) { txhistory = null; - wptr = wownero.WalletManager_createWallet(wmPtr, + final newWptr = wownero.WalletManager_createWallet(wmPtr, path: path, password: password, language: language, networkType: 0); - final status = wownero.Wallet_status(wptr!); + final status = wownero.Wallet_status(newWptr); if (status != 0) { - throw WalletCreationException(message: wownero.Wallet_errorString(wptr!)); + throw WalletCreationException(message: wownero.Wallet_errorString(newWptr)); } + wptr = newWptr; wownero.Wallet_store(wptr!, path: path); openedWalletsByPath[path] = wptr!; @@ -57,9 +58,10 @@ void restoreWalletFromSeedSync( required String seed, int nettype = 0, int restoreHeight = 0}) { + var newWptr; if (seed.split(" ").length == 14) { txhistory = null; - wptr = wownero.WOWNERO_deprecated_restore14WordSeed( + newWptr = wownero.WOWNERO_deprecated_restore14WordSeed( path: path, password: password, language: seed, // I KNOW - this is supposed to be called seed @@ -71,7 +73,7 @@ void restoreWalletFromSeedSync( ); } else { txhistory = null; - wptr = wownero.WalletManager_recoveryWallet( + newWptr = wownero.WalletManager_recoveryWallet( wmPtr, path: path, password: password, @@ -82,13 +84,14 @@ void restoreWalletFromSeedSync( ); } - final status = wownero.Wallet_status(wptr!); + final status = wownero.Wallet_status(newWptr); if (status != 0) { - final error = wownero.Wallet_errorString(wptr!); + final error = wownero.Wallet_errorString(newWptr); throw WalletRestoreFromSeedException(message: error); } + wptr = newWptr; wownero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.passphrase", value: passphrase); openedWalletsByPath[path] = wptr!; @@ -104,7 +107,7 @@ void restoreWalletFromKeysSync( int nettype = 0, int restoreHeight = 0}) { txhistory = null; - wptr = wownero.WalletManager_createWalletFromKeys( + final newWptr = wownero.WalletManager_createWalletFromKeys( wmPtr, path: path, password: password, @@ -115,12 +118,14 @@ void restoreWalletFromKeysSync( nettype: 0, ); - final status = wownero.Wallet_status(wptr!); + final status = wownero.Wallet_status(newWptr); if (status != 0) { throw WalletRestoreFromKeysException( - message: wownero.Wallet_errorString(wptr!)); + message: wownero.Wallet_errorString(newWptr)); } + wptr = newWptr; + openedWalletsByPath[path] = wptr!; } @@ -145,7 +150,7 @@ void restoreWalletFromSpendKeySync( // ); txhistory = null; - wptr = wownero.WalletManager_createDeterministicWalletFromSpendKey( + final newWptr = wownero.WalletManager_createDeterministicWalletFromSpendKey( wmPtr, path: path, password: password, @@ -155,14 +160,16 @@ void restoreWalletFromSpendKeySync( restoreHeight: restoreHeight, ); - final status = wownero.Wallet_status(wptr!); + final status = wownero.Wallet_status(newWptr); if (status != 0) { - final err = wownero.Wallet_errorString(wptr!); + final err = wownero.Wallet_errorString(newWptr); print("err: $err"); throw WalletRestoreFromKeysException(message: err); } + wptr = newWptr; + wownero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed); storeSync(); @@ -220,15 +227,16 @@ void loadWallet( }); } txhistory = null; - wptr = wownero.WalletManager_openWallet(wmPtr, + final newWptr = wownero.WalletManager_openWallet(wmPtr, path: path, password: password); _lastOpenedWallet = path; - final status = wownero.Wallet_status(wptr!); + final status = wownero.Wallet_status(newWptr); if (status != 0) { - final err = wownero.Wallet_errorString(wptr!); + final err = wownero.Wallet_errorString(newWptr); print(err); throw WalletOpeningException(message: err); } + wptr = newWptr; openedWalletsByPath[path] = wptr!; } } diff --git a/lib/view_model/wallet_keys_view_model.dart b/lib/view_model/wallet_keys_view_model.dart index 9018311ee..04fe3951c 100644 --- a/lib/view_model/wallet_keys_view_model.dart +++ b/lib/view_model/wallet_keys_view_model.dart @@ -83,8 +83,8 @@ abstract class WalletKeysViewModelBase with Store { StandartListItem( title: S.current.view_key_private, value: keys['privateViewKey']!), - StandartListItem( - title: S.current.wallet_seed, value: _appStore.wallet!.seed!), + if (_appStore.wallet!.seed!.isNotEmpty) + StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!), ]); if (_appStore.wallet?.seed != null && @@ -129,8 +129,8 @@ abstract class WalletKeysViewModelBase with Store { StandartListItem( title: S.current.view_key_private, value: keys['privateViewKey']!), - StandartListItem( - title: S.current.wallet_seed, value: _appStore.wallet!.seed!), + if (_appStore.wallet!.seed!.isNotEmpty) + StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!), ]); } @@ -153,8 +153,8 @@ abstract class WalletKeysViewModelBase with Store { StandartListItem( title: S.current.view_key_private, value: keys['privateViewKey']!), - StandartListItem( - title: S.current.wallet_seed, value: _appStore.wallet!.seed!), + if (_appStore.wallet!.seed!.isNotEmpty) + StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!), ]); if (_appStore.wallet?.seed != null &&