mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-11 08:56:53 +00:00
Add rename wallet to Ethereum
This commit is contained in:
parent
cf2f1e5692
commit
fade15d65b
7 changed files with 48 additions and 1 deletions
cw_bitcoin/lib
cw_core/lib
cw_ethereum/lib
cw_haven/lib
cw_monero/lib
|
@ -431,6 +431,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
||||||
await transactionHistory.save();
|
await transactionHistory.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
Future<void> renameWalletFiles(String newWalletName) async {
|
Future<void> renameWalletFiles(String newWalletName) async {
|
||||||
final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
|
final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
|
||||||
final currentWalletFile = File(currentWalletPath);
|
final currentWalletFile = File(currentWalletPath);
|
||||||
|
|
|
@ -75,4 +75,6 @@ abstract class WalletBase<
|
||||||
Future<void>? updateBalance();
|
Future<void>? updateBalance();
|
||||||
|
|
||||||
void setExceptionHandler(void Function(FlutterErrorDetails) onError) => null;
|
void setExceptionHandler(void Function(FlutterErrorDetails) onError) => null;
|
||||||
|
|
||||||
|
Future<void> renameWalletFiles(String newWalletName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,5 @@ abstract class WalletService<N extends WalletCredentials,
|
||||||
|
|
||||||
Future<void> remove(String wallet);
|
Future<void> remove(String wallet);
|
||||||
|
|
||||||
Future<void> rename(String name, String password, String newName);
|
Future<void> rename(String currentName, String password, String newName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:cw_core/node.dart';
|
import 'package:cw_core/node.dart';
|
||||||
|
@ -347,4 +348,29 @@ abstract class EthereumWalletBase
|
||||||
|
|
||||||
initialErc20Tokens.forEach((token) => erc20TokensBox.put(token.contractAddress, token));
|
initialErc20Tokens.forEach((token) => erc20TokensBox.put(token.contractAddress, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
// TODO: un-hash when transactions flow is implemented
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
// TODO: un-hash when transactions flow is implemented
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,20 @@ class EthereumWalletService extends WalletService<EthereumNewWalletCredentials,
|
||||||
|
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> rename(String currentName, String password, String newName) async {
|
||||||
|
final currentWalletInfo = walletInfoSource.values
|
||||||
|
.firstWhere((info) => info.id == WalletBase.idFor(currentName, getType()));
|
||||||
|
final currentWallet = await EthereumWalletBase.open(
|
||||||
|
password: password, name: currentName, walletInfo: currentWalletInfo);
|
||||||
|
|
||||||
|
await currentWallet.renameWalletFiles(newName);
|
||||||
|
|
||||||
|
final newWalletInfo = currentWalletInfo;
|
||||||
|
newWalletInfo.id = WalletBase.idFor(newName, getType());
|
||||||
|
newWalletInfo.name = newName;
|
||||||
|
|
||||||
|
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,6 +253,7 @@ abstract class HavenWalletBase extends WalletBase<MoneroBalance,
|
||||||
await haven_wallet.store();
|
await haven_wallet.store();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
Future<void> renameWalletFiles(String newWalletName) async {
|
Future<void> renameWalletFiles(String newWalletName) async {
|
||||||
final currentWalletPath = await pathForWallet(name: name, type: type);
|
final currentWalletPath = await pathForWallet(name: name, type: type);
|
||||||
final currentCacheFile = File(currentWalletPath);
|
final currentCacheFile = File(currentWalletPath);
|
||||||
|
|
|
@ -268,6 +268,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
await monero_wallet.store();
|
await monero_wallet.store();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
Future<void> renameWalletFiles(String newWalletName) async {
|
Future<void> renameWalletFiles(String newWalletName) async {
|
||||||
final currentWalletDirPath = await pathForWalletDir(name: name, type: type);
|
final currentWalletDirPath = await pathForWalletDir(name: name, type: type);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue