Skip to content

Commit

Permalink
fix api connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Oct 5, 2024
1 parent 2b2f82b commit 15c193c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
14 changes: 6 additions & 8 deletions src/contexts/apis/CoretimeApi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,14 @@ const CoretimeApiContextProvider = (props: any) => {
useEffect(() => {
const url = getUrl(network);
if (!url || state.socket === url) return;
if (state.socket !== url) disconnect(state);

if (state.socket !== url) {
try {
disconnect(state);
} catch {
/** empty error handler */
}
connect(state, url, dispatch, true, types);
try {
connect(state, url, dispatch, true);
} catch (_err) {
/** empty error handler */
}
}, [network, state.socket]);
}, [network]);

return (
<CoretimeApiContext.Provider
Expand Down
14 changes: 6 additions & 8 deletions src/contexts/apis/RegionXApi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ const RegionXApiContextProvider = (props: any) => {
}
const url = getUrl(network);
if (!url || state.socket === url) return;
if (state.socket !== url) disconnect(state);

if (state.socket !== url) {
try {
disconnect(state);
} catch {
/** empty error handler */
}
connect(state, url, dispatch, true, types, customRpc);
try {
connect(state, url, dispatch, true);
} catch (_err) {
/** empty error handler */
}
}, [network, state.socket]);
}, [network]);

useEffect(() => {
dispatch({ type: 'DISCONNECTED' });
Expand Down
12 changes: 5 additions & 7 deletions src/contexts/apis/RelayApi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ const RelayApiContextProvider = (props: any) => {
useEffect(() => {
const url = getUrl(network);
if (!url || state.socket === url) return;
if (state.socket !== url) disconnect(state);

if (state.socket !== url) {
try {
disconnect(state);
} catch {
/** empty error handler */
}
try {
connect(state, url, dispatch, true);
} catch (_err) {
/** empty error handler */
}
}, [network, state.socket]);
}, [network]);

useEffect(() => {
const { api, apiState } = state;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/functions/timestamps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const getBlockTime = (network: NetworkType): number => {
return 12 * 1000;
case NetworkType.POLKADOT:
return 12 * 1000;
case NetworkType.PASEO:
return 12 * 1000;
default:
return 0;
}
Expand Down

0 comments on commit 15c193c

Please sign in to comment.