This commit is contained in:
M 2020-09-21 14:50:26 +03:00
parent 5e1132a299
commit e4ebfc94b2
273 changed files with 2472 additions and 7285 deletions

View file

@ -1 +1 @@
a2dce69f54a78f5b00e19850e4b2d402 bc336703210c48e30d7216fac3fe1c0f

View file

@ -47,6 +47,8 @@ PODS:
- Flutter - Flutter
- path_provider_macos (0.0.1): - path_provider_macos (0.0.1):
- Flutter - Flutter
- path_provider_windows (0.0.1):
- Flutter
- Reachability (3.2) - Reachability (3.2)
- share (0.0.1): - share (0.0.1):
- Flutter - Flutter
@ -67,6 +69,8 @@ PODS:
- Flutter - Flutter
- url_launcher_web (0.0.1): - url_launcher_web (0.0.1):
- Flutter - Flutter
- url_launcher_windows (0.0.1):
- Flutter
DEPENDENCIES: DEPENDENCIES:
- barcode_scan (from `.symlinks/plugins/barcode_scan/ios`) - barcode_scan (from `.symlinks/plugins/barcode_scan/ios`)
@ -84,6 +88,7 @@ DEPENDENCIES:
- path_provider (from `.symlinks/plugins/path_provider/ios`) - path_provider (from `.symlinks/plugins/path_provider/ios`)
- path_provider_linux (from `.symlinks/plugins/path_provider_linux/ios`) - path_provider_linux (from `.symlinks/plugins/path_provider_linux/ios`)
- path_provider_macos (from `.symlinks/plugins/path_provider_macos/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`) - share (from `.symlinks/plugins/share/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- shared_preferences_linux (from `.symlinks/plugins/shared_preferences_linux/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_linux (from `.symlinks/plugins/url_launcher_linux/ios`)
- url_launcher_macos (from `.symlinks/plugins/url_launcher_macos/ios`) - url_launcher_macos (from `.symlinks/plugins/url_launcher_macos/ios`)
- url_launcher_web (from `.symlinks/plugins/url_launcher_web/ios`) - url_launcher_web (from `.symlinks/plugins/url_launcher_web/ios`)
- url_launcher_windows (from `.symlinks/plugins/url_launcher_windows/ios`)
SPEC REPOS: SPEC REPOS:
trunk: trunk:
@ -131,6 +137,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/path_provider_linux/ios" :path: ".symlinks/plugins/path_provider_linux/ios"
path_provider_macos: path_provider_macos:
:path: ".symlinks/plugins/path_provider_macos/ios" :path: ".symlinks/plugins/path_provider_macos/ios"
path_provider_windows:
:path: ".symlinks/plugins/path_provider_windows/ios"
share: share:
:path: ".symlinks/plugins/share/ios" :path: ".symlinks/plugins/share/ios"
shared_preferences: shared_preferences:
@ -149,6 +157,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/url_launcher_macos/ios" :path: ".symlinks/plugins/url_launcher_macos/ios"
url_launcher_web: url_launcher_web:
:path: ".symlinks/plugins/url_launcher_web/ios" :path: ".symlinks/plugins/url_launcher_web/ios"
url_launcher_windows:
:path: ".symlinks/plugins/url_launcher_windows/ios"
SPEC CHECKSUMS: SPEC CHECKSUMS:
barcode_scan: a5c27959edfafaa0c771905bad0b29d6d39e4479 barcode_scan: a5c27959edfafaa0c771905bad0b29d6d39e4479
@ -167,6 +177,7 @@ SPEC CHECKSUMS:
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
path_provider_linux: 4d630dc393e1f20364f3e3b4a2ff41d9674a84e4 path_provider_linux: 4d630dc393e1f20364f3e3b4a2ff41d9674a84e4
path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0 path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0
path_provider_windows: a2b81600c677ac1959367280991971cb9a1edb3b
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
share: 0b2c3e82132f5888bccca3351c504d0003b3b410 share: 0b2c3e82132f5888bccca3351c504d0003b3b410
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
@ -178,6 +189,7 @@ SPEC CHECKSUMS:
url_launcher_linux: ac237cb7a8058736e4aae38bdbcc748a4b394cc0 url_launcher_linux: ac237cb7a8058736e4aae38bdbcc748a4b394cc0
url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313 url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313
url_launcher_web: e5527357f037c87560776e36436bf2b0288b965c url_launcher_web: e5527357f037c87560776e36436bf2b0288b965c
url_launcher_windows: 683d7c283894db8d1914d3ab2223b20cc1ad95d5
PODFILE CHECKSUM: c34e2287a9ccaa606aeceab922830efb9a6ff69a PODFILE CHECKSUM: c34e2287a9ccaa606aeceab922830efb9a6ff69a

View file

@ -1,5 +1,5 @@
import 'package:intl/intl.dart'; 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 bitcoinAmountLength = 8;
const bitcoinAmountDivider = 100000000; const bitcoinAmountDivider = 100000000;
@ -11,3 +11,6 @@ String bitcoinAmountToString({int amount}) =>
bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider)); bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider));
double bitcoinAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider); double bitcoinAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider);
int doubleToBitcoinAmount(double amount) =>
(amount * bitcoinAmountDivider).toInt();

View file

@ -2,7 +2,7 @@ import 'dart:convert';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.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 { class BitcoinBalance extends Balance {
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed}) : super(); const BitcoinBalance({@required this.confirmed, @required this.unconfirmed}) : super();

View file

@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; import 'package:cake_wallet/entities/transaction_priority.dart';
class BitcoinTransactionCredentials { class BitcoinTransactionCredentials {
BitcoinTransactionCredentials(this.address, this.amount, this.priority); BitcoinTransactionCredentials(this.address, this.amount, this.priority);

View file

@ -58,16 +58,7 @@ abstract class BitcoinTransactionHistoryBase
final histories = final histories =
wallet.scriptHashes.map((scriptHash) => eclient.getHistory(scriptHash)); wallet.scriptHashes.map((scriptHash) => eclient.getHistory(scriptHash));
final _historiesWithDetails = await Future.wait(histories) final _historiesWithDetails = await Future.wait(histories)
.then((histories) => histories .then((histories) => histories.expand((i) => i).toList())
// .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.map((tx) => fetchTransactionInfo( .then((histories) => histories.map((tx) => fetchTransactionInfo(
hash: tx['tx_hash'] as String, height: tx['height'] as int))); hash: tx['tx_hash'] as String, height: tx['height'] as int)));
final historiesWithDetails = await Future.wait(_historiesWithDetails); final historiesWithDetails = await Future.wait(_historiesWithDetails);

View file

