Replaced eu-node.cakewallet.io by xmr-node-eu.cakewallet.com and node.cakewallet.io by xmr-node-usa-east.cakewallet.com in remote nodes list. Added migration for change current remote node if user use old eu or usa remote node by new addresses. Changed way for set default remote node for initial setup by base on current user time zone.

M committed Jan 8, 2020 at 18:38 UTC 1315a532120d49074526e06b4da9c24b21a910bf
4 files changed +109 -30
assets/node_list.yml
+2 -6
@@ -2,14 +2,10 @@
2 uri: xmr-node-uk.cakewallet.com:18081
3 is_default: true
4 -
5 - uri: eu-node.cakewallet.io:18081
6 - login: cake
7 - password: public_node
5 + uri: xmr-node-eu.cakewallet.com:18081
6 is_default: false
7 -
10 - uri: node.cakewallet.io:18081
11 - login: cake
12 - password: public_node
8 + uri: xmr-node-usa-east.cakewallet.com:18081
9 is_default: false
10 -
11 uri: node.moneroworld.com:18089
lib/main.dart
+2 -1
@@ -80,7 +80,8 @@ void main() async {
80 sharedPreferences: sharedPreferences,
81 walletListService: walletListService,
82 nodes: nodes,
83 - authStore: authenticationStore);
83 + authStore: authenticationStore,
84 + initialMigrationVersion: 2);
85
86 final settingsStore = await SettingsStoreBase.load(
87 nodes: nodes,
lib/src/domain/common/default_settings_migration.dart
+96 -20
@@ -19,28 +19,104 @@ Future defaultSettingsMigration(
19 return;
20 }
21
22 - try {
23 - switch (version) {
24 - case 1:
25 - await sharedPreferences.setString(
26 - 'current_fiat_currency', FiatCurrency.usd.toString());
27 - await sharedPreferences.setInt(
28 - 'current_fee_priority', TransactionPriority.standart.raw);
29 - await sharedPreferences.setInt('current_balance_display_mode',
30 - BalanceDisplayMode.availableBalance.raw);
31 - await sharedPreferences.setInt(
32 - 'current_default_settings_migration_version', 1);
33 - await sharedPreferences.setBool('save_recipient_address', false);
34 - await resetToDefault(nodes);
35 - await sharedPreferences.setInt('current_node_id', 0);
36 - break;
37 - default:
38 - break;
22 + final migrationVersionsLength = version - currentVersion;
23 + final migrationVersions = List<int>.generate(
24 + migrationVersionsLength, (i) => currentVersion + (i + 1));
25 +
26 + await Future.forEach(migrationVersions, (int version) async {
27 + try {
28 + switch (version) {
29 + case 1:
30 + await sharedPreferences.setString(
31 + 'current_fiat_currency', FiatCurrency.usd.toString());
32 + await sharedPreferences.setInt(
33 + 'current_fee_priority', TransactionPriority.standart.raw);
34 + await sharedPreferences.setInt('current_balance_display_mode',
35 + BalanceDisplayMode.availableBalance.raw);
36 + await sharedPreferences.setBool('save_recipient_address', false);
37 + await resetToDefault(nodes);
38 + await changeCurrentNodeToDefault(
39 + sharedPreferences: sharedPreferences, nodes: nodes);
40 +
41 + break;
42 + case 2:
43 + await replaceNodesMigration(nodes: nodes);
44 + await replaceDefaultNode(
45 + sharedPreferences: sharedPreferences, nodes: nodes);
46 +
47 + break;
48 + default:
49 + break;
50 + }
51 +
52 + await sharedPreferences.setInt(
53 + 'current_default_settings_migration_version', version);
54 + } catch (e) {
55 + print('Migration error: ${e.toString()}');
56 }
40 - } catch (e) {
41 - print('Migration error: ${e.toString()}');
42 - }
57 + });
58
59 await sharedPreferences.setInt(
60 'current_default_settings_migration_version', version);
61 }
62 +
63 +Future<void> replaceNodesMigration({@required Box<Node> nodes}) async {
64 + final replaceNodes = <String, Node>{
65 + 'eu-node.cakewallet.io:18081':
66 + Node(uri: 'xmr-node-eu.cakewallet.com:18081'),
67 + 'node.cakewallet.io:18081':
68 + Node(uri: 'xmr-node-usa-east.cakewallet.com:18081')
69 + };
70 +
71 + nodes.values.forEach((Node node) async {
72 + final nodeToReplace = replaceNodes[node.uri];
73 +
74 + if (nodeToReplace != null) {
75 + node.uri = nodeToReplace.uri;
76 + node.login = nodeToReplace.login;
77 + node.password = nodeToReplace.password;
78 + await node.save();
79 + }
80 + });
81 +}
82 +
83 +Future<void> changeCurrentNodeToDefault(
84 + {@required SharedPreferences sharedPreferences,
85 + @required Box<Node> nodes}) async {
86 + final timeZone = DateTime.now().timeZoneOffset.inHours;
87 + String nodeUri = '';
88 +
89 + if (timeZone >= 1) { // Eurasia
90 + nodeUri = 'xmr-node-eu.cakewallet.com:18081';
91 + } else if (timeZone <= -4) { // America
92 + nodeUri = 'xmr-node-usa-east.cakewallet.com:18081';
93 + }
94 +
95 + final node = nodes.values.firstWhere((Node node) => node.uri == nodeUri) ??
96 + nodes.values.first;
97 + final nodeId = node != null ? node.key as int : 0; // 0 - England
98 +
99 + await sharedPreferences.setInt('current_node_id', nodeId);
100 +}
101 +
102 +Future<void> replaceDefaultNode(
103 + {@required SharedPreferences sharedPreferences,
104 + @required Box<Node> nodes}) async {
105 + const nodesForReplace = <String>[
106 + 'xmr-node-uk.cakewallet.com:18081',
107 + 'eu-node.cakewallet.io:18081',
108 + 'node.cakewallet.io:18081'
109 + ];
110 + final currentNodeId = sharedPreferences.getInt('current_node_id');
111 + final currentNode =
112 + nodes.values.firstWhere((Node node) => node.key == currentNodeId);
113 + final needToReplace =
114 + currentNode == null ? true : nodesForReplace.contains(currentNode.uri);
115 +
116 + if (!needToReplace) {
117 + return;
118 + }
119 +
120 + await changeCurrentNodeToDefault(
121 + sharedPreferences: sharedPreferences, nodes: nodes);
122 +}
lib/src/domain/common/node_list.dart
+9 -3
@@ -5,9 +5,15 @@ import 'package:cake_wallet/src/domain/common/node.dart';
5
6 Future<List<Node>> loadDefaultNodes() async {
7 final nodesRaw = await rootBundle.loadString('assets/node_list.yml');
8 - final nodes = loadYaml(nodesRaw) as List<Map<dynamic, dynamic>>;
9 -
10 - return nodes.map((raw) => Node.fromMap(raw)).toList();
8 + final nodes = loadYaml(nodesRaw) as YamlList;
9 +
10 + return nodes.map((dynamic raw) {
11 + if (raw is Map) {
12 + return Node.fromMap(raw);
13 + }
14 +
15 + return null;
16 + }).toList();
17 }
18
19 Future resetToDefault(Box<Node> nodeSource) async {