addAccount method

Future<EthWalletData> addAccount(
  1. KeyringEVM keyring, {
  2. required EVMKeyType keyType,
  3. required Map acc,
  4. required String password,
})

Add account to local storage.

Implementation

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

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

  await apiRoot.eth.account.updateAddressIconsMap(keyring, [acc['address']]);

  return EthWalletData.fromJson(acc);
}