eth token fee parsing fix

This commit is contained in:
julian 2023-04-07 16:02:28 -06:00
parent 1ff19194e7
commit 51211b34f5
2 changed files with 7 additions and 21 deletions

View file

@ -23,14 +23,8 @@ class CachedEthTokenBalance with EthTokenCache {
await updateCachedBalance( await updateCachedBalance(
TokenBalance( TokenBalance(
contractAddress: token.address, contractAddress: token.address,
total: Amount( total: response.value!,
rawValue: BigInt.from(response.value!), spendable: response.value!,
fractionDigits: token.decimals,
),
spendable: Amount(
rawValue: BigInt.from(response.value!),
fractionDigits: token.decimals,
),
blockedTotal: Amount( blockedTotal: Amount(
rawValue: BigInt.zero, rawValue: BigInt.zero,
fractionDigits: token.decimals, fractionDigits: token.decimals,

View file

@ -1,5 +1,4 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:math';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
@ -9,6 +8,7 @@ import 'package:stackwallet/dto/ethereum/eth_tx_dto.dart';
import 'package:stackwallet/dto/ethereum/pending_eth_tx_dto.dart'; import 'package:stackwallet/dto/ethereum/pending_eth_tx_dto.dart';
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart'; import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
import 'package:stackwallet/models/paymint/fee_object_model.dart'; import 'package:stackwallet/models/paymint/fee_object_model.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/eth_commons.dart'; import 'package:stackwallet/utilities/eth_commons.dart';
import 'package:stackwallet/utilities/extensions/extensions.dart'; import 'package:stackwallet/utilities/extensions/extensions.dart';
@ -396,7 +396,7 @@ abstract class EthereumAPI {
// } // }
// } // }
static Future<EthereumResponse<int>> getWalletTokenBalance({ static Future<EthereumResponse<Amount>> getWalletTokenBalance({
required String address, required String address,
required String contractAddress, required String contractAddress,
}) async { }) async {
@ -411,19 +411,11 @@ abstract class EthereumAPI {
if (json["data"] is List) { if (json["data"] is List) {
final map = json["data"].first as Map; final map = json["data"].first as Map;
final bal = Decimal.tryParse(map["balance"].toString()); final balance =
final int balance; Decimal.tryParse(map["balance"].toString()) ?? Decimal.zero;
if (bal == null) {
balance = 0;
} else {
final int decimals = map["decimals"] as int;
balance = (bal * Decimal.fromInt(pow(10, decimals).truncate()))
.toBigInt()
.toInt();
}
return EthereumResponse( return EthereumResponse(
balance, Amount.fromDecimal(balance, fractionDigits: map["decimals"] as int),
null, null,
); );
} else { } else {