Skip to content

Commit

Permalink
Fix feature toggle bug and optimize event filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinciarka committed Apr 3, 2024
1 parent cecb745 commit c5110fa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
16 changes: 15 additions & 1 deletion features/omni-kit/helpers/getOmniPositionUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand Down Expand Up @@ -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)
}
19 changes: 14 additions & 5 deletions features/omni-kit/views/OmniFormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit c5110fa

Please sign in to comment.