Post demo fixes (#458)
* fix: show precission * fix: fixed borrow to wallet * fix: fixed autoLend on funding * fix: adjusted according to feedback * fix: typo * fix: typo
This commit is contained in:
parent
5a5d86f17c
commit
81306b501c
@ -24,8 +24,7 @@ import useCurrentAccount from 'hooks/useCurrentAccount'
|
|||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { getAssetByDenom } from 'utils/assets'
|
import { getAssetByDenom } from 'utils/assets'
|
||||||
import { demagnify } from 'utils/formatters'
|
import { demagnify, formatAmountToPrecision } from 'utils/formatters'
|
||||||
import { BN } from 'utils/helpers'
|
|
||||||
import { getPage, getRoute } from 'utils/route'
|
import { getPage, getRoute } from 'utils/route'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -41,6 +40,7 @@ export default function Index(props: Props) {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { pathname } = useLocation()
|
const { pathname } = useLocation()
|
||||||
const address = useStore((s) => s.address)
|
const address = useStore((s) => s.address)
|
||||||
|
const baseCurrency = useStore((s) => s.baseCurrency)
|
||||||
const [sorting, setSorting] = useState<SortingState>([])
|
const [sorting, setSorting] = useState<SortingState>([])
|
||||||
const updatedAccount = useStore((s) => s.updatedAccount)
|
const updatedAccount = useStore((s) => s.updatedAccount)
|
||||||
const accountBalanceData = useAccountBalanceData({
|
const accountBalanceData = useAccountBalanceData({
|
||||||
@ -94,8 +94,8 @@ export default function Index(props: Props) {
|
|||||||
return (
|
return (
|
||||||
<FormattedNumber
|
<FormattedNumber
|
||||||
className={classNames('text-xs text-right', color)}
|
className={classNames('text-xs text-right', color)}
|
||||||
amount={Number(BN(amount).abs())}
|
amount={formatAmountToPrecision(amount, baseCurrency.decimals)}
|
||||||
options={{ maxDecimals: 4, abbreviated: true }}
|
options={{ maxDecimals: baseCurrency.decimals, minDecimals: 0, abbreviated: true }}
|
||||||
animate
|
animate
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@ -119,7 +119,7 @@ export default function Index(props: Props) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[baseCurrency.decimals],
|
||||||
)
|
)
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
|
@ -44,10 +44,10 @@ export default function AccountFundContent(props: Props) {
|
|||||||
const [fundingAssets, setFundingAssets] = useState<BNCoin[]>([])
|
const [fundingAssets, setFundingAssets] = useState<BNCoin[]>([])
|
||||||
const { data: marketAssets } = useMarketAssets()
|
const { data: marketAssets } = useMarketAssets()
|
||||||
const { data: walletBalances } = useWalletBalances(props.address)
|
const { data: walletBalances } = useWalletBalances(props.address)
|
||||||
const { autoLendEnabledAccountIds, enableAutoLendAccountId } = useAutoLend()
|
const { autoLendEnabledAccountIds } = useAutoLend()
|
||||||
const [isLending, toggleIsLending] = useToggle(lendAssets)
|
const [isLending, toggleIsLending] = useToggle(lendAssets)
|
||||||
const { simulateDeposits } = useUpdatedAccount(props.account)
|
const { simulateDeposits } = useUpdatedAccount(props.account)
|
||||||
|
const autoLendEnabled = autoLendEnabledAccountIds.includes(props.accountId)
|
||||||
const baseAsset = getBaseAsset()
|
const baseAsset = getBaseAsset()
|
||||||
|
|
||||||
const hasAssetSelected = fundingAssets.length > 0
|
const hasAssetSelected = fundingAssets.length > 0
|
||||||
@ -126,16 +126,8 @@ export default function AccountFundContent(props: Props) {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const autoLendEnabled = autoLendEnabledAccountIds.includes(props.accountId)
|
|
||||||
if (lendAssets && !autoLendEnabled) enableAutoLendAccountId(props.accountId)
|
|
||||||
toggleIsLending(autoLendEnabled)
|
toggleIsLending(autoLendEnabled)
|
||||||
}, [
|
}, [autoLendEnabled, toggleIsLending])
|
||||||
props.accountId,
|
|
||||||
autoLendEnabledAccountIds,
|
|
||||||
toggleIsLending,
|
|
||||||
lendAssets,
|
|
||||||
enableAutoLendAccountId,
|
|
||||||
])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (accounts?.length === 1 && isLending) setLendAssets(true)
|
if (accounts?.length === 1 && isLending) setLendAssets(true)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
import AccountSummary from 'components/Account/AccountSummary'
|
import AccountSummary from 'components/Account/AccountSummary'
|
||||||
import AssetImage from 'components/AssetImage'
|
import AssetImage from 'components/AssetImage'
|
||||||
@ -69,7 +69,11 @@ function BorrowModal(props: Props) {
|
|||||||
const isAutoLendEnabled = autoLendEnabledAccountIds.includes(account.id)
|
const isAutoLendEnabled = autoLendEnabledAccountIds.includes(account.id)
|
||||||
const { computeMaxBorrowAmount } = useHealthComputer(account)
|
const { computeMaxBorrowAmount } = useHealthComputer(account)
|
||||||
const totalDebt = BN(getDebtAmount(modal))
|
const totalDebt = BN(getDebtAmount(modal))
|
||||||
const totalDebtRepayAmount = getDebtAmountWithInterest(totalDebt, Number(apr))
|
|
||||||
|
const totalDebtRepayAmount = useMemo(
|
||||||
|
() => getDebtAmountWithInterest(totalDebt, Number(apr)),
|
||||||
|
[totalDebt, apr],
|
||||||
|
)
|
||||||
|
|
||||||
function resetState() {
|
function resetState() {
|
||||||
setAmount(BN_ZERO)
|
setAmount(BN_ZERO)
|
||||||
@ -112,16 +116,28 @@ function BorrowModal(props: Props) {
|
|||||||
(newAmount: BigNumber) => {
|
(newAmount: BigNumber) => {
|
||||||
const coin = BNCoin.fromDenomAndBigNumber(asset.denom, newAmount)
|
const coin = BNCoin.fromDenomAndBigNumber(asset.denom, newAmount)
|
||||||
if (!amount.isEqualTo(newAmount)) setAmount(newAmount)
|
if (!amount.isEqualTo(newAmount)) setAmount(newAmount)
|
||||||
if (isRepay) {
|
if (!isRepay) return
|
||||||
const repayCoin = coin.amount.isGreaterThan(totalDebt)
|
const repayCoin = coin.amount.isGreaterThan(totalDebt)
|
||||||
? BNCoin.fromDenomAndBigNumber(asset.denom, totalDebt)
|
? BNCoin.fromDenomAndBigNumber(asset.denom, totalDebt)
|
||||||
: coin
|
: coin
|
||||||
simulateRepay(repayCoin)
|
simulateRepay(repayCoin)
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[asset, amount, isRepay, simulateRepay, modal, totalDebt, totalDebtRepayAmount],
|
[amount, asset.denom, isRepay, simulateRepay, totalDebt],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxBorrow = useMemo(() => {
|
||||||
|
const maxBorrowAmount = isRepay
|
||||||
|
? BN_ZERO
|
||||||
|
: computeMaxBorrowAmount(asset.denom, borrowToWallet ? 'wallet' : 'deposit')
|
||||||
|
|
||||||
|
return BigNumber.min(maxBorrowAmount, modal.marketData?.liquidity?.amount || 0)
|
||||||
|
}, [asset.denom, borrowToWallet, computeMaxBorrowAmount, isRepay, modal.marketData])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!account || isRepay) return
|
||||||
|
if (maxBorrow !== max) setMax(maxBorrow)
|
||||||
|
}, [account, isRepay, maxBorrow, max])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!account) return
|
if (!account) return
|
||||||
if (isRepay) {
|
if (isRepay) {
|
||||||
@ -132,23 +148,7 @@ function BorrowModal(props: Props) {
|
|||||||
setMax(maxRepayAmount)
|
setMax(maxRepayAmount)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}, [account, asset.denom, isRepay, totalDebtRepayAmount])
|
||||||
const maxBorrowAmount = computeMaxBorrowAmount(
|
|
||||||
asset.denom,
|
|
||||||
borrowToWallet ? 'wallet' : 'deposit',
|
|
||||||
)
|
|
||||||
|
|
||||||
setMax(BigNumber.min(maxBorrowAmount, modal.marketData?.liquidity?.amount || 0))
|
|
||||||
}, [
|
|
||||||
account,
|
|
||||||
isRepay,
|
|
||||||
modal,
|
|
||||||
asset.denom,
|
|
||||||
computeMaxBorrowAmount,
|
|
||||||
borrowToWallet,
|
|
||||||
apr,
|
|
||||||
totalDebtRepayAmount,
|
|
||||||
])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (amount.isGreaterThan(max)) {
|
if (amount.isGreaterThan(max)) {
|
||||||
|
@ -61,8 +61,8 @@ export function useUpdatedAccount(account?: Account) {
|
|||||||
const simulateBorrow = useCallback(
|
const simulateBorrow = useCallback(
|
||||||
(target: 'wallet' | 'deposit' | 'lend', coin: BNCoin) => {
|
(target: 'wallet' | 'deposit' | 'lend', coin: BNCoin) => {
|
||||||
if (!account) return
|
if (!account) return
|
||||||
removeDeposits([])
|
addDeposits([])
|
||||||
removeLends([])
|
addLends([])
|
||||||
addDebts([coin])
|
addDebts([coin])
|
||||||
if (target === 'deposit') addDeposits([coin])
|
if (target === 'deposit') addDeposits([coin])
|
||||||
if (target === 'lend') addLends([coin])
|
if (target === 'lend') addLends([coin])
|
||||||
|
@ -6,7 +6,7 @@ import { BN_ZERO } from 'constants/math'
|
|||||||
import { ORACLE_DENOM } from 'constants/oracle'
|
import { ORACLE_DENOM } from 'constants/oracle'
|
||||||
import { BNCoin } from 'types/classes/BNCoin'
|
import { BNCoin } from 'types/classes/BNCoin'
|
||||||
import { byDenom } from 'utils/array'
|
import { byDenom } from 'utils/array'
|
||||||
import { getAllAssets, getEnabledMarketAssets } from 'utils/assets'
|
import { getAllAssets } from 'utils/assets'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
|
||||||
export function truncate(text = '', [h, t]: [number, number] = [6, 6]): string {
|
export function truncate(text = '', [h, t]: [number, number] = [6, 6]): string {
|
||||||
@ -162,6 +162,10 @@ export function formatAmountWithSymbol(coin: Coin) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatAmountToPrecision(amount: number | string, decimals: number) {
|
||||||
|
return Number(BN(amount).toPrecision(decimals))
|
||||||
|
}
|
||||||
|
|
||||||
export const convertPercentage = (percent: number) => {
|
export const convertPercentage = (percent: number) => {
|
||||||
let percentage = percent
|
let percentage = percent
|
||||||
if (percent >= 100) percentage = 100
|
if (percent >= 100) percentage = 100
|
||||||
|
Loading…
Reference in New Issue
Block a user