CW-653-Migrate-Tron-And-Solana-To-NowNodes (#1492)

* chore: Setup

* feat: Add NowNodes for Tron Wallet and switch it to be the default node for Tron

* feat: Add NowNodes for Solana Wallet and switch it to be the default node for Solana

* fix: Add nownodes entry to secrets

* fix: Remove pubspec.lock in shared external

* fix conflicts with main

* change secrets names

* feat: Remove Solana NowNodes config

* feat: Remove Solana NowNodes config

* feat: Revert commented out code

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Adegoke David 2024-06-28 22:36:12 +01:00 committed by GitHub
parent ac9e473ef5
commit a319e10156
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 51 additions and 8 deletions

View file

@ -37,7 +37,7 @@ const cakeWalletBitcoinCashDefaultNodeUri = 'bitcoincash.stackwallet.com:50002';
const nanoDefaultNodeUri = 'rpc.nano.to';
const nanoDefaultPowNodeUri = 'rpc.nano.to';
const solanaDefaultNodeUri = 'rpc.ankr.com';
const tronDefaultNodeUri = 'api.trongrid.io';
const tronDefaultNodeUri = 'trx.nownodes.io';
const newCakeWalletBitcoinUri = 'btc-electrum.cakewallet.com:50002';
Future<void> defaultSettingsMigration(
@ -234,7 +234,11 @@ Future<void> defaultSettingsMigration(
await changeTronCurrentNodeToDefault(sharedPreferences: sharedPreferences, nodes: nodes);
break;
case 37:
await replaceTronDefaultNode(sharedPreferences: sharedPreferences, nodes: nodes);
break;
case 38:
await fixBtcDerivationPaths(walletInfoSource);
break;
default:
break;
}
@ -1142,3 +1146,29 @@ Future<void> changeTronCurrentNodeToDefault(
await sharedPreferences.setInt(PreferencesKey.currentTronNodeIdKey, nodeId);
}
Future<void> replaceTronDefaultNode({
required SharedPreferences sharedPreferences,
required Box<Node> nodes,
}) async {
// Get the currently active node
final currentTronNodeId = sharedPreferences.getInt(PreferencesKey.currentTronNodeIdKey);
final currentTronNode =
nodes.values.firstWhereOrNull((Node node) => node.key == currentTronNodeId);
//Confirm if this node is part of the default nodes from CakeWallet
final tronDefaultNodeList = [
'tron-rpc.publicnode.com:443',
'api.trongrid.io',
];
bool needsToBeReplaced =
currentTronNode == null ? true : tronDefaultNodeList.contains(currentTronNode.uriRaw);
// If it's a custom node, return. We don't want to switch users from their custom nodes
if (!needsToBeReplaced) {
return;
}
// If it's not, we switch user to the new default node: NowNodes
await changeTronCurrentNodeToDefault(sharedPreferences: sharedPreferences, nodes: nodes);
}