Merge branch 'new-world' into CAKE-49-refactor-send-and-exchange-screen

# Conflicts:
#	lib/di.dart
#	lib/src/screens/base_page.dart
#	lib/src/screens/exchange/widgets/base_exchange_widget.dart
#	lib/src/screens/send/widgets/base_send_widget.dart
#	pubspec.lock
This commit is contained in:
OleksandrSobol
2020-09-22 21:59:13 +03:00
338 changed files with 3759 additions and 9080 deletions
-21
View File
@@ -1,21 +0,0 @@
import 'dart:convert';
import 'package:http/http.dart';
const blockchainInfoBaseURI = 'https://blockchain.info';
const multiAddressURI = '$blockchainInfoBaseURI/multiaddr';
Future<List<String>> fetchAllAddresses({String xpub}) async {
final uri = '$multiAddressURI?active=$xpub';
final response = await get(uri);
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
print(responseJSON);
return (responseJSON['addresses'] as List<dynamic>).map((dynamic row) {
if (row is Map<String, Object>) {
return row['address'] as String;
}
return '';
}).toList();
}
+4 -1
View File
@@ -1,5 +1,5 @@
import 'package:intl/intl.dart';
import 'package:cake_wallet/src/domain/common/crypto_amount_format.dart';
import 'package:cake_wallet/entities/crypto_amount_format.dart';
const bitcoinAmountLength = 8;
const bitcoinAmountDivider = 100000000;
@@ -11,3 +11,6 @@ String bitcoinAmountToString({int amount}) =>
bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider));
double bitcoinAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider);
int doubleToBitcoinAmount(double amount) =>
(amount * bitcoinAmountDivider).toInt();
+1 -1
View File
@@ -2,7 +2,7 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/src/domain/common/balance.dart';
import 'package:cake_wallet/entities/balance.dart';
class BitcoinBalance extends Balance {
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed}) : super();
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cake_wallet/entities/transaction_priority.dart';
class BitcoinTransactionCredentials {
BitcoinTransactionCredentials(this.address, this.amount, this.priority);
+1 -12
View File
@@ -9,8 +9,6 @@ import 'package:cake_wallet/bitcoin/electrum.dart';
part 'bitcoin_transaction_history.g.dart';
// TODO: Think about another transaction store for bitcoin transaction history..
const _transactionsHistoryFileName = 'transactions.json';
class BitcoinTransactionHistory = BitcoinTransactionHistoryBase
@@ -60,16 +58,7 @@ abstract class BitcoinTransactionHistoryBase
final histories =
wallet.scriptHashes.map((scriptHash) => eclient.getHistory(scriptHash));
final _historiesWithDetails = await Future.wait(histories)
.then((histories) => histories
// .map((h) => h.where((tx) {
// final height = tx['height'] as int ?? 0;
// // FIXME: Filter only needed transactions
// final _tx = get(tx['tx_hash'] as String);
//
// return height == 0 || height > _height;
// }))
.expand((i) => i)
.toList())
.then((histories) => histories.expand((i) => i).toList())
.then((histories) => histories.map((tx) => fetchTransactionInfo(
hash: tx['tx_hash'] as String, height: tx['height'] as int)));
final historiesWithDetails = await Future.wait(_historiesWithDetails);
+6 -9
View File
@@ -1,22 +1,22 @@
import 'package:flutter/foundation.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart';
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart';
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
import 'package:cake_wallet/src/domain/common/transaction_info.dart';
import 'package:cake_wallet/src/domain/common/format_amount.dart';
import 'package:cake_wallet/entities/transaction_direction.dart';
import 'package:cake_wallet/entities/transaction_info.dart';
import 'package:cake_wallet/entities/format_amount.dart';
class BitcoinTransactionInfo extends TransactionInfo {
BitcoinTransactionInfo(
{@required this.id,
{@required String id,
@required int height,
@required int amount,
@required TransactionDirection direction,
@required bool isPending,
@required DateTime date,
@required int confirmations}) {
this.id = id;
this.height = height;
this.amount = amount;
this.direction = direction;
@@ -97,7 +97,6 @@ class BitcoinTransactionInfo extends TransactionInfo {
? DateTime.fromMillisecondsSinceEpoch(timestamp * 1000)
: DateTime.now();
// FIXME: Get transaction is pending
return BitcoinTransactionInfo(
id: tx.getId(),
height: height,
@@ -119,8 +118,6 @@ class BitcoinTransactionInfo extends TransactionInfo {
confirmations: data['confirmations'] as int);
}
final String id;
String _fiatAmount;
@override
+20 -33
View File
@@ -1,39 +1,29 @@
import 'dart:async';
import 'dart:typed_data';
import 'dart:convert';
import 'package:mobx/mobx.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:flutter/foundation.dart';
import 'package:rxdart/rxdart.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_no_inputs_exception.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_wrong_balance_exception.dart';
import 'package:cake_wallet/bitcoin/bitcoin_unspent.dart';
import 'package:cake_wallet/bitcoin/bitcoin_wallet_keys.dart';
import 'package:cake_wallet/bitcoin/electrum.dart';
import 'package:cake_wallet/bitcoin/pending_bitcoin_transaction.dart';
import 'package:cake_wallet/bitcoin/script_hash.dart';
import 'package:cake_wallet/bitcoin/utils.dart';
import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart';
import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cw_monero/transaction_history.dart';
import 'package:flutter/cupertino.dart';
import 'package:mobx/mobx.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:flutter/foundation.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/entities/sync_status.dart';
import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_history.dart';
import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart';
import 'package:cake_wallet/bitcoin/file.dart';
import 'package:cake_wallet/bitcoin/electrum.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:rxdart/rxdart.dart';
import 'package:hex/hex.dart';
import 'package:cake_wallet/di.dart';
import 'package:shared_preferences/shared_preferences.dart';
part 'bitcoin_wallet.g.dart';
@@ -44,8 +34,8 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
{@required this.eclient,
@required this.path,
@required String password,
@required this.name,
List<BitcoinAddressRecord> initialAddresses,
@required WalletInfo walletInfo,
@required List<BitcoinAddressRecord> initialAddresses,
int accountIndex = 0,
this.transactionHistory,
this.mnemonic,
@@ -60,9 +50,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
syncStatus = NotConnectedSyncStatus(),
_password = password,
_accountIndex = accountIndex,
_addressesKeys = {} {
type = WalletType.bitcoin;
currency = CryptoCurrency.btc;
super(walletInfo) {
_scripthashesUpdateSubject = {};
}
@@ -114,7 +102,6 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
return BitcoinWallet._internal(
eclient: eclient,
path: walletPath,
name: name,
mnemonic: mnemonic,
password: password,
accountIndex: accountIndex,
@@ -130,9 +117,6 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
final ElectrumClient eclient;
final String mnemonic;
@override
String name;
@override
@observable
String address;
@@ -147,8 +131,6 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
ObservableList<BitcoinAddressRecord> addresses;
Map<String, bitcoin.ECPair> _addressesKeys;
List<String> get scriptHashes =>
addresses.map((addr) => scriptHash(addr.address)).toList();
@@ -161,8 +143,8 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
BitcoinWalletKeys get keys => BitcoinWalletKeys(
wif: hd.wif, privateKey: hd.privKey, publicKey: hd.pubKey);
final String _password;
int _accountIndex;
String _password;
Map<String, BehaviorSubject<Object>> _scripthashesUpdateSubject;
Future<void> init() async {
@@ -334,6 +316,11 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
bitcoin.ECPair keyPairFor({@required int index}) =>
generateKeyPair(hd: hd, index: index);
@override
Future<void> rescan({int height}) async {
// FIXME: Unimplemented
}
void _subscribeForUpdates() {
scriptHashes.forEach((sh) async {
await _scripthashesUpdateSubject[sh]?.close();
+2 -2
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/core/wallet_service.dart';
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
import 'package:cake_wallet/src/domain/common/pathForWallet.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/pathForWallet.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
class BitcoinWalletService extends WalletService<
BitcoinNewWalletCredentials,
+2 -2
View File
@@ -40,6 +40,7 @@ class ElectrumClient {
_tasks = {};
static const connectionTimeout = Duration(seconds: 5);
static const aliveTimerDuration = Duration(seconds: 2);
bool get isConnected => _isConnected;
Socket socket;
@@ -97,8 +98,7 @@ class ElectrumClient {
void keepAlive() {
_aliveTimer?.cancel();
// FIXME: Unnamed constant.
_aliveTimer = Timer.periodic(Duration(seconds: 2), (_) async => ping());
_aliveTimer = Timer.periodic(aliveTimerDuration, (_) async => ping());
}
Future<void> ping() async {
+2 -4
View File
@@ -1,5 +1,4 @@
import 'dart:io';
import 'dart:convert';
import 'package:cake_wallet/bitcoin/key.dart';
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:flutter/foundation.dart';
@@ -28,14 +27,13 @@ Future<void> writeData(
f.writeAsStringSync(encrypted);
}
Future<String> read(
{@required String path, @required String password}) async {
Future<String> read({@required String path, @required String password}) async {
final file = File(path);
if (!file.existsSync()) {
file.createSync();
}
final encrypted = file.readAsStringSync();
return decode(password: password, data: encrypted);
+1 -1
View File
@@ -1,6 +1,6 @@
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
import 'package:cake_wallet/entities/transaction_direction.dart';
import 'package:flutter/foundation.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:cake_wallet/core/pending_transaction.dart';
+1 -1
View File
@@ -1,6 +1,6 @@
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
class AddressLabelValidator extends TextValidator {
AddressLabelValidator({WalletType type})
+1 -1
View File
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
class AddressValidator extends TextValidator {
AddressValidator({@required CryptoCurrency type})
+37
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();
}
}
+92
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);
}
+1 -1
View File
@@ -1,6 +1,6 @@
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
class AmountValidator extends TextValidator {
AmountValidator({WalletType type, bool isAutovalidate = false})
+5 -4
View File
@@ -1,9 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/src/domain/common/secret_store_key.dart';
import 'package:cake_wallet/src/domain/common/encrypt.dart';
import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cake_wallet/entities/secret_store_key.dart';
import 'package:cake_wallet/entities/encrypt.dart';
class AuthService with Store {
AuthService({this.secureStorage, this.sharedPreferences});
@@ -19,7 +19,8 @@ class AuthService with Store {
Future<bool> canAuthenticate() async {
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final walletName = sharedPreferences.getString('current_wallet_name') ?? '';
final walletName =
sharedPreferences.getString(PreferencesKey.currentWalletName) ?? '';
var password = '';
try {
+1 -1
View File
@@ -1,6 +1,6 @@
import 'package:hive/hive.dart';
import 'package:cake_wallet/store/contact_list_store.dart';
import 'package:cake_wallet/src/domain/common/contact.dart';
import 'package:cake_wallet/entities/contact.dart';
class ContactService {
ContactService(this.contactSource, this.contactListStore) {
+13
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;
}
@@ -1,13 +1,16 @@
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
import 'package:cake_wallet/src/domain/common/currency_formatter.dart';
import 'package:cake_wallet/entities/currency_formatter.dart';
const fiatApiAuthority = 'fiat-api.cakewallet.com';
const fiatApiPath = '/v1/rates';
Future<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;
try {
@@ -35,3 +38,12 @@ Future<double> fetchPriceFor({CryptoCurrency crypto, FiatCurrency fiat}) async {
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);
}
+1 -1
View File
@@ -1,6 +1,6 @@
import 'package:uuid/uuid.dart';
import 'package:cake_wallet/bitcoin/key.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
String generateWalletPassword(WalletType type) {
switch (type) {
+2 -2
View File
@@ -1,6 +1,6 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:cake_wallet/src/domain/common/secret_store_key.dart';
import 'package:cake_wallet/src/domain/common/encrypt.dart';
import 'package:cake_wallet/entities/secret_store_key.dart';
import 'package:cake_wallet/entities/encrypt.dart';
class KeyService {
KeyService(this._secureStorage);
+1 -1
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 moneroMnemonicLength = 25;
+1 -1
View File
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
class MoneroLabelValidator extends TextValidator {
MoneroLabelValidator({@required CryptoCurrency type})
+20 -21
View File
@@ -1,15 +1,16 @@
import 'package:bip39/src/wordlists/english.dart' as bitcoin_english;
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/src/domain/common/mnemonic_item.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/chinese_simplified.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/dutch.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/english.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/german.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/japanese.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/portuguese.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/russian.dart';
import 'package:cake_wallet/src/domain/monero/mnemonics/spanish.dart';
import 'package:cake_wallet/entities/mnemonic_item.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/monero/mnemonics/chinese_simplified.dart';
import 'package:cake_wallet/monero/mnemonics/dutch.dart';
import 'package:cake_wallet/monero/mnemonics/english.dart';
import 'package:cake_wallet/monero/mnemonics/german.dart';
import 'package:cake_wallet/monero/mnemonics/japanese.dart';
import 'package:cake_wallet/monero/mnemonics/portuguese.dart';
import 'package:cake_wallet/monero/mnemonics/russian.dart';
import 'package:cake_wallet/monero/mnemonics/spanish.dart';
import 'package:cake_wallet/utils/language_list.dart';
class SeedValidator extends Validator<MnemonicItem> {
SeedValidator({this.type, this.language})
@@ -31,31 +32,29 @@ class SeedValidator extends Validator<MnemonicItem> {
}
static List<String> getMoneroWordList(String language) {
// FIXME: Unnamed constants; Need to be sure that string are in same case;
switch (language) {
case 'English':
case LanguageList.english:
return EnglishMnemonics.words;
break;
case 'Chinese (simplified)':
case LanguageList.chineseSimplified:
return ChineseSimplifiedMnemonics.words;
break;
case 'Dutch':
case LanguageList.dutch:
return DutchMnemonics.words;
break;
case 'German':
case LanguageList.german:
return GermanMnemonics.words;
break;
case 'Japanese':
case LanguageList.japanese:
return JapaneseMnemonics.words;
break;
case 'Portuguese':
case LanguageList.portuguese:
return PortugueseMnemonics.words;
break;
case 'Russian':
case LanguageList.russian:
return RussianMnemonics.words;
break;
case 'Spanish':
case LanguageList.spanish:
return SpanishMnemonics.words;
break;
default:
@@ -64,7 +63,7 @@ class SeedValidator extends Validator<MnemonicItem> {
}
static List<String> getBitcoinWordList(String language) {
assert(language.toLowerCase() == 'english');
assert(language.toLowerCase() == LanguageList.english.toLowerCase());
return bitcoin_english.WORDLIST;
}
+5 -3
View File
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/src/domain/common/transaction_info.dart';
import 'package:cake_wallet/entities/transaction_info.dart';
abstract class TransactionHistoryBase<TransactionType extends TransactionInfo> {
TransactionHistoryBase() : _isUpdating = false;
@@ -10,15 +10,17 @@ abstract class TransactionHistoryBase<TransactionType extends TransactionInfo> {
bool _isUpdating;
@action
Future<void> update() async {
if (_isUpdating) {
return;
}
try {
_isUpdating = false;
transactions.addAll(await fetchTransactions());
_isUpdating = true;
final _transactions = await fetchTransactions();
_transactions.forEach((key, value) => transactions[key] = value);
_isUpdating = false;
} catch (e) {
_isUpdating = false;
rethrow;
+28 -13
View File
@@ -1,24 +1,39 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/core/pending_transaction.dart';
import 'package:cake_wallet/core/transaction_history.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/currency_for_wallet_type.dart';
import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/entities/sync_status.dart';
import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
abstract class WalletBase<BalaceType> {
WalletType type;
WalletBase(this.walletInfo);
CryptoCurrency currency;
static String idFor(String name, WalletType type) =>
walletTypeToString(type).toLowerCase() + '_' + name;
String get name;
WalletInfo walletInfo;
String address;
WalletType get type => walletInfo.type;
BalaceType balance;
CryptoCurrency get currency => currencyForWalletType(type);
SyncStatus syncStatus;
String get id => walletInfo.id;
String get name => walletInfo.name;
String get address;
set address(String address);
BalaceType get balance;
SyncStatus get syncStatus;
set syncStatus(SyncStatus status);
String get seed;
@@ -26,8 +41,6 @@ abstract class WalletBase<BalaceType> {
TransactionHistoryBase transactionHistory;
String get id => walletTypeToString(type).toLowerCase() + '_' + name;
Future<void> connectToNode({@required Node node});
Future<void> startSync();
@@ -37,4 +50,6 @@ abstract class WalletBase<BalaceType> {
double calculateEstimatedFee(TransactionPriority priority);
Future<void> save();
Future<void> rescan({int height});
}
+10 -29
View File
@@ -1,19 +1,17 @@
import 'package:cake_wallet/di.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/core/key_service.dart';
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/core/generate_wallet_password.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/core/wallet_credentials.dart';
import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
import 'package:cake_wallet/monero/monero_wallet_service.dart';
import 'package:cake_wallet/core/wallet_service.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
class WalletCreationService {
WalletCreationService(
{WalletType initialType,
this.appStore,
this.secureStorage,
this.keyService,
this.sharedPreferences})
@@ -24,7 +22,6 @@ class WalletCreationService {
}
WalletType type;
final AppStore appStore;
final FlutterSecureStorage secureStorage;
final SharedPreferences sharedPreferences;
final KeyService keyService;
@@ -32,46 +29,30 @@ class WalletCreationService {
void changeWalletType({@required WalletType type}) {
this.type = type;
switch (type) {
case WalletType.monero:
_service = MoneroWalletService();
break;
case WalletType.bitcoin:
_service = BitcoinWalletService();
break;
default:
break;
}
_service = getIt.get<WalletService>(param1: type);
}
Future<void> create(WalletCredentials credentials) async {
Future<WalletBase> create(WalletCredentials credentials) async {
final password = generateWalletPassword(type);
credentials.password = password;
await keyService.saveWalletPassword(
password: password, walletName: credentials.name);
final wallet = await _service.create(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
return await _service.create(credentials);
}
Future<void> restoreFromKeys(WalletCredentials credentials) async {
Future<WalletBase> restoreFromKeys(WalletCredentials credentials) async {
final password = generateWalletPassword(type);
credentials.password = password;
await keyService.saveWalletPassword(
password: password, walletName: credentials.name);
final wallet = await _service.restoreFromKeys(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
return await _service.restoreFromKeys(credentials);
}
Future<void> restoreFromSeed(WalletCredentials credentials) async {
Future<WalletBase> restoreFromSeed(WalletCredentials credentials) async {
final password = generateWalletPassword(type);
credentials.password = password;
await keyService.saveWalletPassword(
password: password, walletName: credentials.name);
final wallet = await _service.restoreFromSeed(credentials);
appStore.wallet = wallet;
appStore.authenticationStore.allowed();
return await _service.restoreFromSeed(credentials);
}
}
+6 -2
View File
@@ -1,6 +1,10 @@
import 'package:cake_wallet/entities/wallet_info.dart';
abstract class WalletCredentials {
WalletCredentials({this.name, this.password});
WalletCredentials({this.name, this.password, this.height});
final String name;
final int height;
String password;
}
WalletInfo walletInfo;
}
+70 -74
View File
@@ -1,16 +1,24 @@
import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
import 'package:cake_wallet/core/contact_service.dart';
import 'package:cake_wallet/src/domain/common/contact.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
import 'package:cake_wallet/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/entities/contact.dart';
import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/exchange/trade.dart';
// import 'package:cake_wallet/src/domain/services/wallet_service.dart';
import 'package:cake_wallet/src/screens/contact/contact_list_page.dart';
import 'package:cake_wallet/src/screens/contact/contact_page.dart';
import 'package:cake_wallet/src/screens/exchange_trade/exchange_confirm_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/nodes_list_page.dart';
import 'package:cake_wallet/src/screens/rescan/rescan_page.dart';
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
import 'package:cake_wallet/src/screens/send/send_template_page.dart';
import 'package:cake_wallet/src/screens/settings/settings.dart';
import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart';
import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart';
import 'package:cake_wallet/src/screens/exchange/exchange_page.dart';
import 'package:cake_wallet/src/screens/exchange/exchange_template_page.dart';
@@ -20,7 +28,7 @@ import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/core/key_service.dart';
import 'package:cake_wallet/monero/monero_wallet.dart';
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/src/screens/monero_accounts/monero_account_list_page.dart';
import 'package:cake_wallet/src/screens/monero_accounts/monero_account_edit_or_create_page.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
@@ -38,6 +46,8 @@ import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart';
import 'package:cake_wallet/view_model/exchange/exchange_trade_view_model.dart';
import 'package:cake_wallet/view_model/node_list/node_list_view_model.dart';
import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart';
import 'package:cake_wallet/view_model/rescan_view_model.dart';
import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart';
import 'package:cake_wallet/view_model/auth_view_model.dart';
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
@@ -52,6 +62,7 @@ import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
import 'package:cake_wallet/view_model/wallet_seed_view_model.dart';
import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:get_it/get_it.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
@@ -61,51 +72,20 @@ import 'package:cake_wallet/view_model/wallet_restoration_from_seed_vm.dart';
import 'package:cake_wallet/view_model/wallet_restoration_from_keys_vm.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/view_model/wallet_new_vm.dart';
import 'package:cake_wallet/store/authentication_store.dart';
import 'package:cake_wallet/store/dashboard/trades_store.dart';
import 'package:cake_wallet/store/dashboard/trade_filter_store.dart';
import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/templates/send_template_store.dart';
import 'package:cake_wallet/store/templates/exchange_template_store.dart';
import 'package:cake_wallet/src/domain/common/template.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_template.dart';
import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/exchange/exchange_template.dart';
final getIt = GetIt.instance;
// FIXME: Move me.
Stream<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(
{Box<WalletInfo> walletInfoSource,
Box<Node> nodeSource,
@@ -118,11 +98,13 @@ Future setup(
final settingsStore = await SettingsStoreBase.load(nodeSource: nodeSource);
getIt.registerSingleton<Box<Node>>(nodeSource);
getIt.registerSingleton<FlutterSecureStorage>(FlutterSecureStorage());
getIt.registerSingleton(AuthenticationStore());
getIt.registerSingleton<WalletListStore>(WalletListStore());
getIt.registerSingleton(ContactListStore());
getIt.registerSingleton(setupNodeListStore(nodeSource));
getIt.registerSingleton(NodeListStoreBase.instance);
getIt.registerSingleton<SettingsStore>(settingsStore);
getIt.registerSingleton<AppStore>(AppStore(
authenticationStore: getIt.get<AuthenticationStore>(),
@@ -136,7 +118,7 @@ Future setup(
tradesSource: tradesSource, settingsStore: getIt.get<SettingsStore>()));
getIt.registerSingleton<TradeFilterStore>(TradeFilterStore());
getIt.registerSingleton<TransactionFilterStore>(TransactionFilterStore());
getIt.registerSingleton<FiatConvertationStore>(FiatConvertationStore());
getIt.registerSingleton<FiatConversionStore>(FiatConversionStore());
getIt.registerSingleton<SendTemplateStore>(
SendTemplateStore(templateSource: templates));
getIt.registerSingleton<ExchangeTemplateStore>(
@@ -148,13 +130,12 @@ Future setup(
getIt.registerFactoryParam<WalletCreationService, WalletType, void>(
(type, _) => WalletCreationService(
initialType: type,
appStore: getIt.get<AppStore>(),
keyService: getIt.get<KeyService>(),
secureStorage: getIt.get<FlutterSecureStorage>(),
sharedPreferences: getIt.get<SharedPreferences>()));
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
WalletNewVM(
WalletNewVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type));
@@ -164,7 +145,7 @@ Future setup(
final language = args[1] as String;
final mnemonic = args[2] as String;
return WalletRestorationFromSeedVM(
return WalletRestorationFromSeedVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type, language: language, seed: mnemonic);
});
@@ -174,7 +155,7 @@ Future setup(
final type = args.first as WalletType;
final language = args[1] as String;
return WalletRestorationFromKeysVM(
return WalletRestorationFromKeysVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type, language: language);
});
@@ -185,7 +166,7 @@ Future setup(
getIt.registerFactory(() => BalanceViewModel(
wallet: getIt.get<AppStore>().wallet,
settingsStore: getIt.get<SettingsStore>(),
fiatConvertationStore: getIt.get<FiatConvertationStore>()));
fiatConvertationStore: getIt.get<FiatConversionStore>()));
getIt.registerFactory(() => DashboardViewModel(
balanceViewModel: getIt.get<BalanceViewModel>(),
@@ -199,38 +180,24 @@ Future setup(
sharedPreferences: getIt.get<SharedPreferences>()));
getIt.registerFactory<AuthViewModel>(() => AuthViewModel(
authService: getIt.get<AuthService>(),
sharedPreferences: getIt.get<SharedPreferences>()));
getIt.get<AuthService>(),
getIt.get<SharedPreferences>(),
getIt.get<SettingsStore>(),
BiometricAuth()));
getIt.registerFactory<AuthPage>(
() => AuthPage(
allowBiometricalAuthentication: getIt
.get<AppStore>()
.settingsStore
.allowBiometricalAuthentication,
authViewModel: getIt.get<AuthViewModel>(),
onAuthenticationFinished: (isAuthenticated, __) {
() => AuthPage(getIt.get<AuthViewModel>(),
onAuthenticationFinished: (isAuthenticated, __) {
if (isAuthenticated) {
getIt.get<AuthenticationStore>().allowed();
}
},
closable: false),
}, closable: false),
instanceName: 'login');
getIt
.registerFactoryParam<AuthPage, void Function(bool, AuthPageState), void>(
(onAuthFinished, _) {
final allowBiometricalAuthentication =
getIt.get<AppStore>().settingsStore.allowBiometricalAuthentication;
print('allowBiometricalAuthentication $allowBiometricalAuthentication');
return AuthPage(
allowBiometricalAuthentication: allowBiometricalAuthentication,
authViewModel: getIt.get<AuthViewModel>(),
onAuthenticationFinished: onAuthFinished,
closable: false);
});
(onAuthFinished, _) => AuthPage(getIt.get<AuthViewModel>(),
onAuthenticationFinished: onAuthFinished, closable: false));
getIt.registerFactory<DashboardPage>(() => DashboardPage(
walletViewModel: getIt.get<DashboardViewModel>(),
@@ -252,13 +219,13 @@ Future setup(
getIt.registerFactory<SendViewModel>(() => SendViewModel(
getIt.get<AppStore>().wallet,
getIt.get<AppStore>().settingsStore,
getIt.get<FiatConvertationStore>()));
getIt.get<FiatConversionStore>()));
getIt.registerFactory(
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
getIt.registerFactory(
() => SendTemplatePage(sendViewModel: getIt.get<SendViewModel>()));
() => SendTemplatePage(sendViewModel: getIt.get<SendViewModel>()));
getIt.registerFactory(() => WalletListViewModel(
walletInfoSource, getIt.get<AppStore>(), getIt.get<KeyService>()));
@@ -305,10 +272,10 @@ Future setup(
getIt
.registerFactory(() => WalletSeedViewModel(getIt.get<AppStore>().wallet));
getIt.registerFactoryParam<WalletSeedPage, VoidCallback, void>(
(VoidCallback callback, _) => WalletSeedPage(
getIt.registerFactoryParam<WalletSeedPage, bool, void>(
(bool isWalletCreated, _) => WalletSeedPage(
getIt.get<WalletSeedViewModel>(),
onCloseCallback: callback));
isNewWalletCreated: isWalletCreated));
getIt
.registerFactory(() => WalletKeysViewModel(getIt.get<AppStore>().wallet));
@@ -367,6 +334,35 @@ Future setup(
getIt.registerFactory(
() => ExchangeTemplatePage(getIt.get<ExchangeViewModel>()));
getIt.registerFactory(() => MoneroWalletService(walletInfoSource));
getIt.registerFactory(() => BitcoinWalletService());
getIt.registerFactoryParam<WalletService, WalletType, void>(
(WalletType param1, __) {
switch (param1) {
case WalletType.monero:
return getIt.get<MoneroWalletService>();
case WalletType.bitcoin:
return getIt.get<BitcoinWalletService>();
default:
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) {
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/enumerable_item.dart';
import 'package:cake_wallet/entities/enumerable_item.dart';
class BalanceDisplayMode extends EnumerableItem<int> with Serializable<int> {
const BalanceDisplayMode({@required String title, @required int raw})
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cake_wallet/entities/transaction_priority.dart';
double calculateEstimatedFee({TransactionPriority priority}) {
if (priority == TransactionPriority.slow) {
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/utils/mobx.dart';
part 'contact.g.dart';
@@ -1,7 +1,7 @@
// import 'package:hive/hive.dart';
// import 'package:mobx/mobx.dart';
// import 'package:cake_wallet/src/domain/common/contact.dart';
// import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
// import 'package:cake_wallet/entities/contact.dart';
// import 'package:cake_wallet/entities/crypto_currency.dart';
// part 'contact_model.g.dart';
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/enumerable_item.dart';
import 'package:cake_wallet/entities/enumerable_item.dart';
import 'package:hive/hive.dart';
part 'crypto_currency.g.dart';
@@ -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;
}
}
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
String cryptoToString(CryptoCurrency crypto) {
switch (crypto) {
@@ -1,13 +1,13 @@
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
import 'package:cake_wallet/src/domain/common/node_list.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/entities/node_list.dart';
import 'package:cake_wallet/entities/transaction_priority.dart';
Future defaultSettingsMigration(
{@required int version,
@@ -29,13 +29,13 @@ Future defaultSettingsMigration(
switch (version) {
case 1:
await sharedPreferences.setString(
SettingsStoreBase.currentFiatCurrencyKey,
PreferencesKey.currentFiatCurrencyKey,
FiatCurrency.usd.toString());
await sharedPreferences.setInt(
SettingsStoreBase.currentTransactionPriorityKey,
PreferencesKey.currentTransactionPriorityKey,
TransactionPriority.standart.raw);
await sharedPreferences.setInt(
SettingsStoreBase.currentBalanceDisplayModeKey,
PreferencesKey.currentBalanceDisplayModeKey,
BalanceDisplayMode.availableBalance.raw);
await sharedPreferences.setBool('save_recipient_address', true);
await resetToDefault(nodes);
@@ -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> {
const FiatCurrency({String symbol}) : super(title: symbol, raw: symbol);
@@ -1,10 +1,10 @@
import 'dart:io';
import 'dart:convert';
import 'package:cake_wallet/src/domain/common/contact.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
@@ -82,28 +82,28 @@ Future<void> migrate_wallets({Directory appDocDir}) async {
Future<void> migrate_ios_wallet_info(
{@required Directory appDocDir,
@required Box<WalletInfo> walletsInfo}) async {
final walletsDir = Directory('${appDocDir.path}/wallets');
final moneroWalletsDir = Directory('${walletsDir.path}/monero');
// final walletsDir = Directory('${appDocDir.path}/wallets');
// final moneroWalletsDir = Directory('${walletsDir.path}/monero');
moneroWalletsDir.listSync().forEach((item) async {
try {
if (item is Directory) {
final name = item.path.split('/').last;
final configFile = File('${item.path}/$name.json');
final config =
json.decode(configFile.readAsStringSync()) as Map<String, dynamic>;
final isRecovery = config["isRecovery"] as bool ?? false;
final id =
walletTypeToString(WalletType.monero).toLowerCase() + '_' + name;
final walletInfo =
WalletInfo(id: id, name: name, isRecovery: isRecovery);
// moneroWalletsDir.listSync().forEach((item) async {
// try {
// if (item is Directory) {
// final name = item.path.split('/').last;
// final configFile = File('${item.path}/$name.json');
// final config =
// json.decode(configFile.readAsStringSync()) as Map<String, dynamic>;
// final isRecovery = config["isRecovery"] as bool ?? false;
// final id =
// walletTypeToString(WalletType.monero).toLowerCase() + '_' + name;
// final walletInfo =
// WalletInfo(id: id, name: name, isRecovery: isRecovery);
await walletsInfo.add(walletInfo);
}
} catch (e) {
print(e.toString());
}
});
// await walletsInfo.add(walletInfo);
// }
// } catch (e) {
// print(e.toString());
// }
// });
}
Future<void> migrate_ios_trades_list(
+15
View File
@@ -0,0 +1,15 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
const platform =
const MethodChannel('com.cakewallet.cakewallet/legacy_wallet_migration');
Future<String> readTradeList(
{@required String key, @required String salt}) async =>
await platform.invokeMethod('read_trade_list', {'key': key, 'salt': salt});
Future<String> readEncryptedFile(String url,
{@required String key, @required String salt}) async =>
await platform.invokeMethod(
'read_encrypted_file', {'url': url, 'key': key, 'salt': salt});
+23
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;
}
@@ -3,8 +3,8 @@ import 'package:flutter/foundation.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:hive/hive.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/digest_request.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/entities/digest_request.dart';
part 'node.g.dart';
@@ -1,8 +1,8 @@
import 'package:flutter/services.dart';
import 'package:hive/hive.dart';
import "package:yaml/yaml.dart";
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
Future<List<Node>> loadDefaultNodes() async {
final nodesRaw = await rootBundle.loadString('assets/node_list.yml');
@@ -1,5 +1,5 @@
import 'dart:io';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:flutter/foundation.dart';
import 'package:path_provider/path_provider.dart';
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:cw_monero/transaction_history.dart' as transaction_history;
import 'package:cw_monero/structs/pending_transaction.dart';
import 'package:cake_wallet/src/domain/monero/monero_amount_format.dart';
import 'package:cake_wallet/monero/monero_amount_format.dart';
class PendingTransaction {
PendingTransaction(
+16
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';
}
@@ -7,6 +7,7 @@ class TransactionDescription extends HiveObject {
TransactionDescription({this.id, this.recipientAddress});
static const boxName = 'TransactionDescriptions';
static const boxKey = 'transactionDescriptionsBoxKey';
@HiveField(0)
String id;
@@ -1,5 +1,5 @@
import 'package:rxdart/rxdart.dart';
import 'package:cake_wallet/src/domain/common/transaction_info.dart';
import 'package:cake_wallet/entities/transaction_info.dart';
abstract class TransactionHistory {
Observable<List<TransactionInfo>> transactions;
@@ -1,6 +1,7 @@
import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
import 'package:cake_wallet/entities/transaction_direction.dart';
import 'package:cake_wallet/utils/mobx.dart';
abstract class TransactionInfo extends Object {
abstract class TransactionInfo extends Object with Keyable {
String id;
int amount;
TransactionDirection direction;
@@ -11,4 +12,7 @@ abstract class TransactionInfo extends Object {
String amountFormatted();
String fiatAmount();
void changeFiatAmount(String amount);
@override
dynamic get keyIndex => id;
}
@@ -1,5 +1,5 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/enumerable_item.dart';
import 'package:cake_wallet/entities/enumerable_item.dart';
class TransactionPriority extends EnumerableItem<int> with Serializable<int> {
const TransactionPriority({String title, int raw})
@@ -1,11 +1,11 @@
import 'package:rxdart/rxdart.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart';
import 'package:cake_wallet/src/domain/common/transaction_history.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/transaction_creation_credentials.dart';
import 'package:cake_wallet/src/domain/common/pending_transaction.dart';
import 'package:cake_wallet/src/domain/common/balance.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/entities/sync_status.dart';
import 'package:cake_wallet/entities/transaction_history.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/entities/transaction_creation_credentials.dart';
import 'package:cake_wallet/entities/pending_transaction.dart';
import 'package:cake_wallet/entities/balance.dart';
import 'package:cake_wallet/entities/node.dart';
abstract class Wallet {
WalletType getType();
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
class WalletDescription {
WalletDescription({this.name, this.type});
+52
View File
@@ -0,0 +1,52 @@
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
part 'wallet_info.g.dart';
@HiveType(typeId: 4)
class WalletInfo extends HiveObject {
WalletInfo(this.id, this.name, this.type, this.isRecovery, this.restoreHeight,
this.timestamp, this.dirPath, this.path);
factory WalletInfo.external(
{@required String id,
@required String name,
@required WalletType type,
@required bool isRecovery,
@required int restoreHeight,
@required DateTime date,
@required String dirPath,
@required String path}) {
return WalletInfo(id, name, type, isRecovery, restoreHeight,
date.millisecondsSinceEpoch ?? 0, dirPath, path);
}
static const boxName = 'WalletInfo';
@HiveField(0)
String id;
@HiveField(1)
String name;
@HiveField(2)
WalletType type;
@HiveField(3)
bool isRecovery;
@HiveField(4)
int restoreHeight;
@HiveField(5)
int timestamp;
@HiveField(6)
String dirPath;
@HiveField(7)
String path;
DateTime get date => DateTime.fromMillisecondsSinceEpoch(timestamp);
}
@@ -1,5 +1,5 @@
import 'package:cake_wallet/src/domain/common/wallet.dart';
import 'package:cake_wallet/src/domain/common/wallet_description.dart';
import 'package:cake_wallet/entities/wallet.dart';
import 'package:cake_wallet/entities/wallet_description.dart';
abstract class WalletsManager {
Future<Wallet> create(String name, String password, String language);
@@ -1,18 +1,18 @@
import 'dart:convert';
import 'package:cake_wallet/src/domain/exchange/trade_not_found_exeption.dart';
import 'package:cake_wallet/exchange/trade_not_found_exeption.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
import 'package:cake_wallet/src/domain/exchange/changenow/changenow_request.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/exchange/exchange_pair.dart';
import 'package:cake_wallet/exchange/exchange_provider.dart';
import 'package:cake_wallet/exchange/limits.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/exchange/trade_request.dart';
import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/exchange/changenow/changenow_request.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/trade_not_created_exeption.dart';
class ChangeNowExchangeProvider extends ExchangeProvider {
ChangeNowExchangeProvider()
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/exchange/trade_request.dart';
class ChangeNowRequest extends TradeRequest {
ChangeNowRequest(
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
class ExchangePair {
ExchangePair({this.from, this.to, this.reverse = true});
@@ -1,10 +1,10 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/exchange/trade_request.dart';
import 'package:cake_wallet/exchange/exchange_pair.dart';
import 'package:cake_wallet/exchange/limits.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
abstract class ExchangeProvider {
ExchangeProvider({this.pairList});
@@ -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>
with Serializable<int> {
@@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
import 'package:cake_wallet/exchange/trade.dart';
abstract class ExchangeTradeState {}
@@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart';
import 'package:cake_wallet/exchange/limits.dart';
abstract class LimitsState {}
@@ -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;
}
}
}
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/exchange/trade_request.dart';
class MorphTokenRequest extends TradeRequest {
MorphTokenRequest(
@@ -1,8 +1,8 @@
import 'package:hive/hive.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
import 'package:cake_wallet/src/domain/common/format_amount.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/entities/format_amount.dart';
part 'trade.g.dart';
@@ -28,6 +28,7 @@ class Trade extends HiveObject {
stateRaw = state?.raw;
static const boxName = 'Trades';
static const boxKey = 'tradesBoxKey';
@HiveField(0)
String id;
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/generated/i18n.dart';
class TradeNotCreatedException implements Exception {
@@ -1,4 +1,4 @@
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/generated/i18n.dart';
class TradeNotFoundException implements Exception {
@@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/enumerable_item.dart';
import 'package:cake_wallet/entities/enumerable_item.dart';
class TradeState extends EnumerableItem<String> with Serializable<String> {
const TradeState({@required String raw, @required String title})
@@ -1,17 +1,17 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_pair.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_found_exeption.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/exchange/exchange_pair.dart';
import 'package:cake_wallet/exchange/exchange_provider.dart';
import 'package:cake_wallet/exchange/limits.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/exchange/trade_request.dart';
import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/exchange/xmrto/xmrto_trade_request.dart';
import 'package:cake_wallet/exchange/trade_not_created_exeption.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/trade_not_found_exeption.dart';
class XMRTOExchangeProvider extends ExchangeProvider {
XMRTOExchangeProvider()
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/trade_request.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/exchange/trade_request.dart';
class XMRTOTradeRequest extends TradeRequest {
XMRTOTradeRequest(
+655 -1242
View File
File diff suppressed because it is too large Load Diff
+98 -130
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/routes.dart';
import 'package:cake_wallet/store/app_store.dart';
@@ -21,38 +23,41 @@ import 'package:cw_monero/wallet.dart' as monero_wallet;
import 'package:cake_wallet/router.dart';
import 'theme_changer.dart';
import 'themes.dart';
import 'package:cake_wallet/src/domain/common/get_encryption_key.dart';
import 'package:cake_wallet/src/domain/common/contact.dart';
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
import 'package:cake_wallet/src/domain/monero/transaction_description.dart';
import 'package:cake_wallet/entities/get_encryption_key.dart';
import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/entities/wallet_info.dart';
import 'package:cake_wallet/exchange/trade.dart';
// import 'package:cake_wallet/monero/transaction_description.dart';
import 'package:cake_wallet/src/reactions/set_reactions.dart';
import 'package:cake_wallet/src/stores/login/login_store.dart';
import 'package:cake_wallet/src/stores/balance/balance_store.dart';
import 'package:cake_wallet/src/stores/sync/sync_store.dart';
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
import 'package:cake_wallet/src/stores/send_template/send_template_store.dart';
import 'package:cake_wallet/src/stores/exchange_template/exchange_template_store.dart';
// import 'package:cake_wallet/src/stores/login/login_store.dart';
// import 'package:cake_wallet/src/stores/balance/balance_store.dart';
// import 'package:cake_wallet/src/stores/sync/sync_store.dart';
// import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
// import 'package:cake_wallet/src/stores/send_template/send_template_store.dart';
// import 'package:cake_wallet/src/stores/exchange_template/exchange_template_store.dart';
import 'package:cake_wallet/src/screens/root/root.dart';
//import 'package:cake_wallet/src/stores/authentication/authentication_store.dart';
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
import 'package:cake_wallet/src/stores/price/price_store.dart';
import 'package:cake_wallet/src/domain/services/user_service.dart';
import 'package:cake_wallet/src/domain/services/wallet_list_service.dart';
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
import 'package:cake_wallet/src/domain/common/default_settings_migration.dart';
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/common/template.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_template.dart';
import 'package:cake_wallet/src/domain/services/wallet_service.dart';
import 'package:cake_wallet/src/domain/services/fiat_convertation_service.dart';
// import 'package:cake_wallet/src/stores/settings/settings_store.dart';
// import 'package:cake_wallet/src/stores/price/price_store.dart';
// import 'package:cake_wallet/src/domain/services/user_service.dart';
// import 'package:cake_wallet/src/domain/services/wallet_list_service.dart';
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/default_settings_migration.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/exchange/exchange_template.dart';
// import 'package:cake_wallet/src/domain/services/wallet_service.dart';
// import 'package:cake_wallet/src/domain/services/fiat_convertation_service.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/language.dart';
import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
import 'package:cake_wallet/entities/language.dart';
// import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
bool isThemeChangerRegistered = false;
@@ -74,12 +79,9 @@ void main() async {
final secureStorage = FlutterSecureStorage();
final transactionDescriptionsBoxKey = await getEncryptionKey(
secureStorage: secureStorage,
forKey: 'transactionDescriptionsBoxKey'); // FIXME: Unnamed constant
secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
final tradesBoxKey = await getEncryptionKey(
secureStorage: secureStorage,
forKey: 'tradesBoxKey'); // FIXME: Unnamed constant
secureStorage: secureStorage, forKey: Trade.boxKey);
final contacts = await Hive.openBox<Contact>(Contact.boxName);
final nodes = await Hive.openBox<Node>(Node.boxName);
final transactionDescriptions = await Hive.openBox<TransactionDescription>(
@@ -93,35 +95,35 @@ void main() async {
await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
final sharedPreferences = await SharedPreferences.getInstance();
final walletService = WalletService();
final fiatConvertationService = FiatConvertationService();
final walletListService = WalletListService(
secureStorage: secureStorage,
walletInfoSource: walletInfoSource,
walletService: walletService,
sharedPreferences: sharedPreferences);
final userService = UserService(
sharedPreferences: sharedPreferences, secureStorage: secureStorage);
final settingsStore = await SettingsStoreBase.load(
nodes: nodes,
sharedPreferences: sharedPreferences,
initialFiatCurrency: FiatCurrency.usd,
initialTransactionPriority: TransactionPriority.slow,
initialBalanceDisplayMode: BalanceDisplayMode.availableBalance);
final priceStore = PriceStore();
final walletStore =
WalletStore(walletService: walletService, settingsStore: settingsStore);
final syncStore = SyncStore(walletService: walletService);
final balanceStore = BalanceStore(
walletService: walletService,
settingsStore: settingsStore,
priceStore: priceStore);
final loginStore = LoginStore(
sharedPreferences: sharedPreferences, walletsService: walletListService);
final seedLanguageStore = SeedLanguageStore();
final sendTemplateStore = SendTemplateStore(templateSource: templates);
final exchangeTemplateStore =
ExchangeTemplateStore(templateSource: exchangeTemplates);
// final walletService = WalletService();
// final fiatConvertationService = FiatConvertationService();
// final walletListService = WalletListService(
// secureStorage: secureStorage,
// walletInfoSource: walletInfoSource,
// walletService: walletService,
// sharedPreferences: sharedPreferences);
// final userService = UserService(
// sharedPreferences: sharedPreferences, secureStorage: secureStorage);
// final settingsStore = await SettingsStoreBase.load(
// nodes: nodes,
// sharedPreferences: sharedPreferences,
// initialFiatCurrency: FiatCurrency.usd,
// initialTransactionPriority: TransactionPriority.slow,
// initialBalanceDisplayMode: BalanceDisplayMode.availableBalance);
// final priceStore = PriceStore();
// final walletStore =
// WalletStore(walletService: walletService, settingsStore: settingsStore);
// final syncStore = SyncStore(walletService: walletService);
// final balanceStore = BalanceStore(
// walletService: walletService,
// settingsStore: settingsStore,
// priceStore: priceStore);
// final loginStore = LoginStore(
// sharedPreferences: sharedPreferences, walletsService: walletListService);
// final seedLanguageStore = SeedLanguageStore();
// final sendTemplateStore = SendTemplateStore(templateSource: templates);
// final exchangeTemplateStore =
// ExchangeTemplateStore(templateSource: exchangeTemplates);
final walletCreationService = WalletCreationService();
final authService = AuthService();
@@ -132,42 +134,21 @@ void main() async {
walletInfoSource: walletInfoSource,
contactSource: contacts,
tradesSource: trades,
fiatConvertationService: fiatConvertationService,
// fiatConvertationService: fiatConvertationService,
templates: templates,
exchangeTemplates: exchangeTemplates,
initialMigrationVersion: 4);
setReactions(
settingsStore: settingsStore,
priceStore: priceStore,
syncStore: syncStore,
walletStore: walletStore,
walletService: walletService,
// authenticationStore: authenticationStore,
loginStore: loginStore);
// setReactions(
// settingsStore: settingsStore,
// priceStore: priceStore,
// syncStore: syncStore,
// walletStore: walletStore,
// walletService: walletService,
// // authenticationStore: authenticationStore,
// loginStore: loginStore);
runApp(MultiProvider(providers: [
Provider(create: (_) => sharedPreferences),
Provider(create: (_) => walletService),
Provider(create: (_) => walletListService),
Provider(create: (_) => userService),
Provider(create: (_) => settingsStore),
Provider(create: (_) => priceStore),
Provider(create: (_) => walletStore),
Provider(create: (_) => syncStore),
Provider(create: (_) => balanceStore),
// Provider(create: (_) => authenticationStore),
Provider(create: (_) => contacts),
Provider(create: (_) => nodes),
Provider(create: (_) => transactionDescriptions),
Provider(create: (_) => trades),
Provider(create: (_) => seedLanguageStore),
Provider(create: (_) => sendTemplateStore),
Provider(create: (_) => exchangeTemplateStore),
// Provider(create: (_) => appStore),
Provider(create: (_) => walletCreationService),
Provider(create: (_) => authService)
], child: CakeWalletApp()));
runApp(CakeWalletApp());
}
Future<void> initialSetup(
@@ -176,7 +157,7 @@ Future<void> initialSetup(
@required Box<WalletInfo> walletInfoSource,
@required Box<Contact> contactSource,
@required Box<Trade> tradesSource,
@required FiatConvertationService fiatConvertationService,
// @required FiatConvertationService fiatConvertationService,
@required Box<Template> templates,
@required Box<ExchangeTemplate> exchangeTemplates,
int initialMigrationVersion = 4}) async {
@@ -191,9 +172,7 @@ Future<void> initialSetup(
tradesSource: tradesSource,
templates: templates,
exchangeTemplates: exchangeTemplates);
await bootstrap(
fiatConvertationService: fiatConvertationService,
navigatorKey: navigatorKey);
await bootstrap(navigatorKey);
monero_wallet.onStartup();
}
@@ -220,22 +199,22 @@ class CakeWalletApp extends StatelessWidget {
class MaterialAppWithTheme extends StatelessWidget {
@override
Widget build(BuildContext context) {
final sharedPreferences = Provider.of<SharedPreferences>(context);
final walletService = Provider.of<WalletService>(context);
final walletListService = Provider.of<WalletListService>(context);
final userService = Provider.of<UserService>(context);
final settingsStore = Provider.of<SettingsStore>(context);
final priceStore = Provider.of<PriceStore>(context);
final walletStore = Provider.of<WalletStore>(context);
final syncStore = Provider.of<SyncStore>(context);
final balanceStore = Provider.of<BalanceStore>(context);
// final sharedPreferences = Provider.of<SharedPreferences>(context);
// final walletService = Provider.of<WalletService>(context);
// final walletListService = Provider.of<WalletListService>(context);
// final userService = Provider.of<UserService>(context);
// final settingsStore = Provider.of<SettingsStore>(context);
// final priceStore = Provider.of<PriceStore>(context);
// final walletStore = Provider.of<WalletStore>(context);
// final syncStore = Provider.of<SyncStore>(context);
// final balanceStore = Provider.of<BalanceStore>(context);
final theme = Provider.of<ThemeChanger>(context);
final currentLanguage = Provider.of<Language>(context);
final contacts = Provider.of<Box<Contact>>(context);
final nodes = Provider.of<Box<Node>>(context);
final trades = Provider.of<Box<Trade>>(context);
final transactionDescriptions =
Provider.of<Box<TransactionDescription>>(context);
// final currentLanguage = Provider.of<Language>(context);
// final contacts = Provider.of<Box<Contact>>(context);
// final nodes = Provider.of<Box<Node>>(context);
// final trades = Provider.of<Box<Trade>>(context);
// final transactionDescriptions =
// Provider.of<Box<TransactionDescription>>(context);
if (!isThemeChangerRegistered) {
setupThemeChangerStore(theme);
@@ -251,6 +230,10 @@ class MaterialAppWithTheme extends StatelessWidget {
_settingsStore.isDarkTheme ? Brightness.light : Brightness.dark;
final statusBarIconBrightness =
_settingsStore.isDarkTheme ? Brightness.light : Brightness.dark;
final authenticationStore = getIt.get<AuthenticationStore>();
final initialRoute = authenticationStore.state == AuthenticationState.denied
? Routes.welcome
: Routes.login;
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: statusBarColor,
@@ -258,7 +241,7 @@ class MaterialAppWithTheme extends StatelessWidget {
statusBarIconBrightness: statusBarIconBrightness));
return Root(
authenticationStore: getIt.get<AuthenticationStore>(),
authenticationStore: authenticationStore,
child: MaterialApp(
navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false,
@@ -270,24 +253,9 @@ class MaterialAppWithTheme extends StatelessWidget {
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
locale: Locale(currentLanguage.getCurrentLanguage()),
onGenerateRoute: (settings) => Router.generateRoute(
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: Routes.login, // FIXME: get initial route!
// home: Container(color: Colors.blue),
// locale: Locale(currentLanguage.getCurrentLanguage()),
onGenerateRoute: (settings) => Router.generateRoute(settings),
initialRoute: initialRoute,
));
}
}
@@ -1,5 +1,7 @@
import 'package:intl/intl.dart';
// FIXME: Hardcoded values; Works only for monero
final dateFormat = DateFormat('yyyy-MM');
final dates = {
"2014-5": 18844,

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