CAKE-343 | applied subaddresses for contact book; added addresses field to wallet_info.dart; added updateAddressesInfo() to wallet_base.dart; applied updateAddressesInfo() to wallet services and view models

This commit is contained in:
OleksandrSobol 2021-06-18 15:36:49 +03:00
parent b5cacbc1c1
commit 6709b7779a
13 changed files with 81 additions and 18 deletions

View file

@ -44,6 +44,7 @@ class BitcoinWalletService extends WalletService<
final wallet = await BitcoinWalletBase.open(
password: password, name: name, walletInfo: walletInfo);
await wallet.init();
await wallet.updateAddressesInfo();
return wallet;
}

View file

@ -125,6 +125,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
address = addresses[_accountIndex].address;
await updateAddressesInfo();
await save();
}

View file

@ -45,6 +45,7 @@ class LitecoinWalletService extends WalletService<
final wallet = await LitecoinWalletBase.open(
password: password, name: name, walletInfo: walletInfo);
await wallet.init();
await wallet.updateAddressesInfo();
return wallet;
}

View file

@ -66,4 +66,13 @@ abstract class WalletBase<
Future<void> rescan({int height});
void close();
Future<void> updateAddressesInfo() async {
try {
walletInfo.address = address;
await walletInfo.save();
} catch (e) {
print(e.toString());
}
}
}

View file

@ -362,6 +362,7 @@ Future setup(
AccountListItem, void>(
(AccountListItem account, _) => MoneroAccountEditOrCreateViewModel(
(getIt.get<AppStore>().wallet as MoneroWallet).accountList,
wallet: getIt.get<AppStore>().wallet,
accountListItem: account));
getIt.registerFactoryParam<MoneroAccountEditOrCreatePage, AccountListItem,

View file

@ -53,5 +53,8 @@ class WalletInfo extends HiveObject {
@HiveField(8)
String address;
@HiveField(10)
Map<String, String> addresses;
DateTime get date => DateTime.fromMillisecondsSinceEpoch(timestamp);
}

View file

@ -445,4 +445,26 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
print(e.toString());
}
}
@override
Future<void> updateAddressesInfo() async {
final Map<String, String> _addresses = {};
final _subaddressList = MoneroSubaddressList();
accountList.accounts.forEach((account) {
_subaddressList.update(accountIndex: account.id);
_subaddressList.subaddresses.forEach((subaddress) {
_addresses.addAll({subaddress.address:subaddress.label});
});
});
try {
walletInfo.addresses = _addresses;
walletInfo.address = address;
await walletInfo.save();
} catch (e) {
print(e.toString());
}
}
}

View file

@ -126,6 +126,7 @@ class MoneroWalletService extends WalletService<
}
await wallet.init();
await wallet.updateAddressesInfo();
return wallet;
} catch (e) {

View file

@ -151,17 +151,19 @@ class ContactListPage extends BasePage {
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
image ?? Offstage(),
Padding(
padding: image != null
? EdgeInsets.only(left: 12)
: EdgeInsets.only(left: 0),
child: Text(
contact.name,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal,
color: Theme.of(context).primaryTextTheme.title.color),
),
Expanded(
child: Padding(
padding: image != null
? EdgeInsets.only(left: 12)
: EdgeInsets.only(left: 0),
child: Text(
contact.name,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal,
color: Theme.of(context).primaryTextTheme.title.color),
),
)
)
],
),

View file

@ -16,11 +16,23 @@ class ContactListViewModel = ContactListViewModelBase
abstract class ContactListViewModelBase with Store {
ContactListViewModelBase(this.contactSource, this.walletInfoSource)
: contacts = ObservableList<ContactRecord>(),
walletContacts = walletInfoSource.values
.where((info) => info.address?.isNotEmpty ?? false)
.map((info) => WalletContact(
info.address, info.name, walletTypeToCryptoCurrency(info.type)))
.toList() {
walletContacts = [] {
walletInfoSource.values.forEach((info) {
if (info.address?.isNotEmpty ?? false) {
if (info.addresses != null) {
info.addresses.forEach((address, label) {
walletContacts.add(WalletContact(
address,
info.name + ' ($label)',
walletTypeToCryptoCurrency(info.type)));
});
} else {
walletContacts.add(WalletContact(info.address, info.name,
walletTypeToCryptoCurrency(info.type)));
}
}
});
_subscription = contactSource.bindToListWithTransform(
contacts, (Contact contact) => ContactRecord(contactSource, contact),
initialFire: true);

View file

@ -1,3 +1,5 @@
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/monero/monero_account_list.dart';
@ -10,11 +12,12 @@ class MoneroAccountEditOrCreateViewModel = MoneroAccountEditOrCreateViewModelBas
abstract class MoneroAccountEditOrCreateViewModelBase with Store {
MoneroAccountEditOrCreateViewModelBase(this._moneroAccountList,
{AccountListItem accountListItem})
{@required WalletBase wallet, AccountListItem accountListItem})
: state = InitialExecutionState(),
isEdit = accountListItem != null,
label = accountListItem?.label??'',
_accountListItem = accountListItem;
_accountListItem = accountListItem,
_wallet = wallet;
final bool isEdit;
@ -26,6 +29,7 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
final MoneroAccountList _moneroAccountList;
final AccountListItem _accountListItem;
final WalletBase _wallet;
Future<void> save() async {
try {
@ -38,6 +42,8 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
await _moneroAccountList.addAccount(label: label);
}
await _wallet.updateAddressesInfo();
state = ExecutedSuccessfullyState();
} catch (e) {
state = FailureState(e.toString());

View file

@ -54,6 +54,8 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
await _createNew();
}
await _wallet.updateAddressesInfo();
state = AddressSavedSuccessfully();
} catch (e) {
state = AddressEditOrCreateStateFailure(error: e.toString());

View file

@ -54,6 +54,7 @@ abstract class WalletCreationVMBase with Store {
await _walletInfoSource.add(walletInfo);
_appStore.changeCurrentWallet(wallet);
_appStore.authenticationStore.allowed();
await wallet.updateAddressesInfo();
state = ExecutedSuccessfullyState();
} catch (e) {
state = FailureState(e.toString());