diff --git a/src/components/Trade/TradeModule/SwapForm/index.tsx b/src/components/Trade/TradeModule/SwapForm/index.tsx index 83f57c2a..e90861c6 100644 --- a/src/components/Trade/TradeModule/SwapForm/index.tsx +++ b/src/components/Trade/TradeModule/SwapForm/index.tsx @@ -55,7 +55,7 @@ export default function SwapForm(props: Props) { const isAutoLendEnabled = account ? autoLendEnabledAccountIds.includes(account.id) : false const throttledEstimateExactIn = useMemo(() => asyncThrottle(estimateExactIn, 250), []) - const { simulateTrade } = useUpdatedAccount(account) + const { simulateTrade, removedLends } = useUpdatedAccount(account) const borrowAsset = useMemo( () => borrowAssets.find(byDenom(sellAsset.denom)), @@ -165,6 +165,7 @@ export default function SwapForm(props: Props) { return swap({ accountId: account?.id || '', coinIn: BNCoin.fromDenomAndBigNumber(sellAsset.denom, sellAssetAmount.integerValue()), + reclaim: removedLends[0], borrow: borrowCoin, denomOut: buyAsset.denom, slippage, @@ -305,4 +306,4 @@ export default function SwapForm(props: Props) { ) -} +} \ No newline at end of file diff --git a/src/hooks/useUpdatedAccount/index.ts b/src/hooks/useUpdatedAccount/index.ts index 02da880d..22cb6bb6 100644 --- a/src/hooks/useUpdatedAccount/index.ts +++ b/src/hooks/useUpdatedAccount/index.ts @@ -136,8 +136,9 @@ export function useUpdatedAccount(account?: Account) { const { deposit, lend } = getDepositAndLendCoinsToSpend(removeCoin, account) - removeDeposits([deposit]) - removeLends([lend]) + if (!deposit.amount.isZero()) removeDeposits([deposit]) + if (!lend.amount.isZero()) removeLends([lend]) + if (target === 'deposit') addDeposits([addCoin]) if (target === 'lend') addLends([addCoin]) @@ -222,4 +223,4 @@ export function useUpdatedAccount(account?: Account) { simulateVaultDeposit, simulateWithdraw, } -} +} \ No newline at end of file diff --git a/src/store/slices/broadcast.ts b/src/store/slices/broadcast.ts index 53cf4ca5..3e0e7a31 100644 --- a/src/store/slices/broadcast.ts +++ b/src/store/slices/broadcast.ts @@ -20,6 +20,7 @@ import { formatAmountWithSymbol } from 'utils/formatters' import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse' import { BN } from 'utils/helpers' + function generateExecutionMessage( sender: string | undefined = '', contract: string, @@ -414,7 +415,7 @@ export default function createBroadcastSlice( handleResponseMessages( response, - `Successfully deposited ${formatAmountWithSymbol(options.coin.toCoin())}`, + `Successfully lent ${formatAmountWithSymbol(options.coin.toCoin())}`, ) return !!response.result }, @@ -443,6 +444,7 @@ export default function createBroadcastSlice( swap: (options: { accountId: string coinIn: BNCoin + reclaim?: BNCoin borrow?: BNCoin denomOut: string slippage: number @@ -452,6 +454,7 @@ export default function createBroadcastSlice( update_credit_account: { account_id: options.accountId, actions: [ + ...(options.reclaim ? [{ reclaim: options.reclaim.toActionCoin() }] : []), ...(options.borrow ? [{ borrow: options.borrow.toCoin() }] : []), { swap_exact_in: { @@ -526,4 +529,4 @@ export default function createBroadcastSlice( } }, } -} +} \ No newline at end of file diff --git a/src/types/interfaces/store/broadcast.d.ts b/src/types/interfaces/store/broadcast.d.ts index d0902325..07fce14b 100644 --- a/src/types/interfaces/store/broadcast.d.ts +++ b/src/types/interfaces/store/broadcast.d.ts @@ -34,7 +34,8 @@ interface BroadcastSlice { swap: (options: { accountId: string coinIn: BNCoin - borrow: BNCoin + reclaim?: BNCoin + borrow?: BNCoin denomOut: string slippage: number isMax?: boolean @@ -52,4 +53,4 @@ interface BroadcastSlice { borrow: BNCoin[] reclaims: ActionCoin[] }) => Promise -} +} \ No newline at end of file