updateIndicesMap method

Future<void> updateIndicesMap(
  1. Keyring keyring, [
  2. List? addresses
])

This method query account indices and set data to Keyring.store so we can get index info of an account from Keyring instance.

Implementation

Future<void> updateIndicesMap(Keyring keyring, [List? addresses]) async {
  final List<String?> ls = [];
  if (addresses != null) {
    ls.addAll(List<String>.from(addresses));
  } else {
    ls.addAll(keyring.allWithContacts.map((e) => e.address).toList());
  }

  if (ls.length == 0) return;
  // get account indices from webView.
  final res = await apiRoot.account.queryIndexInfo(ls);
  // set new indices to Keyring instance.
  if (res != null) {
    final data = {};
    res.forEach((e) {
      data[e['accountId']] = e;
    });
    keyring.store.updateIndicesMap(Map<String, Map>.from(data));
    keyring.allAccounts;
  }
}