Merge redesign part 7.
M committed
Sep 15, 2020 at 23:35 UTC
95917b2cdbd335ffe0c5c6af34625a67a89f5cb7
31 files changed
+376
-270
analysis_options.yaml
-2
@@ -1,5 +1,3 @@
1
-include: package:pedantic/analysis_options.yaml
2
-
1
analyzer:
2
strong-mode:
3
implicit-casts: false
cw_monero/ios/Classes/monero_api.cpp
+2
-2
@@ -180,7 +180,7 @@ extern "C"
180
void change_current_wallet(Monero::Wallet *wallet)
181
{
182
m_wallet = wallet;
183
- // m_listener = nullptr;
183
+ m_listener = nullptr;
184
185
186
if (wallet != nullptr)
@@ -553,7 +553,7 @@ extern "C"
553
554
if (m_listener != nullptr)
555
{
556
- free(m_listener);
556
+ // free(m_listener);
557
}
558
559
m_listener = new MoneroWalletListener();
cw_monero/lib/wallet.dart
+4
-4
@@ -254,12 +254,12 @@ class SyncListner {
254
onNewBlock(syncHeight, left, ptc);
255
}
256
257
- if (newTransactionExist && onNewTransaction != null) {
258
- onNewTransaction();
257
+ if (newTransactionExist) {
258
+ onNewTransaction?.call();
259
}
260
261
- if (needToRefresh && onNeedToRefresh != null) {
262
- onNeedToRefresh();
261
+ if (needToRefresh) {
262
+ onNeedToRefresh?.call();
263
}
264
});
265
}
ios/Podfile.lock
+22
@@ -3,6 +3,13 @@ PODS:
3
- Flutter
4
- MTBBarcodeScanner
5
- SwiftProtobuf
6
+ - connectivity (0.0.1):
7
+ - Flutter
8
+ - Reachability
9
+ - connectivity_for_web (0.1.0):
10
+ - Flutter
11
+ - connectivity_macos (0.0.1):
12
+ - Flutter
13
- cw_monero (0.0.2):
14
- cw_monero/Boost (= 0.0.2)
15
- cw_monero/lmdb (= 0.0.2)
@@ -40,6 +47,7 @@ PODS:
47
- Flutter
48
- path_provider_macos (0.0.1):
49
- Flutter
50
+ - Reachability (3.2)
51
- share (0.0.1):
52
- Flutter
53
- shared_preferences (0.0.1):
@@ -62,6 +70,9 @@ PODS:
70
71
DEPENDENCIES:
72
- barcode_scan (from `.symlinks/plugins/barcode_scan/ios`)
73
+ - connectivity (from `.symlinks/plugins/connectivity/ios`)
74
+ - connectivity_for_web (from `.symlinks/plugins/connectivity_for_web/ios`)
75
+ - connectivity_macos (from `.symlinks/plugins/connectivity_macos/ios`)
76
- cw_monero (from `.symlinks/plugins/cw_monero/ios`)
77
- devicelocale (from `.symlinks/plugins/devicelocale/ios`)
78
- esys_flutter_share (from `.symlinks/plugins/esys_flutter_share/ios`)
@@ -86,11 +97,18 @@ DEPENDENCIES:
97
SPEC REPOS:
98
trunk:
99
- MTBBarcodeScanner
100
+ - Reachability
101
- SwiftProtobuf
102
103
EXTERNAL SOURCES:
104
barcode_scan:
105
:path: ".symlinks/plugins/barcode_scan/ios"
106
+ connectivity:
107
+ :path: ".symlinks/plugins/connectivity/ios"
108
+ connectivity_for_web:
109
+ :path: ".symlinks/plugins/connectivity_for_web/ios"
110
+ connectivity_macos:
111
+ :path: ".symlinks/plugins/connectivity_macos/ios"
112
cw_monero:
113
:path: ".symlinks/plugins/cw_monero/ios"
114
devicelocale:
@@ -134,6 +152,9 @@ EXTERNAL SOURCES:
152
153
SPEC CHECKSUMS:
154
barcode_scan: a5c27959edfafaa0c771905bad0b29d6d39e4479
155
+ connectivity: c4130b2985d4ef6fd26f9702e886bd5260681467
156
+ connectivity_for_web: 2b8584556930d4bd490d82b836bcf45067ce345b
157
+ connectivity_macos: e2e9731b6b22dda39eb1b128f6969d574460e191
158
cw_monero: 2e1f79929880cc2293b5bc1b25e28152e4d84649
159
devicelocale: feebbe5e7a30adb8c4f83185de1b50ff19b44f00
160
esys_flutter_share: 403498dab005b36ce1f8d7aff377e81f0621b0b4
@@ -146,6 +167,7 @@ SPEC CHECKSUMS:
167
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
168
path_provider_linux: 4d630dc393e1f20364f3e3b4a2ff41d9674a84e4
169
path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0
170
+ Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
171
share: 0b2c3e82132f5888bccca3351c504d0003b3b410
172
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
173
shared_preferences_linux: afefbfe8d921e207f01ede8b60373d9e3b566b78
ios/Runner.xcodeproj/project.pbxproj
+4
@@ -275,8 +275,10 @@
275
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
276
"${PODS_ROOT}/../Flutter/Flutter.framework",
277
"${BUILT_PRODUCTS_DIR}/MTBBarcodeScanner/MTBBarcodeScanner.framework",
278
+ "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework",
279
"${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework",
280
"${BUILT_PRODUCTS_DIR}/barcode_scan/barcode_scan.framework",
281
+ "${BUILT_PRODUCTS_DIR}/connectivity/connectivity.framework",
282
"${BUILT_PRODUCTS_DIR}/cw_monero/cw_monero.framework",
283
"${BUILT_PRODUCTS_DIR}/devicelocale/devicelocale.framework",
284
"${BUILT_PRODUCTS_DIR}/esys_flutter_share/esys_flutter_share.framework",
@@ -293,8 +295,10 @@
295
outputPaths = (
296
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
297
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MTBBarcodeScanner.framework",
298
+ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
299
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftProtobuf.framework",
300
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/barcode_scan.framework",
301
+ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/connectivity.framework",
302
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/cw_monero.framework",
303
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/devicelocale.framework",
304
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/esys_flutter_share.framework",
lib/bitcoin/bitcoin_transaction_history.dart
-2
@@ -9,8 +9,6 @@ import 'package:cake_wallet/bitcoin/electrum.dart';
9
10
part 'bitcoin_transaction_history.g.dart';
11
12
-// TODO: Think about another transaction store for bitcoin transaction history..
13
-
12
const _transactionsHistoryFileName = 'transactions.json';
13
14
class BitcoinTransactionHistory = BitcoinTransactionHistoryBase
lib/bitcoin/bitcoin_wallet.dart
+11
-29
@@ -1,39 +1,29 @@
1
import 'dart:async';
2
-import 'dart:typed_data';
2
import 'dart:convert';
3
+import 'package:mobx/mobx.dart';
4
+import 'package:bip39/bip39.dart' as bip39;
5
+import 'package:flutter/foundation.dart';
6
+import 'package:rxdart/rxdart.dart';
7
+import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
8
import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
5
-import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
9
import 'package:cake_wallet/bitcoin/bitcoin_transaction_no_inputs_exception.dart';
10
import 'package:cake_wallet/bitcoin/bitcoin_transaction_wrong_balance_exception.dart';
11
import 'package:cake_wallet/bitcoin/bitcoin_unspent.dart';
12
import 'package:cake_wallet/bitcoin/bitcoin_wallet_keys.dart';
13
+import 'package:cake_wallet/bitcoin/electrum.dart';
14
import 'package:cake_wallet/bitcoin/pending_bitcoin_transaction.dart';
15
import 'package:cake_wallet/bitcoin/script_hash.dart';
16
import 'package:cake_wallet/bitcoin/utils.dart';
17
import 'package:cake_wallet/src/domain/bitcoin/bitcoin_amount_format.dart';
14
-import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
18
import 'package:cake_wallet/src/domain/common/sync_status.dart';
16
-import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
19
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
18
-import 'package:cw_monero/transaction_history.dart';
19
-import 'package:flutter/cupertino.dart';
20
-import 'package:mobx/mobx.dart';
21
-import 'package:bip39/bip39.dart' as bip39;
22
-import 'package:flutter/foundation.dart';
23
-import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
24
-import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
25
-import 'package:cake_wallet/src/domain/common/wallet_type.dart';
20
+import 'package:cake_wallet/src/domain/common/wallet_info.dart';
21
import 'package:cake_wallet/bitcoin/bitcoin_transaction_history.dart';
22
import 'package:cake_wallet/bitcoin/bitcoin_address_record.dart';
23
import 'package:cake_wallet/bitcoin/file.dart';
29
-import 'package:cake_wallet/bitcoin/electrum.dart';
24
import 'package:cake_wallet/bitcoin/bitcoin_balance.dart';
25
import 'package:cake_wallet/src/domain/common/node.dart';
26
import 'package:cake_wallet/core/wallet_base.dart';
33
-import 'package:rxdart/rxdart.dart';
34
-import 'package:hex/hex.dart';
35
-import 'package:cake_wallet/di.dart';
36
-import 'package:shared_preferences/shared_preferences.dart';
27
28
part 'bitcoin_wallet.g.dart';
29
@@ -44,8 +34,8 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
34
{@required this.eclient,
35
@required this.path,
36
@required String password,
47
- @required this.name,
48
- List<BitcoinAddressRecord> initialAddresses,
37
+ @required WalletInfo walletInfo,
38
+ @required List<BitcoinAddressRecord> initialAddresses,
39
int accountIndex = 0,
40
this.transactionHistory,
41
this.mnemonic,
@@ -60,9 +50,7 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
50
syncStatus = NotConnectedSyncStatus(),
51
_password = password,
52
_accountIndex = accountIndex,
63
- _addressesKeys = {} {
64
- type = WalletType.bitcoin;
65
- currency = CryptoCurrency.btc;
53
+ super(walletInfo) {
54
_scripthashesUpdateSubject = {};
55
}
56
@@ -114,7 +102,6 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
102
return BitcoinWallet._internal(
103
eclient: eclient,
104
path: walletPath,
117
- name: name,
105
mnemonic: mnemonic,
106
password: password,
107
accountIndex: accountIndex,
@@ -130,9 +117,6 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
117
final ElectrumClient eclient;
118
final String mnemonic;
119
133
- @override
134
- String name;
135
-
120
@override
121
@observable
122
String address;
@@ -147,8 +131,6 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
131
132
ObservableList<BitcoinAddressRecord> addresses;
133
150
- Map<String, bitcoin.ECPair> _addressesKeys;
151
-
134
List<String> get scriptHashes =>
135
addresses.map((addr) => scriptHash(addr.address)).toList();
136
@@ -161,8 +143,8 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
143
BitcoinWalletKeys get keys => BitcoinWalletKeys(
144
wif: hd.wif, privateKey: hd.privKey, publicKey: hd.pubKey);
145
146
+ final String _password;
147
int _accountIndex;
165
- String _password;
148
Map<String, BehaviorSubject<Object>> _scripthashesUpdateSubject;
149
150
Future<void> init() async {
lib/bitcoin/file.dart
+2
-4
@@ -1,5 +1,4 @@
1
import 'dart:io';
2
-import 'dart:convert';
2
import 'package:cake_wallet/bitcoin/key.dart';
3
import 'package:encrypt/encrypt.dart' as encrypt;
4
import 'package:flutter/foundation.dart';
@@ -28,14 +27,13 @@ Future<void> writeData(
27
f.writeAsStringSync(encrypted);
28
}
29
31
-Future<String> read(
32
- {@required String path, @required String password}) async {
30
+Future<String> read({@required String path, @required String password}) async {
31
final file = File(path);
32
33
if (!file.existsSync()) {
34
file.createSync();
35
}
38
-
36
+
37
final encrypted = file.readAsStringSync();
38
39
return decode(password: password, data: encrypted);
lib/core/auth_service.dart
-1
@@ -1,4 +1,3 @@
1
-import 'package:flutter/foundation.dart';
1
import 'package:mobx/mobx.dart';
2
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
3
import 'package:shared_preferences/shared_preferences.dart';
lib/core/wallet_base.dart
+32
-8
@@ -1,4 +1,5 @@
1
import 'package:flutter/foundation.dart';
2
+import 'package:cake_wallet/src/domain/common/wallet_info.dart';
3
import 'package:cake_wallet/core/pending_transaction.dart';
4
import 'package:cake_wallet/core/transaction_history.dart';
5
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
@@ -7,18 +8,43 @@ import 'package:cake_wallet/src/domain/common/sync_status.dart';
8
import 'package:cake_wallet/src/domain/common/node.dart';
9
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
10
11
+// FIXME: Move me.
12
+CryptoCurrency currencyForWalletType(WalletType type) {
13
+ switch (type) {
14
+ case WalletType.bitcoin:
15
+ return CryptoCurrency.btc;
16
+ case WalletType.monero:
17
+ return CryptoCurrency.xmr;
18
+ default:
19
+ return null;
20
+ }
21
+}
22
+
23
abstract class WalletBase<BalaceType> {
11
- WalletType type;
24
+ WalletBase(this.walletInfo);
25
+
26
+ static String idFor(String name, WalletType type) =>
27
+ walletTypeToString(type).toLowerCase() + '_' + name;
28
+
29
+ WalletInfo walletInfo;
30
+
31
+ WalletType get type => walletInfo.type;
32
13
- CryptoCurrency currency;
33
+ CryptoCurrency get currency => currencyForWalletType(type);
34
15
- String get name;
35
+ String get id => walletInfo.id;
36
17
- String address;
37
+ String get name => walletInfo.name;
38
19
- BalaceType balance;
39
+ String get address;
40
21
- SyncStatus syncStatus;
41
+ set address(String address);
42
+
43
+ BalaceType get balance;
44
+
45
+ SyncStatus get syncStatus;
46
+
47
+ set syncStatus(SyncStatus status);
48
49
String get seed;
50
@@ -26,8 +52,6 @@ abstract class WalletBase<BalaceType> {
52
53
TransactionHistoryBase transactionHistory;
54
29
- String get id => walletTypeToString(type).toLowerCase() + '_' + name;
30
-
55
Future<void> connectToNode({@required Node node});
56
57
Future<void> startSync();
lib/core/wallet_creation_service.dart
+2
-11
@@ -1,3 +1,4 @@
1
+import 'package:cake_wallet/di.dart';
2
import 'package:flutter/foundation.dart';
3
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
4
import 'package:shared_preferences/shared_preferences.dart';
@@ -32,17 +33,7 @@ class WalletCreationService {
33
34
void changeWalletType({@required WalletType type}) {
35
this.type = type;
35
-
36
- switch (type) {
37
- case WalletType.monero:
38
- _service = MoneroWalletService();
39
- break;
40
- case WalletType.bitcoin:
41
- _service = BitcoinWalletService();
42
- break;
43
- default:
44
- break;
45
- }
36
+ _service = getIt.get<WalletService>(param1: type);
37
}
38
39
Future<void> create(WalletCredentials credentials) async {
lib/core/wallet_credentials.dart
+6
-2
@@ -1,6 +1,10 @@
1
+import 'package:cake_wallet/src/domain/common/wallet_info.dart';
2
+
3
abstract class WalletCredentials {
2
- WalletCredentials({this.name, this.password});
4
+ WalletCredentials({this.name, this.password, this.height});
5
6
final String name;
7
+ final int height;
8
String password;
6
-}
\ No newline at end of file
9
+ WalletInfo walletInfo;
10
+}
lib/di.dart
+20
@@ -1,7 +1,11 @@
1
+import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
2
import 'package:cake_wallet/core/contact_service.dart';
3
+import 'package:cake_wallet/core/wallet_service.dart';
4
+import 'package:cake_wallet/monero/monero_wallet_service.dart';
5
import 'package:cake_wallet/src/domain/common/contact.dart';
6
import 'package:cake_wallet/src/domain/common/node.dart';
7
import 'package:cake_wallet/src/domain/exchange/trade.dart';
8
+// import 'package:cake_wallet/src/domain/services/wallet_service.dart';
9
import 'package:cake_wallet/src/screens/contact/contact_list_page.dart';
10
import 'package:cake_wallet/src/screens/contact/contact_page.dart';
11
import 'package:cake_wallet/src/screens/exchange_trade/exchange_confirm_page.dart';
@@ -367,6 +371,22 @@ Future setup(
371
372
getIt.registerFactory(
373
() => ExchangeTemplatePage(getIt.get<ExchangeViewModel>()));
374
+
375
+ getIt.registerFactory(() => MoneroWalletService(walletInfoSource));
376
+
377
+ getIt.registerFactory(() => BitcoinWalletService());
378
+
379
+ getIt.registerFactoryParam<WalletService, WalletType, void>(
380
+ (WalletType param1, __) {
381
+ switch (param1) {
382
+ case WalletType.monero:
383
+ return getIt.get<MoneroWalletService>();
384
+ case WalletType.bitcoin:
385
+ return getIt.get<BitcoinWalletService>();
386
+ default:
387
+ return null;
388
+ }
389
+ });
390
}
391
392
void setupThemeChangerStore(ThemeChanger themeChanger) {
lib/main.dart
+13
-3
@@ -251,6 +251,17 @@ class MaterialAppWithTheme extends StatelessWidget {
251
_settingsStore.isDarkTheme ? Brightness.light : Brightness.dark;
252
final statusBarIconBrightness =
253
_settingsStore.isDarkTheme ? Brightness.light : Brightness.dark;
254
+ final authenticationStore = getIt.get<AuthenticationStore>();
255
+ String initialRoute;
256
+
257
+ switch (authenticationStore.state) {
258
+ case AuthenticationState.denied:
259
+ initialRoute = Routes.welcome;
260
+ break;
261
+ default:
262
+ initialRoute = Routes.login;
263
+ break;
264
+ }
265
266
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
267
statusBarColor: statusBarColor,
@@ -258,7 +269,7 @@ class MaterialAppWithTheme extends StatelessWidget {
269
statusBarIconBrightness: statusBarIconBrightness));
270
271
return Root(
261
- authenticationStore: getIt.get<AuthenticationStore>(),
272
+ authenticationStore: authenticationStore,
273
child: MaterialApp(
274
navigatorKey: navigatorKey,
275
debugShowCheckedModeBanner: false,
@@ -286,8 +297,7 @@ class MaterialAppWithTheme extends StatelessWidget {
297
nodes: nodes,
298
trades: trades,
299
transactionDescriptions: transactionDescriptions),
289
- initialRoute: Routes.login, // FIXME: get initial route!
290
- // home: Container(color: Colors.blue),
300
+ initialRoute: initialRoute,
301
));
302
}
303
}
lib/monero/monero_wallet.dart
+63
-37
@@ -1,3 +1,4 @@
1
+import 'package:cake_wallet/src/domain/common/wallet_info.dart';
2
import 'package:cake_wallet/src/domain/monero/monero_transaction_creation_credentials.dart';
3
import 'package:flutter/foundation.dart';
4
import 'package:mobx/mobx.dart';
@@ -9,36 +10,29 @@ import 'package:cake_wallet/monero/monero_transaction_history.dart';
10
import 'package:cake_wallet/monero/monero_subaddress_list.dart';
11
import 'package:cake_wallet/monero/monero_account_list.dart';
12
import 'package:cake_wallet/core/wallet_base.dart';
12
-import 'package:cake_wallet/core/transaction_history.dart';
13
-import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
14
-import 'package:cake_wallet/src/domain/common/wallet_type.dart';
13
import 'package:cake_wallet/src/domain/common/sync_status.dart';
14
import 'package:cake_wallet/src/domain/monero/account.dart';
17
-import 'package:cake_wallet/src/domain/monero/account_list.dart';
15
import 'package:cake_wallet/src/domain/monero/subaddress.dart';
16
import 'package:cake_wallet/src/domain/common/node.dart';
17
import 'package:cake_wallet/core/pending_transaction.dart';
18
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
22
-import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart'
23
- as cfa;
19
20
part 'monero_wallet.g.dart';
21
22
+const moneroBlockSize = 1000;
23
+
24
class MoneroWallet = MoneroWalletBase with _$MoneroWallet;
25
26
abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
30
- MoneroWalletBase({String filename, this.isRecovery = false})
27
+ MoneroWalletBase({String filename, WalletInfo walletInfo})
28
: transactionHistory = MoneroTransactionHistory(),
29
accountList = MoneroAccountList(),
33
- subaddressList = MoneroSubaddressList() {
30
+ subaddressList = MoneroSubaddressList(),
31
+ super(walletInfo) {
32
_filename = filename;
33
balance = MoneroBalance(
34
fullBalance: monero_wallet.getFullBalance(accountIndex: 0),
35
unlockedBalance: monero_wallet.getFullBalance(accountIndex: 0));
38
- currency = CryptoCurrency.xmr;
39
- type = WalletType.monero;
40
- _rct = reaction(
41
- (_) => syncStatus, (SyncStatus status) => print(status.toString()));
36
_onAccountChangeReaction = reaction((_) => account, (Account account) {
37
subaddressList.update(accountIndex: account.id);
38
subaddress = subaddressList.subaddresses.first;
@@ -46,8 +40,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
40
});
41
}
42
49
- ReactionDisposer _rct;
50
-
43
@override
44
final MoneroTransactionHistory transactionHistory;
45
@@ -57,15 +49,17 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
49
@observable
50
Subaddress subaddress;
51
52
+ @override
53
@observable
54
SyncStatus syncStatus;
55
56
@override
64
- String get name => _filename.split('/').last;
57
+ @observable
58
+ String address;
59
60
@override
61
@observable
68
- String address;
62
+ MoneroBalance balance;
63
64
@override
65
String get seed => monero_wallet.getSeed();
@@ -81,8 +75,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
75
76
final MoneroAccountList accountList;
77
84
- bool isRecovery;
85
-
78
String _filename;
79
SyncListner _listener;
80
ReactionDisposer _onAccountChangeReaction;
@@ -107,8 +99,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
99
100
@override
101
Future<void> connectToNode({@required Node node}) async {
110
- final node = Node(uri: 'xmr-node-uk.cakewallet.com:18081');
111
-
102
try {
103
syncStatus = ConnectingSyncStatus();
104
await monero_wallet.setupNode(
@@ -127,6 +117,10 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
117
118
@override
119
Future<void> startSync() async {
120
+ try {
121
+ _setInitialHeight();
122
+ } catch (_) {}
123
+
124
try {
125
syncStatus = StartingSyncStatus();
126
monero_wallet.startRefresh();
@@ -180,25 +174,18 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
174
175
@override
176
Future<void> save() async {
183
-// if (_isSaving) {
184
-// return;
185
-// }
186
-
187
- try {
188
-// _isSaving = true;
189
- await monero_wallet.store();
190
-// _isSaving = false;
191
- } catch (e) {
192
- print(e);
193
-// _isSaving = false;
194
- rethrow;
195
- }
177
+ await monero_wallet.store();
178
}
179
180
Future<int> getNodeHeight() async => monero_wallet.getNodeHeight();
181
182
Future<bool> isConnected() async => monero_wallet.isConnected();
183
184
+ Future<void> setAsRecovered() async {
185
+ walletInfo.isRecovery = false;
186
+ await walletInfo.save();
187
+ }
188
+
189
void _setListeners() {
190
_listener?.stop();
191
_listener = monero_wallet.setListeners(
@@ -206,6 +193,41 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
193
_listener.start();
194
}
195
196
+ void _setInitialHeight() {
197
+ if (walletInfo.isRecovery) {
198
+ return;
199
+ }
200
+
201
+ final currentHeight = getCurrentHeight();
202
+ print('currentHeight $currentHeight');
203
+
204
+ if (currentHeight <= 1) {
205
+ final height = _getHeightByDate(walletInfo.date);
206
+ monero_wallet.setRecoveringFromSeed(isRecovery: true);
207
+ monero_wallet.setRefreshFromBlockHeight(height: height);
208
+ }
209
+ }
210
+
211
+ int _getHeightDistance(DateTime date) {
212
+ final distance =
213
+ DateTime.now().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
214
+ final daysTmp = (distance / 86400).round();
215
+ final days = daysTmp < 1 ? 1 : daysTmp;
216
+
217
+ return days * 1000;
218
+ }
219
+
220
+ int _getHeightByDate(DateTime date) {
221
+ final nodeHeight = monero_wallet.getNodeHeightSync();
222
+ final heightDistance = _getHeightDistance(date);
223
+
224
+ if (nodeHeight <= 0) {
225
+ return 0;
226
+ }
227
+
228
+ return nodeHeight - heightDistance;
229
+ }
230
+
231
void _askForUpdateBalance() {
232
final fullBalance = _getFullBalance();
233
final unlockedBalance = _getUnlockedBalance();
@@ -236,13 +258,17 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
258
259
syncStatus = SyncedSyncStatus();
260
239
- if (isRecovery) {
261
+ if (walletInfo.isRecovery) {
262
_askForUpdateTransactionHistory();
263
}
264
243
-// if (isRecovery && (nodeHeight - currentHeight < moneroBlockSize)) {
244
-// await setAsRecovered();
245
-// }
265
+ final currentHeight = getCurrentHeight();
266
+ final nodeHeight = monero_wallet.getNodeHeightSync();
267
+
268
+ if (walletInfo.isRecovery &&
269
+ (nodeHeight - currentHeight < moneroBlockSize)) {
270
+ await setAsRecovered();
271
+ }
272
273
await save();
274
}
lib/monero/monero_wallet_service.dart
+31
-19
@@ -1,12 +1,14 @@
1
import 'dart:io';
2
-
2
+import 'package:cake_wallet/core/wallet_base.dart';
3
+import 'package:hive/hive.dart';
4
+import 'package:cw_monero/wallet_manager.dart' as monero_wallet_manager;
5
+import 'package:cw_monero/wallet.dart' as monero_wallet;
6
import 'package:cake_wallet/monero/monero_wallet.dart';
7
import 'package:cake_wallet/core/wallet_credentials.dart';
8
import 'package:cake_wallet/core/wallet_service.dart';
9
import 'package:cake_wallet/src/domain/common/pathForWallet.dart';
10
+import 'package:cake_wallet/src/domain/common/wallet_info.dart';
11
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
8
-import 'package:cw_monero/wallet_manager.dart' as monero_wallet_manager;
9
-import 'package:cw_monero/wallet.dart' as monero_wallet;
12
13
class MoneroNewWalletCredentials extends WalletCredentials {
14
MoneroNewWalletCredentials({String name, String password, this.language})
@@ -17,11 +19,10 @@ class MoneroNewWalletCredentials extends WalletCredentials {
19
20
class MoneroRestoreWalletFromSeedCredentials extends WalletCredentials {
21
MoneroRestoreWalletFromSeedCredentials(
20
- {String name, String password, this.mnemonic, this.height})
21
- : super(name: name, password: password);
22
+ {String name, String password, int height, this.mnemonic})
23
+ : super(name: name, password: password, height: height);
24
25
final String mnemonic;
24
- final int height;
26
}
27
28
class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials {
@@ -32,32 +33,35 @@ class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials {
33
this.address,
34
this.viewKey,
35
this.spendKey,
35
- this.height})
36
- : super(name: name, password: password);
36
+ int height})
37
+ : super(name: name, password: password, height: height);
38
39
final String language;
40
final String address;
41
final String viewKey;
42
final String spendKey;
42
- final int height;
43
}
44
45
class MoneroWalletService extends WalletService<
46
MoneroNewWalletCredentials,
47
MoneroRestoreWalletFromSeedCredentials,
48
MoneroRestoreWalletFromKeysCredentials> {
49
+ MoneroWalletService(this.walletInfoSource);
50
+
51
+ final Box<WalletInfo> walletInfoSource;
52
+
53
@override
54
Future<MoneroWallet> create(MoneroNewWalletCredentials credentials) async {
55
try {
56
final path =
57
await pathForWallet(name: credentials.name, type: WalletType.monero);
54
-
58
await monero_wallet_manager.createWallet(
59
path: path,
60
password: credentials.password,
61
language: credentials.language);
59
-
60
- final wallet = MoneroWallet(filename: monero_wallet.getFilename());
62
+ final wallet = MoneroWallet(
63
+ filename: monero_wallet.getFilename(),
64
+ walletInfo: credentials.walletInfo);
65
await wallet.init();
66
67
return wallet;
@@ -84,8 +88,16 @@ class MoneroWalletService extends WalletService<
88
Future<MoneroWallet> openWallet(String name, String password) async {
89
try {
90
final path = await pathForWallet(name: name, type: WalletType.monero);
91
+ final file = File(path);
92
+ final stat = await file.stat();
93
+ print(stat.changed);
94
+ print(stat.modified);
95
+ print(stat.accessed);
96
monero_wallet_manager.openWallet(path: path, password: password);
88
- final wallet = MoneroWallet(filename: monero_wallet.getFilename());
97
+ final walletInfo = walletInfoSource.values.firstWhere(
98
+ (info) => info.id == WalletBase.idFor(name, WalletType.monero));
99
+ final wallet = MoneroWallet(
100
+ filename: monero_wallet.getFilename(), walletInfo: walletInfo);
101
await wallet.init();
102
103
return wallet;
@@ -107,7 +119,6 @@ class MoneroWalletService extends WalletService<
119
try {
120
final path =
121
await pathForWallet(name: credentials.name, type: WalletType.monero);
110
-
122
await monero_wallet_manager.restoreFromKeys(
123
path: path,
124
password: credentials.password,
@@ -116,8 +127,9 @@ class MoneroWalletService extends WalletService<
127
address: credentials.address,
128
viewKey: credentials.viewKey,
129
spendKey: credentials.spendKey);
119
-
120
- final wallet = MoneroWallet(filename: monero_wallet.getFilename());
130
+ final wallet = MoneroWallet(
131
+ filename: monero_wallet.getFilename(),
132
+ walletInfo: credentials.walletInfo);
133
await wallet.init();
134
135
return wallet;
@@ -134,14 +146,14 @@ class MoneroWalletService extends WalletService<
146
try {
147
final path =
148
await pathForWallet(name: credentials.name, type: WalletType.monero);
137
-
149
await monero_wallet_manager.restoreFromSeed(
150
path: path,
151
password: credentials.password,
152
seed: credentials.mnemonic,
153
restoreHeight: credentials.height);
143
-
144
- final wallet = MoneroWallet(filename: monero_wallet.getFilename());
154
+ final wallet = MoneroWallet(
155
+ filename: monero_wallet.getFilename(),
156
+ walletInfo: credentials.walletInfo);
157
await wallet.init();
158
159
return wallet;
lib/reactions/bootstrap.dart
+25
-33
@@ -1,28 +1,20 @@
1
import 'dart:async';
2
-
3
-import 'package:cake_wallet/core/key_service.dart';
4
-import 'package:cake_wallet/router.dart';
5
-import 'package:cake_wallet/routes.dart';
6
-import 'package:cake_wallet/src/domain/common/sync_status.dart';
7
-import 'package:cake_wallet/src/screens/auth/auth_page.dart';
8
-import 'package:cake_wallet/src/screens/dashboard/dashboard_page.dart';
2
import 'package:flutter/cupertino.dart';
3
import 'package:flutter/widgets.dart';
4
import 'package:mobx/mobx.dart';
5
import 'package:cake_wallet/di.dart';
6
import 'package:shared_preferences/shared_preferences.dart';
7
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
15
-import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
16
-import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
17
-import 'package:cake_wallet/monero/monero_wallet_service.dart';
8
+import 'package:connectivity/connectivity.dart';
9
+import 'package:cake_wallet/core/key_service.dart';
10
+import 'package:cake_wallet/router.dart';
11
+import 'package:cake_wallet/src/domain/common/sync_status.dart';
12
import 'package:cake_wallet/core/wallet_base.dart';
13
import 'package:cake_wallet/core/wallet_service.dart';
14
import 'package:cake_wallet/store/app_store.dart';
15
import 'package:cake_wallet/store/settings_store.dart';
16
import 'package:cake_wallet/store/authentication_store.dart';
17
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
24
-import 'package:cake_wallet/src/domain/common/secret_store_key.dart';
25
-import 'package:cake_wallet/src/domain/common/encrypt.dart';
18
import 'package:cake_wallet/src/domain/services/fiat_convertation_service.dart';
19
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
20
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
@@ -36,19 +28,7 @@ Future<void> loadCurrentWallet() async {
28
final type = deserializeFromInt(typeRaw);
29
final password =
30
await getIt.get<KeyService>().getWalletPassword(walletName: name);
39
-
40
- WalletService _service;
41
- switch (type) {
42
- case WalletType.monero:
43
- _service = MoneroWalletService();
44
- break;
45
- case WalletType.bitcoin:
46
- _service = BitcoinWalletService();
47
- break;
48
- default:
49
- break;
50
- }
51
-
31
+ final _service = getIt.get<WalletService>(param1: type);
32
final wallet = await _service.openWallet(name, password);
33
appStore.wallet = wallet;
34
}
@@ -79,9 +59,6 @@ Future<void> bootstrap(
59
60
if (state == AuthenticationState.installed) {
61
await loadCurrentWallet();
82
- }
83
-
84
- if (state == AuthenticationState.installed) {
62
await navigatorKey.currentState
63
.pushAndRemoveUntil(createLoginRoute(), (_) => false);
64
}
@@ -101,16 +78,31 @@ Future<void> bootstrap(
78
reaction((_) => getIt.get<AppStore>().wallet, (WalletBase wallet) async {
79
_onWalletSyncStatusChangeReaction?.reaction?.dispose();
80
_reconnectionTimer?.cancel();
104
- _onWalletSyncStatusChangeReaction = reaction(
105
- (_) => wallet.syncStatus is ConnectedSyncStatus,
106
- (Object _) async => await wallet.startSync());
81
+ _onWalletSyncStatusChangeReaction =
82
+ reaction((_) => wallet.syncStatus, (SyncStatus status) async {
83
+ if (status is ConnectedSyncStatus) {
84
+ await wallet.startSync();
85
+ }
86
+ });
87
88
_reconnectionTimer = Timer.periodic(Duration(seconds: 5), (_) async {
89
+ final connectivityResult = await (Connectivity().checkConnectivity());
90
+
91
+ if (connectivityResult == ConnectivityResult.none) {
92
+ wallet.syncStatus = FailedSyncStatus();
93
+ return;
94
+ }
95
+
96
if (wallet.syncStatus is LostConnectionSyncStatus ||
97
wallet.syncStatus is FailedSyncStatus) {
98
try {
112
- await wallet.connectToNode(
113
- node: settingsStore.getCurrentNode(wallet.type));
99
+ final alive =
100
+ await settingsStore.getCurrentNode(wallet.type).requestNode();
101
+
102
+ if (alive) {
103
+ await wallet.connectToNode(
104
+ node: settingsStore.getCurrentNode(wallet.type));
105
+ }
106
} catch (_) {}
107
}
108
});
lib/src/domain/common/fs_migration.dart
+22
-22
@@ -82,28 +82,28 @@ Future<void> migrate_wallets({Directory appDocDir}) async {
82
Future<void> migrate_ios_wallet_info(
83
{@required Directory appDocDir,
84
@required Box<WalletInfo> walletsInfo}) async {
85
- final walletsDir = Directory('${appDocDir.path}/wallets');
86
- final moneroWalletsDir = Directory('${walletsDir.path}/monero');
87
-
88
- moneroWalletsDir.listSync().forEach((item) async {
89
- try {
90
- if (item is Directory) {
91
- final name = item.path.split('/').last;
92
- final configFile = File('${item.path}/$name.json');
93
- final config =
94
- json.decode(configFile.readAsStringSync()) as Map<String, dynamic>;
95
- final isRecovery = config["isRecovery"] as bool ?? false;
96
- final id =
97
- walletTypeToString(WalletType.monero).toLowerCase() + '_' + name;
98
- final walletInfo =
99
- WalletInfo(id: id, name: name, isRecovery: isRecovery);
100
-
101
- await walletsInfo.add(walletInfo);
102
- }
103
- } catch (e) {
104
- print(e.toString());
105
- }
106
- });
85
+ // final walletsDir = Directory('${appDocDir.path}/wallets');
86
+ // final moneroWalletsDir = Directory('${walletsDir.path}/monero');
87
+
88
+ // moneroWalletsDir.listSync().forEach((item) async {
89
+ // try {
90
+ // if (item is Directory) {
91
+ // final name = item.path.split('/').last;
92
+ // final configFile = File('${item.path}/$name.json');
93
+ // final config =
94
+ // json.decode(configFile.readAsStringSync()) as Map<String, dynamic>;
95
+ // final isRecovery = config["isRecovery"] as bool ?? false;
96
+ // final id =
97
+ // walletTypeToString(WalletType.monero).toLowerCase() + '_' + name;
98
+ // final walletInfo =
99
+ // WalletInfo(id: id, name: name, isRecovery: isRecovery);
100
+
101
+ // await walletsInfo.add(walletInfo);
102
+ // }
103
+ // } catch (e) {
104
+ // print(e.toString());
105
+ // }
106
+ // });
107
}
108
109
Future<void> migrate_ios_trades_list(
lib/src/domain/common/wallet_info.dart
+28
-3
@@ -1,12 +1,26 @@
1
-import 'package:cake_wallet/src/domain/common/wallet_type.dart';
1
+import 'package:flutter/foundation.dart';
2
import 'package:hive/hive.dart';
3
+import 'package:cake_wallet/src/domain/common/wallet_type.dart';
4
5
part 'wallet_info.g.dart';
6
7
@HiveType(typeId: 4)
8
class WalletInfo extends HiveObject {
8
- WalletInfo(
9
- {this.id, this.name, this.type, this.isRecovery, this.restoreHeight});
9
+ WalletInfo(this.id, this.name, this.type, this.isRecovery, this.restoreHeight,
10
+ this.timestamp, this.dirPath, this.path);
11
+
12
+ factory WalletInfo.external(
13
+ {@required String id,
14
+ @required String name,
15
+ @required WalletType type,
16
+ @required bool isRecovery,
17
+ @required int restoreHeight,
18
+ @required DateTime date,
19
+ @required String dirPath,
20
+ @required String path}) {
21
+ return WalletInfo(id, name, type, isRecovery, restoreHeight,
22
+ date.millisecondsSinceEpoch ?? 0, dirPath, path);
23
+ }
24
25
static const boxName = 'WalletInfo';
26
@@ -24,4 +38,15 @@ class WalletInfo extends HiveObject {
38
39
@HiveField(4)
40
int restoreHeight;
41
+
42
+ @HiveField(5)
43
+ int timestamp;
44
+
45
+ @HiveField(6)
46
+ String dirPath;
47
+
48
+ @HiveField(7)
49
+ String path;
50
+
51
+ DateTime get date => DateTime.fromMillisecondsSinceEpoch(timestamp);
52
}
lib/src/domain/monero/monero_wallet.dart
+13
-12
@@ -47,18 +47,19 @@ class MoneroWallet extends Wallet {
47
String name,
48
bool isRecovery = false,
49
int restoreHeight = 0}) async {
50
- const type = WalletType.monero;
51
- final id = walletTypeToString(type).toLowerCase() + '_' + name;
52
- final walletInfo = WalletInfo(
53
- id: id,
54
- name: name,
55
- type: type,
56
- isRecovery: isRecovery,
57
- restoreHeight: restoreHeight);
58
- await walletInfoSource.add(walletInfo);
59
-
60
- return await configured(
61
- walletInfo: walletInfo, walletInfoSource: walletInfoSource);
50
+ // const type = WalletType.monero;
51
+ // final id = walletTypeToString(type).toLowerCase() + '_' + name;
52
+ // final walletInfo = WalletInfo(
53
+ // id: id,
54
+ // name: name,
55
+ // type: type,
56
+ // isRecovery: isRecovery,
57
+ // restoreHeight: restoreHeight);
58
+ // await walletInfoSource.add(walletInfo);
59
+
60
+ // return await configured(
61
+ // walletInfo: walletInfo, walletInfoSource: walletInfoSource);
62
+ return null;
63
}
64
65
static Future<MoneroWallet> load(
lib/src/domain/monero/monero_wallets_manager.dart
+2
-3
@@ -12,8 +12,6 @@ import 'package:cake_wallet/src/domain/common/wallet.dart';
12
import 'package:cake_wallet/src/domain/monero/monero_wallet.dart';
13
import 'package:cake_wallet/src/domain/common/wallet_description.dart';
14
15
-
16
-
15
class MoneroWalletsManager extends WalletsManager {
16
MoneroWalletsManager({@required this.walletInfoSource});
17
@@ -27,7 +25,8 @@ class MoneroWalletsManager extends WalletsManager {
25
const isRecovery = false;
26
final path = await pathForWallet(name: name, type: WalletType.monero);
27
30
- await monero_wallet_manager.createWallet(path: path, password: password, language: language);
28
+ await monero_wallet_manager.createWallet(
29
+ path: path, password: password, language: language);
30
31
final wallet = await MoneroWallet.createdWallet(
32
walletInfoSource: walletInfoSource,
lib/src/reactions/set_reactions.dart
+10
-10
@@ -65,18 +65,18 @@ void onSyncStatusChange(
65
{SyncStore syncStore,
66
WalletStore walletStore,
67
SettingsStore settingsStore}) {
68
- _onSyncStatusChangeDisposer?.call();
68
+ // _onSyncStatusChangeDisposer?.call();
69
70
- reaction((_) => syncStore.status, (SyncStatus status) async {
71
- if (status is ConnectedSyncStatus) {
72
- await walletStore.startSync();
73
- }
70
+ // reaction((_) => syncStore.status, (SyncStatus status) async {
71
+ // if (status is ConnectedSyncStatus) {
72
+ // await walletStore.startSync();
73
+ // }
74
75
- // Reconnect to the node if the app is not started sync after 30 seconds
76
- if (status is StartingSyncStatus) {
77
- startReconnectionObserver(syncStore: syncStore, walletStore: walletStore);
78
- }
79
- });
75
+ // // Reconnect to the node if the app is not started sync after 30 seconds
76
+ // if (status is StartingSyncStatus) {
77
+ // startReconnectionObserver(syncStore: syncStore, walletStore: walletStore);
78
+ // }
79
+ // });
80
}
81
82
void startReconnectionObserver({SyncStore syncStore, WalletStore walletStore}) {
lib/view_model/exchange/exchange_trade_view_model.dart
+6
-11
@@ -14,7 +14,8 @@ import 'package:cake_wallet/generated/i18n.dart';
14
15
part 'exchange_trade_view_model.g.dart';
16
17
-class ExchangeTradeViewModel = ExchangeTradeViewModelBase with _$ExchangeTradeViewModel;
17
+class ExchangeTradeViewModel = ExchangeTradeViewModelBase
18
+ with _$ExchangeTradeViewModel;
19
20
abstract class ExchangeTradeViewModelBase with Store {
21
ExchangeTradeViewModelBase({this.wallet, this.trades, this.tradesStore}) {
@@ -38,17 +39,11 @@ abstract class ExchangeTradeViewModelBase with Store {
39
items = ObservableList<ExchangeTradeItem>();
40
items.addAll([
41
ExchangeTradeItem(
41
- title: S.current.id,
42
- data: '${trade.id}',
43
- isCopied: true),
42
+ title: S.current.id, data: '${trade.id}', isCopied: true),
43
ExchangeTradeItem(
45
- title: S.current.amount,
46
- data: '${trade.amount}',
47
- isCopied: false),
44
+ title: S.current.amount, data: '${trade.amount}', isCopied: false),
45
ExchangeTradeItem(
49
- title: S.current.status,
50
- data: '${trade.state}',
51
- isCopied: false),
46
+ title: S.current.status, data: '${trade.state}', isCopied: false),
47
ExchangeTradeItem(
48
title: S.current.widgets_address + ':',
49
data: trade.inputAddress,
@@ -90,4 +85,4 @@ abstract class ExchangeTradeViewModelBase with Store {
85
print(e.toString());
86
}
87
}
93
-}
\ No newline at end of file
88
+}
lib/view_model/node_list/node_list_view_model.dart
+1
-2
@@ -1,5 +1,3 @@
1
-import 'package:cake_wallet/utils/item_cell.dart';
2
-import 'package:flutter/foundation.dart';
1
import 'package:hive/hive.dart';
2
import 'package:mobx/mobx.dart';
3
import 'package:cake_wallet/core/wallet_base.dart';
@@ -10,6 +8,7 @@ import 'package:cake_wallet/store/settings_store.dart';
8
import 'package:cake_wallet/src/domain/common/default_settings_migration.dart';
9
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
10
import 'package:cake_wallet/utils/mobx.dart';
11
+import 'package:cake_wallet/utils/item_cell.dart';
12
13
part 'node_list_view_model.g.dart';
14
lib/view_model/send_view_model.dart
+12
-22
@@ -1,3 +1,6 @@
1
+import 'package:flutter/foundation.dart';
2
+import 'package:intl/intl.dart';
3
+import 'package:mobx/mobx.dart';
4
import 'package:cake_wallet/core/address_validator.dart';
5
import 'package:cake_wallet/core/amount_validator.dart';
6
import 'package:cake_wallet/core/template_validator.dart';
@@ -5,7 +8,6 @@ import 'package:cake_wallet/core/validator.dart';
8
import 'package:cake_wallet/core/wallet_base.dart';
9
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
10
import 'package:cake_wallet/monero/monero_wallet.dart';
8
-import 'package:cake_wallet/src/domain/common/balance.dart';
11
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
12
import 'package:cake_wallet/src/domain/common/calculate_estimated_fee.dart';
13
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
@@ -14,15 +16,6 @@ import 'package:cake_wallet/src/domain/common/sync_status.dart';
16
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
17
import 'package:cake_wallet/store/settings_store.dart';
18
import 'package:cake_wallet/store/templates/send_template_store.dart';
17
-import 'package:flutter/foundation.dart';
18
-import 'package:intl/intl.dart';
19
-import 'package:mobx/mobx.dart';
20
-import 'package:cake_wallet/monero/monero_wallet_service.dart';
21
-import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart';
22
-import 'package:cake_wallet/core/wallet_creation_service.dart';
23
-import 'package:cake_wallet/core/wallet_credentials.dart';
24
-import 'package:cake_wallet/src/domain/common/wallet_type.dart';
25
-import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
19
import 'package:cake_wallet/generated/i18n.dart';
20
import 'package:cake_wallet/src/domain/common/openalias_record.dart';
21
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
@@ -51,12 +44,8 @@ class SendingFailed extends SendViewModelState {
44
class SendViewModel = SendViewModelBase with _$SendViewModel;
45
46
abstract class SendViewModelBase with Store {
54
- SendViewModelBase(
55
- this._wallet,
56
- this._settingsStore,
57
- this._fiatConvertationStore,
58
- this.sendTemplateStore) {
59
-
47
+ SendViewModelBase(this._wallet, this._settingsStore,
48
+ this._fiatConvertationStore, this.sendTemplateStore) {
49
state = InitialSendViewModelState();
50
51
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12;
@@ -116,9 +105,10 @@ abstract class SendViewModelBase with Store {
105
double get price => _fiatConvertationStore.price;
106
107
@computed
119
- ObservableList<Template> get templates => ObservableList.of(
120
- sendTemplateStore.templates.where((item)
121
- => item.cryptoCurrency == _wallet.currency.title).toList());
108
+ ObservableList<Template> get templates =>
109
+ ObservableList.of(sendTemplateStore.templates
110
+ .where((item) => item.cryptoCurrency == _wallet.currency.title)
111
+ .toList());
112
113
@computed
114
String get balance {
@@ -211,8 +201,8 @@ abstract class SendViewModelBase with Store {
201
String recordAddress;
202
203
Future<bool> isOpenaliasRecord(String name) async {
214
- final _openaliasRecord = await OpenaliasRecord
215
- .fetchAddressAndName(OpenaliasRecord.formatDomainName(name));
204
+ final _openaliasRecord = await OpenaliasRecord.fetchAddressAndName(
205
+ OpenaliasRecord.formatDomainName(name));
206
207
recordAddress = _openaliasRecord.address;
208
recordName = _openaliasRecord.name;
@@ -223,4 +213,4 @@ abstract class SendViewModelBase with Store {
213
Future<void> createTransaction() async {}
214
215
Future<void> commitTransaction() async {}
226
-}
\ No newline at end of file
216
+}
lib/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart
+3
-5
@@ -24,15 +24,14 @@ class AddressEditOrCreateStateFailure extends AddressEditOrCreateState {
24
}
25
26
abstract class WalletAddressEditOrCreateViewModelBase with Store {
27
- WalletAddressEditOrCreateViewModelBase({@required WalletBase wallet, dynamic item})
27
+ WalletAddressEditOrCreateViewModelBase(
28
+ {@required WalletBase wallet, dynamic item})
29
: isEdit = item != null,
30
state = AddressEditOrCreateStateInitial(),
31
label = item?.name as String,
32
_item = item,
33
_wallet = wallet;
34
34
- dynamic _item;
35
-
35
@observable
36
AddressEditOrCreateState state;
37
@@ -41,11 +40,10 @@ abstract class WalletAddressEditOrCreateViewModelBase with Store {
40
41
bool isEdit;
42
43
+ final dynamic _item;
44
final WalletBase _wallet;
45
46
Future<void> save() async {
47
- final wallet = _wallet;
48
-
47
try {
48
state = AddressIsSaving();
49
lib/view_model/wallet_address_list/wallet_address_list_view_model.dart
+2
-2
@@ -109,8 +109,8 @@ abstract class WalletAddressListViewModelBase with Store {
109
return addressList;
110
}
111
112
- set address(WalletAddressListItem address) =>
113
- _wallet.address = address.address;
112
+ set address(WalletAddressListItem address) => null;
113
+ // _wallet.address = address.address;
114
115
bool hasAccounts;
116
lib/view_model/wallet_creation_vm.dart
+8
-5
@@ -1,3 +1,4 @@
1
+import 'package:cake_wallet/core/wallet_base.dart';
2
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
3
import 'package:flutter/foundation.dart';
4
import 'package:hive/hive.dart';
@@ -32,14 +33,16 @@ abstract class WalletCreationVMBase with Store {
33
Future<void> create({dynamic options}) async {
34
try {
35
state = WalletCreating();
35
- await process(getCredentials(options));
36
- final id = walletTypeToString(type).toLowerCase() + '_' + name;
37
- final walletInfo = WalletInfo(
38
- id: id,
36
+ final credentials = getCredentials(options);
37
+ final walletInfo = WalletInfo.external(
38
+ id: WalletBase.idFor(name, type),
39
name: name,
40
type: type,
41
isRecovery: isRecovery,
42
- restoreHeight: 0);
42
+ restoreHeight: credentials.height ?? 0,
43
+ date: DateTime.now());
44
+ credentials.walletInfo = walletInfo;
45
+ await process(credentials);
46
await _walletInfoSource.add(walletInfo);
47
state = WalletCreatedSuccessfully();
48
} catch (e) {
lib/view_model/wallet_list/wallet_list_view_model.dart
+3
-16
@@ -1,12 +1,10 @@
1
import 'package:hive/hive.dart';
2
import 'package:mobx/mobx.dart';
3
+import 'package:cake_wallet/di.dart';
4
import 'package:cake_wallet/store/app_store.dart';
5
import 'package:cake_wallet/core/key_service.dart';
6
import 'package:cake_wallet/core/wallet_service.dart';
6
-import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
7
-import 'package:cake_wallet/monero/monero_wallet_service.dart';
7
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
9
-import 'package:cake_wallet/src/domain/common/wallet_type.dart';
8
import 'package:cake_wallet/src/domain/common/wallet_info.dart';
9
10
part 'wallet_list_view_model.g.dart';
@@ -31,29 +29,18 @@ abstract class WalletListViewModelBase with Store {
29
Future<void> loadWallet(WalletListItem wallet) async {
30
final password =
31
await _keyService.getWalletPassword(walletName: wallet.name);
34
- final walletService = _getWalletService(wallet.type);
32
+ final walletService = getIt.get<WalletService>();
33
_appStore.wallet = await walletService.openWallet(wallet.name, password);
34
}
35
36
@action
37
Future<void> remove(WalletListItem wallet) async {
40
- final walletService = _getWalletService(wallet.type);
38
+ final walletService = getIt.get<WalletService>();
39
await walletService.remove(wallet.name);
40
await _walletInfoSource.delete(wallet.key);
41
_updateList();
42
}
43
46
- WalletService _getWalletService(WalletType type) {
47
- switch (type) {
48
- case WalletType.monero:
49
- return MoneroWalletService();
50
- case WalletType.bitcoin:
51
- return BitcoinWalletService();
52
- default:
53
- return null;
54
- }
55
- }
56
-
44
void _updateList() {
45
wallets.clear();
46
wallets.addAll(_walletInfoSource.values.map((info) => WalletListItem(
pubspec.lock
+28
@@ -211,6 +211,34 @@ packages:
211
url: "https://pub.dartlang.org"
212
source: hosted
213
version: "1.14.13"
214
+ connectivity:
215
+ dependency: "direct main"
216
+ description:
217
+ name: connectivity
218
+ url: "https://pub.dartlang.org"
219
+ source: hosted
220
+ version: "0.4.9+2"
221
+ connectivity_for_web:
222
+ dependency: transitive
223
+ description:
224
+ name: connectivity_for_web
225
+ url: "https://pub.dartlang.org"
226
+ source: hosted
227
+ version: "0.3.1+2"
228
+ connectivity_macos:
229
+ dependency: transitive
230
+ description:
231
+ name: connectivity_macos
232
+ url: "https://pub.dartlang.org"
233
+ source: hosted
234
+ version: "0.1.0+4"
235
+ connectivity_platform_interface:
236
+ dependency: transitive
237
+ description:
238
+ name: connectivity_platform_interface
239
+ url: "https://pub.dartlang.org"
240
+ source: hosted
241
+ version: "1.0.6"
242
convert:
243
dependency: transitive
244
description:
pubspec.yaml
+1
@@ -60,6 +60,7 @@ dependencies:
60
basic_utils: ^1.0.8
61
bitcoin_flutter: ^2.0.0
62
get_it: ^4.0.2
63
+ connectivity: ^0.4.9+2
64
65
dev_dependencies:
66
flutter_test: