mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-08 19:59:29 +00:00
token balance fix
This commit is contained in:
parent
7ee5c196a0
commit
004c39102c
1 changed files with 25 additions and 30 deletions
|
@ -1,6 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:decimal/decimal.dart';
|
||||
import 'package:ethereum_addresses/ethereum_addresses.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
@ -40,7 +39,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
// late web3dart.EthereumAddress _contractAddress;
|
||||
late web3dart.EthPrivateKey _credentials;
|
||||
late web3dart.DeployedContract _deployedContract;
|
||||
late web3dart.ContractFunction _balanceFunction;
|
||||
late web3dart.ContractFunction _sendFunction;
|
||||
late web3dart.Web3Client _client;
|
||||
|
||||
|
@ -284,7 +282,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
);
|
||||
|
||||
try {
|
||||
_balanceFunction = _deployedContract.function('balanceOf');
|
||||
_sendFunction = _deployedContract.function('transfer');
|
||||
} catch (_) {
|
||||
//====================================================================
|
||||
|
@ -359,7 +356,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
contractAddress,
|
||||
);
|
||||
|
||||
_balanceFunction = _deployedContract.function('balanceOf');
|
||||
_sendFunction = _deployedContract.function('transfer');
|
||||
|
||||
_client = await getEthClient();
|
||||
|
@ -405,34 +401,33 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
|||
}
|
||||
|
||||
Future<void> refreshCachedBalance() async {
|
||||
final balanceRequest = await _client.call(
|
||||
contract: _deployedContract,
|
||||
function: _balanceFunction,
|
||||
params: [_credentials.address],
|
||||
final response = await EthereumAPI.getWalletTokenBalance(
|
||||
address: _credentials.address.hex,
|
||||
contractAddress: tokenContract.address,
|
||||
);
|
||||
|
||||
String _balance = balanceRequest.first.toString();
|
||||
|
||||
final newBalance = Balance(
|
||||
total: Amount.fromDecimal(
|
||||
Decimal.parse(_balance),
|
||||
fractionDigits: tokenContract.decimals,
|
||||
),
|
||||
spendable: Amount.fromDecimal(
|
||||
Decimal.parse(_balance),
|
||||
fractionDigits: tokenContract.decimals,
|
||||
),
|
||||
blockedTotal: Amount(
|
||||
rawValue: BigInt.zero,
|
||||
fractionDigits: tokenContract.decimals,
|
||||
),
|
||||
pendingSpendable: Amount(
|
||||
rawValue: BigInt.zero,
|
||||
fractionDigits: tokenContract.decimals,
|
||||
),
|
||||
);
|
||||
await updateCachedBalance(newBalance);
|
||||
notifyListeners();
|
||||
if (response.value != null) {
|
||||
await updateCachedBalance(
|
||||
Balance(
|
||||
total: response.value!,
|
||||
spendable: response.value!,
|
||||
blockedTotal: Amount(
|
||||
rawValue: BigInt.zero,
|
||||
fractionDigits: tokenContract.decimals,
|
||||
),
|
||||
pendingSpendable: Amount(
|
||||
rawValue: BigInt.zero,
|
||||
fractionDigits: tokenContract.decimals,
|
||||
),
|
||||
),
|
||||
);
|
||||
notifyListeners();
|
||||
} else {
|
||||
Logging.instance.log(
|
||||
"CachedEthTokenBalance.fetchAndUpdateCachedBalance failed: ${response.exception}",
|
||||
level: LogLevel.Warning,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Transaction>> get transactions => ethWallet.db
|
||||
|
|
Loading…
Reference in a new issue