diff --git a/apps/explorer/src/lib/domain/token-display.ts b/apps/explorer/src/lib/domain/token-display.ts new file mode 100644 index 000000000..66b428f90 --- /dev/null +++ b/apps/explorer/src/lib/domain/token-display.ts @@ -0,0 +1,13 @@ +import { tempo } from 'viem/chains' + +const OUSD_ADDRESS = '0x20c0000000000000000000006a37da5c996874be' + +export function getTokenDisplayName( + chainId: number, + address: string, + name: string, +): string { + if (chainId === tempo.id && address.toLowerCase() === OUSD_ADDRESS) + return 'Open USD' + return name +} diff --git a/apps/explorer/src/lib/server/tokens.ts b/apps/explorer/src/lib/server/tokens.ts index 0181e06a1..5db3d1ef8 100644 --- a/apps/explorer/src/lib/server/tokens.ts +++ b/apps/explorer/src/lib/server/tokens.ts @@ -4,6 +4,7 @@ import type { Address } from 'ox' import { getChainId } from 'wagmi/actions' import * as z from 'zod/mini' import { getAccountTag } from '#lib/account' +import { getTokenDisplayName } from '#lib/domain/token-display' import { api } from '#lib/server/tempo-api' import { parseTimestamp } from '#lib/timestamp' import { getWagmiConfig } from '#wagmi.config.ts' @@ -104,7 +105,7 @@ export const fetchTokens = createServerFn({ method: 'POST' }) return { address, symbol: token.symbol, - name: token.name, + name: getTokenDisplayName(chainId, address, token.name), currency: token.currency, logoURI: token.logoUri, createdAt: diff --git a/apps/explorer/test/token-display.node.test.ts b/apps/explorer/test/token-display.node.test.ts new file mode 100644 index 000000000..65ca5a9ff --- /dev/null +++ b/apps/explorer/test/token-display.node.test.ts @@ -0,0 +1,35 @@ +import { tempo, tempoModerato } from 'viem/chains' +import { describe, expect, it } from 'vitest' +import { getTokenDisplayName } from '#lib/domain/token-display' + +const OUSD_ADDRESS = '0x20c0000000000000000000006a37da5c996874be' + +describe('getTokenDisplayName', () => { + it('displays the branded OUSD name on mainnet', () => { + expect(getTokenDisplayName(tempo.id, OUSD_ADDRESS, 'OpenUSD')).toBe( + 'Open USD', + ) + }) + + it('matches the token address case-insensitively', () => { + expect( + getTokenDisplayName(tempo.id, OUSD_ADDRESS.toUpperCase(), 'OpenUSD'), + ).toBe('Open USD') + }) + + it('leaves the same address on other chains unchanged', () => { + expect(getTokenDisplayName(tempoModerato.id, OUSD_ADDRESS, 'OpenUSD')).toBe( + 'OpenUSD', + ) + }) + + it('leaves other tokens unchanged even if their names match', () => { + expect( + getTokenDisplayName( + tempo.id, + '0x20c0000000000000000000000000000000000000', + 'OpenUSD', + ), + ).toBe('OpenUSD') + }) +})