mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-07 03:19:31 +00:00
c9a6abeea4
* fix: Confirm widget is still mounted * feat: Modify balance display to include full balance * fix: Modifying balance * chore: Feature cleanup * fix: Add frozen balance into consideration when taking available balance and add field to make full balance display only on bitcoin and litecoin wallets * fix: Adjust balance card to display correct available and unavailable balance, unavailable balance should only be displayed when there is one WIP * fix: Cleanup balance page and balance page view_model * chore: Revert formatting * fix: Remove full balance * fix: Remove full balance * fix: Remove full balance * chore: Rever formating [skip ci] * feat: Finalize display only available and unavailable balance * fix: Modify the way balance is displayed, activate frozen balance with label, remove unavailable/additional balance for bitcoin wallet type * fix: Issues coming from syncing with main * fix: Modify additional balance label * fix: Monero and Wownero balances display bug * fix: Resolve merge conflicts * feat: Activate CPFP for BTC, LTC and BCH, also fix issues with frozen balance display * - minor fix - remove unused functions * Fix conflicts --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> Co-authored-by: tuxsudo <tuxsudo@tux.pizza>
45 lines
1.1 KiB
Dart
45 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:math';
|
|
|
|
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 => _balance();
|
|
|
|
@override
|
|
String get formattedAvailableBalance => _balance();
|
|
|
|
String _balance() {
|
|
final String formattedBalance = (balance / BigInt.from(10).pow(exponent)).toString();
|
|
return formattedBalance.substring(0, min(12, formattedBalance.length));
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|