Mp 3007 implement auto lend on account funding (#375)

* fix(deposit): formatting

* feat(deposit): auto lend on account funding

* add missing file

* feat(auto-lend): filter out feature disabled assets
This commit is contained in:
Yusuf Seyrek 2023-08-17 12:56:32 +03:00 committed by GitHub
parent 8df7426abd
commit 13d153de69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -14,8 +14,10 @@ import {
import { getSingleValueFromBroadcastResult } from 'utils/broadcast'
import { defaultFee } from 'utils/constants'
import { formatAmountWithSymbol } from 'utils/formatters'
import checkAutoLendEnabled from 'utils/checkAutoLendEnabled'
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
import { BN } from 'utils/helpers'
import { getAssetByDenom } from 'utils/assets'
function generateExecutionMessage(
sender: string | undefined = '',
@ -176,6 +178,14 @@ export default function createBroadcastSlice(
},
}
if (checkAutoLendEnabled(options.accountId)) {
msg.update_credit_account.actions.push(
...options.coins
.filter((coin) => getAssetByDenom(coin.denom)?.isAutoLendEnabled)
.map((coin) => ({ lend: coin.toActionCoin(true) })),
)
}
const funds = options.coins.map((coin) => coin.toCoin())
const response = await get().executeMsg({
@ -184,7 +194,7 @@ export default function createBroadcastSlice(
const depositString = options.coins
.map((coin) => formatAmountWithSymbol(coin.toCoin()))
.join('and ')
.join(' and ')
handleResponseMessages(response, `Deposited ${depositString} to Account ${options.accountId}`)
return !!response.result
},

View File

@ -0,0 +1,8 @@
import { AUTO_LEND_ENABLED_ACCOUNT_IDS_KEY } from 'constants/localStore'
export default function checkAutoLendEnabled(accountId: string) {
const storageItem = localStorage.getItem(AUTO_LEND_ENABLED_ACCOUNT_IDS_KEY)
const autoLendEnabledAccountIds: string[] = storageItem ? JSON.parse(storageItem) : []
return autoLendEnabledAccountIds.includes(accountId)
}