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:
parent
8df7426abd
commit
13d153de69
@ -14,8 +14,10 @@ import {
|
|||||||
import { getSingleValueFromBroadcastResult } from 'utils/broadcast'
|
import { getSingleValueFromBroadcastResult } from 'utils/broadcast'
|
||||||
import { defaultFee } from 'utils/constants'
|
import { defaultFee } from 'utils/constants'
|
||||||
import { formatAmountWithSymbol } from 'utils/formatters'
|
import { formatAmountWithSymbol } from 'utils/formatters'
|
||||||
|
import checkAutoLendEnabled from 'utils/checkAutoLendEnabled'
|
||||||
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
import { getAssetByDenom } from 'utils/assets'
|
||||||
|
|
||||||
function generateExecutionMessage(
|
function generateExecutionMessage(
|
||||||
sender: string | undefined = '',
|
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 funds = options.coins.map((coin) => coin.toCoin())
|
||||||
|
|
||||||
const response = await get().executeMsg({
|
const response = await get().executeMsg({
|
||||||
@ -184,7 +194,7 @@ export default function createBroadcastSlice(
|
|||||||
|
|
||||||
const depositString = options.coins
|
const depositString = options.coins
|
||||||
.map((coin) => formatAmountWithSymbol(coin.toCoin()))
|
.map((coin) => formatAmountWithSymbol(coin.toCoin()))
|
||||||
.join('and ')
|
.join(' and ')
|
||||||
handleResponseMessages(response, `Deposited ${depositString} to Account ${options.accountId}`)
|
handleResponseMessages(response, `Deposited ${depositString} to Account ${options.accountId}`)
|
||||||
return !!response.result
|
return !!response.result
|
||||||
},
|
},
|
||||||
|
8
src/utils/checkAutoLendEnabled.ts
Normal file
8
src/utils/checkAutoLendEnabled.ts
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user