diff --git a/public/images/near_icon.svg b/public/images/near_icon.svg
index e96f09f..4cf2e15 100644
--- a/public/images/near_icon.svg
+++ b/public/images/near_icon.svg
@@ -1,5 +1,5 @@
diff --git a/src/components/SwapInput/index.tsx b/src/components/SwapInput/index.tsx
index e57154a..3439434 100644
--- a/src/components/SwapInput/index.tsx
+++ b/src/components/SwapInput/index.tsx
@@ -30,7 +30,7 @@ export const SwapInput: React.FC = ({
}
const getOutputValue = () => {
- if (isOutputUnlocked) return outputValue ? outputValue : undefined
+ if (isOutputUnlocked) return outputValue ? outputValue : ''
return swapQuote && value ? String(Number(value) * swapQuote) : ''
}
diff --git a/src/pages/borrow.tsx b/src/pages/borrow.tsx
index 0929a9c..4e7eb60 100644
--- a/src/pages/borrow.tsx
+++ b/src/pages/borrow.tsx
@@ -9,6 +9,7 @@ import { NearContext } from 'src/near/nearContext'
import { useGetNearQuoteQuery } from 'src/redux/api/nearQuote'
import { useGetBalance } from 'src/hooks/useGetBalance'
import { useGetStats } from 'src/hooks/useGetStats'
+import { toNumber } from 'src/utils/numbers'
import { SwapInput } from 'src/components/SwapInput'
@@ -16,14 +17,12 @@ const EXCHANGE_RATE = 0.99090909091
const Borrow: React.FC = () => {
const { contract } = React.useContext(NearContext)
- const [inputAmount, setInputAmount] = React.useState()
- const [outputAmount, setOutputAmount] = React.useState()
- const [inputWithdrawAmount, setInputWithdrawAmount] = React.useState<
- string | undefined
- >()
- const [outputWithdrawAmount, setOutputWithdrawAmount] = React.useState<
- string | undefined
- >()
+ const [inputAmount, setInputAmount] = React.useState('')
+ const [outputAmount, setOutputAmount] = React.useState('')
+ const [inputWithdrawAmount, setInputWithdrawAmount] =
+ React.useState('')
+ const [outputWithdrawAmount, setOutputWithdrawAmount] =
+ React.useState('')
const [isWithdraw, setIsWithdraw] = React.useState(false)
const [isLoading, setIsLoading] = React.useState(false)
const { quidBalance, nearBalance } = useGetBalance()
@@ -38,34 +37,37 @@ const Borrow: React.FC = () => {
const swapQuote = isQuid
? // Todo: investigate if exchange rate applies to Quid
- (1 / Number(nearQuote)) * EXCHANGE_RATE
- : Number(nearQuote) * EXCHANGE_RATE
+ (1 / toNumber(nearQuote)) * EXCHANGE_RATE
+ : toNumber(nearQuote) * EXCHANGE_RATE
const currentBalance = isQuid ? quidBalance : nearBalance
const getCollateralRatio = (): number => {
if (nearQuote && inputAmount && outputAmount) {
- return isQuid
- ? Number(Number(inputAmount) / (Number(outputAmount) * nearQuote))
- : Number(outputAmount) / (Number(inputAmount) * nearQuote)
+ const newRatio = isQuid
+ ? toNumber(toNumber(inputAmount) / (toNumber(outputAmount) * nearQuote))
+ : toNumber(outputAmount) / (toNumber(inputAmount) * nearQuote)
+ return toNumber(newRatio)
}
return 0
}
const getLiquidationPrice = (): number => {
if (nearQuote && inputAmount && outputAmount) {
- return nearQuote * getCollateralRatio()
+ const newLiquidation = nearQuote * getCollateralRatio()
+ return toNumber(newLiquidation)
}
return 0
}
const getGaugeNumber = () => {
- return isWithdraw
- ? (Number(stats?.debit || 0) - Number(outputWithdrawAmount || 0)) /
- ((Number(stats?.credit || 0) - Number(inputWithdrawAmount || 0)) *
- Number(nearQuote))
- : (Number(stats?.debit || 0) + Number(outputAmount || 0)) /
- ((Number(stats?.credit || 0) + Number(inputAmount || 0)) *
- Number(nearQuote))
+ const newValue = isWithdraw
+ ? (toNumber(stats?.debit) - toNumber(outputWithdrawAmount)) /
+ ((toNumber(stats?.credit) - toNumber(inputWithdrawAmount)) *
+ toNumber(nearQuote))
+ : (toNumber(stats?.debit) + toNumber(outputAmount)) /
+ ((toNumber(stats?.credit) + toNumber(inputAmount)) *
+ toNumber(nearQuote))
+ return toNumber(newValue)
}
const handleBorrow = async () => {
@@ -176,22 +178,24 @@ const Borrow: React.FC = () => {
Deposit
(Near)
- {stats?.credit ? Number(stats?.credit).toFixed(3) : 0}
+ {stats?.credit ? toNumber(stats?.credit).toFixed(3) : 0}
Debt
- {stats?.debit ? Number(stats?.debit).toFixed(3) : 0}
+ {stats?.debit ? toNumber(stats?.debit).toFixed(3) : 0}
@@ -212,12 +216,8 @@ const Borrow: React.FC = () => {
{
+ if (value && typeof value === 'number') {
+ return value
+ }
+ if (value && typeof value === 'string') {
+ return Number(value) || 0
+ }
+ return 0
+}