don't save failover epicbox server to hive if primary fails

just return the failover
This commit is contained in:
sneurlax 2023-02-21 15:35:05 -06:00
parent 937c1263e7
commit 63fbd003e2

View file

@ -1036,35 +1036,31 @@ class EpicCashWallet extends CoinServiceAPI
} }
Future<String> getEpicBoxConfig() async { Future<String> getEpicBoxConfig() async {
final storedConfig = String? storedConfig =
await _secureStore.read(key: '${_walletId}_epicboxConfig'); await _secureStore.read(key: '${_walletId}_epicboxConfig');
if (storedConfig != null) { if (storedConfig != null) {
final decoded = json.decode(storedConfig!); dynamic decoded = json.decode(storedConfig!);
final domain = decoded["domain"] ?? "empty"; final domain = decoded["domain"] ?? "empty";
if (domain != "empty") { if (domain != "empty") {
//If we have the old invalid config - update //If we have the old invalid config, use the new default one
//Before writing to secure storage,ensure Epicbox is up storedConfig = DefaultNodes.defaultEpicBoxConfig;
decoded = json.decode(storedConfig);
String defaultConfig = DefaultNodes.defaultEpicBoxConfig; }
final decoded = json.decode(defaultConfig); //Check default Epicbox is up before returning it
bool isEpicboxConnected = await testEpicboxServer( bool isEpicboxConnected = await testEpicboxServer(
decoded["epicbox_domain"] as String, decoded["epicbox_domain"] as String, decoded["epicbox_port"] as int);
decoded["epicbox_port"] as int);
if (!isEpicboxConnected) { if (!isEpicboxConnected) {
//Default Epicbox is not connected, Defaulting to Europe //Default Epicbox is not connected, Defaulting to Europe
defaultConfig = DefaultNodes.epicBoxConfigEUR; storedConfig = json.encode(DefaultNodes.epicBoxConfigEUR);
// TODO test this connection before returning it, iterating through the list of default Epic Box servers
} }
await _secureStore.write( return storedConfig;
key: '${_walletId}_epicboxConfig', value: defaultConfig); } else {
}
return await _secureStore.read(key: '${_walletId}_epicboxConfig') ??
DefaultNodes.defaultEpicBoxConfig;
}
return DefaultNodes.defaultEpicBoxConfig; return DefaultNodes.defaultEpicBoxConfig;
} }
}
Future<String> getRealConfig() async { Future<String> getRealConfig() async {
String? config = await _secureStore.read(key: '${_walletId}_config'); String? config = await _secureStore.read(key: '${_walletId}_config');