@@ -8,6 +8,7 @@ import 'package:cw_core/wallet_service.dart';
8
8
import 'package:cw_core/pathForWallet.dart' ;
9
9
import 'package:cw_core/wallet_info.dart' ;
10
10
import 'package:cw_core/wallet_type.dart' ;
11
+ import 'package:path/path.dart' ;
11
12
import 'package:hive/hive.dart' ;
12
13
import 'package:collection/collection.dart' ;
13
14
import 'package:cw_core/unspent_coins_info.dart' ;
@@ -57,9 +58,10 @@ class DecredWalletService extends WalletService<
57
58
@override
58
59
Future <DecredWallet > create (DecredNewWalletCredentials credentials, {bool ? isTestnet}) async {
59
60
await this .init ();
61
+ final dirPath = await pathForWalletDir (name: credentials.walletInfo! .name, type: getType ());
60
62
final config = {
61
63
"name" : credentials.walletInfo! .name,
62
- "datadir" : credentials.walletInfo ! . dirPath,
64
+ "datadir" : dirPath,
63
65
"pass" : credentials.password! ,
64
66
"net" : isTestnet == true ? testnet : mainnet,
65
67
"unsyncedaddrs" : true ,
@@ -74,6 +76,23 @@ class DecredWalletService extends WalletService<
74
76
return wallet;
75
77
}
76
78
79
+ void copyDirectorySync (Directory source, Directory destination) {
80
+ /// create destination folder if not exist
81
+ if (! destination.existsSync ()) {
82
+ destination.createSync (recursive: true );
83
+ }
84
+
85
+ /// get all files from source (recursive: false is important here)
86
+ source.listSync (recursive: false ).forEach ((entity) {
87
+ final newPath = destination.path + Platform .pathSeparator + basename (entity.path);
88
+ if (entity is File ) {
89
+ entity.copySync (newPath);
90
+ } else if (entity is Directory ) {
91
+ copyDirectorySync (entity, Directory (newPath));
92
+ }
93
+ });
94
+ }
95
+
77
96
@override
78
97
Future <DecredWallet > openWallet (String name, String password) async {
79
98
final walletInfo = walletInfoSource.values
@@ -84,14 +103,22 @@ class DecredWalletService extends WalletService<
84
103
: mainnet;
85
104
86
105
await this .init ();
87
- final walletDirExists = Directory (walletInfo.dirPath).existsSync ();
88
- if (! walletDirExists) {
89
- walletInfo.dirPath = await pathForWalletDir (name: name, type: getType ());
106
+
107
+ // Cake wallet version 4.27.0 and earlier gave a wallet dir that did not
108
+ // match the name. Move those to the correct place.
109
+ final dirPath = await pathForWalletDir (name: name, type: getType ());
110
+ if (walletInfo.dirPath != "" && walletInfo.dirPath != dirPath) {
111
+ final oldWalletDir = new Directory (walletInfo.dirPath);
112
+ final newWalletDir = new Directory (dirPath);
113
+ copyDirectorySync (oldWalletDir, newWalletDir);
114
+ await oldWalletDir.delete (recursive: true );
115
+ // Clear the path so this does not trigger again.
116
+ walletInfo.dirPath = "" ;
90
117
}
91
118
92
119
final config = {
93
- "name" : walletInfo. name,
94
- "datadir" : walletInfo. dirPath,
120
+ "name" : name,
121
+ "datadir" : dirPath,
95
122
"net" : network,
96
123
"unsyncedaddrs" : true ,
97
124
};
@@ -123,11 +150,9 @@ class DecredWalletService extends WalletService<
123
150
124
151
await currentWallet.renameWalletFiles (newName);
125
152
126
- final newDirPath = await pathForWalletDir (name: newName, type: getType ());
127
153
final newWalletInfo = currentWalletInfo;
128
154
newWalletInfo.id = WalletBase .idFor (newName, getType ());
129
155
newWalletInfo.name = newName;
130
- newWalletInfo.dirPath = newDirPath;
131
156
newWalletInfo.network = network;
132
157
133
158
await walletInfoSource.put (currentWalletInfo.key, newWalletInfo);
@@ -137,9 +162,10 @@ class DecredWalletService extends WalletService<
137
162
Future <DecredWallet > restoreFromSeed (DecredRestoreWalletFromSeedCredentials credentials,
138
163
{bool ? isTestnet}) async {
139
164
await this .init ();
165
+ final dirPath = await pathForWalletDir (name: credentials.walletInfo! .name, type: getType ());
140
166
final config = {
141
167
"name" : credentials.walletInfo! .name,
142
- "datadir" : credentials.walletInfo ! . dirPath,
168
+ "datadir" : dirPath,
143
169
"pass" : credentials.password! ,
144
170
"mnemonic" : credentials.mnemonic,
145
171
"net" : isTestnet == true ? testnet : mainnet,
@@ -161,9 +187,10 @@ class DecredWalletService extends WalletService<
161
187
Future <DecredWallet > restoreFromKeys (DecredRestoreWalletFromPubkeyCredentials credentials,
162
188
{bool ? isTestnet}) async {
163
189
await this .init ();
190
+ final dirPath = await pathForWalletDir (name: credentials.walletInfo! .name, type: getType ());
164
191
final config = {
165
192
"name" : credentials.walletInfo! .name,
166
- "datadir" : credentials.walletInfo ! . dirPath,
193
+ "datadir" : dirPath,
167
194
"pubkey" : credentials.pubkey,
168
195
"net" : isTestnet == true ? testnet : mainnet,
169
196
"unsyncedaddrs" : true ,
0 commit comments