From 219f43a959c6e74ce77b6ebff93e23915ea519e3 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 15 Oct 2023 13:36:05 +0000 Subject: [PATCH] added dummy wallet & some zano implementation --- cw_core/lib/crypto_currency.dart | 1 + cw_core/lib/currency_for_wallet_type.dart | 2 + cw_core/lib/node.dart | 4 + cw_core/lib/wallet_type.dart | 14 ++++ cw_dummy/.gitignore | 30 +++++++ cw_dummy/.metadata | 10 +++ cw_dummy/CHANGELOG.md | 3 + cw_dummy/LICENSE | 1 + cw_dummy/README.md | 39 +++++++++ cw_dummy/analysis_options.yaml | 4 + cw_dummy/lib/cw_dummy.dart | 7 ++ cw_dummy/lib/dummy_balance.dart | 14 ++++ ...ummy_transaction_creation_credentials.dart | 10 +++ cw_dummy/lib/dummy_transaction_history.dart | 28 +++++++ cw_dummy/lib/dummy_transaction_info.dart | 27 ++++++ cw_dummy/lib/dummy_transaction_priority.dart | 20 +++++ cw_dummy/lib/dummy_wallet.dart | 72 ++++++++++++++++ cw_dummy/lib/dummy_wallet_addresses.dart | 23 +++++ .../dummy_wallet_creation_credentials.dart | 18 ++++ cw_dummy/lib/dummy_wallet_service.dart | 40 +++++++++ .../.plugin_symlinks/path_provider_linux | 1 + .../flutter/generated_plugin_registrant.cc | 11 +++ .../flutter/generated_plugin_registrant.h | 15 ++++ .../linux/flutter/generated_plugins.cmake | 23 +++++ .../Flutter/GeneratedPluginRegistrant.swift | 12 +++ .../ephemeral/Flutter-Generated.xcconfig | 11 +++ .../ephemeral/flutter_export_environment.sh | 12 +++ cw_dummy/pubspec.yaml | 67 +++++++++++++++ cw_dummy/test/cw_dummy_test.dart | 12 +++ .../flutter/generated_plugin_registrant.cc | 11 +++ .../flutter/generated_plugin_registrant.h | 15 ++++ .../windows/flutter/generated_plugins.cmake | 23 +++++ cw_zano/ios/Classes/zano_api.cpp | 23 +++-- lib/core/seed_validator.dart | 3 + lib/di.dart | 4 + lib/dummy/cw_dummy.dart | 83 +++++++++++++++++++ lib/dummy/dummy.dart | 42 ++++++++++ lib/entities/default_settings_migration.dart | 25 +++++- lib/entities/preferences_key.dart | 3 + lib/entities/priority_for_wallet_type.dart | 6 ++ .../desktop_wallet_selection_dropdown.dart | 6 ++ .../dashboard/widgets/menu_widget.dart | 6 +- .../screens/wallet_list/wallet_list_page.dart | 2 + lib/store/settings_store.dart | 63 +++++++++++++- .../dashboard/transaction_list_item.dart | 16 ++++ .../exchange/exchange_view_model.dart | 21 +++++ .../node_list/node_list_view_model.dart | 6 ++ lib/view_model/send/output.dart | 20 +++++ lib/view_model/send/send_view_model.dart | 15 ++++ .../transaction_details_view_model.dart | 38 +++++++++ ...let_address_edit_or_create_view_model.dart | 6 ++ .../wallet_address_list_view_model.dart | 48 +++++++++++ lib/view_model/wallet_keys_view_model.dart | 23 +++++ lib/view_model/wallet_new_vm.dart | 3 + lib/view_model/wallet_restore_view_model.dart | 26 ++++++ 55 files changed, 1053 insertions(+), 15 deletions(-) create mode 100644 cw_dummy/.gitignore create mode 100644 cw_dummy/.metadata create mode 100644 cw_dummy/CHANGELOG.md create mode 100644 cw_dummy/LICENSE create mode 100644 cw_dummy/README.md create mode 100644 cw_dummy/analysis_options.yaml create mode 100644 cw_dummy/lib/cw_dummy.dart create mode 100644 cw_dummy/lib/dummy_balance.dart create mode 100644 cw_dummy/lib/dummy_transaction_creation_credentials.dart create mode 100644 cw_dummy/lib/dummy_transaction_history.dart create mode 100644 cw_dummy/lib/dummy_transaction_info.dart create mode 100644 cw_dummy/lib/dummy_transaction_priority.dart create mode 100644 cw_dummy/lib/dummy_wallet.dart create mode 100644 cw_dummy/lib/dummy_wallet_addresses.dart create mode 100644 cw_dummy/lib/dummy_wallet_creation_credentials.dart create mode 100644 cw_dummy/lib/dummy_wallet_service.dart create mode 120000 cw_dummy/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux create mode 100644 cw_dummy/linux/flutter/generated_plugin_registrant.cc create mode 100644 cw_dummy/linux/flutter/generated_plugin_registrant.h create mode 100644 cw_dummy/linux/flutter/generated_plugins.cmake create mode 100644 cw_dummy/macos/Flutter/GeneratedPluginRegistrant.swift create mode 100644 cw_dummy/macos/Flutter/ephemeral/Flutter-Generated.xcconfig create mode 100755 cw_dummy/macos/Flutter/ephemeral/flutter_export_environment.sh create mode 100644 cw_dummy/pubspec.yaml create mode 100644 cw_dummy/test/cw_dummy_test.dart create mode 100644 cw_dummy/windows/flutter/generated_plugin_registrant.cc create mode 100644 cw_dummy/windows/flutter/generated_plugin_registrant.h create mode 100644 cw_dummy/windows/flutter/generated_plugins.cmake create mode 100644 lib/dummy/cw_dummy.dart create mode 100644 lib/dummy/dummy.dart diff --git a/cw_core/lib/crypto_currency.dart b/cw_core/lib/crypto_currency.dart index 25ce1a564..06b42f6f5 100644 --- a/cw_core/lib/crypto_currency.dart +++ b/cw_core/lib/crypto_currency.dart @@ -200,6 +200,7 @@ class CryptoCurrency extends EnumerableItem with Serializable implemen static const dydx = CryptoCurrency(title: 'DYDX', tag: 'ETH', fullName: 'dYdX', raw: 84, name: 'dydx', iconPath: 'assets/images/dydx_icon.png'); static const steth = CryptoCurrency(title: 'STETH', tag: 'ETH', fullName: 'Lido Staked Ethereum', raw: 85, name: 'steth', iconPath: 'assets/images/steth_icon.png'); static const zano = CryptoCurrency(title: 'ZANO', tag: 'ZANO', fullName: 'Zano', raw: 86, name: 'zano', iconPath: 'assets/images/zano_icon.png'); + static const dummy = CryptoCurrency(title: 'DUMMY', tag: 'DUMMY', fullName: 'Dummy', raw: 87, name: 'dummy', iconPath: 'assets/images/dummy_icon.png'); static final Map _rawCurrencyMap = diff --git a/cw_core/lib/currency_for_wallet_type.dart b/cw_core/lib/currency_for_wallet_type.dart index b2f6d356f..2e5e9b5c9 100644 --- a/cw_core/lib/currency_for_wallet_type.dart +++ b/cw_core/lib/currency_for_wallet_type.dart @@ -15,6 +15,8 @@ CryptoCurrency currencyForWalletType(WalletType type) { return CryptoCurrency.eth; case WalletType.zano: return CryptoCurrency.zano; + case WalletType.dummy: + return CryptoCurrency.dummy; default: throw Exception( 'Unexpected wallet type: ${type.toString()} for CryptoCurrency currencyForWalletType'); diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index eae8d64c8..63fef965e 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -80,6 +80,8 @@ class Node extends HiveObject with Keyable { return Uri.http(uriRaw, ''); case WalletType.ethereum: return Uri.https(uriRaw, ''); + case WalletType.dummy: + return Uri.https(uriRaw, ''); default: throw Exception('Unexpected type ${type.toString()} for Node uri'); } @@ -133,6 +135,8 @@ class Node extends HiveObject with Keyable { return requestMoneroNode(); case WalletType.ethereum: return requestElectrumServer(); + case WalletType.dummy: + throw UnimplementedError(); default: return false; } diff --git a/cw_core/lib/wallet_type.dart b/cw_core/lib/wallet_type.dart index 022b181b9..0b26bde73 100644 --- a/cw_core/lib/wallet_type.dart +++ b/cw_core/lib/wallet_type.dart @@ -11,6 +11,7 @@ const walletTypes = [ WalletType.haven, WalletType.ethereum, WalletType.zano, + WalletType.dummy, ]; @HiveType(typeId: WALLET_TYPE_TYPE_ID) @@ -35,6 +36,9 @@ enum WalletType { @HiveField(6) zano, + + @HiveField(7) + dummy, } int serializeToInt(WalletType type) { @@ -51,6 +55,8 @@ int serializeToInt(WalletType type) { return 4; case WalletType.zano: return 5; + case WalletType.dummy: + return 6; default: return -1; } @@ -70,6 +76,8 @@ WalletType deserializeFromInt(int raw) { return WalletType.ethereum; case 5: return WalletType.zano; + case 6: + return WalletType.dummy; default: throw Exception( 'Unexpected token: $raw for WalletType deserializeFromInt'); @@ -90,6 +98,8 @@ String walletTypeToString(WalletType type) { return 'Ethereum'; case WalletType.zano: return 'Zano'; + case WalletType.dummy: + return 'Dummy'; default: return ''; } @@ -109,6 +119,8 @@ String walletTypeToDisplayName(WalletType type) { return 'Ethereum (ETH)'; case WalletType.zano: return 'Zano (ZANO)'; + case WalletType.dummy: + return 'Dummy (DUMMY)'; default: return ''; } @@ -128,6 +140,8 @@ CryptoCurrency walletTypeToCryptoCurrency(WalletType type) { return CryptoCurrency.zano; case WalletType.ethereum: return CryptoCurrency.eth; + case WalletType.dummy: + return CryptoCurrency.dummy; default: throw Exception( 'Unexpected wallet type: ${type.toString()} for CryptoCurrency walletTypeToCryptoCurrency'); diff --git a/cw_dummy/.gitignore b/cw_dummy/.gitignore new file mode 100644 index 000000000..96486fd93 --- /dev/null +++ b/cw_dummy/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/cw_dummy/.metadata b/cw_dummy/.metadata new file mode 100644 index 000000000..fa347fc6a --- /dev/null +++ b/cw_dummy/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + channel: stable + +project_type: package diff --git a/cw_dummy/CHANGELOG.md b/cw_dummy/CHANGELOG.md new file mode 100644 index 000000000..41cc7d819 --- /dev/null +++ b/cw_dummy/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/cw_dummy/LICENSE b/cw_dummy/LICENSE new file mode 100644 index 000000000..ba75c69f7 --- /dev/null +++ b/cw_dummy/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/cw_dummy/README.md b/cw_dummy/README.md new file mode 100644 index 000000000..02fe8ecab --- /dev/null +++ b/cw_dummy/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/cw_dummy/analysis_options.yaml b/cw_dummy/analysis_options.yaml new file mode 100644 index 000000000..a5744c1cf --- /dev/null +++ b/cw_dummy/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/cw_dummy/lib/cw_dummy.dart b/cw_dummy/lib/cw_dummy.dart new file mode 100644 index 000000000..126c12a36 --- /dev/null +++ b/cw_dummy/lib/cw_dummy.dart @@ -0,0 +1,7 @@ +library cw_dummy; + +/// A Calculator. +class Calculator { + /// Returns [value] plus 1. + int addOne(int value) => value + 1; +} diff --git a/cw_dummy/lib/dummy_balance.dart b/cw_dummy/lib/dummy_balance.dart new file mode 100644 index 000000000..b6352850b --- /dev/null +++ b/cw_dummy/lib/dummy_balance.dart @@ -0,0 +1,14 @@ +import 'package:cw_core/balance.dart'; + +class DummyBalance extends Balance { + DummyBalance(super.available, super.additional); + + @override + // TODO: implement formattedAdditionalBalance + String get formattedAdditionalBalance => throw UnimplementedError(); + + @override + // TODO: implement formattedAvailableBalance + String get formattedAvailableBalance => throw UnimplementedError(); + +} \ No newline at end of file diff --git a/cw_dummy/lib/dummy_transaction_creation_credentials.dart b/cw_dummy/lib/dummy_transaction_creation_credentials.dart new file mode 100644 index 000000000..75de84938 --- /dev/null +++ b/cw_dummy/lib/dummy_transaction_creation_credentials.dart @@ -0,0 +1,10 @@ +import 'package:cw_core/output_info.dart'; + +import 'dummy_transaction_priority.dart'; + +class DummyTransactionCreationCredentials { + final List outputs; + final DummyTransactionPriority? priority; + + DummyTransactionCreationCredentials({required this.outputs, this.priority}); +} diff --git a/cw_dummy/lib/dummy_transaction_history.dart b/cw_dummy/lib/dummy_transaction_history.dart new file mode 100644 index 000000000..ac8655091 --- /dev/null +++ b/cw_dummy/lib/dummy_transaction_history.dart @@ -0,0 +1,28 @@ +import 'package:mobx/mobx.dart'; +import 'package:cw_core/transaction_history.dart'; + +import 'dummy_transaction_info.dart'; + +part 'dummy_transaction_history.g.dart'; + +class DummyTransactionHistory = DummyTransactionHistoryBase + with _$DummyTransactionHistory; + +abstract class DummyTransactionHistoryBase + extends TransactionHistoryBase with Store { + DummyTransactionHistoryBase() { + transactions = ObservableMap(); + } + + @override + Future save() async { + throw UnimplementedError; + } + + @override + void addOne(DummyTransactionInfo transaction) => transactions[transaction.id] = transaction; + + @override + void addMany(Map transactions) => + this.transactions.addAll(transactions); +} diff --git a/cw_dummy/lib/dummy_transaction_info.dart b/cw_dummy/lib/dummy_transaction_info.dart new file mode 100644 index 000000000..71461d26e --- /dev/null +++ b/cw_dummy/lib/dummy_transaction_info.dart @@ -0,0 +1,27 @@ +import 'package:cw_core/transaction_info.dart'; + +class DummyTransactionInfo extends TransactionInfo { + @override + String amountFormatted() { + // TODO: implement amountFormatted + throw UnimplementedError(); + } + + @override + void changeFiatAmount(String amount) { + // TODO: implement changeFiatAmount + } + + @override + String? feeFormatted() { + // TODO: implement feeFormatted + throw UnimplementedError(); + } + + @override + String fiatAmount() { + // TODO: implement fiatAmount + throw UnimplementedError(); + } + +} \ No newline at end of file diff --git a/cw_dummy/lib/dummy_transaction_priority.dart b/cw_dummy/lib/dummy_transaction_priority.dart new file mode 100644 index 000000000..46f1d5a70 --- /dev/null +++ b/cw_dummy/lib/dummy_transaction_priority.dart @@ -0,0 +1,20 @@ +import 'package:cw_core/transaction_priority.dart'; + +class DummyTransactionPriority extends TransactionPriority { + const DummyTransactionPriority({required super.title, required super.raw}); + + static const List all = [slow, medium, fast]; + + static const slow = DummyTransactionPriority(title: 'Slow', raw: 0); + static const medium = DummyTransactionPriority(title: 'Medium', raw: 1); + static const fast = DummyTransactionPriority(title: 'Fast', raw: 2); + + static DummyTransactionPriority deserialize({required int raw}) { + switch (raw) { + case 0: return slow; + case 1: return medium; + case 2: return fast; + default: throw Exception('Unexpected token: $raw for DummyTransactionPriority deserialize'); + } + } +} \ No newline at end of file diff --git a/cw_dummy/lib/dummy_wallet.dart b/cw_dummy/lib/dummy_wallet.dart new file mode 100644 index 000000000..c937fa61f --- /dev/null +++ b/cw_dummy/lib/dummy_wallet.dart @@ -0,0 +1,72 @@ +import 'package:cw_core/crypto_currency.dart'; +import 'package:cw_core/node.dart'; +import 'package:cw_core/pending_transaction.dart'; +import 'package:cw_core/sync_status.dart'; +import 'package:cw_core/transaction_priority.dart'; +import 'package:cw_core/wallet_info.dart'; +import 'package:mobx/mobx.dart'; +import 'package:cw_core/wallet_base.dart'; + +import 'dummy_balance.dart'; +import 'dummy_transaction_history.dart'; +import 'dummy_transaction_info.dart'; +import 'dummy_wallet_addresses.dart'; + +part 'dummy_wallet.g.dart'; + +class DummyWallet = DummyWalletBase with _$DummyWallet; + +abstract class DummyWalletBase extends WalletBase with Store { + DummyWalletBase({required WalletInfo walletInfo}) : super(walletInfo) {} + + @override + int calculateEstimatedFee(TransactionPriority priority, int? amount) => throw UnimplementedError(); + + @override + Future changePassword(String password) async => throw UnimplementedError(); + + @override + Future close() async => throw UnimplementedError(); + + @override + Future connectToNode({required Node node}) async => throw UnimplementedError(); + + @override + Future createTransaction(Object credentials) async => throw UnimplementedError(); + + @override + Future> fetchTransactions() async => throw UnimplementedError(); + + @override + Future renameWalletFiles(String newWalletName) async => throw UnimplementedError(); + + @override + Future rescan({required int height}) async => throw UnimplementedError(); + + @override + Future save() async => throw UnimplementedError(); + + @override + Future startSync() async => throw UnimplementedError(); + + @override + Future? updateBalance() => null; + + @override + @observable + late ObservableMap balance; + + @override + Object get keys => throw UnimplementedError("keys"); + + @override + String get seed => "seed"; + + @override + @observable + late SyncStatus syncStatus; + + @override + late DummyWalletAddresses walletAddresses; +} diff --git a/cw_dummy/lib/dummy_wallet_addresses.dart b/cw_dummy/lib/dummy_wallet_addresses.dart new file mode 100644 index 000000000..9e6fbfb4c --- /dev/null +++ b/cw_dummy/lib/dummy_wallet_addresses.dart @@ -0,0 +1,23 @@ +import 'package:mobx/mobx.dart'; +import 'package:cw_core/wallet_addresses.dart'; + +part 'dummy_wallet_addresses.g.dart'; + +class DummyWalletAddresses = DummyWalletAddressesBase with _$DummyWalletAddresses; + +abstract class DummyWalletAddressesBase extends WalletAddresses with Store { + DummyWalletAddressesBase(super.walletInfo); + + @override + @observable + late String address; + + @override + Future init() async => throw UnimplementedError(); + + @override + Future updateAddressesInBox() async => throw UnimplementedError(); + + // TODO: from electrum wallet addresses implementation + Future generateNewAddress() async => throw UnimplementedError(); +} \ No newline at end of file diff --git a/cw_dummy/lib/dummy_wallet_creation_credentials.dart b/cw_dummy/lib/dummy_wallet_creation_credentials.dart new file mode 100644 index 000000000..7fc48d037 --- /dev/null +++ b/cw_dummy/lib/dummy_wallet_creation_credentials.dart @@ -0,0 +1,18 @@ +import 'package:cw_core/wallet_credentials.dart'; +import 'package:cw_core/wallet_info.dart'; + +class DummyNewWalletCredentials extends WalletCredentials { + DummyNewWalletCredentials({required String name, WalletInfo? walletInfo}) + : super(name: name, walletInfo: walletInfo); +} + +class DummyRestoreWalletFromSeedCredentials extends WalletCredentials { + DummyRestoreWalletFromSeedCredentials({required String name, WalletInfo? walletInfo}) + : super(name: name, walletInfo: walletInfo); +} + +class DummyRestoreWalletFromKeyCredentials extends WalletCredentials { + DummyRestoreWalletFromKeyCredentials({required String name, WalletInfo? walletInfo}) + : super(name: name, walletInfo: walletInfo); +} + diff --git a/cw_dummy/lib/dummy_wallet_service.dart b/cw_dummy/lib/dummy_wallet_service.dart new file mode 100644 index 000000000..bb9e77838 --- /dev/null +++ b/cw_dummy/lib/dummy_wallet_service.dart @@ -0,0 +1,40 @@ +import 'package:cw_core/balance.dart'; +import 'package:cw_core/transaction_history.dart'; +import 'package:cw_core/transaction_info.dart'; +import 'package:cw_core/wallet_base.dart'; +import 'package:cw_core/wallet_info.dart'; +import 'package:cw_core/wallet_service.dart'; +import 'package:cw_core/wallet_type.dart'; +import 'package:hive/hive.dart'; +import 'dummy_wallet_creation_credentials.dart'; + + +class DummyWalletService extends WalletService { + DummyWalletService(this.walletInfoSource); + + final Box walletInfoSource; + + @override + Future, TransactionInfo>> create(DummyNewWalletCredentials credentials) => throw UnimplementedError(); + + @override + WalletType getType() => WalletType.dummy; + + @override + Future isWalletExit(String name) => throw UnimplementedError(); + + @override + Future, TransactionInfo>> openWallet(String name, String password) => throw UnimplementedError(); + + @override + Future remove(String wallet) => throw UnimplementedError(); + + @override + Future rename(String currentName, String password, String newName) => throw UnimplementedError(); + + @override + Future, TransactionInfo>> restoreFromKeys(DummyRestoreWalletFromKeyCredentials credentials) => throw UnimplementedError(); + + @override + Future, TransactionInfo>> restoreFromSeed(DummyRestoreWalletFromSeedCredentials credentials) => throw UnimplementedError(); +} \ No newline at end of file diff --git a/cw_dummy/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux b/cw_dummy/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux new file mode 120000 index 000000000..5f46c0555 --- /dev/null +++ b/cw_dummy/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux @@ -0,0 +1 @@ +/home/leo/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/ \ No newline at end of file diff --git a/cw_dummy/linux/flutter/generated_plugin_registrant.cc b/cw_dummy/linux/flutter/generated_plugin_registrant.cc new file mode 100644 index 000000000..e71a16d23 --- /dev/null +++ b/cw_dummy/linux/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void fl_register_plugins(FlPluginRegistry* registry) { +} diff --git a/cw_dummy/linux/flutter/generated_plugin_registrant.h b/cw_dummy/linux/flutter/generated_plugin_registrant.h new file mode 100644 index 000000000..e0f0a47bc --- /dev/null +++ b/cw_dummy/linux/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void fl_register_plugins(FlPluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/cw_dummy/linux/flutter/generated_plugins.cmake b/cw_dummy/linux/flutter/generated_plugins.cmake new file mode 100644 index 000000000..2e1de87a7 --- /dev/null +++ b/cw_dummy/linux/flutter/generated_plugins.cmake @@ -0,0 +1,23 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/cw_dummy/macos/Flutter/GeneratedPluginRegistrant.swift b/cw_dummy/macos/Flutter/GeneratedPluginRegistrant.swift new file mode 100644 index 000000000..e777c67df --- /dev/null +++ b/cw_dummy/macos/Flutter/GeneratedPluginRegistrant.swift @@ -0,0 +1,12 @@ +// +// Generated file. Do not edit. +// + +import FlutterMacOS +import Foundation + +import path_provider_foundation + +func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) +} diff --git a/cw_dummy/macos/Flutter/ephemeral/Flutter-Generated.xcconfig b/cw_dummy/macos/Flutter/ephemeral/Flutter-Generated.xcconfig new file mode 100644 index 000000000..78a963b83 --- /dev/null +++ b/cw_dummy/macos/Flutter/ephemeral/Flutter-Generated.xcconfig @@ -0,0 +1,11 @@ +// This is a generated file; do not edit or check into version control. +FLUTTER_ROOT=/home/leo/flutter +FLUTTER_APPLICATION_PATH=/opt/android/cake_wallet/cw_dummy +COCOAPODS_PARALLEL_CODE_SIGN=true +FLUTTER_BUILD_DIR=build +FLUTTER_BUILD_NAME=0.0.1 +FLUTTER_BUILD_NUMBER=0.0.1 +DART_OBFUSCATION=false +TRACK_WIDGET_CREATION=true +TREE_SHAKE_ICONS=false +PACKAGE_CONFIG=.dart_tool/package_config.json diff --git a/cw_dummy/macos/Flutter/ephemeral/flutter_export_environment.sh b/cw_dummy/macos/Flutter/ephemeral/flutter_export_environment.sh new file mode 100755 index 000000000..fba94197d --- /dev/null +++ b/cw_dummy/macos/Flutter/ephemeral/flutter_export_environment.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/home/leo/flutter" +export "FLUTTER_APPLICATION_PATH=/opt/android/cake_wallet/cw_dummy" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_BUILD_DIR=build" +export "FLUTTER_BUILD_NAME=0.0.1" +export "FLUTTER_BUILD_NUMBER=0.0.1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=true" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.dart_tool/package_config.json" diff --git a/cw_dummy/pubspec.yaml b/cw_dummy/pubspec.yaml new file mode 100644 index 000000000..d7fe703b8 --- /dev/null +++ b/cw_dummy/pubspec.yaml @@ -0,0 +1,67 @@ +name: cw_dummy +description: A new Flutter package project. +version: 0.0.1 +homepage: +publish_to: none + +environment: + sdk: ">=2.17.5 <3.0.0" + flutter: ">=1.20.0" + +dependencies: + flutter: + sdk: flutter + ffi: ^2.0.1 + http: ^1.1.0 + path_provider: ^2.0.11 + mobx: ^2.0.7+4 + flutter_mobx: ^2.0.6+1 + intl: ^0.18.0 + cw_core: + path: ../cw_core + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + build_runner: ^2.1.11 + mobx_codegen: ^2.0.7 + build_resolvers: ^2.0.9 + hive_generator: ^1.1.3 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # To add assets to your package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # To add custom fonts to your package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/cw_dummy/test/cw_dummy_test.dart b/cw_dummy/test/cw_dummy_test.dart new file mode 100644 index 000000000..3d74bbf1c --- /dev/null +++ b/cw_dummy/test/cw_dummy_test.dart @@ -0,0 +1,12 @@ +import 'package:flutter_test/flutter_test.dart'; + +import 'package:cw_dummy/cw_dummy.dart'; + +void main() { + test('adds one to input values', () { + final calculator = Calculator(); + expect(calculator.addOne(2), 3); + expect(calculator.addOne(-7), -6); + expect(calculator.addOne(0), 1); + }); +} diff --git a/cw_dummy/windows/flutter/generated_plugin_registrant.cc b/cw_dummy/windows/flutter/generated_plugin_registrant.cc new file mode 100644 index 000000000..8b6d4680a --- /dev/null +++ b/cw_dummy/windows/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void RegisterPlugins(flutter::PluginRegistry* registry) { +} diff --git a/cw_dummy/windows/flutter/generated_plugin_registrant.h b/cw_dummy/windows/flutter/generated_plugin_registrant.h new file mode 100644 index 000000000..dc139d85a --- /dev/null +++ b/cw_dummy/windows/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void RegisterPlugins(flutter::PluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/cw_dummy/windows/flutter/generated_plugins.cmake b/cw_dummy/windows/flutter/generated_plugins.cmake new file mode 100644 index 000000000..b93c4c30c --- /dev/null +++ b/cw_dummy/windows/flutter/generated_plugins.cmake @@ -0,0 +1,23 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/cw_zano/ios/Classes/zano_api.cpp b/cw_zano/ios/Classes/zano_api.cpp index 376b040be..4463506c9 100644 --- a/cw_zano/ios/Classes/zano_api.cpp +++ b/cw_zano/ios/Classes/zano_api.cpp @@ -15,14 +15,17 @@ void __clear_cache(void* start, void* end) { } #endif #include "plain_wallet_api.h" +#include "plain_wallet_api_ex.h" -using namespace std::chrono_literals; + + +//using namespace std::chrono_literals; #ifdef __cplusplus extern "C" { #endif - const uint64_t MONERO_BLOCK_SIZE = 1000; + //const uint64_t MONERO_BLOCK_SIZE = 1000; struct Utf8Box { @@ -61,19 +64,19 @@ extern "C" } }; - struct HavenBalance + struct ZanoBalance { uint64_t amount; char *assetType; - HavenBalance(char *_assetType, uint64_t _amount) + ZanoBalance(char *_assetType, uint64_t _amount) { amount = _amount; assetType = _assetType; } }; - struct HavenRate + struct ZanoRate { uint64_t rate; char *assetType; @@ -85,7 +88,7 @@ extern "C" } }; - struct MoneroWalletListener : Monero::WalletListener + /*struct MoneroWalletListener : Monero::WalletListener { uint64_t m_height; bool m_need_to_refresh; @@ -153,6 +156,7 @@ extern "C" return m_height; } }; + */ struct TransactionInfoRow { @@ -171,9 +175,9 @@ extern "C" int64_t datetime; - TransactionInfoRow(Monero::TransactionInfo *transaction) - { - amount = transaction->amount(); + TransactionInfoRow(wallet_public::wallet_transfer_info& wti) + { + amount = wti.subtransfers. fee = transaction->fee(); blockHeight = transaction->blockHeight(); subaddrAccount = transaction->subaddrAccount(); @@ -187,6 +191,7 @@ extern "C" hash = strdup(hash_str->c_str()); paymentId = strdup(transaction->paymentId().c_str()); assetType = strdup(transaction->assetType().c_str()); + */ } }; diff --git a/lib/core/seed_validator.dart b/lib/core/seed_validator.dart index 3d8d81aa8..545d40282 100644 --- a/lib/core/seed_validator.dart +++ b/lib/core/seed_validator.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/haven/haven.dart'; import 'package:cake_wallet/zano/zano.dart'; @@ -32,6 +33,8 @@ class SeedValidator extends Validator { return zano!.getMoneroWordList(language); case WalletType.ethereum: return ethereum!.getEthereumWordList(language); + case WalletType.dummy: + return dummy!.getDummyWordList(); default: return []; } diff --git a/lib/di.dart b/lib/di.dart index 3ae705294..29406339c 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -5,6 +5,7 @@ import 'package:cake_wallet/buy/onramper/onramper_buy_provider.dart'; import 'package:cake_wallet/buy/payfura/payfura_buy_provider.dart'; import 'package:cake_wallet/buy/robinhood/robinhood_buy_provider.dart'; import 'package:cake_wallet/core/yat_service.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/entities/background_tasks.dart'; import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart'; @@ -792,6 +793,9 @@ Future setup({ return ethereum!.createEthereumWalletService(_walletInfoSource); case WalletType.zano: return zano!.createZanoWalletService(_walletInfoSource); + case WalletType.dummy: + return dummy!.createDummyWalletService(_walletInfoSource); + default: throw Exception( 'Unexpected token: ${param1.toString()} for generating of WalletService'); diff --git a/lib/dummy/cw_dummy.dart b/lib/dummy/cw_dummy.dart new file mode 100644 index 000000000..f0772959b --- /dev/null +++ b/lib/dummy/cw_dummy.dart @@ -0,0 +1,83 @@ +part of 'dummy.dart'; + +class CWDummy extends Dummy { + @override + List getDummyWordList() => ["aaa", "bbb", "ccc"]; + + @override + WalletService createDummyWalletService(Box walletInfoSource) => + DummyWalletService(walletInfoSource); + + @override + WalletCredentials createDummyNewWalletCredentials( + {required String name, WalletInfo? walletInfo}) => + DummyNewWalletCredentials(name: name, walletInfo: walletInfo); + + @override + WalletCredentials createDummyRestoreWalletFromSeedCredentials( + {required String name, WalletInfo? walletInfo}) => + DummyRestoreWalletFromSeedCredentials(name: name, walletInfo: walletInfo); + + @override + WalletCredentials createDummyRestoreWalletFromKeyCredentials( + {required String name, WalletInfo? walletInfo}) => + DummyRestoreWalletFromKeyCredentials(name: name, walletInfo: walletInfo); + + @override + List getTransactionPriorities() => + DummyTransactionPriority.all; + + @override + TransactionPriority deserializeDummyTransactionPriority(int raw) => + DummyTransactionPriority.deserialize(raw: raw); + + @override + TransactionPriority getDefaultTransactionPriority() => + DummyTransactionPriority.fast; + + @override + CryptoCurrency assetOfTransaction(TransactionInfo tx) { + final transaction = tx as DummyTransactionInfo; + // TODO: !!! + return CryptoCurrency.dummy; + } + + @override + String formatterDummyAmountToString({required int amount}) => + throw UnimplementedError(); + + @override + TransactionPriority getDummyTransactionPrioritySlow() => + DummyTransactionPriority.slow; + + @override + TransactionPriority getDummyTransactionPriorityMedium() => + DummyTransactionPriority.medium; + + @override + double formatterDummyAmountToDouble({required int amount}) => throw UnimplementedError(); + + @override + int formatterDummyParseAmount({required String amount}) => throw UnimplementedError(); + + @override + Object createDummyTransactionCreationCredentials({required List outputs, required TransactionPriority priority}) => + DummyTransactionCreationCredentials(outputs: outputs.map((out) => OutputInfo( + fiatAmount: out.fiatAmount, + cryptoAmount: out.cryptoAmount, + address: out.address, + note: out.note, + sendAll: out.sendAll, + extractedAddress: out.extractedAddress, + isParsedAddress: out.isParsedAddress, + formattedCryptoAmount: out.formattedCryptoAmount)).toList(), priority: priority as DummyTransactionPriority); + + @override + Future generateNewAddress(Object wallet) async { + final dummyWallet = wallet as DummyWallet; + await dummyWallet.walletAddresses.generateNewAddress(); + } + + @override + String getAddress(WalletBase wallet) => (wallet as DummyWallet).walletAddresses.address; +} diff --git a/lib/dummy/dummy.dart b/lib/dummy/dummy.dart new file mode 100644 index 000000000..884db3f1d --- /dev/null +++ b/lib/dummy/dummy.dart @@ -0,0 +1,42 @@ +import 'package:cake_wallet/view_model/send/output.dart'; +import 'package:cw_core/crypto_currency.dart'; +import 'package:cw_core/output_info.dart'; +import 'package:cw_core/transaction_info.dart'; +import 'package:cw_core/transaction_priority.dart'; +import 'package:cw_core/wallet_base.dart'; +import 'package:cw_core/wallet_credentials.dart'; +import 'package:cw_core/wallet_info.dart'; +import 'package:cw_core/wallet_service.dart'; +import 'package:cw_dummy/dummy_transaction_info.dart'; +import 'package:cw_dummy/dummy_transaction_priority.dart'; +import 'package:cw_dummy/dummy_wallet.dart'; +import 'package:cw_dummy/dummy_wallet_creation_credentials.dart'; +import 'package:cw_dummy/dummy_transaction_creation_credentials.dart'; +import 'package:cw_dummy/dummy_wallet_service.dart'; +import 'package:hive/hive.dart'; + +part 'cw_dummy.dart'; + +Dummy? dummy = CWDummy(); + +abstract class Dummy { + WalletCredentials createDummyNewWalletCredentials( + {required String name, WalletInfo? walletInfo}); + WalletCredentials createDummyRestoreWalletFromKeyCredentials( + {required String name, WalletInfo? walletInfo}); + WalletCredentials createDummyRestoreWalletFromSeedCredentials( + {required String name, WalletInfo? walletInfo}); + WalletService createDummyWalletService(Box walletInfoSource); + TransactionPriority deserializeDummyTransactionPriority(int raw); + List getDummyWordList(); + List getTransactionPriorities(); + TransactionPriority getDefaultTransactionPriority(); + CryptoCurrency assetOfTransaction(TransactionInfo tx); + double formatterDummyAmountToDouble({required int amount}); + TransactionPriority getDummyTransactionPrioritySlow(); + TransactionPriority getDummyTransactionPriorityMedium(); + int formatterDummyParseAmount({required String amount}); + Object createDummyTransactionCreationCredentials({required List outputs, required TransactionPriority priority}); + Future generateNewAddress(Object wallet); + String getAddress(WalletBase wallet); +} diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 6591f8f81..65d2615a7 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -27,6 +27,7 @@ const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002'; const havenDefaultNodeUri = 'nodes.havenprotocol.org:443'; const ethereumDefaultNodeUri = 'ethereum.publicnode.com'; const zanoDefaultNodeUri = 'zano.org'; +const dummyDefaultNodeUri = 'example.com'; Future defaultSettingsMigration( {required int version, @@ -317,6 +318,18 @@ Node? getEthereumDefaultNode({required Box nodes}) { ?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.ethereum); } +Node? getZanoDefaultNode({required Box nodes}) { + return nodes.values.firstWhereOrNull( + (Node node) => node.uriRaw == zanoDefaultNodeUri) + ?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.zano); +} + +Node? getDummyDefaultNode({required Box nodes}) { + return nodes.values.firstWhereOrNull( + (Node node) => node.uriRaw == dummyDefaultNodeUri) + ?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.dummy); +} + Node getMoneroDefaultNode({required Box nodes}) { final timeZone = DateTime.now().timeZoneOffset.inHours; var nodeUri = ''; @@ -517,6 +530,8 @@ Future checkCurrentNodes( .getInt(PreferencesKey.currentEthereumNodeIdKey); final currentZanoNodeId = sharedPreferences .getInt(PreferencesKey.currentZanoNodeIdKey); + final currentDummyNodeId = sharedPreferences + .getInt(PreferencesKey.currentDummyNodeIdKey); final currentMoneroNode = nodeSource.values.firstWhereOrNull( (node) => node.key == currentMoneroNodeId); final currentBitcoinElectrumServer = nodeSource.values.firstWhereOrNull( @@ -528,7 +543,8 @@ Future checkCurrentNodes( final currentEthereumNodeServer = nodeSource.values.firstWhereOrNull( (node) => node.key == currentEthereumNodeId); final currentZanoNode = nodeSource.values.firstWhereOrNull((node) => node.key == currentZanoNodeId); - + final currentDummyNode = nodeSource.values.firstWhereOrNull((node) => node.key == currentDummyNodeId); + if (currentMoneroNode == null) { final newCakeWalletNode = Node(uri: newCakeWalletMoneroUri, type: WalletType.monero); @@ -575,6 +591,13 @@ Future checkCurrentNodes( await sharedPreferences.setInt( PreferencesKey.currentZanoNodeIdKey, node.key as int); } + + if (currentDummyNode == null) { + final node = Node(uri: dummyDefaultNodeUri, type: WalletType.dummy); + await nodeSource.add(node); + await sharedPreferences.setInt( + PreferencesKey.currentDummyNodeIdKey, node.key as int); + } } Future resetBitcoinElectrumServer( diff --git a/lib/entities/preferences_key.dart b/lib/entities/preferences_key.dart index 1da002187..5bdab9e76 100644 --- a/lib/entities/preferences_key.dart +++ b/lib/entities/preferences_key.dart @@ -6,6 +6,7 @@ class PreferencesKey { static const currentLitecoinElectrumSererIdKey = 'current_node_id_ltc'; static const currentHavenNodeIdKey = 'current_node_id_xhv'; static const currentZanoNodeIdKey = 'current_node_id_zano'; + static const currentDummyNodeIdKey = 'current_node_id_dummy'; static const currentEthereumNodeIdKey = 'current_node_id_eth'; static const currentFiatCurrencyKey = 'current_fiat_currency'; static const currentTransactionPriorityKeyLegacy = 'current_fee_priority'; @@ -35,6 +36,8 @@ class PreferencesKey { static const havenTransactionPriority = 'current_fee_priority_haven'; static const litecoinTransactionPriority = 'current_fee_priority_litecoin'; static const ethereumTransactionPriority = 'current_fee_priority_ethereum'; + static const zanoTransactionPriority = 'current_fee_priority_zano'; + static const dummyTransactionPriority = 'current_fee_priority_dummy'; static const shouldShowReceiveWarning = 'should_show_receive_warning'; static const shouldShowYatPopup = 'should_show_yat_popup'; static const moneroWalletPasswordUpdateV1Base = 'monero_wallet_update_v1'; diff --git a/lib/entities/priority_for_wallet_type.dart b/lib/entities/priority_for_wallet_type.dart index eb9417763..59bf63ceb 100644 --- a/lib/entities/priority_for_wallet_type.dart +++ b/lib/entities/priority_for_wallet_type.dart @@ -1,7 +1,9 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/haven/haven.dart'; import 'package:cake_wallet/monero/monero.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cw_core/wallet_type.dart'; @@ -17,6 +19,10 @@ List priorityForWalletType(WalletType type) { return haven!.getTransactionPriorities(); case WalletType.ethereum: return ethereum!.getTransactionPriorities(); + case WalletType.zano: + return zano!.getTransactionPriorities(); + case WalletType.dummy: + return dummy!.getTransactionPriorities(); default: return []; } diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart index 684f7cd08..1245986b1 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart @@ -33,6 +33,8 @@ class _DesktopWalletSelectionDropDownState extends State Image.asset( @@ -141,6 +143,10 @@ class _DesktopWalletSelectionDropDownState extends State { this.litecoinIcon = Image.asset('assets/images/litecoin_menu.png'), this.havenIcon = Image.asset('assets/images/haven_menu.png'), this.ethereumIcon = Image.asset('assets/images/eth_icon.png'), - this.zanoIcon = Image.asset('assets/images/zano_icon.png'); + this.zanoIcon = Image.asset('assets/images/zano_icon.png'), + this.dummyIcon = Image.asset('assets/images/dummy_icon.png'); final largeScreen = 731; @@ -49,6 +50,7 @@ class MenuWidgetState extends State { Image havenIcon; Image ethereumIcon; Image zanoIcon; + Image dummyIcon; @override void initState() { @@ -210,6 +212,8 @@ class MenuWidgetState extends State { return ethereumIcon; case WalletType.zano: return zanoIcon; + case WalletType.dummy: + return dummyIcon; default: throw Exception('No icon for ${type.toString()}'); } diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index fd7952628..3a223479d 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -48,6 +48,8 @@ class WalletListBodyState extends State { final nonWalletTypeIcon = Image.asset('assets/images/close.png', height: 24, width: 24); final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24); final ethereumIcon = Image.asset('assets/images/eth_icon.png', height: 24, width: 24); + final zanoIcon = Image.asset('assets/images/zano_icon.png', height: 24, width: 24); + final dummyIcon = Image.asset('assets/images/dummy_icon.png', height: 24, width: 24); final scrollController = ScrollController(); final double tileHeight = 60; Flushbar? _progressBar; diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 7e4b8c88d..5bf8cf332 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart'; import 'package:cake_wallet/entities/buy_provider_types.dart'; import 'package:cake_wallet/entities/cake_2fa_preset_options.dart'; @@ -12,6 +13,7 @@ import 'package:cake_wallet/entities/sort_balance_types.dart'; import 'package:cake_wallet/view_model/settings/sync_mode.dart'; import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_list.dart'; @@ -84,7 +86,10 @@ abstract class SettingsStoreBase with Store { TransactionPriority? initialMoneroTransactionPriority, TransactionPriority? initialHavenTransactionPriority, TransactionPriority? initialLitecoinTransactionPriority, - TransactionPriority? initialEthereumTransactionPriority}) + TransactionPriority? initialEthereumTransactionPriority, + TransactionPriority? initialZanoTransactionPriority, + TransactionPriority? initialDummyTransactionPriority, + }) : nodes = ObservableMap.of(nodes), _sharedPreferences = sharedPreferences, _backgroundTasks = backgroundTasks, @@ -144,6 +149,14 @@ abstract class SettingsStoreBase with Store { priority[WalletType.ethereum] = initialEthereumTransactionPriority; } + if (initialZanoTransactionPriority != null) { + priority[WalletType.zano] = initialZanoTransactionPriority; + } + + if (initialDummyTransactionPriority != null) { + priority[WalletType.dummy] = initialDummyTransactionPriority; + } + reaction( (_) => fiatCurrency, (FiatCurrency fiatCurrency) => sharedPreferences.setString( @@ -172,6 +185,12 @@ abstract class SettingsStoreBase with Store { case WalletType.ethereum: key = PreferencesKey.ethereumTransactionPriority; break; + case WalletType.zano: + key = PreferencesKey.zanoTransactionPriority; + break; + case WalletType.dummy: + key = PreferencesKey.dummyTransactionPriority; + break; default: key = null; } @@ -518,6 +537,8 @@ abstract class SettingsStoreBase with Store { TransactionPriority? havenTransactionPriority; TransactionPriority? litecoinTransactionPriority; TransactionPriority? ethereumTransactionPriority; + TransactionPriority? zanoTransactionPriority; + TransactionPriority? dummyTransactionPriority; if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) { havenTransactionPriority = monero?.deserializeMoneroTransactionPriority( @@ -531,12 +552,22 @@ abstract class SettingsStoreBase with Store { ethereumTransactionPriority = bitcoin?.deserializeLitecoinTransactionPriority( sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!); } + if (sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority) != null) { + zanoTransactionPriority = monero?.deserializeMoneroTransactionPriority( + raw: sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority)!); + } + if (sharedPreferences.getInt(PreferencesKey.dummyTransactionPriority) != null) { + dummyTransactionPriority = dummy?.deserializeDummyTransactionPriority( + sharedPreferences.getInt(PreferencesKey.dummyTransactionPriority)!); + } moneroTransactionPriority ??= monero?.getDefaultTransactionPriority(); bitcoinTransactionPriority ??= bitcoin?.getMediumTransactionPriority(); havenTransactionPriority ??= monero?.getDefaultTransactionPriority(); litecoinTransactionPriority ??= bitcoin?.getLitecoinTransactionPriorityMedium(); ethereumTransactionPriority ??= ethereum?.getDefaultTransactionPriority(); + zanoTransactionPriority ??= zano?.getDefaultTransactionPriority(); + dummyTransactionPriority ??= dummy?.getDefaultTransactionPriority(); final currentBalanceDisplayMode = BalanceDisplayMode.deserialize( raw: sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey)!); @@ -619,15 +650,14 @@ abstract class SettingsStoreBase with Store { final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey); final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey); final zanoNodeId = sharedPreferences.getInt(PreferencesKey.currentZanoNodeIdKey); - //final zanoNodeId = 9; - debugPrint("zanoNodeId $zanoNodeId"); + final dummyNodeId = sharedPreferences.getInt(PreferencesKey.currentDummyNodeIdKey); final moneroNode = nodeSource.get(nodeId); final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId); final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId); final havenNode = nodeSource.get(havenNodeId); final ethereumNode = nodeSource.get(ethereumNodeId); final zanoNode = nodeSource.get(zanoNodeId); - debugPrint("zanoNode $zanoNode"); + final dummyNode = nodeSource.get(dummyNodeId); final packageInfo = await PackageInfo.fromPlatform(); final deviceName = await _getDeviceName() ?? ''; final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true; @@ -663,6 +693,10 @@ abstract class SettingsStoreBase with Store { nodes[WalletType.zano] = zanoNode; } + if (dummyNode != null) { + nodes[WalletType.dummy] = dummyNode; + } + final savedSyncMode = SyncMode.all.firstWhere((element) { return element.type.index == (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 1); }); @@ -702,6 +736,8 @@ abstract class SettingsStoreBase with Store { initialBitcoinTransactionPriority: bitcoinTransactionPriority, initialHavenTransactionPriority: havenTransactionPriority, initialLitecoinTransactionPriority: litecoinTransactionPriority, + initialZanoTransactionPriority: zanoTransactionPriority, + initialDummyTransactionPriority: dummyTransactionPriority, initialShouldRequireTOTP2FAForAccessingWallet: shouldRequireTOTP2FAForAccessingWallet, initialShouldRequireTOTP2FAForSendsToContact: shouldRequireTOTP2FAForSendsToContact, initialShouldRequireTOTP2FAForSendsToNonContact: shouldRequireTOTP2FAForSendsToNonContact, @@ -748,6 +784,16 @@ abstract class SettingsStoreBase with Store { sharedPreferences.getInt(PreferencesKey.ethereumTransactionPriority)!) ?? priority[WalletType.ethereum]!; } + if (sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority) != null) { + priority[WalletType.zano] = zano?.deserializeMoneroTransactionPriority( + raw: sharedPreferences.getInt(PreferencesKey.zanoTransactionPriority)!) ?? + priority[WalletType.zano]!; + } + if (sharedPreferences.getInt(PreferencesKey.dummyTransactionPriority) != null) { + priority[WalletType.dummy] = dummy?.deserializeDummyTransactionPriority( + sharedPreferences.getInt(PreferencesKey.dummyTransactionPriority)!) ?? + priority[WalletType.dummy]!; + } final generateSubaddresses = sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey); @@ -835,6 +881,7 @@ abstract class SettingsStoreBase with Store { sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey); final havenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey); final zanoNodeId = sharedPreferences.getInt(PreferencesKey.currentZanoNodeIdKey); + final dummyNodeId = sharedPreferences.getInt(PreferencesKey.currentDummyNodeIdKey); final ethereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey); final moneroNode = nodeSource.get(nodeId); final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId); @@ -842,6 +889,7 @@ abstract class SettingsStoreBase with Store { final havenNode = nodeSource.get(havenNodeId); final ethereumNode = nodeSource.get(ethereumNodeId); final zanoNode = nodeSource.get(zanoNodeId); + final dummyNode = nodeSource.get(dummyNodeId); if (moneroNode != null) { nodes[WalletType.monero] = moneroNode; @@ -866,6 +914,10 @@ abstract class SettingsStoreBase with Store { if (zanoNode != null) { nodes[WalletType.zano] = zanoNode; } + + if (dummyNode != null) { + nodes[WalletType.dummy] = dummyNode; + } } Future _saveCurrentNode(Node node, WalletType walletType) async { @@ -890,6 +942,9 @@ abstract class SettingsStoreBase with Store { case WalletType.zano: await _sharedPreferences.setInt(PreferencesKey.currentZanoNodeIdKey, node.key as int); break; + case WalletType.dummy: + await _sharedPreferences.setInt(PreferencesKey.currentDummyNodeIdKey, node.key as int); + break; default: break; } diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index ac74df89d..d5c85c793 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -1,7 +1,9 @@ +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:cw_core/transaction_direction.dart'; import 'package:cw_core/transaction_info.dart'; import 'package:cake_wallet/store/settings_store.dart'; @@ -92,6 +94,20 @@ class TransactionListItem extends ActionListItem with Keyable { cryptoAmount: ethereum!.formatterEthereumAmountToDouble(transaction: transaction), price: price); break; + case WalletType.zano: + final asset = zano!.assetOfTransaction(transaction); + final price = balanceViewModel.fiatConvertationStore.prices[asset]; + amount = calculateFiatAmountRaw( + cryptoAmount: zano!.formatterMoneroAmountToDouble(amount: transaction.amount), + price: price); + break; + case WalletType.dummy: + final asset = dummy!.assetOfTransaction(transaction); + final price = balanceViewModel.fiatConvertationStore.prices[asset]; + amount = calculateFiatAmountRaw( + cryptoAmount: dummy!.formatterDummyAmountToDouble(amount: transaction.amount), + price: price); + break; default: break; } diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 2e90a3a33..f046d0006 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -3,6 +3,7 @@ import 'dart:collection'; import 'dart:convert'; import 'package:cake_wallet/core/wallet_change_listener_view_model.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; import 'package:cake_wallet/entities/wallet_contact.dart'; @@ -277,6 +278,10 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with return transactionPriority == bitcoin!.getBitcoinTransactionPrioritySlow(); case WalletType.litecoin: return transactionPriority == bitcoin!.getLitecoinTransactionPrioritySlow(); + case WalletType.zano: + return transactionPriority == monero!.getMoneroTransactionPrioritySlow(); + case WalletType.dummy: + return transactionPriority == dummy!.getDummyTransactionPrioritySlow(); default: return false; } @@ -689,6 +694,16 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with depositCurrency = CryptoCurrency.eth; receiveCurrency = CryptoCurrency.xmr; break; + case WalletType.zano: + // TODO: !!! + // depositCurrency = CryptoCurrency.zano; + // receiveCurrency = ??? + throw UnimplementedError(); + case WalletType.dummy: + // TODO: !!! + // depositCurrency = CryptoCurrency.dummy; + // receiveCurrency = ??? + throw UnimplementedError(); default: break; } @@ -772,6 +787,12 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with case WalletType.litecoin: _settingsStore.priority[wallet.type] = bitcoin!.getLitecoinTransactionPriorityMedium(); break; + case WalletType.zano: + _settingsStore.priority[wallet.type] = monero!.getMoneroTransactionPriorityAutomatic(); + break; + case WalletType.dummy: + _settingsStore.priority[wallet.type] = dummy!.getDummyTransactionPriorityMedium(); + break; default: break; } diff --git a/lib/view_model/node_list/node_list_view_model.dart b/lib/view_model/node_list/node_list_view_model.dart index ea612c63c..8805962ce 100644 --- a/lib/view_model/node_list/node_list_view_model.dart +++ b/lib/view_model/node_list/node_list_view_model.dart @@ -66,6 +66,12 @@ abstract class NodeListViewModelBase with Store { case WalletType.ethereum: node = getEthereumDefaultNode(nodes: _nodeSource)!; break; + case WalletType.zano: + node = getZanoDefaultNode(nodes: _nodeSource)!; + break; + case WalletType.dummy: + node = getDummyDefaultNode(nodes: _nodeSource)!; + break; default: throw Exception('Unexpected wallet type: ${_appStore.wallet!.type}'); } diff --git a/lib/view_model/send/output.dart b/lib/view_model/send/output.dart index 8008812ba..4daa228ca 100644 --- a/lib/view_model/send/output.dart +++ b/lib/view_model/send/output.dart @@ -1,10 +1,12 @@ import 'package:cake_wallet/di.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart'; import 'package:cake_wallet/entities/parse_address_from_domain.dart'; import 'package:cake_wallet/entities/parsed_address.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/haven/haven.dart'; import 'package:cake_wallet/src/screens/send/widgets/extract_address_from_parsed.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -94,6 +96,12 @@ abstract class OutputBase with Store { case WalletType.ethereum: _amount = ethereum!.formatterEthereumParseAmount(_cryptoAmount); break; + case WalletType.zano: + _amount = zano!.formatterMoneroParseAmount(amount: _cryptoAmount); + break; + case WalletType.dummy: + _amount = dummy!.formatterDummyParseAmount(amount: _cryptoAmount); + break; default: break; } @@ -128,9 +136,17 @@ abstract class OutputBase with Store { return haven!.formatterMoneroAmountToDouble(amount: fee); } + if (_wallet.type == WalletType.zano) { + return zano!.formatterMoneroAmountToDouble(amount: fee); + } + if (_wallet.type == WalletType.ethereum) { return ethereum!.formatterEthereumAmountToDouble(amount: BigInt.from(fee)); } + + if (_wallet.type == WalletType.dummy) { + return dummy!.formatterDummyAmountToDouble(amount: fee); + } } catch (e) { print(e.toString()); } @@ -240,6 +256,10 @@ abstract class OutputBase with Store { case WalletType.ethereum: maximumFractionDigits = 12; break; + case WalletType.dummy: + case WalletType.zano: + // TODO: enter correct values + throw UnimplementedError(); default: break; } diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 329b3c4ad..743d0f7be 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/core/wallet_change_listener_view_model.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/entities/contact_record.dart'; import 'package:cake_wallet/entities/priority_for_wallet_type.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; @@ -6,6 +7,7 @@ import 'package:cake_wallet/entities/wallet_contact.dart'; import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cake_wallet/view_model/send/send_template_view_model.dart'; @@ -378,6 +380,19 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor return ethereum!.createEthereumTransactionCredentials(outputs, priority: priority, currency: selectedCryptoCurrency); + case WalletType.zano: + final priority = _settingsStore.priority[wallet.type]; + if (priority == null) { + throw Exception('Priority is null for wallet type: ${wallet.type}'); + } + return zano!.createZanoTransactionCreationCredentials( + outputs: outputs, priority: priority, assetType: selectedCryptoCurrency.title); + case WalletType.dummy: + final priority = _settingsStore.priority[wallet.type]; + if (priority == null) { + throw Exception('Priority is null for wallet type: ${wallet.type}'); + } + return dummy!.createDummyTransactionCreationCredentials(outputs: outputs, priority: priority); default: throw Exception('Unexpected wallet type: ${wallet.type}'); } diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index 1620870b4..ceb63ccc5 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -47,6 +47,12 @@ abstract class TransactionDetailsViewModelBase with Store { case WalletType.ethereum: _addEthereumListItems(tx, dateFormat); break; + case WalletType.zano: + _addZanoListItems(tx, dateFormat); + break; + case WalletType.dummy: + _addDummyListItems(tx, dateFormat); + break; default: break; } @@ -116,6 +122,10 @@ abstract class TransactionDetailsViewModelBase with Store { return 'https://explorer.havenprotocol.org/search?value=${txId}'; case WalletType.ethereum: return 'https://etherscan.io/tx/${txId}'; + case WalletType.zano: + return 'https://example.com/${txId}'; + case WalletType.dummy: + return 'https://example.com/${txId}'; default: return ''; } @@ -133,6 +143,10 @@ abstract class TransactionDetailsViewModelBase with Store { return S.current.view_transaction_on + 'explorer.havenprotocol.org'; case WalletType.ethereum: return S.current.view_transaction_on + 'etherscan.io'; + case WalletType.zano: + return S.current.view_transaction_on + 'zano'; + case WalletType.dummy: + return S.current.view_transaction_on + 'dummy'; default: return ''; } @@ -221,4 +235,28 @@ abstract class TransactionDetailsViewModelBase with Store { items.addAll(_items); } + + void _addZanoListItems(TransactionInfo tx, DateFormat dateFormat) { + items.addAll([ + StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id), + StandartListItem( + title: S.current.transaction_details_date, value: dateFormat.format(tx.date)), + StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'), + StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()), + if (tx.feeFormatted()?.isNotEmpty ?? false) + StandartListItem(title: S.current.transaction_details_fee, value: tx.feeFormatted()!), + ]); + } + + void _addDummyListItems(TransactionInfo tx, DateFormat dateFormat) { + items.addAll([ + StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id), + StandartListItem( + title: S.current.transaction_details_date, value: dateFormat.format(tx.date)), + StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'), + StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()), + if (tx.feeFormatted()?.isNotEmpty ?? false) + StandartListItem(title: S.current.transaction_details_fee, value: tx.feeFormatted()!), + ]); + } } diff --git a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart index a4eb3d386..bb056bb5a 100644 --- a/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_item.dart'; import 'package:mobx/mobx.dart'; import 'package:flutter/foundation.dart'; @@ -90,6 +91,11 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store { label: label); await wallet.save(); } + + if (wallet.type == WalletType.dummy) { + await dummy!.generateNewAddress(wallet); + await wallet.save(); + } } Future _update() async { diff --git a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart index db45ae117..a3c1b360f 100644 --- a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart @@ -1,8 +1,10 @@ import 'package:cake_wallet/core/wallet_change_listener_view_model.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart'; import 'package:cake_wallet/store/yat/yat_store.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:cw_core/currency.dart'; import 'package:intl/intl.dart'; import 'package:mobx/mobx.dart'; @@ -107,6 +109,38 @@ class EthereumURI extends PaymentURI { } } +class ZanoURI extends PaymentURI { + ZanoURI({required String amount, required String address}) + : super(amount: amount, address: address); + + @override + String toString() { + var base = 'zano:' + address; + + if (amount.isNotEmpty) { + base += '?amount=${amount.replaceAll(',', '.')}'; + } + + return base; + } +} + +class DummyURI extends PaymentURI { + DummyURI({required String amount, required String address}) + : super(amount: amount, address: address); + + @override + String toString() { + var base = 'dummy:' + address; + + if (amount.isNotEmpty) { + base += '?amount=${amount.replaceAll(',', '.')}'; + } + + return base; + } +} + abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewModel with Store { WalletAddressListViewModelBase({ required AppStore appStore, @@ -176,6 +210,14 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo return EthereumURI(amount: amount, address: address.address); } + if (wallet.type == WalletType.zano) { + return ZanoURI(amount: amount, address: address.address); + } + + if (wallet.type == WalletType.dummy) { + return DummyURI(amount: amount, address: address.address); + } + throw Exception('Unexpected type: ${type.toString()}'); } @@ -232,6 +274,12 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress)); } + if (wallet.type == WalletType.dummy) { + final primaryAddress = dummy!.getAddress(wallet); + + addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress)); + } + return addressList; } diff --git a/lib/view_model/wallet_keys_view_model.dart b/lib/view_model/wallet_keys_view_model.dart index 0233e13e9..0a01893cf 100644 --- a/lib/view_model/wallet_keys_view_model.dart +++ b/lib/view_model/wallet_keys_view_model.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/store/app_store.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:cw_core/transaction_direction.dart'; import 'package:cw_core/transaction_info.dart'; import 'package:cw_core/wallet_type.dart'; @@ -104,6 +105,19 @@ abstract class WalletKeysViewModelBase with Store { StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!), ]); } + + if (_appStore.wallet!.type == WalletType.zano) { + items.addAll([ + StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!), + ]); + } + + if (_appStore.wallet!.type == WalletType.dummy) { + items.addAll([ + StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!), + ]); + } + } Future _currentHeight() async { @@ -113,6 +127,9 @@ abstract class WalletKeysViewModelBase with Store { if (_appStore.wallet!.type == WalletType.monero) { return monero_wallet.getCurrentHeight(); } + if (_appStore.wallet!.type == WalletType.zano) { + return await zano!.getCurrentHeight(); + } return null; } @@ -128,6 +145,10 @@ abstract class WalletKeysViewModelBase with Store { return 'haven-wallet'; case WalletType.ethereum: return 'ethereum-wallet'; + case WalletType.zano: + return 'zano-wallet'; + case WalletType.dummy: + return 'dummy-wallet'; default: throw Exception('Unexpected wallet type: ${_appStore.wallet!.toString()}'); } @@ -172,6 +193,8 @@ abstract class WalletKeysViewModelBase with Store { return monero!.getHeigthByDate(date: date); } else if (type == WalletType.haven) { return haven!.getHeightByDate(date: date); + } else if (type == WalletType.zano) { + return zano!.getHeightByDate(date: date); } return 0; } diff --git a/lib/view_model/wallet_new_vm.dart b/lib/view_model/wallet_new_vm.dart index 230b7ade5..f5f504880 100644 --- a/lib/view_model/wallet_new_vm.dart +++ b/lib/view_model/wallet_new_vm.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/view_model/restore/restore_wallet.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/zano/zano.dart'; @@ -49,6 +50,8 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store { case WalletType.zano: return zano!.createZanoNewWalletCredentials( name: name, language: "en"); + case WalletType.dummy: + return dummy!.createDummyNewWalletCredentials(name: name); default: throw Exception('Unexpected type: ${type.toString()}');; } diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index 65f122bf0..0378e5971 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -1,5 +1,7 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/dummy/dummy.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; +import 'package:cake_wallet/zano/zano.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/store/app_store.dart'; @@ -90,6 +92,15 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { name: name, mnemonic: seed, password: password); + case WalletType.zano: + return zano!.createZanoRestoreWalletFromSeedCredentials( + name: name, + password: password, + height: height, + mnemonic: seed); + case WalletType.dummy: + return dummy!.createDummyRestoreWalletFromSeedCredentials( + name: name); default: break; } @@ -122,6 +133,17 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { language: 'English'); } + if (type == WalletType.zano) { + return zano!.createZanoRestoreWalletFromKeysCredentials( + name: name, + height: height, + spendKey: spendKey!, + viewKey: viewKey!, + address: address!, + password: password, + language: 'English'); + } + if (type == WalletType.ethereum) { return ethereum!.createEthereumRestoreWalletFromPrivateKey( name: name, @@ -129,6 +151,10 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { password: password, ); } + + if (type == WalletType.dummy) { + return dummy!.createDummyRestoreWalletFromKeyCredentials(name: name); + } } throw Exception('Unexpected type: ${type.toString()}');