Skip to content

Commit e5a9afd

Browse files
v3.0.8 (#1770)
Co-authored-by: Monkmansteve <47855432+StefChatz@users.noreply.github.com>
1 parent e967724 commit e5a9afd

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/components/common/MarketDetails.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export default function MarketDetails({ row, type }: Props) {
5353
title: 'Oracle Price',
5454
},
5555
{
56-
amount: debt.isZero() ? 0 : debt.dividedBy(deposits).multipliedBy(100).toNumber(),
56+
amount: debt.isZero()
57+
? 0
58+
: Math.min(debt.dividedBy(deposits).multipliedBy(100).toNumber(), 100),
5759
options: { minDecimals: 2, maxDecimals: 2, suffix: '%' },
5860
title: 'Utilization Rate',
5961
},
@@ -82,7 +84,9 @@ export default function MarketDetails({ row, type }: Props) {
8284
title: 'Oracle Price',
8385
},
8486
{
85-
amount: debt.isZero() ? 0 : debt.dividedBy(deposits).multipliedBy(100).toNumber(),
87+
amount: debt.isZero()
88+
? 0
89+
: Math.min(debt.dividedBy(deposits).multipliedBy(100).toNumber(), 100),
8690
options: { minDecimals: 2, maxDecimals: 2, suffix: '%' },
8791
title: 'Utilization Rate',
8892
},

src/components/earn/lend/Table/Columns/LendButton.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default function LendButton(props: Props) {
3838
const assetDepositAmount = accountDeposits.find(byDenom(props.data.asset.denom))?.amount
3939
const address = useStore((s) => s.address)
4040
const hasWalletBalance = walletBalance && BN(walletBalance.amount).isGreaterThan(0)
41+
const hasAccountDeposit = assetDepositAmount && assetDepositAmount.isGreaterThan(0)
4142
const isDefaultAccount = currentAccount?.kind === 'default'
4243
const isLendEnabled = !!props.data.asset.isAutoLendEnabled
4344
const { isAutoLendEnabledForCurrentAccount } = useAutoLend()
@@ -51,6 +52,8 @@ export default function LendButton(props: Props) {
5152
onClick: () => {
5253
openDeposit(props.data)
5354
},
55+
disabled: !hasWalletBalance,
56+
disabledTooltip: `You don't have any ${props.data.asset.symbol} in your wallet.`,
5457
},
5558
...(isLendEnabled
5659
? [
@@ -60,10 +63,12 @@ export default function LendButton(props: Props) {
6063
onClick: () => {
6164
openDepositAndLend(props.data)
6265
},
66+
disabled: !hasWalletBalance,
67+
disabledTooltip: `You don't have any ${props.data.asset.symbol} in your wallet.`,
6368
},
6469
]
6570
: []),
66-
...(isLendEnabled && assetDepositAmount
71+
...(isLendEnabled && hasAccountDeposit
6772
? [
6873
{
6974
icon: <ArrowUpLine />,
@@ -73,11 +78,19 @@ export default function LendButton(props: Props) {
7378
]
7479
: []),
7580
],
76-
[assetDepositAmount, isLendEnabled, openLend, openDeposit, openDepositAndLend, props.data],
81+
[
82+
hasWalletBalance,
83+
hasAccountDeposit,
84+
isLendEnabled,
85+
openLend,
86+
openDeposit,
87+
openDepositAndLend,
88+
props.data,
89+
],
7790
)
7891

79-
// If user has wallet balance and it's a default account, show Manage dropdown
80-
if (hasWalletBalance && address && isDefaultAccount) {
92+
// If user has wallet balance or account deposits and it's a default account, show Manage dropdown
93+
if ((hasWalletBalance || hasAccountDeposit) && address && isDefaultAccount) {
8194
return (
8295
<div className='flex justify-end'>
8396
<DropDownButton items={ITEMS} text='Manage' color='tertiary' />
@@ -123,16 +136,20 @@ export default function LendButton(props: Props) {
123136
// If asset doesn't support lending, don't show anything
124137
if (!isLendEnabled) return null
125138

139+
// For lending: user can lend from wallet OR from unlent account deposits
140+
const canLend = hasWalletBalance || hasAccountDeposit
141+
const lendTooltip = !canLend
142+
? `You don't have any ${props.data.asset.symbol} in your wallet or Credit Account.`
143+
: undefined
144+
126145
return (
127146
<div className='flex justify-end'>
128147
<ConditionalWrapper
129-
condition={!hasWalletBalance && !!address}
148+
condition={!canLend && !!address}
130149
wrapper={(children) => (
131150
<Tooltip
132151
type='warning'
133-
content={
134-
<Text size='sm'>{`You don't have any ${props.data.asset.symbol} in your wallet.`}</Text>
135-
}
152+
content={<Text size='sm'>{lendTooltip}</Text>}
136153
contentClassName='max-w-[200px]'
137154
className='ml-auto'
138155
>
@@ -143,7 +160,7 @@ export default function LendButton(props: Props) {
143160
{isAutoLendEnabledForCurrentAccount ? (
144161
<ActionButton
145162
leftIcon={<ArrowUpLine />}
146-
disabled={!hasWalletBalance}
163+
disabled={!canLend}
147164
color='tertiary'
148165
onClick={(e) => {
149166
openLend(props.data)

src/hooks/markets/useMarketsInfo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import BigNumber from 'bignumber.js'
12
import useSWR from 'swr'
23

4+
import { BN_ZERO } from 'constants/math'
35
import useChainConfig from 'hooks/chain/useChainConfig'
46
import useClients from 'hooks/chain/useClients'
57
import { BN } from 'utils/helpers'
@@ -42,6 +44,6 @@ async function getMarketsInfo(clients: ContractClients) {
4244
...market,
4345
debt: BN(debts[index]),
4446
deposits: BN(liquidity[index]),
45-
liquidity: BN(liquidity[index]).minus(debts[index]),
47+
liquidity: BigNumber.max(BN(liquidity[index]).minus(debts[index]), BN_ZERO),
4648
}))
4749
}

0 commit comments

Comments
 (0)