Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use blocktimestamp hook #2553

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions client/src/ui/components/entities/Entity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { ArrivalInfo } from "@/hooks/helpers/use-resource-arrivals";
import { getArmyByEntityId } from "@/hooks/helpers/useArmies";
import { useEntitiesUtils } from "@/hooks/helpers/useEntities";
import { useResourcesUtils } from "@/hooks/helpers/useResources";
import useUIStore from "@/hooks/store/useUIStore";
import useNextBlockTimestamp from "@/hooks/useNextBlockTimestamp";
import { ArmyCapacity } from "@/ui/elements/ArmyCapacity";
import { ResourceCost } from "@/ui/elements/ResourceCost";
import { divideByPrecision, formatTime, getEntityIdFromKeys } from "@/ui/utils/utils";
import { EntityType } from "@bibliothecadao/eternum";
import { useComponentValue } from "@dojoengine/react";
import clsx from "clsx";
import React, { useMemo, useState } from "react";
import React, { useMemo } from "react";
import { DepositResources } from "../resources/DepositResources";

const entityIcon: Record<EntityType, string> = {
Expand All @@ -35,11 +35,9 @@ const CACHE_DURATION = 2 * 60 * 1000; // 2 minutes in milliseconds
export const EntityArrival = ({ arrival, ...props }: EntityProps) => {
const dojo = useDojo();

const [isSyncing, setIsSyncing] = useState(false);

const { getEntityInfo, getEntityName } = useEntitiesUtils();
const { getResourcesFromBalance } = useResourcesUtils();
const nextBlockTimestamp = useUIStore.getState().nextBlockTimestamp;
const { nextBlockTimestamp } = useNextBlockTimestamp();
const { getArmy } = getArmyByEntityId();

const weight = useComponentValue(dojo.setup.components.Weight, getEntityIdFromKeys([BigInt(arrival.entityId)]));
Expand Down Expand Up @@ -68,10 +66,6 @@ export const EntityArrival = ({ arrival, ...props }: EntityProps) => {
}, [nextBlockTimestamp, arrival.recipientEntityId, arrival.hasResources, entity.arrivalTime]);

const renderedResources = useMemo(() => {
if (isSyncing) {
return <div className="text-gold/50 italic">Syncing resources...</div>;
}

return entityResources
.filter(Boolean)
.map((resource) => (
Expand All @@ -85,7 +79,7 @@ export const EntityArrival = ({ arrival, ...props }: EntityProps) => {
amount={divideByPrecision(resource.amount)}
/>
));
}, [entityResources, isSyncing]);
}, [entityResources]);

const name = entity.entityType === EntityType.TROOP ? army?.name : entityName[entity.entityType];

Expand Down
Loading