Skip to content

Commit

Permalink
fix: 🐛 get portfolio transactions error
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan committed Jul 2, 2024
1 parent 4920a51 commit 7612431
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
8 changes: 0 additions & 8 deletions src/middleware/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,15 +1177,7 @@ function buildPortfolioMovementsQuery(args: string, filter: string): DocumentNod
nodes {
id
fromId
from {
identityId
number
}
toId
to {
identityId
number
}
assetId
amount
address
Expand Down
18 changes: 18 additions & 0 deletions src/utils/__tests__/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ import {
permissionGroupIdentifierToAgentGroup,
permissionsLikeToPermissions,
permissionsToMeshPermissions,
portfolioIdStringToPortfolio,
portfolioIdToMeshPortfolioId,
portfolioLikeToPortfolio,
portfolioLikeToPortfolioId,
Expand Down Expand Up @@ -10167,3 +10168,20 @@ describe('receiptDetailsToMeshReceiptDetails', () => {
expect(result).toEqual(fakeResult);
});
});

describe('portfolioIdStringToPortfolio', () => {
test('should convert a valid id string to MiddlewarePortfolio object', () => {
const id = '12345/678';
const expectedOutput = { identityId: '12345', number: 678 };

expect(portfolioIdStringToPortfolio(id)).toEqual(expectedOutput);
});

test('should return NaN for invalid number part', () => {
const id = '12345/abc';
const result = portfolioIdStringToPortfolio(id);

expect(result.identityId).toBe('12345');
expect(result.number).toBeNaN();
});
});
15 changes: 12 additions & 3 deletions src/utils/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4764,6 +4764,15 @@ export function toCustomClaimTypeWithIdentity(
}));
}

/**
* @hidden
*/
export function portfolioIdStringToPortfolio(id: string): MiddlewarePortfolio {
const [identityId, number] = id.split('/');

return { identityId, number: parseInt(number, 10) } as MiddlewarePortfolio;
}

/**
* @hidden
*/
Expand Down Expand Up @@ -4832,7 +4841,7 @@ export function toHistoricalSettlements(
});

portfolioMovementsResult.data.portfolioMovements.nodes.forEach(
({ createdBlock, from, to, fromId, toId, assetId, amount, address: accountAddress }) => {
({ createdBlock, fromId, toId, assetId, amount, address: accountAddress }) => {
const { blockId, hash } = createdBlock!;
data.push({
blockNumber: new BigNumber(blockId),
Expand All @@ -4844,8 +4853,8 @@ export function toHistoricalSettlements(
asset: new FungibleAsset({ ticker: assetId }, context),
amount: new BigNumber(amount).shiftedBy(-6),
direction: getDirection(fromId, toId),
from: middlewarePortfolioToPortfolio(from!, context),
to: middlewarePortfolioToPortfolio(to!, context),
from: middlewarePortfolioToPortfolio(portfolioIdStringToPortfolio(fromId), context),
to: middlewarePortfolioToPortfolio(portfolioIdStringToPortfolio(toId), context),
},
],
});
Expand Down

0 comments on commit 7612431

Please sign in to comment.