From 2922126fec9b23b77fd4bde843c847c77143e31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Sim=C3=A3o?= Date: Thu, 17 Feb 2022 22:00:04 +0100 Subject: [PATCH] Fixed out of range bugs on inputs --- src/components/SwapInput/index.tsx | 6 ++---- src/hooks/useGetBalance.ts | 4 ++-- src/pages/stake.tsx | 4 ++-- src/pages/swap.tsx | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/SwapInput/index.tsx b/src/components/SwapInput/index.tsx index 171cbaa..a922aba 100644 --- a/src/components/SwapInput/index.tsx +++ b/src/components/SwapInput/index.tsx @@ -71,7 +71,7 @@ export const SwapInput: React.FC = ({ size="xxlarge" textAlign="start" min={0} - value={value} + value={value ? value : ''} onChange={(e) => { onChange(e?.target?.value) }} @@ -118,9 +118,7 @@ export const SwapInput: React.FC = ({ size="xxlarge" textAlign="start" min={0} - value={ - swapQuote && value ? String(Number(value) * swapQuote) : undefined - } + value={swapQuote && value ? String(Number(value) * swapQuote) : ''} onChange={(e) => { onChange(String(Number(e?.target?.value) / (swapQuote || 1))) }} diff --git a/src/hooks/useGetBalance.ts b/src/hooks/useGetBalance.ts index d19f678..10da83f 100644 --- a/src/hooks/useGetBalance.ts +++ b/src/hooks/useGetBalance.ts @@ -25,12 +25,12 @@ export const useGetBalance = (): { account_id: currentUser?.accountId, }) const newQuidBalance = utils.format.formatNearAmount(quidRes) - setQuidBalance(Number(newQuidBalance).toFixed(3)) + setQuidBalance(Number(newQuidBalance || 0).toFixed(3)) // Get Near balance const newNearBalance = utils.format.formatNearAmount( currentUser?.balance || '0' ) - setNearBalance(Number(newNearBalance).toFixed(3)) + setNearBalance(Number(newNearBalance || 0).toFixed(3)) } catch (e) { // Todo: add a toaster warning of errors console.error(e) diff --git a/src/pages/stake.tsx b/src/pages/stake.tsx index 8bf3a2a..8c7ba54 100644 --- a/src/pages/stake.tsx +++ b/src/pages/stake.tsx @@ -78,7 +78,7 @@ const Stake: React.FC = () => {
{ setIsQuid(!isQuid)} diff --git a/src/pages/swap.tsx b/src/pages/swap.tsx index f210000..35ef91b 100644 --- a/src/pages/swap.tsx +++ b/src/pages/swap.tsx @@ -87,7 +87,7 @@ const Swap: React.FC = () => { >