Skip to content

Commit a468024

Browse files
committed
fix onchain endpoints with new indexer
1 parent 6bbae30 commit a468024

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

pages/api/[network]/get-name-by-token-id.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ async function handler(req, res) {
1616
return res.status(400).json({ message: "Missing required parameters" });
1717
}
1818
const subDomainName = await sql`
19-
SELECT name, address, "textRecords" FROM ponder_prod."NftSubdomain" WHERE "domainName" = ${domain} AND "tokenId" = ${tokenId}
19+
SELECT
20+
name,
21+
address,
22+
text_records as textRecords
23+
FROM
24+
ponder_prod."NftSubdomain"
25+
WHERE
26+
domain_name = ${domain} AND token_id = ${tokenId}
2027
`;
2128

2229
if (subDomainName.length === 0) {

pages/api/[network]/get-onchain-names.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,66 @@ const cors = Cors({
77
});
88

99
async function handler(req, res) {
10-
// Check required parameters
1110
const domain = req.query.domain;
12-
const addresses = req.query.addresses?.split(","); // Assuming addresses are comma-separated
11+
const addresses = req.query.addresses
12+
?.split(",")
13+
.map((address) => address.toLowerCase()); // comma-separated
1314
const name = req.query.name;
1415

1516
if (!domain) {
1617
return res.status(400).json({ message: "Missing required parameters" });
1718
}
1819

1920
let subDomainNames;
21+
2022
if (name) {
2123
subDomainNames = await sql`
22-
SELECT name, address, owner, "tokenId", "textRecords" as "textRecordsPayload", "coinTypes" as "coinTypesPayload", "registeredAt", contenthash FROM ponder_prod."NftSubdomain" WHERE "domainName" = ${domain} AND "name" = ${name} order by "registeredAt" desc
24+
SELECT
25+
name,
26+
address,
27+
owner,
28+
"token_id" AS "tokenId",
29+
"text_records" AS "textRecordsPayload",
30+
"coin_types" AS "coinTypesPayload",
31+
"registered_at" AS "registeredAt",
32+
contenthash
33+
FROM ponder_prod."NftSubdomain"
34+
WHERE domain_name = ${domain}
35+
AND "name" = ${name}
36+
ORDER BY "registered_at" DESC
2337
`;
2438
} else {
2539
if (addresses && addresses.length > 0) {
2640
subDomainNames = await sql`
27-
SELECT name, address, owner, "tokenId", "textRecords" as "textRecordsPayload", "coinTypes" as "coinTypesPayload", "registeredAt", contenthash FROM ponder_prod."NftSubdomain" WHERE "domainName" = ${domain} AND "address" = ANY (${addresses}) order by "registeredAt" desc
28-
`;
41+
SELECT
42+
name,
43+
address,
44+
owner,
45+
"token_id" AS "tokenId",
46+
"text_records" AS "textRecordsPayload",
47+
"coin_types" AS "coinTypesPayload",
48+
"registered_at" AS "registeredAt",
49+
contenthash
50+
FROM ponder_prod."NftSubdomain"
51+
WHERE domain_name = ${domain}
52+
AND "address" = ANY (${addresses})
53+
ORDER BY "registered_at" DESC
54+
`;
2955
} else {
3056
subDomainNames = await sql`
31-
SELECT name, address, owner, "tokenId", "textRecords" as "textRecordsPayload", "coinTypes" as "coinTypesPayload", "registeredAt", contenthash FROM ponder_prod."NftSubdomain" WHERE "domainName" = ${domain} order by "registeredAt" desc
32-
`;
57+
SELECT
58+
name,
59+
address,
60+
owner,
61+
"token_id" AS "tokenId",
62+
"text_records" AS "textRecordsPayload",
63+
"coin_types" AS "coinTypesPayload",
64+
"registered_at" AS "registeredAt",
65+
contenthash
66+
FROM ponder_prod."NftSubdomain"
67+
WHERE domain_name = ${domain}
68+
ORDER BY "registered_at" DESC
69+
`;
3370
}
3471
}
3572

@@ -50,6 +87,7 @@ async function handler(req, res) {
5087
} of subDomainNames) {
5188
const text_records = JSON.parse(textRecordsPayload);
5289
const coin_types = JSON.parse(coinTypesPayload);
90+
5391
result.push({
5492
name,
5593
address,

0 commit comments

Comments
 (0)