mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
Merge pull request #4 from cake-tech/add-new-nodes
Changed cake wallet remote nodes addresses and credentials
This commit is contained in:
commit
e46c653f3b
4 changed files with 109 additions and 30 deletions
|
@ -2,14 +2,10 @@
|
||||||
uri: xmr-node-uk.cakewallet.com:18081
|
uri: xmr-node-uk.cakewallet.com:18081
|
||||||
is_default: true
|
is_default: true
|
||||||
-
|
-
|
||||||
uri: eu-node.cakewallet.io:18081
|
uri: xmr-node-eu.cakewallet.com:18081
|
||||||
login: cake
|
|
||||||
password: public_node
|
|
||||||
is_default: false
|
is_default: false
|
||||||
-
|
-
|
||||||
uri: node.cakewallet.io:18081
|
uri: xmr-node-usa-east.cakewallet.com:18081
|
||||||
login: cake
|
|
||||||
password: public_node
|
|
||||||
is_default: false
|
is_default: false
|
||||||
-
|
-
|
||||||
uri: node.moneroworld.com:18089
|
uri: node.moneroworld.com:18089
|
||||||
|
|
|
@ -80,7 +80,8 @@ void main() async {
|
||||||
sharedPreferences: sharedPreferences,
|
sharedPreferences: sharedPreferences,
|
||||||
walletListService: walletListService,
|
walletListService: walletListService,
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
authStore: authenticationStore);
|
authStore: authenticationStore,
|
||||||
|
initialMigrationVersion: 2);
|
||||||
|
|
||||||
final settingsStore = await SettingsStoreBase.load(
|
final settingsStore = await SettingsStoreBase.load(
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
|
|
|
@ -19,28 +19,104 @@ Future defaultSettingsMigration(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
final migrationVersionsLength = version - currentVersion;
|
||||||
switch (version) {
|
final migrationVersions = List<int>.generate(
|
||||||
case 1:
|
migrationVersionsLength, (i) => currentVersion + (i + 1));
|
||||||
await sharedPreferences.setString(
|
|
||||||
'current_fiat_currency', FiatCurrency.usd.toString());
|
await Future.forEach(migrationVersions, (int version) async {
|
||||||
await sharedPreferences.setInt(
|
try {
|
||||||
'current_fee_priority', TransactionPriority.standart.raw);
|
switch (version) {
|
||||||
await sharedPreferences.setInt('current_balance_display_mode',
|
case 1:
|
||||||
BalanceDisplayMode.availableBalance.raw);
|
await sharedPreferences.setString(
|
||||||
await sharedPreferences.setInt(
|
'current_fiat_currency', FiatCurrency.usd.toString());
|
||||||
'current_default_settings_migration_version', 1);
|
await sharedPreferences.setInt(
|
||||||
await sharedPreferences.setBool('save_recipient_address', false);
|
'current_fee_priority', TransactionPriority.standart.raw);
|
||||||
await resetToDefault(nodes);
|
await sharedPreferences.setInt('current_balance_display_mode',
|
||||||
await sharedPreferences.setInt('current_node_id', 0);
|
BalanceDisplayMode.availableBalance.raw);
|
||||||
break;
|
await sharedPreferences.setBool('save_recipient_address', false);
|
||||||
default:
|
await resetToDefault(nodes);
|
||||||
break;
|
await changeCurrentNodeToDefault(
|
||||||
|
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
await replaceNodesMigration(nodes: nodes);
|
||||||
|
await replaceDefaultNode(
|
||||||
|
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await sharedPreferences.setInt(
|
||||||
|
'current_default_settings_migration_version', version);
|
||||||
|
} catch (e) {
|
||||||
|
print('Migration error: ${e.toString()}');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
});
|
||||||
print('Migration error: ${e.toString()}');
|
|
||||||
}
|
|
||||||
|
|
||||||
await sharedPreferences.setInt(
|
await sharedPreferences.setInt(
|
||||||
'current_default_settings_migration_version', version);
|
'current_default_settings_migration_version', version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> replaceNodesMigration({@required Box<Node> nodes}) async {
|
||||||
|
final replaceNodes = <String, Node>{
|
||||||
|
'eu-node.cakewallet.io:18081':
|
||||||
|
Node(uri: 'xmr-node-eu.cakewallet.com:18081'),
|
||||||
|
'node.cakewallet.io:18081':
|
||||||
|
Node(uri: 'xmr-node-usa-east.cakewallet.com:18081')
|
||||||
|
};
|
||||||
|
|
||||||
|
nodes.values.forEach((Node node) async {
|
||||||
|
final nodeToReplace = replaceNodes[node.uri];
|
||||||
|
|
||||||
|
if (nodeToReplace != null) {
|
||||||
|
node.uri = nodeToReplace.uri;
|
||||||
|
node.login = nodeToReplace.login;
|
||||||
|
node.password = nodeToReplace.password;
|
||||||
|
await node.save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> changeCurrentNodeToDefault(
|
||||||
|
{@required SharedPreferences sharedPreferences,
|
||||||
|
@required Box<Node> nodes}) async {
|
||||||
|
final timeZone = DateTime.now().timeZoneOffset.inHours;
|
||||||
|
String nodeUri = '';
|
||||||
|
|
||||||
|
if (timeZone >= 1) { // Eurasia
|
||||||
|
nodeUri = 'xmr-node-eu.cakewallet.com:18081';
|
||||||
|
} else if (timeZone <= -4) { // America
|
||||||
|
nodeUri = 'xmr-node-usa-east.cakewallet.com:18081';
|
||||||
|
}
|
||||||
|
|
||||||
|
final node = nodes.values.firstWhere((Node node) => node.uri == nodeUri) ??
|
||||||
|
nodes.values.first;
|
||||||
|
final nodeId = node != null ? node.key as int : 0; // 0 - England
|
||||||
|
|
||||||
|
await sharedPreferences.setInt('current_node_id', nodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> replaceDefaultNode(
|
||||||
|
{@required SharedPreferences sharedPreferences,
|
||||||
|
@required Box<Node> nodes}) async {
|
||||||
|
const nodesForReplace = <String>[
|
||||||
|
'xmr-node-uk.cakewallet.com:18081',
|
||||||
|
'eu-node.cakewallet.io:18081',
|
||||||
|
'node.cakewallet.io:18081'
|
||||||
|
];
|
||||||
|
final currentNodeId = sharedPreferences.getInt('current_node_id');
|
||||||
|
final currentNode =
|
||||||
|
nodes.values.firstWhere((Node node) => node.key == currentNodeId);
|
||||||
|
final needToReplace =
|
||||||
|
currentNode == null ? true : nodesForReplace.contains(currentNode.uri);
|
||||||
|
|
||||||
|
if (!needToReplace) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await changeCurrentNodeToDefault(
|
||||||
|
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||||
|
}
|
||||||
|
|
|
@ -5,9 +5,15 @@ import 'package:cake_wallet/src/domain/common/node.dart';
|
||||||
|
|
||||||
Future<List<Node>> loadDefaultNodes() async {
|
Future<List<Node>> loadDefaultNodes() async {
|
||||||
final nodesRaw = await rootBundle.loadString('assets/node_list.yml');
|
final nodesRaw = await rootBundle.loadString('assets/node_list.yml');
|
||||||
final nodes = loadYaml(nodesRaw) as List<Map<dynamic, dynamic>>;
|
final nodes = loadYaml(nodesRaw) as YamlList;
|
||||||
|
|
||||||
return nodes.map((raw) => Node.fromMap(raw)).toList();
|
return nodes.map((dynamic raw) {
|
||||||
|
if (raw is Map) {
|
||||||
|
return Node.fromMap(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future resetToDefault(Box<Node> nodeSource) async {
|
Future resetToDefault(Box<Node> nodeSource) async {
|
||||||
|
|
Loading…
Reference in a new issue