Skip to content

Commit

Permalink
Set default value to max + filter out 0 balance resources
Browse files Browse the repository at this point in the history
  • Loading branch information
bob0005 committed Dec 27, 2024
1 parent 4dcb803 commit 8ac94d9
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions landing/src/components/ui/SelectResources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SelectResources = ({
setSelectedResourceAmounts: any;
entity_id: ID;
}) => {
const { getBalance } = useResourceBalance({entityId: entity_id});
const { getBalance } = useResourceBalance({ entityId: entity_id });

const unselectedResources = useMemo(
() => resources.filter((res) => !selectedResourceIds.includes(res.id)),
Expand All @@ -32,20 +32,20 @@ export const SelectResources = ({
setSelectedResourceIds([...selectedResourceIds, unselectedResources[0].id]);
setSelectedResourceAmounts({
...selectedResourceAmounts,
[unselectedResources[0].id]: 1,
[unselectedResources[0].id]: divideByPrecision(getBalance(unselectedResources[0].id) || 0),
});
};

return (
<div className=" items-center col-span-4 space-y-2 p-3">
{selectedResourceIds.map((id: any, index: any) => {
const resource = getBalance(id);
const options = [resources.find((res) => res.id === id), ...unselectedResources].map((res: any) => ({
id: res.id,
label: (
<ResourceCost resourceId={res.id} amount={divideByPrecision(getBalance(res.id) || 0)} />
),
}));
const options = [resources.find((res) => res.id === id), ...unselectedResources]
.filter((res) => getBalance(res.id) > 0)
.map((res: any) => ({
id: res.id,
label: <ResourceCost resourceId={res.id} amount={divideByPrecision(getBalance(res.id) || 0)} />,
}));

return (
<div key={id} className="flex items-center gap-4">
Expand Down Expand Up @@ -75,7 +75,7 @@ export const SelectResources = ({
const { [selectedResourceIds[index]]: _, ...remainingAmounts } = selectedResourceAmounts;
setSelectedResourceAmounts({
...remainingAmounts,
[value]: 1,
[value]: divideByPrecision(getBalance(value) || 0),
});
// playResourceSound(value);
}}
Expand Down Expand Up @@ -117,7 +117,7 @@ export const SelectSingleResource = ({
setSelectedResourceAmounts: any;
entity_id: ID;
}) => {
const { getBalance } = useResourceBalance({entityId: entity_id});
const { getBalance } = useResourceBalance({ entityId: entity_id });

const unselectedResources = useMemo(
() => resources.filter((res) => !selectedResourceIds.includes(res.id)),
Expand All @@ -134,20 +134,20 @@ export const SelectSingleResource = ({
setSelectedResourceIds([...selectedResourceIds, unselectedResources[0].id]);
setSelectedResourceAmounts({
...selectedResourceAmounts,
[unselectedResources[0].id]: 1,
[unselectedResources[0].id]: divideByPrecision(getBalance(unselectedResources[0].id) || 0),
});
};

return (
<div className=" items-center col-span-4 space-y-2 p-3">
{selectedResourceIds.map((id: any, index: any) => {
const resourceBalance = getBalance(id);
const options = [resources.find((res) => res.id === id), ...unselectedResources].map((res: any) => ({
id: res.id,
label: (
<ResourceCost resourceId={res.id} amount={divideByPrecision(getBalance(res.id) || 0)} />
),
}));
const options = [resources.find((res) => res.id === id), ...unselectedResources]
.filter((res) => getBalance(res.id) > 0)
.map((res: any) => ({
id: res.id,
label: <ResourceCost resourceId={res.id} amount={divideByPrecision(getBalance(res.id) || 0)} />,
}));

return (
<>
Expand All @@ -165,7 +165,7 @@ export const SelectSingleResource = ({
const { [selectedResourceIds[index]]: _, ...remainingAmounts } = selectedResourceAmounts;
setSelectedResourceAmounts({
...remainingAmounts,
[value]: 1,
[value]: divideByPrecision(getBalance(value) || 0),
});
// playResourceSound(value);
}}
Expand Down Expand Up @@ -218,7 +218,7 @@ export const ShowSingleResource = ({
setSelectedResourceAmounts: any;
entity_id: ID;
}) => {
const { getBalance } = useResourceBalance({entityId: entity_id});
const { getBalance } = useResourceBalance({ entityId: entity_id });

const unselectedResources = useMemo(
() => resources.filter((res) => !selectedResourceIds.includes(res.id)),
Expand All @@ -235,7 +235,7 @@ export const ShowSingleResource = ({
setSelectedResourceIds([...selectedResourceIds, unselectedResources[0].id]);
setSelectedResourceAmounts({
...selectedResourceAmounts,
[unselectedResources[0].id]: 1,
[unselectedResources[0].id]: divideByPrecision(getBalance(unselectedResources[0].id) || 0),
});
};

Expand Down

0 comments on commit 8ac94d9

Please sign in to comment.