From 78c98953129f5700a5932e8e2fd53e25f4b45be5 Mon Sep 17 00:00:00 2001 From: Joseph Tary Date: Thu, 31 Aug 2023 09:00:58 -0700 Subject: [PATCH] feat: change network type and add updgrade handler --- web/src/hooks/useRpcNode.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/web/src/hooks/useRpcNode.ts b/web/src/hooks/useRpcNode.ts index 3f7bd63..375a769 100644 --- a/web/src/hooks/useRpcNode.ts +++ b/web/src/hooks/useRpcNode.ts @@ -5,7 +5,7 @@ const storageKey = 'rpc_settings'; export const defaultRpcSettings = { rpcNode: 'https://rpc.akashnet.net/', chainId: 'akashnet-2', - networkType: 'mainnet', + networkType: 'testnet', }; export const testnetRpcSettings = { @@ -36,6 +36,13 @@ function isRpcSettings(value: unknown): value is RpcSettings { ); } +function hasNetworkUpgraded(settings: RpcSettings) { + const config = [defaultRpcSettings, testnetRpcSettings, sandboxRpcSettings] + .find((config) => config.chainId === settings.chainId); + + return config ? config.networkType !== settings.networkType : false; +} + function getRpcFromStorageOrDefault(defaultValue: RpcSettings) { const raw = localStorage.getItem(storageKey); @@ -44,6 +51,12 @@ function getRpcFromStorageOrDefault(defaultValue: RpcSettings) { const parsed = raw ? JSON.parse(raw) : null; if (parsed) { + if (hasNetworkUpgraded(parsed)) { + console.warn('Network has been upgraded. Resetting RPC settings.'); + deleteRpcFromStorage(); + return defaultValue; + } + return parsed; } }