mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
d4969633b0
* feat: Replace trash and swipe with edit icons on node list item - replaces yellow Test button with red Delete node button with confirmation on the edit node page * feat: make node indicator icons bigger (figma comment) * feat: Replace trash and swipe with edit icons on wallet list page and create wallet_edit_page.dart * fix: make delete buttons red * fix: make wallet name wrap when it is too long * refactor: improve logic & fix observer not refreshing * fix: add string * feat: remove the confirmation pop-up for switching between wallets - which was another item on the jira issue * fix: remove slideable widgets from node list * feat: add edit button to currently selected node & disable deleting if selected * fix: rename wallet also renames to new wallet files * feat: make sure edits can't overlap existing names * fix: improve rename flow, fix electrum transactions refresh & add delete old logic * fix: also fix rename for monero & haven * refactor: fix identations * refactor: dont declare the current wallet twice * refactor: missing newWalletInfo.id * fix: dont unnecessarily load the current wallet * fix: remove unnecessary reaction * feat: make save button disabled until the text is changed * feat: make walletEditViewModel and make state useful for pending actions * fix: add back reaction for desktop flow * - Remove un-necessary code - Format Edit page --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
90 lines
2.7 KiB
Dart
90 lines
2.7 KiB
Dart
import 'dart:convert';
|
|
import 'package:cw_core/pathForWallet.dart';
|
|
import 'package:cw_core/wallet_info.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cw_core/transaction_history.dart';
|
|
import 'package:cw_bitcoin/file.dart';
|
|
import 'package:cw_bitcoin/electrum_transaction_info.dart';
|
|
|
|
part 'electrum_transaction_history.g.dart';
|
|
|
|
const transactionsHistoryFileName = 'transactions.json';
|
|
|
|
class ElectrumTransactionHistory = ElectrumTransactionHistoryBase
|
|
with _$ElectrumTransactionHistory;
|
|
|
|
abstract class ElectrumTransactionHistoryBase
|
|
extends TransactionHistoryBase<ElectrumTransactionInfo> with Store {
|
|
ElectrumTransactionHistoryBase(
|
|
{required this.walletInfo, required String password})
|
|
: _password = password,
|
|
_height = 0 {
|
|
transactions = ObservableMap<String, ElectrumTransactionInfo>();
|
|
}
|
|
|
|
final WalletInfo walletInfo;
|
|
String _password;
|
|
int _height;
|
|
|
|
Future<void> init() async => await _load();
|
|
|
|
@override
|
|
void addOne(ElectrumTransactionInfo transaction) =>
|
|
transactions[transaction.id] = transaction;
|
|
|
|
@override
|
|
void addMany(Map<String, ElectrumTransactionInfo> transactions) =>
|
|
transactions.forEach((_, tx) => _update(tx));
|
|
|
|
@override
|
|
Future<void> save() async {
|
|
try {
|
|
final dirPath =
|
|
await pathForWalletDir(name: walletInfo.name, type: walletInfo.type);
|
|
final path = '$dirPath/$transactionsHistoryFileName';
|
|
final data =
|
|
json.encode({'height': _height, 'transactions': transactions});
|
|
await writeData(path: path, password: _password, data: data);
|
|
} catch (e) {
|
|
print('Error while save bitcoin transaction history: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
Future<void> changePassword(String password) async {
|
|
_password = password;
|
|
await save();
|
|
}
|
|
|
|
Future<Map<String, dynamic>> _read() async {
|
|
final dirPath =
|
|
await pathForWalletDir(name: walletInfo.name, type: walletInfo.type);
|
|
final path = '$dirPath/$transactionsHistoryFileName';
|
|
final content = await read(path: path, password: _password);
|
|
return json.decode(content) as Map<String, dynamic>;
|
|
}
|
|
|
|
Future<void> _load() async {
|
|
try {
|
|
final content = await _read();
|
|
final txs = content['transactions'] as Map<String, dynamic> ?? {};
|
|
|
|
txs.entries.forEach((entry) {
|
|
final val = entry.value;
|
|
|
|
if (val is Map<String, dynamic>) {
|
|
final tx = ElectrumTransactionInfo.fromJson(val, walletInfo.type);
|
|
_update(tx);
|
|
}
|
|
});
|
|
|
|
_height = content['height'] as int;
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
|
|
void _update(ElectrumTransactionInfo transaction) =>
|
|
transactions[transaction.id] = transaction;
|
|
|
|
}
|