addAccount method

dynamic addAccount({
  1. required String walletId,
  2. required Future<String?> getPassword(),
  3. SecureStore? secureStore,
})

Implementation

addAccount({
  required String walletId,
  required Future<String?> Function() getPassword,
  SecureStore? secureStore,
}) async {
  final wallet = state.wallets[walletId];
  if (wallet == null) {
    throw Exception("Wallet not found");
  }
  secureStore = secureStore ??
      await getSecureStore(
        getPassword: getPassword,
        type: wallet.secureStoreType,
      );
  final seedPhrase = await secureStore.getSecret(
    key: seedPhraseKey(walletId),
  );
  if (seedPhrase == null) {
    throw Exception("Seed phrase not found");
  }
  final (walletWithAccount, account) = await WalletService.addAccount(
    secureStore: secureStore,
    wallet: wallet,
    seedPhrase: seedPhrase,
  );
  updateWallet(wallet: walletWithAccount, accountId: account.id);
}