refreshEthBalance method
dynamic
refreshEthBalance(
- String walletId,
- int accountId
)
Implementation
refreshEthBalance(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 ethBalance = await getEthBalance(
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.ETH.name: double.parse(ethBalance.toStringAsFixed(4)),
},
),
},
)
});
}