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: 22 additions & 1 deletion app/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,28 @@ settings.get("/link-status", async (c) => {
} catch { /* best effort */ }
return c.json({ linked: true, agentId: Number(agentId), owsWallet: address, owner });
}
} catch { /* contract call may fail */ }
} catch { /* agentIdByWallet may revert if not bound */ }

// Fallback: check if wallet owns an agent NFT (register() creates NFT but doesn't bind via setAgentWallet)
try {
const balance = await publicClient.readContract({
address: ERC_8004,
abi: [{ type: "function", name: "balanceOf", stateMutability: "view", inputs: [{ name: "owner", type: "address" }], outputs: [{ name: "", type: "uint256" }] }] as const,
functionName: "balanceOf",
args: [address as `0x${string}`],
}) 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 });
}
} catch { /* best effort */ }

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.14",
"version": "1.0.15",
"bin": {
"plotlink-ows": "./bin/plotlink-ows.js"
},
Expand Down
Loading