Skip to content

Commit

Permalink
refactor: network check
Browse files Browse the repository at this point in the history
  • Loading branch information
noyyyy committed Oct 15, 2024
1 parent 3f9e3f6 commit 97ad967
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
30 changes: 16 additions & 14 deletions packages/client/src/ui/hooks/useCheckNetworkHealth.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { useEffect } from "react";
import { useDojo } from "./useDojo";
import { logDebug } from "../lib/utils";

export function useCheckNetworkHealth() {
const {
networkLayer: { toriiClient },
} = useDojo();

useEffect(() => {
const t = setInterval(async () => {
try {
await toriiClient.getEntities(1, 0);
} catch (e) {
alert("network disconnect, please refresh the page");
clearInterval(t);
const errorHandler = (event: ErrorEvent): void => {
logDebug("Global error:", event.error);

if (
event.error &&
event.error.toString().includes("RuntimeError: unreachable")
) {
alert("network disconnect, page will be refreshed");
location.reload();
}
}, 5000);
};

window.addEventListener("error", errorHandler);

return () => {
clearInterval(t);
window.removeEventListener("error", errorHandler);
};
}, [toriiClient]);
}, []);

return;
}
1 change: 1 addition & 0 deletions packages/client/src/ui/hooks/useEscCloseDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const BLOCK_ESC_SHOW_ITEM = [
ShowItem.CurseNotice,
ShowItem.DangerStage,
ShowItem.SettleDialog,
ShowItem.HeroInfoDialog,
];

export function useEscCloseDialog() {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/ui/hooks/useHeroAttr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getComponentValueStrict } from "@dojoengine/recs";
import { getEntityIdFromKeys } from "@dojoengine/utils";
import { Monster } from "../../phaser/config/constants";
import { ClientComponents } from "../../dojo/createClientComponents";
import { getPieceEntity, logDebug } from "../lib/utils";
import { getPieceEntity } from "../lib/utils";
import { getOrder, getOrigins } from "../../utils";

export const SELL_PRICE: Record<number, Record<number, number>> = {
Expand Down

0 comments on commit 97ad967

Please sign in to comment.