diff --git a/handlers/portfolio/positions/handlers/aave-like/helpers.ts b/handlers/portfolio/positions/handlers/aave-like/helpers.ts index b8a5a7b0ad..20cb88f2ab 100644 --- a/handlers/portfolio/positions/handlers/aave-like/helpers.ts +++ b/handlers/portfolio/positions/handlers/aave-like/helpers.ts @@ -77,6 +77,7 @@ interface CommonDataMapperParams { apiVaults?: Vault[] allOraclePrices?: AaveLikeOraclePriceData debug?: boolean + useOmniKitLinks?: boolean } export const commonDataMapper = ({ @@ -87,6 +88,7 @@ export const commonDataMapper = ({ apiVaults, allOraclePrices, debug, + useOmniKitLinks, }: CommonDataMapperParams) => { const primaryToken = getTokenName(dpm.networkId, dpm.collateralToken) const secondaryToken = getTokenName(dpm.networkId, dpm.debtToken) @@ -119,27 +121,37 @@ export const commonDataMapper = ({ Spark: emptyAutomations, AAVE_V3: emptyAutomations, }[dpm.protocol] + const primaryTokenSymbol = getTokenDisplayName(primaryToken) + const secondaryTokenSymbol = getTokenDisplayName(secondaryToken) + const omniKitUrl = `/${networksById[dpm.networkId].name.toLowerCase()}/omni/${ + { + AAVE_V3: 'aave/v3', + Spark: 'spark', + }[dpm.protocol] + }/${positionType}/${primaryTokenSymbol.toLocaleLowerCase()}-${secondaryTokenSymbol.toLocaleLowerCase()}/${dpm.vaultId}` + const regularUrl = `/${networksById[dpm.networkId].name.toLowerCase()}/${ + { + AAVE_V3: 'aave', + Spark: 'spark', + AAVE: 'aave', + }[dpm.protocol] + }/${ + { + AAVE_V3: 'v3', + Spark: 'v3', + AAVE: 'v2', + }[dpm.protocol] + }/${dpm.vaultId}` + const url = useOmniKitLinks && dpm.protocol !== 'AAVE' ? omniKitUrl : regularUrl return { commonData: { positionId: positionIdAsString ? dpm.vaultId : Number(dpm.vaultId), type: positionType, network: networksById[dpm.networkId].name, protocol, - primaryToken: getTokenDisplayName(primaryToken), - secondaryToken: getTokenDisplayName(secondaryToken), - url: `/${networksById[dpm.networkId].name.toLowerCase()}/${ - { - AAVE_V3: 'aave', - Spark: 'spark', - AAVE: 'aave', - }[dpm.protocol] - }/${ - { - AAVE_V3: 'v3', - Spark: 'v3', - AAVE: 'v2', - }[dpm.protocol] - }/${dpm.vaultId}`, + primaryToken: primaryTokenSymbol, + secondaryToken: secondaryTokenSymbol, + url, automations: { ...(dpm.positionType !== OmniProductType.Earn ? { diff --git a/handlers/portfolio/positions/handlers/aave-like/index.ts b/handlers/portfolio/positions/handlers/aave-like/index.ts index 2db8a2015e..3fad659c5e 100644 --- a/handlers/portfolio/positions/handlers/aave-like/index.ts +++ b/handlers/portfolio/positions/handlers/aave-like/index.ts @@ -39,6 +39,7 @@ const getAaveLikeBorrowPosition: GetAaveLikePositionHandlerType = async ({ allOraclePrices, apiVaults, debug, + useOmniKitLinks, }) => { const positionAutomations = allPositionsAutomations .filter(filterAutomation(dpm)) @@ -50,6 +51,7 @@ const getAaveLikeBorrowPosition: GetAaveLikePositionHandlerType = async ({ apiVaults, allOraclePrices, debug, + useOmniKitLinks, }) const [primaryTokenReserveData, secondaryTokenReserveData, onChainPositionData] = await Promise.all([ @@ -124,6 +126,7 @@ const getAaveLikeMultiplyPosition: GetAaveLikePositionHandlerType = async ({ allOraclePrices, apiVaults, debug, + useOmniKitLinks, }) => { const positionAutomations = allPositionsAutomations .filter(filterAutomation(dpm)) @@ -135,6 +138,7 @@ const getAaveLikeMultiplyPosition: GetAaveLikePositionHandlerType = async ({ apiVaults, allOraclePrices, debug, + useOmniKitLinks, }) const [ primaryTokenReserveConfiguration, @@ -247,12 +251,14 @@ const getAaveLikeEarnPosition: GetAaveLikePositionHandlerType = async ({ allPositionsHistory, allOraclePrices, debug, + useOmniKitLinks, }) => { const { commonData, primaryTokenPrice, secondaryTokenPrice, ...commonRest } = commonDataMapper({ dpm, prices, allOraclePrices, debug, + useOmniKitLinks, }) const [onChainPositionData, primaryTokenReserveData, secondaryTokenReserveData] = await Promise.all([ @@ -351,6 +357,7 @@ export const aaveLikePositionsHandler: PortfolioPositionsHandler = async ({ apiVaults, positionsCount, debug, + useOmniKitLinks, }) => { const aaveLikeDpmList = dpmList.filter(({ protocol }) => [aaveLikeProtocolNames.aavev3, aaveLikeProtocolNames.sparkv3].includes(protocol), @@ -420,6 +427,7 @@ export const aaveLikePositionsHandler: PortfolioPositionsHandler = async ({ allOraclePrices, apiVaults, debug, + useOmniKitLinks, } switch (dpm.positionType.toLowerCase()) { case OmniProductType.Multiply: diff --git a/handlers/portfolio/positions/handlers/aave-like/types.ts b/handlers/portfolio/positions/handlers/aave-like/types.ts index f47db86eca..dcb03dbfc6 100644 --- a/handlers/portfolio/positions/handlers/aave-like/types.ts +++ b/handlers/portfolio/positions/handlers/aave-like/types.ts @@ -25,6 +25,7 @@ export type GetAaveLikePositionHandlerType = ({ allOraclePrices, apiVaults, debug, + useOmniKitLinks, }: { dpm: DpmSubgraphData prices: TokensPricesList @@ -33,4 +34,5 @@ export type GetAaveLikePositionHandlerType = ({ allOraclePrices: AaveLikeOraclePriceData apiVaults?: Vault[] debug?: boolean + useOmniKitLinks?: boolean }) => Promise diff --git a/handlers/portfolio/positions/index.ts b/handlers/portfolio/positions/index.ts index 9e86e59bd1..b69211da10 100644 --- a/handlers/portfolio/positions/index.ts +++ b/handlers/portfolio/positions/index.ts @@ -28,6 +28,7 @@ export const portfolioPositionsHandler = async ({ }: NextApiRequest): Promise => { const address = (query.address as string).toLowerCase() const debug = 'debug' in query + const useOmniKitLinks = 'useOmniKitLinks' in query const positionsCount = 'positionsCount' in query if (portfolioCache.has(address)) { if (positionsCount) { @@ -55,6 +56,7 @@ export const portfolioPositionsHandler = async ({ prices: prices.data.tokens, positionsCount, debug, + useOmniKitLinks, } const positionsReply = await Promise.all([ diff --git a/handlers/portfolio/types.ts b/handlers/portfolio/types.ts index ca1e454117..8f5d72225e 100644 --- a/handlers/portfolio/types.ts +++ b/handlers/portfolio/types.ts @@ -66,6 +66,7 @@ export type PortfolioPositionsHandler = ({ prices, positionsCount, debug, + useOmniKitLinks, }: { address: string apiVaults?: Vault[] @@ -74,6 +75,7 @@ export type PortfolioPositionsHandler = ({ positionsCount?: boolean allPositionsHistory?: HistoryResponse debug?: boolean + useOmniKitLinks?: boolean }) => Promise export type DetailsTypeCommon = diff --git a/helpers/clients/portfolio-client.ts b/helpers/clients/portfolio-client.ts index 848abfb54f..9ad485405d 100644 --- a/helpers/clients/portfolio-client.ts +++ b/helpers/clients/portfolio-client.ts @@ -3,6 +3,7 @@ import type { PortfolioOverviewResponse, } from 'components/portfolio/types/domain-types' import type { PortfolioPositionsReply } from 'handlers/portfolio/types' +import { getLocalAppConfig } from 'helpers/config' import { useCallback, useMemo } from 'react' /** @@ -12,6 +13,7 @@ import { useCallback, useMemo } from 'react' * @returns getters for portfolio data */ export const usePortfolioClient = (baseUrl?: string, headers?: HeadersInit) => { + const { UseOmniKitLinks } = getLocalAppConfig('features') const fetchPortfolioGeneric = useCallback( async ( section: 'overview' | 'assets' | 'positions' | 'positionsCount', @@ -20,7 +22,9 @@ export const usePortfolioClient = (baseUrl?: string, headers?: HeadersInit) => { let callUrl switch (section) { case 'positions': - callUrl = `/api/positions/${address}` + callUrl = UseOmniKitLinks + ? `/api/positions/${address}?useOmniKitLinks` + : `/api/positions/${address}` break case 'overview': case 'assets': @@ -36,7 +40,7 @@ export const usePortfolioClient = (baseUrl?: string, headers?: HeadersInit) => { .catch((err) => console.error(err)) return response }, - [baseUrl, headers], + [baseUrl, headers, UseOmniKitLinks], ) return useMemo(