From 13d153de69bcb3126f3b5212d0620c52691403fa Mon Sep 17 00:00:00 2001 From: Yusuf Seyrek Date: Thu, 17 Aug 2023 12:56:32 +0300 Subject: [PATCH] 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 --- src/store/slices/broadcast.ts | 12 +++++++++++- src/utils/checkAutoLendEnabled.ts | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/utils/checkAutoLendEnabled.ts diff --git a/src/store/slices/broadcast.ts b/src/store/slices/broadcast.ts index 41e6768a..31b42e0e 100644 --- a/src/store/slices/broadcast.ts +++ b/src/store/slices/broadcast.ts @@ -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 }, diff --git a/src/utils/checkAutoLendEnabled.ts b/src/utils/checkAutoLendEnabled.ts new file mode 100644 index 00000000..566319c7 --- /dev/null +++ b/src/utils/checkAutoLendEnabled.ts @@ -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) +}