Improve how wallets are renamed. (#3352)
What changed, and why it matters
This commit refactors how Cake Wallet renames cryptocurrency wallets. Previously, each wallet type had its own rename code that opened the wallet, copied specific files, and deleted the old directory. The new code centralizes the file-copying logic and makes the process more consistent across Bitcoin-like coins, Litecoin, Bitcoin Cash, Dogecoin, EVM chains, Solana, and Tron. The change appears to be a code-quality and reliability improvement rather than an obvious security fix, but it does address some risky patterns in the old rename implementation—such as deleting the old wallet directory before confirming the new one is valid, and not checking whether the destination wallet already exists.
Treat this as a defensive hardening change. Review the new copyWalletFilesTo and base rename() paths for edge cases: insufficient disk space during recursive copy, partial copy followed by destination directory cleanup, concurrent renames, and permissions errors on the old directory deletion. Ensure automated tests cover rename with wallets containing extra files, identical names, and destination-name collisions. Consider whether the destination-exists check should also apply to the EVM custom rename path, which currently duplicates the logic.
Security signals we found
Old rename implementations deleted the source wallet directory after copying only a few known files, risking data loss if new files were present or copy failed partway.
New centralized copyWalletFilesTo recursively copies the entire wallet directory and renames the key files, reducing the chance of orphaned wallet data.
New code checks whether the destination wallet already exists before copying, preventing accidental or malicious overwrites of an existing wallet.
Old code did not short-circuit on identical current/new names; new code does, avoiding unnecessary I/O and potential self-deletion bugs.
Old EVM/Solana/Tron renameWalletFiles did not appear to retry or gracefully handle deletion failures; new base implementation logs deletion failures instead of crashing.
No explicit security framing by the vendor; commit title and message describe the change as an 'improvement' to wallet renaming.
Evidence from the diff
The patch removes duplicated per-wallet-type rename() and renameWalletFiles() implementations and moves the core logic into cw_core/pathForWallet.dart (copyWalletFilesTo) and cw_core/wallet_service.dart (base rename()). The new flow: (1) short-circuit if names are identical, (2) verify the source wallet directory exists, (3) throw if the destination already exists, (4) recursively copy the wallet directory, (5) rename files with suffixes ‘’, ‘.keys’, ‘.keys.backup’ to the new wallet name, (6) save a backup, (7) update WalletInfo id/name, (8) delete the old directory. Litecoin gets special handling for its MwebUtxo Hive box. EVM keeps a slightly customized rename because it looks up WalletInfo by name differently. The old code opened the wallet instance before renaming and only copied a hardcoded list of files, which could miss data or leave partial state if deletion failed.
Changed components
cw_core/lib/pathForWallet.dartcw_core/lib/wallet_service.dartcw_core/lib/wallet_base.dartcw_bitcoin/lib/bitcoin_wallet_service.dartcw_bitcoin/lib/electrum_wallet.dartcw_bitcoin/lib/litecoin_wallet.dartcw_bitcoin/lib/litecoin_wallet_service.dartcw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dartcw_dogecoin/lib/src/dogecoin_wallet_service.dartcw_evm/lib/evm_chain_wallet.dartcw_evm/lib/evm_chain_wallet_service.dartcw_solana/lib/solana_wallet.dartcw_solana/lib/solana_wallet_service.dartcw_tron/lib/tron_wallet.dartcw_tron/lib/tron_wallet_service.dartInspect captured patch +108 / −280
diff --git a/cw_bitcoin/lib/bitcoin_wallet_service.dart b/cw_bitcoin/lib/bitcoin_wallet_service.dart
index 6163a8a8..8a034d8c 100644
--- a/cw_bitcoin/lib/bitcoin_wallet_service.dart
+++ b/cw_bitcoin/lib/bitcoin_wallet_service.dart
@@ -8,7 +8,6 @@ import 'package:cw_core/encryption_file_utils.dart';
import 'package:cw_core/payjoin_session.dart';
import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/utils/zpub.dart';
-import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_bitcoin/bitcoin_wallet.dart';
import 'package:cw_core/pathForWallet.dart';
@@ -130,31 +129,6 @@ class BitcoinWalletService extends WalletService<
}
}
- @override
- Future<void> rename(String currentName, String password, String newName) async {
- final currentWalletInfo = await WalletInfo.get(currentName, getType());
- if (currentWalletInfo == null) {
- throw Exception('Wallet not found');
- }
- final currentWallet = await BitcoinWalletBase.open(
- password: password,
- name: currentName,
- walletInfo: currentWalletInfo,
- unspentCoinsInfo: unspentCoinsInfoSource,
- payjoinBox: payjoinSessionSource,
- encryptionFileUtils: encryptionFileUtilsFor(isDirect),
- );
-
- await currentWallet.renameWalletFiles(newName);
- await saveBackup(newName);
-
- final newWalletInfo = currentWalletInfo;
- newWalletInfo.id = WalletBase.idFor(newName, getType());
- newWalletInfo.name = newName;
-
- await newWalletInfo.save();
- }
-
@override
Future<BitcoinWallet> restoreFromHardwareWallet(BitcoinRestoreWalletFromHardware credentials,
{bool? isTestnet}) async {
diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart
index 21b67146..3dbecad9 100644
--- a/cw_bitcoin/lib/electrum_wallet.dart
+++ b/cw_bitcoin/lib/electrum_wallet.dart
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
-import 'dart:io';
import 'dart:isolate';
import 'package:bitcoin_base/bitcoin_base.dart';
@@ -38,7 +37,6 @@ import 'package:cw_core/get_height_by_date.dart';
import 'package:cw_core/hardware/hardware_wallet_service.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/output_info.dart';
-import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/root_dir.dart';
import 'package:cw_core/sync_status.dart';
@@ -1736,37 +1734,6 @@ abstract class ElectrumWalletBase
await transactionHistory.save();
}
- @override
- Future<void> renameWalletFiles(String newWalletName) async {
- final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
- final currentWalletFile = File(currentWalletPath);
-
- final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
- final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
-
- // Copies current wallet files into new wallet name's dir and files
- if (currentWalletFile.existsSync()) {
- final newWalletPath = await pathForWallet(name: newWalletName, type: type);
- await currentWalletFile.copy(newWalletPath);
- }
- if (currentTransactionsFile.existsSync()) {
- final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
- await currentTransactionsFile.copy('$newDirPath/$transactionsHistoryFileName');
- }
-
- // Delete old name's dir and files
- final dir = Directory(currentDirPath);
- for (var attempt = 0; attempt < 3; attempt++) {
- try {
- await dir.delete(recursive: true);
- break;
- } on FileSystemException {
- if (attempt == 2) rethrow;
- await Future<void>.delayed(const Duration(milliseconds: 200));
- }
- }
- }
-
@override
Future<void> changePassword(String password) async {
_password = password;
diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart
index 51cc8a4d..2f9ae0b3 100644
--- a/cw_bitcoin/lib/litecoin_wallet.dart
+++ b/cw_bitcoin/lib/litecoin_wallet.dart
@@ -497,22 +497,25 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(boxName);
}
- @override
- Future<void> renameWalletFiles(String newWalletName) async {
- // rename the hive box:
- final oldBoxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
- final newBoxName = "${newWalletName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
+ static Future<void> copyMwebBox({
+ required String fromName,
+ required String toName,
+ }) async {
+ final oldBoxName = "${fromName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
+ final newBoxName = "${toName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
+ if (oldBoxName == newBoxName) return;
final oldBox = await CakeHive.openBox<MwebUtxo>(oldBoxName);
- mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
+ final newBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
for (final key in oldBox.keys) {
- final value = oldBox.get(key);
- await oldBox.delete(key);
- await mwebUtxosBox.put(key, value!);
+ await newBox.put(key, oldBox.get(key)!);
}
- oldBox.deleteFromDisk();
+ }
- await super.renameWalletFiles(newWalletName);
+ static Future<void> deleteMwebBox(String name) async {
+ final boxName = "${name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
+ final box = await CakeHive.openBox<MwebUtxo>(boxName);
+ await box.deleteFromDisk();
}
@action
diff --git a/cw_bitcoin/lib/litecoin_wallet_service.dart b/cw_bitcoin/lib/litecoin_wallet_service.dart
index 739602e2..0156ee67 100644
--- a/cw_bitcoin/lib/litecoin_wallet_service.dart
+++ b/cw_bitcoin/lib/litecoin_wallet_service.dart
@@ -12,8 +12,6 @@ import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_core/wallet_info.dart';
-import 'package:cw_core/wallet_base.dart';
-import 'package:collection/collection.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:path_provider/path_provider.dart';
@@ -139,26 +137,11 @@ class LitecoinWalletService extends WalletService<
@override
Future<void> rename(String currentName, String password, String newName) async {
- final currentWalletInfo = await WalletInfo.get(currentName, getType());
- if (currentWalletInfo == null) {
- throw Exception('Wallet not found');
- }
- final currentWallet = await LitecoinWalletBase.open(
- password: password,
- name: currentName,
- walletInfo: currentWalletInfo,
- unspentCoinsInfo: unspentCoinsInfoSource,
- encryptionFileUtils: encryptionFileUtilsFor(isDirect),
- );
-
- await currentWallet.renameWalletFiles(newName);
- await saveBackup(newName);
-
- final newWalletInfo = currentWalletInfo;
- newWalletInfo.id = WalletBase.idFor(newName, getType());
- newWalletInfo.name = newName;
+ if (currentName == newName) return;
- await newWalletInfo.save();
+ await LitecoinWalletBase.copyMwebBox(fromName: currentName, toName: newName);
+ await super.rename(currentName, password, newName);
+ await LitecoinWalletBase.deleteMwebBox(currentName);
}
@override
diff --git a/cw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dart b/cw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dart
index 1861b21f..c7316ec4 100644
--- a/cw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dart
+++ b/cw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dart
@@ -1,13 +1,11 @@
import 'dart:io';
import 'package:bip39/bip39.dart';
-import 'package:collection/collection.dart';
import 'package:cw_bitcoin/bitcoin_mnemonics_bip39.dart';
import 'package:cw_bitcoin_cash/cw_bitcoin_cash.dart';
import 'package:cw_core/encryption_file_utils.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/unspent_coins_info.dart';
-import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/wallet_type.dart';
@@ -99,29 +97,6 @@ class BitcoinCashWalletService extends WalletService<
}
}
- @override
- Future<void> rename(String currentName, String password, String newName) async {
- final currentWalletInfo = await WalletInfo.get(currentName, getType());
- if (currentWalletInfo == null) {
- throw Exception('Wallet not found');
- }
- final currentWallet = await BitcoinCashWalletBase.open(
- password: password,
- name: currentName,
- walletInfo: currentWalletInfo,
- unspentCoinsInfo: unspentCoinsInfoSource,
- encryptionFileUtils: encryptionFileUtilsFor(isDirect));
-
- await currentWallet.renameWalletFiles(newName);
- await saveBackup(newName);
-
- final newWalletInfo = currentWalletInfo;
- newWalletInfo.id = WalletBase.idFor(newName, getType());
- newWalletInfo.name = newName;
-
- await newWalletInfo.save();
- }
-
@override
Future<BitcoinCashWallet> restoreFromHardwareWallet(BitcoinCashNewWalletCredentials credentials) {
throw UnimplementedError(
diff --git a/cw_core/lib/pathForWallet.dart b/cw_core/lib/pathForWallet.dart
index cb5a4fe7..9fe5f717 100644
--- a/cw_core/lib/pathForWallet.dart
+++ b/cw_core/lib/pathForWallet.dart
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:cw_core/root_dir.dart';
import 'package:cw_core/wallet_type.dart';
+import 'package:path/path.dart' as p;
Future<String> pathForWalletTypeDir({required WalletType type}) async {
final root = await getAppDir();
@@ -36,3 +37,43 @@ Future<String> outdatedAndroidPathForWalletDir({required String name}) async {
return pathDir;
}
+
+Future<void> copyWalletFilesTo({
+ required String fromName,
+ required String toName,
+ required WalletType type,
+}) async {
+ if (fromName == toName) return;
+
+ final typeRoot = await pathForWalletTypeDir(type: type);
+ final sourceDir = Directory(p.join(typeRoot, fromName));
+ if (!sourceDir.existsSync()) {
+ throw "Source wallet not found: $fromName $type";
+ }
+
+ if (Directory(p.join(typeRoot, toName)).existsSync()) {
+ throw Exception('Cannot rename wallet: "$toName" already exists');
+ }
+
+ final destinationDir = Directory(p.join(typeRoot, toName));
+ await _copyDirectory(sourceDir, destinationDir);
+
+ for (final suffix in const ['', '.keys', '.keys.backup']) {
+ final file = File(p.join(destinationDir.path, '$fromName$suffix'));
+ if (file.existsSync()) {
+ await file.rename(p.join(destinationDir.path, '$toName$suffix'));
+ }
+ }
+}
+
+Future<void> _copyDirectory(Directory source, Directory destination) async {
+ await destination.create(recursive: true);
+ await for (final entity in source.list(followLinks: false)) {
+ final name = p.basename(entity.path);
+ if (entity is File) {
+ await entity.copy(p.join(destination.path, name));
+ } else if (entity is Directory) {
+ await _copyDirectory(entity, Directory(p.join(destination.path, name)));
+ }
+ }
+}
diff --git a/cw_core/lib/wallet_base.dart b/cw_core/lib/wallet_base.dart
index 917d86ef..89d6356d 100644
--- a/cw_core/lib/wallet_base.dart
+++ b/cw_core/lib/wallet_base.dart
@@ -12,6 +12,7 @@ import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/sync_status.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/wallet_type.dart';
+import 'package:cw_core/pathForWallet.dart';
abstract class WalletBase<BalanceType extends Balance, HistoryType extends TransactionHistoryBase,
TransactionType extends TransactionInfo> {
@@ -115,7 +116,8 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
void setExceptionHandler(void Function(FlutterErrorDetails) onError) => null;
- Future<void> renameWalletFiles(String newWalletName);
+ Future<void> renameWalletFiles(String newWalletName) =>
+ copyWalletFilesTo(fromName: walletInfo.name, toName: newWalletName, type: type);
Future<String> signMessage(String message, {String? address = null});
diff --git a/cw_core/lib/wallet_service.dart b/cw_core/lib/wallet_service.dart
index 016f3cc6..8d19a9f8 100644
--- a/cw_core/lib/wallet_service.dart
+++ b/cw_core/lib/wallet_service.dart
@@ -3,9 +3,12 @@ import 'dart:io';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/utils/file.dart';
+import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_credentials.dart';
+import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
+import 'package:path/path.dart' as p;
abstract class WalletService<N extends WalletCredentials, RFS extends WalletCredentials,
RFK extends WalletCredentials, RFH extends WalletCredentials> {
@@ -25,7 +28,30 @@ abstract class WalletService<N extends WalletCredentials, RFS extends WalletCred
Future<void> remove(String wallet);
- Future<void> rename(String currentName, String password, String newName);
+ Future<void> rename(String currentName, String password, String newName) async {
+ if (currentName == newName) return;
+
+ final currentWalletInfo = await WalletInfo.get(currentName, getType());
+ if (currentWalletInfo == null) {
+ throw Exception('Wallet not found');
+ }
+
+ await copyWalletFilesTo(fromName: currentName, toName: newName, type: getType());
+ await saveBackup(newName);
+
+ currentWalletInfo.id = WalletBase.idFor(newName, getType());
+ currentWalletInfo.name = newName;
+ await currentWalletInfo.save();
+
+ final oldDir = Directory(p.join(await pathForWalletTypeDir(type: getType()), currentName));
+ if (oldDir.existsSync()) {
+ try {
+ await oldDir.delete(recursive: true);
+ } catch (e) {
+ printV('rename: failed to delete old wallet dir "$currentName": $e');
+ }
+ }
+ }
Future<void> restoreWalletFilesFromBackup(String name) async {
final backupWalletDirPath = await pathForWalletDir(name: "$name.backup", type: getType());
diff --git a/cw_dogecoin/lib/src/dogecoin_wallet_service.dart b/cw_dogecoin/lib/src/dogecoin_wallet_service.dart
index 988abd2e..1a78e14f 100644
--- a/cw_dogecoin/lib/src/dogecoin_wallet_service.dart
+++ b/cw_dogecoin/lib/src/dogecoin_wallet_service.dart
@@ -1,12 +1,10 @@
import 'dart:io';
import 'package:bip39/bip39.dart';
-import 'package:collection/collection.dart';
import 'package:cw_bitcoin/bitcoin_mnemonics_bip39.dart';
import 'package:cw_core/encryption_file_utils.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/unspent_coins_info.dart';
-import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/wallet_type.dart';
@@ -100,29 +98,6 @@ class DogeCoinWalletService extends WalletService<
}
}
- @override
- Future<void> rename(String currentName, String password, String newName) async {
- final currentWalletInfo = await WalletInfo.get(currentName, getType());
- if (currentWalletInfo == null) {
- throw Exception('Wallet not found');
- }
- final currentWallet = await DogeCoinWalletBase.open(
- password: password,
- name: currentName,
- walletInfo: currentWalletInfo,
- unspentCoinsInfo: unspentCoinsInfoSource,
- encryptionFileUtils: encryptionFileUtilsFor(isDirect));
-
- await currentWallet.renameWalletFiles(newName);
- await saveBackup(newName);
-
- final newWalletInfo = currentWalletInfo;
- newWalletInfo.id = WalletBase.idFor(newName, getType());
- newWalletInfo.name = newName;
-
- await newWalletInfo.save();
- }
-
@override
Future<DogeCoinWallet> restoreFromHardwareWallet(DogeCoinNewWalletCredentials credentials) {
throw UnimplementedError(
diff --git a/cw_evm/lib/evm_chain_wallet.dart b/cw_evm/lib/evm_chain_wallet.dart
index 6cd05f75..d404013f 100644
--- a/cw_evm/lib/evm_chain_wallet.dart
+++ b/cw_evm/lib/evm_chain_wallet.dart
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
-import 'dart:io';
import 'dart:typed_data';
import 'package:bip32/bip32.dart' as bip32;
@@ -1703,30 +1702,6 @@ abstract class EVMChainWalletBase
);
}
- @override
- Future<void> renameWalletFiles(String newWalletName) async {
- final transactionHistoryFileNameForWallet = getTransactionHistoryFileName();
-
- final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
- final currentWalletFile = File(currentWalletPath);
-
- final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
- final currentTransactionsFile = File('$currentDirPath/$transactionHistoryFileNameForWallet');
-
- // Copies current wallet files into new wallet name's dir and files
- if (currentWalletFile.existsSync()) {
- final newWalletPath = await pathForWallet(name: newWalletName, type: type);
- await currentWalletFile.copy(newWalletPath);
- }
- if (currentTransactionsFile.existsSync()) {
- final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
- await currentTransactionsFile.copy('$newDirPath/$transactionHistoryFileNameForWallet');
- }
-
- // Delete old name's dir and files
- await Directory(currentDirPath).delete(recursive: true);
- }
-
void _setTransactionUpdateTimer() {
if (_transactionsUpdateTimer?.isActive ?? false) {
_transactionsUpdateTimer!.cancel();
diff --git a/cw_evm/lib/evm_chain_wallet_service.dart b/cw_evm/lib/evm_chain_wallet_service.dart
index d6368622..425bdceb 100644
--- a/cw_evm/lib/evm_chain_wallet_service.dart
+++ b/cw_evm/lib/evm_chain_wallet_service.dart
@@ -3,10 +3,12 @@ import 'dart:io';
import 'package:bip39/bip39.dart' as bip39;
import 'package:cw_core/encryption_file_utils.dart';
import 'package:cw_core/pathForWallet.dart';
+import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/wallet_type.dart';
+import 'package:path/path.dart' as p;
import 'package:cw_evm/clients/evm_chain_client.dart';
import 'package:cw_evm/evm_chain_client_factory.dart';
import 'package:cw_evm/evm_chain_registry.dart';
@@ -166,29 +168,30 @@ class EVMChainWalletService extends WalletService<
@override
Future<void> rename(String currentName, String password, String newName) async {
+ if (currentName == newName) return;
+
final currentWalletInfo = await _findWalletByName(currentName);
if (currentWalletInfo == null) {
throw Exception('Wallet not found');
}
- final currentWallet = await _openWalletInstance(
- password: password,
- name: currentName,
- walletInfo: currentWalletInfo,
- encryptionFileUtils: encryptionFileUtilsFor(isDirect),
- );
+ final type = currentWalletInfo.type;
- await currentWallet.renameWalletFiles(newName);
+ await copyWalletFilesTo(fromName: currentName, toName: newName, type: type);
+ await saveBackup(newName, walletInfo: currentWalletInfo);
- // Update walletInfo with new name before saving backup
- final newWalletInfo = currentWalletInfo;
- newWalletInfo.id = WalletBase.idFor(newName, currentWalletInfo.type);
- newWalletInfo.name = newName;
+ currentWalletInfo.id = WalletBase.idFor(newName, type);
+ currentWalletInfo.name = newName;
+ await currentWalletInfo.save();
- // Pass walletInfo to saveBackup to avoid lookup (since WalletInfo not saved yet)
- await saveBackup(newName, walletInfo: newWalletInfo);
-
- await newWalletInfo.save();
+ final oldDir = Directory(p.join(await pathForWalletTypeDir(type: type), currentName));
+ if (oldDir.existsSync()) {
+ try {
+ await oldDir.delete(recursive: true);
+ } catch (e) {
+ printV('rename: failed to delete old wallet dir "$currentName": $e');
+ }
+ }
}
@override
diff --git a/cw_evm/pubspec.yaml b/cw_evm/pubspec.yaml
index 0186841c..5cc563e6 100644
--- a/cw_evm/pubspec.yaml
+++ b/cw_evm/pubspec.yaml
@@ -21,6 +21,7 @@ dependencies:
http: ^1.1.0
hive: ^2.2.3
collection: ^1.17.1
+ path: ^1.8.0
shared_preferences: ^2.0.15
mobx: ^2.0.7+4
cw_core:
diff --git a/cw_solana/lib/solana_wallet.dart b/cw_solana/lib/solana_wallet.dart
index 34308b04..b5b9309f 100644
--- a/cw_solana/lib/solana_wallet.dart
+++ b/cw_solana/lib/solana_wallet.dart
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
-import 'dart:io';
import 'package:cw_core/amount/money.dart';
import 'package:cw_core/cake_hive.dart';
@@ -833,28 +832,6 @@ abstract class SolanaWalletBase
}
}
- @override
- Future<void> renameWalletFiles(String newWalletName) async {
- final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
- final currentWalletFile = File(currentWalletPath);
-
- final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
- final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
-
- // Copies current wallet files into new wallet name's dir and files
- if (currentWalletFile.existsSync()) {
- final newWalletPath = await pathForWallet(name: newWalletName, type: type);
- await currentWalletFile.copy(newWalletPath);
- }
- if (currentTransactionsFile.existsSync()) {
- final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
- await currentTransactionsFile.copy('$newDirPath/$transactionsHistoryFileName');
- }
-
- // Delete old name's dir and files
- await Directory(currentDirPath).delete(recursive: true);
- }
-
void _setTransactionUpdateTimer() {
if (_transactionsUpdateTimer?.isActive ?? false) {
_transactionsUpdateTimer!.cancel();
diff --git a/cw_solana/lib/solana_wallet_service.dart b/cw_solana/lib/solana_wallet_service.dart
index a16f3ee6..d1fce3b2 100644
--- a/cw_solana/lib/solana_wallet_service.dart
+++ b/cw_solana/lib/solana_wallet_service.dart
@@ -1,7 +1,6 @@
import 'dart:io';
import 'package:bip39/bip39.dart' as bip39;
-import 'package:collection/collection.dart';
import 'package:cw_core/encryption_file_utils.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/pathForWallet.dart';
@@ -14,7 +13,6 @@ import 'package:cw_core/wallet_type.dart';
import 'package:cw_solana/solana_mnemonics.dart';
import 'package:cw_solana/solana_wallet.dart';
import 'package:cw_solana/solana_wallet_creation_credentials.dart';
-import 'package:hive/hive.dart';
class SolanaWalletService extends WalletService<SolanaNewWalletCredentials,
SolanaRestoreWalletFromSeedCredentials, SolanaRestoreWalletFromPrivateKey, SolanaNewWalletCredentials> {
@@ -138,29 +136,6 @@ class SolanaWalletService extends WalletService<SolanaNewWalletCredentials,
return wallet;
}
- @override
- Future<void> rename(String currentName, String password, String newName) async {
- final currentWalletInfo = await WalletInfo.get(currentName, getType());
- if (currentWalletInfo == null) {
- throw Exception('Wallet not found');
- }
- final currentWallet = await SolanaWalletBase.open(
- password: password,
- name: currentName,
- walletInfo: currentWalletInfo,
- encryptionFileUtils: encryptionFileUtilsFor(isDirect),
- );
-
- await currentWallet.renameWalletFiles(newName);
- await saveBackup(newName);
-
- final newWalletInfo = currentWalletInfo;
- newWalletInfo.id = WalletBase.idFor(newName, getType());
- newWalletInfo.name = newName;
-
- await newWalletInfo.save();
- }
-
@override
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>> restoreFromHardwareWallet(SolanaNewWalletCredentials credentials) {
// TODO: implement restoreFromHardwareWallet
diff --git a/cw_tron/lib/tron_wallet.dart b/cw_tron/lib/tron_wallet.dart
index 1a4d98b4..24fa83f1 100644
--- a/cw_tron/lib/tron_wallet.dart
+++ b/cw_tron/lib/tron_wallet.dart
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
-import 'dart:io';
import 'package:bip39/bip39.dart' as bip39;
import 'package:blockchain_utils/blockchain_utils.dart';
@@ -607,30 +606,6 @@ abstract class TronWalletBase
Future<TronToken?> getTronToken(String contractAddress) async =>
await _client.getTronToken(contractAddress, _tronAddress);
- @override
- Future<void> renameWalletFiles(String newWalletName) async {
- const transactionHistoryFileNameForWallet = 'tron_transactions.json';
-
- final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
- final currentWalletFile = File(currentWalletPath);
-
- final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
- final currentTransactionsFile = File('$currentDirPath/$transactionHistoryFileNameForWallet');
-
- // Copies current wallet files into new wallet name's dir and files
- if (currentWalletFile.existsSync()) {
- final newWalletPath = await pathForWallet(name: newWalletName, type: type);
- await currentWalletFile.copy(newWalletPath);
- }
- if (currentTransactionsFile.existsSync()) {
- final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
- await currentTransactionsFile.copy('$newDirPath/$transactionHistoryFileNameForWallet');
- }
-
- // Delete old name's dir and files
- await Directory(currentDirPath).delete(recursive: true);
- }
-
void _setTransactionUpdateTimer() {
if (_transactionsUpdateTimer?.isActive ?? false) {
_transactionsUpdateTimer!.cancel();
diff --git a/cw_tron/lib/tron_wallet_service.dart b/cw_tron/lib/tron_wallet_service.dart
index cf83b915..9b81a9a5 100644
--- a/cw_tron/lib/tron_wallet_service.dart
+++ b/cw_tron/lib/tron_wallet_service.dart
@@ -14,7 +14,6 @@ import 'package:cw_tron/tron_client.dart';
import 'package:cw_tron/tron_exception.dart';
import 'package:cw_tron/tron_wallet.dart';
import 'package:cw_tron/tron_wallet_creation_credentials.dart';
-import 'package:hive/hive.dart';
class TronWalletService extends WalletService<
TronNewWalletCredentials,
@@ -134,29 +133,6 @@ class TronWalletService extends WalletService<
return wallet;
}
- @override
- Future<void> rename(String currentName, String password, String newName) async {
- final currentWalletInfo = await WalletInfo.get(currentName, getType());
- if (currentWalletInfo == null) {
- throw Exception('Wallet not found');
- }
- final currentWallet = await TronWalletBase.open(
- password: password,
- name: currentName,
- walletInfo: currentWalletInfo,
- encryptionFileUtils: encryptionFileUtilsFor(isDirect),
- );
-
- await currentWallet.renameWalletFiles(newName);
- await saveBackup(newName);
-
- final newWalletInfo = currentWalletInfo;
- newWalletInfo.id = WalletBase.idFor(newName, getType());
- newWalletInfo.name = newName;
-
- await newWalletInfo.save();
- }
-
@override
Future<bool> isWalletExit(String name) async =>
File(await pathForWallet(name: name, type: getType())).existsSync();
Why this scored 32/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.