Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions app/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,21 @@ settings.get("/link-status", async (c) => {
}) as bigint;

if (balance > 0n) {
const tokenId = await publicClient.readContract({
address: ERC_8004,
abi: [{ type: "function", name: "tokenOfOwnerByIndex", stateMutability: "view", inputs: [{ name: "owner", type: "address" }, { name: "index", type: "uint256" }], outputs: [{ name: "", type: "uint256" }] }] as const,
functionName: "tokenOfOwnerByIndex",
args: [address as `0x${string}`, 0n],
}) as bigint;

return c.json({ linked: true, agentId: Number(tokenId), owsWallet: address });
// Try to get token ID (ERC-721 Enumerable — may not be supported)
let agentId: number | undefined;
try {
const tokenId = await publicClient.readContract({
address: ERC_8004,
abi: [{ type: "function", name: "tokenOfOwnerByIndex", stateMutability: "view", inputs: [{ name: "owner", type: "address" }, { name: "index", type: "uint256" }], outputs: [{ name: "", type: "uint256" }] }] as const,
functionName: "tokenOfOwnerByIndex",
args: [address as `0x${string}`, 0n],
}) as bigint;
agentId = Number(tokenId);
} catch { /* ERC-721 Enumerable not supported — agent ID unknown */ }

return c.json({ linked: true, agentId, owsWallet: address });
}
} catch { /* best effort */ }
} catch { /* balanceOf failed */ }

return c.json({ linked: false, owsWallet: address });
} catch (err: unknown) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plotlink-ows",
"version": "1.0.15",
"version": "1.0.16",
"bin": {
"plotlink-ows": "./bin/plotlink-ows.js"
},
Expand Down
Loading