plotlink-ows 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/routes/settings.ts +27 -1
- package/package.json +1 -1
package/app/routes/settings.ts
CHANGED
|
@@ -182,7 +182,33 @@ settings.get("/link-status", async (c) => {
|
|
|
182
182
|
} catch { /* best effort */ }
|
|
183
183
|
return c.json({ linked: true, agentId: Number(agentId), owsWallet: address, owner });
|
|
184
184
|
}
|
|
185
|
-
} catch { /*
|
|
185
|
+
} catch { /* agentIdByWallet may revert if not bound */ }
|
|
186
|
+
|
|
187
|
+
// Fallback: check if wallet owns an agent NFT (register() creates NFT but doesn't bind via setAgentWallet)
|
|
188
|
+
try {
|
|
189
|
+
const balance = await publicClient.readContract({
|
|
190
|
+
address: ERC_8004,
|
|
191
|
+
abi: [{ type: "function", name: "balanceOf", stateMutability: "view", inputs: [{ name: "owner", type: "address" }], outputs: [{ name: "", type: "uint256" }] }] as const,
|
|
192
|
+
functionName: "balanceOf",
|
|
193
|
+
args: [address as `0x${string}`],
|
|
194
|
+
}) as bigint;
|
|
195
|
+
|
|
196
|
+
if (balance > 0n) {
|
|
197
|
+
// Try to get token ID (ERC-721 Enumerable — may not be supported)
|
|
198
|
+
let agentId: number | undefined;
|
|
199
|
+
try {
|
|
200
|
+
const tokenId = await publicClient.readContract({
|
|
201
|
+
address: ERC_8004,
|
|
202
|
+
abi: [{ type: "function", name: "tokenOfOwnerByIndex", stateMutability: "view", inputs: [{ name: "owner", type: "address" }, { name: "index", type: "uint256" }], outputs: [{ name: "", type: "uint256" }] }] as const,
|
|
203
|
+
functionName: "tokenOfOwnerByIndex",
|
|
204
|
+
args: [address as `0x${string}`, 0n],
|
|
205
|
+
}) as bigint;
|
|
206
|
+
agentId = Number(tokenId);
|
|
207
|
+
} catch { /* ERC-721 Enumerable not supported — agent ID unknown */ }
|
|
208
|
+
|
|
209
|
+
return c.json({ linked: true, agentId, owsWallet: address });
|
|
210
|
+
}
|
|
211
|
+
} catch { /* balanceOf failed */ }
|
|
186
212
|
|
|
187
213
|
return c.json({ linked: false, owsWallet: address });
|
|
188
214
|
} catch (err: unknown) {
|