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

cap buy and sell orders by resource and lords balance #1714

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

bob0005
Copy link
Collaborator

@bob0005 bob0005 commented Sep 23, 2024

Fixes #1673

Copy link

vercel bot commented Sep 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 23, 2024 8:23pm

Copy link

Preparing PR description...

Copy link

Preparing review...

Copy link
Contributor

@mentatbot mentatbot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes effectively address the issue of capping buy and sell orders based on available balances. The implementation is well-thought-out, using ProductionManager for accurate balance calculations and introducing balance ratios to limit input values. The code is clean, consistent, and follows good React practices with the use of useMemo and useEffect. The updates to the 'Max' button and NumberInput component ensure that users can't exceed their available balances. Overall, this is a solid implementation that should resolve the issue while maintaining good performance and user experience.

Thanks for using MentatBot. Give comments a 👍 or 👎 to help me improve!

@@ -154,6 +155,8 @@ const MarketOrders = ({
offers: MarketInterface[];
isOwnStructureInBattle: boolean;
}) => {
const [updateBalance, setUpdateBalance] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition of the updateBalance state. This will help trigger re-renders when balances change.

systemCalls: { cancel_order, accept_partial_order },
},
} = useDojo();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of ProductionManager to get accurate balances for Lords and resources.

@@ -282,6 +298,28 @@

const currentDefaultTick = useUIStore((state) => state.currentDefaultTick);

const resourceBalanceRatio = useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good implementation of resourceBalanceRatio and lordsBalanceRatio to cap the input value based on available balances.

: (offer.takerGets[0].amount / EternumGlobalConfig.resources.resourcePrecision) * lordsBalanceRatio;
});

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect hook is a good addition to update the input value when balance ratios change.

@@ -336,6 +374,7 @@
} catch (error) {
console.error("Failed to accept order", error);
} finally {
setUpdateBalance(!updateBalance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good practice to update the balance after a successful transaction.

@@ -418,11 +457,17 @@
value={inputValue}
className="w-full col-span-3"
onChange={setInputValue}
max={getsDisplayNumber / EternumGlobalConfig.resources.resourcePrecision}
max={
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice update to the max prop of the NumberInput component to respect the balance ratios.

/>
<Button
onClick={() => {
setInputValue(getsDisplayNumber / EternumGlobalConfig.resources.resourcePrecision);
setInputValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good update to the 'Max' button functionality to respect the new balance limits.

Copy link
Collaborator

@edisontim edisontim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@edisontim edisontim merged commit bc3f0c7 into main Oct 1, 2024
8 checks passed
@edisontim edisontim deleted the fix/order-book branch October 1, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[client] able to buy resource in order book even if i dont have enough lords
2 participants