Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(app-tokens): Match on network and token ID as well (#1937)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich committed Dec 16, 2022
1 parent 85970b1 commit b7c97cb
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/position/template/app-token.template.position-fetcher.ts
@@ -1,6 +1,6 @@
import { Inject } from '@nestjs/common';
import { BigNumberish, Contract } from 'ethers/lib/ethers';
import _, { isEqual, uniqWith } from 'lodash';
import _, { isEqual, isNumber, uniqWith } from 'lodash';
import { compact, intersection, isArray, partition, sortBy, sum } from 'lodash';

import { drillBalance } from '~app-toolkit';
Expand Down Expand Up @@ -203,7 +203,22 @@ export abstract class AppTokenTemplatePositionFetcher<

const skeletonsWithResolvedTokens = await Promise.all(
skeletonsSubset.map(async ({ address, definition, underlyingTokenDefinitions }) => {
const maybeTokens = underlyingTokenDefinitions.map(v => allTokens.find(t => t.address === v.address));
const maybeTokens = underlyingTokenDefinitions.map(definition => {
const match = allTokens.find(token => {
const isAddressMatch = token.address === definition.address;
const isNetworkMatch = token.network === definition.network;
const isMaybeTokenIdMatch =
!isNumber(definition.tokenId) ||
(token.type === ContractType.APP_TOKEN && token.dataProps.tokenId === definition.tokenId) ||
(token.type === ContractType.NON_FUNGIBLE_TOKEN &&
Number(token.assets?.[0].tokenId) === definition.tokenId);

return isAddressMatch && isNetworkMatch && isMaybeTokenIdMatch;
});

return match;
});

const tokens = compact(maybeTokens);

if (maybeTokens.length !== tokens.length) return null;
Expand Down

0 comments on commit b7c97cb

Please sign in to comment.