mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
add ability to rename and delete
This commit is contained in:
parent
3a36582cee
commit
20acc303fd
6 changed files with 22 additions and 141 deletions
|
@ -1,7 +1,4 @@
|
||||||
export 'bitcoin_cash_balance.dart';
|
export 'bitcoin_cash_balance.dart';
|
||||||
export 'bitcoin_cash_client.dart';
|
|
||||||
export 'bitcoin_cash_transaction_history.dart';
|
|
||||||
export 'bitcoin_cash_transaction_info.dart';
|
|
||||||
export 'bitcoin_cash_wallet.dart';
|
export 'bitcoin_cash_wallet.dart';
|
||||||
export 'bitcoin_cash_wallet_addresses.dart';
|
export 'bitcoin_cash_wallet_addresses.dart';
|
||||||
export 'bitcoin_cash_wallet_creation_credentials.dart';
|
export 'bitcoin_cash_wallet_creation_credentials.dart';
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
class BitcoinCashClient {}
|
|
|
@ -1,25 +0,0 @@
|
||||||
import 'package:cw_core/pending_transaction.dart';
|
|
||||||
|
|
||||||
class BitcoinCashPendingTransaction with PendingTransaction {
|
|
||||||
@override
|
|
||||||
// TODO: implement amountFormatted
|
|
||||||
String get amountFormatted => throw UnimplementedError('amountFormatted is not implemented');
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> commit() {
|
|
||||||
// TODO: implement commit
|
|
||||||
throw UnimplementedError('commit is not implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement feeFormatted
|
|
||||||
String get feeFormatted => throw UnimplementedError('feeFormatted is not implemented');
|
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement hex
|
|
||||||
String get hex => throw UnimplementedError('hex is not implemented');
|
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement id
|
|
||||||
String get id => throw UnimplementedError('id is not implemented');
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
import 'dart:core';
|
|
||||||
|
|
||||||
import 'package:cw_core/transaction_history.dart';
|
|
||||||
import 'package:cw_core/wallet_info.dart';
|
|
||||||
import 'package:mobx/mobx.dart';
|
|
||||||
|
|
||||||
import 'bitcoin_cash_transaction_info.dart';
|
|
||||||
|
|
||||||
part 'bitcoin_cash_transaction_history.g.dart';
|
|
||||||
|
|
||||||
class BitcoinCashTransactionHistory = BitcoinCashTransactionHistoryBase
|
|
||||||
with _$BitcoinCashTransactionHistory;
|
|
||||||
|
|
||||||
abstract class BitcoinCashTransactionHistoryBase
|
|
||||||
extends TransactionHistoryBase<BitcoinCashTransactionInfo> with Store {
|
|
||||||
BitcoinCashTransactionHistoryBase({required this.walletInfo, required String password})
|
|
||||||
: _password = password,
|
|
||||||
_height = 0 {
|
|
||||||
transactions = ObservableMap<String, BitcoinCashTransactionInfo>();
|
|
||||||
}
|
|
||||||
|
|
||||||
final WalletInfo walletInfo;
|
|
||||||
String _password;
|
|
||||||
int _height;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> save() async {
|
|
||||||
// TODO: implement
|
|
||||||
UnimplementedError('save() is not implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void addOne(BitcoinCashTransactionInfo transaction) => transactions[transaction.id] = transaction;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void addMany(Map<String, BitcoinCashTransactionInfo> transactions) =>
|
|
||||||
this.transactions.addAll(transactions);
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
import 'package:cw_core/format_amount.dart';
|
|
||||||
import 'package:cw_core/transaction_direction.dart';
|
|
||||||
import 'package:cw_core/transaction_info.dart';
|
|
||||||
|
|
||||||
class BitcoinCashTransactionInfo extends TransactionInfo {
|
|
||||||
BitcoinCashTransactionInfo({
|
|
||||||
required this.id,
|
|
||||||
required this.height,
|
|
||||||
required this.amount,
|
|
||||||
required this.fee,
|
|
||||||
this.tokenSymbol = "BCH",
|
|
||||||
this.exponent = 18,
|
|
||||||
required this.direction,
|
|
||||||
required this.isPending,
|
|
||||||
required this.date,
|
|
||||||
required this.confirmations,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String id;
|
|
||||||
final int height;
|
|
||||||
final int amount;
|
|
||||||
final int exponent;
|
|
||||||
final TransactionDirection direction;
|
|
||||||
final DateTime date;
|
|
||||||
final bool isPending;
|
|
||||||
final int fee;
|
|
||||||
final int confirmations;
|
|
||||||
final String tokenSymbol;
|
|
||||||
String? _fiatAmount;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String amountFormatted() =>
|
|
||||||
'${formatAmount((BigInt.from(amount) / BigInt.from(10).pow(exponent)).toString())} $tokenSymbol';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String fiatAmount() => _fiatAmount ?? '';
|
|
||||||
|
|
||||||
@override
|
|
||||||
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String feeFormatted() => '${(BigInt.from(fee) / BigInt.from(10).pow(exponent)).toString()} BCH';
|
|
||||||
|
|
||||||
factory BitcoinCashTransactionInfo.fromJson(Map<String, dynamic> data) {
|
|
||||||
return BitcoinCashTransactionInfo(
|
|
||||||
id: data['id'] as String,
|
|
||||||
height: data['height'] as int,
|
|
||||||
amount: data['amount'] as int,
|
|
||||||
fee: data['fee'] as int,
|
|
||||||
direction: parseTransactionDirectionFromInt(data['direction'] as int),
|
|
||||||
date: DateTime.fromMillisecondsSinceEpoch(data['date'] as int),
|
|
||||||
isPending: data['isPending'] as bool,
|
|
||||||
confirmations: data['confirmations'] as int);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
final m = <String, dynamic>{};
|
|
||||||
m['id'] = id;
|
|
||||||
m['height'] = height;
|
|
||||||
m['amount'] = amount;
|
|
||||||
m['direction'] = direction.index;
|
|
||||||
m['date'] = date.millisecondsSinceEpoch;
|
|
||||||
m['isPending'] = isPending;
|
|
||||||
m['confirmations'] = confirmations;
|
|
||||||
m['fee'] = fee;
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -54,15 +54,31 @@ class BitcoinCashWalletService extends WalletService<BitcoinCashNewWalletCredent
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> remove(String wallet) {
|
Future<void> remove(String wallet) async {
|
||||||
// TODO: implement remove
|
File(await pathForWalletDir(name: wallet, type: getType()))
|
||||||
throw UnimplementedError('remove() is not implemented');
|
.delete(recursive: true);
|
||||||
|
final walletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||||
|
(info) => info.id == WalletBase.idFor(wallet, getType()))!;
|
||||||
|
await walletInfoSource.delete(walletInfo.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> rename(String currentName, String password, String newName) {
|
Future<void> rename(String currentName, String password, String newName) async {
|
||||||
// TODO: implement rename
|
final currentWalletInfo = walletInfoSource.values.firstWhereOrNull(
|
||||||
throw UnimplementedError('rename() is not implemented');
|
(info) => info.id == WalletBase.idFor(currentName, getType()))!;
|
||||||
|
final currentWallet = await BitcoinCashWalletBase.open(
|
||||||
|
password: password,
|
||||||
|
name: currentName,
|
||||||
|
walletInfo: currentWalletInfo,
|
||||||
|
unspentCoinsInfo: unspentCoinsInfoSource);
|
||||||
|
|
||||||
|
await currentWallet.renameWalletFiles(newName);
|
||||||
|
|
||||||
|
final newWalletInfo = currentWalletInfo;
|
||||||
|
newWalletInfo.id = WalletBase.idFor(newName, getType());
|
||||||
|
newWalletInfo.name = newName;
|
||||||
|
|
||||||
|
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue