diff --git a/ui/src/app/containers/UpgradeScreen.tsx b/ui/src/app/containers/UpgradeScreen.tsx index 7cd38e12e..03007a560 100644 --- a/ui/src/app/containers/UpgradeScreen.tsx +++ b/ui/src/app/containers/UpgradeScreen.tsx @@ -87,7 +87,6 @@ export default function UpgradeScreen({ const equipItems = useUIStore((state) => state.equipItems); const dropItems = useUIStore((state) => state.dropItems); const entropyReady = useUIStore((state) => state.entropyReady); - const setEntropyReady = useUIStore((state) => state.setEntropyReady); const onKatana = useUIStore((state) => state.onKatana); const setVitBoostRemoved = useUIStore((state) => state.setVitBoostRemoved); const pendingMessage = useLoadingStore((state) => state.pendingMessage); @@ -99,27 +98,6 @@ export default function UpgradeScreen({ const { play: clickPlay } = useUiSounds(soundSelector.click); - useEffect(() => { - if (onKatana) return; - const fetchEntropy = async () => { - const entropy = await gameContract!.call("get_adventurer_entropy", [ - adventurer?.id!, - ]); - if (entropy !== BigInt(0)) { - setEntropyReady(true); - clearInterval(interval); - } - }; - - // Call the function immediately - fetchEntropy(); - - // Set up the interval to call the function every 5 seconds - const interval = setInterval(fetchEntropy, 5000); - - return () => clearInterval(interval); // Cleanup on component unmount - }, []); - const setData = useQueriesStore((state) => state.setData); useEffect(() => { diff --git a/ui/src/app/hooks/useUIStore.ts b/ui/src/app/hooks/useUIStore.ts index daa748961..2fd859f38 100644 --- a/ui/src/app/hooks/useUIStore.ts +++ b/ui/src/app/hooks/useUIStore.ts @@ -95,6 +95,8 @@ type State = { setIsMintingLords: (value: boolean) => void; averageBlockTime: number; setAverageBlockTime: (value: number) => void; + adventurerEntropy: bigint; + setAdventurerEntropy: (value: bigint) => void; entropyReady: boolean; setEntropyReady: (value: boolean) => void; loginScreen: boolean; @@ -176,6 +178,8 @@ const useUIStore = create((set) => ({ setIsMintingLords: (value) => set({ isMintingLords: value }), averageBlockTime: 0, setAverageBlockTime: (value) => set({ averageBlockTime: value }), + adventurerEntropy: BigInt(0), + setAdventurerEntropy: (value) => set({ adventurerEntropy: value }), entropyReady: false, setEntropyReady: (value) => set({ entropyReady: value }), loginScreen: false, diff --git a/ui/src/app/page.tsx b/ui/src/app/page.tsx index 52f6d6b0f..d1bc38b49 100644 --- a/ui/src/app/page.tsx +++ b/ui/src/app/page.tsx @@ -159,6 +159,9 @@ function Home() { const showDeathDialog = useUIStore((state) => state.showDeathDialog); const setStartOption = useUIStore((state) => state.setStartOption); const setEntropyReady = useUIStore((state) => state.setEntropyReady); + const setAdventurerEntropy = useUIStore( + (state) => state.setAdventurerEntropy + ); const [accountChainId, setAccountChainId] = useState< constants.StarknetChainId | undefined >(); @@ -521,6 +524,29 @@ function Home() { } }, [onboarded]); + useEffect(() => { + const fetchEntropy = async () => { + if (adventurer?.id) { + const entropy = await gameContract!.call("get_adventurer_entropy", [ + adventurer?.id!, + ]); + if (entropy !== BigInt(0)) { + setAdventurerEntropy(BigInt(entropy.toString())); + setEntropyReady(true); + clearInterval(interval); + } + } + }; + + // Call the function immediately + fetchEntropy(); + + // Set up the interval to call the function every 5 seconds + const interval = setInterval(fetchEntropy, 5000); + + return () => clearInterval(interval); // Cleanup on component unmount + }, [adventurer?.level]); + if (!isConnected && disconnected) { return ; }