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)