| 1 | part of 'zano.dart'; |
| 2 | |
| 3 | class CWZano extends Zano { |
| 4 | List<ZanoAsset> getZanoAssets(WalletBase wallet) => |
| 5 | (wallet as ZanoWallet).zanoAssets.values.toList(); |
| 6 | |
| 7 | @override |
| 8 | Future<CryptoCurrency> addZanoAssetById(WalletBase wallet, String assetId) async => |
| 9 | await (wallet as ZanoWallet).addZanoAssetById(assetId); |
| 10 | |
| 11 | @override |
| 12 | Future<void> changeZanoAssetAvailability(WalletBase wallet, CryptoCurrency token) async => |
| 13 | await (wallet as ZanoWallet).changeZanoAssetAvailability(token as ZanoAsset); |
| 14 | |
| 15 | @override |
| 16 | Future<void> deleteZanoAsset(WalletBase wallet, CryptoCurrency token) async => |
| 17 | await (wallet as ZanoWallet).deleteZanoAsset(token as ZanoAsset); |
| 18 | |
| 19 | @override |
| 20 | Future<ZanoAsset?> getZanoAsset(WalletBase wallet, String assetId) async { |
| 21 | final zanoWallet = wallet as ZanoWallet; |
| 22 | return await zanoWallet.getZanoAsset(assetId); |
| 23 | } |
| 24 | |
| 25 | // @override |
| 26 | // TransactionHistoryBase getTransactionHistory(Object wallet) { |
| 27 | // final zanoWallet = wallet as ZanoWallet; |
| 28 | // return zanoWallet.transactionHistory; |
| 29 | // } |
| 30 | |
| 31 | @override |
| 32 | TransactionPriority getDefaultTransactionPriority() { |
| 33 | return MoneroTransactionPriority.automatic; |
| 34 | } |
| 35 | |
| 36 | @override |
| 37 | TransactionPriority deserializeMoneroTransactionPriority({required int raw}) { |
| 38 | return MoneroTransactionPriority.deserialize(raw: raw); |
| 39 | } |
| 40 | |
| 41 | @override |
| 42 | List<TransactionPriority> getTransactionPriorities() { |
| 43 | return MoneroTransactionPriority.all; |
| 44 | } |
| 45 | |
| 46 | @override |
| 47 | List<String> getWordList(String language) { |
| 48 | assert(language.toLowerCase() == LanguageList.english.toLowerCase()); |
| 49 | return EnglishMnemonics.words; |
| 50 | } |
| 51 | |
| 52 | @override |
| 53 | WalletCredentials createZanoRestoreWalletFromSeedCredentials( |
| 54 | {required String name, |
| 55 | required String password, |
| 56 | required int height, |
| 57 | required String passphrase, |
| 58 | required String mnemonic}) { |
| 59 | return ZanoRestoreWalletFromSeedCredentials( |
| 60 | name: name, password: password, passphrase: passphrase, height: height, mnemonic: mnemonic); |
| 61 | } |
| 62 | |
| 63 | @override |
| 64 | WalletCredentials createZanoNewWalletCredentials( |
| 65 | {required String name, required String? password, required String? passphrase}) { |
| 66 | return ZanoNewWalletCredentials(name: name, password: password, passphrase: passphrase); |
| 67 | } |
| 68 | |
| 69 | @override |
| 70 | Map<String, String> getKeys(Object wallet) { |
| 71 | final zanoWallet = wallet as ZanoWallet; |
| 72 | final keys = zanoWallet.keys; |
| 73 | return <String, String>{ |
| 74 | 'privateSpendKey': keys.privateSpendKey, |
| 75 | 'privateViewKey': keys.privateViewKey, |
| 76 | 'publicSpendKey': keys.publicSpendKey, |
| 77 | 'publicViewKey': keys.publicViewKey |
| 78 | }; |
| 79 | } |
| 80 | |
| 81 | @override |
| 82 | Object createZanoTransactionCredentials( |
| 83 | {required List<Output> outputs, |
| 84 | required TransactionPriority priority, |
| 85 | required CryptoCurrency currency}) => |
| 86 | ZanoTransactionCredentials( |
| 87 | outputs: outputs |
| 88 | .map((out) => OutputInfo( |
| 89 | fiatAmount: out.fiatAmount, |
| 90 | cryptoAmount: out.cryptoAmountMoney, |
| 91 | address: out.address, |
| 92 | note: out.note, |
| 93 | sendAll: out.sendAll, |
| 94 | extractedAddress: out.extractedAddress, |
| 95 | isParsedAddress: out.isParsedAddress, |
| 96 | )) |
| 97 | .toList(), |
| 98 | priority: priority as MoneroTransactionPriority, |
| 99 | currency: currency, |
| 100 | ); |
| 101 | |
| 102 | @override |
| 103 | double formatterIntAmountToDouble( |
| 104 | {required int amount, required CryptoCurrency currency, required bool forFee}) { |
| 105 | // fee always counted in zano with default decimal points |
| 106 | if (forFee) return ZanoFormatter.intAmountToDouble(amount); |
| 107 | if (currency is ZanoAsset) |
| 108 | return ZanoFormatter.intAmountToDouble(amount, currency.decimalPoint); |
| 109 | return ZanoFormatter.intAmountToDouble(amount); |
| 110 | } |
| 111 | |
| 112 | @override |
| 113 | int formatterParseAmount({required String amount, required CryptoCurrency currency}) { |
| 114 | if (currency is ZanoAsset) return ZanoFormatter.parseAmount(amount, currency.decimalPoint); |
| 115 | return ZanoFormatter.parseAmount(amount); |
| 116 | } |
| 117 | |
| 118 | // @override |
| 119 | // int getTransactionInfoAccountId(TransactionInfo tx) { |
| 120 | // final zanoTransactionInfo = tx as ZanoTransactionInfo; |
| 121 | // return zanoTransactionInfo.accountIndex; |
| 122 | // } |
| 123 | |
| 124 | @override |
| 125 | WalletService createZanoWalletService() { |
| 126 | return ZanoWalletService(); |
| 127 | } |
| 128 | |
| 129 | @override |
| 130 | CryptoCurrency? assetOfTransaction(WalletBase wallet, TransactionInfo transaction) { |
| 131 | transaction as ZanoTransactionInfo; |
| 132 | if (transaction.tokenSymbol == CryptoCurrency.zano.title) { |
| 133 | return CryptoCurrency.zano; |
| 134 | } |
| 135 | wallet as ZanoWallet; |
| 136 | final asset = wallet.zanoAssets.values |
| 137 | .firstWhereOrNull((element) => element?.ticker == transaction.tokenSymbol); |
| 138 | return asset; |
| 139 | } |
| 140 | |
| 141 | String getZanoAssetAddress(CryptoCurrency asset) => (asset as ZanoAsset).assetId; |
| 142 | |
| 143 | @override |
| 144 | String getAddress(WalletBase wallet) => (wallet as ZanoWallet).walletAddresses.address; |
| 145 | |
| 146 | @override |
| 147 | bool validateAddress(String address) => ZanoUtils.validateAddress(address); |
| 148 | |
| 149 | @override |
| 150 | Map<String, List<int>> debugCallLength() { |
| 151 | return api.debugCallLength(); |
| 152 | } |
| 153 | |
| 154 | @override |
| 155 | bool isTokenAlreadyAdded(WalletBase wallet, String contractAddress) { |
| 156 | final zanoWallet = wallet as ZanoWallet; |
| 157 | return zanoWallet.zanoAssets.values.any((element) => element?.assetId == contractAddress); |
| 158 | } |
| 159 | } |