cake_wallet/cw_solana/lib/solana_balance.dart
Adegoke David 24f6541fa6
CW-647-Birdpay-Trc20 (#1469)
* fix: Desktop resize bug

* fix: Birdpay working for trc20 and adjust transaction fee currency

* fix: Filter logic

* fix: Solana token balance not fully displaying

* fix: Minor enhancements
2024-05-28 16:32:36 +03:00

39 lines
925 B
Dart

import 'dart:convert';
import 'package:cw_core/balance.dart';
class SolanaBalance extends Balance {
SolanaBalance(this.balance) : super(balance.toInt(), balance.toInt());
final double balance;
@override
String get formattedAdditionalBalance => _balanceFormatted();
@override
String get formattedAvailableBalance => _balanceFormatted();
String _balanceFormatted() {
String stringBalance = balance.toString();
if (stringBalance.toString().length >= 12) {
stringBalance = stringBalance.substring(0, 12);
}
return stringBalance;
}
static SolanaBalance? fromJSON(String? jsonSource) {
if (jsonSource == null) {
return null;
}
final decoded = json.decode(jsonSource) as Map;
try {
return SolanaBalance(decoded['balance']);
} catch (e) {
return SolanaBalance(0.0);
}
}
String toJSON() => json.encode({'balance': balance.toString()});
}