diff --git a/src/endpoints/tokens/token.controller.ts b/src/endpoints/tokens/token.controller.ts index e3d1e1854..864a8576e 100644 --- a/src/endpoints/tokens/token.controller.ts +++ b/src/endpoints/tokens/token.controller.ts @@ -341,7 +341,7 @@ export class TokenController { } @Get("/tokens/:identifier/roles/:address") - @ApiOperation({ summary: 'Token address roles', description: 'Returns roles detalils for a specific address of a given token', deprecated: true }) + @ApiOperation({ summary: 'Token address roles', description: 'Returns roles details for a specific address of a given token', deprecated: true }) @ApiOkResponse({ type: TokenRoles }) @ApiNotFoundResponse({ description: 'Token not found' }) async getTokenRolesForAddress( @@ -435,7 +435,7 @@ export class TokenController { } @Get("/tokens/:identifier/transfers/count") - @ApiOperation({ summary: 'Account transfer count', description: 'Return total count of tranfers triggerred by a user account (type = Transaction), as well as transfers triggerred by smart contracts (type = SmartContractResult)' }) + @ApiOperation({ summary: 'Account transfer count', description: 'Return total count of transfers triggerred by a user account (type = Transaction), as well as transfers triggerred by smart contracts (type = SmartContractResult)' }) @ApiOkResponse({ type: Number }) @ApiQuery({ name: 'sender', description: 'Address of the transfer sender', required: false }) @ApiQuery({ name: 'receiver', description: 'Search by multiple receiver addresses, comma-separated', required: false }) diff --git a/src/endpoints/tokens/token.service.ts b/src/endpoints/tokens/token.service.ts index 0f7782fc8..3ceb5183a 100644 --- a/src/endpoints/tokens/token.service.ts +++ b/src/endpoints/tokens/token.service.ts @@ -48,6 +48,7 @@ import { NftSubType } from "../nfts/entities/nft.sub.type"; export class TokenService { private readonly logger = new OriginLogger(TokenService.name); private readonly nftSubTypes = [NftSubType.DynamicNonFungibleESDT, NftSubType.DynamicMetaESDT, NftSubType.NonFungibleESDTv2, NftSubType.DynamicSemiFungibleESDT]; + private readonly egldIdentifierInMultiTransfer = 'EGLD-000000'; constructor( private readonly esdtService: EsdtService, @@ -126,7 +127,9 @@ export class TokenService { this.applyTickerFromAssets(token); } - return tokens.map(item => ApiUtils.mergeObjects(new TokenDetailed(), item)); + return tokens + .map(item => ApiUtils.mergeObjects(new TokenDetailed(), item)) + .filter(t => t.identifier !== this.egldIdentifierInMultiTransfer); } applyTickerFromAssets(token: Token) { @@ -838,6 +841,20 @@ export class TokenService { token => token.transactions ?? 0, ); + const egldToken = new TokenDetailed({ + identifier: this.egldIdentifierInMultiTransfer, + name: 'EGLD', + type: TokenType.FungibleESDT, + assets: await this.assetsService.getTokenAssets(this.egldIdentifierInMultiTransfer), + decimals: 18, + isLowLiquidity: false, + price: await this.dataApiService.getEgldPrice(), + supply: '0', + circulatingSupply: '0', + marketCap: 0, + }); + tokens = [...tokens, egldToken]; + return tokens; } diff --git a/src/test/unit/services/tokens.spec.ts b/src/test/unit/services/tokens.spec.ts index 222e5ae15..f025eaddb 100644 --- a/src/test/unit/services/tokens.spec.ts +++ b/src/test/unit/services/tokens.spec.ts @@ -134,6 +134,7 @@ describe('Token Service', () => { provide: DataApiService, useValue: { getEsdtTokenPrice: jest.fn(), + getEgldPrice: jest.fn(), }, }, { @@ -690,6 +691,7 @@ describe('Token Service', () => { jest.spyOn(tokenService as any, 'applyMexPairTradesCount').mockImplementation(() => Promise.resolve()); jest.spyOn(cacheService as any, 'batchApplyAll').mockImplementation(() => Promise.resolve()); jest.spyOn(dataApiService, 'getEsdtTokenPrice').mockResolvedValue(100); + jest.spyOn(dataApiService, 'getEgldPrice').mockResolvedValue(100); jest.spyOn(tokenService as any, 'fetchTokenDataFromUrl').mockResolvedValue(100); jest.spyOn(esdtService, 'getTokenSupply').mockResolvedValue(mockTokenSupply as EsdtSupply); @@ -710,7 +712,7 @@ describe('Token Service', () => { expect(assetsService.getTokenAssets).toHaveBeenCalledWith(mockToken.identifier); mockToken.name = mockTokenAssets.name; }); - expect(assetsService.getTokenAssets).toHaveBeenCalledTimes(mockTokens.length); + expect(assetsService.getTokenAssets).toHaveBeenCalledTimes(mockTokens.length + 1); // add 1 for EGLD-000000 expect((collectionService as any).getNftCollections).toHaveBeenCalledWith(expect.anything(), { type: [TokenType.MetaESDT] }); @@ -763,6 +765,24 @@ describe('Token Service', () => { token => token.isLowLiquidity ? 0 : (token.marketCap ?? 0), token => token.transactions ?? 0, ); + + mockTokens.push(new TokenDetailed({ + identifier: 'EGLD-000000', + name: 'EGLD', + canPause: false, + canUpgrade: false, + canWipe: false, + price: 100, + decimals: 18, + isLowLiquidity: false, + marketCap: 0, + circulatingSupply: '0', + supply: '0', + assets: { + name: 'mockName', + } as TokenAssets, + })); + expect(result).toEqual(mockTokens); }); });