mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-10-30 00:47:48 +00:00
f8b0c0ad2a
* subaddress fix * fix subaddress generation * rewrite usedAddresses for xmr and wow * [skip ci] remove print statements * refactor address handling * do not remove manual addresses, just mark them * monero display latest address on receive page when autogenerate is enabled [skip ci] * WIP subaddresses, hidden addresses, and UI improvements for monero * update configure script * fix subaddress generation, display latest address * Update lib/core/wallet_loading_service.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Exclude manually created addresses Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * don't call .save function multiple times Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * - revert usedAddress functinality - add mutex to prevent crashes - fix UI flashing in tx screen - fixes from comments * account index fixes added code to wownero code comment * - added subaddress index - fixed received count also accounting for change (we don't want that) - fix bad state: no element - fix search - fix automatic generation * prevent crashes by acquiring mutex before setting the pointer * - fix ttDetails generation in larger/restored wallets - show manual add icon in monero/wownero even when autogeneration is enabled - disable colors on non-debug builds - cache getAddress call in xmr/wow [skip ci] * fix: silent payment error in address setter enable fancy new features only for xmr / wow * refresh subaddress list, when we add new address fix manual addresses marking * add toggle to hide and show address * update transaction details after restore * show only one address in address book for xmr, wow and haven * fix address book reset address only when autogenerate is on * enable isEnabledAutoGenerateSubaddress on new wallets * hide addresses after exchange only for XMR and WOW * fix: bad-state no element * Update cw_monero/lib/monero_wallet_addresses.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Update cw_monero/lib/monero_wallet_addresses.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * improvements to performance * 0, 0 -> accountIndex, addressIndex * make constant variables final * Update cw_wownero/lib/wownero_wallet_addresses.dart [skip ci] * Update cw_wownero/lib/wownero_wallet_addresses.dart [skip ci] * Update cw_monero/lib/monero_wallet.dart [skip ci] * fix potential exception * fix after removing late * remove orElse, replaced it with a try catch block. fix strings * fix valid seed function * fix null check error [skip ci] * fix updateSubaddressList for wow and haven --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
80 lines
2.3 KiB
Dart
80 lines
2.3 KiB
Dart
import 'package:cw_core/address_info.dart';
|
|
import 'package:cw_core/wallet_info.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
abstract class WalletAddresses {
|
|
WalletAddresses(this.walletInfo)
|
|
: addressesMap = {},
|
|
allAddressesMap = {},
|
|
addressInfos = {},
|
|
usedAddresses = {},
|
|
hiddenAddresses = walletInfo.hiddenAddresses?.toSet() ?? {},
|
|
manualAddresses = walletInfo.manualAddresses?.toSet() ?? {};
|
|
|
|
final WalletInfo walletInfo;
|
|
|
|
String get address;
|
|
|
|
String get latestAddress {
|
|
if (walletInfo.type == WalletType.monero || walletInfo.type == WalletType.wownero) {
|
|
if (addressesMap.keys.length == 0) return address;
|
|
return addressesMap[addressesMap.keys.last] ?? address;
|
|
}
|
|
return _localAddress ?? address;
|
|
}
|
|
|
|
String? get primaryAddress => null;
|
|
|
|
String? _localAddress;
|
|
|
|
set address(String address) => _localAddress = address;
|
|
|
|
String get addressForExchange => address;
|
|
|
|
Map<String, String> addressesMap;
|
|
Map<String, String> allAddressesMap;
|
|
|
|
Map<String, String> get usableAddressesMap {
|
|
final tmp = addressesMap.map((key, value) => MapEntry(key, value)); // copy address map
|
|
tmp.removeWhere((key, value) => hiddenAddresses.contains(key) || manualAddresses.contains(key));
|
|
return tmp;
|
|
}
|
|
|
|
Map<String, String> get usableAllAddressesMap {
|
|
final tmp = allAddressesMap.map((key, value) => MapEntry(key, value)); // copy address map
|
|
tmp.removeWhere((key, value) => hiddenAddresses.contains(key) || manualAddresses.contains(key));
|
|
return tmp;
|
|
}
|
|
|
|
Map<int, List<AddressInfo>> addressInfos;
|
|
|
|
Set<String> usedAddresses;
|
|
|
|
Set<String> hiddenAddresses;
|
|
|
|
Set<String> manualAddresses;
|
|
|
|
Future<void> init();
|
|
|
|
Future<void> updateAddressesInBox();
|
|
|
|
Future<void> saveAddressesInBox() async {
|
|
try {
|
|
walletInfo.address = address;
|
|
walletInfo.addresses = addressesMap;
|
|
walletInfo.addressInfos = addressInfos;
|
|
walletInfo.usedAddresses = usedAddresses.toList();
|
|
walletInfo.hiddenAddresses = hiddenAddresses.toList();
|
|
walletInfo.manualAddresses = manualAddresses.toList();
|
|
|
|
if (walletInfo.isInBox) {
|
|
await walletInfo.save();
|
|
}
|
|
} catch (e) {
|
|
print(e.toString());
|
|
}
|
|
}
|
|
|
|
bool containsAddress(String address) =>
|
|
addressesMap.containsKey(address) || allAddressesMap.containsKey(address);
|
|
}
|