Skip to content

Commit f8dba2a

Browse files
authored
Merge pull request #71 from kleros/fix/tokens-not-showing-and-other-improvements
fix: fix tokens, fix hex to base10, improve return formats and wordin…
2 parents 6fd208f + 793dbee commit f8dba2a

File tree

7 files changed

+50
-24
lines changed

7 files changed

+50
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/scout",
3-
"version": "1.3.8",
3+
"version": "1.3.9",
44
"description": "",
55
"homepage": "https://contract-insight-snap.kleros.builders/",
66
"bugs": {

packages/site/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/scout-site",
3-
"version": "1.3.8",
3+
"version": "1.3.9",
44
"private": true,
55
"license": "(MIT-0 OR Apache-2.0)",
66
"scripts": {

packages/site/src/pages/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,20 @@ const Index = () => {
121121

122122
useEffect(() => {
123123
const filterPackages = async () => {
124-
const results = await axios.get(
125-
`https://registry.npmjs.org/-/v1/search?text=${search}`,
126-
);
127-
setFilteredPackages(
128-
results.data.objects.map((obj: { package: any }) => obj.package),
129-
);
124+
try {
125+
const results = await axios.get(
126+
`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(search)}`,
127+
);
128+
setFilteredPackages(
129+
results.data.objects.map((obj: { package: any }) => obj.package),
130+
);
131+
} catch (error) {
132+
console.error('Search API error:', error);
133+
setFilteredPackages([]);
134+
}
130135
};
131136

132-
if (search) {
137+
if (search && search.length > 2) {
133138
filterPackages();
134139
} else {
135140
setFilteredPackages([]);
@@ -143,7 +148,7 @@ const Index = () => {
143148
};
144149

145150
const handleConnectClick = async () => {
146-
const defaultSnapOrigin = `npm:{selectedPackage}`;
151+
const defaultSnapOrigin = `npm:${selectedPackage}`;
147152

148153
try {
149154
await connectSnap(defaultSnapOrigin);

packages/snap/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ This Snap pulls contract metadata from Kleros's decentralized token curated regi
1818
- The data used in this Snap is pulled from the following decentralized registries on Kleros Curate:
1919
- [Contract-Domain Name Registry](https://curate.kleros.io/tcr/100/0x957a53a994860be4750810131d9c876b2f52d6e1)
2020
- [Address Tags Registry](https://curate.kleros.io/tcr/100/0x66260c69d03837016d88c9877e61e08ef74c59f2)
21-
- [Tokens Registry](https://curate.kleros.io/tcr/100/0x70533554fe5c17caf77fe530f77eab933b92af60)
21+
- [Tokens Registry](https://curate.kleros.io/tcr/100/0xee1502e29795ef6c2d60f8d7120596abe3bad990)

packages/snap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/scout-snap",
3-
"version": "1.3.8",
3+
"version": "1.3.9",
44
"description": "A Metamask Snap that retrieves contract metadata from the Kleros Curate registries",
55
"repository": {
66
"type": "git",

packages/snap/snap.manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"version": "1.3.8",
2+
"version": "1.3.9",
33
"description": "A Snap that retrieves contract metadata from the Kleros Curate registries.",
44
"proposedName": "Kleros Scout",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/kleros/scout-snap.git"
88
},
99
"source": {
10-
"shasum": "j/r2uYX9VjmbmsLWgKQ0TNeuemmmfK4M+E8S8jcPSjo=",
10+
"shasum": "ayOxQ97u42HLTny+ivrIjLTsq/hQnctZYM2lO5jG6o8=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/index.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Token = {
3232
caipAddress: string;
3333
name: string;
3434
symbol: string;
35+
website?: string;
3536
};
3637

3738
type CuratedInfo = {
@@ -42,7 +43,10 @@ type CuratedInfo = {
4243

4344
const parseMetadata = (metadata: any, keys: string[]) => {
4445
return keys.reduce((acc, key, index) => {
45-
acc[key] = mdEscape(metadata[`key${index}`]);
46+
const value = metadata[`key${index}`];
47+
if (value !== undefined && value !== null && value !== '') {
48+
acc[key] = mdEscape(value);
49+
}
4650
return acc;
4751
}, {} as any);
4852
};
@@ -99,7 +103,7 @@ const fetchGraphQLData = async (variables: {
99103
}
100104
}
101105
tokens: litems(where:{
102-
registry:"0x70533554fe5c17caf77fe530f77eab933b92af60",
106+
registry:"0xee1502e29795ef6c2d60f8d7120596abe3bad990",
103107
metadata_: {
104108
key0_starts_with_nocase: $targetAddress,
105109
key0_ends_with_nocase: $targetAddress,
@@ -110,6 +114,7 @@ const fetchGraphQLData = async (variables: {
110114
key0
111115
key1
112116
key2
117+
key3
113118
}
114119
}
115120
}
@@ -146,10 +151,14 @@ const fetchGraphQLData = async (variables: {
146151
: undefined;
147152

148153
const parsedToken = result.data.tokens[0]
149-
? parseMetadata(result.data.tokens[0].metadata, ['caipAddress', 'name', 'symbol'])
154+
? parseMetadata(result.data.tokens[0].metadata, ['caipAddress', 'name', 'symbol', 'website'])
150155
: undefined;
151156

152-
return { addressTag: parsedAddressTag, contractDomain: parsedContractDomain, token: parsedToken };
157+
return {
158+
addressTag: parsedAddressTag,
159+
contractDomain: parsedContractDomain,
160+
token: parsedToken,
161+
};
153162
} catch (error) {
154163
console.error('GraphQL fetch error:', error);
155164
return null;
@@ -181,6 +190,7 @@ const getInsights = async (
181190
const insights: string[] = [];
182191

183192
if (result.addressTag) {
193+
insights.push(`✅ **Verified contract**`);
184194
// key2 is projectName, which is optional. No project name === "", which is falsy.
185195
const projectNameLabel = result.addressTag.projectName
186196
? result.addressTag.infoLink
@@ -191,15 +201,20 @@ const getInsights = async (
191201
// Contract tag is a mandatory field.
192202
const contractTag = result.addressTag.publicName;
193203
insights.push(`**Project:** ${projectNameLabel}`);
194-
insights.push(`**Contract Tag:** ${contractTag}`);
204+
insights.push(`**Tag:** ${contractTag}`);
195205
}
196206

197207
if (result.contractDomain) {
208+
insights.push(`✅ **Verified domain**`);
198209
insights.push(`**Domain:** _${domain}_ is **verified** for this contract`);
199210
}
200211

201212
if (result.token) {
202-
insights.push(`**Token:** ${result.token.name} (${result.token.symbol})`);
213+
insights.push(`✅ **Verified token**`);
214+
const tokenName = result.token.website
215+
? `[${result.token.name}](${result.token.website})`
216+
: result.token.name;
217+
insights.push(`**Token:** ${tokenName} (${result.token.symbol})`);
203218
}
204219

205220
return insights;
@@ -265,7 +280,7 @@ export const onTransaction: OnTransactionHandler = async ({
265280
console.error('Invalid transaction origin:', error);
266281
}
267282
}
268-
const numericChainId = parseInt(chainId.split(':')[1], 16);
283+
const numericChainId = parseInt(chainId.split(':')[1], 10);
269284
const caipAddress = `eip155:${numericChainId}:${transaction.to as string}`;
270285

271286
const result = await getInsights(caipAddress, domain);
@@ -281,18 +296,24 @@ export const onTransaction: OnTransactionHandler = async ({
281296
'mempool.space', 'explorer.solana.com', 'basescan.org', 'arbiscan.io',
282297
'moonscan.io', 'lineascan.build', 'optimistic.etherscan.io', 'ftmscan.com',
283298
'moonriver.moonscan.io', 'snowscan.xyz', 'cronoscan.com', 'bttcscan.com',
284-
'zkevm.polygonscan.com', 'wemixscan.com', 'scrollscan.com', 'era.zksync.network', 'celoscan.io'
299+
'zkevm.polygonscan.com', 'wemixscan.com', 'scrollscan.com', 'era.zksync.network',
300+
'celoscan.io', 'avascan.info', 'blastscan.io', 'mantlescan.xyz', 'sepolia.etherscan.io',
301+
'goerli.etherscan.io', 'holesky.etherscan.io', 'testnet.bscscan.com', 'testnet.ftmscan.com',
302+
'mumbai.polygonscan.com', 'goerli.arbiscan.io', 'sepolia.arbiscan.io', 'testnet.snowtrace.io',
303+
'explorer.testnet.mantle.xyz', 'sepolia.basescan.org', 'goerli.basescan.org', 'alfajores.celoscan.io',
304+
'blockscout.com', 'explorer.zksync.io', 'layerzeroscan.com', 'routescan.io',
305+
'moonbeam.moonscan.io', 'subscan.io', 'solscan.io', 'explorer.near.org',
306+
'cardanoscan.io', 'astar.subscan.io', 'polkadot.subscan.io', 'kusama.subscan.io'
285307
];
286308

287309
if (!excludedDomains.includes(domain) && !insights.some(insight => insight.includes('Domain'))) {
288310
const cdnPathURL = `https://app.klerosscout.eth.limo/#/?registry=CDN&network=1&network=100&network=137&network=56&network=42161&network=10&network=43114&network=534352&network=42220&network=8453&network=250&network=324&status=Registered&status=RegistrationRequested&status=ClearingRequested&status=Absent&disputed=true&disputed=false&page=1&orderDirection=desc&&additem=CDN&caip10Address=${caipAddress}&domain=${domain}`;
289311

290-
insights.push(`Is this contract linked to this domain? If so, submit the info at [Scout App](${cdnPathURL}) to verify it for all users!`);
312+
insights.push(`Is this contract officially linked to **${domain}**? If so, submit the info at [Scout App](${cdnPathURL}) to verify it for all users!`);
291313
}
292314

293315
return {
294316
content: panel([
295-
heading('Contract insights'),
296317
...insights.map((insight) => text(insight)),
297318
]),
298319
};

0 commit comments

Comments
 (0)