mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
added different digits (decimal points) for formatters, some refactoring
This commit is contained in:
parent
662aba5d72
commit
9d9fe4a5a6
9 changed files with 42 additions and 132 deletions
|
@ -11,24 +11,35 @@ class ZanoFormatter {
|
|||
..maximumFractionDigits = defaultDecimalPoint
|
||||
..minimumFractionDigits = 1;
|
||||
|
||||
static Decimal _intDivision({required int amount, required BigInt divider}) => (Decimal.fromInt(amount) / Decimal.fromBigInt(divider)).toDecimal();
|
||||
static Decimal _bigIntDivision({required BigInt amount, required BigInt divider}) =>
|
||||
(Decimal.fromBigInt(amount) / Decimal.fromBigInt(divider)).toDecimal();
|
||||
|
||||
static String intAmountToString(int amount, [int decimalPoint = defaultDecimalPoint]) => numberFormat.format(
|
||||
static String intAmountToString(int amount, [int decimalPoint = defaultDecimalPoint]) => numberFormat
|
||||
.format(
|
||||
DecimalIntl(
|
||||
_intDivision(
|
||||
amount: amount,
|
||||
_bigIntDivision(
|
||||
amount: BigInt.from(amount),
|
||||
divider: BigInt.from(pow(10, decimalPoint)),
|
||||
),
|
||||
),
|
||||
).replaceAll(',', '');
|
||||
static String bigIntAmountToString(BigInt amount, [int decimalPoint = defaultDecimalPoint]) => numberFormat.format(
|
||||
)
|
||||
.replaceAll(',', '');
|
||||
static String bigIntAmountToString(BigInt amount, [int decimalPoint = defaultDecimalPoint]) => numberFormat
|
||||
.format(
|
||||
DecimalIntl(
|
||||
_bigIntDivision(
|
||||
amount: amount,
|
||||
divider: BigInt.from(pow(10, decimalPoint)),
|
||||
),
|
||||
),
|
||||
).replaceAll(',', '');
|
||||
)
|
||||
.replaceAll(',', '');
|
||||
|
||||
static double intAmountToDouble(int amount, [int decimalPoint = defaultDecimalPoint]) => _bigIntDivision(
|
||||
amount: BigInt.from(amount),
|
||||
divider: BigInt.from(pow(10, decimalPoint)),
|
||||
).toDouble();
|
||||
|
||||
static int parseAmount(String amount, [int decimalPoint = defaultDecimalPoint]) =>
|
||||
(Decimal.parse(amount) * Decimal.fromBigInt(BigInt.from(10).pow(decimalPoint))).toBigInt().toInt();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:cw_zano/api/api_calls.dart';
|
||||
import 'package:cw_zano/api/model/get_address_info_result.dart';
|
||||
import 'package:cw_zano/zano_wallet_api.dart';
|
||||
|
||||
class ZanoUtils {
|
||||
static bool validateAddress(String address) {
|
||||
|
|
|
@ -42,7 +42,6 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
static const int _autoSaveInterval = 30;
|
||||
|
||||
List<Transfer> transfers = [];
|
||||
//String defaultAsssetId = '';
|
||||
@override
|
||||
ZanoWalletAddresses walletAddresses;
|
||||
|
||||
|
@ -200,6 +199,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
comment: outputs.first.note ?? '',
|
||||
assetId: assetId,
|
||||
ticker: credentials.currency.title,
|
||||
decimalPoint: credentials.currency.decimals,
|
||||
amount: totalAmount,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import 'package:cw_zano/zano_formatter.dart';
|
|||
import 'package:cw_zano/zano_wallet.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
class ZanoNewWalletCredentials extends WalletCredentials {
|
||||
ZanoNewWalletCredentials({required String name, String? password}) : super(name: name, password: password);
|
||||
|
|
|
@ -119,7 +119,7 @@ class TransactionListItem extends ActionListItem with Keyable {
|
|||
final asset = zano!.assetOfTransaction(balanceViewModel.wallet, transaction);
|
||||
final price = balanceViewModel.fiatConvertationStore.prices[asset];
|
||||
amount = calculateFiatAmountRaw(
|
||||
cryptoAmount: zano!.formatterMoneroAmountToDouble(amount: transaction.amount),
|
||||
cryptoAmount: zano!.formatterIntAmountToDouble(amount: transaction.amount, currency: asset),
|
||||
price: price);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -98,7 +98,7 @@ abstract class OutputBase with Store {
|
|||
_amount = polygon!.formatterPolygonParseAmount(_cryptoAmount);
|
||||
break;
|
||||
case WalletType.zano:
|
||||
_amount = zano!.formatterMoneroParseAmount(amount: _cryptoAmount);
|
||||
_amount = zano!.formatterParseAmount(amount: _cryptoAmount, currency: cryptoCurrencyHandler());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -144,7 +144,7 @@ abstract class OutputBase with Store {
|
|||
}
|
||||
|
||||
if (_wallet.type == WalletType.zano) {
|
||||
return zano!.formatterMoneroAmountToDouble(amount: fee);
|
||||
return zano!.formatterIntAmountToDouble(amount: fee, currency: cryptoCurrencyHandler());
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
|
|
|
@ -373,6 +373,12 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
|
|||
addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress));
|
||||
}
|
||||
|
||||
if (wallet.type == WalletType.zano) {
|
||||
final primaryAddress = zano!.getAddress(wallet);
|
||||
|
||||
addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress));
|
||||
}
|
||||
|
||||
if (searchText.isNotEmpty) {
|
||||
return ObservableList.of(addressList.where((item) {
|
||||
if (item is WalletAddressListItem) {
|
||||
|
|
|
@ -186,37 +186,16 @@ class CWZano extends Zano {
|
|||
);
|
||||
}
|
||||
|
||||
// @override
|
||||
// String formatterMoneroAmountToString({required int amount}) {
|
||||
// return moneroAmountToString(amount: amount);
|
||||
// }
|
||||
|
||||
@override
|
||||
double formatterMoneroAmountToDouble({required int amount}) {
|
||||
return moneroAmountToDouble(amount: amount);
|
||||
double formatterIntAmountToDouble({required int amount, required CryptoCurrency currency}) {
|
||||
if (currency is ZanoAsset) return ZanoFormatter.intAmountToDouble(amount, currency.decimalPoint);
|
||||
return ZanoFormatter.intAmountToDouble(amount);
|
||||
}
|
||||
|
||||
@override
|
||||
int formatterMoneroParseAmount({required String amount}) {
|
||||
return moneroParseAmount(amount: amount);
|
||||
}
|
||||
|
||||
// @override
|
||||
// Account getCurrentAccount(Object wallet) {
|
||||
// final zanoWallet = wallet as ZanoWallet;
|
||||
// final acc = zanoWallet.walletAddresses.account as monero_account.Account;
|
||||
// return Account(id: acc.id, label: acc.label);
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void setCurrentAccount(Object wallet, int id, String label) {
|
||||
// final zanoWallet = wallet as ZanoWallet;
|
||||
// zanoWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
|
||||
// }
|
||||
|
||||
@override
|
||||
void onStartup() {
|
||||
debugPrint("onStartup");
|
||||
int formatterParseAmount({required String amount, required CryptoCurrency currency}) {
|
||||
if (currency is ZanoAsset) return ZanoFormatter.parseAmount(amount, currency.decimalPoint);
|
||||
return ZanoFormatter.parseAmount(amount);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -230,12 +209,6 @@ class CWZano extends Zano {
|
|||
return ZanoWalletService(walletInfoSource);
|
||||
}
|
||||
|
||||
// @override
|
||||
// String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
|
||||
// final zanoWallet = wallet as ZanoWallet;
|
||||
// return zanoWallet.getTransactionAddress(accountIndex, addressIndex);
|
||||
// }
|
||||
|
||||
@override
|
||||
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction) {
|
||||
transaction as ZanoTransactionInfo;
|
||||
|
@ -247,4 +220,7 @@ class CWZano extends Zano {
|
|||
}
|
||||
|
||||
String getZanoAssetAddress(CryptoCurrency asset) => (asset as ZanoAsset).assetId;
|
||||
|
||||
@override
|
||||
String getAddress(WalletBase wallet) => (wallet as ZanoWallet).walletAddresses.address;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:cake_wallet/utils/language_list.dart';
|
|||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_zano/model/zano_asset.dart';
|
||||
import 'package:cw_zano/model/zano_transaction_credentials.dart';
|
||||
import 'package:cw_zano/zano_formatter.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cw_core/wallet_credentials.dart';
|
||||
|
@ -26,68 +27,8 @@ part 'cw_zano.dart';
|
|||
|
||||
Zano? zano = CWZano();
|
||||
|
||||
// class Account {
|
||||
// Account({required this.id, required this.label});
|
||||
// final int id;
|
||||
// final String label;
|
||||
// }
|
||||
|
||||
// class Subaddress {
|
||||
// Subaddress({
|
||||
// required this.id,
|
||||
// required this.label,
|
||||
// required this.address});
|
||||
// final int id;
|
||||
// final String label;
|
||||
// final String address;
|
||||
// }
|
||||
|
||||
/*class ZanoBalance extends Balance {
|
||||
ZanoBalance({required this.fullBalance, required this.unlockedBalance})
|
||||
: formattedFullBalance = zano!.formatterMoneroAmountToString(amount: fullBalance),
|
||||
formattedUnlockedBalance =
|
||||
zano!.formatterMoneroAmountToString(amount: unlockedBalance),
|
||||
super(unlockedBalance, fullBalance);
|
||||
|
||||
ZanoBalance.fromString(
|
||||
{required this.formattedFullBalance,
|
||||
required this.formattedUnlockedBalance})
|
||||
: fullBalance = zano!.formatterMoneroParseAmount(amount: formattedFullBalance),
|
||||
unlockedBalance = zano!.formatterMoneroParseAmount(amount: formattedUnlockedBalance),
|
||||
super(zano!.formatterMoneroParseAmount(amount: formattedUnlockedBalance),
|
||||
zano!.formatterMoneroParseAmount(amount: formattedFullBalance));
|
||||
|
||||
final int fullBalance;
|
||||
final int unlockedBalance;
|
||||
final String formattedFullBalance;
|
||||
final String formattedUnlockedBalance;
|
||||
|
||||
@override
|
||||
String get formattedAvailableBalance => formattedUnlockedBalance;
|
||||
|
||||
@override
|
||||
String get formattedAdditionalBalance => formattedFullBalance;
|
||||
}*/
|
||||
|
||||
|
||||
/*abstract class ZanoWalletDetails {
|
||||
// FIX-ME: it's abstruct class
|
||||
// @observable
|
||||
// late Account account;
|
||||
// FIX-ME: it's abstruct class
|
||||
@observable
|
||||
late ZanoBalance balance;
|
||||
}*/
|
||||
|
||||
abstract class Zano {
|
||||
/**ZanoAccountList getAccountList(Object wallet);*/
|
||||
|
||||
TransactionHistoryBase getTransactionHistory(Object wallet);
|
||||
|
||||
//ZanoWalletDetails getZanoWalletDetails(Object wallet);
|
||||
|
||||
// String getTransactionAddress(Object wallet, int accountIndex, int addressIndex);
|
||||
|
||||
TransactionPriority getDefaultTransactionPriority();
|
||||
TransactionPriority deserializeMoneroTransactionPriority({required int raw});
|
||||
List<TransactionPriority> getTransactionPriorities();
|
||||
|
@ -105,12 +46,8 @@ abstract class Zano {
|
|||
WalletCredentials createZanoNewWalletCredentials({required String name, String password});
|
||||
Map<String, String> getKeys(Object wallet);
|
||||
Object createZanoTransactionCredentials({required List<Output> outputs, required TransactionPriority priority, required CryptoCurrency currency});
|
||||
// String formatterMoneroAmountToString({required int amount});
|
||||
double formatterMoneroAmountToDouble({required int amount});
|
||||
int formatterMoneroParseAmount({required String amount});
|
||||
// Account getCurrentAccount(Object wallet);
|
||||
// void setCurrentAccount(Object wallet, int id, String label);
|
||||
void onStartup();
|
||||
double formatterIntAmountToDouble({required int amount, required CryptoCurrency currency});
|
||||
int formatterParseAmount({required String amount, required CryptoCurrency currency});
|
||||
int getTransactionInfoAccountId(TransactionInfo tx);
|
||||
WalletService createZanoWalletService(Box<WalletInfo> walletInfoSource);
|
||||
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo tx);
|
||||
|
@ -120,24 +57,5 @@ abstract class Zano {
|
|||
Future<CryptoCurrency> addZanoAssetById(WalletBase wallet, String assetId);
|
||||
Future<void> deleteZanoAsset(WalletBase wallet, CryptoCurrency token);
|
||||
Future<CryptoCurrency?> getZanoAsset(WalletBase wallet, String contractAddress);
|
||||
String getAddress(WalletBase wallet);
|
||||
}
|
||||
|
||||
// abstract class MoneroSubaddressList {
|
||||
// ObservableList<Subaddress> get subaddresses;
|
||||
// void update(Object wallet, {required int accountIndex});
|
||||
// void refresh(Object wallet, {required int accountIndex});
|
||||
// List<Subaddress> getAll(Object wallet);
|
||||
// Future<void> addSubaddress(Object wallet, {required int accountIndex, required String label});
|
||||
// Future<void> setLabelSubaddress(Object wallet,
|
||||
// {required int accountIndex, required int addressIndex, required String label});
|
||||
// }
|
||||
|
||||
// abstract class ZanoAccountList {
|
||||
// ObservableList<Account> get accounts;
|
||||
// void update(Object wallet);
|
||||
// void refresh(Object wallet);
|
||||
// List<Account> getAll(Object wallet);
|
||||
// Future<void> addAccount(Object wallet, {required String label});
|
||||
// Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
|
||||
// }
|
||||
|
||||
|
|
Loading…
Reference in a new issue