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,34 +1036,30 @@ 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);
}
//Check default Epicbox is up before returning it
bool isEpicboxConnected = await testEpicboxServer(
decoded["epicbox_domain"] as String, decoded["epicbox_port"] as int);
String defaultConfig = DefaultNodes.defaultEpicBoxConfig; if (!isEpicboxConnected) {
final decoded = json.decode(defaultConfig); //Default Epicbox is not connected, Defaulting to Europe
bool isEpicboxConnected = await testEpicboxServer( storedConfig = json.encode(DefaultNodes.epicBoxConfigEUR);
decoded["epicbox_domain"] as String, // TODO test this connection before returning it, iterating through the list of default Epic Box servers
decoded["epicbox_port"] as int);
if (!isEpicboxConnected) {
//Default Epicbox is not connected, Defaulting to Europe
defaultConfig = DefaultNodes.epicBoxConfigEUR;
}
await _secureStore.write(
key: '${_walletId}_epicboxConfig', value: defaultConfig);
} }
return await _secureStore.read(key: '${_walletId}_epicboxConfig') ?? return storedConfig;
DefaultNodes.defaultEpicBoxConfig; } else {
return DefaultNodes.defaultEpicBoxConfig;
} }
return DefaultNodes.defaultEpicBoxConfig;
} }
Future<String> getRealConfig() async { Future<String> getRealConfig() async {