adding/removing from whitelist

This commit is contained in:
leo 2024-03-15 12:42:27 +00:00
parent 5699230ba1
commit b2b6578972
17 changed files with 573 additions and 332 deletions

View file

@ -104,6 +104,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
CryptoCurrency.digibyte,
CryptoCurrency.usdtSol,
CryptoCurrency.zano,
CryptoCurrency.ctZano,
];
static const havenCurrencies = [
@ -219,6 +220,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
static const digibyte = CryptoCurrency(title: 'DGB', fullName: 'DigiByte', raw: 90, name: 'dgb', iconPath: 'assets/images/digibyte.png', decimals: 8);
static const usdtSol = CryptoCurrency(title: 'USDT', tag: 'SOL', fullName: 'USDT Tether', raw: 91, name: 'usdtsol', iconPath: 'assets/images/usdt_icon.png', decimals: 6);
static const zano = CryptoCurrency(title: 'ZANO', tag: 'ZANO', fullName: 'Zano', raw: 92, name: 'zano', iconPath: 'assets/images/zano_icon.png', decimals: 12);
static const ctZano = CryptoCurrency(title: 'CT', tag: 'ZANO', fullName: 'Confidential token', raw: 93, name: 'ctzano', iconPath: 'assets/images/zano_icon.png', decimals: 12);
static final Map<int, CryptoCurrency> _rawCurrencyMap =

View file

@ -376,7 +376,7 @@ extern "C"
bool restore_wallet_from_spend_key(char *path, char *password, char *seed, char *language, char *spendKey, int32_t networkType, uint64_t restoreHeight, char *error)
{
Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
/*Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
Monero::Wallet *wallet = Monero::WalletManagerFactory::getWalletManager()->createDeterministicWalletFromSpendKey(
std::string(path),
std::string(password),
@ -399,7 +399,7 @@ extern "C"
return false;
}
change_current_wallet(wallet);
change_current_wallet(wallet);*/
return true;
}

View file

@ -0,0 +1,9 @@
class AddRemoveAssetsWhitelistParams {
final String assetId;
AddRemoveAssetsWhitelistParams({required this.assetId});
Map<String, dynamic> toJson() => {
'asset_id': assetId,
};
}

View file

@ -0,0 +1,38 @@
// class AssetDescriptor {
// static const defaultDecimalPoint = 12;
// final String assetId;
// final int currentSupply;
// final int decimalPoint;
// final String fullName;
// final bool hiddenSupply;
// final String metaInfo;
// final String owner;
// final String ticker;
// final int totalMaxSupply;
// AssetDescriptor({
// required this.assetId,
// required this.currentSupply,
// required this.decimalPoint,
// required this.fullName,
// required this.hiddenSupply,
// required this.metaInfo,
// required this.owner,
// required this.ticker,
// required this.totalMaxSupply,
// });
// factory AssetDescriptor.fromJson(Map<String, dynamic> json) =>
// AssetDescriptor(
// assetId: json['asset_id'] as String? ?? '',
// currentSupply: json['current_supply'] as int? ?? 0,
// decimalPoint: json['decimal_point'] as int? ?? defaultDecimalPoint,
// fullName: json['full_name'] as String? ?? '',
// hiddenSupply: json['hidden_supply'] as bool? ?? false,
// metaInfo: json['meta_info'] as String? ?? '',
// owner: json['owner'] as String? ?? '',
// ticker: json['ticker'] as String? ?? '',
// totalMaxSupply: json['total_max_supply'] as int? ?? 0,
// );
// }

View file

@ -1,34 +1,34 @@
class AssetInfo {
final String assetId;
final int currentSupply;
final int decimalPoint;
final String fullName;
final bool hiddenSupply;
final String metaInfo;
final String owner;
final String ticker;
final int totalMaxSupply;
// class AssetInfo {
// final String assetId;
// final int currentSupply;
// final int decimalPoint;
// final String fullName;
// final bool hiddenSupply;
// final String metaInfo;
// final String owner;
// final String ticker;
// final int totalMaxSupply;
AssetInfo(
{required this.assetId,
required this.currentSupply,
required this.decimalPoint,
required this.fullName,
required this.hiddenSupply,
required this.metaInfo,
required this.owner,
required this.ticker,
required this.totalMaxSupply});
// AssetInfo(
// {required this.assetId,
// required this.currentSupply,
// required this.decimalPoint,
// required this.fullName,
// required this.hiddenSupply,
// required this.metaInfo,
// required this.owner,
// required this.ticker,
// required this.totalMaxSupply});
factory AssetInfo.fromJson(Map<String, dynamic> json) => AssetInfo(
assetId: json['asset_id'] as String? ?? '',
currentSupply: json['current_supply'] as int? ?? 0,
decimalPoint: json['decimal_point'] as int? ?? 0,
fullName: json['full_name'] as String? ?? '',
hiddenSupply: json['hidden_supply'] as bool,
metaInfo: json['meta_info'] as String? ?? '',
owner: json['owner'] as String? ?? '',
ticker: json['ticker'] as String? ?? '',
totalMaxSupply: json['total_max_supply'] as int? ?? 0,
);
}
// factory AssetInfo.fromJson(Map<String, dynamic> json) => AssetInfo(
// assetId: json['asset_id'] as String? ?? '',
// currentSupply: json['current_supply'] as int? ?? 0,
// decimalPoint: json['decimal_point'] as int? ?? 0,
// fullName: json['full_name'] as String? ?? '',
// hiddenSupply: json['hidden_supply'] as bool,
// metaInfo: json['meta_info'] as String? ?? '',
// owner: json['owner'] as String? ?? '',
// ticker: json['ticker'] as String? ?? '',
// totalMaxSupply: json['total_max_supply'] as int? ?? 0,
// );
// }

View file

@ -1,7 +1,10 @@
import 'package:cw_core/amount_converter.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_zano/api/model/asset_info.dart';
import 'package:cw_zano/zano_asset.dart';
class Balance {
final AssetInfo assetInfo;
final ZanoAsset assetInfo;
final int awaitingIn;
final int awaitingOut;
final int total;
@ -14,9 +17,12 @@ class Balance {
required this.total,
required this.unlocked});
@override
String toString() => '$assetInfo: ${AmountConverter.amountIntToString(CryptoCurrency.zano, total)}/${AmountConverter.amountIntToString(CryptoCurrency.zano, unlocked)}';
factory Balance.fromJson(Map<String, dynamic> json) => Balance(
assetInfo:
AssetInfo.fromJson(json['asset_info'] as Map<String, dynamic>? ?? {}),
ZanoAsset.fromJson(json['asset_info'] as Map<String, dynamic>? ?? {}),
awaitingIn: json['awaiting_in'] as int? ?? 0,
awaitingOut: json['awaiting_out'] as int? ?? 0,
total: json['total'] as int? ?? 0,

View file

@ -4,26 +4,30 @@ import 'package:cw_zano/zano_asset.dart';
class DefaultZanoAssets {
final List<ZanoAsset> _defaultAssets = [
ZanoAsset(
assetId: 'd6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a',
decimal: 12,
name: 'Zano',
symbol: 'ZANO',
decimalPoint: 12,
fullName: 'Confidential token',
assetId: 'cc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6',
owner: '32911fabcf90b9731a152d2a3a75fcbb0a46c78e2f502678bae44c3d6823b4ce',
ticker: 'CT',
enabled: false,
),
ZanoAsset(
assetId: '123',
decimal: 12,
name: 'Test Coin',
symbol: 'TC',
decimalPoint: 12,
fullName: '새로운경제',
assetId: 'bb9590162509f956ff79851fb1bc0ced6646f5d5ba7eae847a9f21c92c39437c',
owner: '32911fabcf90b9731a152d2a3a75fcbb0a46c78e2f502678bae44c3d6823b4ce',
ticker: '새로운경제',
enabled: false,
),
];
List<ZanoAsset> get initialZanoAssets => _defaultAssets.map(
(token) {
(asset) {
String? iconPath;
if (CryptoCurrency.all.any((element) => element.title.toUpperCase() == token.symbol.toUpperCase())) {
iconPath = CryptoCurrency.all.singleWhere((element) => element.title.toUpperCase() == token.symbol.toUpperCase()).iconPath;
}
return ZanoAsset.copyWith(token, iconPath, 'ZANO');
try {
iconPath = CryptoCurrency.all.firstWhere((element) => element.title.toUpperCase() == asset.title.toUpperCase()).iconPath;
} catch (_) {}
return ZanoAsset.copyWith(asset, iconPath, 'ZANO');
},
).toList();
}

View file

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:cw_zano/api/exceptions/transfer_exception.dart';
import 'package:cw_zano/api/model/destination.dart';
import 'package:cw_zano/api/model/history.dart';
import 'package:cw_zano/api/model/transfer_params.dart';
import 'package:cw_zano/api/model/transfer_result.dart';
import 'package:cw_core/crypto_currency.dart';
@ -41,7 +42,7 @@ class PendingZanoTransaction with PendingTransaction {
final params = TransferParams(
destinations: destinations,
fee: fee,
mixin: zanoMixin,
mixin: zanoMixinValue,
paymentId: '',
comment: comment,
pushPayer: false,

View file

@ -7,58 +7,96 @@ part 'zano_asset.g.dart';
@HiveType(typeId: ZanoAsset.typeId)
class ZanoAsset extends CryptoCurrency with HiveObjectMixin {
@HiveField(0)
final String name;
final String fullName;
@HiveField(1)
final String symbol;
final String ticker;
@HiveField(2)
final String assetId;
@HiveField(3)
final int decimal;
final int decimalPoint;
@HiveField(4, defaultValue: true)
bool _enabled;
@HiveField(5)
final String? iconPath;
@HiveField(6)
final String? tag;
@HiveField(7)
final String owner;
@HiveField(8)
final String metaInfo;
@HiveField(9)
final int currentSupply;
@HiveField(10)
final bool hiddenSupply;
@HiveField(11)
final int totalMaxSupply;
bool get enabled => _enabled;
set enabled(bool value) => _enabled = value;
ZanoAsset({
required this.name,
required this.symbol,
this.fullName = '',
this.ticker = '',
required this.assetId,
required this.decimal,
this.decimalPoint = defaultDecimalPoint,
bool enabled = true,
this.iconPath,
this.tag,
this.owner = defaultOwner,
this.metaInfo = '',
this.currentSupply = 0,
this.hiddenSupply = false,
this.totalMaxSupply = 0,
}) : _enabled = enabled,
super(
name: symbol.toLowerCase(),
title: symbol.toUpperCase(),
fullName: name,
tag: tag,
iconPath: iconPath,
decimals: decimal);
name: fullName,
title: ticker.toUpperCase(),
fullName: fullName,
tag: tag,
iconPath: iconPath,
decimals: decimalPoint,
);
ZanoAsset.copyWith(ZanoAsset other, String? icon, String? tag)
: this.name = other.name,
this.symbol = other.symbol,
this.assetId = other.assetId,
this.decimal = other.decimal,
this._enabled = other.enabled,
ZanoAsset.copyWith(ZanoAsset other, String? icon, String? tag, {String? assetId, bool enabled = false})
: this.fullName = other.fullName,
this.ticker = other.ticker,
this.assetId = assetId ?? other.assetId,
this.decimalPoint = other.decimalPoint,
this._enabled = enabled || other.enabled,
this.tag = tag,
this.iconPath = icon,
this.currentSupply = other.currentSupply,
this.hiddenSupply = other.hiddenSupply,
this.metaInfo = other.metaInfo,
this.owner = other.owner,
this.totalMaxSupply = other.totalMaxSupply,
super(
name: other.name,
title: other.symbol.toUpperCase(),
title: other.ticker.toUpperCase(),
fullName: other.name,
tag: tag,
iconPath: icon,
decimals: other.decimal,
decimals: other.decimalPoint,
);
factory ZanoAsset.fromJson(Map<String, dynamic> json) => ZanoAsset(
assetId: json['asset_id'] as String? ?? '',
currentSupply: json['current_supply'] as int? ?? 0,
decimalPoint: json['decimal_point'] as int? ?? defaultDecimalPoint,
fullName: json['full_name'] as String? ?? '',
hiddenSupply: json['hidden_supply'] as bool? ?? false,
metaInfo: json['meta_info'] as String? ?? '',
owner: json['owner'] as String? ?? '',
ticker: json['ticker'] as String? ?? '',
totalMaxSupply: json['total_max_supply'] as int? ?? 0,
);
@override
String toString() => '$ticker (${assetId.substring(0, 4)}...${assetId.substring(assetId.length - 4)})';
static const typeId = ZANO_ASSET_TYPE_ID;
static const zanoAssetsBoxName = 'zanoAssets';
}
static const zanoAssetsBoxName = 'zanoAssetsBox';
static const defaultDecimalPoint = 12;
static const defaultOwner = '0000000000000000000000000000000000000000000000000000000000000000';
}

View file

@ -1,8 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'dart:math';
import 'package:cw_core/cake_hive.dart';
import 'package:cw_core/crypto_currency.dart';
@ -17,13 +14,9 @@ import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_zano/api/api_calls.dart';
import 'package:cw_zano/api/model/destination.dart';
import 'package:cw_zano/api/model/get_recent_txs_and_info_params.dart';
import 'package:cw_zano/api/model/get_wallet_info_result.dart';
import 'package:cw_zano/api/model/get_wallet_status_result.dart';
import 'package:cw_zano/api/model/history.dart';
import 'package:cw_zano/api/model/store_result.dart';
import 'package:cw_zano/api/model/zano_wallet_keys.dart';
import 'package:cw_zano/api/zano_api.dart';
import 'package:cw_zano/exceptions/zano_transaction_creation_exception.dart';
import 'package:cw_zano/pending_zano_transaction.dart';
import 'package:cw_zano/zano_asset.dart';
@ -32,7 +25,7 @@ import 'package:cw_zano/zano_transaction_credentials.dart';
import 'package:cw_zano/zano_transaction_history.dart';
import 'package:cw_zano/zano_transaction_info.dart';
import 'package:cw_zano/zano_wallet_addresses.dart';
import 'package:ffi/ffi.dart';
import 'package:cw_zano/zano_wallet_api.dart';
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
@ -41,23 +34,15 @@ import 'default_zano_assets.dart';
part 'zano_wallet.g.dart';
const moneroBlockSize = 1000;
const int zanoMixin = 10;
typedef _load_wallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, Int8);
typedef _LoadWallet = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, int);
const int zanoMixinValue = 10;
class ZanoWallet = ZanoWalletBase with _$ZanoWallet;
abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHistory, ZanoTransactionInfo> with Store {
abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHistory, ZanoTransactionInfo> with Store, ZanoWalletApi {
static const int _autoSaveInterval = 30;
static const _statusDelivered = 'delivered';
static const _maxAttempts = 10;
List<History> history = [];
String defaultAsssetId = '';
//String defaultAsssetId = '';
@override
ZanoWalletAddresses walletAddresses;
@ -88,7 +73,6 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
bool _isTransactionUpdating;
bool _hasSyncAfterStartup;
Timer? _autoSaveTimer;
int _hWallet = 0;
ZanoWalletBase(WalletInfo walletInfo)
: balance = ObservableMap.of({CryptoCurrency.zano: ZanoBalance(total: 0, unlocked: 0)}),
@ -98,7 +82,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
syncStatus = NotConnectedSyncStatus(),
super(walletInfo) {
transactionHistory = ZanoTransactionHistory();
if (!CakeHive.isAdapterRegistered(ZanoAsset.typeId)) {
if (!CakeHive.isAdapterRegistered(ZanoAsset.typeId)) {
CakeHive.registerAdapter(ZanoAssetAdapter());
}
// _onAccountChangeReaction =
@ -111,25 +95,17 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
// });
}
int get hWallet => _hWallet;
set hWallet(int value) {
_hWallet = value;
}
@override
int calculateEstimatedFee(TransactionPriority priority, [int? amount = null]) {
return ApiCalls.getCurrentTxFee(priority: priority.raw);
}
int calculateEstimatedFee(TransactionPriority priority, [int? amount = null]) => getCurrentTxFee(priority);
@override
Future<void> changePassword(String password) async {
ApiCalls.setPassword(hWallet: hWallet, password: password);
setPassword(password);
}
@override
void close() {
ApiCalls.closeWallet(hWallet: hWallet);
closeWallet();
_updateSyncInfoTimer?.cancel();
//_listener?.stop();
// _onAccountChangeReaction?.reaction.dispose();
@ -138,23 +114,16 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
@override
Future<void> connectToNode({required Node node}) async {
try {
syncStatus = ConnectingSyncStatus();
await ApiCalls.setupNode(
address: '195.201.107.230:33336', // node.uriRaw,
login: '', // node.login,
password: '', // node.password,
useSSL: false, // node.useSSL ?? false,
isLightWallet: false, // FIXME: hardcoded value
/*socksProxyAddress: node.socksProxyAddress*/
);
//zano_wallet.setTrustedDaemon(node.trusted);
syncStatus = ConnectedSyncStatus();
} catch (e) {
syncStatus = FailedSyncStatus();
print(e);
}
syncStatus = ConnectingSyncStatus();
await setupNode();
syncStatus = ConnectedSyncStatus();
// if (await setupNode() == false) {
// syncStatus = FailedSyncStatus();
// // TODO: what's going on?
// //throw 'error connecting to zano node';
// } else {
// syncStatus = ConnectedSyncStatus();
// }
}
@override
@ -178,7 +147,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
.map((output) => Destination(
amount: output.formattedCryptoAmount ?? 0,
address: output.isParsedAddress ? output.extractedAddress! : output.address,
assetId: defaultAsssetId,
assetId: "defaultAsssetId",
))
.toList();
} else {
@ -197,7 +166,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
Destination(
amount: amount,
address: output.isParsedAddress ? output.extractedAddress! : output.address,
assetId: defaultAsssetId,
assetId: "defaultAsssetId",
)
];
}
@ -229,22 +198,14 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
}
}
GetWalletInfoResult getWalletInfo() {
final json = ApiCalls.getWalletInfo(hWallet);
print('wallet info $json'); // TODO: remove
final result = GetWalletInfoResult.fromJson(jsonDecode(json) as Map<String, dynamic>);
return result;
}
GetWalletStatusResult getWalletStatus() {
final json = ApiCalls.getWalletStatus(hWallet: hWallet);
print('wallet status $json'); // TODO: remove
final status = GetWalletStatusResult.fromJson(jsonDecode(json) as Map<String, dynamic>);
return status;
}
Future<void> init(String address) async {
_initZanoAssetsBox();
final boxName = "${walletInfo.name.replaceAll(" ", "_")}_${ZanoAsset.zanoAssetsBoxName}";
zanoAssetsBox = await CakeHive.openBox<ZanoAsset>(boxName);
print(
'assets in box total: ${zanoAssetsBox.length} ${zanoAssetsBox.values} active: ${zanoAssetsBox.values.where((element) => element.enabled).length} ${zanoAssetsBox.values.where((element) => element.enabled)}');
for (final asset in zanoAssetsBox.values) {
if (asset.enabled) balance[asset] = ZanoBalance(total: 0, unlocked: 0);
}
await walletAddresses.init();
await walletAddresses.updateAddress(address);
@ -255,25 +216,6 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
_autoSaveTimer = Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save());
}
Future<String> invokeMethod(String methodName, Object params) async {
var invokeResult =
ApiCalls.asyncCall(methodName: 'invoke', hWallet: hWallet, params: '{"method": "$methodName","params": ${jsonEncode(params)}}');
var map = jsonDecode(invokeResult) as Map<String, dynamic>;
int attempts = 0;
if (map['job_id'] != null) {
final jobId = map['job_id'] as int;
do {
await Future.delayed(Duration(milliseconds: attempts < 2 ? 100 : 500));
final result = ApiCalls.tryPullResult(jobId);
map = jsonDecode(result) as Map<String, dynamic>;
if (map['status'] != null && map['status'] == _statusDelivered && map['result'] != null) {
return result;
}
} while (++attempts < _maxAttempts);
}
return invokeResult;
}
String loadWallet(String path, String password) {
print('load_wallet path $path password $password');
final result = ApiCalls.loadWallet(path: path, password: password);
@ -312,7 +254,6 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
debugPrint('setRefreshFromBlockHeight height $height');
debugPrint('rescanBlockchainAsync');
await startSync();
_askForUpdateBalance();
/**walletAddresses.accountList.update();*/
await _askForUpdateTransactionHistory();
await save();
@ -335,6 +276,9 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
await walletInfo.save();
}
bool _calledOnce = false;
int _counter = 0;
@override
Future<void> startSync() async {
try {
@ -342,7 +286,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
_cachedBlockchainHeight = 0;
_lastKnownBlockHeight = 0;
_initialSyncHeight = 0;
_updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async {
_updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: /*1200*/5000), (_) async {
/*if (isNewTransactionExist()) {
onNewTransaction?.call();
}*/
@ -360,10 +304,32 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
publicViewKey: walletInfo.wiExtended.viewPublicKey,
);
final _balance = walletInfo.wi.balances.first;
defaultAsssetId = _balance.assetInfo.assetId;
balance[CryptoCurrency.zano] = ZanoBalance(total: _balance.total, unlocked: _balance.unlocked);
//balance = ObservableMap.of({CryptoCurrency.zano: ZanoBalance(total: _balance.total, unlocked: _balance.unlocked)});
for (final item in walletInfo.wi.balances) {
if (item.assetInfo.ticker == 'ZANO') {
balance[CryptoCurrency.zano] = ZanoBalance(total: item.total, unlocked: item.unlocked);
} else {
for (final asset in balance.keys) {
if (asset is ZanoAsset && asset.assetId == item.assetInfo.assetId) {
balance[asset] = ZanoBalance(total: item.total, unlocked: item.unlocked);
}
}
}
}
//await getAssetsWhitelist();
if (!_calledOnce) {
//await addAssetsWhitelist('00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff');
//await removeAssetsWhitelist('cc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6');
//await removeAssetsWhitelist('bb9590162509f956ff79851fb1bc0ced6646f5d5ba7eae847a9f21c92c39437c');
//await removeAssetsWhitelist('');
_calledOnce = true;
} else {
await getAssetsWhitelist();
}
// if (++_counter >= 10) {
// await getAssetsWhitelist();
// _counter = 0;
// }
}
});
} catch (e) {
@ -373,19 +339,6 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
}
}
Future<void> store() async {
try {
final json = await invokeMethod('store', '{}');
final map = jsonDecode(json) as Map<String, dynamic>;
if (map['result'] == null || map['result']['result'] == null) {
throw 'store empty response';
}
final _ = StoreResult.fromJson(map['result']['result'] as Map<String, dynamic>);
} catch (e) {
print(e.toString());
}
}
@override
Future<void>? updateBalance() => null;
@ -405,15 +358,6 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
}
}
Future<void> _initZanoAssetsBox() async {
final boxName = "${walletInfo.name.replaceAll(" ", "_")}_${ZanoAsset.zanoAssetsBoxName}";
if (await CakeHive.boxExists(boxName)) {
zanoAssetsBox = await CakeHive.openBox<ZanoAsset>(boxName);
} else {
zanoAssetsBox = await CakeHive.openBox<ZanoAsset>(boxName.replaceAll(" ", ""));
}
}
void addInitialAssets() {
final initialZanoAssets = DefaultZanoAssets().initialZanoAssets;
@ -422,46 +366,56 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
}
}
ZanoAsset createNewZanoAssetObject(ZanoAsset asset, String? iconPath) {
return ZanoAsset(
name: asset.name,
symbol: asset.symbol,
assetId: asset.assetId,
decimal: asset.decimal,
enabled: asset.enabled,
tag: asset.tag ?? "ZANO",
iconPath: iconPath,
);
}
Future<void> addZanoAsset(ZanoAsset asset) async {
Future<CryptoCurrency> addZanoAssetById(String assetId) async {
if (zanoAssetsBox.containsKey(assetId)) {
throw 'zano asset with id $assetId already added';
}
final assetDescriptor = await addAssetsWhitelist(assetId);
if (assetDescriptor == null) {
throw "there's no zano asset with id $assetId";
}
String? iconPath;
try {
iconPath = CryptoCurrency.all
.firstWhere((element) => element.title.toUpperCase() == asset.title.toUpperCase())
.iconPath;
iconPath = CryptoCurrency.all.firstWhere((element) => element.title.toUpperCase() == assetDescriptor.title.toUpperCase()).iconPath;
} catch (_) {}
final asset = ZanoAsset.copyWith(assetDescriptor, iconPath, 'ZANO', assetId: assetId, enabled: true);
await zanoAssetsBox.put(asset.assetId, ZanoAsset.copyWith(asset, iconPath, 'ZANO'));
balance[asset] = ZanoBalance(total: 0, unlocked: 0);
return asset;
}
final newAsset = createNewZanoAssetObject(asset, iconPath);
await zanoAssetsBox.put(newAsset.assetId, newAsset);
Future<void> addRemoveZanoAsset(ZanoAsset asset) async {
String? iconPath;
try {
iconPath = CryptoCurrency.all.firstWhere((element) => element.title.toUpperCase() == asset.title.toUpperCase()).iconPath;
} catch (_) {}
await zanoAssetsBox.put(asset.assetId, ZanoAsset.copyWith(asset, iconPath, 'ZANO'));
if (asset.enabled) {
final assetDescriptor = await addAssetsWhitelist(asset.assetId);
if (assetDescriptor == null) {
print('error adding zano asset');
return;
}
balance[asset] = ZanoBalance(total: 0, unlocked: 0);
} else {
balance.remove(asset);
final result = await removeAssetsWhitelist(asset.assetId);
if (result == false) {
print('error removing zano asset');
return;
}
balance.removeWhere((key, _) => key is ZanoAsset && key.assetId == asset.assetId);
}
}
Future<void> deleteZanoAsset(ZanoAsset token) async {
await token.delete();
balance.remove(token);
//_updateBalance();
Future<void> deleteZanoAsset(ZanoAsset asset) async {
final result = await removeAssetsWhitelist(asset.assetId);
if (result == false) return;
await asset.delete();
balance.removeWhere((key, _) => key is ZanoAsset && key.assetId == asset.assetId);
}
Future<ZanoAsset?> getZanoAsset(String assetId) async {
return ZanoAsset(assetId: assetId, decimal: 12, name: 'Not implemented', symbol: 'NI');
return null;
}
// List<ZanoTransactionInfo> _getAllTransactions(dynamic _) =>
@ -475,23 +429,17 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
// _listener = zano_wallet.setListeners(_onNewBlock, _onNewTransaction);
// }
void _askForUpdateBalance() {
debugPrint('askForUpdateBalance'); // TODO: remove, also remove this method completely
}
Future<void> _askForUpdateTransactionHistory() async => await updateTransactions();
void _onNewBlock(int height, int blocksLeft, double ptc) async {
try {
if (walletInfo.isRecovery) {
await _askForUpdateTransactionHistory();
_askForUpdateBalance();
/*walletAddresses.accountList.update();*/
}
if (blocksLeft < 1000) {
await _askForUpdateTransactionHistory();
_askForUpdateBalance();
/*walletAddresses.accountList.update();*/
syncStatus = SyncedSyncStatus();
@ -514,7 +462,6 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
void _onNewTransaction() async {
try {
await _askForUpdateTransactionHistory();
_askForUpdateBalance();
await Future<void>.delayed(Duration(seconds: 1)); // TODO: ???
} catch (e) {
print(e.toString());
@ -523,31 +470,7 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
Future<void> _refreshTransactions() async {
try {
final result = await invokeMethod('get_recent_txs_and_info', GetRecentTxsAndInfoParams(offset: 0, count: 30));
final map = jsonDecode(result) as Map<String, dynamic>?;
if (map == null) {
print('get_recent_txs_and_info empty response');
return;
}
final resultData = map['result'];
if (resultData == null) {
print('get_recent_txs_and_info empty response');
return;
}
if (resultData['error'] != null) {
print('get_recent_txs_and_info error ${resultData['error']}');
return;
}
final transfers = resultData['result']?['transfers'] as List<dynamic>?;
if (transfers == null) {
print('get_recent_txs_and_info empty transfers');
return;
}
history = transfers.map((e) => History.fromJson(e as Map<String, dynamic>)).toList();
history = await getRecentTxsAndInfo();
} catch (e) {
print(e.toString());
}

View file

@ -0,0 +1,186 @@
import 'dart:convert';
import 'package:cw_core/transaction_priority.dart';
import 'package:cw_zano/api/api_calls.dart';
import 'package:cw_zano/api/model/add_remove_assets_whitelist_params.dart';
import 'package:cw_zano/api/model/asset_descriptor.dart';
import 'package:cw_zano/api/model/get_recent_txs_and_info_params.dart';
import 'package:cw_zano/api/model/get_wallet_info_result.dart';
import 'package:cw_zano/api/model/get_wallet_status_result.dart';
import 'package:cw_zano/api/model/history.dart';
import 'package:cw_zano/zano_asset.dart';
import 'api/model/store_result.dart';
enum _LogType { none, simple, json }
mixin ZanoWalletApi {
static const _defaultNodeUri = '195.201.107.230:33336';
static const _statusDelivered = 'delivered';
static const _maxAttempts = 10;
static const _logType = _LogType.simple;
int _hWallet = 0;
int get hWallet => _hWallet;
set hWallet(int value) {
_hWallet = value;
}
int getCurrentTxFee(TransactionPriority priority) => ApiCalls.getCurrentTxFee(priority: priority.raw);
void setPassword(String password) => ApiCalls.setPassword(hWallet: hWallet, password: password);
void closeWallet() => ApiCalls.closeWallet(hWallet: hWallet);
Future<bool> setupNode() async => ApiCalls.setupNode(
address: _defaultNodeUri,
login: '',
password: '',
useSSL: false,
isLightWallet: false,
);
GetWalletInfoResult getWalletInfo() {
final json = ApiCalls.getWalletInfo(hWallet);
final result = GetWalletInfoResult.fromJson(jsonDecode(json) as Map<String, dynamic>);
switch (_logType) {
case _LogType.json:
print('get_wallet_info $json');
break;
case _LogType.simple:
print('get_wallet_info got ${result.wi.balances.length} balances: ${result.wi.balances}');
}
return result;
}
GetWalletStatusResult getWalletStatus() {
final json = ApiCalls.getWalletStatus(hWallet: hWallet);
final status = GetWalletStatusResult.fromJson(jsonDecode(json) as Map<String, dynamic>);
switch (_logType) {
case _LogType.json:
print('get_wallet_status $json');
break;
case _LogType.simple:
print('get_wallet_status connected: ${status.isDaemonConnected} in refresh: ${status.isInLongRefresh} wallet state: ${status.walletState}');
}
return status;
}
Future<String> invokeMethod(String methodName, Object params) async {
var invokeResult =
ApiCalls.asyncCall(methodName: 'invoke', hWallet: hWallet, params: '{"method": "$methodName","params": ${jsonEncode(params)}}');
var map = jsonDecode(invokeResult) as Map<String, dynamic>;
int attempts = 0;
if (map['job_id'] != null) {
final jobId = map['job_id'] as int;
do {
await Future.delayed(Duration(milliseconds: attempts < 2 ? 100 : 500));
final result = ApiCalls.tryPullResult(jobId);
map = jsonDecode(result) as Map<String, dynamic>;
if (map['status'] != null && map['status'] == _statusDelivered && map['result'] != null) {
return result;
}
} while (++attempts < _maxAttempts);
}
return invokeResult;
}
Future<List<ZanoAsset>> getAssetsWhitelist() async {
try {
final json = await invokeMethod('assets_whitelist_get', '{}');
if (_logType == _LogType.json) print('assets_whitelist_get $json');
final map = jsonDecode(json) as Map<String, dynamic>?;
_checkForErrors(map);
final assets = map?['result']?['result']?['assets'] as List<dynamic>?;
final result = assets?.map((e) => ZanoAsset.fromJson(e as Map<String, dynamic>)).toList();
if (_logType == _LogType.simple) print('assets_whitelist_get got ${result?.length ?? 0} assets: $result');
return result ?? [];
} catch (e) {
print(e.toString());
return [];
}
}
Future<ZanoAsset?> addAssetsWhitelist(String assetId) async {
try {
final json = await invokeMethod('assets_whitelist_add', AddRemoveAssetsWhitelistParams(assetId: assetId));
if (_logType == _LogType.json) print('assets_whitelist_add $assetId $json');
final map = jsonDecode(json) as Map<String, dynamic>?;
_checkForErrors(map);
if (map!['result']!['result']!['status']! == 'OK') {
final assetDescriptor = ZanoAsset.fromJson(map['result']!['result']!['asset_descriptor']! as Map<String, dynamic>);
if (_logType == _LogType.simple) print('assets_whitelist_add added ${assetDescriptor.fullName} ${assetDescriptor.ticker}');
return assetDescriptor;
} else {
if (_logType == _LogType.simple) print('assets_whitelist_add status ${map['result']!['result']!['status']!}');
return null;
}
} catch (e) {
print(e.toString());
return null;
}
}
Future<bool> removeAssetsWhitelist(String assetId) async {
try {
final json = await invokeMethod('assets_whitelist_remove', AddRemoveAssetsWhitelistParams(assetId: assetId));
if (_logType == _LogType.json) print('assets_whitelist_remove $assetId $json');
final map = jsonDecode(json) as Map<String, dynamic>?;
_checkForErrors(map);
if (_logType == _LogType.simple) print('assets_whitelist_remove status ${map!['result']!['result']!['status']!}');
return (map!['result']!['result']!['status']! == 'OK');
} catch (e) {
print(e.toString());
return false;
}
}
Future<StoreResult?> store() async {
try {
final json = await invokeMethod('store', '{}');
final map = jsonDecode(json) as Map<String, dynamic>?;
_checkForErrors(map);
return StoreResult.fromJson(map!['result']['result'] as Map<String, dynamic>);
} catch (e) {
print(e);
return null;
}
}
Future<List<History>> getRecentTxsAndInfo() async {
try {
final json = await invokeMethod('get_recent_txs_and_info', GetRecentTxsAndInfoParams(offset: 0, count: 30));
final map = jsonDecode(json) as Map<String, dynamic>?;
_checkForErrors(map);
final transfers = map?['result']?['result']?['transfers'] as List<dynamic>?;
if (transfers == null) {
print('get_recent_txs_and_info empty transfers');
return [];
}
return transfers.map((e) => History.fromJson(e as Map<String, dynamic>)).toList();
} catch (e) {
print(e);
return [];
}
}
void _checkForErrors(Map<String, dynamic>? map) {
if (map == null) {
throw 'empty response';
}
final result = map['result'];
if (result == null) {
throw 'empty response';
}
if (result['error'] != null) {
final code = result['error']!['code'] ?? '';
final message = result['error']!['message'] ?? '';
throw 'error $code $message';
}
}
}

View file

@ -18,6 +18,7 @@ import 'package:cw_zano/api/exceptions/create_wallet_exception.dart';
import 'package:cw_zano/api/exceptions/restore_from_seed_exception.dart';
import 'package:cw_zano/api/exceptions/wrong_seed_exception.dart';
import 'package:cw_zano/api/model/create_wallet_result.dart';
import 'package:cw_zano/zano_asset.dart';
import 'package:cw_zano/zano_balance.dart';
import 'package:cw_zano/zano_wallet.dart';
import 'package:hive/hive.dart';
@ -36,7 +37,13 @@ class ZanoRestoreWalletFromSeedCredentials extends WalletCredentials {
class ZanoRestoreWalletFromKeysCredentials extends WalletCredentials {
ZanoRestoreWalletFromKeysCredentials(
{required String name, required String password, required this.language, required this.address, required this.viewKey, required this.spendKey, required int height})
{required String name,
required String password,
required this.language,
required this.address,
required this.viewKey,
required this.spendKey,
required int height})
: super(name: name, password: password, height: height);
final String language;
@ -126,7 +133,7 @@ class ZanoWalletService extends WalletService<ZanoNewWalletCredentials, ZanoRest
final message = map['error']!['message'] ?? '';
throw CreateWalletException('Error creating/loading wallet $code $message');
}
if (map['result'] == null) {
if (map['result'] == null) {
throw CreateWalletException('Error creating/loading wallet, empty response');
}
}
@ -135,9 +142,17 @@ class ZanoWalletService extends WalletService<ZanoNewWalletCredentials, ZanoRest
hWallet = result.walletId;
wallet.hWallet = hWallet;
wallet.walletAddresses.address = result.wi.address;
final balance = result.wi.balances.first;
wallet.defaultAsssetId = balance.assetInfo.assetId;
wallet.balance = ObservableMap.of({CryptoCurrency.zano: ZanoBalance(total: balance.total, unlocked: balance.unlocked)});
for (final item in result.wi.balances) {
if (item.assetInfo.ticker == 'ZANO') {
wallet.balance[CryptoCurrency.zano] = ZanoBalance(total: item.total, unlocked: item.unlocked);
} else {
for (final asset in wallet.balance.keys) {
if (asset is ZanoAsset && asset.assetId == item.assetInfo.assetId) {
wallet.balance[asset] = ZanoBalance(total: item.total, unlocked: item.unlocked);
}
}
}
}
if (result.recentHistory.history != null) {
wallet.history = result.recentHistory.history!;
}

View file

@ -2,14 +2,17 @@ import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/widgets/address_text_field.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:cake_wallet/src/widgets/checkbox_widget.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
import 'package:cake_wallet/themes/extensions/transaction_trade_theme.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/dashboard/home_settings_view_model.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/erc20_token.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_zano/zano_asset.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@ -79,7 +82,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
if (widget.token != null) {
address = widget.homeSettingsViewModel.getTokenAddressBasedOnWallet(widget.token!);
_contractAddressController.text = address ?? '';
_tokenNameController.text = widget.token!.name;
_tokenSymbolController.text = widget.token!.title;
@ -145,9 +148,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal,
color: Theme.of(context)
.extension<TransactionTradeTheme>()!
.detailsTitlesColor,
color: Theme.of(context).extension<TransactionTradeTheme>()!.detailsTitlesColor,
),
),
),
@ -194,25 +195,32 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
Expanded(
child: PrimaryButton(
onPressed: () async {
if (_formKey.currentState!.validate() &&
(!_showDisclaimer || _disclaimerChecked)) {
// TODO: fix it!!!
await widget.homeSettingsViewModel.addToken(ZanoAsset(
name: _tokenNameController.text,
symbol: _tokenSymbolController.text,
assetId: _contractAddressController.text,
decimal: int.parse(_tokenDecimalController.text),
));
// await widget.homeSettingsViewModel.addToken(Erc20Token(
// name: _tokenNameController.text,
// symbol: _tokenSymbolController.text,
// contractAddress: _contractAddressController.text,
// decimal: int.parse(_tokenDecimalController.text),
// ));
if (context.mounted) {
Navigator.pop(context);
if (_formKey.currentState!.validate() && (!_showDisclaimer || _disclaimerChecked)) {
if (widget.homeSettingsViewModel.walletType == WalletType.zano) {
if (!await widget.homeSettingsViewModel.addAsset(_contractAddressController.text)) {
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: S.current.error,
alertContent: 'Cannot add asset ${_contractAddressController.text}',
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
return;
}
} else {
await widget.homeSettingsViewModel.addToken(Erc20Token(
name: _tokenNameController.text,
symbol: _tokenSymbolController.text,
contractAddress: _contractAddressController.text,
decimal: int.parse(_tokenDecimalController.text),
));
}
}
if (context.mounted) {
Navigator.pop(context);
}
},
text: S.of(context).save,
color: Theme.of(context).primaryColor,
@ -234,8 +242,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
if (token != null) {
if (_tokenNameController.text.isEmpty) _tokenNameController.text = token.name;
if (_tokenSymbolController.text.isEmpty) _tokenSymbolController.text = token.title;
if (_tokenDecimalController.text.isEmpty)
_tokenDecimalController.text = token.decimals.toString();
if (_tokenDecimalController.text.isEmpty) _tokenDecimalController.text = token.decimals.toString();
}
}
}
@ -271,53 +278,55 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
_pasteText();
},
),
const SizedBox(height: 8),
BaseTextFormField(
controller: _tokenNameController,
focusNode: _tokenNameFocusNode,
onSubmit: (_) => FocusScope.of(context).requestFocus(_tokenSymbolFocusNode),
textInputAction: TextInputAction.next,
hintText: S.of(context).token_name,
validator: (text) {
if (text?.isNotEmpty ?? false) {
return null;
}
if (widget.homeSettingsViewModel.walletType != WalletType.zano) ...[
const SizedBox(height: 8),
BaseTextFormField(
controller: _tokenNameController,
focusNode: _tokenNameFocusNode,
onSubmit: (_) => FocusScope.of(context).requestFocus(_tokenSymbolFocusNode),
textInputAction: TextInputAction.next,
hintText: S.of(context).token_name,
validator: (text) {
if (text?.isNotEmpty ?? false) {
return null;
}
return S.of(context).field_required;
},
),
const SizedBox(height: 8),
BaseTextFormField(
controller: _tokenSymbolController,
focusNode: _tokenSymbolFocusNode,
onSubmit: (_) => FocusScope.of(context).requestFocus(_tokenDecimalFocusNode),
textInputAction: TextInputAction.next,
hintText: S.of(context).token_symbol,
validator: (text) {
if (text?.isNotEmpty ?? false) {
return null;
}
return S.of(context).field_required;
},
),
const SizedBox(height: 8),
BaseTextFormField(
controller: _tokenDecimalController,
focusNode: _tokenDecimalFocusNode,
textInputAction: TextInputAction.done,
hintText: S.of(context).token_decimal,
validator: (text) {
if (text?.isEmpty ?? true) {
return S.of(context).field_required;
}
if (int.tryParse(text!) == null) {
return S.of(context).invalid_input;
}
},
),
const SizedBox(height: 8),
BaseTextFormField(
controller: _tokenSymbolController,
focusNode: _tokenSymbolFocusNode,
onSubmit: (_) => FocusScope.of(context).requestFocus(_tokenDecimalFocusNode),
textInputAction: TextInputAction.next,
hintText: S.of(context).token_symbol,
validator: (text) {
if (text?.isNotEmpty ?? false) {
return null;
}
return null;
},
),
return S.of(context).field_required;
},
),
const SizedBox(height: 8),
BaseTextFormField(
controller: _tokenDecimalController,
focusNode: _tokenDecimalFocusNode,
textInputAction: TextInputAction.done,
hintText: S.of(context).token_decimal,
validator: (text) {
if (text?.isEmpty ?? true) {
return S.of(context).field_required;
}
if (int.tryParse(text!) == null) {
return S.of(context).invalid_input;
}
return null;
},
),
],
SizedBox(height: 24),
],
),

View file

@ -27,6 +27,8 @@ abstract class HomeSettingsViewModelBase with Store {
final ObservableSet<CryptoCurrency> tokens;
WalletType get walletType => _balanceViewModel.wallet.type;
@observable
String searchText = '';
@ -45,6 +47,20 @@ abstract class HomeSettingsViewModelBase with Store {
@action
void setPinNativeToken(bool value) => _settingsStore.pinNativeTokenAtTop = value;
Future<bool> addAsset(String assetId) async {
if (_balanceViewModel.wallet.type == WalletType.zano) {
try {
final asset = await zano!.addZanoAssetById(_balanceViewModel.wallet, assetId);
_updateTokensList();
_updateFiatPrices(asset);
return true;
} catch (e) {
return false;
}
}
return false;
}
Future<void> addToken(CryptoCurrency token) async {
if (_balanceViewModel.wallet.type == WalletType.ethereum) {
await ethereum!.addErc20Token(_balanceViewModel.wallet, token);

View file

@ -159,7 +159,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
language: 'English',
);
if (type == WalletType.zano) {
case WalletType.zano:
return zano!.createZanoRestoreWalletFromKeysCredentials(
name: name,
height: height,
@ -168,7 +168,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
address: address!,
password: password,
language: 'English');
}
case WalletType.ethereum:
return ethereum!.createEthereumRestoreWalletFromPrivateKey(

View file

@ -84,18 +84,22 @@ class CWZano extends Zano {
return zanoWallet.zanoAssets;
}
@override
Future<CryptoCurrency> addZanoAssetById(WalletBase wallet, String assetId) async =>
await (wallet as ZanoWallet).addZanoAssetById(assetId);
@override
Future<void> addZanoAsset(WalletBase wallet, CryptoCurrency token) async =>
await (wallet as ZanoWallet).addZanoAsset(token as ZanoAsset);
await (wallet as ZanoWallet).addRemoveZanoAsset(token as ZanoAsset);
@override
Future<void> deleteZanoAsset(WalletBase wallet, CryptoCurrency token) async =>
await (wallet as ZanoWallet).deleteZanoAsset(token as ZanoAsset);
@override
Future<ZanoAsset?> getZanoAsset(WalletBase wallet, String mintAddress) async {
Future<ZanoAsset?> getZanoAsset(WalletBase wallet, String assetId) async {
final zanoWallet = wallet as ZanoWallet;
return await zanoWallet.getZanoAsset(mintAddress);
return await zanoWallet.getZanoAsset(assetId);
}
@override
@ -234,8 +238,4 @@ class CWZano extends Zano {
}
String getZanoAssetAddress(CryptoCurrency asset) => (asset as ZanoAsset).assetId;
// @override
// List<AssetRate> getAssetRate() =>
// getRate().map((rate) => AssetRate(rate.getAssetType(), rate.getRate())).toList();
}

View file

@ -69,12 +69,6 @@ class ZanoBalance extends Balance {
String get formattedAdditionalBalance => formattedFullBalance;
}
class AssetRate {
AssetRate(this.asset, this.rate);
final String asset;
final int rate;
}
abstract class ZanoWalletDetails {
// FIX-ME: it's abstruct class
@ -123,9 +117,9 @@ abstract class Zano {
List<ZanoAsset> getZanoAssets(WalletBase wallet);
String getZanoAssetAddress(CryptoCurrency asset);
Future<void> addZanoAsset(WalletBase wallet, CryptoCurrency token);
Future<CryptoCurrency> addZanoAssetById(WalletBase wallet, String assetId);
Future<void> deleteZanoAsset(WalletBase wallet, CryptoCurrency token);
Future<CryptoCurrency?> getZanoAsset(WalletBase wallet, String contractAddress);
// List<AssetRate> getAssetRate();
}
// abstract class MoneroSubaddressList {