Skip to content

Commit

Permalink
Fixed out of range bugs on inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrosimao committed Feb 17, 2022
1 parent f41fca7 commit 2922126
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/components/SwapInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const SwapInput: React.FC<t.SwapInputPropsType> = ({
size="xxlarge"
textAlign="start"
min={0}
value={value}
value={value ? value : ''}
onChange={(e) => {
onChange(e?.target?.value)
}}
Expand Down Expand Up @@ -118,9 +118,7 @@ export const SwapInput: React.FC<t.SwapInputPropsType> = ({
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)))
}}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useGetBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/stake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Stake: React.FC = () => {
<br />
<Box direction="column">
<CryptoInput
value={String(depositAmnt)}
value={depositAmnt ? String(depositAmnt) : ''}
maxValue={currentBalance}
onChange={setDepositAmnt}
currencyQuote={nearQuote}
Expand Down Expand Up @@ -126,7 +126,7 @@ const Stake: React.FC = () => {
<Box direction="column">
<CryptoInput
maxValue={currentSpBalance}
value={String(withdrawAmnt)}
value={withdrawAmnt ? String(withdrawAmnt) : ''}
currencyQuote={nearQuote}
onChange={setWithdrawAmnt}
onChangeCurrency={() => setIsQuid(!isQuid)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Swap: React.FC = () => {
>
<Box direction="column">
<SwapInput
value={String(swapAmount)}
value={swapAmount ? String(swapAmount) : ''}
maxValue={currentBalance}
onChange={setSwapAmount}
swapQuote={swapQuote}
Expand Down

0 comments on commit 2922126

Please sign in to comment.