Skip to content

Commit 50fb2de

Browse files
authored
dApp: Disable "Max" button in TokenBalanceInput (#526)
Closes: #504 ### Issue: As you attempt to deposit max amount of wallet balance you won't beable to finalize the transaction due to insuficient balance to pay gas fee. ### Possible solution: Estimate gas fee, uncomment and handle error edge case.
2 parents 46562c7 + e826e10 commit 50fb2de

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function StakeFormModal({
2020
tokenBalance={tokenBalance}
2121
minTokenAmount={minDepositAmount}
2222
onSubmitForm={onSubmitForm}
23+
withMaxButton={false}
2324
>
2425
<StakeDetails currency="bitcoin" />
2526
<FormSubmitButton mt={10}>Stake</FormSubmitButton>

dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function UnstakeFormModal({
2020
tokenBalance={balance}
2121
minTokenAmount={minTokenAmount}
2222
onSubmitForm={onSubmitForm}
23+
withMaxButton
2324
>
2425
<UnstakeDetails balance={balance} currency="bitcoin" />
2526
<FormSubmitButton mt={10}>Withdraw</FormSubmitButton>

dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type TokenAmountFormBaseProps = {
2525
tokenBalance: bigint
2626
tokenBalanceInputPlaceholder: string
2727
currency: CurrencyType
28+
withMaxButton: boolean
2829
fiatCurrency?: CurrencyType
2930
children?: React.ReactNode
3031
}
@@ -35,6 +36,7 @@ export default function TokenAmountFormBase({
3536
currency,
3637
fiatCurrency,
3738
tokenBalanceInputPlaceholder,
39+
withMaxButton,
3840
children,
3941
...formikProps
4042
}: TokenAmountFormBaseProps & FormikProps<TokenAmountFormValues>) {
@@ -46,6 +48,7 @@ export default function TokenAmountFormBase({
4648
placeholder={tokenBalanceInputPlaceholder}
4749
currency={currency}
4850
fiatCurrency={fiatCurrency}
51+
withMaxButton={withMaxButton}
4952
/>
5053
{children}
5154
</Form>

dapp/src/components/shared/TokenBalanceInput/index.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export type TokenBalanceInputProps = {
100100
size?: "lg" | "md"
101101
fiatCurrency?: CurrencyType
102102
setAmount: (value?: bigint) => void
103+
withMaxButton?: boolean
103104
} & InputProps &
104105
HelperErrorTextProps
105106

@@ -114,6 +115,7 @@ export default function TokenBalanceInput({
114115
helperText,
115116
hasError = false,
116117
fiatCurrency,
118+
withMaxButton = false,
117119
...inputProps
118120
}: TokenBalanceInputProps) {
119121
const valueRef = useRef<bigint | undefined>(amount)
@@ -159,11 +161,14 @@ export default function TokenBalanceInput({
159161
setAmount(valueRef?.current)
160162
}}
161163
/>
162-
<InputRightElement>
163-
<Button h="70%" onClick={() => setAmount(tokenBalance)}>
164-
Max
165-
</Button>
166-
</InputRightElement>
164+
165+
{withMaxButton && (
166+
<InputRightElement>
167+
<Button h="70%" onClick={() => setAmount(tokenBalance)}>
168+
Max
169+
</Button>
170+
</InputRightElement>
171+
)}
167172
</InputGroup>
168173
<HelperErrorText
169174
helperText={helperText}

0 commit comments

Comments
 (0)