diff --git a/cw_zano/lib/zano_formatter.dart b/cw_zano/lib/zano_formatter.dart index b96eee235..92851e388 100644 --- a/cw_zano/lib/zano_formatter.dart +++ b/cw_zano/lib/zano_formatter.dart @@ -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(); } diff --git a/cw_zano/lib/zano_utils.dart b/cw_zano/lib/zano_utils.dart index 643cf7051..57ea72279 100644 --- a/cw_zano/lib/zano_utils.dart +++ b/cw_zano/lib/zano_utils.dart @@ -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) { diff --git a/cw_zano/lib/zano_wallet.dart b/cw_zano/lib/zano_wallet.dart index 21bbce3b1..f17ea8d6b 100644 --- a/cw_zano/lib/zano_wallet.dart +++ b/cw_zano/lib/zano_wallet.dart @@ -42,7 +42,6 @@ abstract class ZanoWalletBase extends WalletBase transfers = []; - //String defaultAsssetId = ''; @override ZanoWalletAddresses walletAddresses; @@ -200,6 +199,7 @@ abstract class ZanoWalletBase extends WalletBase (asset as ZanoAsset).assetId; + + @override + String getAddress(WalletBase wallet) => (wallet as ZanoWallet).walletAddresses.address; } diff --git a/lib/zano/zano.dart b/lib/zano/zano.dart index c5517d372..91d8edb96 100644 --- a/lib/zano/zano.dart +++ b/lib/zano/zano.dart @@ -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 getTransactionPriorities(); @@ -105,12 +46,8 @@ abstract class Zano { WalletCredentials createZanoNewWalletCredentials({required String name, String password}); Map getKeys(Object wallet); Object createZanoTransactionCredentials({required List 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 walletInfoSource); CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo tx); @@ -120,24 +57,5 @@ abstract class Zano { Future addZanoAssetById(WalletBase wallet, String assetId); Future deleteZanoAsset(WalletBase wallet, CryptoCurrency token); Future getZanoAsset(WalletBase wallet, String contractAddress); + String getAddress(WalletBase wallet); } - -// abstract class MoneroSubaddressList { -// ObservableList get subaddresses; -// void update(Object wallet, {required int accountIndex}); -// void refresh(Object wallet, {required int accountIndex}); -// List getAll(Object wallet); -// Future addSubaddress(Object wallet, {required int accountIndex, required String label}); -// Future setLabelSubaddress(Object wallet, -// {required int accountIndex, required int addressIndex, required String label}); -// } - -// abstract class ZanoAccountList { -// ObservableList get accounts; -// void update(Object wallet); -// void refresh(Object wallet); -// List getAll(Object wallet); -// Future addAccount(Object wallet, {required String label}); -// Future setLabelAccount(Object wallet, {required int accountIndex, required String label}); -// } -