Skip to content

Commit 9ee811c

Browse files
committed
dcr: Always fetch the current dir path.
On ios devices the path will change between updates breaking decred. Never save the path and always check to ensure it is up to date.
1 parent 4448adb commit 9ee811c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

cw_decred/lib/wallet.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'dart:io';
44
import 'package:cw_core/exceptions.dart';
55
import 'package:cw_core/transaction_direction.dart';
66
import 'package:cw_core/utils/print_verbose.dart';
7+
import 'package:cw_core/pathForWallet.dart';
8+
import 'package:cw_core/wallet_type.dart';
79
import 'package:cw_decred/amount_format.dart';
810
import 'package:cw_decred/pending_transaction.dart';
911
import 'package:cw_decred/transaction_credentials.dart';
@@ -306,9 +308,10 @@ abstract class DecredWalletBase
306308
persistantPeer = addr;
307309
await _libwallet.closeWallet(walletInfo.name);
308310
final network = isTestnet ? "testnet" : "mainnet";
311+
final dirPath = await pathForWalletDir(name: walletInfo.name, type: WalletType.decred);
309312
final config = {
310313
"name": walletInfo.name,
311-
"datadir": walletInfo.dirPath,
314+
"datadir": dirPath,
312315
"net": network,
313316
"unsyncedaddrs": true,
314317
};

cw_decred/lib/wallet_service.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ class DecredWalletService extends WalletService<
5757
@override
5858
Future<DecredWallet> create(DecredNewWalletCredentials credentials, {bool? isTestnet}) async {
5959
await this.init();
60+
final dirPath = await pathForWalletDir(name: credentials.walletInfo!.name, type: getType());
6061
final config = {
6162
"name": credentials.walletInfo!.name,
62-
"datadir": credentials.walletInfo!.dirPath,
63+
"datadir": dirPath,
6364
"pass": credentials.password!,
6465
"net": isTestnet == true ? testnet : mainnet,
6566
"unsyncedaddrs": true,
@@ -84,14 +85,11 @@ class DecredWalletService extends WalletService<
8485
: mainnet;
8586

8687
await this.init();
87-
final walletDirExists = Directory(walletInfo.dirPath).existsSync();
88-
if (!walletDirExists) {
89-
walletInfo.dirPath = await pathForWalletDir(name: name, type: getType());
90-
}
88+
final dirPath = await pathForWalletDir(name: name, type: getType());
9189

9290
final config = {
93-
"name": walletInfo.name,
94-
"datadir": walletInfo.dirPath,
91+
"name": name,
92+
"datadir": dirPath,
9593
"net": network,
9694
"unsyncedaddrs": true,
9795
};
@@ -123,11 +121,9 @@ class DecredWalletService extends WalletService<
123121

124122
await currentWallet.renameWalletFiles(newName);
125123

126-
final newDirPath = await pathForWalletDir(name: newName, type: getType());
127124
final newWalletInfo = currentWalletInfo;
128125
newWalletInfo.id = WalletBase.idFor(newName, getType());
129126
newWalletInfo.name = newName;
130-
newWalletInfo.dirPath = newDirPath;
131127
newWalletInfo.network = network;
132128

133129
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
@@ -137,9 +133,10 @@ class DecredWalletService extends WalletService<
137133
Future<DecredWallet> restoreFromSeed(DecredRestoreWalletFromSeedCredentials credentials,
138134
{bool? isTestnet}) async {
139135
await this.init();
136+
final dirPath = await pathForWalletDir(name: credentials.walletInfo!.name, type: getType());
140137
final config = {
141138
"name": credentials.walletInfo!.name,
142-
"datadir": credentials.walletInfo!.dirPath,
139+
"datadir": dirPath,
143140
"pass": credentials.password!,
144141
"mnemonic": credentials.mnemonic,
145142
"net": isTestnet == true ? testnet : mainnet,
@@ -161,9 +158,10 @@ class DecredWalletService extends WalletService<
161158
Future<DecredWallet> restoreFromKeys(DecredRestoreWalletFromPubkeyCredentials credentials,
162159
{bool? isTestnet}) async {
163160
await this.init();
161+
final dirPath = await pathForWalletDir(name: credentials.walletInfo!.name, type: getType());
164162
final config = {
165163
"name": credentials.walletInfo!.name,
166-
"datadir": credentials.walletInfo!.dirPath,
164+
"datadir": dirPath,
167165
"pubkey": credentials.pubkey,
168166
"net": isTestnet == true ? testnet : mainnet,
169167
"unsyncedaddrs": true,

0 commit comments

Comments
 (0)