Skip to content

Commit c3e159f

Browse files
committed
fix: return fts without sip16 metadata in search results
1 parent 6340895 commit c3e159f

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

src/pg/pg-store.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,18 @@ export class PgStore extends BasePgStore {
396396
m.cached_image,
397397
COUNT(*) OVER() as total
398398
FROM tokens AS t
399-
INNER JOIN metadata AS m ON t.id = m.token_id
399+
LEFT JOIN metadata AS m ON t.id = m.token_id
400400
INNER JOIN smart_contracts AS s ON t.smart_contract_id = s.id
401401
WHERE t.type = 'ft'
402402
${
403403
args.filters?.name
404-
? sql`AND LOWER(t.name) LIKE LOWER(${'%' + args.filters.name + '%'})`
404+
? sql`AND LOWER(t.name) LIKE '%' || LOWER(${args.filters.name}) || '%'`
405405
: sql``
406406
}
407407
${args.filters?.symbol ? sql`AND LOWER(t.symbol) = LOWER(${args.filters.symbol})` : sql``}
408-
${args.filters?.address ? sql`AND s.principal LIKE ${args.filters.address + '%'}` : sql``}
408+
${
409+
args.filters?.address ? sql`AND s.principal LIKE ${args.filters.address} || '%'` : sql``
410+
}
409411
ORDER BY ${orderBy} ${order}
410412
LIMIT ${args.page.limit}
411413
OFFSET ${args.page.offset}

tests/api/ft.test.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe('FT routes', () => {
283283
});
284284

285285
describe('index', () => {
286-
const insertFt = async (item: DbFungibleTokenMetadataItem) => {
286+
const insertFt = async (item: DbFungibleTokenMetadataItem, skipMetadata: boolean = false) => {
287287
const [tokenJob] = await insertAndEnqueueTestContractWithTokens(
288288
db,
289289
item.principal,
@@ -301,22 +301,24 @@ describe('FT routes', () => {
301301
total_supply: item.total_supply?.toString(),
302302
uri: item.uri ?? null,
303303
},
304-
metadataLocales: [
305-
{
306-
metadata: {
307-
sip: 16,
308-
token_id: tokenJob.token_id ?? 0,
309-
name: item.name ?? '',
310-
l10n_locale: 'en',
311-
l10n_uri: null,
312-
l10n_default: true,
313-
description: item.description ?? '',
314-
image: item.image ?? '',
315-
cached_image: item.cached_image ?? '',
316-
cached_thumbnail_image: item.cached_thumbnail_image ?? '',
317-
},
318-
},
319-
],
304+
metadataLocales: skipMetadata
305+
? []
306+
: [
307+
{
308+
metadata: {
309+
sip: 16,
310+
token_id: tokenJob.token_id ?? 0,
311+
name: item.name ?? '',
312+
l10n_locale: 'en',
313+
l10n_uri: null,
314+
l10n_default: true,
315+
description: item.description ?? '',
316+
image: item.image ?? '',
317+
cached_image: item.cached_image ?? '',
318+
cached_thumbnail_image: item.cached_thumbnail_image ?? '',
319+
},
320+
},
321+
],
320322
},
321323
});
322324
};
@@ -437,6 +439,24 @@ describe('FT routes', () => {
437439
const json3 = response3.json();
438440
expect(json3.total).toBe(1);
439441
expect(json3.results[0].symbol).toBe('MIA');
442+
443+
// Test a token without SIP-16 metadata
444+
await insertFt({
445+
name: 'Scam token',
446+
symbol: 'rstSTX',
447+
decimals: 5,
448+
tx_id: '0xbdc41843d5e0cd4a70611f6badeb5c87b07b12309e77c4fbaf2334c7b4cee89b',
449+
principal: 'SP22PCWZ9EJMHV4PHVS0C8H3B3E4Q079ZHY6CXDS1.meme-token',
450+
total_supply: '200000',
451+
});
452+
const response4 = await fastify.inject({
453+
method: 'GET',
454+
url: '/metadata/ft?name=scam',
455+
});
456+
expect(response4.statusCode).toBe(200);
457+
const json4 = response4.json();
458+
expect(json4.total).toBe(1);
459+
expect(json4.results[0].symbol).toBe('rstSTX');
440460
});
441461

442462
test('filters by symbol', async () => {

0 commit comments

Comments
 (0)