Skip to content

Commit

Permalink
perf: ⚡️ connect to polkadot api before connecting wallet
Browse files Browse the repository at this point in the history
Closes: #166
  • Loading branch information
sahilnanda1995 committed Dec 19, 2020
1 parent 6797b57 commit db43cc7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion components/common/layouts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -73,7 +84,7 @@ const withBaseLayout = (children) => {
throw err;
});
}
}, [accounts]);
}, [accounts, selectedNetwork]);

useEffect(() => {
// wallet connected state:
Expand Down
12 changes: 12 additions & 0 deletions components/common/layouts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit db43cc7

Please sign in to comment.