updateAddressState method

Future<void> updateAddressState (
  1. Address x,
  2. AddressState newState,
  3. {bool store: true}
)

When an Address changes state, update Account.reserveAddress tracking.

Implementation

Future<void> updateAddressState(Address x, AddressState newState,
    {bool store = true}) async {
  if (x.state == newState) return;
  bool wasReserve = x.state == AddressState.reserve;
  if (wasReserve) accounts[x.accountId].reserveAddress.remove(x.chainIndex);
  x.state = newState;
  if (store) {
    await _storeAddress(x);
    if (notifyListeners != null) notifyListeners();
  }
  if (wasReserve) await addNextAddress(account: accounts[x.accountId]);
}