refreshStrkBalance method

dynamic refreshStrkBalance(
  1. String walletId,
  2. int accountId
)

Implementation

refreshStrkBalance(String walletId, int accountId) async {
  final accountAddress =
      state.wallets[walletId]?.accounts[accountId]?.address;
  if (accountAddress == null) {
    throw Exception('Account address is null');
  }
  final provider = WalletKit().provider;
  final strkBalance = await getStrkBalance(
    provider: provider,
    accountAddress: s.Felt.fromHexString(accountAddress),
  );
  final wallet = state.wallets[walletId];
  if (wallet == null) {
    throw Exception("Wallet not found");
  }
  final account = wallet.accounts[accountId];
  if (account == null) {
    throw Exception("Account not found");
  }
  state = state.copyWith(wallets: {
    ...state.wallets,
    walletId: wallet.copyWith(
      accounts: {
        ...wallet.accounts,
        accountId: account.copyWith(
          balances: {
            ...account.balances,
            TokenSymbol.STRK.name:
                double.parse(strkBalance.toStringAsFixed(4)),
          },
        ),
      },
    )
  });
}