Skip to content

Commit

Permalink
Enable third party defi positions & fix token list exclusion logic (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbbb authored and ibrahimtaveras00 committed Dec 6, 2024
1 parent 03bfb03 commit dd49d9c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/resources/defi/PositionsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getPositions = async (address: string, currency: NativeCurrencyKey): Promi
method: 'get',
params: {
currency,
enableThirdParty: 'false',
enableThirdParty: 'true',
},
headers: {
Authorization: `Bearer ${ADDYS_API_KEY}`,
Expand Down
17 changes: 7 additions & 10 deletions src/resources/defi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,15 @@ export function parsePositions(data: AddysPositionsResponse, currency: NativeCur

const positions = Object.values(versionAgnosticPositions);

const positionTokens: string[] = [];
// these are tokens that would be represented twice if shown in the token list, such as a Sushiswap LP token
const tokensToExcludeFromTokenList: string[] = [];

positions.forEach(({ deposits, stakes }) => {
positions.forEach(({ deposits }) => {
deposits.forEach(({ asset }) => {
const uniqueId = ethereumUtils.getUniqueId(asset.asset_code.toLowerCase(), chainsIdByName[asset.network]);
positionTokens.push(uniqueId);
});
stakes.forEach(({ underlying }) => {
underlying.forEach(({ asset }) => {
if (asset.defi_position) {
const uniqueId = ethereumUtils.getUniqueId(asset.asset_code.toLowerCase(), chainsIdByName[asset.network]);
positionTokens.push(uniqueId);
});
tokensToExcludeFromTokenList.push(uniqueId);
}
});
});

Expand All @@ -425,6 +422,6 @@ export function parsePositions(data: AddysPositionsResponse, currency: NativeCur
...positionsTotals,
},
positions,
positionTokens,
positionTokens: tokensToExcludeFromTokenList,
};
}
15 changes: 11 additions & 4 deletions src/screens/positions/LpPositionListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const LpPositionListItem: React.FC<Props> = ({ assets, totalAssetsValue,
const rangeStatus = getRangeStatus(assets, isConcentratedLiquidity);

const assetAllocations = assets.map(asset => {
// if both assets value are 0 value, return 1 for asset with non-zero quantity
if (totalAssetsValue === '0') {
return asset.quantity === '0' ? 0 : 1;
}
return parseFloat(divide(asset.native.amount, totalAssetsValue));
});

Expand Down Expand Up @@ -136,10 +140,13 @@ export const LpPositionListItem: React.FC<Props> = ({ assets, totalAssetsValue,
</Text>
</Box>
<LpRangeBadge
assets={assets.map((underlying, index) => ({
color: underlying.asset.colors?.primary ?? underlying.asset.colors?.fallback ?? colors.black,
allocationPercentage: assetAllocations[index],
}))}
assets={assets
.filter(asset => asset.quantity !== '0')
.map((underlying, index) => ({
id: underlying.asset.asset_code,
color: underlying.asset.colors?.primary ?? underlying.asset.colors?.fallback ?? colors.black,
allocationPercentage: assetAllocations[index],
}))}
/>
</Inline>
</Column>
Expand Down

0 comments on commit dd49d9c

Please sign in to comment.