Improve how wallets are renamed. (#3352)

* Improve how wallets are renamed. affected wallets (Electrum-like) (BTC, LTC, BCH, Doge) * more improvements also added Solana, Tron, EVM

Omar Hatem committed Jul 12, 2026 at 04:15 UTC 00088502edfd415619b9f533b5d676484e88ec08
16 files changed +108 -280
cw_bitcoin/lib/bitcoin_wallet_service.dart
-26
@@ -8,7 +8,6 @@ import 'package:cw_core/encryption_file_utils.dart';
8 import 'package:cw_core/payjoin_session.dart';
9 import 'package:cw_core/unspent_coins_info.dart';
10 import 'package:cw_core/utils/zpub.dart';
11 -import 'package:cw_core/wallet_base.dart';
11 import 'package:cw_core/wallet_service.dart';
12 import 'package:cw_bitcoin/bitcoin_wallet.dart';
13 import 'package:cw_core/pathForWallet.dart';
@@ -130,31 +129,6 @@ class BitcoinWalletService extends WalletService<
129 }
130 }
131
133 - @override
134 - Future<void> rename(String currentName, String password, String newName) async {
135 - final currentWalletInfo = await WalletInfo.get(currentName, getType());
136 - if (currentWalletInfo == null) {
137 - throw Exception('Wallet not found');
138 - }
139 - final currentWallet = await BitcoinWalletBase.open(
140 - password: password,
141 - name: currentName,
142 - walletInfo: currentWalletInfo,
143 - unspentCoinsInfo: unspentCoinsInfoSource,
144 - payjoinBox: payjoinSessionSource,
145 - encryptionFileUtils: encryptionFileUtilsFor(isDirect),
146 - );
147 -
148 - await currentWallet.renameWalletFiles(newName);
149 - await saveBackup(newName);
150 -
151 - final newWalletInfo = currentWalletInfo;
152 - newWalletInfo.id = WalletBase.idFor(newName, getType());
153 - newWalletInfo.name = newName;
154 -
155 - await newWalletInfo.save();
156 - }
157 -
132 @override
133 Future<BitcoinWallet> restoreFromHardwareWallet(BitcoinRestoreWalletFromHardware credentials,
134 {bool? isTestnet}) async {
cw_bitcoin/lib/electrum_wallet.dart
-33
@@ -1,6 +1,5 @@
1 import 'dart:async';
2 import 'dart:convert';
3 -import 'dart:io';
3 import 'dart:isolate';
4
5 import 'package:bitcoin_base/bitcoin_base.dart';
@@ -38,7 +37,6 @@ import 'package:cw_core/get_height_by_date.dart';
37 import 'package:cw_core/hardware/hardware_wallet_service.dart';
38 import 'package:cw_core/node.dart';
39 import 'package:cw_core/output_info.dart';
41 -import 'package:cw_core/pathForWallet.dart';
40 import 'package:cw_core/pending_transaction.dart';
41 import 'package:cw_core/root_dir.dart';
42 import 'package:cw_core/sync_status.dart';
@@ -1736,37 +1734,6 @@ abstract class ElectrumWalletBase
1734 await transactionHistory.save();
1735 }
1736
1739 - @override
1740 - Future<void> renameWalletFiles(String newWalletName) async {
1741 - final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
1742 - final currentWalletFile = File(currentWalletPath);
1743 -
1744 - final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
1745 - final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
1746 -
1747 - // Copies current wallet files into new wallet name's dir and files
1748 - if (currentWalletFile.existsSync()) {
1749 - final newWalletPath = await pathForWallet(name: newWalletName, type: type);
1750 - await currentWalletFile.copy(newWalletPath);
1751 - }
1752 - if (currentTransactionsFile.existsSync()) {
1753 - final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
1754 - await currentTransactionsFile.copy('$newDirPath/$transactionsHistoryFileName');
1755 - }
1756 -
1757 - // Delete old name's dir and files
1758 - final dir = Directory(currentDirPath);
1759 - for (var attempt = 0; attempt < 3; attempt++) {
1760 - try {
1761 - await dir.delete(recursive: true);
1762 - break;
1763 - } on FileSystemException {
1764 - if (attempt == 2) rethrow;
1765 - await Future<void>.delayed(const Duration(milliseconds: 200));
1766 - }
1767 - }
1768 - }
1769 -
1737 @override
1738 Future<void> changePassword(String password) async {
1739 _password = password;
cw_bitcoin/lib/litecoin_wallet.dart
+14 -11
@@ -497,22 +497,25 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
497 mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(boxName);
498 }
499
500 - @override
501 - Future<void> renameWalletFiles(String newWalletName) async {
502 - // rename the hive box:
503 - final oldBoxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
504 - final newBoxName = "${newWalletName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
500 + static Future<void> copyMwebBox({
501 + required String fromName,
502 + required String toName,
503 + }) async {
504 + final oldBoxName = "${fromName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
505 + final newBoxName = "${toName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
506 + if (oldBoxName == newBoxName) return;
507
508 final oldBox = await CakeHive.openBox<MwebUtxo>(oldBoxName);
507 - mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
509 + final newBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
510 for (final key in oldBox.keys) {
509 - final value = oldBox.get(key);
510 - await oldBox.delete(key);
511 - await mwebUtxosBox.put(key, value!);
511 + await newBox.put(key, oldBox.get(key)!);
512 }
513 - oldBox.deleteFromDisk();
513 + }
514
515 - await super.renameWalletFiles(newWalletName);
515 + static Future<void> deleteMwebBox(String name) async {
516 + final boxName = "${name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
517 + final box = await CakeHive.openBox<MwebUtxo>(boxName);
518 + await box.deleteFromDisk();
519 }
520
521 @action
cw_bitcoin/lib/litecoin_wallet_service.dart
+4 -21
@@ -12,8 +12,6 @@ import 'package:cw_core/wallet_service.dart';
12 import 'package:cw_core/pathForWallet.dart';
13 import 'package:cw_core/wallet_type.dart';
14 import 'package:cw_core/wallet_info.dart';
15 -import 'package:cw_core/wallet_base.dart';
16 -import 'package:collection/collection.dart';
15 import 'package:bip39/bip39.dart' as bip39;
16 import 'package:path_provider/path_provider.dart';
17
@@ -139,26 +137,11 @@ class LitecoinWalletService extends WalletService<
137
138 @override
139 Future<void> rename(String currentName, String password, String newName) async {
142 - final currentWalletInfo = await WalletInfo.get(currentName, getType());
143 - if (currentWalletInfo == null) {
144 - throw Exception('Wallet not found');
145 - }
146 - final currentWallet = await LitecoinWalletBase.open(
147 - password: password,
148 - name: currentName,
149 - walletInfo: currentWalletInfo,
150 - unspentCoinsInfo: unspentCoinsInfoSource,
151 - encryptionFileUtils: encryptionFileUtilsFor(isDirect),
152 - );
153 -
154 - await currentWallet.renameWalletFiles(newName);
155 - await saveBackup(newName);
156 -
157 - final newWalletInfo = currentWalletInfo;
158 - newWalletInfo.id = WalletBase.idFor(newName, getType());
159 - newWalletInfo.name = newName;
140 + if (currentName == newName) return;
141
161 - await newWalletInfo.save();
142 + await LitecoinWalletBase.copyMwebBox(fromName: currentName, toName: newName);
143 + await super.rename(currentName, password, newName);
144 + await LitecoinWalletBase.deleteMwebBox(currentName);
145 }
146
147 @override
cw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dart
-25
@@ -1,13 +1,11 @@
1 import 'dart:io';
2
3 import 'package:bip39/bip39.dart';
4 -import 'package:collection/collection.dart';
4 import 'package:cw_bitcoin/bitcoin_mnemonics_bip39.dart';
5 import 'package:cw_bitcoin_cash/cw_bitcoin_cash.dart';
6 import 'package:cw_core/encryption_file_utils.dart';
7 import 'package:cw_core/pathForWallet.dart';
8 import 'package:cw_core/unspent_coins_info.dart';
10 -import 'package:cw_core/wallet_base.dart';
9 import 'package:cw_core/wallet_info.dart';
10 import 'package:cw_core/wallet_service.dart';
11 import 'package:cw_core/wallet_type.dart';
@@ -99,29 +97,6 @@ class BitcoinCashWalletService extends WalletService<
97 }
98 }
99
102 - @override
103 - Future<void> rename(String currentName, String password, String newName) async {
104 - final currentWalletInfo = await WalletInfo.get(currentName, getType());
105 - if (currentWalletInfo == null) {
106 - throw Exception('Wallet not found');
107 - }
108 - final currentWallet = await BitcoinCashWalletBase.open(
109 - password: password,
110 - name: currentName,
111 - walletInfo: currentWalletInfo,
112 - unspentCoinsInfo: unspentCoinsInfoSource,
113 - encryptionFileUtils: encryptionFileUtilsFor(isDirect));
114 -
115 - await currentWallet.renameWalletFiles(newName);
116 - await saveBackup(newName);
117 -
118 - final newWalletInfo = currentWalletInfo;
119 - newWalletInfo.id = WalletBase.idFor(newName, getType());
120 - newWalletInfo.name = newName;
121 -
122 - await newWalletInfo.save();
123 - }
124 -
100 @override
101 Future<BitcoinCashWallet> restoreFromHardwareWallet(BitcoinCashNewWalletCredentials credentials) {
102 throw UnimplementedError(
cw_core/lib/pathForWallet.dart
+41
@@ -1,6 +1,7 @@
1 import 'dart:io';
2 import 'package:cw_core/root_dir.dart';
3 import 'package:cw_core/wallet_type.dart';
4 +import 'package:path/path.dart' as p;
5
6 Future<String> pathForWalletTypeDir({required WalletType type}) async {
7 final root = await getAppDir();
@@ -36,3 +37,43 @@ Future<String> outdatedAndroidPathForWalletDir({required String name}) async {
37
38 return pathDir;
39 }
40 +
41 +Future<void> copyWalletFilesTo({
42 + required String fromName,
43 + required String toName,
44 + required WalletType type,
45 +}) async {
46 + if (fromName == toName) return;
47 +
48 + final typeRoot = await pathForWalletTypeDir(type: type);
49 + final sourceDir = Directory(p.join(typeRoot, fromName));
50 + if (!sourceDir.existsSync()) {
51 + throw "Source wallet not found: $fromName $type";
52 + }
53 +
54 + if (Directory(p.join(typeRoot, toName)).existsSync()) {
55 + throw Exception('Cannot rename wallet: "$toName" already exists');
56 + }
57 +
58 + final destinationDir = Directory(p.join(typeRoot, toName));
59 + await _copyDirectory(sourceDir, destinationDir);
60 +
61 + for (final suffix in const ['', '.keys', '.keys.backup']) {
62 + final file = File(p.join(destinationDir.path, '$fromName$suffix'));
63 + if (file.existsSync()) {
64 + await file.rename(p.join(destinationDir.path, '$toName$suffix'));
65 + }
66 + }
67 +}
68 +
69 +Future<void> _copyDirectory(Directory source, Directory destination) async {
70 + await destination.create(recursive: true);
71 + await for (final entity in source.list(followLinks: false)) {
72 + final name = p.basename(entity.path);
73 + if (entity is File) {
74 + await entity.copy(p.join(destination.path, name));
75 + } else if (entity is Directory) {
76 + await _copyDirectory(entity, Directory(p.join(destination.path, name)));
77 + }
78 + }
79 +}
cw_core/lib/wallet_base.dart
+3 -1
@@ -12,6 +12,7 @@ import 'package:cw_core/crypto_currency.dart';
12 import 'package:cw_core/sync_status.dart';
13 import 'package:cw_core/node.dart';
14 import 'package:cw_core/wallet_type.dart';
15 +import 'package:cw_core/pathForWallet.dart';
16
17 abstract class WalletBase<BalanceType extends Balance, HistoryType extends TransactionHistoryBase,
18 TransactionType extends TransactionInfo> {
@@ -115,7 +116,8 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
116
117 void setExceptionHandler(void Function(FlutterErrorDetails) onError) => null;
118
118 - Future<void> renameWalletFiles(String newWalletName);
119 + Future<void> renameWalletFiles(String newWalletName) =>
120 + copyWalletFilesTo(fromName: walletInfo.name, toName: newWalletName, type: type);
121
122 Future<String> signMessage(String message, {String? address = null});
123
cw_core/lib/wallet_service.dart
+27 -1
@@ -3,9 +3,12 @@ import 'dart:io';
3
4 import 'package:cw_core/pathForWallet.dart';
5 import 'package:cw_core/utils/file.dart';
6 +import 'package:cw_core/utils/print_verbose.dart';
7 import 'package:cw_core/wallet_base.dart';
8 import 'package:cw_core/wallet_credentials.dart';
9 +import 'package:cw_core/wallet_info.dart';
10 import 'package:cw_core/wallet_type.dart';
11 +import 'package:path/path.dart' as p;
12
13 abstract class WalletService<N extends WalletCredentials, RFS extends WalletCredentials,
14 RFK extends WalletCredentials, RFH extends WalletCredentials> {
@@ -25,7 +28,30 @@ abstract class WalletService<N extends WalletCredentials, RFS extends WalletCred
28
29 Future<void> remove(String wallet);
30
28 - Future<void> rename(String currentName, String password, String newName);
31 + Future<void> rename(String currentName, String password, String newName) async {
32 + if (currentName == newName) return;
33 +
34 + final currentWalletInfo = await WalletInfo.get(currentName, getType());
35 + if (currentWalletInfo == null) {
36 + throw Exception('Wallet not found');
37 + }
38 +
39 + await copyWalletFilesTo(fromName: currentName, toName: newName, type: getType());
40 + await saveBackup(newName);
41 +
42 + currentWalletInfo.id = WalletBase.idFor(newName, getType());
43 + currentWalletInfo.name = newName;
44 + await currentWalletInfo.save();
45 +
46 + final oldDir = Directory(p.join(await pathForWalletTypeDir(type: getType()), currentName));
47 + if (oldDir.existsSync()) {
48 + try {
49 + await oldDir.delete(recursive: true);
50 + } catch (e) {
51 + printV('rename: failed to delete old wallet dir "$currentName": $e');
52 + }
53 + }
54 + }
55
56 Future<void> restoreWalletFilesFromBackup(String name) async {
57 final backupWalletDirPath = await pathForWalletDir(name: "$name.backup", type: getType());
cw_dogecoin/lib/src/dogecoin_wallet_service.dart
-25
@@ -1,12 +1,10 @@
1 import 'dart:io';
2
3 import 'package:bip39/bip39.dart';
4 -import 'package:collection/collection.dart';
4 import 'package:cw_bitcoin/bitcoin_mnemonics_bip39.dart';
5 import 'package:cw_core/encryption_file_utils.dart';
6 import 'package:cw_core/pathForWallet.dart';
7 import 'package:cw_core/unspent_coins_info.dart';
9 -import 'package:cw_core/wallet_base.dart';
8 import 'package:cw_core/wallet_info.dart';
9 import 'package:cw_core/wallet_service.dart';
10 import 'package:cw_core/wallet_type.dart';
@@ -100,29 +98,6 @@ class DogeCoinWalletService extends WalletService<
98 }
99 }
100
103 - @override
104 - Future<void> rename(String currentName, String password, String newName) async {
105 - final currentWalletInfo = await WalletInfo.get(currentName, getType());
106 - if (currentWalletInfo == null) {
107 - throw Exception('Wallet not found');
108 - }
109 - final currentWallet = await DogeCoinWalletBase.open(
110 - password: password,
111 - name: currentName,
112 - walletInfo: currentWalletInfo,
113 - unspentCoinsInfo: unspentCoinsInfoSource,
114 - encryptionFileUtils: encryptionFileUtilsFor(isDirect));
115 -
116 - await currentWallet.renameWalletFiles(newName);
117 - await saveBackup(newName);
118 -
119 - final newWalletInfo = currentWalletInfo;
120 - newWalletInfo.id = WalletBase.idFor(newName, getType());
121 - newWalletInfo.name = newName;
122 -
123 - await newWalletInfo.save();
124 - }
125 -
101 @override
102 Future<DogeCoinWallet> restoreFromHardwareWallet(DogeCoinNewWalletCredentials credentials) {
103 throw UnimplementedError(
cw_evm/lib/evm_chain_wallet.dart
-25
@@ -1,6 +1,5 @@
1 import 'dart:async';
2 import 'dart:convert';
3 -import 'dart:io';
3 import 'dart:typed_data';
4
5 import 'package:bip32/bip32.dart' as bip32;
@@ -1703,30 +1702,6 @@ abstract class EVMChainWalletBase
1702 );
1703 }
1704
1706 - @override
1707 - Future<void> renameWalletFiles(String newWalletName) async {
1708 - final transactionHistoryFileNameForWallet = getTransactionHistoryFileName();
1709 -
1710 - final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
1711 - final currentWalletFile = File(currentWalletPath);
1712 -
1713 - final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
1714 - final currentTransactionsFile = File('$currentDirPath/$transactionHistoryFileNameForWallet');
1715 -
1716 - // Copies current wallet files into new wallet name's dir and files
1717 - if (currentWalletFile.existsSync()) {
1718 - final newWalletPath = await pathForWallet(name: newWalletName, type: type);
1719 - await currentWalletFile.copy(newWalletPath);
1720 - }
1721 - if (currentTransactionsFile.existsSync()) {
1722 - final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
1723 - await currentTransactionsFile.copy('$newDirPath/$transactionHistoryFileNameForWallet');
1724 - }
1725 -
1726 - // Delete old name's dir and files
1727 - await Directory(currentDirPath).delete(recursive: true);
1728 - }
1729 -
1705 void _setTransactionUpdateTimer() {
1706 if (_transactionsUpdateTimer?.isActive ?? false) {
1707 _transactionsUpdateTimer!.cancel();
cw_evm/lib/evm_chain_wallet_service.dart
+18 -15
@@ -3,10 +3,12 @@ import 'dart:io';
3 import 'package:bip39/bip39.dart' as bip39;
4 import 'package:cw_core/encryption_file_utils.dart';
5 import 'package:cw_core/pathForWallet.dart';
6 +import 'package:cw_core/utils/print_verbose.dart';
7 import 'package:cw_core/wallet_base.dart';
8 import 'package:cw_core/wallet_info.dart';
9 import 'package:cw_core/wallet_service.dart';
10 import 'package:cw_core/wallet_type.dart';
11 +import 'package:path/path.dart' as p;
12 import 'package:cw_evm/clients/evm_chain_client.dart';
13 import 'package:cw_evm/evm_chain_client_factory.dart';
14 import 'package:cw_evm/evm_chain_registry.dart';
@@ -166,29 +168,30 @@ class EVMChainWalletService extends WalletService<
168
169 @override
170 Future<void> rename(String currentName, String password, String newName) async {
171 + if (currentName == newName) return;
172 +
173 final currentWalletInfo = await _findWalletByName(currentName);
174 if (currentWalletInfo == null) {
175 throw Exception('Wallet not found');
176 }
177
174 - final currentWallet = await _openWalletInstance(
175 - password: password,
176 - name: currentName,
177 - walletInfo: currentWalletInfo,
178 - encryptionFileUtils: encryptionFileUtilsFor(isDirect),
179 - );
178 + final type = currentWalletInfo.type;
179
181 - await currentWallet.renameWalletFiles(newName);
180 + await copyWalletFilesTo(fromName: currentName, toName: newName, type: type);
181 + await saveBackup(newName, walletInfo: currentWalletInfo);
182
183 - // Update walletInfo with new name before saving backup
184 - final newWalletInfo = currentWalletInfo;
185 - newWalletInfo.id = WalletBase.idFor(newName, currentWalletInfo.type);
186 - newWalletInfo.name = newName;
183 + currentWalletInfo.id = WalletBase.idFor(newName, type);
184 + currentWalletInfo.name = newName;
185 + await currentWalletInfo.save();
186
188 - // Pass walletInfo to saveBackup to avoid lookup (since WalletInfo not saved yet)
189 - await saveBackup(newName, walletInfo: newWalletInfo);
190 -
191 - await newWalletInfo.save();
187 + final oldDir = Directory(p.join(await pathForWalletTypeDir(type: type), currentName));
188 + if (oldDir.existsSync()) {
189 + try {
190 + await oldDir.delete(recursive: true);
191 + } catch (e) {
192 + printV('rename: failed to delete old wallet dir "$currentName": $e');
193 + }
194 + }
195 }
196
197 @override
cw_evm/pubspec.yaml
+1
@@ -21,6 +21,7 @@ dependencies:
21 http: ^1.1.0
22 hive: ^2.2.3
23 collection: ^1.17.1
24 + path: ^1.8.0
25 shared_preferences: ^2.0.15
26 mobx: ^2.0.7+4
27 cw_core:
cw_solana/lib/solana_wallet.dart
-23
@@ -1,6 +1,5 @@
1 import 'dart:async';
2 import 'dart:convert';
3 -import 'dart:io';
3
4 import 'package:cw_core/amount/money.dart';
5 import 'package:cw_core/cake_hive.dart';
@@ -833,28 +832,6 @@ abstract class SolanaWalletBase
832 }
833 }
834
836 - @override
837 - Future<void> renameWalletFiles(String newWalletName) async {
838 - final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
839 - final currentWalletFile = File(currentWalletPath);
840 -
841 - final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
842 - final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
843 -
844 - // Copies current wallet files into new wallet name's dir and files
845 - if (currentWalletFile.existsSync()) {
846 - final newWalletPath = await pathForWallet(name: newWalletName, type: type);
847 - await currentWalletFile.copy(newWalletPath);
848 - }
849 - if (currentTransactionsFile.existsSync()) {
850 - final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
851 - await currentTransactionsFile.copy('$newDirPath/$transactionsHistoryFileName');
852 - }
853 -
854 - // Delete old name's dir and files
855 - await Directory(currentDirPath).delete(recursive: true);
856 - }
857 -
835 void _setTransactionUpdateTimer() {
836 if (_transactionsUpdateTimer?.isActive ?? false) {
837 _transactionsUpdateTimer!.cancel();
cw_solana/lib/solana_wallet_service.dart
-25
@@ -1,7 +1,6 @@
1 import 'dart:io';
2
3 import 'package:bip39/bip39.dart' as bip39;
4 -import 'package:collection/collection.dart';
4 import 'package:cw_core/encryption_file_utils.dart';
5 import 'package:cw_core/balance.dart';
6 import 'package:cw_core/pathForWallet.dart';
@@ -14,7 +13,6 @@ import 'package:cw_core/wallet_type.dart';
13 import 'package:cw_solana/solana_mnemonics.dart';
14 import 'package:cw_solana/solana_wallet.dart';
15 import 'package:cw_solana/solana_wallet_creation_credentials.dart';
17 -import 'package:hive/hive.dart';
16
17 class SolanaWalletService extends WalletService<SolanaNewWalletCredentials,
18 SolanaRestoreWalletFromSeedCredentials, SolanaRestoreWalletFromPrivateKey, SolanaNewWalletCredentials> {
@@ -138,29 +136,6 @@ class SolanaWalletService extends WalletService<SolanaNewWalletCredentials,
136 return wallet;
137 }
138
141 - @override
142 - Future<void> rename(String currentName, String password, String newName) async {
143 - final currentWalletInfo = await WalletInfo.get(currentName, getType());
144 - if (currentWalletInfo == null) {
145 - throw Exception('Wallet not found');
146 - }
147 - final currentWallet = await SolanaWalletBase.open(
148 - password: password,
149 - name: currentName,
150 - walletInfo: currentWalletInfo,
151 - encryptionFileUtils: encryptionFileUtilsFor(isDirect),
152 - );
153 -
154 - await currentWallet.renameWalletFiles(newName);
155 - await saveBackup(newName);
156 -
157 - final newWalletInfo = currentWalletInfo;
158 - newWalletInfo.id = WalletBase.idFor(newName, getType());
159 - newWalletInfo.name = newName;
160 -
161 - await newWalletInfo.save();
162 - }
163 -
139 @override
140 Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>> restoreFromHardwareWallet(SolanaNewWalletCredentials credentials) {
141 // TODO: implement restoreFromHardwareWallet
cw_tron/lib/tron_wallet.dart
-25
@@ -1,7 +1,6 @@
1 import 'dart:async';
2 import 'dart:convert';
3 import 'dart:developer';
4 -import 'dart:io';
4
5 import 'package:bip39/bip39.dart' as bip39;
6 import 'package:blockchain_utils/blockchain_utils.dart';
@@ -607,30 +606,6 @@ abstract class TronWalletBase
606 Future<TronToken?> getTronToken(String contractAddress) async =>
607 await _client.getTronToken(contractAddress, _tronAddress);
608
610 - @override
611 - Future<void> renameWalletFiles(String newWalletName) async {
612 - const transactionHistoryFileNameForWallet = 'tron_transactions.json';
613 -
614 - final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
615 - final currentWalletFile = File(currentWalletPath);
616 -
617 - final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
618 - final currentTransactionsFile = File('$currentDirPath/$transactionHistoryFileNameForWallet');
619 -
620 - // Copies current wallet files into new wallet name's dir and files
621 - if (currentWalletFile.existsSync()) {
622 - final newWalletPath = await pathForWallet(name: newWalletName, type: type);
623 - await currentWalletFile.copy(newWalletPath);
624 - }
625 - if (currentTransactionsFile.existsSync()) {
626 - final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
627 - await currentTransactionsFile.copy('$newDirPath/$transactionHistoryFileNameForWallet');
628 - }
629 -
630 - // Delete old name's dir and files
631 - await Directory(currentDirPath).delete(recursive: true);
632 - }
633 -
609 void _setTransactionUpdateTimer() {
610 if (_transactionsUpdateTimer?.isActive ?? false) {
611 _transactionsUpdateTimer!.cancel();
cw_tron/lib/tron_wallet_service.dart
-24
@@ -14,7 +14,6 @@ import 'package:cw_tron/tron_client.dart';
14 import 'package:cw_tron/tron_exception.dart';
15 import 'package:cw_tron/tron_wallet.dart';
16 import 'package:cw_tron/tron_wallet_creation_credentials.dart';
17 -import 'package:hive/hive.dart';
17
18 class TronWalletService extends WalletService<
19 TronNewWalletCredentials,
@@ -134,29 +133,6 @@ class TronWalletService extends WalletService<
133 return wallet;
134 }
135
137 - @override
138 - Future<void> rename(String currentName, String password, String newName) async {
139 - final currentWalletInfo = await WalletInfo.get(currentName, getType());
140 - if (currentWalletInfo == null) {
141 - throw Exception('Wallet not found');
142 - }
143 - final currentWallet = await TronWalletBase.open(
144 - password: password,
145 - name: currentName,
146 - walletInfo: currentWalletInfo,
147 - encryptionFileUtils: encryptionFileUtilsFor(isDirect),
148 - );
149 -
150 - await currentWallet.renameWalletFiles(newName);
151 - await saveBackup(newName);
152 -
153 - final newWalletInfo = currentWalletInfo;
154 - newWalletInfo.id = WalletBase.idFor(newName, getType());
155 - newWalletInfo.name = newName;
156 -
157 - await newWalletInfo.save();
158 - }
159 -
136 @override
137 Future<bool> isWalletExit(String name) async =>
138 File(await pathForWallet(name: name, type: getType())).existsSync();