fix: allow topup amount input to be fully cleared (#6473)
This commit is contained in:
@@ -116,7 +116,10 @@ export function RechargeFormCard({
|
||||
const [localAmount, setLocalAmount] = useState(topupAmount.toString())
|
||||
|
||||
useEffect(() => {
|
||||
setLocalAmount(topupAmount.toString())
|
||||
// Empty string must survive, otherwise the field can never be cleared
|
||||
setLocalAmount((prev) =>
|
||||
prev === '' && topupAmount === 0 ? prev : topupAmount.toString()
|
||||
)
|
||||
}, [topupAmount])
|
||||
|
||||
const handleAmountChange = (value: string) => {
|
||||
@@ -317,7 +320,10 @@ export function RechargeFormCard({
|
||||
{hasStandardPaymentMethods ? (
|
||||
<div className='grid grid-cols-2 gap-1.5 sm:gap-3 lg:grid-cols-3'>
|
||||
{topupInfo?.pay_methods?.map((method) => {
|
||||
const minTopup = method.min_topup || 0
|
||||
const minTopup = Math.max(
|
||||
method.min_topup || 0,
|
||||
getMinTopupAmount(topupInfo)
|
||||
)
|
||||
const disabled = minTopup > topupAmount
|
||||
const disabledReason = disabled
|
||||
? t('Minimum topup amount: {{amount}}', {
|
||||
|
||||
@@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import { useState, useEffect, useCallback, useMemo } from 'react'
|
||||
import { useState, useEffect, useCallback, useMemo, useRef } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { SectionPageLayout } from '@/components/layout'
|
||||
@@ -137,8 +137,10 @@ export function Wallet(props: WalletProps) {
|
||||
}, [props.initialShowHistory])
|
||||
|
||||
// Initialize topup amount when topup info is loaded
|
||||
const topupAmountInitializedRef = useRef(false)
|
||||
useEffect(() => {
|
||||
if (topupInfo && topupAmount === 0) {
|
||||
if (topupInfo && !topupAmountInitializedRef.current) {
|
||||
topupAmountInitializedRef.current = true
|
||||
const minTopup = getMinTopupAmount(topupInfo)
|
||||
setTopupAmount(minTopup)
|
||||
|
||||
@@ -146,7 +148,7 @@ export function Wallet(props: WalletProps) {
|
||||
const defaultPaymentType = getDefaultPaymentType(topupInfo)
|
||||
calculatePaymentAmount(minTopup, defaultPaymentType)
|
||||
}
|
||||
}, [topupInfo, topupAmount, calculatePaymentAmount])
|
||||
}, [topupInfo, calculatePaymentAmount])
|
||||
|
||||
// Get current payment type (selected or default)
|
||||
const getCurrentPaymentType = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user