From b6a28403689fee7060e6a6f3e84d4ceb221804fe Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 20 Oct 2022 11:01:25 -0600 Subject: [PATCH] check and update primary node if primary node is a default node that was updated --- lib/services/node_service.dart | 13 +++++++++++++ lib/utilities/enums/coin_enum.dart | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/services/node_service.dart b/lib/services/node_service.dart index 06c8c40ea..5b9fe5063 100644 --- a/lib/services/node_service.dart +++ b/lib/services/node_service.dart @@ -39,6 +39,19 @@ class NodeService extends ChangeNotifier { key: savedNode.id, value: defaultNode.copyWith(enabled: savedNode.enabled)); } + + // check if a default node is the primary node for the crypto currency + // and update it if needed + final coin = coinFromPrettyName(defaultNode.coinName); + final primaryNode = getPrimaryNodeFor(coin: coin); + if (primaryNode != null && primaryNode.id == defaultNode.id) { + await setPrimaryNodeFor( + coin: coin, + node: defaultNode.copyWith( + enabled: primaryNode.enabled, + ), + ); + } } } diff --git a/lib/utilities/enums/coin_enum.dart b/lib/utilities/enums/coin_enum.dart index 78a04e220..c25a5ca4e 100644 --- a/lib/utilities/enums/coin_enum.dart +++ b/lib/utilities/enums/coin_enum.dart @@ -181,25 +181,32 @@ Coin coinFromPrettyName(String name) { case "Bitcoin": case "bitcoin": return Coin.bitcoin; + case "Bitcoincash": case "bitcoincash": case "Bitcoin Cash": return Coin.bitcoincash; + case "Dogecoin": case "dogecoin": return Coin.dogecoin; + case "Epic Cash": case "epicCash": return Coin.epicCash; + case "Firo": case "firo": return Coin.firo; + case "Monero": case "monero": return Coin.monero; + case "Namecoin": case "namecoin": return Coin.namecoin; + case "Bitcoin Testnet": case "tBitcoin": case "bitcoinTestNet": @@ -208,19 +215,24 @@ Coin coinFromPrettyName(String name) { case "Bitcoincash Testnet": case "tBitcoin Cash": case "Bitcoin Cash Testnet": + case "bitcoincashTestnet": return Coin.bitcoincashTestnet; + case "Firo Testnet": case "tFiro": case "firoTestNet": return Coin.firoTestNet; + case "Dogecoin Testnet": case "tDogecoin": case "dogecoinTestNet": return Coin.dogecoinTestNet; + case "Wownero": case "tWownero": case "wownero": return Coin.wownero; + default: throw ArgumentError.value( name, "name", "No Coin enum value with that prettyName");