From db43cc7e209a092031e0fe7ca5b6991f3ab78c86 Mon Sep 17 00:00:00 2001 From: Sahil Date: Sat, 19 Dec 2020 20:37:31 +0530 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=9A=A1=EF=B8=8F=20connect=20to=20pol?= =?UTF-8?q?kadot=20api=20before=20connecting=20wallet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #166 --- components/common/layouts/base.js | 13 ++++++++++++- components/common/layouts/dashboard.js | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/components/common/layouts/base.js b/components/common/layouts/base.js index a0d95caf..340ff3a8 100644 --- a/components/common/layouts/base.js +++ b/components/common/layouts/base.js @@ -44,6 +44,17 @@ const withBaseLayout = (children) => { const { stakingAmount, setTransactionState } = useTransaction((state) => pick(state, ["stakingAmount", "setTransactionState"]) ); + useEffect(() => { + if (isNil(apiInstance) && !isNil(selectedNetwork)) { + createPolkadotAPIInstance(selectedNetwork, apiInstance) + .then(async (api) => { + setApiInstance(api); + }) + .catch((err) => { + console.info("Unable to connect to polkadot api!"); + }); + } + }, [selectedNetwork]); useEffect(() => { if (accounts && accounts.length > 0) { createPolkadotAPIInstance(selectedNetwork, apiInstance) @@ -73,7 +84,7 @@ const withBaseLayout = (children) => { throw err; }); } - }, [accounts]); + }, [accounts, selectedNetwork]); useEffect(() => { // wallet connected state: diff --git a/components/common/layouts/dashboard.js b/components/common/layouts/dashboard.js index 381f9cf0..134c8610 100644 --- a/components/common/layouts/dashboard.js +++ b/components/common/layouts/dashboard.js @@ -53,6 +53,18 @@ const withDashboardLayout = (children) => { pick(state, ["stakingAmount", "setTransactionState"]) ); + useEffect(() => { + if (isNil(apiInstance) && !isNil(selectedNetwork)) { + createPolkadotAPIInstance(selectedNetwork, apiInstance) + .then(async (api) => { + setApiInstance(api); + }) + .catch((err) => { + console.info("Unable to connect to polkadot api!"); + }); + } + }, [selectedNetwork]); + useEffect(() => { if (accounts && accounts.length > 0) { createPolkadotAPIInstance(selectedNetwork, apiInstance)