-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Preparing PR description... |
Preparing review... |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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(); | ||
|
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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={ |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Fixes #1673