From c5110fa035c79f1c4d0f3bac361c9bd37605eaa8 Mon Sep 17 00:00:00 2001 From: Marcin Ciarka Date: Wed, 3 Apr 2024 12:20:51 +0200 Subject: [PATCH] Fix feature toggle bug and optimize event filtering --- .../omni-kit/helpers/getOmniPositionUrl.ts | 16 +++++++++++++++- .../helpers/aaveLikeFlowStateFilter.ts | 6 ++---- features/omni-kit/views/OmniFormView.tsx | 19 ++++++++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/features/omni-kit/helpers/getOmniPositionUrl.ts b/features/omni-kit/helpers/getOmniPositionUrl.ts index b8f66ec7ee..3f8e204241 100644 --- a/features/omni-kit/helpers/getOmniPositionUrl.ts +++ b/features/omni-kit/helpers/getOmniPositionUrl.ts @@ -3,7 +3,8 @@ import { getOmniProtocolUrlMap } from 'features/omni-kit/helpers' import { erc4626VaultsByName } from 'features/omni-kit/protocols/erc-4626/settings' import { Erc4626PseudoProtocol } from 'features/omni-kit/protocols/morpho-blue/constants' import type { OmniProductType } from 'features/omni-kit/types' -import type { LendingProtocol } from 'lendingProtocols' +import { getLocalAppConfig } from 'helpers/config' +import { LendingProtocol } from 'lendingProtocols' interface GetOmniPositionUrlParams { collateralAddress?: string @@ -32,8 +33,21 @@ export function getOmniPositionUrl({ quoteAddress, quoteToken, }: GetOmniPositionUrlParams) { + const featureToggles = getLocalAppConfig('features') const resolvedPositionId = positionId ? `/${positionId}` : '' + if ( + featureToggles.UseOmniKitLinks && + [LendingProtocol.AaveV3, LendingProtocol.SparkV3].includes(protocol) + ) { + return `/${networkName}/omni/${ + { + [LendingProtocol.AaveV3]: 'aave/v3', + [LendingProtocol.SparkV3]: 'spark', + }[protocol as LendingProtocol.SparkV3 | LendingProtocol.AaveV3] + }/${productType}/${collateralToken}-${quoteToken}` + } + if (pseudoProtocol === Erc4626PseudoProtocol && label) { const { id } = erc4626VaultsByName[label] diff --git a/features/omni-kit/protocols/aave-like/helpers/aaveLikeFlowStateFilter.ts b/features/omni-kit/protocols/aave-like/helpers/aaveLikeFlowStateFilter.ts index 935904d459..53e0e2df6a 100644 --- a/features/omni-kit/protocols/aave-like/helpers/aaveLikeFlowStateFilter.ts +++ b/features/omni-kit/protocols/aave-like/helpers/aaveLikeFlowStateFilter.ts @@ -13,9 +13,7 @@ export async function aaveLikeFlowStateFilter({ quoteAddress, protocol, networkId, - // we ignore filterConsumed because we dont want ANY positions with aave/spark debt - // so it doesnt matter if we're filtering all/used proxies - filterConsumed: _filterConsumed, + filterConsumed, }: OmniFlowStateFilterParams & { networkId: NetworkIds }): Promise { @@ -43,7 +41,7 @@ export async function aaveLikeFlowStateFilter({ address: event.args.proxyAddress, networkId: networkId as SparkV3SupportedNetwork, }) - return userData.totalDebtBase.isZero() + return !!filterConsumed && userData.totalDebtBase.isZero() } return Promise.resolve(false) } diff --git a/features/omni-kit/views/OmniFormView.tsx b/features/omni-kit/views/OmniFormView.tsx index 423392eb73..48947f41c9 100644 --- a/features/omni-kit/views/OmniFormView.tsx +++ b/features/omni-kit/views/OmniFormView.tsx @@ -121,12 +121,21 @@ export function OmniFormView({ state, quotePrecision, }), - filterConsumedProxy: async (events) => - ( - await Promise.all(events.map((event) => omniProxyFilter({ event, filterConsumed: true }))) - ).every(Boolean), + filterConsumedProxy: async (events) => { + // leaving this all separate as its easier for debugging + const filterConsumedProxiesPromisesList = events.map((event) => + omniProxyFilter({ event, filterConsumed: true }), + ) + const filteredConsumedProxies = await Promise.all(filterConsumedProxiesPromisesList) + return filteredConsumedProxies.every(Boolean) + }, onProxiesAvailable: async (events, dpmAccounts) => { - const filteredEvents = await Promise.all(events.filter((event) => omniProxyFilter({ event }))) + const filteredEventsBooleanMap = await Promise.all( + events.map((event) => omniProxyFilter({ event })), + ) + const filteredEvents = events.filter( + (_event, eventIndex) => filteredEventsBooleanMap[eventIndex], + ) if (!hasDupePosition && filteredEvents.length) { setHasDupePosition(true) openModal(OmniDupePositionModal, {