mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 04:19:36 +00:00
90508b8726
Conflicts: configure_cake_wallet.sh cw_core/lib/amount_converter.dart cw_core/lib/wallet_type.dart cw_monero/lib/monero_wallet.dart lib/view_model/unspent_coins/unspent_coins_list_view_model.dart scripts/android/pubspec_gen.sh scripts/ios/app_config.sh scripts/macos/app_config.sh tool/configure.dart
94 lines
3.3 KiB
Dart
94 lines
3.3 KiB
Dart
import 'package:intl/intl.dart';
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
|
|
class AmountConverter {
|
|
static const _moneroAmountLength = 12;
|
|
static const _moneroAmountDivider = 1000000000000;
|
|
static const _wowneroAmountLength = 11;
|
|
static const _wowneroAmountDivider = 100000000000;
|
|
static const _ethereumAmountDivider = 1000000000000000000;
|
|
static const _bitcoinAmountDivider = 100000000;
|
|
static const _bitcoinAmountLength = 8;
|
|
static final _bitcoinAmountFormat = NumberFormat()
|
|
..maximumFractionDigits = _bitcoinAmountLength
|
|
..minimumFractionDigits = 1;
|
|
static final _moneroAmountFormat = NumberFormat()
|
|
..maximumFractionDigits = _moneroAmountLength
|
|
..minimumFractionDigits = 1;
|
|
static final _wowneroAmountFormat = NumberFormat()
|
|
..maximumFractionDigits = _wowneroAmountLength
|
|
..minimumFractionDigits = 1;
|
|
|
|
static int amountStringToInt(CryptoCurrency cryptoCurrency, String amount) {
|
|
switch (cryptoCurrency) {
|
|
case CryptoCurrency.xmr:
|
|
return _moneroParseAmount(amount);
|
|
case CryptoCurrency.xhv:
|
|
case CryptoCurrency.xag:
|
|
case CryptoCurrency.xau:
|
|
case CryptoCurrency.xaud:
|
|
case CryptoCurrency.xbtc:
|
|
case CryptoCurrency.xcad:
|
|
case CryptoCurrency.xchf:
|
|
case CryptoCurrency.xcny:
|
|
case CryptoCurrency.xeur:
|
|
case CryptoCurrency.xgbp:
|
|
case CryptoCurrency.xjpy:
|
|
case CryptoCurrency.xnok:
|
|
case CryptoCurrency.xnzd:
|
|
case CryptoCurrency.xusd:
|
|
return _moneroParseAmount(amount);
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
static String amountIntToString(CryptoCurrency cryptoCurrency, int amount) {
|
|
switch (cryptoCurrency) {
|
|
case CryptoCurrency.xmr:
|
|
return _moneroAmountToString(amount);
|
|
case CryptoCurrency.wow:
|
|
return _wowneroAmountToString(amount);
|
|
case CryptoCurrency.btc:
|
|
case CryptoCurrency.bch:
|
|
case CryptoCurrency.ltc:
|
|
return _bitcoinAmountToString(amount);
|
|
case CryptoCurrency.btcln:
|
|
return _lightningAmountToString(amount);
|
|
case CryptoCurrency.xhv:
|
|
case CryptoCurrency.xag:
|
|
case CryptoCurrency.xau:
|
|
case CryptoCurrency.xaud:
|
|
case CryptoCurrency.xbtc:
|
|
case CryptoCurrency.xcad:
|
|
case CryptoCurrency.xchf:
|
|
case CryptoCurrency.xcny:
|
|
case CryptoCurrency.xeur:
|
|
case CryptoCurrency.xgbp:
|
|
case CryptoCurrency.xjpy:
|
|
case CryptoCurrency.xnok:
|
|
case CryptoCurrency.xnzd:
|
|
case CryptoCurrency.xusd:
|
|
return _moneroAmountToString(amount);
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
static double cryptoAmountToDouble({required num amount, required num divider}) =>
|
|
amount / divider;
|
|
|
|
static String _moneroAmountToString(int amount) => _moneroAmountFormat
|
|
.format(cryptoAmountToDouble(amount: amount, divider: _moneroAmountDivider));
|
|
|
|
static String _bitcoinAmountToString(int amount) => _bitcoinAmountFormat
|
|
.format(cryptoAmountToDouble(amount: amount, divider: _bitcoinAmountDivider));
|
|
|
|
static String _lightningAmountToString(int amount) {
|
|
String formattedAmount = _bitcoinAmountFormat.format(amount);
|
|
return formattedAmount.substring(0, formattedAmount.length - 2);
|
|
}
|
|
|
|
static String _wowneroAmountToString(int amount) => _wowneroAmountFormat
|
|
.format(cryptoAmountToDouble(amount: amount, divider: _wowneroAmountDivider));
|
|
}
|