|
1 | | -import React, { useCallback, useMemo } from 'react' |
| 1 | +import React, { useCallback, useMemo, useState } from 'react' |
2 | 2 | import { Slider } from 'office-ui-fabric-react' |
3 | 3 | import { Trans, useTranslation } from 'react-i18next' |
4 | 4 | import TextField from 'widgets/TextField' |
@@ -66,6 +66,7 @@ const DepositDialog = ({ |
66 | 66 | }: DepositDialogProps) => { |
67 | 67 | const [t, { language }] = useTranslation() |
68 | 68 | const disabled = !isTxGenerated |
| 69 | + const [isTyping, setIsTyping] = useState(false) |
69 | 70 | const { isBalanceReserved, onIsBalanceReservedChange, setIsBalanceReserved } = useBalanceReserved() |
70 | 71 | const { depositValue, onChangeDepositValue, slidePercent, onSliderChange, resetDepositValue } = useDepositValue( |
71 | 72 | balance, |
@@ -108,6 +109,16 @@ const DepositDialog = ({ |
108 | 109 |
|
109 | 110 | const isChinese = language === 'zh' || language.startsWith('zh-') |
110 | 111 |
|
| 112 | + const handleBlur = useCallback(() => { |
| 113 | + setIsTyping(false) |
| 114 | + }, [setIsTyping]) |
| 115 | + |
| 116 | + const handleFocus = useCallback(() => { |
| 117 | + setIsTyping(true) |
| 118 | + }, [setIsTyping]) |
| 119 | + |
| 120 | + const inputValue = useMemo(() => maxDepositValue ?? depositValue, [maxDepositValue, depositValue]) |
| 121 | + |
111 | 122 | return ( |
112 | 123 | <Dialog |
113 | 124 | show={show} |
@@ -151,8 +162,10 @@ const DepositDialog = ({ |
151 | 162 | className={styles.depositValue} |
152 | 163 | width="100%" |
153 | 164 | field="depositValue" |
154 | | - value={localNumberFormatter(maxDepositValue ?? depositValue)} |
| 165 | + value={isTyping ? inputValue : localNumberFormatter(inputValue)} |
155 | 166 | onChange={onChangeDepositValue} |
| 167 | + onBlur={handleBlur} |
| 168 | + onFocus={handleFocus} |
156 | 169 | suffix="CKB" |
157 | 170 | required |
158 | 171 | error={errorMessage} |
|
0 commit comments