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( final wallet = await BitcoinWalletBase.open(
password: password, name: name, walletInfo: walletInfo); password: password, name: name, walletInfo: walletInfo);
await wallet.init(); await wallet.init();
await wallet.updateAddressesInfo();
return wallet; return wallet;
} }

View file

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

View file

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

View file

@ -66,4 +66,13 @@ abstract class WalletBase<
Future<void> rescan({int height}); Future<void> rescan({int height});
void close(); 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, void>(
(AccountListItem account, _) => MoneroAccountEditOrCreateViewModel( (AccountListItem account, _) => MoneroAccountEditOrCreateViewModel(
(getIt.get<AppStore>().wallet as MoneroWallet).accountList, (getIt.get<AppStore>().wallet as MoneroWallet).accountList,
wallet: getIt.get<AppStore>().wallet,
accountListItem: account)); accountListItem: account));
getIt.registerFactoryParam<MoneroAccountEditOrCreatePage, AccountListItem, getIt.registerFactoryParam<MoneroAccountEditOrCreatePage, AccountListItem,

View file

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

View file

@ -445,4 +445,26 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
print(e.toString()); 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.init();
await wallet.updateAddressesInfo();
return wallet; return wallet;
} catch (e) { } catch (e) {

View file

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

View file

@ -16,11 +16,23 @@ class ContactListViewModel = ContactListViewModelBase
abstract class ContactListViewModelBase with Store { abstract class ContactListViewModelBase with Store {
ContactListViewModelBase(this.contactSource, this.walletInfoSource) ContactListViewModelBase(this.contactSource, this.walletInfoSource)
: contacts = ObservableList<ContactRecord>(), : contacts = ObservableList<ContactRecord>(),
walletContacts = walletInfoSource.values walletContacts = [] {
.where((info) => info.address?.isNotEmpty ?? false) walletInfoSource.values.forEach((info) {
.map((info) => WalletContact( if (info.address?.isNotEmpty ?? false) {
info.address, info.name, walletTypeToCryptoCurrency(info.type))) if (info.addresses != null) {
.toList() { 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( _subscription = contactSource.bindToListWithTransform(
contacts, (Contact contact) => ContactRecord(contactSource, contact), contacts, (Contact contact) => ContactRecord(contactSource, contact),
initialFire: true); 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:mobx/mobx.dart';
import 'package:cake_wallet/core/execution_state.dart'; import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/monero/monero_account_list.dart'; import 'package:cake_wallet/monero/monero_account_list.dart';
@ -10,11 +12,12 @@ class MoneroAccountEditOrCreateViewModel = MoneroAccountEditOrCreateViewModelBas
abstract class MoneroAccountEditOrCreateViewModelBase with Store { abstract class MoneroAccountEditOrCreateViewModelBase with Store {
MoneroAccountEditOrCreateViewModelBase(this._moneroAccountList, MoneroAccountEditOrCreateViewModelBase(this._moneroAccountList,
{AccountListItem accountListItem}) {@required WalletBase wallet, AccountListItem accountListItem})
: state = InitialExecutionState(), : state = InitialExecutionState(),
isEdit = accountListItem != null, isEdit = accountListItem != null,
label = accountListItem?.label??'', label = accountListItem?.label??'',
_accountListItem = accountListItem; _accountListItem = accountListItem,
_wallet = wallet;
final bool isEdit; final bool isEdit;
@ -26,6 +29,7 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
final MoneroAccountList _moneroAccountList; final MoneroAccountList _moneroAccountList;
final AccountListItem _accountListItem; final AccountListItem _accountListItem;
final WalletBase _wallet;
Future<void> save() async { Future<void> save() async {
try { try {
@ -38,6 +42,8 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store {
await _moneroAccountList.addAccount(label: label); await _moneroAccountList.addAccount(label: label);
} }
await _wallet.updateAddressesInfo();
state = ExecutedSuccessfullyState(); state = ExecutedSuccessfullyState();
} catch (e) { } catch (e) {
state = FailureState(e.toString()); state = FailureState(e.toString());

View file

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

View file

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