@ -1,22 +1,22 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; 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: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/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart'; import 'package:cake_wallet/entities/transaction_direction.dart';
import 'package:cake_wallet/src/domain/common/transaction_direction.dart'; import 'package:cake_wallet/entities/transaction_info.dart';
import 'package:cake_wallet/src/domain/common/transaction_info.dart'; import 'package:cake_wallet/entities/format_amount.dart';
import 'package:cake_wallet/src/domain/common/format_amount.dart';
class BitcoinTransactionInfo extends TransactionInfo { class BitcoinTransactionInfo extends TransactionInfo {
BitcoinTransactionInfo( BitcoinTransactionInfo(
{@required this.id, {@required String id,
@required int height, @required int height,
@required int amount, @required int amount,
@required TransactionDirection direction, @required TransactionDirection direction,
@required bool isPending, @required bool isPending,
@required DateTime date, @required DateTime date,
@required int confirmations}) { @required int confirmations}) {
this.id = id;
this.height = height; this.height = height;
this.amount = amount; this.amount = amount;
this.direction = direction; this.direction = direction;
@ -97,7 +97,6 @@ class BitcoinTransactionInfo extends TransactionInfo {
? DateTime.fromMillisecondsSinceEpoch(timestamp * 1000) ? DateTime.fromMillisecondsSinceEpoch(timestamp * 1000)
: DateTime.now(); : DateTime.now();
// FIXME: Get transaction is pending
return BitcoinTransactionInfo( return BitcoinTransactionInfo(
id: tx.getId(), id: tx.getId(),
height: height, height: height,
@ -119,8 +118,6 @@ class BitcoinTransactionInfo extends TransactionInfo {
confirmations: data['confirmations'] as int); confirmations: data['confirmations'] as int);
} }
final String id;
String _fiatAmount; String _fiatAmount;
@override @override

View file

@ -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/pending_bitcoin_transaction.dart';
import 'package:cake_wallet/bitcoin/script_hash.dart'; import 'package:cake_wallet/bitcoin/script_hash.dart';
import 'package:cake_wallet/bitcoin/utils.dart'; import 'package:cake_wallet/bitcoin/utils.dart';
import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart'; import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart'; import 'package:cake_wallet/entities/sync_status.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/src/domain/common/wallet_info.dart'; import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_history.dart'; import 'package:cake_wallet/bitcoin/bitcoin_transaction_history.dart';
import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart'; import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart';
import 'package:cake_wallet/bitcoin/file.dart'; import 'package:cake_wallet/bitcoin/file.dart';
import 'package:cake_wallet/bitcoin/bitcoin_balance.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'; import 'package:cake_wallet/core/wallet_base.dart';
part 'bitcoin_wallet.g.dart'; part 'bitcoin_wallet.g.dart';
@ -316,6 +316,11 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
bitcoin.ECPair keyPairFor({@required int index}) => bitcoin.ECPair keyPairFor({@required int index}) =>
generateKeyPair(hd: hd, index: index); generateKeyPair(hd: hd, index: index);
@override
Future<void> rescan({int height}) async {
// FIXME: Unimplemented
}
void _subscribeForUpdates() { void _subscribeForUpdates() {
scriptHashes.forEach((sh) async { scriptHashes.forEach((sh) async {
await _scripthashesUpdateSubject[sh]?.close(); await _scripthashesUpdateSubject[sh]?.close();

View file

@ -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/bitcoin/bitcoin_wallet_creation_credentials.dart';
import 'package:cake_wallet/core/wallet_service.dart'; import 'package:cake_wallet/core/wallet_service.dart';
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart'; import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
import 'package:cake_wallet/src/domain/common/pathForWallet.dart'; import 'package:cake_wallet/entities/pathForWallet.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
class BitcoinWalletService extends WalletService< class BitcoinWalletService extends WalletService<
BitcoinNewWalletCredentials, BitcoinNewWalletCredentials,

View file

@ -40,6 +40,7 @@ class ElectrumClient {
_tasks = {}; _tasks = {};
static const connectionTimeout = Duration(seconds: 5); static const connectionTimeout = Duration(seconds: 5);
static const aliveTimerDuration = Duration(seconds: 2);
bool get isConnected => _isConnected; bool get isConnected => _isConnected;
Socket socket; Socket socket;
@ -97,8 +98,7 @@ class ElectrumClient {
void keepAlive() { void keepAlive() {
_aliveTimer?.cancel(); _aliveTimer?.cancel();
// FIXME: Unnamed constant. _aliveTimer = Timer.periodic(aliveTimerDuration, (_) async => ping());
_aliveTimer = Timer.periodic(Duration(seconds: 2), (_) async => ping());
} }
Future<void> ping() async { Future<void> ping() async {

View file

@ -1,6 +1,6 @@
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart'; import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.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:flutter/foundation.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:cake_wallet/core/pending_transaction.dart'; import 'package:cake_wallet/core/pending_transaction.dart';

View file

@ -1,6 +1,6 @@
import 'package:cake_wallet/core/validator.dart'; import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/generated/i18n.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 { class AddressLabelValidator extends TextValidator {
AddressLabelValidator({WalletType type}) AddressLabelValidator({WalletType type})

View file

@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/core/validator.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 { class AddressValidator extends TextValidator {
AddressValidator({@required CryptoCurrency type}) AddressValidator({@required CryptoCurrency type})

37
lib/core/amount.dart Normal file
View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -1,6 +1,6 @@
import 'package:cake_wallet/core/validator.dart'; import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/generated/i18n.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 { class AmountValidator extends TextValidator {
AmountValidator({WalletType type, bool isAutovalidate = false}) AmountValidator({WalletType type, bool isAutovalidate = false})

View file

@ -1,8 +1,9 @@
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/src/domain/common/secret_store_key.dart'; import 'package:cake_wallet/entities/preferences_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 AuthService with Store { class AuthService with Store {
AuthService({this.secureStorage, this.sharedPreferences}); AuthService({this.secureStorage, this.sharedPreferences});
@ -18,7 +19,8 @@ class AuthService with Store {
Future<bool> canAuthenticate() async { Future<bool> canAuthenticate() async {
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword); final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final walletName = sharedPreferences.getString('current_wallet_name') ?? ''; final walletName =
sharedPreferences.getString(PreferencesKey.currentWalletName) ?? '';
var password = ''; var password = '';
try { try {

View file

@ -1,6 +1,6 @@
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:cake_wallet/store/contact_list_store.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 { class ContactService {
ContactService(this.contactSource, this.contactListStore) { ContactService(this.contactSource, this.contactListStore) {

View file

@ -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;
}

View file

@ -1,13 +1,16 @@
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/currency_formatter.dart';
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
import 'package:cake_wallet/src/domain/common/currency_formatter.dart';
const fiatApiAuthority = 'fiat-api.cakewallet.com'; const fiatApiAuthority = 'fiat-api.cakewallet.com';
const fiatApiPath = '/v1/rates'; const fiatApiPath = '/v1/rates';
Future<double> fetchPriceFor({CryptoCurrency crypto, FiatCurrency fiat}) async { Future<double> _fetchPrice(Map<String, dynamic> args) async {
final crypto = args['crypto'] as CryptoCurrency;
final fiat = args['fiat'] as FiatCurrency;
double price = 0.0; double price = 0.0;
try { try {
@ -35,3 +38,12 @@ Future<double> fetchPriceFor({CryptoCurrency crypto, FiatCurrency fiat}) async {
return price; return price;
} }
} }
Future<double> _fetchPriceAsync(
CryptoCurrency crypto, FiatCurrency fiat) async =>
compute(_fetchPrice, {'fiat': fiat, 'crypto': crypto});
class FiatConversionService {
static Future<double> fetchPrice(CryptoCurrency crypto, FiatCurrency fiat) async =>
await _fetchPriceAsync(crypto, fiat);
}

View file

@ -1,6 +1,6 @@
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
import 'package:cake_wallet/bitcoin/key.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) { String generateWalletPassword(WalletType type) {
switch (type) { switch (type) {

View file

@ -1,6 +1,6 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:cake_wallet/src/domain/common/secret_store_key.dart'; import 'package:cake_wallet/entities/secret_store_key.dart';
import 'package:cake_wallet/src/domain/common/encrypt.dart'; import 'package:cake_wallet/entities/encrypt.dart';
class KeyService { class KeyService {
KeyService(this._secureStorage); KeyService(this._secureStorage);

View file

@ -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 bitcoinMnemonicLength = 12;
const moneroMnemonicLength = 25; const moneroMnemonicLength = 25;

View file

@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/core/validator.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 { class MoneroLabelValidator extends TextValidator {
MoneroLabelValidator({@required CryptoCurrency type}) MoneroLabelValidator({@required CryptoCurrency type})

View file

@ -1,15 +1,16 @@
import 'package:bip39/src/wordlists/english.dart' as bitcoin_english; import 'package:bip39/src/wordlists/english.dart' as bitcoin_english;
import 'package:cake_wallet/core/validator.dart'; import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/src/domain/common/mnemonic_item.dart'; import 'package:cake_wallet/entities/mnemonic_item.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/chinese_simplified.dart'; import 'package:cake_wallet/monero/mnemonics/chinese_simplified.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/dutch.dart'; import 'package:cake_wallet/monero/mnemonics/dutch.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/english.dart'; import 'package:cake_wallet/monero/mnemonics/english.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/german.dart'; import 'package:cake_wallet/monero/mnemonics/german.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/japanese.dart'; import 'package:cake_wallet/monero/mnemonics/japanese.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/portuguese.dart'; import 'package:cake_wallet/monero/mnemonics/portuguese.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/russian.dart'; import 'package:cake_wallet/monero/mnemonics/russian.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/spanish.dart'; import 'package:cake_wallet/monero/mnemonics/spanish.dart';
import 'package:cake_wallet/utils/language_list.dart';
class SeedValidator extends Validator<MnemonicItem> { class SeedValidator extends Validator<MnemonicItem> {
SeedValidator({this.type, this.language}) SeedValidator({this.type, this.language})
@ -31,31 +32,29 @@ class SeedValidator extends Validator<MnemonicItem> {
} }
static List<String> getMoneroWordList(String language) { static List<String> getMoneroWordList(String language) {
// FIXME: Unnamed constants; Need to be sure that string are in same case;
switch (language) { switch (language) {
case 'English': case LanguageList.english:
return EnglishMnemonics.words; return EnglishMnemonics.words;
break; break;
case 'Chinese (simplified)': case LanguageList.chineseSimplified:
return ChineseSimplifiedMnemonics.words; return ChineseSimplifiedMnemonics.words;
break; break;
case 'Dutch': case LanguageList.dutch:
return DutchMnemonics.words; return DutchMnemonics.words;
break; break;
case 'German': case LanguageList.german:
return GermanMnemonics.words; return GermanMnemonics.words;
break; break;
case 'Japanese': case LanguageList.japanese:
return JapaneseMnemonics.words; return JapaneseMnemonics.words;
break; break;
case 'Portuguese': case LanguageList.portuguese:
return PortugueseMnemonics.words; return PortugueseMnemonics.words;
break; break;
case 'Russian': case LanguageList.russian:
return RussianMnemonics.words; return RussianMnemonics.words;
break; break;
case 'Spanish': case LanguageList.spanish:
return SpanishMnemonics.words; return SpanishMnemonics.words;
break; break;
default: default:
@ -64,7 +63,7 @@ class SeedValidator extends Validator<MnemonicItem> {
} }
static List<String> getBitcoinWordList(String language) { static List<String> getBitcoinWordList(String language) {
assert(language.toLowerCase() == 'english'); assert(language.toLowerCase() == LanguageList.english.toLowerCase());
return bitcoin_english.WORDLIST; return bitcoin_english.WORDLIST;
} }

View file

@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.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<TransactionType extends TransactionInfo> { abstract class TransactionHistoryBase<TransactionType extends TransactionInfo> {
TransactionHistoryBase() : _isUpdating = false; TransactionHistoryBase() : _isUpdating = false;

View file

@ -1,24 +1,13 @@
import 'package:flutter/foundation.dart'; 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/pending_transaction.dart';
import 'package:cake_wallet/core/transaction_history.dart'; import 'package:cake_wallet/core/transaction_history.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; import 'package:cake_wallet/entities/currency_for_wallet_type.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/node.dart'; import 'package:cake_wallet/entities/sync_status.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';
// FIXME: Move me.
CryptoCurrency currencyForWalletType(WalletType type) {
switch (type) {
case WalletType.bitcoin:
return CryptoCurrency.btc;
case WalletType.monero:
return CryptoCurrency.xmr;
default:
return null;
}
}
abstract class WalletBase<BalaceType> { abstract class WalletBase<BalaceType> {
WalletBase(this.walletInfo); WalletBase(this.walletInfo);
@ -61,4 +50,6 @@ abstract class WalletBase<BalaceType> {
double calculateEstimatedFee(TransactionPriority priority); double calculateEstimatedFee(TransactionPriority priority);
Future<void> save(); Future<void> save();
Future<void> rescan({int height});
} }

View file

@ -3,18 +3,15 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/core/key_service.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/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/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/core/wallet_service.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
class WalletCreationService { class WalletCreationService {
WalletCreationService( WalletCreationService(
{WalletType initialType, {WalletType initialType,
this.appStore,
this.secureStorage, this.secureStorage,
this.keyService, this.keyService,
this.sharedPreferences}) this.sharedPreferences})
@ -25,7 +22,6 @@ class WalletCreationService {
} }
WalletType type; WalletType type;
final AppStore appStore;
final FlutterSecureStorage secureStorage; final FlutterSecureStorage secureStorage;
final SharedPreferences sharedPreferences; final SharedPreferences sharedPreferences;
final KeyService keyService; final KeyService keyService;
@ -36,33 +32,27 @@ class WalletCreationService {
_service = getIt.get<WalletService>(param1: type); _service = getIt.get<WalletService>(param1: type);
} }
Future<void> create(WalletCredentials credentials) async { Future<WalletBase> create(WalletCredentials credentials) async {
final password = generateWalletPassword(type); final password = generateWalletPassword(type);
credentials.password = password; credentials.password = password;
await keyService.saveWalletPassword( await keyService.saveWalletPassword(
password: password, walletName: credentials.name); password: password, walletName: credentials.name);
final wallet = await _service.create(credentials); return await _service.create(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
} }
Future<void> restoreFromKeys(WalletCredentials credentials) async { Future<WalletBase> restoreFromKeys(WalletCredentials credentials) async {
final password = generateWalletPassword(type); final password = generateWalletPassword(type);
credentials.password = password; credentials.password = password;
await keyService.saveWalletPassword( await keyService.saveWalletPassword(
password: password, walletName: credentials.name); password: password, walletName: credentials.name);
final wallet = await _service.restoreFromKeys(credentials); return await _service.restoreFromKeys(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
} }
Future<void> restoreFromSeed(WalletCredentials credentials) async { Future<WalletBase> restoreFromSeed(WalletCredentials credentials) async {
final password = generateWalletPassword(type); final password = generateWalletPassword(type);
credentials.password = password; credentials.password = password;
await keyService.saveWalletPassword( await keyService.saveWalletPassword(
password: password, walletName: credentials.name); password: password, walletName: credentials.name);
final wallet = await _service.restoreFromSeed(credentials); return await _service.restoreFromSeed(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
} }
} }

View file

@ -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 { abstract class WalletCredentials {
WalletCredentials({this.name, this.password, this.height}); WalletCredentials({this.name, this.password, this.height});

View file

@ -1,10 +1,12 @@
import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
import 'package:cake_wallet/core/contact_service.dart'; import 'package:cake_wallet/core/contact_service.dart';
import 'package:cake_wallet/core/wallet_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/monero/monero_wallet_service.dart';
import 'package:cake_wallet/src/domain/common/contact.dart'; import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/src/domain/common/node.dart'; import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/exchange/trade.dart';
// import 'package:cake_wallet/src/domain/services/wallet_service.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_list_page.dart';
import 'package:cake_wallet/src/screens/contact/contact_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/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/node_create_or_edit_page.dart';
import 'package:cake_wallet/src/screens/nodes/nodes_list_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/seed/wallet_seed_page.dart';
import 'package:cake_wallet/src/screens/send/send_template_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/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/wallet_keys/wallet_keys_page.dart';
import 'package:cake_wallet/src/screens/exchange/exchange_page.dart'; import 'package:cake_wallet/src/screens/exchange/exchange_page.dart';
import 'package:cake_wallet/src/screens/exchange/exchange_template_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/auth_service.dart';
import 'package:cake_wallet/core/key_service.dart'; import 'package:cake_wallet/core/key_service.dart';
import 'package:cake_wallet/monero/monero_wallet.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_list_page.dart';
import 'package:cake_wallet/src/screens/monero_accounts/monero_account_edit_or_create_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'; 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/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_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/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/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/auth_view_model.dart';
import 'package:cake_wallet/view_model/dashboard/dashboard_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/wallet_seed_view_model.dart';
import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart'; import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:mobx/mobx.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/view_model/wallet_restoration_from_keys_vm.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart'; import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cake_wallet/store/app_store.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/view_model/wallet_new_vm.dart';
import 'package:cake_wallet/store/authentication_store.dart'; import 'package:cake_wallet/store/authentication_store.dart';
import 'package:cake_wallet/store/dashboard/trades_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/trade_filter_store.dart';
import 'package:cake_wallet/store/dashboard/transaction_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/send_template_store.dart';
import 'package:cake_wallet/store/templates/exchange_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/entities/template.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_template.dart'; import 'package:cake_wallet/exchange/exchange_template.dart';
final getIt = GetIt.instance; final getIt = GetIt.instance;
// FIXME: Move me.
Stream<BoxEvent> _onNodesSourceChange;
NodeListStore _nodeListStore;
NodeListStore setupNodeListStore(Box<Node> 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( Future setup(
{Box<WalletInfo> walletInfoSource, {Box<WalletInfo> walletInfoSource,
Box<Node> nodeSource, Box<Node> nodeSource,
@ -122,11 +98,13 @@ Future setup(
final settingsStore = await SettingsStoreBase.load(nodeSource: nodeSource); final settingsStore = await SettingsStoreBase.load(nodeSource: nodeSource);
getIt.registerSingleton<Box<Node>>(nodeSource);
getIt.registerSingleton<FlutterSecureStorage>(FlutterSecureStorage()); getIt.registerSingleton<FlutterSecureStorage>(FlutterSecureStorage());
getIt.registerSingleton(AuthenticationStore()); getIt.registerSingleton(AuthenticationStore());
getIt.registerSingleton<WalletListStore>(WalletListStore()); getIt.registerSingleton<WalletListStore>(WalletListStore());
getIt.registerSingleton(ContactListStore()); getIt.registerSingleton(ContactListStore());
getIt.registerSingleton(setupNodeListStore(nodeSource)); getIt.registerSingleton(NodeListStoreBase.instance);
getIt.registerSingleton<SettingsStore>(settingsStore); getIt.registerSingleton<SettingsStore>(settingsStore);
getIt.registerSingleton<AppStore>(AppStore( getIt.registerSingleton<AppStore>(AppStore(
authenticationStore: getIt.get<AuthenticationStore>(), authenticationStore: getIt.get<AuthenticationStore>(),
@ -140,7 +118,7 @@ Future setup(
tradesSource: tradesSource, settingsStore: getIt.get<SettingsStore>())); tradesSource: tradesSource, settingsStore: getIt.get<SettingsStore>()));
getIt.registerSingleton<TradeFilterStore>(TradeFilterStore()); getIt.registerSingleton<TradeFilterStore>(TradeFilterStore());
getIt.registerSingleton<TransactionFilterStore>(TransactionFilterStore()); getIt.registerSingleton<TransactionFilterStore>(TransactionFilterStore());
getIt.registerSingleton<FiatConvertationStore>(FiatConvertationStore()); getIt.registerSingleton<FiatConversionStore>(FiatConversionStore());
getIt.registerSingleton<SendTemplateStore>( getIt.registerSingleton<SendTemplateStore>(
SendTemplateStore(templateSource: templates)); SendTemplateStore(templateSource: templates));
getIt.registerSingleton<ExchangeTemplateStore>( getIt.registerSingleton<ExchangeTemplateStore>(
@ -152,13 +130,12 @@ Future setup(
getIt.registerFactoryParam<WalletCreationService, WalletType, void>( getIt.registerFactoryParam<WalletCreationService, WalletType, void>(
(type, _) => WalletCreationService( (type, _) => WalletCreationService(
initialType: type, initialType: type,
appStore: getIt.get<AppStore>(),
keyService: getIt.get<KeyService>(), keyService: getIt.get<KeyService>(),
secureStorage: getIt.get<FlutterSecureStorage>(), secureStorage: getIt.get<FlutterSecureStorage>(),
sharedPreferences: getIt.get<SharedPreferences>())); sharedPreferences: getIt.get<SharedPreferences>()));
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) => getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
WalletNewVM( WalletNewVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), walletInfoSource, getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type)); type: type));
@ -168,7 +145,7 @@ Future setup(
final language = args[1] as String; final language = args[1] as String;
final mnemonic = args[2] as String; final mnemonic = args[2] as String;
return WalletRestorationFromSeedVM( return WalletRestorationFromSeedVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), walletInfoSource, getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type, language: language, seed: mnemonic); type: type, language: language, seed: mnemonic);
}); });
@ -178,7 +155,7 @@ Future setup(
final type = args.first as WalletType; final type = args.first as WalletType;
final language = args[1] as String; final language = args[1] as String;
return WalletRestorationFromKeysVM( return WalletRestorationFromKeysVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), walletInfoSource, getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type, language: language); type: type, language: language);
}); });
@ -189,7 +166,7 @@ Future setup(
getIt.registerFactory(() => BalanceViewModel( getIt.registerFactory(() => BalanceViewModel(
wallet: getIt.get<AppStore>().wallet, wallet: getIt.get<AppStore>().wallet,
settingsStore: getIt.get<SettingsStore>(), settingsStore: getIt.get<SettingsStore>(),
fiatConvertationStore: getIt.get<FiatConvertationStore>())); fiatConvertationStore: getIt.get<FiatConversionStore>()));
getIt.registerFactory(() => DashboardViewModel( getIt.registerFactory(() => DashboardViewModel(
balanceViewModel: getIt.get<BalanceViewModel>(), balanceViewModel: getIt.get<BalanceViewModel>(),
@ -203,38 +180,24 @@ Future setup(
sharedPreferences: getIt.get<SharedPreferences>())); sharedPreferences: getIt.get<SharedPreferences>()));
getIt.registerFactory<AuthViewModel>(() => AuthViewModel( getIt.registerFactory<AuthViewModel>(() => AuthViewModel(
authService: getIt.get<AuthService>(), getIt.get<AuthService>(),
sharedPreferences: getIt.get<SharedPreferences>())); getIt.get<SharedPreferences>(),
getIt.get<SettingsStore>(),
BiometricAuth()));
getIt.registerFactory<AuthPage>( getIt.registerFactory<AuthPage>(
() => AuthPage( () => AuthPage(getIt.get<AuthViewModel>(),
allowBiometricalAuthentication: getIt
.get<AppStore>()
.settingsStore
.allowBiometricalAuthentication,
authViewModel: getIt.get<AuthViewModel>(),
onAuthenticationFinished: (isAuthenticated, __) { onAuthenticationFinished: (isAuthenticated, __) {
if (isAuthenticated) { if (isAuthenticated) {
getIt.get<AuthenticationStore>().allowed(); getIt.get<AuthenticationStore>().allowed();
} }
}, }, closable: false),
closable: false),
instanceName: 'login'); instanceName: 'login');
getIt getIt
.registerFactoryParam<AuthPage, void Function(bool, AuthPageState), void>( .registerFactoryParam<AuthPage, void Function(bool, AuthPageState), void>(
(onAuthFinished, _) { (onAuthFinished, _) => AuthPage(getIt.get<AuthViewModel>(),
final allowBiometricalAuthentication = onAuthenticationFinished: onAuthFinished, closable: false));
getIt.get<AppStore>().settingsStore.allowBiometricalAuthentication;
print('allowBiometricalAuthentication $allowBiometricalAuthentication');
return AuthPage(
allowBiometricalAuthentication: allowBiometricalAuthentication,
authViewModel: getIt.get<AuthViewModel>(),
onAuthenticationFinished: onAuthFinished,
closable: false);
});
getIt.registerFactory<DashboardPage>(() => DashboardPage( getIt.registerFactory<DashboardPage>(() => DashboardPage(
walletViewModel: getIt.get<DashboardViewModel>(), walletViewModel: getIt.get<DashboardViewModel>(),
@ -256,7 +219,7 @@ Future setup(
getIt.registerFactory<SendViewModel>(() => SendViewModel( getIt.registerFactory<SendViewModel>(() => SendViewModel(
getIt.get<AppStore>().wallet, getIt.get<AppStore>().wallet,
getIt.get<AppStore>().settingsStore, getIt.get<AppStore>().settingsStore,
getIt.get<FiatConvertationStore>())); getIt.get<FiatConversionStore>()));
getIt.registerFactory( getIt.registerFactory(
() => SendPage(sendViewModel: getIt.get<SendViewModel>())); () => SendPage(sendViewModel: getIt.get<SendViewModel>()));
@ -387,6 +350,19 @@ Future setup(
return null; return null;
} }
}); });
getIt.registerFactory<SetupPinCodeViewModel>(() => SetupPinCodeViewModel(
getIt.get<AuthService>(), getIt.get<SettingsStore>()));
getIt.registerFactoryParam<SetupPinCodePage,
void Function(BuildContext, String), void>(
(onSuccessfulPinSetup, _) => SetupPinCodePage(
getIt.get<SetupPinCodeViewModel>(),
onSuccessfulPinSetup: onSuccessfulPinSetup));
getIt.registerFactory(() => RescanViewModel(getIt.get<AppStore>().wallet));
getIt.registerFactory(() => RescanPage(getIt.get<RescanViewModel>()));
} }
void setupThemeChangerStore(ThemeChanger themeChanger) { void setupThemeChangerStore(ThemeChanger themeChanger) {

View file

@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/generated/i18n.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<int> with Serializable<int> { class BalanceDisplayMode extends EnumerableItem<int> with Serializable<int> {
const BalanceDisplayMode({@required String title, @required int raw}) const BalanceDisplayMode({@required String title, @required int raw})

View file

@ -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}) { double calculateEstimatedFee({TransactionPriority priority}) {
if (priority == TransactionPriority.slow) { if (priority == TransactionPriority.slow) {

View file

@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:hive/hive.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'; import 'package:cake_wallet/utils/mobx.dart';
part 'contact.g.dart'; part 'contact.g.dart';

View file

@ -1,7 +1,7 @@
// import 'package:hive/hive.dart'; // import 'package:hive/hive.dart';
// import 'package:mobx/mobx.dart'; // import 'package:mobx/mobx.dart';
// import 'package:cake_wallet/src/domain/common/contact.dart'; // import 'package:cake_wallet/entities/contact.dart';
// import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; // import 'package:cake_wallet/entities/crypto_currency.dart';
// part 'contact_model.g.dart'; // part 'contact_model.g.dart';

View file

@ -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'; import 'package:hive/hive.dart';
part 'crypto_currency.g.dart'; part 'crypto_currency.g.dart';

View file

@ -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;
}
}

View file

@ -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) { String cryptoToString(CryptoCurrency crypto) {
switch (crypto) { switch (crypto) {

View file

@ -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:flutter/foundation.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/src/domain/common/node.dart'; import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/fiat_currency.dart'; import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/src/domain/common/node_list.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.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( Future defaultSettingsMigration(
{@required int version, {@required int version,
@ -29,13 +29,13 @@ Future defaultSettingsMigration(
switch (version) { switch (version) {
case 1: case 1:
await sharedPreferences.setString( await sharedPreferences.setString(
SettingsStoreBase.currentFiatCurrencyKey, PreferencesKey.currentFiatCurrencyKey,
FiatCurrency.usd.toString()); FiatCurrency.usd.toString());
await sharedPreferences.setInt( await sharedPreferences.setInt(
SettingsStoreBase.currentTransactionPriorityKey, PreferencesKey.currentTransactionPriorityKey,
TransactionPriority.standart.raw); TransactionPriority.standart.raw);
await sharedPreferences.setInt( await sharedPreferences.setInt(
SettingsStoreBase.currentBalanceDisplayModeKey, PreferencesKey.currentBalanceDisplayModeKey,
BalanceDisplayMode.availableBalance.raw); BalanceDisplayMode.availableBalance.raw);
await sharedPreferences.setBool('save_recipient_address', true); await sharedPreferences.setBool('save_recipient_address', true);
await resetToDefault(nodes); await resetToDefault(nodes);

View file

@ -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<String> with Serializable<String> { class FiatCurrency extends EnumerableItem<String> with Serializable<String> {
const FiatCurrency({String symbol}) : super(title: symbol, raw: symbol); const FiatCurrency({String symbol}) : super(title: symbol, raw: symbol);

View file

@ -1,10 +1,10 @@
import 'dart:io'; import 'dart:io';
import 'dart:convert'; import 'dart:convert';
import 'package:cake_wallet/src/domain/common/contact.dart'; import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/wallet_info.dart'; import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/exchange/trade.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';

View file

@ -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<void> loadCurrentWallet() async {
final appStore = getIt.get<AppStore>();
final name = getIt
.get<SharedPreferences>()
.getString(PreferencesKey.currentWalletName);
final typeRaw =
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ??
0;
final type = deserializeFromInt(typeRaw);
final password =
await getIt.get<KeyService>().getWalletPassword(walletName: name);
final _service = getIt.get<WalletService>(param1: type);
final wallet = await _service.openWallet(name, password);
appStore.wallet = wallet;
}

View file

@ -3,8 +3,8 @@ import 'package:flutter/foundation.dart';
import 'dart:convert'; import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/digest_request.dart'; import 'package:cake_wallet/entities/digest_request.dart';
part 'node.g.dart'; part 'node.g.dart';

View file

@ -1,8 +1,8 @@
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import "package:yaml/yaml.dart"; import "package:yaml/yaml.dart";
import 'package:cake_wallet/src/domain/common/node.dart'; import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
Future<List<Node>> loadDefaultNodes() async { Future<List<Node>> loadDefaultNodes() async {
final nodesRaw = await rootBundle.loadString('assets/node_list.yml'); final nodesRaw = await rootBundle.loadString('assets/node_list.yml');

View file

@ -1,5 +1,5 @@
import 'dart:io'; 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:flutter/foundation.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';

View file

@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cw_monero/transaction_history.dart' as transaction_history; import 'package:cw_monero/transaction_history.dart' as transaction_history;
import 'package:cw_monero/structs/pending_transaction.dart'; 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 { class PendingTransaction {
PendingTransaction( PendingTransaction(

View file

@ -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';
}

View file

@ -7,6 +7,7 @@ class TransactionDescription extends HiveObject {
TransactionDescription({this.id, this.recipientAddress}); TransactionDescription({this.id, this.recipientAddress});
static const boxName = 'TransactionDescriptions'; static const boxName = 'TransactionDescriptions';
static const boxKey = 'transactionDescriptionsBoxKey';
@HiveField(0) @HiveField(0)
String id; String id;

View file

@ -1,5 +1,5 @@
import 'package:rxdart/rxdart.dart'; 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 { abstract class TransactionHistory {
Observable<List<TransactionInfo>> transactions; Observable<List<TransactionInfo>> transactions;

View file

@ -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 { abstract class TransactionInfo extends Object {
String id; String id;

View file

@ -1,5 +1,5 @@
import 'package:cake_wallet/generated/i18n.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 TransactionPriority extends EnumerableItem<int> with Serializable<int> { class TransactionPriority extends EnumerableItem<int> with Serializable<int> {
const TransactionPriority({String title, int raw}) const TransactionPriority({String title, int raw})

View file

@ -1,11 +1,11 @@
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart'; import 'package:cake_wallet/entities/sync_status.dart';
import 'package:cake_wallet/src/domain/common/transaction_history.dart'; import 'package:cake_wallet/entities/transaction_history.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/transaction_creation_credentials.dart'; import 'package:cake_wallet/entities/transaction_creation_credentials.dart';
import 'package:cake_wallet/src/domain/common/pending_transaction.dart'; import 'package:cake_wallet/entities/pending_transaction.dart';
import 'package:cake_wallet/src/domain/common/balance.dart'; import 'package:cake_wallet/entities/balance.dart';
import 'package:cake_wallet/src/domain/common/node.dart'; import 'package:cake_wallet/entities/node.dart';
abstract class Wallet { abstract class Wallet {
WalletType getType(); WalletType getType();

View file

@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
class WalletDescription { class WalletDescription {
WalletDescription({this.name, this.type}); WalletDescription({this.name, this.type});

View file

@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:hive/hive.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'; part 'wallet_info.g.dart';

View file

@ -1,5 +1,5 @@
import 'package:cake_wallet/src/domain/common/wallet.dart'; import 'package:cake_wallet/entities/wallet.dart';
import 'package:cake_wallet/src/domain/common/wallet_description.dart'; import 'package:cake_wallet/entities/wallet_description.dart';
abstract class WalletsManager { abstract class WalletsManager {
Future<Wallet> create(String name, String password, String language); Future<Wallet> create(String name, String password, String language);

View file

@ -1,18 +1,18 @@
import 'dart:convert'; 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:flutter/foundation.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets; import 'package:cake_wallet/.secrets.g.dart' as secrets;
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart'; import 'package:cake_wallet/exchange/exchange_pair.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart'; import 'package:cake_wallet/exchange/exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart'; import 'package:cake_wallet/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; import 'package:cake_wallet/exchange/trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/trade_state.dart'; import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/src/domain/exchange/changenow/changenow_request.dart'; import 'package:cake_wallet/exchange/changenow/changenow_request.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart'; import 'package:cake_wallet/exchange/trade_not_created_exeption.dart';
class ChangeNowExchangeProvider extends ExchangeProvider { class ChangeNowExchangeProvider extends ExchangeProvider {
ChangeNowExchangeProvider() ChangeNowExchangeProvider()

View file

@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; import 'package:cake_wallet/exchange/trade_request.dart';
class ChangeNowRequest extends TradeRequest { class ChangeNowRequest extends TradeRequest {
ChangeNowRequest( ChangeNowRequest(

View file

@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
class ExchangePair { class ExchangePair {
ExchangePair({this.from, this.to, this.reverse = true}); ExchangePair({this.from, this.to, this.reverse = true});

View file

@ -1,10 +1,10 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; import 'package:cake_wallet/exchange/trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart'; import 'package:cake_wallet/exchange/exchange_pair.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart'; import 'package:cake_wallet/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/exchange/exchange_provider_description.dart';
abstract class ExchangeProvider { abstract class ExchangeProvider {
ExchangeProvider({this.pairList}); ExchangeProvider({this.pairList});

View file

@ -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<int> class ExchangeProviderDescription extends EnumerableItem<int>
with Serializable<int> { with Serializable<int> {

View file

@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/exchange/trade.dart';
abstract class ExchangeTradeState {} abstract class ExchangeTradeState {}

View file

@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart'; import 'package:cake_wallet/exchange/limits.dart';
abstract class LimitsState {} abstract class LimitsState {}

View file

@ -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<Trade> 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<Limits> 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<String, dynamic>;
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<Trade> 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<String, dynamic>;
final error = responseJSON['description'] as String;
throw TradeNotCreatedException(description, description: error);
}
throw TradeNotCreatedException(description);
}
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
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<Trade> 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<String, dynamic>;
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<String, dynamic>;
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<double> 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<String, dynamic>;
final rate = responseJSON['data'][from.toString()][to.toString()] as String;
try {
final estimatedAmount = double.parse(rate) * amount;
return estimatedAmount;
} catch (e) {
return 0.0;
}
}
}

View file

@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; import 'package:cake_wallet/exchange/trade_request.dart';
class MorphTokenRequest extends TradeRequest { class MorphTokenRequest extends TradeRequest {
MorphTokenRequest( MorphTokenRequest(

View file

@ -1,8 +1,8 @@
import 'package:hive/hive.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/src/domain/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_state.dart'; import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/src/domain/common/format_amount.dart'; import 'package:cake_wallet/entities/format_amount.dart';
part 'trade.g.dart'; part 'trade.g.dart';
@ -28,6 +28,7 @@ class Trade extends HiveObject {
stateRaw = state?.raw; stateRaw = state?.raw;
static const boxName = 'Trades'; static const boxName = 'Trades';
static const boxKey = 'tradesBoxKey';
@HiveField(0) @HiveField(0)
String id; String id;

View file

@ -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'; import 'package:cake_wallet/generated/i18n.dart';
class TradeNotCreatedException implements Exception { class TradeNotCreatedException implements Exception {

View file

@ -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'; import 'package:cake_wallet/generated/i18n.dart';
class TradeNotFoundException implements Exception { class TradeNotFoundException implements Exception {

View file

@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart'; 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<String> with Serializable<String> { class TradeState extends EnumerableItem<String> with Serializable<String> {
const TradeState({@required String raw, @required String title}) const TradeState({@required String raw, @required String title})

View file

@ -1,17 +1,17 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart'; import 'package:cake_wallet/exchange/exchange_pair.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart'; import 'package:cake_wallet/exchange/exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart'; import 'package:cake_wallet/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; import 'package:cake_wallet/exchange/trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/trade_state.dart'; import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_trade_request.dart'; import 'package:cake_wallet/exchange/xmrto/xmrto_trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart'; import 'package:cake_wallet/exchange/trade_not_created_exeption.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_found_exeption.dart'; import 'package:cake_wallet/exchange/trade_not_found_exeption.dart';
class XMRTOExchangeProvider extends ExchangeProvider { class XMRTOExchangeProvider extends ExchangeProvider {
XMRTOExchangeProvider() XMRTOExchangeProvider()

View file

@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart'; import 'package:cake_wallet/exchange/trade_request.dart';
class XMRTOTradeRequest extends TradeRequest { class XMRTOTradeRequest extends TradeRequest {
XMRTOTradeRequest( XMRTOTradeRequest(

View file

@ -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/reactions/bootstrap.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/store/app_store.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 'package:cake_wallet/router.dart';
import 'theme_changer.dart'; import 'theme_changer.dart';
import 'themes.dart'; import 'themes.dart';
import 'package:cake_wallet/src/domain/common/get_encryption_key.dart'; import 'package:cake_wallet/entities/get_encryption_key.dart';
import 'package:cake_wallet/src/domain/common/contact.dart'; import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/src/domain/common/node.dart'; import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/src/domain/common/wallet_info.dart'; import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/src/domain/monero/transaction_description.dart';
// import 'package:cake_wallet/monero/transaction_description.dart';
import 'package:cake_wallet/src/reactions/set_reactions.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/login/login_store.dart';
import 'package:cake_wallet/src/stores/sync/sync_store.dart'; // import 'package:cake_wallet/src/stores/balance/balance_store.dart';
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart'; // import 'package:cake_wallet/src/stores/sync/sync_store.dart';
import 'package:cake_wallet/src/stores/send_template/send_template_store.dart'; // import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
import 'package:cake_wallet/src/stores/exchange_template/exchange_template_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/screens/root/root.dart';
//import 'package:cake_wallet/src/stores/authentication/authentication_store.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/settings/settings_store.dart';
import 'package:cake_wallet/src/stores/price/price_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/user_service.dart';
import 'package:cake_wallet/src/domain/services/wallet_list_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/entities/balance_display_mode.dart';
import 'package:cake_wallet/src/domain/common/default_settings_migration.dart'; import 'package:cake_wallet/entities/default_settings_migration.dart';
import 'package:cake_wallet/src/domain/common/fiat_currency.dart'; import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/template.dart'; import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_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/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/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/language.dart'; import 'package:cake_wallet/entities/language.dart';
import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart'; // import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
bool isThemeChangerRegistered = false; bool isThemeChangerRegistered = false;
@ -74,12 +79,9 @@ void main() async {
final secureStorage = FlutterSecureStorage(); final secureStorage = FlutterSecureStorage();
final transactionDescriptionsBoxKey = await getEncryptionKey( final transactionDescriptionsBoxKey = await getEncryptionKey(
secureStorage: secureStorage, secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
forKey: 'transactionDescriptionsBoxKey'); // FIXME: Unnamed constant
final tradesBoxKey = await getEncryptionKey( final tradesBoxKey = await getEncryptionKey(
secureStorage: secureStorage, secureStorage: secureStorage, forKey: Trade.boxKey);
forKey: 'tradesBoxKey'); // FIXME: Unnamed constant
final contacts = await Hive.openBox<Contact>(Contact.boxName); final contacts = await Hive.openBox<Contact>(Contact.boxName);
final nodes = await Hive.openBox<Node>(Node.boxName); final nodes = await Hive.openBox<Node>(Node.boxName);
final transactionDescriptions = await Hive.openBox<TransactionDescription>( final transactionDescriptions = await Hive.openBox<TransactionDescription>(
@ -93,35 +95,35 @@ void main() async {
await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName); await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
final sharedPreferences = await SharedPreferences.getInstance(); final sharedPreferences = await SharedPreferences.getInstance();
final walletService = WalletService(); // final walletService = WalletService();
final fiatConvertationService = FiatConvertationService(); // final fiatConvertationService = FiatConvertationService();
final walletListService = WalletListService( // final walletListService = WalletListService(
secureStorage: secureStorage, // secureStorage: secureStorage,
walletInfoSource: walletInfoSource, // walletInfoSource: walletInfoSource,
walletService: walletService, // walletService: walletService,
sharedPreferences: sharedPreferences); // sharedPreferences: sharedPreferences);
final userService = UserService( // final userService = UserService(
sharedPreferences: sharedPreferences, secureStorage: secureStorage); // sharedPreferences: sharedPreferences, secureStorage: secureStorage);
final settingsStore = await SettingsStoreBase.load( // final settingsStore = await SettingsStoreBase.load(
nodes: nodes, // nodes: nodes,
sharedPreferences: sharedPreferences, // sharedPreferences: sharedPreferences,
initialFiatCurrency: FiatCurrency.usd, // initialFiatCurrency: FiatCurrency.usd,
initialTransactionPriority: TransactionPriority.slow, // initialTransactionPriority: TransactionPriority.slow,
initialBalanceDisplayMode: BalanceDisplayMode.availableBalance); // initialBalanceDisplayMode: BalanceDisplayMode.availableBalance);
final priceStore = PriceStore(); // final priceStore = PriceStore();
final walletStore = // final walletStore =
WalletStore(walletService: walletService, settingsStore: settingsStore); // WalletStore(walletService: walletService, settingsStore: settingsStore);
final syncStore = SyncStore(walletService: walletService); // final syncStore = SyncStore(walletService: walletService);
final balanceStore = BalanceStore( // final balanceStore = BalanceStore(
walletService: walletService, // walletService: walletService,
settingsStore: settingsStore, // settingsStore: settingsStore,
priceStore: priceStore); // priceStore: priceStore);
final loginStore = LoginStore( // final loginStore = LoginStore(
sharedPreferences: sharedPreferences, walletsService: walletListService); // sharedPreferences: sharedPreferences, walletsService: walletListService);
final seedLanguageStore = SeedLanguageStore(); // final seedLanguageStore = SeedLanguageStore();
final sendTemplateStore = SendTemplateStore(templateSource: templates); // final sendTemplateStore = SendTemplateStore(templateSource: templates);
final exchangeTemplateStore = // final exchangeTemplateStore =
ExchangeTemplateStore(templateSource: exchangeTemplates); // ExchangeTemplateStore(templateSource: exchangeTemplates);
final walletCreationService = WalletCreationService(); final walletCreationService = WalletCreationService();
final authService = AuthService(); final authService = AuthService();
@ -132,42 +134,21 @@ void main() async {
walletInfoSource: walletInfoSource, walletInfoSource: walletInfoSource,
contactSource: contacts, contactSource: contacts,
tradesSource: trades, tradesSource: trades,
fiatConvertationService: fiatConvertationService, // fiatConvertationService: fiatConvertationService,
templates: templates, templates: templates,
exchangeTemplates: exchangeTemplates, exchangeTemplates: exchangeTemplates,
initialMigrationVersion: 4); initialMigrationVersion: 4);
setReactions( // setReactions(
settingsStore: settingsStore, // settingsStore: settingsStore,
priceStore: priceStore, // priceStore: priceStore,
syncStore: syncStore, // syncStore: syncStore,
walletStore: walletStore, // walletStore: walletStore,
walletService: walletService, // walletService: walletService,
// authenticationStore: authenticationStore, // // authenticationStore: authenticationStore,
loginStore: loginStore); // loginStore: loginStore);
runApp(MultiProvider(providers: [ runApp(CakeWalletApp());
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()));
} }
Future<void> initialSetup( Future<void> initialSetup(
@ -176,7 +157,7 @@ Future<void> initialSetup(
@required Box<WalletInfo> walletInfoSource, @required Box<WalletInfo> walletInfoSource,
@required Box<Contact> contactSource, @required Box<Contact> contactSource,
@required Box<Trade> tradesSource, @required Box<Trade> tradesSource,
@required FiatConvertationService fiatConvertationService, // @required FiatConvertationService fiatConvertationService,
@required Box<Template> templates, @required Box<Template> templates,
@required Box<ExchangeTemplate> exchangeTemplates, @required Box<ExchangeTemplate> exchangeTemplates,
int initialMigrationVersion = 4}) async { int initialMigrationVersion = 4}) async {
@ -191,9 +172,7 @@ Future<void> initialSetup(
tradesSource: tradesSource, tradesSource: tradesSource,
templates: templates, templates: templates,
exchangeTemplates: exchangeTemplates); exchangeTemplates: exchangeTemplates);
await bootstrap( await bootstrap(navigatorKey);
fiatConvertationService: fiatConvertationService,
navigatorKey: navigatorKey);
monero_wallet.onStartup(); monero_wallet.onStartup();
} }
@ -220,22 +199,22 @@ class CakeWalletApp extends StatelessWidget {
class MaterialAppWithTheme extends StatelessWidget { class MaterialAppWithTheme extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final sharedPreferences = Provider.of<SharedPreferences>(context); // final sharedPreferences = Provider.of<SharedPreferences>(context);
final walletService = Provider.of<WalletService>(context); // final walletService = Provider.of<WalletService>(context);
final walletListService = Provider.of<WalletListService>(context); // final walletListService = Provider.of<WalletListService>(context);
final userService = Provider.of<UserService>(context); // final userService = Provider.of<UserService>(context);
final settingsStore = Provider.of<SettingsStore>(context); // final settingsStore = Provider.of<SettingsStore>(context);
final priceStore = Provider.of<PriceStore>(context); // final priceStore = Provider.of<PriceStore>(context);
final walletStore = Provider.of<WalletStore>(context); // final walletStore = Provider.of<WalletStore>(context);
final syncStore = Provider.of<SyncStore>(context); // final syncStore = Provider.of<SyncStore>(context);
final balanceStore = Provider.of<BalanceStore>(context); // final balanceStore = Provider.of<BalanceStore>(context);
final theme = Provider.of<ThemeChanger>(context); final theme = Provider.of<ThemeChanger>(context);
final currentLanguage = Provider.of<Language>(context); // final currentLanguage = Provider.of<Language>(context);
final contacts = Provider.of<Box<Contact>>(context); // final contacts = Provider.of<Box<Contact>>(context);
final nodes = Provider.of<Box<Node>>(context); // final nodes = Provider.of<Box<Node>>(context);
final trades = Provider.of<Box<Trade>>(context); // final trades = Provider.of<Box<Trade>>(context);
final transactionDescriptions = // final transactionDescriptions =
Provider.of<Box<TransactionDescription>>(context); // Provider.of<Box<TransactionDescription>>(context);
if (!isThemeChangerRegistered) { if (!isThemeChangerRegistered) {
setupThemeChangerStore(theme); setupThemeChangerStore(theme);
@ -252,16 +231,9 @@ class MaterialAppWithTheme extends StatelessWidget {
final statusBarIconBrightness = final statusBarIconBrightness =
_settingsStore.isDarkTheme ? Brightness.light : Brightness.dark; _settingsStore.isDarkTheme ? Brightness.light : Brightness.dark;
final authenticationStore = getIt.get<AuthenticationStore>(); final authenticationStore = getIt.get<AuthenticationStore>();
String initialRoute; final initialRoute = authenticationStore.state == AuthenticationState.denied
? Routes.welcome
switch (authenticationStore.state) { : Routes.login;
case AuthenticationState.denied:
initialRoute = Routes.welcome;
break;
default:
initialRoute = Routes.login;
break;
}
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: statusBarColor, statusBarColor: statusBarColor,
@ -281,22 +253,8 @@ class MaterialAppWithTheme extends StatelessWidget {
GlobalWidgetsLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
], ],
supportedLocales: S.delegate.supportedLocales, supportedLocales: S.delegate.supportedLocales,
locale: Locale(currentLanguage.getCurrentLanguage()), // locale: Locale(currentLanguage.getCurrentLanguage()),
onGenerateRoute: (settings) => Router.generateRoute( onGenerateRoute: (settings) => Router.generateRoute(settings),
sharedPreferences: sharedPreferences,
walletListService: walletListService,
walletService: walletService,
userService: userService,
settings: settings,
priceStore: priceStore,
walletStore: walletStore,
syncStore: syncStore,
balanceStore: balanceStore,
settingsStore: settingsStore,
contacts: contacts,
nodes: nodes,
trades: trades,
transactionDescriptions: transactionDescriptions),
initialRoute: initialRoute, initialRoute: initialRoute,
)); ));
} }

View file

@ -1,5 +1,7 @@
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
// FIXME: Hardcoded values; Works only for monero
final dateFormat = DateFormat('yyyy-MM'); final dateFormat = DateFormat('yyyy-MM');
final dates = { final dates = {
"2014-5": 18844, "2014-5": 18844,

Some files were not shown because too many files have changed in this diff Show more