@@ -440,10 +440,12 @@ class EpiccashWallet extends Bip39Wallet {
440440
441441 // ================= Private =================================================
442442
443- Future <String > _getConfig () async {
444- if (_epicNode == null ) {
445- await updateNode ();
446- }
443+ Future <bool > _hasConfig () async =>
444+ (await secureStorageInterface.read (key: '${walletId }_config' )) != null ;
445+
446+ Future <String > _buildConfig () async {
447+ _epicNode ?? = getCurrentNode ();
448+
447449 final NodeModel node = _epicNode! ;
448450 final String nodeAddress = node.host;
449451 final int port = node.port;
@@ -465,6 +467,7 @@ class EpiccashWallet extends Bip39Wallet {
465467 "" ,
466468 );
467469 final String stringConfig = jsonEncode (config);
470+
468471 return stringConfig;
469472 }
470473
@@ -743,21 +746,6 @@ class EpiccashWallet extends Bip39Wallet {
743746 await libEpic.startEpicboxListener (wallet: _wallet! );
744747 }
745748
746- // As opposed to fake config?
747- Future <String > _getRealConfig () async {
748- String ? config = await secureStorageInterface.read (
749- key: '${walletId }_config' ,
750- );
751- if (Platform .isIOS) {
752- final walletDir = await _currentWalletDirPath ();
753- final editConfig = jsonDecode (config as String );
754-
755- editConfig["wallet_dir" ] = walletDir;
756- config = jsonEncode (editConfig);
757- }
758- return config! ;
759- }
760-
761749 // TODO: make more robust estimate of date maybe using https://explorer.epic.tech/api-index
762750 int _calculateRestoreHeightFrom ({required DateTime date}) {
763751 final int secondsSinceEpoch = date.millisecondsSinceEpoch ~ / 1000 ;
@@ -835,23 +823,25 @@ class EpiccashWallet extends Bip39Wallet {
835823 @override
836824 Future <void > init ({bool ? isRestore}) async {
837825 if (isRestore != true ) {
838- final existingWalletConfig = await secureStorageInterface.read (
839- key: '${walletId }_config' ,
840- );
826+ final existingWalletConfig = await _hasConfig ();
841827
842828 // check if should create a new wallet
843- if (existingWalletConfig == null ) {
829+ if (! existingWalletConfig) {
844830 await updateNode ();
845831 final mnemonicString = await getMnemonic ();
846832
847833 final String password = generatePassword ();
848- final String stringConfig = await _getConfig ();
849834 final EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig ();
850835
836+ final String stringConfig = await _buildConfig ();
837+
838+ // no need to save the config, just a string flag to know we have a
839+ // wallet created
851840 await secureStorageInterface.write (
852841 key: '${walletId }_config' ,
853- value: stringConfig ,
842+ value: "true" ,
854843 );
844+
855845 await secureStorageInterface.write (
856846 key: '${walletId }_password' ,
857847 value: password,
@@ -907,7 +897,7 @@ class EpiccashWallet extends Bip39Wallet {
907897 final epicboxConfig = await getEpicBoxConfig ();
908898
909899 _wallet = await libEpic.openWallet (
910- config: existingWalletConfig ,
900+ config: await _buildConfig () ,
911901 password: password! ,
912902 epicboxConfig: epicboxConfig.toString (),
913903 ); // Spawns worker isolate
@@ -1098,7 +1088,6 @@ class EpiccashWallet extends Bip39Wallet {
10981088 isar: mainDB.isar,
10991089 );
11001090
1101- final stringConfig = await _getRealConfig ();
11021091 final password = await secureStorageInterface.read (
11031092 key: '${walletId }_password' ,
11041093 );
@@ -1118,7 +1107,7 @@ class EpiccashWallet extends Bip39Wallet {
11181107 }
11191108
11201109 _wallet = await libEpic.recoverWallet (
1121- config: stringConfig ,
1110+ config: await _buildConfig () ,
11221111 password: password! ,
11231112 mnemonic: await getMnemonic (),
11241113 name: info.walletId,
@@ -1132,12 +1121,13 @@ class EpiccashWallet extends Bip39Wallet {
11321121 await updateNode ();
11331122 final String password = generatePassword ();
11341123
1135- final String stringConfig = await _getConfig ();
11361124 final EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig ();
11371125
1126+ // no need to save the config, just a string flag to know we have a
1127+ // wallet created
11381128 await secureStorageInterface.write (
11391129 key: '${walletId }_config' ,
1140- value: stringConfig ,
1130+ value: "true" ,
11411131 );
11421132 await secureStorageInterface.write (
11431133 key: '${walletId }_password' ,
@@ -1156,7 +1146,7 @@ class EpiccashWallet extends Bip39Wallet {
11561146 }
11571147
11581148 _wallet = await libEpic.recoverWallet (
1159- config: stringConfig ,
1149+ config: await _buildConfig () ,
11601150 password: password,
11611151 mnemonic: await getMnemonic (),
11621152 name: info.walletId,
@@ -1560,13 +1550,7 @@ class EpiccashWallet extends Bip39Wallet {
15601550 Future <void > updateNode () async {
15611551 _epicNode = getCurrentNode ();
15621552
1563- // TODO: [prio=low] move this out of secure storage if secure storage not
1564- // needed
1565- final String stringConfig = await _getConfig ();
1566- await secureStorageInterface.write (
1567- key: '${walletId }_config' ,
1568- value: stringConfig,
1569- );
1553+ libEpic.updateConfig (wallet: _wallet! , config: await _buildConfig ());
15701554
15711555 // unawaited(refresh());
15721556 }
@@ -1598,7 +1582,7 @@ class EpiccashWallet extends Bip39Wallet {
15981582 @override
15991583 Future <void > updateChainHeight () async {
16001584 _hackedCheckTorNodePrefs ();
1601- final config = await _getRealConfig ();
1585+ final config = await _buildConfig ();
16021586 final latestHeight = await libEpic.getChainHeight (config: config);
16031587 await info.updateCachedChainHeight (
16041588 newHeight: latestHeight,
@@ -1678,19 +1662,7 @@ Future<String> deleteEpicWallet({
16781662 required EpiccashWallet wallet,
16791663 required SecureStorageInterface secureStore,
16801664}) async {
1681- String ? config = await secureStore.read (key: '${wallet .walletId }_config' );
1682- if (Platform .isIOS) {
1683- final Directory appDir = await StackFileSystem .applicationRootDirectory ();
1684-
1685- final path = "${appDir .path }/epiccash" ;
1686- final String name = wallet.walletId.trim ();
1687- final walletDir = '$path /$name ' ;
1688-
1689- final editConfig = jsonDecode (config as String );
1690-
1691- editConfig["wallet_dir" ] = walletDir;
1692- config = jsonEncode (editConfig);
1693- }
1665+ final config = await wallet._hasConfig () ? await wallet._buildConfig () : null ;
16941666
16951667 if (config == null ) {
16961668 return "Tried to delete non existent epic wallet file with"
0 commit comments