Files
hash-wallet/cw_evm/lib/evm_erc20_balance.dart
T
43f2225e0c CW-1130-deuro-fixes-improvements (#2392)
* feat: add support for Ethereum EIP-681 URIs in PaymentRequest and implement test coverage

* test: add unit test for EIP-681 URI handling with contract and no chainId [skip-ci]

* fix(CW-1114): rounding error for really large numbers

* fix: wrong decimals for eth fee display

* fix: limit fractional digits to a maximum of `decimals` in `format_fixed` function [skip-ci]

* test: add unit tests for `formatFixed` function

* refactor: replace custom balance formatting with `formatFixed` utility function

* refactor: improve dEuroViewModel formatting and computation logic

* refactor: extract and simplify interest action handlers in dEuro savings page

* fix: deuro add should show edit Add bottom sheet

* feat: block user from entering amount bigger than the max

* feat: use new tooltip bottomsheet for dEuro

* feat: add pull down to refresh dEuro savings

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2025-07-19 01:47:06 +03:00

41 lines
1.0 KiB
Dart

import 'dart:convert';
import 'package:cw_core/format_fixed.dart';
import 'package:cw_core/balance.dart';
class EVMChainERC20Balance extends Balance {
EVMChainERC20Balance(this.balance, {this.exponent = 18})
: super(balance.toInt(), balance.toInt());
final BigInt balance;
final int exponent;
@override
String get formattedAdditionalBalance => formatFixed(balance, exponent, fractionalDigits: 12);
@override
String get formattedAvailableBalance => formatFixed(balance, exponent, fractionalDigits: 12);
String toJSON() => json.encode({
'balanceInWei': balance.toString(),
'exponent': exponent,
});
static EVMChainERC20Balance? fromJSON(String? jsonSource) {
if (jsonSource == null) {
return null;
}
final decoded = json.decode(jsonSource) as Map;
try {
return EVMChainERC20Balance(
BigInt.parse(decoded['balanceInWei']),
exponent: decoded['exponent'],
);
} catch (e) {
return EVMChainERC20Balance(BigInt.zero);
}
}
}