better is number check

This commit is contained in:
tjs 2022-10-31 16:39:43 +00:00
parent 5f61ad117b
commit 7d15e8e798
5 changed files with 18 additions and 13 deletions

View File

@ -62,10 +62,13 @@ const CreateAccountForm = ({
const newAccount = mangoAccounts.find(
(acc) => acc.accountNum === newAccountNum
)
if (newAccount) {
await newAccount.reloadAccountData(client)
set((s) => {
s.mangoAccount.current = newAccount
s.mangoAccounts = mangoAccounts
})
}
setLoading(false)
notify({
title: t('new-account-success'),

View File

@ -229,7 +229,7 @@ function BorrowModal({ isOpen, onClose, token }: ModalCombinedProps) {
placeholder="0.00"
value={inputAmount}
onValueChange={(e: NumberFormatValues) =>
setInputAmount(Number(e.value) ? e.value : '')
setInputAmount(!Number.isNaN(Number(e.value)) ? e.value : '')
}
isAllowed={withValueLimit}
/>

View File

@ -98,7 +98,7 @@ function DepositModal({ isOpen, onClose, token }: ModalCombinedProps) {
selectedToken === 'SOL' ? tokenMax.maxAmount - 0.05 : tokenMax.maxAmount
setInputAmount(max.toString())
setSizePercentage('100')
}, [tokenMax])
}, [tokenMax, selectedToken])
const handleSizePercentage = useCallback(
(percentage: string) => {
@ -113,7 +113,7 @@ function DepositModal({ isOpen, onClose, token }: ModalCombinedProps) {
setInputAmount(amount.toString())
},
[tokenMax]
[tokenMax, selectedToken]
)
useEffect(() => {
@ -294,9 +294,9 @@ function DepositModal({ isOpen, onClose, token }: ModalCombinedProps) {
className="w-full rounded-lg rounded-l-none border border-th-bkg-4 bg-th-bkg-1 p-3 text-right font-mono text-xl tracking-wider text-th-fgd-1 focus:outline-none"
placeholder="0.00"
value={inputAmount}
onValueChange={(e: NumberFormatValues) =>
setInputAmount(Number(e.value) ? e.value : '')
}
onValueChange={(e: NumberFormatValues) => {
setInputAmount(!Number.isNaN(Number(e.value)) ? e.value : '')
}}
isAllowed={withValueLimit}
/>
</div>

View File

@ -237,7 +237,9 @@ function WithdrawModal({ isOpen, onClose, token }: ModalCombinedProps) {
placeholder="0.00"
value={inputAmount}
onValueChange={(e: NumberFormatValues) =>
setInputAmount(Number(e.value) ? e.value : '')
setInputAmount(
!Number.isNaN(Number(e.value)) ? e.value : ''
)
}
isAllowed={withValueLimit}
/>

View File

@ -94,7 +94,7 @@ const AdvancedTradeForm = () => {
if (info.source !== 'event') return
set((s) => {
s.tradeForm.price = e.value
if (s.tradeForm.baseSize && Number(e.value)) {
if (s.tradeForm.baseSize && !Number.isNaN(Number(e.value))) {
s.tradeForm.quoteSize = (
parseFloat(e.value) * parseFloat(s.tradeForm.baseSize)
).toString()
@ -111,7 +111,7 @@ const AdvancedTradeForm = () => {
set((s) => {
s.tradeForm.baseSize = e.value
if (s.tradeForm.price && Number(e.value)) {
if (s.tradeForm.price && !Number.isNaN(Number(e.value))) {
s.tradeForm.quoteSize = (
parseFloat(s.tradeForm.price) * parseFloat(e.value)
).toString()