diff --git a/client/src/ui/components/resources/ResourceChip.tsx b/client/src/ui/components/resources/ResourceChip.tsx
index 5e7e5cac5..7cddae57f 100644
--- a/client/src/ui/components/resources/ResourceChip.tsx
+++ b/client/src/ui/components/resources/ResourceChip.tsx
@@ -153,7 +153,7 @@ export const ResourceChip = ({
return (
<>
-
+
{
- const togglePopup = useUIStore((state) => state.togglePopup);
- const isOpen = useUIStore((state) => state.isPopupOpen(resource.toString()));
-
- const { playerRealms } = useEntities();
-
- const {
- setup: {
- network: {
- contractComponents: { Resource },
- },
- },
- } = useDojo();
-
- return (
-
togglePopup(resource.toString())}
- show={isOpen}
- >
-
- {icon}
- {resource}
-
{balance}
-
-
- {playerRealms().map((realm) => (
- {}}
- />
- ))}
-
- );
+type transferCall = {
+ sender_entity_id: num.BigNumberish;
+ recipient_entity_id: num.BigNumberish;
+ resources: num.BigNumberish[];
};
-export const RealmTransferBalance = ({
- resource,
- balance,
- resourceComponent,
- realm,
- icon,
- add,
-}: {
- resource: ResourcesIds;
- balance: number;
- realm: any;
- resourceComponent: ClientComponents["Resource"];
- icon: React.ReactNode;
- add: (amount: Call) => void;
-}) => {
- const [input, setInput] = useState(balance);
-
- const resourceBalance = useComponentValue(resourceComponent, getEntityIdFromKeys(realm.entity_id));
-
- return (
-
- {resourceBalance?.balance.toString()}
- {
- setInput(amount);
- }}
- />
-
-
- );
-};
+
+ setType((prev) => (prev === "send" ? "receive" : "send"))}
+ />
+
+
+
+
+
{currencyFormat(balance ? Number(balance) : 0, 0)}
+
+
+ {playerRealms().map((realm) => (
+
+ ))}
+
+
+ {calls.map((call, index) => (
+
+
{call.resources[1].toString()}
+
+
+ ))}
+
+
+
+
+
+
+
+ );
+ },
+);
+export const RealmTransferBalance = memo(
+ ({
+ resource,
+ balance,
+ realm,
+ add,
+ tick,
+ }: {
+ resource: ResourcesIds;
+ balance: number;
+ realm: any;
+ add: Dispatch
>;
+ tick: number;
+ }) => {
+ const [input, setInput] = useState(0);
+
+ const resourceManager = useResourceManager(realm.entity_id, resource);
+
+ const getBalance = useCallback(() => {
+ return resourceManager.balance(tick);
+ }, [resourceManager, tick]);
+
+ const getProduction = useCallback(() => {
+ return resourceManager.getProduction();
+ }, [resourceManager]);
+
+ return (
+
+
+
{realm.name}
+
{currencyFormat(getBalance() ? Number(getBalance()) : 0, 0)}
+
+
+
{
+ setInput(amount);
+ add((prev) => {
+ // Remove any existing calls for this realm
+ const filtered = prev.filter((call) => call.sender_entity_id !== realm.entity_id);
+
+ // Only add new call if amount > 0
+ if (amount > 0) {
+ return [
+ ...filtered,
+ {
+ sender_entity_id: realm.entity_id,
+ recipient_entity_id: realm.entity_id,
+ resources: [resource, amount],
+ },
+ ];
+ }
+ return filtered;
+ });
+ }}
+ />
+
+ );
+ },
+);