mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-24 19:25:52 +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 'dart:async';
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
|
||||||
import 'package:ethereum_addresses/ethereum_addresses.dart';
|
import 'package:ethereum_addresses/ethereum_addresses.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
|
@ -40,7 +39,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
// late web3dart.EthereumAddress _contractAddress;
|
// late web3dart.EthereumAddress _contractAddress;
|
||||||
late web3dart.EthPrivateKey _credentials;
|
late web3dart.EthPrivateKey _credentials;
|
||||||
late web3dart.DeployedContract _deployedContract;
|
late web3dart.DeployedContract _deployedContract;
|
||||||
late web3dart.ContractFunction _balanceFunction;
|
|
||||||
late web3dart.ContractFunction _sendFunction;
|
late web3dart.ContractFunction _sendFunction;
|
||||||
late web3dart.Web3Client _client;
|
late web3dart.Web3Client _client;
|
||||||
|
|
||||||
|
@ -284,7 +282,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_balanceFunction = _deployedContract.function('balanceOf');
|
|
||||||
_sendFunction = _deployedContract.function('transfer');
|
_sendFunction = _deployedContract.function('transfer');
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
//====================================================================
|
//====================================================================
|
||||||
|
@ -359,7 +356,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
contractAddress,
|
contractAddress,
|
||||||
);
|
);
|
||||||
|
|
||||||
_balanceFunction = _deployedContract.function('balanceOf');
|
|
||||||
_sendFunction = _deployedContract.function('transfer');
|
_sendFunction = _deployedContract.function('transfer');
|
||||||
|
|
||||||
_client = await getEthClient();
|
_client = await getEthClient();
|
||||||
|
@ -405,23 +401,16 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refreshCachedBalance() async {
|
Future<void> refreshCachedBalance() async {
|
||||||
final balanceRequest = await _client.call(
|
final response = await EthereumAPI.getWalletTokenBalance(
|
||||||
contract: _deployedContract,
|
address: _credentials.address.hex,
|
||||||
function: _balanceFunction,
|
contractAddress: tokenContract.address,
|
||||||
params: [_credentials.address],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
String _balance = balanceRequest.first.toString();
|
if (response.value != null) {
|
||||||
|
await updateCachedBalance(
|
||||||
final newBalance = Balance(
|
Balance(
|
||||||
total: Amount.fromDecimal(
|
total: response.value!,
|
||||||
Decimal.parse(_balance),
|
spendable: response.value!,
|
||||||
fractionDigits: tokenContract.decimals,
|
|
||||||
),
|
|
||||||
spendable: Amount.fromDecimal(
|
|
||||||
Decimal.parse(_balance),
|
|
||||||
fractionDigits: tokenContract.decimals,
|
|
||||||
),
|
|
||||||
blockedTotal: Amount(
|
blockedTotal: Amount(
|
||||||
rawValue: BigInt.zero,
|
rawValue: BigInt.zero,
|
||||||
fractionDigits: tokenContract.decimals,
|
fractionDigits: tokenContract.decimals,
|
||||||
|
@ -430,9 +419,15 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
rawValue: BigInt.zero,
|
rawValue: BigInt.zero,
|
||||||
fractionDigits: tokenContract.decimals,
|
fractionDigits: tokenContract.decimals,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
await updateCachedBalance(newBalance);
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
} else {
|
||||||
|
Logging.instance.log(
|
||||||
|
"CachedEthTokenBalance.fetchAndUpdateCachedBalance failed: ${response.exception}",
|
||||||
|
level: LogLevel.Warning,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Transaction>> get transactions => ethWallet.db
|
Future<List<Transaction>> get transactions => ethWallet.db
|
||||||
|
|
Loading…
Reference in a new issue