Merge branch 'main' of https://github.com/mars-protocol/mars-v2-frontend into develop
# Conflicts: # package.json # src/components/Modals/BorrowModal.tsx # src/components/Trade/TradeChart/TVChartContainer.tsx # src/components/Trade/TradeChart/index.tsx # src/components/Trade/TradeModule/SwapForm/TradeSummary.tsx # src/components/Trade/TradeModule/SwapForm/index.tsx # src/components/Trade/TradeModule/index.tsx # src/components/Wallet/WalletFetchBalancesAndAccounts.tsx # src/pages/TradePage.tsx
This commit is contained in:
commit
701071d981
@ -35,8 +35,8 @@ export default function DepositCapMessage(props: Props) {
|
||||
<FormattedNumber
|
||||
amount={coin.amount.toNumber()}
|
||||
options={{
|
||||
abbreviated: true,
|
||||
decimals: asset.decimals,
|
||||
maxDecimals: asset.decimals,
|
||||
suffix: ` ${asset.symbol}`,
|
||||
}}
|
||||
className='text-xs text-white/60'
|
||||
|
@ -18,6 +18,7 @@ import { BN_ZERO } from 'constants/math'
|
||||
import useAutoLend from 'hooks/useAutoLend'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useHealthComputer from 'hooks/useHealthComputer'
|
||||
import useMarketAssets from 'hooks/useMarketAssets'
|
||||
import useToggle from 'hooks/useToggle'
|
||||
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
|
||||
import { getDepositAndLendCoinsToSpend } from 'hooks/useUpdatedAccount/functions'
|
||||
@ -90,6 +91,7 @@ function BorrowModal(props: Props) {
|
||||
const isAutoLendEnabled = autoLendEnabledAccountIds.includes(account.id)
|
||||
const { computeMaxBorrowAmount } = useHealthComputer(account)
|
||||
const totalDebt = BN(getDebtAmount(modal))
|
||||
const { data: marketAssets } = useMarketAssets()
|
||||
|
||||
const [depositBalance, lendBalance] = useMemo(
|
||||
() => [
|
||||
@ -104,11 +106,22 @@ function BorrowModal(props: Props) {
|
||||
[totalDebt, apy],
|
||||
)
|
||||
|
||||
const overpayExeedsCap = useMemo(() => {
|
||||
const marketAsset = marketAssets.find(byDenom(asset.denom))
|
||||
if (!marketAsset) return
|
||||
const overpayAmount = totalDebtRepayAmount.minus(totalDebt)
|
||||
const marketCapAfterOverpay = marketAsset.cap.used.plus(overpayAmount)
|
||||
|
||||
return marketAsset.cap.max.isLessThanOrEqualTo(marketCapAfterOverpay)
|
||||
}, [marketAssets, asset.denom])
|
||||
|
||||
const maxRepayAmount = useMemo(() => {
|
||||
const maxBalance = repayFromWallet
|
||||
? BN(walletBalances.find(byDenom(asset.denom))?.amount ?? 0)
|
||||
: depositBalance.plus(lendBalance)
|
||||
return isRepay ? BigNumber.min(maxBalance, totalDebtRepayAmount) : BN_ZERO
|
||||
return isRepay
|
||||
? BigNumber.min(maxBalance, overpayExeedsCap ? totalDebt : totalDebtRepayAmount)
|
||||
: BN_ZERO
|
||||
}, [
|
||||
depositBalance,
|
||||
lendBalance,
|
||||
|
@ -586,7 +586,6 @@ export default function createBroadcastSlice(
|
||||
fromWallet?: boolean
|
||||
}) => {
|
||||
const actions: Action[] = [
|
||||
...(options.fromWallet ? [{ deposit: options.coin.toCoin() }] : []),
|
||||
{
|
||||
repay: {
|
||||
coin: options.coin.toActionCoin(options.accountBalance),
|
||||
@ -597,12 +596,18 @@ export default function createBroadcastSlice(
|
||||
if (options.lend && options.lend.amount.isGreaterThan(0))
|
||||
actions.unshift({ reclaim: options.lend.toActionCoin() })
|
||||
|
||||
const msg: CreditManagerExecuteMsg = {
|
||||
update_credit_account: {
|
||||
account_id: options.accountId,
|
||||
actions,
|
||||
},
|
||||
}
|
||||
const msg: CreditManagerExecuteMsg = options.fromWallet
|
||||
? {
|
||||
repay_from_wallet: {
|
||||
account_id: options.accountId,
|
||||
},
|
||||
}
|
||||
: {
|
||||
update_credit_account: {
|
||||
account_id: options.accountId,
|
||||
actions,
|
||||
},
|
||||
}
|
||||
|
||||
const response = get().executeMsg({
|
||||
messages: [
|
||||
|
Loading…
Reference in New Issue
Block a user