addAccount method

Future<KeyPairData> addAccount(
  1. Keyring keyring, {
  2. required KeyType keyType,
  3. required Map acc,
  4. required String password,
})

Add account to local storage.

Implementation

Future<KeyPairData> addAccount(
  Keyring keyring, {
  required KeyType keyType,
  required Map acc,
  required String password,
}) async {
  // save seed and remove it before add account
  if (keyType == KeyType.mnemonic || keyType == KeyType.rawSeed) {
    final String type = keyType.toString().split('.')[1];
    final String? seed = acc[type];
    if (seed != null && seed.isNotEmpty) {
      keyring.store
          .encryptSeedAndSave(acc['pubKey'], acc[type], type, password);
      acc.remove(type);
    }
  }

  // save keystore to storage
  await keyring.store.addAccount(acc);

  await updatePubKeyIconsMap(keyring, [acc['pubKey']]);
  await updatePubKeyAddressMap(keyring);
  updateIndicesMap(keyring, [acc['address']]);

  return KeyPairData.fromJson(acc as Map<String, dynamic>);
}