Skip to content

Commit

Permalink
chore: Add postMessage listener to update token0 on message event
Browse files Browse the repository at this point in the history
  • Loading branch information
deblanco committed Aug 5, 2024
1 parent f1d1abb commit 4cd0f48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/src/Pages/Main/Components/Box2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const Box2 = () => {
description: "There was an error claiming stbleUSD",
},
});
p.then(() => {
window.postMessage(JSON.stringify({ type: "update" }), "*");
});
};

return (
Expand Down
13 changes: 13 additions & 0 deletions app/src/Pages/Main/Components/Box3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ export const Box3 = () => {
});
};

useEffect(() => {
const fn = (ev: MessageEvent) => {
const data = JSON.parse(ev.data) as { type: string };
if (data.type !== "update") return;
token0.refetch();
};
window.addEventListener("message", fn);

return () => {
window.removeEventListener("message", fn);
};
}, [token0]);

return (
<Box p={4} w={["100vw", "xl"]} bg={"gray.700"} borderRadius={4}>
<Heading size="md">Swap</Heading>
Expand Down

0 comments on commit 4cd0f48

Please sign in to comment.