diff --git a/src/api/init.ts b/src/api/init.ts index a6dd7e48..f008d859 100644 --- a/src/api/init.ts +++ b/src/api/init.ts @@ -8,8 +8,7 @@ import FastifyCors from '@fastify/cors'; import { StatusRoutes } from './routes/status'; import FastifyMetrics, { IFastifyMetrics } from 'fastify-metrics'; import { Server } from 'http'; -import { isProdEnv } from './util/helpers'; -import { PINO_LOGGER_CONFIG } from '@hirosystems/api-toolkit'; +import { isProdEnv, PINO_LOGGER_CONFIG } from '@hirosystems/api-toolkit'; export const Api: FastifyPluginAsync, Server, TypeBoxTypeProvider> = async ( fastify, diff --git a/src/api/routes/ft.ts b/src/api/routes/ft.ts index 2c54e089..c436e907 100644 --- a/src/api/routes/ft.ts +++ b/src/api/routes/ft.ts @@ -19,6 +19,7 @@ import { import { handleChainTipCache, handleTokenCache } from '../util/cache'; import { generateTokenErrorResponse, TokenErrorResponseSchema } from '../util/errors'; import { parseMetadataLocaleBundle } from '../util/helpers'; +import BigNumber from 'bignumber.js'; const IndexRoutes: FastifyPluginCallback, Server, TypeBoxTypeProvider> = ( fastify, @@ -121,11 +122,16 @@ const ShowRoutes: FastifyPluginCallback, Server, TypeBoxTyp locale: request.query.locale, }); const contract = metadataBundle?.smartContract; + const decimals = metadataBundle?.token?.decimals ?? undefined; + const total_supply = metadataBundle?.token?.total_supply ?? undefined; await reply.send({ name: metadataBundle?.token?.name ?? undefined, symbol: metadataBundle?.token?.symbol ?? undefined, - decimals: metadataBundle?.token?.decimals ?? undefined, - total_supply: metadataBundle?.token?.total_supply ?? undefined, + decimals, + total_supply: + decimals != undefined && total_supply != undefined + ? BigNumber(total_supply).shiftedBy(-decimals).toString() + : undefined, token_uri: metadataBundle?.token?.uri ?? undefined, description: metadataBundle?.metadataLocale?.metadata?.description ?? undefined, tx_id: contract.tx_id, diff --git a/src/api/util/helpers.ts b/src/api/util/helpers.ts index a6d3cf9f..ebfd99d0 100644 --- a/src/api/util/helpers.ts +++ b/src/api/util/helpers.ts @@ -1,14 +1,6 @@ import { DbMetadataLocaleBundle } from '../../pg/types'; import { MetadataPropertiesType, MetadataType, MetadataValueType } from '../schemas'; -export const isDevEnv = process.env.NODE_ENV === 'development'; -export const isTestEnv = process.env.NODE_ENV === 'test'; -export const isProdEnv = - process.env.NODE_ENV === 'production' || - process.env.NODE_ENV === 'prod' || - !process.env.NODE_ENV || - (!isTestEnv && !isDevEnv); - export function parseMetadataLocaleBundle( locale?: DbMetadataLocaleBundle ): MetadataType | undefined { diff --git a/src/index.ts b/src/index.ts index 66d36b99..4f22b6c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,12 @@ import { buildApiServer, buildPromServer } from './api/init'; import { TokenProcessorMetrics } from './token-processor/token-processor-metrics'; import { ENV } from './env'; import { buildAdminRpcServer } from './admin-rpc/init'; -import { isProdEnv } from './api/util/helpers'; -import { buildProfilerServer, logger, registerShutdownConfig } from '@hirosystems/api-toolkit'; +import { + buildProfilerServer, + isProdEnv, + logger, + registerShutdownConfig, +} from '@hirosystems/api-toolkit'; import { closeChainhookServer, startChainhookServer } from './chainhook/server'; /** diff --git a/tests/api/ft.test.ts b/tests/api/ft.test.ts index 04edcef7..dafe8d6f 100644 --- a/tests/api/ft.test.ts +++ b/tests/api/ft.test.ts @@ -167,7 +167,7 @@ describe('FT routes', () => { name: 'hello-world', symbol: 'HELLO', token_uri: 'http://test.com/uri.json', - total_supply: '1', + total_supply: '0.000001', sender_address: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS', asset_identifier: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS.hello-world::ft-token', tx_id: '0x123456', @@ -240,7 +240,7 @@ describe('FT routes', () => { name: 'hello-world', symbol: 'HELLO', token_uri: 'http://test.com/uri.json', - total_supply: '1', + total_supply: '0.000001', decimals: 6, sender_address: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS', asset_identifier: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS.hello-world::ft-token',