From e0934abb3537891010d3f43acec4c9b355a04a95 Mon Sep 17 00:00:00 2001 From: tedison Date: Mon, 23 Dec 2024 13:37:18 +0100 Subject: [PATCH] Fix decimals in transfer --- .../resources/EntityResourceTable.tsx | 4 ++-- .../ui/components/resources/ResourceChip.tsx | 2 +- .../components/resources/realm-transfer.tsx | 21 ++++++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/client/src/ui/components/resources/EntityResourceTable.tsx b/client/src/ui/components/resources/EntityResourceTable.tsx index 7407fbb65..665750707 100644 --- a/client/src/ui/components/resources/EntityResourceTable.tsx +++ b/client/src/ui/components/resources/EntityResourceTable.tsx @@ -1,13 +1,12 @@ import { configManager } from "@/dojo/setup"; import { useDojo } from "@/hooks/context/DojoContext"; -import { useStructures } from "@/hooks/helpers/useStructures"; import useNextBlockTimestamp from "@/hooks/useNextBlockTimestamp"; import { getEntityIdFromKeys, gramToKg, multiplyByPrecision } from "@/ui/utils/utils"; import { BuildingType, CapacityConfigCategory, ID, RESOURCE_TIERS, StructureType } from "@bibliothecadao/eternum"; import { useComponentValue } from "@dojoengine/react"; +import { getComponentValue } from "@dojoengine/recs"; import { useMemo } from "react"; import { ResourceChip } from "./ResourceChip"; -import { getComponentValue } from "@dojoengine/recs"; export const EntityResourceTable = ({ entityId }: { entityId: ID | undefined }) => { const dojo = useDojo(); @@ -42,6 +41,7 @@ export const EntityResourceTable = ({ entityId }: { entityId: ID | undefined }) tick={tick} /> )); + return (
{resources}
diff --git a/client/src/ui/components/resources/ResourceChip.tsx b/client/src/ui/components/resources/ResourceChip.tsx index 7cddae57f..7ab753521 100644 --- a/client/src/ui/components/resources/ResourceChip.tsx +++ b/client/src/ui/components/resources/ResourceChip.tsx @@ -164,7 +164,7 @@ export const ResourceChip = ({ > {icon}
-
{currencyFormat(balance ? Number(balance) : 0, 0)}
+
{currencyFormat(balance ? Number(balance) : 0, 2)}
{timeUntilValueReached !== 0 diff --git a/client/src/ui/components/resources/realm-transfer.tsx b/client/src/ui/components/resources/realm-transfer.tsx index 038c28805..72b781fea 100644 --- a/client/src/ui/components/resources/realm-transfer.tsx +++ b/client/src/ui/components/resources/realm-transfer.tsx @@ -59,20 +59,24 @@ export const RealmTransfer = memo( setResourceWeight(multipliedWeight); }, [calls]); - const handleTransfer = useCallback(() => { + const handleTransfer = useCallback(async () => { setIsLoading(true); const cleanedCalls = calls.map(({ sender_entity_id, recipient_entity_id, resources }) => ({ sender_entity_id, recipient_entity_id, - resources: [resources[0], BigInt(resources[1]) * BigInt(1000)], + resources: [resources[0], BigInt(Number(resources[1]) * 1000)], })); - send_resources_multiple({ - signer: account, - calls: cleanedCalls, - }).finally(() => { + try { + await send_resources_multiple({ + signer: account, + calls: cleanedCalls, + }); + } catch (error) { + console.error(error); + } finally { setIsLoading(false); - }); + } setCalls([]); }, [calls]); @@ -102,7 +106,7 @@ export const RealmTransfer = memo( size="xxl" className="mr-3 self-center" /> -
{currencyFormat(balance ? Number(balance) : 0, 0)}
+
{currencyFormat(balance ? Number(balance) : 0, 2)}
{playerStructures().map((structure) => ( @@ -225,6 +229,7 @@ export const RealmTransferBalance = memo( min={0} step={100} value={input} + allowDecimals disabled={!canCarry || (type === "receive" && getDonkeyBalance() === 0)} onChange={(amount) => { setInput(amount);