From 6709b7779a9692cfafd8186439b7e9ca1dfdfde0 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Fri, 18 Jun 2021 15:36:49 +0300 Subject: [PATCH 1/4] 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 --- lib/bitcoin/bitcoin_wallet_service.dart | 1 + lib/bitcoin/electrum_wallet.dart | 2 ++ lib/bitcoin/litecoin_wallet_service.dart | 1 + lib/core/wallet_base.dart | 9 +++++++ lib/di.dart | 1 + lib/entities/wallet_info.dart | 3 +++ lib/monero/monero_wallet.dart | 22 +++++++++++++++++ lib/monero/monero_wallet_service.dart | 1 + .../screens/contact/contact_list_page.dart | 24 ++++++++++--------- .../contact_list/contact_list_view_model.dart | 22 +++++++++++++---- ...ero_account_edit_or_create_view_model.dart | 10 ++++++-- ...let_address_edit_or_create_view_model.dart | 2 ++ lib/view_model/wallet_creation_vm.dart | 1 + 13 files changed, 81 insertions(+), 18 deletions(-) diff --git a/lib/bitcoin/bitcoin_wallet_service.dart b/lib/bitcoin/bitcoin_wallet_service.dart index aefe0fadf..2cd3310fd 100644 --- a/lib/bitcoin/bitcoin_wallet_service.dart +++ b/lib/bitcoin/bitcoin_wallet_service.dart @@ -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; } diff --git a/lib/bitcoin/electrum_wallet.dart b/lib/bitcoin/electrum_wallet.dart index bf3dfd542..bb0ee3c3e 100644 --- a/lib/bitcoin/electrum_wallet.dart +++ b/lib/bitcoin/electrum_wallet.dart @@ -125,6 +125,8 @@ abstract class ElectrumWalletBase extends WalletBase rescan({int height}); void close(); + + Future updateAddressesInfo() async { + try { + walletInfo.address = address; + await walletInfo.save(); + } catch (e) { + print(e.toString()); + } + } } diff --git a/lib/di.dart b/lib/di.dart index 37b6c5968..1f5350370 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -362,6 +362,7 @@ Future setup( AccountListItem, void>( (AccountListItem account, _) => MoneroAccountEditOrCreateViewModel( (getIt.get().wallet as MoneroWallet).accountList, + wallet: getIt.get().wallet, accountListItem: account)); getIt.registerFactoryParam addresses; + DateTime get date => DateTime.fromMillisecondsSinceEpoch(timestamp); } diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index e902f1080..753dff53b 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -445,4 +445,26 @@ abstract class MoneroWalletBase extends WalletBase updateAddressesInfo() async { + final Map _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()); + } + } } diff --git a/lib/monero/monero_wallet_service.dart b/lib/monero/monero_wallet_service.dart index 7795b8700..17b02dcbb 100644 --- a/lib/monero/monero_wallet_service.dart +++ b/lib/monero/monero_wallet_service.dart @@ -126,6 +126,7 @@ class MoneroWalletService extends WalletService< } await wallet.init(); + await wallet.updateAddressesInfo(); return wallet; } catch (e) { diff --git a/lib/src/screens/contact/contact_list_page.dart b/lib/src/screens/contact/contact_list_page.dart index bf2b593ee..fd126981a 100644 --- a/lib/src/screens/contact/contact_list_page.dart +++ b/lib/src/screens/contact/contact_list_page.dart @@ -151,17 +151,19 @@ class ContactListPage extends BasePage { crossAxisAlignment: CrossAxisAlignment.center, children: [ 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), + ), + ) ) ], ), diff --git a/lib/view_model/contact_list/contact_list_view_model.dart b/lib/view_model/contact_list/contact_list_view_model.dart index 17083efe2..fd6196c89 100644 --- a/lib/view_model/contact_list/contact_list_view_model.dart +++ b/lib/view_model/contact_list/contact_list_view_model.dart @@ -16,11 +16,23 @@ class ContactListViewModel = ContactListViewModelBase abstract class ContactListViewModelBase with Store { ContactListViewModelBase(this.contactSource, this.walletInfoSource) : contacts = ObservableList(), - 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); diff --git a/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart b/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart index d32f8eadd..cf999e414 100644 --- a/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart +++ b/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart @@ -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 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()); diff --git a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart index b018c542d..6b6873cd5 100644 --- a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart @@ -54,6 +54,8 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store { await _createNew(); } + await _wallet.updateAddressesInfo(); + state = AddressSavedSuccessfully(); } catch (e) { state = AddressEditOrCreateStateFailure(error: e.toString()); diff --git a/lib/view_model/wallet_creation_vm.dart b/lib/view_model/wallet_creation_vm.dart index 58ee24087..54cad29c9 100644 --- a/lib/view_model/wallet_creation_vm.dart +++ b/lib/view_model/wallet_creation_vm.dart @@ -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()); From c72245d90463e460de6fa91a826ef54d4857b371 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Wed, 7 Jul 2021 12:29:33 +0300 Subject: [PATCH 2/4] CAKE-343 | fixed contact_list_view_model.dart and updateAddressInfo() in the monero_wallet.dart --- lib/monero/monero_wallet.dart | 2 +- lib/view_model/contact_list/contact_list_view_model.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index 753dff53b..c9ea9e03e 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -454,7 +454,7 @@ abstract class MoneroWalletBase extends WalletBase Date: Thu, 8 Jul 2021 17:52:48 +0300 Subject: [PATCH 3/4] CAKE-343 | added wallet_addresses.dart, monero_wallet_addresses.dart, electrum_wallet_addresses.dart, wallet_addresses_credentials.dart, monero_wallet_addresses_credentials.dart and electrum_wallet_addresses_credentials.dart to the app; applied ElectrumWalletAddresses to electrum_wallet.dart and MoneroWalletAddresses to monero_wallet.dart; fixed contact_list_view_model.dart, other view models and services --- lib/bitcoin/bitcoin_wallet_service.dart | 1 - lib/bitcoin/electrum_wallet.dart | 16 +++++++- lib/bitcoin/electrum_wallet_addresses.dart | 32 ++++++++++++++++ ...electrum_wallet_addresses_credentials.dart | 7 ++++ lib/bitcoin/litecoin_wallet_service.dart | 1 - lib/core/wallet_base.dart | 10 ----- lib/entities/wallet_addresses.dart | 30 +++++++++++++++ .../wallet_addresses_credentials.dart | 1 + lib/monero/monero_wallet.dart | 37 +++++++++--------- lib/monero/monero_wallet_addresses.dart | 38 +++++++++++++++++++ .../monero_wallet_addresses_credentials.dart | 9 +++++ lib/monero/monero_wallet_service.dart | 1 - .../contact_list/contact_list_view_model.dart | 21 +++++----- ...ero_account_edit_or_create_view_model.dart | 3 +- ...let_address_edit_or_create_view_model.dart | 2 - lib/view_model/wallet_creation_vm.dart | 1 - 16 files changed, 159 insertions(+), 51 deletions(-) create mode 100644 lib/bitcoin/electrum_wallet_addresses.dart create mode 100644 lib/bitcoin/electrum_wallet_addresses_credentials.dart create mode 100644 lib/entities/wallet_addresses.dart create mode 100644 lib/entities/wallet_addresses_credentials.dart create mode 100644 lib/monero/monero_wallet_addresses.dart create mode 100644 lib/monero/monero_wallet_addresses_credentials.dart diff --git a/lib/bitcoin/bitcoin_wallet_service.dart b/lib/bitcoin/bitcoin_wallet_service.dart index 2cd3310fd..aefe0fadf 100644 --- a/lib/bitcoin/bitcoin_wallet_service.dart +++ b/lib/bitcoin/bitcoin_wallet_service.dart @@ -44,7 +44,6 @@ class BitcoinWalletService extends WalletService< final wallet = await BitcoinWalletBase.open( password: password, name: name, walletInfo: walletInfo); await wallet.init(); - await wallet.updateAddressesInfo(); return wallet; } diff --git a/lib/bitcoin/electrum_wallet.dart b/lib/bitcoin/electrum_wallet.dart index bb0ee3c3e..d0b1c9a6c 100644 --- a/lib/bitcoin/electrum_wallet.dart +++ b/lib/bitcoin/electrum_wallet.dart @@ -1,5 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:cake_wallet/bitcoin/electrum_wallet_addresses.dart'; +import 'package:cake_wallet/bitcoin/electrum_wallet_addresses_credentials.dart'; import 'package:mobx/mobx.dart'; import 'package:rxdart/subjects.dart'; import 'package:flutter/foundation.dart'; @@ -63,6 +65,8 @@ abstract class ElectrumWalletBase extends WalletBase @@ -93,6 +97,9 @@ abstract class ElectrumWalletBase extends WalletBase hd.base58; + ElectrumWalletAddresses _walletAddressInBox; + ElectrumWalletAddressesCredentials _walletAddressInBoxCredentials; + @override String get seed => mnemonic; @@ -113,6 +120,7 @@ abstract class ElectrumWalletBase extends WalletBase @@ -466,4 +473,9 @@ abstract class ElectrumWalletBase extends WalletBase _updateWalletAddressInBox() async { + _walletAddressInBoxCredentials.address = address; + await _walletAddressInBox.update(_walletAddressInBoxCredentials); + } } diff --git a/lib/bitcoin/electrum_wallet_addresses.dart b/lib/bitcoin/electrum_wallet_addresses.dart new file mode 100644 index 000000000..ac4895ae8 --- /dev/null +++ b/lib/bitcoin/electrum_wallet_addresses.dart @@ -0,0 +1,32 @@ +import 'package:cake_wallet/bitcoin/electrum_wallet_addresses_credentials.dart'; +import 'package:cake_wallet/entities/wallet_addresses.dart'; +import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; + +class ElectrumWalletAddresses extends WalletAddresses { + ElectrumWalletAddresses(WalletInfo walletInfo) : super(walletInfo); + + @override + Future update(WalletAddressesCredentials credentials) async { + try { + if (credentials == null) { + return; + } + + final _credentials = credentials as ElectrumWalletAddressesCredentials; + final _address = _credentials.address; + final _label = ''; + + if (_address == null || _address.isEmpty) { + return; + } + + addresses.clear(); + addresses[_address] = _label; + + await save(); + } catch (e) { + print(e.toString()); + } + } +} \ No newline at end of file diff --git a/lib/bitcoin/electrum_wallet_addresses_credentials.dart b/lib/bitcoin/electrum_wallet_addresses_credentials.dart new file mode 100644 index 000000000..30a41f8ff --- /dev/null +++ b/lib/bitcoin/electrum_wallet_addresses_credentials.dart @@ -0,0 +1,7 @@ +import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; + +class ElectrumWalletAddressesCredentials extends WalletAddressesCredentials { + ElectrumWalletAddressesCredentials(); + + String address; +} \ No newline at end of file diff --git a/lib/bitcoin/litecoin_wallet_service.dart b/lib/bitcoin/litecoin_wallet_service.dart index 071baf4af..053fd785f 100644 --- a/lib/bitcoin/litecoin_wallet_service.dart +++ b/lib/bitcoin/litecoin_wallet_service.dart @@ -45,7 +45,6 @@ class LitecoinWalletService extends WalletService< final wallet = await LitecoinWalletBase.open( password: password, name: name, walletInfo: walletInfo); await wallet.init(); - await wallet.updateAddressesInfo(); return wallet; } diff --git a/lib/core/wallet_base.dart b/lib/core/wallet_base.dart index 9e7b89e8d..f6ed64142 100644 --- a/lib/core/wallet_base.dart +++ b/lib/core/wallet_base.dart @@ -6,7 +6,6 @@ import 'package:cake_wallet/entities/wallet_info.dart'; import 'package:cake_wallet/core/pending_transaction.dart'; import 'package:cake_wallet/core/transaction_history.dart'; import 'package:cake_wallet/entities/currency_for_wallet_type.dart'; -import 'package:cake_wallet/entities/monero_transaction_priority.dart'; import 'package:cake_wallet/entities/crypto_currency.dart'; import 'package:cake_wallet/entities/sync_status.dart'; import 'package:cake_wallet/entities/node.dart'; @@ -66,13 +65,4 @@ abstract class WalletBase< Future rescan({int height}); void close(); - - Future updateAddressesInfo() async { - try { - walletInfo.address = address; - await walletInfo.save(); - } catch (e) { - print(e.toString()); - } - } } diff --git a/lib/entities/wallet_addresses.dart b/lib/entities/wallet_addresses.dart new file mode 100644 index 000000000..81b4fdea7 --- /dev/null +++ b/lib/entities/wallet_addresses.dart @@ -0,0 +1,30 @@ +import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; + +abstract class WalletAddresses { + WalletAddresses(this.walletInfo) { + addresses = walletInfo?.addresses ?? {}; + } + + final WalletInfo walletInfo; + + Map addresses; + + Future update(WalletAddressesCredentials credentials); + + Future save() async { + try { + if (walletInfo == null) { + return; + } + + walletInfo.addresses = addresses; + + if (walletInfo.isInBox) { + await walletInfo.save(); + } + } catch (e) { + print(e.toString()); + } + } +} \ No newline at end of file diff --git a/lib/entities/wallet_addresses_credentials.dart b/lib/entities/wallet_addresses_credentials.dart new file mode 100644 index 000000000..fe3d2c927 --- /dev/null +++ b/lib/entities/wallet_addresses_credentials.dart @@ -0,0 +1 @@ +abstract class WalletAddressesCredentials {} \ No newline at end of file diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index c9ea9e03e..77cd2f53f 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -3,6 +3,8 @@ import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:cake_wallet/monero/monero_amount_format.dart'; import 'package:cake_wallet/monero/monero_transaction_creation_exception.dart'; import 'package:cake_wallet/monero/monero_transaction_info.dart'; +import 'package:cake_wallet/monero/monero_wallet_addresses.dart'; +import 'package:cake_wallet/monero/monero_wallet_addresses_credentials.dart'; import 'package:flutter/foundation.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_monero/transaction_history.dart' @@ -47,6 +49,8 @@ abstract class MoneroWalletBase extends WalletBase account, (Account account) { balance = MoneroBalance( fullBalance: monero_wallet.getFullBalance(accountIndex: account.id), @@ -99,6 +103,8 @@ abstract class MoneroWalletBase extends WalletBase init() async { accountList.update(); @@ -110,6 +116,7 @@ abstract class MoneroWalletBase extends WalletBase save() async { + await _updateWalletAllAddressesInBox(); + final now = DateTime.now().millisecondsSinceEpoch; if (now - _lastSaveTimestamp < Duration(seconds: 10).inMilliseconds) { @@ -446,25 +455,13 @@ abstract class MoneroWalletBase extends WalletBase updateAddressesInfo() async { - final Map _addresses = {}; - final _subaddressList = MoneroSubaddressList(); - - accountList.accounts.forEach((account) { - _subaddressList.update(accountIndex: account.id); - _subaddressList.subaddresses.forEach((subaddress) { - _addresses[subaddress.address] = subaddress.label; - }); - }); - - try { - walletInfo.addresses = _addresses; - walletInfo.address = address; - - await walletInfo.save(); - } catch (e) { - print(e.toString()); - } + Future _updateWalletAllAddressesInBox() async { + _walletAddressesCredentials + ..accountList = accountList + ..subaddressList = subaddressList; + await _walletAllAddresses.update(_walletAddressesCredentials); + subaddressList.update(accountIndex: account.id ?? 0); + subaddress = subaddressList.subaddresses.first; + address = subaddress.address; } } diff --git a/lib/monero/monero_wallet_addresses.dart b/lib/monero/monero_wallet_addresses.dart new file mode 100644 index 000000000..55680e1c9 --- /dev/null +++ b/lib/monero/monero_wallet_addresses.dart @@ -0,0 +1,38 @@ +import 'package:cake_wallet/entities/wallet_addresses.dart'; +import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; +import 'monero_wallet_addresses_credentials.dart'; + +class MoneroWalletAddresses extends WalletAddresses { + MoneroWalletAddresses(WalletInfo walletInfo) : super(walletInfo); + + @override + Future update(WalletAddressesCredentials credentials) async { + try { + if (credentials == null) { + return; + } + + final _credentials = credentials as MoneroWalletAddressesCredentials; + final _accountList = _credentials.accountList; + final _subaddressList = _credentials.subaddressList; + + if (_accountList == null || _subaddressList == null) { + return; + } + + addresses.clear(); + + _accountList.accounts.forEach((account) { + _subaddressList.update(accountIndex: account.id); + _subaddressList.subaddresses.forEach((subaddress) { + addresses[subaddress.address] = subaddress.label; + }); + }); + + await save(); + } catch (e) { + print(e.toString()); + } + } +} \ No newline at end of file diff --git a/lib/monero/monero_wallet_addresses_credentials.dart b/lib/monero/monero_wallet_addresses_credentials.dart new file mode 100644 index 000000000..0808cb127 --- /dev/null +++ b/lib/monero/monero_wallet_addresses_credentials.dart @@ -0,0 +1,9 @@ +import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; +import 'package:cake_wallet/monero/monero_account_list.dart'; +import 'package:cake_wallet/monero/monero_subaddress_list.dart'; + +class MoneroWalletAddressesCredentials extends WalletAddressesCredentials { + + MoneroAccountList accountList; + MoneroSubaddressList subaddressList; +} \ No newline at end of file diff --git a/lib/monero/monero_wallet_service.dart b/lib/monero/monero_wallet_service.dart index 17b02dcbb..7795b8700 100644 --- a/lib/monero/monero_wallet_service.dart +++ b/lib/monero/monero_wallet_service.dart @@ -126,7 +126,6 @@ class MoneroWalletService extends WalletService< } await wallet.init(); - await wallet.updateAddressesInfo(); return wallet; } catch (e) { diff --git a/lib/view_model/contact_list/contact_list_view_model.dart b/lib/view_model/contact_list/contact_list_view_model.dart index b5143cffa..1a8bbc021 100644 --- a/lib/view_model/contact_list/contact_list_view_model.dart +++ b/lib/view_model/contact_list/contact_list_view_model.dart @@ -18,18 +18,17 @@ abstract class ContactListViewModelBase with Store { : contacts = ObservableList(), 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, + if (info.addresses?.isNotEmpty ?? false) { + info.addresses?.forEach((address, label) { + final name = label.isNotEmpty + ? info.name + ' ($label)' + : info.name; + + walletContacts.add(WalletContact( + address, + name, walletTypeToCryptoCurrency(info.type))); - } + }); } }); diff --git a/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart b/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart index cf999e414..a86fa2773 100644 --- a/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart +++ b/lib/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart @@ -42,8 +42,7 @@ abstract class MoneroAccountEditOrCreateViewModelBase with Store { await _moneroAccountList.addAccount(label: label); } - await _wallet.updateAddressesInfo(); - + await _wallet.save(); state = ExecutedSuccessfullyState(); } catch (e) { state = FailureState(e.toString()); diff --git a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart index 6b6873cd5..b018c542d 100644 --- a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart @@ -54,8 +54,6 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store { await _createNew(); } - await _wallet.updateAddressesInfo(); - state = AddressSavedSuccessfully(); } catch (e) { state = AddressEditOrCreateStateFailure(error: e.toString()); diff --git a/lib/view_model/wallet_creation_vm.dart b/lib/view_model/wallet_creation_vm.dart index 54cad29c9..58ee24087 100644 --- a/lib/view_model/wallet_creation_vm.dart +++ b/lib/view_model/wallet_creation_vm.dart @@ -54,7 +54,6 @@ 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()); From 0d367c4b455c2ea9972649aad731f725754471dc Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Tue, 13 Jul 2021 08:46:34 +0300 Subject: [PATCH 4/4] CAKE-343 | added bitcoin_wallet_addresses.dart and litecoin_wallet_addresses.dart tj the app; moved addresses from wallets to wallet addresses classes; deleted wallet addresses credentials --- lib/bitcoin/bitcoin_wallet.dart | 16 +-- lib/bitcoin/bitcoin_wallet_addresses.dart | 33 +++++ lib/bitcoin/electrum_wallet.dart | 100 ++------------- lib/bitcoin/electrum_wallet_addresses.dart | 119 +++++++++++++++--- ...electrum_wallet_addresses_credentials.dart | 7 -- lib/bitcoin/litecoin_wallet.dart | 36 ++---- lib/bitcoin/litecoin_wallet_addresses.dart | 54 ++++++++ lib/buy/buy_provider.dart | 2 +- lib/core/wallet_base.dart | 7 +- lib/di.dart | 2 +- lib/entities/wallet_addresses.dart | 18 ++- .../wallet_addresses_credentials.dart | 1 - lib/monero/monero_wallet.dart | 90 +++---------- lib/monero/monero_wallet_addresses.dart | 87 ++++++++++--- .../monero_wallet_addresses_credentials.dart | 9 -- lib/monero/monero_wallet_service.dart | 2 +- lib/reactions/on_current_wallet_change.dart | 2 +- lib/src/screens/exchange/exchange_page.dart | 14 ++- .../exchange/exchange_template_page.dart | 14 ++- .../dashboard/dashboard_view_model.dart | 24 ++-- .../exchange/exchange_view_model.dart | 9 +- .../monero_account_list_view_model.dart | 9 +- ...let_address_edit_or_create_view_model.dart | 20 +-- .../wallet_address_list_view_model.dart | 19 +-- lib/view_model/wallet_creation_vm.dart | 2 +- 25 files changed, 384 insertions(+), 312 deletions(-) create mode 100644 lib/bitcoin/bitcoin_wallet_addresses.dart delete mode 100644 lib/bitcoin/electrum_wallet_addresses_credentials.dart create mode 100644 lib/bitcoin/litecoin_wallet_addresses.dart delete mode 100644 lib/entities/wallet_addresses_credentials.dart delete mode 100644 lib/monero/monero_wallet_addresses_credentials.dart diff --git a/lib/bitcoin/bitcoin_wallet.dart b/lib/bitcoin/bitcoin_wallet.dart index fd8402887..02af295fc 100644 --- a/lib/bitcoin/bitcoin_wallet.dart +++ b/lib/bitcoin/bitcoin_wallet.dart @@ -1,12 +1,12 @@ import 'package:mobx/mobx.dart'; import 'package:flutter/foundation.dart'; import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; -import 'package:cake_wallet/bitcoin/utils.dart'; import 'package:cake_wallet/bitcoin/electrum_wallet_snapshot.dart'; import 'package:cake_wallet/bitcoin/electrum_wallet.dart'; import 'package:cake_wallet/entities/wallet_info.dart'; import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; import 'package:cake_wallet/bitcoin/electrum_balance.dart'; +import 'package:cake_wallet/bitcoin/bitcoin_wallet_addresses.dart'; part 'bitcoin_wallet.g.dart'; @@ -26,8 +26,14 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { walletInfo: walletInfo, networkType: bitcoin.bitcoin, initialAddresses: initialAddresses, - initialBalance: initialBalance, - accountIndex: accountIndex); + initialBalance: initialBalance) { + walletAddresses = BitcoinWalletAddresses( + walletInfo, + initialAddresses: initialAddresses, + accountIndex: accountIndex, + hd: hd, + networkType: networkType); + } static Future open({ @required String name, @@ -44,8 +50,4 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { initialBalance: snp.balance, accountIndex: snp.accountIndex); } - - @override - String getAddress({@required int index, @required bitcoin.HDWallet hd}) => - generateP2WPKHAddress(hd: hd, index: index, networkType: networkType); } diff --git a/lib/bitcoin/bitcoin_wallet_addresses.dart b/lib/bitcoin/bitcoin_wallet_addresses.dart new file mode 100644 index 000000000..ecded3cb8 --- /dev/null +++ b/lib/bitcoin/bitcoin_wallet_addresses.dart @@ -0,0 +1,33 @@ +import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; +import 'package:cake_wallet/bitcoin/utils.dart'; +import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; +import 'package:cake_wallet/bitcoin/electrum_wallet_addresses.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; +import 'package:flutter/foundation.dart'; +import 'package:mobx/mobx.dart'; + +part 'bitcoin_wallet_addresses.g.dart'; + +class BitcoinWalletAddresses = BitcoinWalletAddressesBase + with _$BitcoinWalletAddresses; + +abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses + with Store { + BitcoinWalletAddressesBase( + WalletInfo walletInfo, + {@required List initialAddresses, + int accountIndex = 0, + @required bitcoin.HDWallet hd, + @required this.networkType}) + : super( + walletInfo, + initialAddresses: initialAddresses, + accountIndex: accountIndex, + hd: hd); + + bitcoin.NetworkType networkType; + + @override + String getAddress({@required int index, @required bitcoin.HDWallet hd}) => + generateP2WPKHAddress(hd: hd, index: index, networkType: networkType); +} \ No newline at end of file diff --git a/lib/bitcoin/electrum_wallet.dart b/lib/bitcoin/electrum_wallet.dart index d0b1c9a6c..38fc192de 100644 --- a/lib/bitcoin/electrum_wallet.dart +++ b/lib/bitcoin/electrum_wallet.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:convert'; import 'package:cake_wallet/bitcoin/electrum_wallet_addresses.dart'; -import 'package:cake_wallet/bitcoin/electrum_wallet_addresses_credentials.dart'; import 'package:mobx/mobx.dart'; import 'package:rxdart/subjects.dart'; import 'package:flutter/foundation.dart'; @@ -44,18 +43,14 @@ abstract class ElectrumWalletBase extends WalletBase.of( - (initialAddresses ?? []).toSet()), syncStatus = NotConnectedSyncStatus(), _password = password, - _accountIndex = accountIndex, _feeRates = [], _isTransactionUpdating = false, super(walletInfo) { @@ -65,8 +60,6 @@ abstract class ElectrumWalletBase extends WalletBase @@ -78,8 +71,7 @@ abstract class ElectrumWalletBase extends WalletBase addresses; - - List get scriptHashes => addresses + List get scriptHashes => walletAddresses.addresses .map((addr) => scriptHash(addr.address, networkType: networkType)) .toList(); String get xpub => hd.base58; - ElectrumWalletAddresses _walletAddressInBox; - ElectrumWalletAddressesCredentials _walletAddressInBoxCredentials; - @override String get seed => mnemonic; @@ -112,81 +99,21 @@ abstract class ElectrumWalletBase extends WalletBase _unspent; List _feeRates; - int _accountIndex; Map> _scripthashesUpdateSubject; bool _isTransactionUpdating; Future init() async { - await generateAddresses(); - address = addresses[_accountIndex].address; + await walletAddresses.init(); await transactionHistory.init(); - await _updateWalletAddressInBox(); - } - - @action - Future nextAddress() async { - _accountIndex += 1; - - if (_accountIndex >= addresses.length) { - _accountIndex = 0; - } - - address = addresses[_accountIndex].address; - await save(); } - Future generateAddresses() async { - if (addresses.length < 33) { - final addressesCount = 33 - addresses.length; - await generateNewAddresses(addressesCount, - startIndex: addresses.length, hd: hd); - } - } - - Future generateNewAddress( - {bool isHidden = false, bitcoin.HDWallet hd}) async { - _accountIndex += 1; - final _hd = hd ?? this.hd; - final address = BitcoinAddressRecord( - getAddress(index: _accountIndex, hd: _hd), - index: _accountIndex, - isHidden: isHidden); - addresses.add(address); - await save(); - return address; - } - - Future> generateNewAddresses(int count, - {int startIndex = 0, bitcoin.HDWallet hd, bool isHidden = false}) async { - final list = []; - - for (var i = startIndex; i < count + startIndex; i++) { - final address = BitcoinAddressRecord(getAddress(index: i, hd: hd), - index: i, isHidden: isHidden); - list.add(address); - } - - addresses.addAll(list); - await save(); - return list; - } - - Future updateAddress(String address) async { - for (final addr in addresses) { - if (addr.address == address) { - await save(); - break; - } - } - } - @action @override Future startSync() async { try { syncStatus = StartingSyncStatus(); - updateTransactions(); + await updateTransactions(); _subscribeForUpdates(); await _updateBalance(); await _updateUnspent(); @@ -238,7 +165,7 @@ abstract class ElectrumWalletBase extends WalletBase json.encode({ 'mnemonic': mnemonic, - 'account_index': _accountIndex.toString(), - 'addresses': addresses.map((addr) => addr.toJSON()).toList(), + 'account_index': walletAddresses.accountIndex.toString(), + 'addresses': walletAddresses.addresses.map((addr) => addr.toJSON()).toList(), 'balance': balance?.toJSON() }); @@ -370,7 +297,6 @@ abstract class ElectrumWalletBase extends WalletBase @@ -386,13 +312,12 @@ abstract class ElectrumWalletBase extends WalletBase ''; - Future makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type); Future _updateUnspent() async { - final unspent = await Future.wait(addresses.map((address) => electrumClient + final unspent = await Future.wait(walletAddresses + .addresses.map((address) => electrumClient .getListUnspentWithAddress(address.address, networkType) .then((unspent) => unspent .map((unspent) => BitcoinUnspent.fromJSON(address, unspent))))); @@ -403,7 +328,7 @@ abstract class ElectrumWalletBase extends WalletBase _updateWalletAddressInBox() async { - _walletAddressInBoxCredentials.address = address; - await _walletAddressInBox.update(_walletAddressInBoxCredentials); - } } diff --git a/lib/bitcoin/electrum_wallet_addresses.dart b/lib/bitcoin/electrum_wallet_addresses.dart index ac4895ae8..843ac4065 100644 --- a/lib/bitcoin/electrum_wallet_addresses.dart +++ b/lib/bitcoin/electrum_wallet_addresses.dart @@ -1,30 +1,109 @@ -import 'package:cake_wallet/bitcoin/electrum_wallet_addresses_credentials.dart'; +import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; +import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; import 'package:cake_wallet/entities/wallet_addresses.dart'; -import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; import 'package:cake_wallet/entities/wallet_info.dart'; +import 'package:flutter/foundation.dart'; +import 'package:mobx/mobx.dart'; -class ElectrumWalletAddresses extends WalletAddresses { - ElectrumWalletAddresses(WalletInfo walletInfo) : super(walletInfo); +part 'electrum_wallet_addresses.g.dart'; + +class ElectrumWalletAddresses = ElectrumWalletAddressesBase + with _$ElectrumWalletAddresses; + +abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store { + ElectrumWalletAddressesBase(WalletInfo walletInfo, + {@required List initialAddresses, + int accountIndex = 0, + @required bitcoin.HDWallet hd}) + : super(walletInfo) { + this.hd = hd; + this.accountIndex = accountIndex; + addresses = ObservableList.of( + (initialAddresses ?? []).toSet()); + } @override - Future update(WalletAddressesCredentials credentials) async { + @observable + String address; + + bitcoin.HDWallet hd; + + ObservableList addresses; + + int accountIndex; + + @override + Future init() async { + await generateAddresses(); + address = addresses[accountIndex].address; + await updateAddressesInBox(); + } + + @action + Future nextAddress() async { + accountIndex += 1; + + if (accountIndex >= addresses.length) { + accountIndex = 0; + } + + address = addresses[accountIndex].address; + + await updateAddressesInBox(); + } + + Future generateAddresses() async { + if (addresses.length < 33) { + final addressesCount = 33 - addresses.length; + await generateNewAddresses(addressesCount, + startIndex: addresses.length, hd: hd); + } + } + + Future generateNewAddress( + {bool isHidden = false, bitcoin.HDWallet hd}) async { + accountIndex += 1; + final _hd = hd ?? this.hd; + final address = BitcoinAddressRecord( + getAddress(index: accountIndex, hd: _hd), + index: accountIndex, + isHidden: isHidden); + addresses.add(address); + return address; + } + + Future> generateNewAddresses(int count, + {int startIndex = 0, bitcoin.HDWallet hd, bool isHidden = false}) async { + final list = []; + + for (var i = startIndex; i < count + startIndex; i++) { + final address = BitcoinAddressRecord(getAddress(index: i, hd: hd), + index: i, isHidden: isHidden); + list.add(address); + } + + addresses.addAll(list); + return list; + } + + /*Future updateAddress(String address) async { + for (final addr in addresses) { + if (addr.address == address) { + await save(); + break; + } + } + }*/ + + String getAddress({@required int index, @required bitcoin.HDWallet hd}) => ''; + + @override + Future updateAddressesInBox() async { try { - if (credentials == null) { - return; - } + addressesMap.clear(); + addressesMap[address] = ''; - final _credentials = credentials as ElectrumWalletAddressesCredentials; - final _address = _credentials.address; - final _label = ''; - - if (_address == null || _address.isEmpty) { - return; - } - - addresses.clear(); - addresses[_address] = _label; - - await save(); + await saveAddressesInBox(); } catch (e) { print(e.toString()); } diff --git a/lib/bitcoin/electrum_wallet_addresses_credentials.dart b/lib/bitcoin/electrum_wallet_addresses_credentials.dart deleted file mode 100644 index 30a41f8ff..000000000 --- a/lib/bitcoin/electrum_wallet_addresses_credentials.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; - -class ElectrumWalletAddressesCredentials extends WalletAddressesCredentials { - ElectrumWalletAddressesCredentials(); - - String address; -} \ No newline at end of file diff --git a/lib/bitcoin/litecoin_wallet.dart b/lib/bitcoin/litecoin_wallet.dart index 209d1904e..bfb7da6d6 100644 --- a/lib/bitcoin/litecoin_wallet.dart +++ b/lib/bitcoin/litecoin_wallet.dart @@ -1,6 +1,5 @@ -import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; -import 'package:cake_wallet/bitcoin/bitcoin_mnemonic.dart'; import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart'; +import 'package:cake_wallet/bitcoin/litecoin_wallet_addresses.dart'; import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:flutter/foundation.dart'; import 'package:mobx/mobx.dart'; @@ -10,7 +9,6 @@ import 'package:cake_wallet/bitcoin/electrum_wallet.dart'; import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; import 'package:cake_wallet/bitcoin/electrum_balance.dart'; import 'package:cake_wallet/bitcoin/litecoin_network.dart'; -import 'package:cake_wallet/bitcoin/utils.dart'; part 'litecoin_wallet.g.dart'; @@ -30,8 +28,15 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { walletInfo: walletInfo, networkType: litecoinNetwork, initialAddresses: initialAddresses, - initialBalance: initialBalance, - accountIndex: accountIndex); + initialBalance: initialBalance) { + walletAddresses = LitecoinWalletAddresses( + walletInfo, + initialAddresses: initialAddresses, + accountIndex: accountIndex, + hd: hd, + networkType: networkType, + mnemonic: mnemonic); + } static Future open({ @required String name, @@ -49,27 +54,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { accountIndex: snp.accountIndex); } - @override - String getAddress({@required int index, @required bitcoin.HDWallet hd}) => - generateP2WPKHAddress(hd: hd, index: index, networkType: networkType); - - @override - Future generateAddresses() async { - if (addresses.length < 33) { - final addressesCount = 22 - addresses.length; - await generateNewAddresses(addressesCount, - hd: hd, startIndex: addresses.length); - - final changeRoot = bitcoin.HDWallet.fromSeed( - mnemonicToSeedBytes(mnemonic), - network: networkType) - .derivePath("m/0'/1"); - - await generateNewAddresses(11, - startIndex: 0, hd: changeRoot, isHidden: true); - } - } - @override int feeRate(TransactionPriority priority) { if (priority is LitecoinTransactionPriority) { diff --git a/lib/bitcoin/litecoin_wallet_addresses.dart b/lib/bitcoin/litecoin_wallet_addresses.dart new file mode 100644 index 000000000..19ade7566 --- /dev/null +++ b/lib/bitcoin/litecoin_wallet_addresses.dart @@ -0,0 +1,54 @@ +import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; +import 'package:cake_wallet/bitcoin/bitcoin_mnemonic.dart'; +import 'package:cake_wallet/bitcoin/utils.dart'; +import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; +import 'package:cake_wallet/bitcoin/electrum_wallet_addresses.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; +import 'package:flutter/foundation.dart'; +import 'package:mobx/mobx.dart'; + +part 'litecoin_wallet_addresses.g.dart'; + +class LitecoinWalletAddresses = LitecoinWalletAddressesBase + with _$LitecoinWalletAddresses; + +abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses + with Store { + LitecoinWalletAddressesBase( + WalletInfo walletInfo, + {@required List initialAddresses, + int accountIndex = 0, + @required bitcoin.HDWallet hd, + @required this.networkType, + @required this.mnemonic}) + : super( + walletInfo, + initialAddresses: initialAddresses, + accountIndex: accountIndex, + hd: hd); + + bitcoin.NetworkType networkType; + + final String mnemonic; + + @override + String getAddress({@required int index, @required bitcoin.HDWallet hd}) => + generateP2WPKHAddress(hd: hd, index: index, networkType: networkType); + + @override + Future generateAddresses() async { + if (addresses.length < 33) { + final addressesCount = 22 - addresses.length; + await generateNewAddresses(addressesCount, + hd: hd, startIndex: addresses.length); + + final changeRoot = bitcoin.HDWallet.fromSeed( + mnemonicToSeedBytes(mnemonic), + network: networkType) + .derivePath("m/0'/1"); + + await generateNewAddresses(11, + startIndex: 0, hd: changeRoot, isHidden: true); + } + } +} \ No newline at end of file diff --git a/lib/buy/buy_provider.dart b/lib/buy/buy_provider.dart index b908d7bc5..dc450ad7e 100644 --- a/lib/buy/buy_provider.dart +++ b/lib/buy/buy_provider.dart @@ -15,7 +15,7 @@ abstract class BuyProvider { String get trackUrl; WalletType get walletType => wallet.type; - String get walletAddress => wallet.address; + String get walletAddress => wallet.walletAddresses.address; String get walletId => wallet.id; @override diff --git a/lib/core/wallet_base.dart b/lib/core/wallet_base.dart index f6ed64142..edcb05466 100644 --- a/lib/core/wallet_base.dart +++ b/lib/core/wallet_base.dart @@ -1,6 +1,7 @@ import 'package:cake_wallet/entities/balance.dart'; import 'package:cake_wallet/entities/transaction_info.dart'; import 'package:cake_wallet/entities/transaction_priority.dart'; +import 'package:cake_wallet/entities/wallet_addresses.dart'; import 'package:flutter/foundation.dart'; import 'package:cake_wallet/entities/wallet_info.dart'; import 'package:cake_wallet/core/pending_transaction.dart'; @@ -30,9 +31,9 @@ abstract class WalletBase< String get name => walletInfo.name; - String get address; + //String get address; - set address(String address); + //set address(String address); BalanceType get balance; @@ -44,6 +45,8 @@ abstract class WalletBase< Object get keys; + WalletAddresses get walletAddresses; + HistoryType transactionHistory; Future connectToNode({@required Node node}); diff --git a/lib/di.dart b/lib/di.dart index 1f5350370..3b709d707 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -361,7 +361,7 @@ Future setup( getIt.registerFactoryParam( (AccountListItem account, _) => MoneroAccountEditOrCreateViewModel( - (getIt.get().wallet as MoneroWallet).accountList, + (getIt.get().wallet as MoneroWallet).walletAddresses.accountList, wallet: getIt.get().wallet, accountListItem: account)); diff --git a/lib/entities/wallet_addresses.dart b/lib/entities/wallet_addresses.dart index 81b4fdea7..cd5331911 100644 --- a/lib/entities/wallet_addresses.dart +++ b/lib/entities/wallet_addresses.dart @@ -1,24 +1,30 @@ -import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; import 'package:cake_wallet/entities/wallet_info.dart'; abstract class WalletAddresses { WalletAddresses(this.walletInfo) { - addresses = walletInfo?.addresses ?? {}; + addressesMap = {}; } final WalletInfo walletInfo; - Map addresses; + String get address; - Future update(WalletAddressesCredentials credentials); + set address(String address); - Future save() async { + Map addressesMap; + + Future init(); + + Future updateAddressesInBox(); + + Future saveAddressesInBox() async { try { if (walletInfo == null) { return; } - walletInfo.addresses = addresses; + walletInfo.address = address; + walletInfo.addresses = addressesMap; if (walletInfo.isInBox) { await walletInfo.save(); diff --git a/lib/entities/wallet_addresses_credentials.dart b/lib/entities/wallet_addresses_credentials.dart deleted file mode 100644 index fe3d2c927..000000000 --- a/lib/entities/wallet_addresses_credentials.dart +++ /dev/null @@ -1 +0,0 @@ -abstract class WalletAddressesCredentials {} \ No newline at end of file diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index 77cd2f53f..411982a88 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -4,7 +4,6 @@ import 'package:cake_wallet/monero/monero_amount_format.dart'; import 'package:cake_wallet/monero/monero_transaction_creation_exception.dart'; import 'package:cake_wallet/monero/monero_transaction_info.dart'; import 'package:cake_wallet/monero/monero_wallet_addresses.dart'; -import 'package:cake_wallet/monero/monero_wallet_addresses_credentials.dart'; import 'package:flutter/foundation.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_monero/transaction_history.dart' @@ -17,10 +16,7 @@ import 'package:cake_wallet/monero/pending_monero_transaction.dart'; import 'package:cake_wallet/monero/monero_wallet_keys.dart'; import 'package:cake_wallet/monero/monero_balance.dart'; import 'package:cake_wallet/monero/monero_transaction_history.dart'; -import 'package:cake_wallet/monero/monero_subaddress_list.dart'; -import 'package:cake_wallet/monero/monero_account_list.dart'; import 'package:cake_wallet/monero/account.dart'; -import 'package:cake_wallet/monero/subaddress.dart'; import 'package:cake_wallet/core/pending_transaction.dart'; import 'package:cake_wallet/core/wallet_base.dart'; import 'package:cake_wallet/entities/sync_status.dart'; @@ -37,9 +33,7 @@ class MoneroWallet = MoneroWalletBase with _$MoneroWallet; abstract class MoneroWalletBase extends WalletBase with Store { MoneroWalletBase({WalletInfo walletInfo}) - : accountList = MoneroAccountList(), - subaddressList = MoneroSubaddressList(), - super(walletInfo) { + : super(walletInfo) { transactionHistory = MoneroTransactionHistory(); balance = MoneroBalance( fullBalance: monero_wallet.getFullBalance(accountIndex: 0), @@ -49,35 +43,26 @@ abstract class MoneroWalletBase extends WalletBase account, (Account account) { + walletAddresses = MoneroWalletAddresses(walletInfo); + _onAccountChangeReaction = reaction((_) => walletAddresses.account, + (Account account) { balance = MoneroBalance( fullBalance: monero_wallet.getFullBalance(accountIndex: account.id), unlockedBalance: monero_wallet.getUnlockedBalance(accountIndex: account.id)); - subaddressList.update(accountIndex: account.id); - subaddress = subaddressList.subaddresses.first; - address = subaddress.address; + walletAddresses.updateSubaddressList(accountIndex: account.id); }); } static const int _autoAfterSyncSaveInterval = 60000; - @observable - Account account; - - @observable - Subaddress subaddress; + @override + MoneroWalletAddresses walletAddresses; @override @observable SyncStatus syncStatus; - @override - @observable - String address; - @override @observable MoneroBalance balance; @@ -92,10 +77,6 @@ abstract class MoneroWalletBase extends WalletBase init() async { - accountList.update(); - account = accountList.accounts.first; - subaddressList.update(accountIndex: account.id ?? 0); - subaddress = subaddressList.getAll().first; + await walletAddresses.init(); balance = MoneroBalance( - fullBalance: monero_wallet.getFullBalance(accountIndex: account.id), + fullBalance: monero_wallet.getFullBalance(accountIndex: walletAddresses.account.id), unlockedBalance: - monero_wallet.getUnlockedBalance(accountIndex: account.id)); - address = subaddress.address; - await _updateWalletAllAddressesInBox(); + monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account.id)); _setListeners(); await updateTransactions(); @@ -136,24 +110,6 @@ abstract class MoneroWalletBase extends WalletBase connectToNode({@required Node node}) async { try { @@ -196,7 +152,7 @@ abstract class MoneroWalletBase extends WalletBase save() async { - await _updateWalletAllAddressesInBox(); + await walletAddresses.updateAddressesInBox(); final now = DateTime.now().millisecondsSinceEpoch; @@ -274,7 +230,7 @@ abstract class MoneroWalletBase extends WalletBase - monero_wallet.getFullBalance(accountIndex: account.id); + monero_wallet.getFullBalance(accountIndex: walletAddresses.account.id); int _getUnlockedBalance() => - monero_wallet.getUnlockedBalance(accountIndex: account.id); + monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account.id); Future _afterSyncSave() async { try { @@ -423,13 +379,13 @@ abstract class MoneroWalletBase extends WalletBase _updateWalletAllAddressesInBox() async { - _walletAddressesCredentials - ..accountList = accountList - ..subaddressList = subaddressList; - await _walletAllAddresses.update(_walletAddressesCredentials); - subaddressList.update(accountIndex: account.id ?? 0); - subaddress = subaddressList.subaddresses.first; - address = subaddress.address; - } } diff --git a/lib/monero/monero_wallet_addresses.dart b/lib/monero/monero_wallet_addresses.dart index 55680e1c9..d14caa27b 100644 --- a/lib/monero/monero_wallet_addresses.dart +++ b/lib/monero/monero_wallet_addresses.dart @@ -1,38 +1,85 @@ import 'package:cake_wallet/entities/wallet_addresses.dart'; -import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; import 'package:cake_wallet/entities/wallet_info.dart'; -import 'monero_wallet_addresses_credentials.dart'; +import 'package:cake_wallet/monero/account.dart'; +import 'package:cake_wallet/monero/monero_account_list.dart'; +import 'package:cake_wallet/monero/monero_subaddress_list.dart'; +import 'package:cake_wallet/monero/subaddress.dart'; +import 'package:mobx/mobx.dart'; -class MoneroWalletAddresses extends WalletAddresses { - MoneroWalletAddresses(WalletInfo walletInfo) : super(walletInfo); +part 'monero_wallet_addresses.g.dart'; + +class MoneroWalletAddresses = MoneroWalletAddressesBase + with _$MoneroWalletAddresses; + +abstract class MoneroWalletAddressesBase extends WalletAddresses with Store { + MoneroWalletAddressesBase(WalletInfo walletInfo) : super(walletInfo) { + accountList = MoneroAccountList(); + subaddressList = MoneroSubaddressList(); + } @override - Future update(WalletAddressesCredentials credentials) async { + @observable + String address; + + @observable + Account account; + + @observable + Subaddress subaddress; + + MoneroSubaddressList subaddressList; + + MoneroAccountList accountList; + + @override + Future init() async { + accountList.update(); + account = accountList.accounts.first; + updateSubaddressList(accountIndex: account.id ?? 0); + await updateAddressesInBox(); + } + + @override + Future updateAddressesInBox() async { try { - if (credentials == null) { - return; - } + final _subaddressList = MoneroSubaddressList(); - final _credentials = credentials as MoneroWalletAddressesCredentials; - final _accountList = _credentials.accountList; - final _subaddressList = _credentials.subaddressList; + addressesMap.clear(); - if (_accountList == null || _subaddressList == null) { - return; - } - - addresses.clear(); - - _accountList.accounts.forEach((account) { + accountList.accounts.forEach((account) { _subaddressList.update(accountIndex: account.id); _subaddressList.subaddresses.forEach((subaddress) { - addresses[subaddress.address] = subaddress.label; + addressesMap[subaddress.address] = subaddress.label; }); }); - await save(); + await saveAddressesInBox(); } catch (e) { print(e.toString()); } } + + bool validate() { + accountList.update(); + final accountListLength = accountList.accounts?.length ?? 0; + + if (accountListLength <= 0) { + return false; + } + + subaddressList.update(accountIndex: accountList.accounts.first.id); + final subaddressListLength = subaddressList.subaddresses?.length ?? 0; + + if (subaddressListLength <= 0) { + return false; + } + + return true; + } + + void updateSubaddressList({int accountIndex}) { + subaddressList.update(accountIndex: accountIndex); + subaddress = subaddressList.subaddresses.first; + address = subaddress.address; + } } \ No newline at end of file diff --git a/lib/monero/monero_wallet_addresses_credentials.dart b/lib/monero/monero_wallet_addresses_credentials.dart deleted file mode 100644 index 0808cb127..000000000 --- a/lib/monero/monero_wallet_addresses_credentials.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:cake_wallet/entities/wallet_addresses_credentials.dart'; -import 'package:cake_wallet/monero/monero_account_list.dart'; -import 'package:cake_wallet/monero/monero_subaddress_list.dart'; - -class MoneroWalletAddressesCredentials extends WalletAddressesCredentials { - - MoneroAccountList accountList; - MoneroSubaddressList subaddressList; -} \ No newline at end of file diff --git a/lib/monero/monero_wallet_service.dart b/lib/monero/monero_wallet_service.dart index 7795b8700..67db056d9 100644 --- a/lib/monero/monero_wallet_service.dart +++ b/lib/monero/monero_wallet_service.dart @@ -117,7 +117,7 @@ class MoneroWalletService extends WalletService< (info) => info.id == WalletBase.idFor(name, getType()), orElse: () => null); final wallet = MoneroWallet(walletInfo: walletInfo); - final isValid = wallet.validate(); + final isValid = wallet.walletAddresses.validate(); if (!isValid) { await _removeCache(name); diff --git a/lib/reactions/on_current_wallet_change.dart b/lib/reactions/on_current_wallet_change.dart index 428f2703e..5c702b0af 100644 --- a/lib/reactions/on_current_wallet_change.dart +++ b/lib/reactions/on_current_wallet_change.dart @@ -37,7 +37,7 @@ void startCurrentWalletChangeReaction(AppStore appStore, await wallet.connectToNode(node: node); if (wallet.walletInfo.address?.isEmpty ?? true) { - wallet.walletInfo.address = wallet.address; + wallet.walletInfo.address = wallet.walletAddresses.address; if (wallet.walletInfo.isInBox) { await wallet.walletInfo.save(); diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index 3eb23da3a..6b4e9e3cb 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -179,7 +179,7 @@ class ExchangePage extends BasePage { initialAddress: exchangeViewModel.depositCurrency == exchangeViewModel.wallet.currency - ? exchangeViewModel.wallet.address + ? exchangeViewModel.wallet.walletAddresses.address : exchangeViewModel.depositAddress, initialIsAmountEditable: true, initialIsAddressEditable: @@ -240,7 +240,7 @@ class ExchangePage extends BasePage { initialAddress: exchangeViewModel .receiveCurrency == exchangeViewModel.wallet.currency - ? exchangeViewModel.wallet.address + ? exchangeViewModel.wallet.walletAddresses.address : exchangeViewModel.receiveAddress, initialIsAmountEditable: exchangeViewModel .isReceiveAmountEditable, @@ -646,7 +646,8 @@ class ExchangePage extends BasePage { } }); - reaction((_) => exchangeViewModel.wallet.address, (String address) { + reaction((_) => exchangeViewModel.wallet.walletAddresses.address, + (String address) { if (exchangeViewModel.depositCurrency == CryptoCurrency.xmr) { depositKey.currentState.changeAddress(address: address); } @@ -707,7 +708,8 @@ class ExchangePage extends BasePage { isCurrentTypeWallet ? exchangeViewModel.wallet.name : null); key.currentState.changeAddress( - address: isCurrentTypeWallet ? exchangeViewModel.wallet.address : ''); + address: isCurrentTypeWallet + ? exchangeViewModel.wallet.walletAddresses.address : ''); key.currentState.changeAmount(amount: ''); } @@ -719,9 +721,9 @@ class ExchangePage extends BasePage { if (isCurrentTypeWallet) { key.currentState.changeWalletName(exchangeViewModel.wallet.name); key.currentState.addressController.text = - exchangeViewModel.wallet.address; + exchangeViewModel.wallet.walletAddresses.address; } else if (key.currentState.addressController.text == - exchangeViewModel.wallet.address) { + exchangeViewModel.wallet.walletAddresses.address) { key.currentState.changeWalletName(null); key.currentState.addressController.text = null; } diff --git a/lib/src/screens/exchange/exchange_template_page.dart b/lib/src/screens/exchange/exchange_template_page.dart index 7df55f320..c978a535f 100644 --- a/lib/src/screens/exchange/exchange_template_page.dart +++ b/lib/src/screens/exchange/exchange_template_page.dart @@ -129,7 +129,7 @@ class ExchangeTemplatePage extends BasePage { initialAddress: exchangeViewModel .depositCurrency == exchangeViewModel.wallet.currency - ? exchangeViewModel.wallet.address + ? exchangeViewModel.wallet.walletAddresses.address : exchangeViewModel.depositAddress, initialIsAmountEditable: true, initialIsAddressEditable: exchangeViewModel @@ -168,7 +168,7 @@ class ExchangeTemplatePage extends BasePage { initialAddress: exchangeViewModel.receiveCurrency == exchangeViewModel.wallet.currency - ? exchangeViewModel.wallet.address + ? exchangeViewModel.wallet.walletAddresses.address : exchangeViewModel.receiveAddress, initialIsAmountEditable: exchangeViewModel.provider is @@ -383,7 +383,8 @@ class ExchangeTemplatePage extends BasePage { } }); - reaction((_) => exchangeViewModel.wallet.address, (String address) { + reaction((_) => exchangeViewModel.wallet.walletAddresses.address, + (String address) { if (exchangeViewModel.depositCurrency == CryptoCurrency.xmr) { depositKey.currentState.changeAddress(address: address); } @@ -405,7 +406,8 @@ class ExchangeTemplatePage extends BasePage { isCurrentTypeWallet ? exchangeViewModel.wallet.name : null); key.currentState.changeAddress( - address: isCurrentTypeWallet ? exchangeViewModel.wallet.address : ''); + address: isCurrentTypeWallet + ? exchangeViewModel.wallet.walletAddresses.address : ''); key.currentState.changeAmount(amount: ''); } @@ -417,9 +419,9 @@ class ExchangeTemplatePage extends BasePage { if (isCurrentTypeWallet) { key.currentState.changeWalletName(exchangeViewModel.wallet.name); key.currentState.addressController.text = - exchangeViewModel.wallet.address; + exchangeViewModel.wallet.walletAddresses.address; } else if (key.currentState.addressController.text == - exchangeViewModel.wallet.address) { + exchangeViewModel.wallet.walletAddresses.address) { key.currentState.changeWalletName(null); key.currentState.addressController.text = null; } diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index e35316d11..0777d3ecd 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -92,17 +92,17 @@ abstract class DashboardViewModelBase with Store { final _wallet = wallet; if (_wallet is MoneroWallet) { - subname = _wallet.account?.label; + subname = _wallet.walletAddresses.account?.label; - _onMoneroAccountChangeReaction = reaction((_) => _wallet.account, - (Account account) => _onMoneroAccountChange(_wallet)); + _onMoneroAccountChangeReaction = reaction((_) => _wallet.walletAddresses + .account, (Account account) => _onMoneroAccountChange(_wallet)); _onMoneroBalanceChangeReaction = reaction((_) => _wallet.balance, (MoneroBalance balance) => _onMoneroTransactionsUpdate(_wallet)); final _accountTransactions = _wallet .transactionHistory.transactions.values - .where((tx) => tx.accountIndex == _wallet.account.id) + .where((tx) => tx.accountIndex == _wallet.walletAddresses.account.id) .toList(); transactions = ObservableList.of(_accountTransactions.map((transaction) => @@ -131,7 +131,7 @@ abstract class DashboardViewModelBase with Store { filter: (TransactionInfo tx) { final wallet = _wallet; if (tx is MoneroTransactionInfo && wallet is MoneroWallet) { - return tx.accountIndex == wallet.account.id; + return tx.accountIndex == wallet.walletAddresses.account.id; } return true; @@ -153,7 +153,7 @@ abstract class DashboardViewModelBase with Store { String subname; @computed - String get address => wallet.address; + String get address => wallet.walletAddresses.address; @computed SyncStatus get status => wallet.syncStatus; @@ -251,13 +251,13 @@ abstract class DashboardViewModelBase with Store { wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24; if (wallet is MoneroWallet) { - subname = wallet.account?.label; + subname = wallet.walletAddresses.account?.label; _onMoneroAccountChangeReaction?.reaction?.dispose(); _onMoneroBalanceChangeReaction?.reaction?.dispose(); - _onMoneroAccountChangeReaction = reaction((_) => wallet.account, - (Account account) => _onMoneroAccountChange(wallet)); + _onMoneroAccountChangeReaction = reaction((_) => wallet.walletAddresses + .account, (Account account) => _onMoneroAccountChange(wallet)); _onMoneroBalanceChangeReaction = reaction((_) => wallet.balance, (MoneroBalance balance) => _onMoneroTransactionsUpdate(wallet)); @@ -284,7 +284,7 @@ abstract class DashboardViewModelBase with Store { settingsStore: appStore.settingsStore), filter: (TransactionInfo tx) { if (tx is MoneroTransactionInfo && wallet is MoneroWallet) { - return tx.accountIndex == wallet.account.id; + return tx.accountIndex == wallet.walletAddresses.account.id; } return true; @@ -293,7 +293,7 @@ abstract class DashboardViewModelBase with Store { @action void _onMoneroAccountChange(MoneroWallet wallet) { - subname = wallet.account?.label; + subname = wallet.walletAddresses.account?.label; _onMoneroTransactionsUpdate(wallet); } @@ -302,7 +302,7 @@ abstract class DashboardViewModelBase with Store { transactions.clear(); final _accountTransactions = wallet.transactionHistory.transactions.values - .where((tx) => tx.accountIndex == wallet.account.id) + .where((tx) => tx.accountIndex == wallet.walletAddresses.account.id) .toList(); transactions.addAll(_accountTransactions.map((transaction) => diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index f3f00cd77..01246542b 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -41,7 +41,8 @@ abstract class ExchangeViewModelBase with Store { depositAmount = ''; receiveAmount = ''; receiveAddress = ''; - depositAddress = depositCurrency == wallet.currency ? wallet.address : ''; + depositAddress = depositCurrency == wallet.currency + ? wallet.walletAddresses.address : ''; limitsState = LimitsInitialState(); tradeState = ExchangeTradeStateInitial(); _cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12; @@ -308,8 +309,10 @@ abstract class ExchangeViewModelBase with Store { isReceiveAmountEntered = false; depositAmount = ''; receiveAmount = ''; - depositAddress = depositCurrency == wallet.currency ? wallet.address : ''; - receiveAddress = receiveCurrency == wallet.currency ? wallet.address : ''; + depositAddress = depositCurrency == wallet.currency + ? wallet.walletAddresses.address : ''; + receiveAddress = receiveCurrency == wallet.currency + ? wallet.walletAddresses.address : ''; isDepositAddressEnabled = !(depositCurrency == wallet.currency); isReceiveAddressEnabled = !(receiveCurrency == wallet.currency); isFixedRateMode = false; diff --git a/lib/view_model/monero_account_list/monero_account_list_view_model.dart b/lib/view_model/monero_account_list/monero_account_list_view_model.dart index c6d6aa686..ca0eb67ef 100644 --- a/lib/view_model/monero_account_list/monero_account_list_view_model.dart +++ b/lib/view_model/monero_account_list/monero_account_list_view_model.dart @@ -20,15 +20,16 @@ abstract class MoneroAccountListViewModelBase with Store { } @computed - List get accounts => _moneroWallet.accountList.accounts - .map((acc) => AccountListItem( + List get accounts => _moneroWallet.walletAddresses + .accountList.accounts.map((acc) => AccountListItem( label: acc.label, id: acc.id, - isSelected: acc.id == _moneroWallet.account.id)) + isSelected: acc.id == _moneroWallet.walletAddresses.account.id)) .toList(); final MoneroWallet _moneroWallet; void select(AccountListItem item) => - _moneroWallet.account = Account(id: item.id, label: item.label); + _moneroWallet.walletAddresses.account = + Account(id: item.id, label: item.label); } diff --git a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart index b018c542d..3676b3bf6 100644 --- a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart @@ -64,12 +64,15 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store { final wallet = _wallet; if (wallet is ElectrumWallet) { - await wallet.generateNewAddress(); + await wallet.walletAddresses.generateNewAddress(); + await wallet.save(); } if (wallet is MoneroWallet) { - await wallet.subaddressList - .addSubaddress(accountIndex: wallet.account.id, label: label); + await wallet.walletAddresses.subaddressList + .addSubaddress( + accountIndex: wallet.walletAddresses.account.id, + label: label); await wallet.save(); } } @@ -77,13 +80,14 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store { Future _update() async { final wallet = _wallet; - if (wallet is BitcoinWallet) { - await wallet.updateAddress(_item.address as String); - } + /*if (wallet is BitcoinWallet) { + await wallet.walletAddresses.updateAddress(_item.address as String); + await wallet.save(); + }*/ if (wallet is MoneroWallet) { - await wallet.subaddressList.setLabelSubaddress( - accountIndex: wallet.account.id, + await wallet.walletAddresses.subaddressList.setLabelSubaddress( + accountIndex: wallet.walletAddresses.account.id, addressIndex: _item.id as int, label: label); await wallet.save(); diff --git a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart index b15443222..a4d6eff66 100644 --- a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart @@ -80,7 +80,7 @@ abstract class WalletAddressListViewModelBase with Store { @computed WalletAddressListItem get address => - WalletAddressListItem(address: _wallet.address); + WalletAddressListItem(address: _wallet.walletAddresses.address); @computed PaymentURI get uri { @@ -105,8 +105,10 @@ abstract class WalletAddressListViewModelBase with Store { final addressList = ObservableList(); if (wallet is MoneroWallet) { - final primaryAddress = wallet.subaddressList.subaddresses.first; - addressList.addAll(wallet.subaddressList.subaddresses.map((subaddress) { + final primaryAddress = + wallet.walletAddresses.subaddressList.subaddresses.first; + addressList.addAll(wallet.walletAddresses.subaddressList.subaddresses + .map((subaddress) { final isPrimary = subaddress == primaryAddress; return WalletAddressListItem( @@ -118,8 +120,8 @@ abstract class WalletAddressListViewModelBase with Store { } if (wallet is BitcoinWallet) { - final primaryAddress = wallet.addresses.first; - final bitcoinAddresses = wallet.addresses.map((addr) { + final primaryAddress = wallet.walletAddresses.addresses.first; + final bitcoinAddresses = wallet.walletAddresses.addresses.map((addr) { final isPrimary = addr == primaryAddress; return WalletAddressListItem( @@ -139,7 +141,7 @@ abstract class WalletAddressListViewModelBase with Store { final wallet = _wallet; if (wallet is MoneroWallet) { - return wallet.account.label; + return wallet.walletAddresses.account.label; } return null; @@ -160,7 +162,7 @@ abstract class WalletAddressListViewModelBase with Store { @action void setAddress(WalletAddressListItem address) => - _wallet.address = address.address; + _wallet.walletAddresses.address = address.address; void _init() { _baseItems = []; @@ -177,7 +179,8 @@ abstract class WalletAddressListViewModelBase with Store { final wallet = _wallet; if (wallet is ElectrumWallet) { - wallet.nextAddress(); + wallet.walletAddresses.nextAddress(); + wallet.save(); } } } diff --git a/lib/view_model/wallet_creation_vm.dart b/lib/view_model/wallet_creation_vm.dart index 58ee24087..402d3be8f 100644 --- a/lib/view_model/wallet_creation_vm.dart +++ b/lib/view_model/wallet_creation_vm.dart @@ -50,7 +50,7 @@ abstract class WalletCreationVMBase with Store { dirPath: dirPath); credentials.walletInfo = walletInfo; final wallet = await process(credentials); - walletInfo.address = wallet.address; + walletInfo.address = wallet.walletAddresses.address; await _walletInfoSource.add(walletInfo); _appStore.changeCurrentWallet(wallet); _appStore.authenticationStore.allowed();