Skip to content

Commit

Permalink
Fix decimals in transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
edisontim committed Dec 23, 2024
1 parent d70eb4a commit e0934ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions client/src/ui/components/resources/EntityResourceTable.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -42,6 +41,7 @@ export const EntityResourceTable = ({ entityId }: { entityId: ID | undefined })
tick={tick}
/>
));

return (
<div key={tier}>
<div className="grid grid-cols-1 flex-wrap">{resources}</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/components/resources/ResourceChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const ResourceChip = ({
>
{icon}
<div className="grid grid-cols-10 w-full">
<div className="self-center font-bold col-span-3">{currencyFormat(balance ? Number(balance) : 0, 0)}</div>
<div className="self-center font-bold col-span-3">{currencyFormat(balance ? Number(balance) : 0, 2)}</div>

<div className="self-center m-y-auto font-bold col-span-4 text-center">
{timeUntilValueReached !== 0
Expand Down
21 changes: 13 additions & 8 deletions client/src/ui/components/resources/realm-transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -102,7 +106,7 @@ export const RealmTransfer = memo(
size="xxl"
className="mr-3 self-center"
/>
<div className="py-3 text-center text-xl">{currencyFormat(balance ? Number(balance) : 0, 0)}</div>
<div className="py-3 text-center text-xl">{currencyFormat(balance ? Number(balance) : 0, 2)}</div>
</div>

{playerStructures().map((structure) => (
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e0934ab

Please sign in to comment.