diff --git a/ios/Flutter/.last_build_id b/ios/Flutter/.last_build_id index 8e3e3da7e..c4f58572f 100644 --- a/ios/Flutter/.last_build_id +++ b/ios/Flutter/.last_build_id @@ -1 +1 @@ -a2dce69f54a78f5b00e19850e4b2d402 \ No newline at end of file +bc336703210c48e30d7216fac3fe1c0f \ No newline at end of file diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 63e247dc4..4343ce3d9 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -47,6 +47,8 @@ PODS: - Flutter - path_provider_macos (0.0.1): - Flutter + - path_provider_windows (0.0.1): + - Flutter - Reachability (3.2) - share (0.0.1): - Flutter @@ -67,6 +69,8 @@ PODS: - Flutter - url_launcher_web (0.0.1): - Flutter + - url_launcher_windows (0.0.1): + - Flutter DEPENDENCIES: - barcode_scan (from `.symlinks/plugins/barcode_scan/ios`) @@ -84,6 +88,7 @@ DEPENDENCIES: - path_provider (from `.symlinks/plugins/path_provider/ios`) - path_provider_linux (from `.symlinks/plugins/path_provider_linux/ios`) - path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`) + - path_provider_windows (from `.symlinks/plugins/path_provider_windows/ios`) - share (from `.symlinks/plugins/share/ios`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) - shared_preferences_linux (from `.symlinks/plugins/shared_preferences_linux/ios`) @@ -93,6 +98,7 @@ DEPENDENCIES: - url_launcher_linux (from `.symlinks/plugins/url_launcher_linux/ios`) - url_launcher_macos (from `.symlinks/plugins/url_launcher_macos/ios`) - url_launcher_web (from `.symlinks/plugins/url_launcher_web/ios`) + - url_launcher_windows (from `.symlinks/plugins/url_launcher_windows/ios`) SPEC REPOS: trunk: @@ -131,6 +137,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/path_provider_linux/ios" path_provider_macos: :path: ".symlinks/plugins/path_provider_macos/ios" + path_provider_windows: + :path: ".symlinks/plugins/path_provider_windows/ios" share: :path: ".symlinks/plugins/share/ios" shared_preferences: @@ -149,6 +157,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/url_launcher_macos/ios" url_launcher_web: :path: ".symlinks/plugins/url_launcher_web/ios" + url_launcher_windows: + :path: ".symlinks/plugins/url_launcher_windows/ios" SPEC CHECKSUMS: barcode_scan: a5c27959edfafaa0c771905bad0b29d6d39e4479 @@ -167,6 +177,7 @@ SPEC CHECKSUMS: path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c path_provider_linux: 4d630dc393e1f20364f3e3b4a2ff41d9674a84e4 path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0 + path_provider_windows: a2b81600c677ac1959367280991971cb9a1edb3b Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 share: 0b2c3e82132f5888bccca3351c504d0003b3b410 shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d @@ -178,6 +189,7 @@ SPEC CHECKSUMS: url_launcher_linux: ac237cb7a8058736e4aae38bdbcc748a4b394cc0 url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313 url_launcher_web: e5527357f037c87560776e36436bf2b0288b965c + url_launcher_windows: 683d7c283894db8d1914d3ab2223b20cc1ad95d5 PODFILE CHECKSUM: c34e2287a9ccaa606aeceab922830efb9a6ff69a diff --git a/lib/bitcoin/bitcoin_amount_format.dart b/lib/bitcoin/bitcoin_amount_format.dart index a1ff8cecf..75db6c314 100644 --- a/lib/bitcoin/bitcoin_amount_format.dart +++ b/lib/bitcoin/bitcoin_amount_format.dart @@ -1,5 +1,5 @@ import 'package:intl/intl.dart'; -import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart'; +import 'package:cake_wallet/entities/crypto_amount_format.dart'; const bitcoinAmountLength = 8; const bitcoinAmountDivider = 100000000; @@ -11,3 +11,6 @@ String bitcoinAmountToString({int amount}) => bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider)); double bitcoinAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider); + +int doubleToBitcoinAmount(double amount) => + (amount * bitcoinAmountDivider).toInt(); \ No newline at end of file diff --git a/lib/bitcoin/bitcoin_balance.dart b/lib/bitcoin/bitcoin_balance.dart index a1bc5c844..6aefe28f4 100644 --- a/lib/bitcoin/bitcoin_balance.dart +++ b/lib/bitcoin/bitcoin_balance.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart'; -import 'package:cake_wallet/src/domain/common/balance.dart'; +import 'package:cake_wallet/entities/balance.dart'; class BitcoinBalance extends Balance { const BitcoinBalance({@required this.confirmed, @required this.unconfirmed}) : super(); diff --git a/lib/bitcoin/bitcoin_transaction_credentials.dart b/lib/bitcoin/bitcoin_transaction_credentials.dart index 874da1263..9e64634b3 100644 --- a/lib/bitcoin/bitcoin_transaction_credentials.dart +++ b/lib/bitcoin/bitcoin_transaction_credentials.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; +import 'package:cake_wallet/entities/transaction_priority.dart'; class BitcoinTransactionCredentials { BitcoinTransactionCredentials(this.address, this.amount, this.priority); diff --git a/lib/bitcoin/bitcoin_transaction_history.dart b/lib/bitcoin/bitcoin_transaction_history.dart index 81ed01fe7..c687c0ba4 100644 --- a/lib/bitcoin/bitcoin_transaction_history.dart +++ b/lib/bitcoin/bitcoin_transaction_history.dart @@ -58,16 +58,7 @@ abstract class BitcoinTransactionHistoryBase final histories = wallet.scriptHashes.map((scriptHash) => eclient.getHistory(scriptHash)); final _historiesWithDetails = await Future.wait(histories) - .then((histories) => histories -// .map((h) => h.where((tx) { -// final height = tx['height'] as int ?? 0; -// // FIXME: Filter only needed transactions -// final _tx = get(tx['tx_hash'] as String); -// -// return height == 0 || height > _height; -// })) - .expand((i) => i) - .toList()) + .then((histories) => histories.expand((i) => i).toList()) .then((histories) => histories.map((tx) => fetchTransactionInfo( hash: tx['tx_hash'] as String, height: tx['height'] as int))); final historiesWithDetails = await Future.wait(_historiesWithDetails); diff --git a/lib/bitcoin/bitcoin_transaction_info.dart b/lib/bitcoin/bitcoin_transaction_info.dart index 4198ca9e2..29cb8521e 100644 --- a/lib/bitcoin/bitcoin_transaction_info.dart +++ b/lib/bitcoin/bitcoin_transaction_info.dart @@ -1,22 +1,22 @@ import 'package:flutter/foundation.dart'; import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; -import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData; +import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart'; -import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart'; -import 'package:cake_wallet/src/domain/common/transaction_direction.dart'; -import 'package:cake_wallet/src/domain/common/transaction_info.dart'; -import 'package:cake_wallet/src/domain/common/format_amount.dart'; +import 'package:cake_wallet/entities/transaction_direction.dart'; +import 'package:cake_wallet/entities/transaction_info.dart'; +import 'package:cake_wallet/entities/format_amount.dart'; class BitcoinTransactionInfo extends TransactionInfo { BitcoinTransactionInfo( - {@required this.id, + {@required String id, @required int height, @required int amount, @required TransactionDirection direction, @required bool isPending, @required DateTime date, @required int confirmations}) { + this.id = id; this.height = height; this.amount = amount; this.direction = direction; @@ -97,7 +97,6 @@ class BitcoinTransactionInfo extends TransactionInfo { ? DateTime.fromMillisecondsSinceEpoch(timestamp * 1000) : DateTime.now(); - // FIXME: Get transaction is pending return BitcoinTransactionInfo( id: tx.getId(), height: height, @@ -119,8 +118,6 @@ class BitcoinTransactionInfo extends TransactionInfo { confirmations: data['confirmations'] as int); } - final String id; - String _fiatAmount; @override diff --git a/lib/bitcoin/bitcoin_wallet.dart b/lib/bitcoin/bitcoin_wallet.dart index fe6cbf184..e43c0aeaa 100644 --- a/lib/bitcoin/bitcoin_wallet.dart +++ b/lib/bitcoin/bitcoin_wallet.dart @@ -14,15 +14,15 @@ import 'package:cake_wallet/bitcoin/electrum.dart'; import 'package:cake_wallet/bitcoin/pending_bitcoin_transaction.dart'; import 'package:cake_wallet/bitcoin/script_hash.dart'; import 'package:cake_wallet/bitcoin/utils.dart'; -import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart'; -import 'package:cake_wallet/src/domain/common/sync_status.dart'; -import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; -import 'package:cake_wallet/src/domain/common/wallet_info.dart'; +import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart'; +import 'package:cake_wallet/entities/sync_status.dart'; +import 'package:cake_wallet/entities/transaction_priority.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; import 'package:cake_wallet/bitcoin/bitcoin_transaction_history.dart'; import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; import 'package:cake_wallet/bitcoin/file.dart'; import 'package:cake_wallet/bitcoin/bitcoin_balance.dart'; -import 'package:cake_wallet/src/domain/common/node.dart'; +import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/core/wallet_base.dart'; part 'bitcoin_wallet.g.dart'; @@ -316,6 +316,11 @@ abstract class BitcoinWalletBase extends WalletBase with Store { bitcoin.ECPair keyPairFor({@required int index}) => generateKeyPair(hd: hd, index: index); + @override + Future rescan({int height}) async { + // FIXME: Unimplemented + } + void _subscribeForUpdates() { scriptHashes.forEach((sh) async { await _scripthashesUpdateSubject[sh]?.close(); diff --git a/lib/bitcoin/bitcoin_wallet_service.dart b/lib/bitcoin/bitcoin_wallet_service.dart index cb2d241fb..2e9a1c305 100644 --- a/lib/bitcoin/bitcoin_wallet_service.dart +++ b/lib/bitcoin/bitcoin_wallet_service.dart @@ -4,8 +4,8 @@ import 'package:cake_wallet/bitcoin/file.dart'; import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart'; import 'package:cake_wallet/core/wallet_service.dart'; import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart'; -import 'package:cake_wallet/src/domain/common/pathForWallet.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/pathForWallet.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; class BitcoinWalletService extends WalletService< BitcoinNewWalletCredentials, diff --git a/lib/bitcoin/electrum.dart b/lib/bitcoin/electrum.dart index 69d1c332f..5348959e7 100644 --- a/lib/bitcoin/electrum.dart +++ b/lib/bitcoin/electrum.dart @@ -40,6 +40,7 @@ class ElectrumClient { _tasks = {}; static const connectionTimeout = Duration(seconds: 5); + static const aliveTimerDuration = Duration(seconds: 2); bool get isConnected => _isConnected; Socket socket; @@ -97,8 +98,7 @@ class ElectrumClient { void keepAlive() { _aliveTimer?.cancel(); - // FIXME: Unnamed constant. - _aliveTimer = Timer.periodic(Duration(seconds: 2), (_) async => ping()); + _aliveTimer = Timer.periodic(aliveTimerDuration, (_) async => ping()); } Future ping() async { diff --git a/lib/bitcoin/pending_bitcoin_transaction.dart b/lib/bitcoin/pending_bitcoin_transaction.dart index 64b317169..d2c018a35 100644 --- a/lib/bitcoin/pending_bitcoin_transaction.dart +++ b/lib/bitcoin/pending_bitcoin_transaction.dart @@ -1,6 +1,6 @@ import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart'; import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart'; -import 'package:cake_wallet/src/domain/common/transaction_direction.dart'; +import 'package:cake_wallet/entities/transaction_direction.dart'; import 'package:flutter/foundation.dart'; import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; import 'package:cake_wallet/core/pending_transaction.dart'; diff --git a/lib/core/address_label_validator.dart b/lib/core/address_label_validator.dart index 903b2e50e..7d8f8c631 100644 --- a/lib/core/address_label_validator.dart +++ b/lib/core/address_label_validator.dart @@ -1,6 +1,6 @@ import 'package:cake_wallet/core/validator.dart'; import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; class AddressLabelValidator extends TextValidator { AddressLabelValidator({WalletType type}) diff --git a/lib/core/address_validator.dart b/lib/core/address_validator.dart index 26e239f6c..1ee9e72db 100644 --- a/lib/core/address_validator.dart +++ b/lib/core/address_validator.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/core/validator.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; class AddressValidator extends TextValidator { AddressValidator({@required CryptoCurrency type}) diff --git a/lib/core/amount.dart b/lib/core/amount.dart new file mode 100644 index 000000000..62e59db18 --- /dev/null +++ b/lib/core/amount.dart @@ -0,0 +1,37 @@ +abstract class Amount { + Amount(this.value); + + int value; + + int minorDigits; + + String code; + + String formatted(); +} + +class MoneroAmount extends Amount { + MoneroAmount(int value) : super(value) { + minorDigits = 12; + code = 'XMR'; + } + + // const moneroAmountLength = 12; + // const moneroAmountDivider = 1000000000000; + // final moneroAmountFormat = NumberFormat() + // ..maximumFractionDigits = moneroAmountLength + // ..minimumFractionDigits = 1; + + // String moneroAmountToString({int amount}) => + // moneroAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider)); + + // double moneroAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider); + + // int moneroParseAmount({String amount}) => moneroAmountFormat.parse(amount).toInt(); + + @override + String formatted() { + // TODO: implement formatted + throw UnimplementedError(); + } +} diff --git a/lib/core/amount_converter.dart b/lib/core/amount_converter.dart new file mode 100644 index 000000000..7ef4ed442 --- /dev/null +++ b/lib/core/amount_converter.dart @@ -0,0 +1,92 @@ +import 'package:intl/intl.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; + +class AmountConverter { + static const _moneroAmountLength = 12; + static const _moneroAmountDivider = 1000000000000; + static const _litecoinAmountDivider = 100000000; + static const _ethereumAmountDivider = 1000000000000000000; + static const _dashAmountDivider = 100000000; + static const _bitcoinCashAmountDivider = 100000000; + static const _bitcoinAmountDivider = 100000000; + static const _bitcoinAmountLength = 8; + static final _bitcoinAmountFormat = NumberFormat() + ..maximumFractionDigits = _bitcoinAmountLength + ..minimumFractionDigits = 1; + static final _moneroAmountFormat = NumberFormat() + ..maximumFractionDigits = _moneroAmountLength + ..minimumFractionDigits = 1; + + static double amountIntToDouble(CryptoCurrency cryptoCurrency, int amount) { + switch (cryptoCurrency) { + case CryptoCurrency.xmr: + return _moneroAmountToDouble(amount); + case CryptoCurrency.btc: + return _bitcoinAmountToDouble(amount); + case CryptoCurrency.bch: + return _bitcoinCashAmountToDouble(amount); + case CryptoCurrency.dash: + return _dashAmountToDouble(amount); + case CryptoCurrency.eth: + return _ethereumAmountToDouble(amount); + case CryptoCurrency.ltc: + return _litecoinAmountToDouble(amount); + default: + return null; + } + } + + static int amountStringToInt(CryptoCurrency cryptoCurrency, String amount) { + switch (cryptoCurrency) { + case CryptoCurrency.xmr: + return _moneroParseAmount(amount); + default: + return null; + } + } + + static String amountIntToString(CryptoCurrency cryptoCurrency, int amount) { + switch (cryptoCurrency) { + case CryptoCurrency.xmr: + return _moneroAmountToString(amount); + case CryptoCurrency.btc: + return _bitcoinAmountToString(amount); + default: + return null; + } + } + + static double cryptoAmountToDouble({num amount, num divider}) => + amount / divider; + + static String _moneroAmountToString(int amount) => _moneroAmountFormat.format( + cryptoAmountToDouble(amount: amount, divider: _moneroAmountDivider)); + + static double _moneroAmountToDouble(int amount) => + cryptoAmountToDouble(amount: amount, divider: _moneroAmountDivider); + + static int _moneroParseAmount(String amount) => + _moneroAmountFormat.parse(amount).toInt(); + + static String _bitcoinAmountToString(int amount) => + _bitcoinAmountFormat.format( + cryptoAmountToDouble(amount: amount, divider: _bitcoinAmountDivider)); + + static double _bitcoinAmountToDouble(int amount) => + cryptoAmountToDouble(amount: amount, divider: _bitcoinAmountDivider); + + static int _doubleToBitcoinAmount(double amount) => + (amount * _bitcoinAmountDivider).toInt(); + + static double _bitcoinCashAmountToDouble(int amount) => + cryptoAmountToDouble(amount: amount, divider: _bitcoinCashAmountDivider); + + static double _dashAmountToDouble(int amount) => + cryptoAmountToDouble(amount: amount, divider: _dashAmountDivider); + + static double _ethereumAmountToDouble(num amount) => + cryptoAmountToDouble(amount: amount, divider: _ethereumAmountDivider); + + static double _litecoinAmountToDouble(int amount) => + cryptoAmountToDouble(amount: amount, divider: _litecoinAmountDivider); +} diff --git a/lib/core/amount_validator.dart b/lib/core/amount_validator.dart index cee4fe8e1..abf55b6b7 100644 --- a/lib/core/amount_validator.dart +++ b/lib/core/amount_validator.dart @@ -1,6 +1,6 @@ import 'package:cake_wallet/core/validator.dart'; import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; class AmountValidator extends TextValidator { AmountValidator({WalletType type, bool isAutovalidate = false}) diff --git a/lib/core/auth_service.dart b/lib/core/auth_service.dart index 557800fd6..f2c07d265 100644 --- a/lib/core/auth_service.dart +++ b/lib/core/auth_service.dart @@ -1,8 +1,9 @@ import 'package:mobx/mobx.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:cake_wallet/src/domain/common/secret_store_key.dart'; -import 'package:cake_wallet/src/domain/common/encrypt.dart'; +import 'package:cake_wallet/entities/preferences_key.dart'; +import 'package:cake_wallet/entities/secret_store_key.dart'; +import 'package:cake_wallet/entities/encrypt.dart'; class AuthService with Store { AuthService({this.secureStorage, this.sharedPreferences}); @@ -18,7 +19,8 @@ class AuthService with Store { Future canAuthenticate() async { final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword); - final walletName = sharedPreferences.getString('current_wallet_name') ?? ''; + final walletName = + sharedPreferences.getString(PreferencesKey.currentWalletName) ?? ''; var password = ''; try { diff --git a/lib/core/contact_service.dart b/lib/core/contact_service.dart index 1141a1d06..c7027fa8f 100644 --- a/lib/core/contact_service.dart +++ b/lib/core/contact_service.dart @@ -1,6 +1,6 @@ import 'package:hive/hive.dart'; import 'package:cake_wallet/store/contact_list_store.dart'; -import 'package:cake_wallet/src/domain/common/contact.dart'; +import 'package:cake_wallet/entities/contact.dart'; class ContactService { ContactService(this.contactSource, this.contactListStore) { diff --git a/lib/core/execution_state.dart b/lib/core/execution_state.dart new file mode 100644 index 000000000..d4e3faeec --- /dev/null +++ b/lib/core/execution_state.dart @@ -0,0 +1,13 @@ +abstract class ExecutionState {} + +class InitialExecutionState extends ExecutionState {} + +class IsExecutingState extends ExecutionState {} + +class ExecutedSuccessfullyState extends ExecutionState {} + +class FailureState extends ExecutionState { + FailureState(this.error); + + final String error; +} \ No newline at end of file diff --git a/lib/src/domain/common/fetch_price.dart b/lib/core/fiat_conversion_service.dart similarity index 53% rename from lib/src/domain/common/fetch_price.dart rename to lib/core/fiat_conversion_service.dart index 36f996f7e..a6d72497e 100644 --- a/lib/src/domain/common/fetch_price.dart +++ b/lib/core/fiat_conversion_service.dart @@ -1,13 +1,16 @@ +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/entities/fiat_currency.dart'; import 'dart:convert'; +import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/common/fiat_currency.dart'; -import 'package:cake_wallet/src/domain/common/currency_formatter.dart'; +import 'package:cake_wallet/entities/currency_formatter.dart'; const fiatApiAuthority = 'fiat-api.cakewallet.com'; const fiatApiPath = '/v1/rates'; -Future fetchPriceFor({CryptoCurrency crypto, FiatCurrency fiat}) async { +Future _fetchPrice(Map args) async { + final crypto = args['crypto'] as CryptoCurrency; + final fiat = args['fiat'] as FiatCurrency; double price = 0.0; try { @@ -35,3 +38,12 @@ Future fetchPriceFor({CryptoCurrency crypto, FiatCurrency fiat}) async { return price; } } + +Future _fetchPriceAsync( + CryptoCurrency crypto, FiatCurrency fiat) async => + compute(_fetchPrice, {'fiat': fiat, 'crypto': crypto}); + +class FiatConversionService { + static Future fetchPrice(CryptoCurrency crypto, FiatCurrency fiat) async => + await _fetchPriceAsync(crypto, fiat); +} diff --git a/lib/core/generate_wallet_password.dart b/lib/core/generate_wallet_password.dart index ea5b80d23..abf2e6dac 100644 --- a/lib/core/generate_wallet_password.dart +++ b/lib/core/generate_wallet_password.dart @@ -1,6 +1,6 @@ import 'package:uuid/uuid.dart'; import 'package:cake_wallet/bitcoin/key.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; String generateWalletPassword(WalletType type) { switch (type) { diff --git a/lib/core/key_service.dart b/lib/core/key_service.dart index 85185be72..eafca2b0a 100644 --- a/lib/core/key_service.dart +++ b/lib/core/key_service.dart @@ -1,6 +1,6 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:cake_wallet/src/domain/common/secret_store_key.dart'; -import 'package:cake_wallet/src/domain/common/encrypt.dart'; +import 'package:cake_wallet/entities/secret_store_key.dart'; +import 'package:cake_wallet/entities/encrypt.dart'; class KeyService { KeyService(this._secureStorage); diff --git a/lib/core/mnemonic_length.dart b/lib/core/mnemonic_length.dart index 84100d8a7..8adf5c438 100644 --- a/lib/core/mnemonic_length.dart +++ b/lib/core/mnemonic_length.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; const bitcoinMnemonicLength = 12; const moneroMnemonicLength = 25; diff --git a/lib/core/monero_account_label_validator.dart b/lib/core/monero_account_label_validator.dart index 9d06a437c..dcbac668f 100644 --- a/lib/core/monero_account_label_validator.dart +++ b/lib/core/monero_account_label_validator.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/core/validator.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; class MoneroLabelValidator extends TextValidator { MoneroLabelValidator({@required CryptoCurrency type}) diff --git a/lib/core/seed_validator.dart b/lib/core/seed_validator.dart index 54b1ffea7..36a06cb03 100644 --- a/lib/core/seed_validator.dart +++ b/lib/core/seed_validator.dart @@ -1,15 +1,16 @@ import 'package:bip39/src/wordlists/english.dart' as bitcoin_english; import 'package:cake_wallet/core/validator.dart'; -import 'package:cake_wallet/src/domain/common/mnemonic_item.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/chinese_simplified.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/dutch.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/english.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/german.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/japanese.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/portuguese.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/russian.dart'; -import 'package:cake_wallet/src/domain/monero/mnemonics/spanish.dart'; +import 'package:cake_wallet/entities/mnemonic_item.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; +import 'package:cake_wallet/monero/mnemonics/chinese_simplified.dart'; +import 'package:cake_wallet/monero/mnemonics/dutch.dart'; +import 'package:cake_wallet/monero/mnemonics/english.dart'; +import 'package:cake_wallet/monero/mnemonics/german.dart'; +import 'package:cake_wallet/monero/mnemonics/japanese.dart'; +import 'package:cake_wallet/monero/mnemonics/portuguese.dart'; +import 'package:cake_wallet/monero/mnemonics/russian.dart'; +import 'package:cake_wallet/monero/mnemonics/spanish.dart'; +import 'package:cake_wallet/utils/language_list.dart'; class SeedValidator extends Validator { SeedValidator({this.type, this.language}) @@ -31,31 +32,29 @@ class SeedValidator extends Validator { } static List getMoneroWordList(String language) { - // FIXME: Unnamed constants; Need to be sure that string are in same case; - switch (language) { - case 'English': + case LanguageList.english: return EnglishMnemonics.words; break; - case 'Chinese (simplified)': + case LanguageList.chineseSimplified: return ChineseSimplifiedMnemonics.words; break; - case 'Dutch': + case LanguageList.dutch: return DutchMnemonics.words; break; - case 'German': + case LanguageList.german: return GermanMnemonics.words; break; - case 'Japanese': + case LanguageList.japanese: return JapaneseMnemonics.words; break; - case 'Portuguese': + case LanguageList.portuguese: return PortugueseMnemonics.words; break; - case 'Russian': + case LanguageList.russian: return RussianMnemonics.words; break; - case 'Spanish': + case LanguageList.spanish: return SpanishMnemonics.words; break; default: @@ -64,7 +63,7 @@ class SeedValidator extends Validator { } static List getBitcoinWordList(String language) { - assert(language.toLowerCase() == 'english'); + assert(language.toLowerCase() == LanguageList.english.toLowerCase()); return bitcoin_english.WORDLIST; } diff --git a/lib/core/transaction_history.dart b/lib/core/transaction_history.dart index dd2c5a0f2..6fa5bd228 100644 --- a/lib/core/transaction_history.dart +++ b/lib/core/transaction_history.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:mobx/mobx.dart'; -import 'package:cake_wallet/src/domain/common/transaction_info.dart'; +import 'package:cake_wallet/entities/transaction_info.dart'; abstract class TransactionHistoryBase { TransactionHistoryBase() : _isUpdating = false; diff --git a/lib/core/wallet_base.dart b/lib/core/wallet_base.dart index b5f8e27cc..8eea39dca 100644 --- a/lib/core/wallet_base.dart +++ b/lib/core/wallet_base.dart @@ -1,24 +1,13 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/common/wallet_info.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; import 'package:cake_wallet/core/pending_transaction.dart'; import 'package:cake_wallet/core/transaction_history.dart'; -import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/common/sync_status.dart'; -import 'package:cake_wallet/src/domain/common/node.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; - -// FIXME: Move me. -CryptoCurrency currencyForWalletType(WalletType type) { - switch (type) { - case WalletType.bitcoin: - return CryptoCurrency.btc; - case WalletType.monero: - return CryptoCurrency.xmr; - default: - return null; - } -} +import 'package:cake_wallet/entities/currency_for_wallet_type.dart'; +import 'package:cake_wallet/entities/transaction_priority.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/entities/sync_status.dart'; +import 'package:cake_wallet/entities/node.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; abstract class WalletBase { WalletBase(this.walletInfo); @@ -61,4 +50,6 @@ abstract class WalletBase { double calculateEstimatedFee(TransactionPriority priority); Future save(); + + Future rescan({int height}); } diff --git a/lib/core/wallet_creation_service.dart b/lib/core/wallet_creation_service.dart index ce14fa1e2..fe3062d36 100644 --- a/lib/core/wallet_creation_service.dart +++ b/lib/core/wallet_creation_service.dart @@ -3,18 +3,15 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:cake_wallet/core/key_service.dart'; +import 'package:cake_wallet/core/wallet_base.dart'; import 'package:cake_wallet/core/generate_wallet_password.dart'; -import 'package:cake_wallet/store/app_store.dart'; import 'package:cake_wallet/core/wallet_credentials.dart'; -import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; -import 'package:cake_wallet/monero/monero_wallet_service.dart'; import 'package:cake_wallet/core/wallet_service.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; class WalletCreationService { WalletCreationService( {WalletType initialType, - this.appStore, this.secureStorage, this.keyService, this.sharedPreferences}) @@ -25,7 +22,6 @@ class WalletCreationService { } WalletType type; - final AppStore appStore; final FlutterSecureStorage secureStorage; final SharedPreferences sharedPreferences; final KeyService keyService; @@ -36,33 +32,27 @@ class WalletCreationService { _service = getIt.get(param1: type); } - Future create(WalletCredentials credentials) async { + Future create(WalletCredentials credentials) async { final password = generateWalletPassword(type); credentials.password = password; await keyService.saveWalletPassword( password: password, walletName: credentials.name); - final wallet = await _service.create(credentials); - appStore.wallet = wallet; - appStore.authenticationStore.allowed(); + return await _service.create(credentials); } - Future restoreFromKeys(WalletCredentials credentials) async { + Future restoreFromKeys(WalletCredentials credentials) async { final password = generateWalletPassword(type); credentials.password = password; await keyService.saveWalletPassword( password: password, walletName: credentials.name); - final wallet = await _service.restoreFromKeys(credentials); - appStore.wallet = wallet; - appStore.authenticationStore.allowed(); + return await _service.restoreFromKeys(credentials); } - Future restoreFromSeed(WalletCredentials credentials) async { + Future restoreFromSeed(WalletCredentials credentials) async { final password = generateWalletPassword(type); credentials.password = password; await keyService.saveWalletPassword( password: password, walletName: credentials.name); - final wallet = await _service.restoreFromSeed(credentials); - appStore.wallet = wallet; - appStore.authenticationStore.allowed(); + return await _service.restoreFromSeed(credentials); } } diff --git a/lib/core/wallet_credentials.dart b/lib/core/wallet_credentials.dart index 7dc93f848..3998bb005 100644 --- a/lib/core/wallet_credentials.dart +++ b/lib/core/wallet_credentials.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/wallet_info.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; abstract class WalletCredentials { WalletCredentials({this.name, this.password, this.height}); diff --git a/lib/di.dart b/lib/di.dart index efa9a90f2..4b5f5f077 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,10 +1,12 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; import 'package:cake_wallet/core/contact_service.dart'; import 'package:cake_wallet/core/wallet_service.dart'; +import 'package:cake_wallet/entities/biometric_auth.dart'; import 'package:cake_wallet/monero/monero_wallet_service.dart'; -import 'package:cake_wallet/src/domain/common/contact.dart'; -import 'package:cake_wallet/src/domain/common/node.dart'; -import 'package:cake_wallet/src/domain/exchange/trade.dart'; +import 'package:cake_wallet/entities/contact.dart'; +import 'package:cake_wallet/entities/node.dart'; +import 'package:cake_wallet/exchange/trade.dart'; + // import 'package:cake_wallet/src/domain/services/wallet_service.dart'; import 'package:cake_wallet/src/screens/contact/contact_list_page.dart'; import 'package:cake_wallet/src/screens/contact/contact_page.dart'; @@ -12,9 +14,11 @@ import 'package:cake_wallet/src/screens/exchange_trade/exchange_confirm_page.dar import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart'; import 'package:cake_wallet/src/screens/nodes/node_create_or_edit_page.dart'; import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart'; +import 'package:cake_wallet/src/screens/rescan/rescan_page.dart'; import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart'; import 'package:cake_wallet/src/screens/send/send_template_page.dart'; import 'package:cake_wallet/src/screens/settings/settings.dart'; +import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart'; import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart'; import 'package:cake_wallet/src/screens/exchange/exchange_page.dart'; import 'package:cake_wallet/src/screens/exchange/exchange_template_page.dart'; @@ -24,7 +28,7 @@ import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/core/auth_service.dart'; import 'package:cake_wallet/core/key_service.dart'; import 'package:cake_wallet/monero/monero_wallet.dart'; -import 'package:cake_wallet/src/domain/common/wallet_info.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; import 'package:cake_wallet/src/screens/monero_accounts/monero_account_list_page.dart'; import 'package:cake_wallet/src/screens/monero_accounts/monero_account_edit_or_create_page.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; @@ -42,6 +46,8 @@ import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart'; import 'package:cake_wallet/view_model/exchange/exchange_trade_view_model.dart'; import 'package:cake_wallet/view_model/node_list/node_list_view_model.dart'; import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart'; +import 'package:cake_wallet/view_model/rescan_view_model.dart'; +import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart'; import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart'; import 'package:cake_wallet/view_model/auth_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; @@ -56,6 +62,7 @@ import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; import 'package:cake_wallet/view_model/wallet_seed_view_model.dart'; import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart'; import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; import 'package:get_it/get_it.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; @@ -65,51 +72,20 @@ import 'package:cake_wallet/view_model/wallet_restoration_from_seed_vm.dart'; import 'package:cake_wallet/view_model/wallet_restoration_from_keys_vm.dart'; import 'package:cake_wallet/core/wallet_creation_service.dart'; import 'package:cake_wallet/store/app_store.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/view_model/wallet_new_vm.dart'; import 'package:cake_wallet/store/authentication_store.dart'; import 'package:cake_wallet/store/dashboard/trades_store.dart'; import 'package:cake_wallet/store/dashboard/trade_filter_store.dart'; import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart'; -import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart'; +import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart'; import 'package:cake_wallet/store/templates/send_template_store.dart'; import 'package:cake_wallet/store/templates/exchange_template_store.dart'; -import 'package:cake_wallet/src/domain/common/template.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_template.dart'; +import 'package:cake_wallet/entities/template.dart'; +import 'package:cake_wallet/exchange/exchange_template.dart'; final getIt = GetIt.instance; -// FIXME: Move me. - -Stream _onNodesSourceChange; -NodeListStore _nodeListStore; - -NodeListStore setupNodeListStore(Box nodeSource) { - if (_nodeListStore != null) { - return _nodeListStore; - } - - _nodeListStore = NodeListStore(); - _nodeListStore.replaceValues(nodeSource.values); - _onNodesSourceChange = nodeSource.watch(); - _onNodesSourceChange.listen((event) { -// print(event); - - if (event.deleted) { - _nodeListStore.nodes.removeWhere((n) { - return n.key != null ? n.key == event.key : true; - }); - } - - if (event.value is Node) { - final val = event.value as Node; - _nodeListStore.nodes.add(val); - } - }); - - return _nodeListStore; -} - Future setup( {Box walletInfoSource, Box nodeSource, @@ -122,11 +98,13 @@ Future setup( final settingsStore = await SettingsStoreBase.load(nodeSource: nodeSource); + getIt.registerSingleton>(nodeSource); + getIt.registerSingleton(FlutterSecureStorage()); getIt.registerSingleton(AuthenticationStore()); getIt.registerSingleton(WalletListStore()); getIt.registerSingleton(ContactListStore()); - getIt.registerSingleton(setupNodeListStore(nodeSource)); + getIt.registerSingleton(NodeListStoreBase.instance); getIt.registerSingleton(settingsStore); getIt.registerSingleton(AppStore( authenticationStore: getIt.get(), @@ -140,7 +118,7 @@ Future setup( tradesSource: tradesSource, settingsStore: getIt.get())); getIt.registerSingleton(TradeFilterStore()); getIt.registerSingleton(TransactionFilterStore()); - getIt.registerSingleton(FiatConvertationStore()); + getIt.registerSingleton(FiatConversionStore()); getIt.registerSingleton( SendTemplateStore(templateSource: templates)); getIt.registerSingleton( @@ -152,13 +130,12 @@ Future setup( getIt.registerFactoryParam( (type, _) => WalletCreationService( initialType: type, - appStore: getIt.get(), keyService: getIt.get(), secureStorage: getIt.get(), sharedPreferences: getIt.get())); getIt.registerFactoryParam((type, _) => - WalletNewVM( + WalletNewVM(getIt.get(), getIt.get(param1: type), walletInfoSource, type: type)); @@ -168,7 +145,7 @@ Future setup( final language = args[1] as String; final mnemonic = args[2] as String; - return WalletRestorationFromSeedVM( + return WalletRestorationFromSeedVM(getIt.get(), getIt.get(param1: type), walletInfoSource, type: type, language: language, seed: mnemonic); }); @@ -178,7 +155,7 @@ Future setup( final type = args.first as WalletType; final language = args[1] as String; - return WalletRestorationFromKeysVM( + return WalletRestorationFromKeysVM(getIt.get(), getIt.get(param1: type), walletInfoSource, type: type, language: language); }); @@ -189,7 +166,7 @@ Future setup( getIt.registerFactory(() => BalanceViewModel( wallet: getIt.get().wallet, settingsStore: getIt.get(), - fiatConvertationStore: getIt.get())); + fiatConvertationStore: getIt.get())); getIt.registerFactory(() => DashboardViewModel( balanceViewModel: getIt.get(), @@ -203,38 +180,24 @@ Future setup( sharedPreferences: getIt.get())); getIt.registerFactory(() => AuthViewModel( - authService: getIt.get(), - sharedPreferences: getIt.get())); + getIt.get(), + getIt.get(), + getIt.get(), + BiometricAuth())); getIt.registerFactory( - () => AuthPage( - allowBiometricalAuthentication: getIt - .get() - .settingsStore - .allowBiometricalAuthentication, - authViewModel: getIt.get(), - onAuthenticationFinished: (isAuthenticated, __) { + () => AuthPage(getIt.get(), + onAuthenticationFinished: (isAuthenticated, __) { if (isAuthenticated) { getIt.get().allowed(); } - }, - closable: false), + }, closable: false), instanceName: 'login'); getIt .registerFactoryParam( - (onAuthFinished, _) { - final allowBiometricalAuthentication = - getIt.get().settingsStore.allowBiometricalAuthentication; - - print('allowBiometricalAuthentication $allowBiometricalAuthentication'); - - return AuthPage( - allowBiometricalAuthentication: allowBiometricalAuthentication, - authViewModel: getIt.get(), - onAuthenticationFinished: onAuthFinished, - closable: false); - }); + (onAuthFinished, _) => AuthPage(getIt.get(), + onAuthenticationFinished: onAuthFinished, closable: false)); getIt.registerFactory(() => DashboardPage( walletViewModel: getIt.get(), @@ -256,13 +219,13 @@ Future setup( getIt.registerFactory(() => SendViewModel( getIt.get().wallet, getIt.get().settingsStore, - getIt.get())); + getIt.get())); getIt.registerFactory( () => SendPage(sendViewModel: getIt.get())); getIt.registerFactory( - () => SendTemplatePage(sendViewModel: getIt.get())); + () => SendTemplatePage(sendViewModel: getIt.get())); getIt.registerFactory(() => WalletListViewModel( walletInfoSource, getIt.get(), getIt.get())); @@ -387,6 +350,19 @@ Future setup( return null; } }); + + getIt.registerFactory(() => SetupPinCodeViewModel( + getIt.get(), getIt.get())); + + getIt.registerFactoryParam( + (onSuccessfulPinSetup, _) => SetupPinCodePage( + getIt.get(), + onSuccessfulPinSetup: onSuccessfulPinSetup)); + + getIt.registerFactory(() => RescanViewModel(getIt.get().wallet)); + + getIt.registerFactory(() => RescanPage(getIt.get())); } void setupThemeChangerStore(ThemeChanger themeChanger) { diff --git a/lib/src/stores/action_list/action_list_display_mode.dart b/lib/entities/action_list_display_mode.dart similarity index 100% rename from lib/src/stores/action_list/action_list_display_mode.dart rename to lib/entities/action_list_display_mode.dart diff --git a/lib/src/domain/common/balance.dart b/lib/entities/balance.dart similarity index 100% rename from lib/src/domain/common/balance.dart rename to lib/entities/balance.dart diff --git a/lib/src/domain/common/balance_display_mode.dart b/lib/entities/balance_display_mode.dart similarity index 94% rename from lib/src/domain/common/balance_display_mode.dart rename to lib/entities/balance_display_mode.dart index 42dc09924..57197e57b 100644 --- a/lib/src/domain/common/balance_display_mode.dart +++ b/lib/entities/balance_display_mode.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/src/domain/common/enumerable_item.dart'; +import 'package:cake_wallet/entities/enumerable_item.dart'; class BalanceDisplayMode extends EnumerableItem with Serializable { const BalanceDisplayMode({@required String title, @required int raw}) diff --git a/lib/src/domain/common/biometric_auth.dart b/lib/entities/biometric_auth.dart similarity index 100% rename from lib/src/domain/common/biometric_auth.dart rename to lib/entities/biometric_auth.dart diff --git a/lib/src/domain/common/calculate_estimated_fee.dart b/lib/entities/calculate_estimated_fee.dart similarity index 85% rename from lib/src/domain/common/calculate_estimated_fee.dart rename to lib/entities/calculate_estimated_fee.dart index 8d6aa6bc6..6c9200834 100644 --- a/lib/src/domain/common/calculate_estimated_fee.dart +++ b/lib/entities/calculate_estimated_fee.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; +import 'package:cake_wallet/entities/transaction_priority.dart'; double calculateEstimatedFee({TransactionPriority priority}) { if (priority == TransactionPriority.slow) { diff --git a/lib/src/domain/common/calculate_fiat_amount.dart b/lib/entities/calculate_fiat_amount.dart similarity index 100% rename from lib/src/domain/common/calculate_fiat_amount.dart rename to lib/entities/calculate_fiat_amount.dart diff --git a/lib/src/domain/common/calculate_fiat_amount_raw.dart b/lib/entities/calculate_fiat_amount_raw.dart similarity index 100% rename from lib/src/domain/common/calculate_fiat_amount_raw.dart rename to lib/entities/calculate_fiat_amount_raw.dart diff --git a/lib/src/domain/common/contact.dart b/lib/entities/contact.dart similarity index 91% rename from lib/src/domain/common/contact.dart rename to lib/entities/contact.dart index 4aca925eb..e54ab0126 100644 --- a/lib/src/domain/common/contact.dart +++ b/lib/entities/contact.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; import 'package:cake_wallet/utils/mobx.dart'; part 'contact.g.dart'; diff --git a/lib/src/domain/common/contact_model.dart b/lib/entities/contact_model.dart similarity index 86% rename from lib/src/domain/common/contact_model.dart rename to lib/entities/contact_model.dart index 94185a647..dacd1cfb1 100644 --- a/lib/src/domain/common/contact_model.dart +++ b/lib/entities/contact_model.dart @@ -1,7 +1,7 @@ // import 'package:hive/hive.dart'; // import 'package:mobx/mobx.dart'; -// import 'package:cake_wallet/src/domain/common/contact.dart'; -// import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; +// import 'package:cake_wallet/entities/contact.dart'; +// import 'package:cake_wallet/entities/crypto_currency.dart'; // part 'contact_model.g.dart'; diff --git a/lib/src/domain/common/crypto_amount_format.dart b/lib/entities/crypto_amount_format.dart similarity index 100% rename from lib/src/domain/common/crypto_amount_format.dart rename to lib/entities/crypto_amount_format.dart diff --git a/lib/src/domain/common/crypto_currency.dart b/lib/entities/crypto_currency.dart similarity index 97% rename from lib/src/domain/common/crypto_currency.dart rename to lib/entities/crypto_currency.dart index fb09ff181..722fc2aef 100644 --- a/lib/src/domain/common/crypto_currency.dart +++ b/lib/entities/crypto_currency.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/enumerable_item.dart'; +import 'package:cake_wallet/entities/enumerable_item.dart'; import 'package:hive/hive.dart'; part 'crypto_currency.g.dart'; diff --git a/lib/entities/currency_for_wallet_type.dart b/lib/entities/currency_for_wallet_type.dart new file mode 100644 index 000000000..840e75dd1 --- /dev/null +++ b/lib/entities/currency_for_wallet_type.dart @@ -0,0 +1,13 @@ +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; + +CryptoCurrency currencyForWalletType(WalletType type) { + switch (type) { + case WalletType.bitcoin: + return CryptoCurrency.btc; + case WalletType.monero: + return CryptoCurrency.xmr; + default: + return null; + } +} \ No newline at end of file diff --git a/lib/src/domain/common/currency_formatter.dart b/lib/entities/currency_formatter.dart similarity index 74% rename from lib/src/domain/common/currency_formatter.dart rename to lib/entities/currency_formatter.dart index efe1bf759..40326a7e6 100644 --- a/lib/src/domain/common/currency_formatter.dart +++ b/lib/entities/currency_formatter.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; String cryptoToString(CryptoCurrency crypto) { switch (crypto) { diff --git a/lib/src/domain/common/default_settings_migration.dart b/lib/entities/default_settings_migration.dart similarity index 89% rename from lib/src/domain/common/default_settings_migration.dart rename to lib/entities/default_settings_migration.dart index 44165fdbf..f16349387 100644 --- a/lib/src/domain/common/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -1,13 +1,13 @@ -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; -import 'package:cake_wallet/store/settings_store.dart'; import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:cake_wallet/src/domain/common/node.dart'; -import 'package:cake_wallet/src/domain/common/balance_display_mode.dart'; -import 'package:cake_wallet/src/domain/common/fiat_currency.dart'; -import 'package:cake_wallet/src/domain/common/node_list.dart'; -import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; +import 'package:cake_wallet/entities/preferences_key.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; +import 'package:cake_wallet/entities/node.dart'; +import 'package:cake_wallet/entities/balance_display_mode.dart'; +import 'package:cake_wallet/entities/fiat_currency.dart'; +import 'package:cake_wallet/entities/node_list.dart'; +import 'package:cake_wallet/entities/transaction_priority.dart'; Future defaultSettingsMigration( {@required int version, @@ -29,13 +29,13 @@ Future defaultSettingsMigration( switch (version) { case 1: await sharedPreferences.setString( - SettingsStoreBase.currentFiatCurrencyKey, + PreferencesKey.currentFiatCurrencyKey, FiatCurrency.usd.toString()); await sharedPreferences.setInt( - SettingsStoreBase.currentTransactionPriorityKey, + PreferencesKey.currentTransactionPriorityKey, TransactionPriority.standart.raw); await sharedPreferences.setInt( - SettingsStoreBase.currentBalanceDisplayModeKey, + PreferencesKey.currentBalanceDisplayModeKey, BalanceDisplayMode.availableBalance.raw); await sharedPreferences.setBool('save_recipient_address', true); await resetToDefault(nodes); diff --git a/lib/src/domain/common/digest_request.dart b/lib/entities/digest_request.dart similarity index 100% rename from lib/src/domain/common/digest_request.dart rename to lib/entities/digest_request.dart diff --git a/lib/src/domain/common/encrypt.dart b/lib/entities/encrypt.dart similarity index 100% rename from lib/src/domain/common/encrypt.dart rename to lib/entities/encrypt.dart diff --git a/lib/src/domain/common/enumerable_item.dart b/lib/entities/enumerable_item.dart similarity index 100% rename from lib/src/domain/common/enumerable_item.dart rename to lib/entities/enumerable_item.dart diff --git a/lib/src/domain/common/fiat_currency.dart b/lib/entities/fiat_currency.dart similarity index 97% rename from lib/src/domain/common/fiat_currency.dart rename to lib/entities/fiat_currency.dart index 7c86ad610..8066c8f6a 100644 --- a/lib/src/domain/common/fiat_currency.dart +++ b/lib/entities/fiat_currency.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/enumerable_item.dart'; +import 'package:cake_wallet/entities/enumerable_item.dart'; class FiatCurrency extends EnumerableItem with Serializable { const FiatCurrency({String symbol}) : super(title: symbol, raw: symbol); diff --git a/lib/src/domain/common/format_amount.dart b/lib/entities/format_amount.dart similarity index 100% rename from lib/src/domain/common/format_amount.dart rename to lib/entities/format_amount.dart diff --git a/lib/src/domain/common/fs_migration.dart b/lib/entities/fs_migration.dart similarity index 92% rename from lib/src/domain/common/fs_migration.dart rename to lib/entities/fs_migration.dart index 0d848aeb9..bb674b493 100644 --- a/lib/src/domain/common/fs_migration.dart +++ b/lib/entities/fs_migration.dart @@ -1,10 +1,10 @@ import 'dart:io'; import 'dart:convert'; -import 'package:cake_wallet/src/domain/common/contact.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/common/wallet_info.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; -import 'package:cake_wallet/src/domain/exchange/trade.dart'; +import 'package:cake_wallet/entities/contact.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; +import 'package:cake_wallet/exchange/trade.dart'; import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; import 'package:path_provider/path_provider.dart'; diff --git a/lib/src/domain/common/get_encryption_key.dart b/lib/entities/get_encryption_key.dart similarity index 100% rename from lib/src/domain/common/get_encryption_key.dart rename to lib/entities/get_encryption_key.dart diff --git a/lib/src/domain/common/language.dart b/lib/entities/language.dart similarity index 100% rename from lib/src/domain/common/language.dart rename to lib/entities/language.dart diff --git a/lib/entities/load_current_wallet.dart b/lib/entities/load_current_wallet.dart new file mode 100644 index 000000000..ef690521f --- /dev/null +++ b/lib/entities/load_current_wallet.dart @@ -0,0 +1,23 @@ +import 'package:cake_wallet/di.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:cake_wallet/store/app_store.dart'; +import 'package:cake_wallet/core/key_service.dart'; +import 'package:cake_wallet/core/wallet_service.dart'; +import 'package:cake_wallet/entities/preferences_key.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; + +Future loadCurrentWallet() async { + final appStore = getIt.get(); + final name = getIt + .get() + .getString(PreferencesKey.currentWalletName); + final typeRaw = + getIt.get().getInt(PreferencesKey.currentWalletType) ?? + 0; + final type = deserializeFromInt(typeRaw); + final password = + await getIt.get().getWalletPassword(walletName: name); + final _service = getIt.get(param1: type); + final wallet = await _service.openWallet(name, password); + appStore.wallet = wallet; +} diff --git a/lib/src/domain/common/mnemonic_item.dart b/lib/entities/mnemonic_item.dart similarity index 100% rename from lib/src/domain/common/mnemonic_item.dart rename to lib/entities/mnemonic_item.dart diff --git a/lib/src/domain/common/node.dart b/lib/entities/node.dart similarity index 94% rename from lib/src/domain/common/node.dart rename to lib/entities/node.dart index 931eabf6c..74643112a 100644 --- a/lib/src/domain/common/node.dart +++ b/lib/entities/node.dart @@ -3,8 +3,8 @@ import 'package:flutter/foundation.dart'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:hive/hive.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; -import 'package:cake_wallet/src/domain/common/digest_request.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; +import 'package:cake_wallet/entities/digest_request.dart'; part 'node.g.dart'; diff --git a/lib/src/domain/common/node_list.dart b/lib/entities/node_list.dart similarity index 90% rename from lib/src/domain/common/node_list.dart rename to lib/entities/node_list.dart index 67bfe6eac..118394e6f 100644 --- a/lib/src/domain/common/node_list.dart +++ b/lib/entities/node_list.dart @@ -1,8 +1,8 @@ import 'package:flutter/services.dart'; import 'package:hive/hive.dart'; import "package:yaml/yaml.dart"; -import 'package:cake_wallet/src/domain/common/node.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/node.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; Future> loadDefaultNodes() async { final nodesRaw = await rootBundle.loadString('assets/node_list.yml'); diff --git a/lib/src/domain/common/openalias_record.dart b/lib/entities/openalias_record.dart similarity index 100% rename from lib/src/domain/common/openalias_record.dart rename to lib/entities/openalias_record.dart diff --git a/lib/src/domain/common/parseBoolFromString.dart b/lib/entities/parseBoolFromString.dart similarity index 100% rename from lib/src/domain/common/parseBoolFromString.dart rename to lib/entities/parseBoolFromString.dart diff --git a/lib/src/domain/common/pathForWallet.dart b/lib/entities/pathForWallet.dart similarity index 91% rename from lib/src/domain/common/pathForWallet.dart rename to lib/entities/pathForWallet.dart index d7caf8c1d..7e21ac178 100644 --- a/lib/src/domain/common/pathForWallet.dart +++ b/lib/entities/pathForWallet.dart @@ -1,5 +1,5 @@ import 'dart:io'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:flutter/foundation.dart'; import 'package:path_provider/path_provider.dart'; diff --git a/lib/src/domain/common/pending_transaction.dart b/lib/entities/pending_transaction.dart similarity index 92% rename from lib/src/domain/common/pending_transaction.dart rename to lib/entities/pending_transaction.dart index 9168b3195..77e5d7b48 100644 --- a/lib/src/domain/common/pending_transaction.dart +++ b/lib/entities/pending_transaction.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:cw_monero/transaction_history.dart' as transaction_history; import 'package:cw_monero/structs/pending_transaction.dart'; -import 'package:cake_wallet/src/domain/monero/monero_amount_format.dart'; +import 'package:cake_wallet/monero/monero_amount_format.dart'; class PendingTransaction { PendingTransaction( diff --git a/lib/entities/preferences_key.dart b/lib/entities/preferences_key.dart new file mode 100644 index 000000000..53d59460a --- /dev/null +++ b/lib/entities/preferences_key.dart @@ -0,0 +1,16 @@ +class PreferencesKey { + static const currentWalletType ='current_wallet_type'; + static const currentWalletName ='current_wallet_name'; + static const currentNodeIdKey = 'current_node_id'; + static const currentBitcoinElectrumSererIdKey = 'current_node_id_btc'; + static const currentFiatCurrencyKey = 'current_fiat_currency'; + static const currentTransactionPriorityKey = 'current_fee_priority'; + static const currentBalanceDisplayModeKey = 'current_balance_display_mode'; + static const shouldSaveRecipientAddressKey = 'save_recipient_address'; + static const allowBiometricalAuthenticationKey = + 'allow_biometrical_authentication'; + static const currentDarkTheme = 'dark_theme'; + static const displayActionListModeKey = 'display_list_mode'; + static const currentPinLength = 'current_pin_length'; + static const currentLanguageCode = 'language_code'; +} \ No newline at end of file diff --git a/lib/src/domain/common/qr_scanner.dart b/lib/entities/qr_scanner.dart similarity index 100% rename from lib/src/domain/common/qr_scanner.dart rename to lib/entities/qr_scanner.dart diff --git a/lib/src/domain/common/secret_store_key.dart b/lib/entities/secret_store_key.dart similarity index 100% rename from lib/src/domain/common/secret_store_key.dart rename to lib/entities/secret_store_key.dart diff --git a/lib/src/domain/common/sync_status.dart b/lib/entities/sync_status.dart similarity index 100% rename from lib/src/domain/common/sync_status.dart rename to lib/entities/sync_status.dart diff --git a/lib/src/domain/common/template.dart b/lib/entities/template.dart similarity index 100% rename from lib/src/domain/common/template.dart rename to lib/entities/template.dart diff --git a/lib/src/domain/common/transaction_creation_credentials.dart b/lib/entities/transaction_creation_credentials.dart similarity index 100% rename from lib/src/domain/common/transaction_creation_credentials.dart rename to lib/entities/transaction_creation_credentials.dart diff --git a/lib/src/domain/monero/transaction_description.dart b/lib/entities/transaction_description.dart similarity index 85% rename from lib/src/domain/monero/transaction_description.dart rename to lib/entities/transaction_description.dart index 51f01e219..3f817fe4f 100644 --- a/lib/src/domain/monero/transaction_description.dart +++ b/lib/entities/transaction_description.dart @@ -7,6 +7,7 @@ class TransactionDescription extends HiveObject { TransactionDescription({this.id, this.recipientAddress}); static const boxName = 'TransactionDescriptions'; + static const boxKey = 'transactionDescriptionsBoxKey'; @HiveField(0) String id; diff --git a/lib/src/domain/common/transaction_direction.dart b/lib/entities/transaction_direction.dart similarity index 100% rename from lib/src/domain/common/transaction_direction.dart rename to lib/entities/transaction_direction.dart diff --git a/lib/src/domain/common/transaction_history.dart b/lib/entities/transaction_history.dart similarity index 72% rename from lib/src/domain/common/transaction_history.dart rename to lib/entities/transaction_history.dart index 57e508b59..55c02f247 100644 --- a/lib/src/domain/common/transaction_history.dart +++ b/lib/entities/transaction_history.dart @@ -1,5 +1,5 @@ import 'package:rxdart/rxdart.dart'; -import 'package:cake_wallet/src/domain/common/transaction_info.dart'; +import 'package:cake_wallet/entities/transaction_info.dart'; abstract class TransactionHistory { Observable> transactions; diff --git a/lib/src/domain/common/transaction_info.dart b/lib/entities/transaction_info.dart similarity index 78% rename from lib/src/domain/common/transaction_info.dart rename to lib/entities/transaction_info.dart index e5da3bed6..7dfaa64d3 100644 --- a/lib/src/domain/common/transaction_info.dart +++ b/lib/entities/transaction_info.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/transaction_direction.dart'; +import 'package:cake_wallet/entities/transaction_direction.dart'; abstract class TransactionInfo extends Object { String id; diff --git a/lib/src/domain/common/transaction_priority.dart b/lib/entities/transaction_priority.dart similarity index 95% rename from lib/src/domain/common/transaction_priority.dart rename to lib/entities/transaction_priority.dart index f611313e0..9bad84c9f 100644 --- a/lib/src/domain/common/transaction_priority.dart +++ b/lib/entities/transaction_priority.dart @@ -1,5 +1,5 @@ import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/src/domain/common/enumerable_item.dart'; +import 'package:cake_wallet/entities/enumerable_item.dart'; class TransactionPriority extends EnumerableItem with Serializable { const TransactionPriority({String title, int raw}) diff --git a/lib/src/domain/common/wallet.dart b/lib/entities/wallet.dart similarity index 67% rename from lib/src/domain/common/wallet.dart rename to lib/entities/wallet.dart index e2cca5e58..90a3929fe 100644 --- a/lib/src/domain/common/wallet.dart +++ b/lib/entities/wallet.dart @@ -1,11 +1,11 @@ import 'package:rxdart/rxdart.dart'; -import 'package:cake_wallet/src/domain/common/sync_status.dart'; -import 'package:cake_wallet/src/domain/common/transaction_history.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; -import 'package:cake_wallet/src/domain/common/transaction_creation_credentials.dart'; -import 'package:cake_wallet/src/domain/common/pending_transaction.dart'; -import 'package:cake_wallet/src/domain/common/balance.dart'; -import 'package:cake_wallet/src/domain/common/node.dart'; +import 'package:cake_wallet/entities/sync_status.dart'; +import 'package:cake_wallet/entities/transaction_history.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; +import 'package:cake_wallet/entities/transaction_creation_credentials.dart'; +import 'package:cake_wallet/entities/pending_transaction.dart'; +import 'package:cake_wallet/entities/balance.dart'; +import 'package:cake_wallet/entities/node.dart'; abstract class Wallet { WalletType getType(); diff --git a/lib/src/domain/common/wallet_description.dart b/lib/entities/wallet_description.dart similarity index 65% rename from lib/src/domain/common/wallet_description.dart rename to lib/entities/wallet_description.dart index f56616cb1..1e25ffc1c 100644 --- a/lib/src/domain/common/wallet_description.dart +++ b/lib/entities/wallet_description.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; class WalletDescription { WalletDescription({this.name, this.type}); diff --git a/lib/src/domain/common/wallet_info.dart b/lib/entities/wallet_info.dart similarity index 94% rename from lib/src/domain/common/wallet_info.dart rename to lib/entities/wallet_info.dart index c9682f103..97ae9f326 100644 --- a/lib/src/domain/common/wallet_info.dart +++ b/lib/entities/wallet_info.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; part 'wallet_info.g.dart'; diff --git a/lib/src/domain/common/wallet_type.dart b/lib/entities/wallet_type.dart similarity index 100% rename from lib/src/domain/common/wallet_type.dart rename to lib/entities/wallet_type.dart diff --git a/lib/src/domain/common/wallets_manager.dart b/lib/entities/wallets_manager.dart similarity index 79% rename from lib/src/domain/common/wallets_manager.dart rename to lib/entities/wallets_manager.dart index a8d31a8a6..72c80de97 100644 --- a/lib/src/domain/common/wallets_manager.dart +++ b/lib/entities/wallets_manager.dart @@ -1,5 +1,5 @@ -import 'package:cake_wallet/src/domain/common/wallet.dart'; -import 'package:cake_wallet/src/domain/common/wallet_description.dart'; +import 'package:cake_wallet/entities/wallet.dart'; +import 'package:cake_wallet/entities/wallet_description.dart'; abstract class WalletsManager { Future create(String name, String password, String language); diff --git a/lib/src/domain/exchange/changenow/changenow_exchange_provider.dart b/lib/exchange/changenow/changenow_exchange_provider.dart similarity index 86% rename from lib/src/domain/exchange/changenow/changenow_exchange_provider.dart rename to lib/exchange/changenow/changenow_exchange_provider.dart index 7fc3f5d63..94f8ea6ac 100644 --- a/lib/src/domain/exchange/changenow/changenow_exchange_provider.dart +++ b/lib/exchange/changenow/changenow_exchange_provider.dart @@ -1,18 +1,18 @@ import 'dart:convert'; -import 'package:cake_wallet/src/domain/exchange/trade_not_found_exeption.dart'; +import 'package:cake_wallet/exchange/trade_not_found_exeption.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; import 'package:cake_wallet/.secrets.g.dart' as secrets; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart'; -import 'package:cake_wallet/src/domain/exchange/limits.dart'; -import 'package:cake_wallet/src/domain/exchange/trade.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_state.dart'; -import 'package:cake_wallet/src/domain/exchange/changenow/changenow_request.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/exchange_pair.dart'; +import 'package:cake_wallet/exchange/exchange_provider.dart'; +import 'package:cake_wallet/exchange/limits.dart'; +import 'package:cake_wallet/exchange/trade.dart'; +import 'package:cake_wallet/exchange/trade_request.dart'; +import 'package:cake_wallet/exchange/trade_state.dart'; +import 'package:cake_wallet/exchange/changenow/changenow_request.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/exchange/trade_not_created_exeption.dart'; class ChangeNowExchangeProvider extends ExchangeProvider { ChangeNowExchangeProvider() diff --git a/lib/src/domain/exchange/changenow/changenow_request.dart b/lib/exchange/changenow/changenow_request.dart similarity index 72% rename from lib/src/domain/exchange/changenow/changenow_request.dart rename to lib/exchange/changenow/changenow_request.dart index 0201cb3c6..1f79dfa47 100644 --- a/lib/src/domain/exchange/changenow/changenow_request.dart +++ b/lib/exchange/changenow/changenow_request.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/trade_request.dart'; class ChangeNowRequest extends TradeRequest { ChangeNowRequest( diff --git a/lib/src/domain/exchange/exchange_pair.dart b/lib/exchange/exchange_pair.dart similarity index 70% rename from lib/src/domain/exchange/exchange_pair.dart rename to lib/exchange/exchange_pair.dart index 42e2b5db0..b8b77a0dd 100644 --- a/lib/src/domain/exchange/exchange_pair.dart +++ b/lib/exchange/exchange_pair.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; class ExchangePair { ExchangePair({this.from, this.to, this.reverse = true}); diff --git a/lib/src/domain/exchange/exchange_provider.dart b/lib/exchange/exchange_provider.dart similarity index 56% rename from lib/src/domain/exchange/exchange_provider.dart rename to lib/exchange/exchange_provider.dart index 9079d367d..418d20b8c 100644 --- a/lib/src/domain/exchange/exchange_provider.dart +++ b/lib/exchange/exchange_provider.dart @@ -1,10 +1,10 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart'; -import 'package:cake_wallet/src/domain/exchange/limits.dart'; -import 'package:cake_wallet/src/domain/exchange/trade.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/trade_request.dart'; +import 'package:cake_wallet/exchange/exchange_pair.dart'; +import 'package:cake_wallet/exchange/limits.dart'; +import 'package:cake_wallet/exchange/trade.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; abstract class ExchangeProvider { ExchangeProvider({this.pairList}); diff --git a/lib/src/domain/exchange/exchange_provider_description.dart b/lib/exchange/exchange_provider_description.dart similarity index 91% rename from lib/src/domain/exchange/exchange_provider_description.dart rename to lib/exchange/exchange_provider_description.dart index 67a2565d8..bb3b621b5 100644 --- a/lib/src/domain/exchange/exchange_provider_description.dart +++ b/lib/exchange/exchange_provider_description.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/common/enumerable_item.dart'; +import 'package:cake_wallet/entities/enumerable_item.dart'; class ExchangeProviderDescription extends EnumerableItem with Serializable { diff --git a/lib/src/domain/exchange/exchange_template.dart b/lib/exchange/exchange_template.dart similarity index 100% rename from lib/src/domain/exchange/exchange_template.dart rename to lib/exchange/exchange_template.dart diff --git a/lib/src/stores/exchange/exchange_trade_state.dart b/lib/exchange/exchange_trade_state.dart similarity index 88% rename from lib/src/stores/exchange/exchange_trade_state.dart rename to lib/exchange/exchange_trade_state.dart index 1f9eecad1..324ae9338 100644 --- a/lib/src/stores/exchange/exchange_trade_state.dart +++ b/lib/exchange/exchange_trade_state.dart @@ -1,5 +1,5 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/exchange/trade.dart'; +import 'package:cake_wallet/exchange/trade.dart'; abstract class ExchangeTradeState {} diff --git a/lib/src/domain/exchange/limits.dart b/lib/exchange/limits.dart similarity index 100% rename from lib/src/domain/exchange/limits.dart rename to lib/exchange/limits.dart diff --git a/lib/src/stores/exchange/limits_state.dart b/lib/exchange/limits_state.dart similarity index 87% rename from lib/src/stores/exchange/limits_state.dart rename to lib/exchange/limits_state.dart index ccc5934d8..66adaa8a2 100644 --- a/lib/src/stores/exchange/limits_state.dart +++ b/lib/exchange/limits_state.dart @@ -1,5 +1,5 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/exchange/limits.dart'; +import 'package:cake_wallet/exchange/limits.dart'; abstract class LimitsState {} diff --git a/lib/exchange/morphtoken/morphtoken_exchange_provider.dart b/lib/exchange/morphtoken/morphtoken_exchange_provider.dart new file mode 100644 index 000000000..ec632cccb --- /dev/null +++ b/lib/exchange/morphtoken/morphtoken_exchange_provider.dart @@ -0,0 +1,202 @@ +import 'dart:convert'; +import 'package:cake_wallet/core/amount_converter.dart'; +import 'package:cake_wallet/monero/monero_amount_format.dart'; +import 'package:hive/hive.dart'; +import 'package:cake_wallet/exchange/trade_not_found_exeption.dart'; +import 'package:flutter/foundation.dart'; +import 'package:http/http.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/exchange_pair.dart'; +import 'package:cake_wallet/exchange/exchange_provider.dart'; +import 'package:cake_wallet/exchange/limits.dart'; +import 'package:cake_wallet/exchange/trade.dart'; +import 'package:cake_wallet/exchange/trade_request.dart'; +import 'package:cake_wallet/exchange/trade_state.dart'; +import 'package:cake_wallet/exchange/morphtoken/morphtoken_request.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/exchange/trade_not_created_exeption.dart'; + +class MorphTokenExchangeProvider extends ExchangeProvider { + MorphTokenExchangeProvider({@required this.trades}) + : super(pairList: [ + ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.eth), + ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.bch), + ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.ltc), + ExchangePair(from: CryptoCurrency.xmr, to: CryptoCurrency.dash), + ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.btc), + ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.eth), + ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.bch), + ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.ltc), + ExchangePair(from: CryptoCurrency.dash, to: CryptoCurrency.xmr), + ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.btc), + ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.eth), + ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.bch), + ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.dash), + ExchangePair(from: CryptoCurrency.ltc, to: CryptoCurrency.xmr), + ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.btc), + ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.eth), + ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.ltc), + ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.dash), + ExchangePair(from: CryptoCurrency.bch, to: CryptoCurrency.xmr), + ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.btc), + ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.bch), + ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.ltc), + ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.dash), + ExchangePair(from: CryptoCurrency.eth, to: CryptoCurrency.xmr), + ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.eth), + ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.bch), + ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.ltc), + ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.dash), + ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.xmr) + ]); + + Box trades; + + static const apiUri = 'https://api.morphtoken.com'; + static const _morphURISuffix = '/morph'; + static const _limitsURISuffix = '/limits'; + static const _ratesURISuffix = '/rates'; + static const weight = 10000; + + @override + String get title => 'MorphToken'; + + @override + ExchangeProviderDescription get description => + ExchangeProviderDescription.morphToken; + + @override + Future fetchLimits({CryptoCurrency from, CryptoCurrency to}) async { + final url = apiUri + _limitsURISuffix; + final headers = {'Content-type': 'application/json'}; + final body = json.encode({ + "input": {"asset": from.toString()}, + "output": [ + {"asset": to.toString(), "weight": weight} + ] + }); + final response = await post(url, headers: headers, body: body); + final responseJSON = json.decode(response.body) as Map; + + final min = responseJSON['input']['limits']['min'] as int; + int max; + double ethMax; + + if (from == CryptoCurrency.eth) { + ethMax = responseJSON['input']['limits']['max'] as double; + } else { + max = responseJSON['input']['limits']['max'] as int; + } + + double minFormatted = AmountConverter.amountIntToDouble(from, min); + double maxFormatted = AmountConverter.amountIntToDouble(from, max); + + return Limits(min: minFormatted, max: maxFormatted); + } + + @override + Future createTrade({TradeRequest request}) async { + const url = apiUri + _morphURISuffix; + final _request = request as MorphTokenRequest; + final body = { + "input": { + "asset": _request.from.toString(), + "refund": _request.refundAddress + }, + "output": [ + { + "asset": _request.to.toString(), + "weight": weight, + "address": _request.address + } + ], + "tag": "cakewallet" + }; + + final response = await post(url, + headers: {'Content-Type': 'application/json'}, body: json.encode(body)); + + if (response.statusCode != 200) { + if (response.statusCode == 400) { + final responseJSON = json.decode(response.body) as Map; + final error = responseJSON['description'] as String; + + throw TradeNotCreatedException(description, description: error); + } + + throw TradeNotCreatedException(description); + } + + final responseJSON = json.decode(response.body) as Map; + final id = responseJSON['id'] as String; + + return Trade( + id: id, + provider: description, + from: _request.from, + to: _request.to, + state: TradeState.created, + amount: _request.amount, + createdAt: DateTime.now()); + } + + @override + Future findTradeById({@required String id}) async { + final url = apiUri + _morphURISuffix + '/' + id; + final response = await get(url); + + if (response.statusCode != 200) { + if (response.statusCode == 400) { + final responseJSON = json.decode(response.body) as Map; + final error = responseJSON['description'] as String; + + throw TradeNotFoundException(id, + provider: description, description: error); + } + + throw TradeNotFoundException(id, provider: description); + } + + final responseJSON = json.decode(response.body) as Map; + final fromCurrency = responseJSON['input']['asset'] as String; + final from = CryptoCurrency.fromString(fromCurrency.toLowerCase()); + final toCurrency = responseJSON['output'][0]['asset'] as String; + final to = CryptoCurrency.fromString(toCurrency.toLowerCase()); + final inputAddress = responseJSON['input']['deposit_address'] as String; + final status = responseJSON['state'] as String; + final state = TradeState.deserialize(raw: status.toLowerCase()); + + String amount = ""; + for (final trade in trades.values) { + if (trade.id == id) { + amount = trade.amount; + break; + } + } + + return Trade( + id: id, + from: from, + to: to, + provider: description, + inputAddress: inputAddress, + amount: amount, + state: state); + } + + @override + Future calculateAmount( + {CryptoCurrency from, CryptoCurrency to, double amount}) async { + final url = apiUri + _ratesURISuffix; + final response = await get(url); + final responseJSON = json.decode(response.body) as Map; + final rate = responseJSON['data'][from.toString()][to.toString()] as String; + + try { + final estimatedAmount = double.parse(rate) * amount; + return estimatedAmount; + } catch (e) { + return 0.0; + } + } +} diff --git a/lib/src/domain/exchange/morphtoken/morphtoken_request.dart b/lib/exchange/morphtoken/morphtoken_request.dart similarity index 73% rename from lib/src/domain/exchange/morphtoken/morphtoken_request.dart rename to lib/exchange/morphtoken/morphtoken_request.dart index f034372d9..d92a643e8 100644 --- a/lib/src/domain/exchange/morphtoken/morphtoken_request.dart +++ b/lib/exchange/morphtoken/morphtoken_request.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/trade_request.dart'; class MorphTokenRequest extends TradeRequest { MorphTokenRequest( diff --git a/lib/src/domain/exchange/trade.dart b/lib/exchange/trade.dart similarity index 88% rename from lib/src/domain/exchange/trade.dart rename to lib/exchange/trade.dart index 83e09a4b4..c7110f55f 100644 --- a/lib/src/domain/exchange/trade.dart +++ b/lib/exchange/trade.dart @@ -1,8 +1,8 @@ import 'package:hive/hive.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_state.dart'; -import 'package:cake_wallet/src/domain/common/format_amount.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/exchange/trade_state.dart'; +import 'package:cake_wallet/entities/format_amount.dart'; part 'trade.g.dart'; @@ -28,6 +28,7 @@ class Trade extends HiveObject { stateRaw = state?.raw; static const boxName = 'Trades'; + static const boxKey = 'tradesBoxKey'; @HiveField(0) String id; diff --git a/lib/src/domain/exchange/trade_not_created_exeption.dart b/lib/exchange/trade_not_created_exeption.dart similarity index 84% rename from lib/src/domain/exchange/trade_not_created_exeption.dart rename to lib/exchange/trade_not_created_exeption.dart index 2fc037a06..181d05397 100644 --- a/lib/src/domain/exchange/trade_not_created_exeption.dart +++ b/lib/exchange/trade_not_created_exeption.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/generated/i18n.dart'; class TradeNotCreatedException implements Exception { diff --git a/lib/src/domain/exchange/trade_not_found_exeption.dart b/lib/exchange/trade_not_found_exeption.dart similarity index 85% rename from lib/src/domain/exchange/trade_not_found_exeption.dart rename to lib/exchange/trade_not_found_exeption.dart index ad789a215..0d0dbd944 100644 --- a/lib/src/domain/exchange/trade_not_found_exeption.dart +++ b/lib/exchange/trade_not_found_exeption.dart @@ -1,4 +1,4 @@ -import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/generated/i18n.dart'; class TradeNotFoundException implements Exception { diff --git a/lib/src/domain/exchange/trade_request.dart b/lib/exchange/trade_request.dart similarity index 100% rename from lib/src/domain/exchange/trade_request.dart rename to lib/exchange/trade_request.dart diff --git a/lib/src/domain/exchange/trade_state.dart b/lib/exchange/trade_state.dart similarity index 97% rename from lib/src/domain/exchange/trade_state.dart rename to lib/exchange/trade_state.dart index 0a94cf4c0..7095626b9 100644 --- a/lib/src/domain/exchange/trade_state.dart +++ b/lib/exchange/trade_state.dart @@ -1,5 +1,5 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/common/enumerable_item.dart'; +import 'package:cake_wallet/entities/enumerable_item.dart'; class TradeState extends EnumerableItem with Serializable { const TradeState({@required String raw, @required String title}) diff --git a/lib/src/domain/exchange/xmrto/xmrto_exchange_provider.dart b/lib/exchange/xmrto/xmrto_exchange_provider.dart similarity index 88% rename from lib/src/domain/exchange/xmrto/xmrto_exchange_provider.dart rename to lib/exchange/xmrto/xmrto_exchange_provider.dart index d65f23db3..ca1253310 100644 --- a/lib/src/domain/exchange/xmrto/xmrto_exchange_provider.dart +++ b/lib/exchange/xmrto/xmrto_exchange_provider.dart @@ -1,17 +1,17 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart'; -import 'package:cake_wallet/src/domain/exchange/limits.dart'; -import 'package:cake_wallet/src/domain/exchange/trade.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_state.dart'; -import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_trade_request.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_not_found_exeption.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/exchange_pair.dart'; +import 'package:cake_wallet/exchange/exchange_provider.dart'; +import 'package:cake_wallet/exchange/limits.dart'; +import 'package:cake_wallet/exchange/trade.dart'; +import 'package:cake_wallet/exchange/trade_request.dart'; +import 'package:cake_wallet/exchange/trade_state.dart'; +import 'package:cake_wallet/exchange/xmrto/xmrto_trade_request.dart'; +import 'package:cake_wallet/exchange/trade_not_created_exeption.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/exchange/trade_not_found_exeption.dart'; class XMRTOExchangeProvider extends ExchangeProvider { XMRTOExchangeProvider() diff --git a/lib/src/domain/exchange/xmrto/xmrto_trade_request.dart b/lib/exchange/xmrto/xmrto_trade_request.dart similarity index 74% rename from lib/src/domain/exchange/xmrto/xmrto_trade_request.dart rename to lib/exchange/xmrto/xmrto_trade_request.dart index 204798698..a456b572a 100644 --- a/lib/src/domain/exchange/xmrto/xmrto_trade_request.dart +++ b/lib/exchange/xmrto/xmrto_trade_request.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; -import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; -import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/trade_request.dart'; class XMRTOTradeRequest extends TradeRequest { XMRTOTradeRequest( diff --git a/lib/main.dart b/lib/main.dart index 19e4fe1b8..6370bf55d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +import 'package:cake_wallet/entities/transaction_description.dart'; +import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/reactions/bootstrap.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/store/app_store.dart'; @@ -21,38 +23,41 @@ import 'package:cw_monero/wallet.dart' as monero_wallet; import 'package:cake_wallet/router.dart'; import 'theme_changer.dart'; import 'themes.dart'; -import 'package:cake_wallet/src/domain/common/get_encryption_key.dart'; -import 'package:cake_wallet/src/domain/common/contact.dart'; -import 'package:cake_wallet/src/domain/common/node.dart'; -import 'package:cake_wallet/src/domain/common/wallet_info.dart'; -import 'package:cake_wallet/src/domain/exchange/trade.dart'; -import 'package:cake_wallet/src/domain/monero/transaction_description.dart'; +import 'package:cake_wallet/entities/get_encryption_key.dart'; +import 'package:cake_wallet/entities/contact.dart'; +import 'package:cake_wallet/entities/node.dart'; +import 'package:cake_wallet/entities/wallet_info.dart'; +import 'package:cake_wallet/exchange/trade.dart'; + +// import 'package:cake_wallet/monero/transaction_description.dart'; import 'package:cake_wallet/src/reactions/set_reactions.dart'; -import 'package:cake_wallet/src/stores/login/login_store.dart'; -import 'package:cake_wallet/src/stores/balance/balance_store.dart'; -import 'package:cake_wallet/src/stores/sync/sync_store.dart'; -import 'package:cake_wallet/src/stores/wallet/wallet_store.dart'; -import 'package:cake_wallet/src/stores/send_template/send_template_store.dart'; -import 'package:cake_wallet/src/stores/exchange_template/exchange_template_store.dart'; + +// import 'package:cake_wallet/src/stores/login/login_store.dart'; +// import 'package:cake_wallet/src/stores/balance/balance_store.dart'; +// import 'package:cake_wallet/src/stores/sync/sync_store.dart'; +// import 'package:cake_wallet/src/stores/wallet/wallet_store.dart'; +// import 'package:cake_wallet/src/stores/send_template/send_template_store.dart'; +// import 'package:cake_wallet/src/stores/exchange_template/exchange_template_store.dart'; import 'package:cake_wallet/src/screens/root/root.dart'; //import 'package:cake_wallet/src/stores/authentication/authentication_store.dart'; -import 'package:cake_wallet/src/stores/settings/settings_store.dart'; -import 'package:cake_wallet/src/stores/price/price_store.dart'; -import 'package:cake_wallet/src/domain/services/user_service.dart'; -import 'package:cake_wallet/src/domain/services/wallet_list_service.dart'; -import 'package:cake_wallet/src/domain/common/balance_display_mode.dart'; -import 'package:cake_wallet/src/domain/common/default_settings_migration.dart'; -import 'package:cake_wallet/src/domain/common/fiat_currency.dart'; -import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; -import 'package:cake_wallet/src/domain/common/wallet_type.dart'; -import 'package:cake_wallet/src/domain/common/template.dart'; -import 'package:cake_wallet/src/domain/exchange/exchange_template.dart'; -import 'package:cake_wallet/src/domain/services/wallet_service.dart'; -import 'package:cake_wallet/src/domain/services/fiat_convertation_service.dart'; +// import 'package:cake_wallet/src/stores/settings/settings_store.dart'; +// import 'package:cake_wallet/src/stores/price/price_store.dart'; +// import 'package:cake_wallet/src/domain/services/user_service.dart'; +// import 'package:cake_wallet/src/domain/services/wallet_list_service.dart'; +import 'package:cake_wallet/entities/balance_display_mode.dart'; +import 'package:cake_wallet/entities/default_settings_migration.dart'; +import 'package:cake_wallet/entities/fiat_currency.dart'; +import 'package:cake_wallet/entities/transaction_priority.dart'; +import 'package:cake_wallet/entities/wallet_type.dart'; +import 'package:cake_wallet/entities/template.dart'; +import 'package:cake_wallet/exchange/exchange_template.dart'; + +// import 'package:cake_wallet/src/domain/services/wallet_service.dart'; +// import 'package:cake_wallet/src/domain/services/fiat_convertation_service.dart'; import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/src/domain/common/language.dart'; -import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart'; +import 'package:cake_wallet/entities/language.dart'; +// import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart'; bool isThemeChangerRegistered = false; @@ -74,12 +79,9 @@ void main() async { final secureStorage = FlutterSecureStorage(); final transactionDescriptionsBoxKey = await getEncryptionKey( - secureStorage: secureStorage, - forKey: 'transactionDescriptionsBoxKey'); // FIXME: Unnamed constant + secureStorage: secureStorage, forKey: TransactionDescription.boxKey); final tradesBoxKey = await getEncryptionKey( - secureStorage: secureStorage, - forKey: 'tradesBoxKey'); // FIXME: Unnamed constant - + secureStorage: secureStorage, forKey: Trade.boxKey); final contacts = await Hive.openBox(Contact.boxName); final nodes = await Hive.openBox(Node.boxName); final transactionDescriptions = await Hive.openBox( @@ -93,35 +95,35 @@ void main() async { await Hive.openBox(ExchangeTemplate.boxName); final sharedPreferences = await SharedPreferences.getInstance(); - final walletService = WalletService(); - final fiatConvertationService = FiatConvertationService(); - final walletListService = WalletListService( - secureStorage: secureStorage, - walletInfoSource: walletInfoSource, - walletService: walletService, - sharedPreferences: sharedPreferences); - final userService = UserService( - sharedPreferences: sharedPreferences, secureStorage: secureStorage); - final settingsStore = await SettingsStoreBase.load( - nodes: nodes, - sharedPreferences: sharedPreferences, - initialFiatCurrency: FiatCurrency.usd, - initialTransactionPriority: TransactionPriority.slow, - initialBalanceDisplayMode: BalanceDisplayMode.availableBalance); - final priceStore = PriceStore(); - final walletStore = - WalletStore(walletService: walletService, settingsStore: settingsStore); - final syncStore = SyncStore(walletService: walletService); - final balanceStore = BalanceStore( - walletService: walletService, - settingsStore: settingsStore, - priceStore: priceStore); - final loginStore = LoginStore( - sharedPreferences: sharedPreferences, walletsService: walletListService); - final seedLanguageStore = SeedLanguageStore(); - final sendTemplateStore = SendTemplateStore(templateSource: templates); - final exchangeTemplateStore = - ExchangeTemplateStore(templateSource: exchangeTemplates); + // final walletService = WalletService(); + // final fiatConvertationService = FiatConvertationService(); + // final walletListService = WalletListService( + // secureStorage: secureStorage, + // walletInfoSource: walletInfoSource, + // walletService: walletService, + // sharedPreferences: sharedPreferences); + // final userService = UserService( + // sharedPreferences: sharedPreferences, secureStorage: secureStorage); + // final settingsStore = await SettingsStoreBase.load( + // nodes: nodes, + // sharedPreferences: sharedPreferences, + // initialFiatCurrency: FiatCurrency.usd, + // initialTransactionPriority: TransactionPriority.slow, + // initialBalanceDisplayMode: BalanceDisplayMode.availableBalance); + // final priceStore = PriceStore(); + // final walletStore = + // WalletStore(walletService: walletService, settingsStore: settingsStore); + // final syncStore = SyncStore(walletService: walletService); + // final balanceStore = BalanceStore( + // walletService: walletService, + // settingsStore: settingsStore, + // priceStore: priceStore); + // final loginStore = LoginStore( + // sharedPreferences: sharedPreferences, walletsService: walletListService); + // final seedLanguageStore = SeedLanguageStore(); + // final sendTemplateStore = SendTemplateStore(templateSource: templates); + // final exchangeTemplateStore = + // ExchangeTemplateStore(templateSource: exchangeTemplates); final walletCreationService = WalletCreationService(); final authService = AuthService(); @@ -132,42 +134,21 @@ void main() async { walletInfoSource: walletInfoSource, contactSource: contacts, tradesSource: trades, - fiatConvertationService: fiatConvertationService, + // fiatConvertationService: fiatConvertationService, templates: templates, exchangeTemplates: exchangeTemplates, initialMigrationVersion: 4); - setReactions( - settingsStore: settingsStore, - priceStore: priceStore, - syncStore: syncStore, - walletStore: walletStore, - walletService: walletService, -// authenticationStore: authenticationStore, - loginStore: loginStore); +// setReactions( +// settingsStore: settingsStore, +// priceStore: priceStore, +// syncStore: syncStore, +// walletStore: walletStore, +// walletService: walletService, +// // authenticationStore: authenticationStore, +// loginStore: loginStore); - runApp(MultiProvider(providers: [ - Provider(create: (_) => sharedPreferences), - Provider(create: (_) => walletService), - Provider(create: (_) => walletListService), - Provider(create: (_) => userService), - Provider(create: (_) => settingsStore), - Provider(create: (_) => priceStore), - Provider(create: (_) => walletStore), - Provider(create: (_) => syncStore), - Provider(create: (_) => balanceStore), -// Provider(create: (_) => authenticationStore), - Provider(create: (_) => contacts), - Provider(create: (_) => nodes), - Provider(create: (_) => transactionDescriptions), - Provider(create: (_) => trades), - Provider(create: (_) => seedLanguageStore), - Provider(create: (_) => sendTemplateStore), - Provider(create: (_) => exchangeTemplateStore), -// Provider(create: (_) => appStore), - Provider(create: (_) => walletCreationService), - Provider(create: (_) => authService) - ], child: CakeWalletApp())); + runApp(CakeWalletApp()); } Future initialSetup( @@ -176,7 +157,7 @@ Future initialSetup( @required Box walletInfoSource, @required Box contactSource, @required Box tradesSource, - @required FiatConvertationService fiatConvertationService, + // @required FiatConvertationService fiatConvertationService, @required Box