updatePubKeyIconsMap method

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

This method query account icons and set icons to Keyring.store so we can get icon of an account from Keyring instance.

Implementation

Future<void> updatePubKeyIconsMap(Keyring keyring, [List? pubKeys]) async {
  final List<String?> ls = [];
  if (pubKeys != null) {
    ls.addAll(List<String>.from(pubKeys));
  } else {
    ls.addAll(keyring.keyPairs.map((e) => e.pubKey).toList());
    ls.addAll(keyring.contacts.map((e) => e.pubKey).toList());
  }

  if (ls.length == 0) return;
  // get icons from webView.
  final res = await service!.getPubKeyIconsMap(ls);
  // set new icons to Keyring instance.
  if (res != null) {
    final data = {};
    res.forEach((e) {
      data[e[0]] = e[1];
    });
    keyring.store.updateIconsMap(Map<String, String>.from(data));
  }
}