diff --git a/client/src/ui/components/entities/Entity.tsx b/client/src/ui/components/entities/Entity.tsx index 9cc55d990..6dd2fff63 100644 --- a/client/src/ui/components/entities/Entity.tsx +++ b/client/src/ui/components/entities/Entity.tsx @@ -1,4 +1,3 @@ -import { addToSubscription } from "@/dojo/queries"; import { useDojo } from "@/hooks/context/DojoContext"; import { ArrivalInfo } from "@/hooks/helpers/use-resource-arrivals"; import { getArmyByEntityId } from "@/hooks/helpers/useArmies"; @@ -11,7 +10,7 @@ import { divideByPrecision, formatTime, getEntityIdFromKeys } from "@/ui/utils/u import { EntityType } from "@bibliothecadao/eternum"; import { useComponentValue } from "@dojoengine/react"; import clsx from "clsx"; -import React, { useEffect, useMemo, useState } from "react"; +import React, { useMemo, useState } from "react"; import { DepositResources } from "../resources/DepositResources"; const entityIcon: Record = { @@ -51,33 +50,6 @@ export const EntityArrival = ({ arrival, ...props }: EntityProps) => { return getResourcesFromBalance(arrival.entityId); }, [weight]); - useEffect(() => { - if (entityResources.length === 0) { - const cacheKey = `${CACHE_KEY}-${arrival.entityId}`; - const cachedTime = localStorage.getItem(cacheKey); - const now = Date.now(); - - if (cachedTime && now - parseInt(cachedTime) < CACHE_DURATION) { - return; - } - - setIsSyncing(true); - const fetch = async () => { - try { - await addToSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any, [ - arrival.entityId.toString(), - ]); - localStorage.setItem(cacheKey, now.toString()); - } catch (error) { - console.error("Fetch failed", error); - } finally { - setIsSyncing(false); - } - }; - fetch(); - } - }, [arrival.entityId, dojo.network.toriiClient, dojo.network.contractComponents, entityResources.length]); - const army = useMemo(() => getArmy(arrival.entityId), [arrival.entityId, entity.resources]); const renderEntityStatus = useMemo(() => { diff --git a/client/src/ui/components/trading/ResourceArrivals.tsx b/client/src/ui/components/trading/ResourceArrivals.tsx index 72dc5ddde..c2daa74a4 100644 --- a/client/src/ui/components/trading/ResourceArrivals.tsx +++ b/client/src/ui/components/trading/ResourceArrivals.tsx @@ -1,22 +1,41 @@ +import { addToSubscription } from "@/dojo/queries"; +import { useDojo } from "@/hooks/context/DojoContext"; import { ArrivalInfo } from "@/hooks/helpers/use-resource-arrivals"; import { Headline } from "@/ui/elements/Headline"; import { HintModalButton } from "@/ui/elements/HintModalButton"; -import { memo } from "react"; +import { memo, useEffect } from "react"; import { EntityArrival } from "../entities/Entity"; import { HintSection } from "../hints/HintModal"; export const AllResourceArrivals = memo( - ({ arrivals, className = "" }: { arrivals: ArrivalInfo[]; className?: string }) => ( -
- -
-
Transfers
- -
-
- {arrivals.map((arrival) => ( - - ))} -
- ), + ({ arrivals, className = "" }: { arrivals: ArrivalInfo[]; className?: string }) => { + const dojo = useDojo(); + + useEffect(() => { + const fetch = async () => { + try { + await addToSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any, [ + ...arrivals.map((arrival) => arrival.entityId.toString()), + ]); + } catch (error) { + console.error("Fetch failed", error); + } + }; + fetch(); + }, [arrivals, dojo.network.toriiClient, dojo.network.contractComponents]); + + return ( +
+ +
+
Transfers
+ +
+
+ {arrivals.map((arrival) => ( + + ))} +
+ ); + }, );