Skip to content

Commit 5eb7b17

Browse files
committed
fix: refactor max button to use InputAdornment and truncate balance
1 parent e998a06 commit 5eb7b17

1 file changed

Lines changed: 67 additions & 44 deletions

File tree

components/bridge-input/bridge-input.tsx

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react'
22
import { Controller, useFormContext } from 'react-hook-form'
3-
import { TextField } from '@mui/material'
3+
import { Button, TextField, InputAdornment } from '@mui/material'
44

55
import { BridgeInputProps } from './bridge-input.types'
66
import { useBridgeInfo } from '@/hooks/use-bridge-info'
@@ -105,54 +105,77 @@ export const BridgeInput = ({ fromNetwork, availableBalance, remainingDailyLimit
105105
},
106106
}}
107107
render={({ field }) => (
108-
<TextField
109-
{...field}
110-
type="number"
111-
variant="standard"
112-
placeholder="0"
113-
error={Boolean(errors.amount)}
114-
helperText={helperText as React.ReactNode}
115-
onKeyDown={handleKeyDown}
116-
onChange={handleChange(field.onChange)}
117-
slotProps={{
118-
input: {
119-
disableUnderline: true,
120-
inputMode: 'decimal',
121-
inputProps: {
108+
<div style={{ position: 'relative', width: '100%' }}>
109+
<TextField
110+
{...field}
111+
type="number"
112+
variant="standard"
113+
placeholder="0"
114+
error={Boolean(errors.amount)}
115+
helperText={helperText as React.ReactNode}
116+
onKeyDown={handleKeyDown}
117+
onChange={handleChange(field.onChange)}
118+
slotProps={{
119+
input: {
120+
disableUnderline: true,
121+
inputMode: 'decimal',
122+
inputProps: {
123+
style: {
124+
fontSize: getFontSize(valueLength),
125+
fontWeight: 500,
126+
minWidth: '180px',
127+
width: '100%',
128+
padding: 0,
129+
appearance: 'textfield',
130+
},
131+
},
122132
style: {
123-
fontSize: getFontSize(valueLength),
124-
fontWeight: 500,
125-
minWidth: '180px',
126-
width: '100%',
127-
padding: 0,
128-
appearance: 'textfield',
133+
display: 'flex',
134+
alignItems: 'center',
135+
height: '35px',
136+
paddingTop: '10px',
129137
},
130138
},
131-
style: {
132-
display: 'flex',
133-
alignItems: 'center',
134-
height: '35px',
135-
paddingTop: '10px',
136-
},
137-
},
138-
}}
139-
sx={{
140-
'& .MuiInputBase-input': {
141-
appearance: 'textfield',
142-
'&::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
143-
appearance: 'none',
144-
margin: 0,
139+
}}
140+
sx={{
141+
'& .MuiInputBase-input': {
142+
appearance: 'textfield',
143+
'&::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
144+
appearance: 'none',
145+
margin: 0,
146+
},
145147
},
146-
},
147-
'& .Mui-error': {
148-
fontSize: '11px',
149-
marginTop: '2px',
150-
'@media (max-width:1280px)': {
151-
fontSize: '9px',
148+
'& .Mui-error': {
149+
fontSize: '11px',
150+
marginTop: '2px',
151+
'@media (max-width:1280px)': {
152+
fontSize: '9px',
153+
},
152154
},
153-
},
154-
}}
155-
/>
155+
}}
156+
InputProps={{
157+
endAdornment: (
158+
<InputAdornment position="end">
159+
<Button
160+
variant="text"
161+
size="small"
162+
onClick={() => field.onChange(String(Math.floor(availableBalance * 10**6) / 10**6))}
163+
sx={{
164+
minWidth: 'unset',
165+
padding: '2px 5px',
166+
lineHeight: 1,
167+
fontSize: '12px',
168+
fontWeight: 600,
169+
color: 'primary.main',
170+
}}
171+
>
172+
MAX
173+
</Button>
174+
</InputAdornment>
175+
),
176+
}}
177+
/>
178+
</div>
156179
)}
157180
/>
158181
)

0 commit comments

Comments
 (0)