Skip to content

Commit

Permalink
refactor: make cta button active even for stonks with zero balance
Browse files Browse the repository at this point in the history
  • Loading branch information
katamarinaki committed Mar 25, 2024
1 parent 15aef45 commit 15e6ed3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/stonks/hooks/useStonksData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function useStonksData() {
marginInBasisPoints: marginInBasisPoints.toNumber(),
orderDurationInSeconds: orderDurationInSeconds.toNumber(),
priceToleranceInBasisPoints: priceToleranceInBasisPoints.toNumber(),
currentBalanceBn: currentBalance,
currentBalance: isEnoughBalance
? formatUnits(currentBalance, tokenFromDecimals)
: '0',
Expand Down
4 changes: 2 additions & 2 deletions modules/stonks/ui/StonksGrid/StonksGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export function StonksGrid({ stonksData }: Props) {
</Text>
<Button
size="xs"
disabled={isZero}
variant={isZero ? 'outlined' : 'filled'}
onClick={() => router.push(stonksInstance(stonks.address))}
>
Create Order
{isZero ? 'Inspect' : 'Create Order'}
</Button>
</Card>
)
Expand Down
6 changes: 5 additions & 1 deletion modules/stonks/ui/StonksOrderForm/StonksOrderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ export function StonksOrderForm() {
return <MessageBox>Stonks pair not found</MessageBox>
}

const isBalanceZero = selectedStonksPair.currentBalanceBn.isZero()

return (
<Form formMethods={formMethods} onSubmit={handleSubmit}>
<Title
title={`New Stonks order ${selectedStonksPair.tokenFrom.label} -> ${selectedStonksPair.tokenTo.label}`}
title={`Stonks pair ${selectedStonksPair.tokenFrom.label} -> ${selectedStonksPair.tokenTo.label}`}
/>
<FormFields>
<MotionInfoBox>
Expand All @@ -93,6 +95,7 @@ export function StonksOrderForm() {
label="Minimum acceptable amount"
name="minAcceptableAmount"
rules={{ required: 'Field is required' }}
disabled={isBalanceZero}
/>
</InputRow>
</MotionInfoBox>
Expand Down Expand Up @@ -140,6 +143,7 @@ export function StonksOrderForm() {
<Button
type="submit"
fullwidth
disabled={isBalanceZero}
children="Create Order"
loading={isSubmitting}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function StonksOrderProgressSafe({ safeTxHash }: Props) {
</MessageBox>
<MessageBox>
<Text size={14} weight={500}>
Once you obtain the transaction hash, you can proceed with the order
Once the transaction is signed and transaction has is obtained, you
can proceed with the order. Click the button below to open up the
order form.
</Text>
<Button size="sm" onClick={() => router.push(stonks)}>
Back to Stonks
Expand Down

0 comments on commit 15e6ed3

Please sign in to comment.