Skip to content

Commit b6d92b4

Browse files
authored
Name service: use protocol list instead of chain ID (#3283)
* Name service: use protocol list instead of chain ID Resolves #3281 * fix envs for demo
1 parent 0ea6396 commit b6d92b4

20 files changed

Lines changed: 125 additions & 50 deletions

File tree

configs/app/features/nameServices.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import type { Feature } from './types';
22

33
import apis from '../apis';
4-
import { getEnvValue } from '../utils';
4+
import { getEnvValue, parseEnvJson } from '../utils';
55

66
const title = 'Name services integration';
77

8-
const config: Feature<{ ens: { isEnabled: boolean }; clusters: { isEnabled: boolean; cdnUrl: string } }> = (() => {
8+
const config: Feature<{ ens: { isEnabled: boolean; protocols: Array<string> }; clusters: { isEnabled: boolean; cdnUrl: string } }> = (() => {
99
if (apis.bens || apis.clusters) {
1010
return Object.freeze({
1111
title,
1212
isEnabled: true,
1313
ens: {
1414
isEnabled: apis.bens ? true : false,
15+
protocols: parseEnvJson<Array<string>>(getEnvValue('NEXT_PUBLIC_NAME_SERVICE_PROTOCOLS')) || [ 'ens' ],
1516
},
1617
clusters: {
1718
isEnabled: apis.clusters ? true : false,

configs/envs/.env.gnosis

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ NEXT_PUBLIC_APP_PORT=3000
99
NEXT_PUBLIC_APP_ENV=development
1010
NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws
1111

12+
NEXT_PUBLIC_NAME_SERVICE_PROTOCOLS=['genome','ens']
13+
1214
# Instance ENVs
1315
NEXT_PUBLIC_AD_BANNER_ENABLE_SPECIFY=true
1416
NEXT_PUBLIC_ADDRESS_3RD_PARTY_WIDGETS=['talentprotocol','drops','blockscoutbadges','gitpoap','efp','etherscore','webacy','humanpassport','trustblock','smartmuv','humanode','deepdao']
@@ -41,7 +43,6 @@ NEXT_PUBLIC_MARKETPLACE_BANNER_CONTENT_URL=https://gist.githubusercontent.com/0x
4143
NEXT_PUBLIC_MARKETPLACE_BANNER_LINK_URL=https://badges.blockscout.com/badges-list?utm_source=blockscout-explorer&utm_medium=marketplace-banner
4244
NEXT_PUBLIC_MARKETPLACE_CATEGORIES_URL=https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/marketplace-categories/default.json
4345
NEXT_PUBLIC_MARKETPLACE_ENABLED=true
44-
NEXT_PUBLIC_MARKETPLACE_ESSENTIAL_DAPPS_CONFIG={'swap': {'chains': ['1', '10', '30', '100', '122', '130', '137', '324', '480', '1135', '1514', '1868', '8453', '13371', '42161', '42220', '57073', '534352', '11155111', '1313161554', '1923', '42793', '59144'], 'fee': '0.004', 'integrator': 'blockscout'}, 'multisend': {'chains': ['1', '10', '30', '100', '122', '130', '137', '324', '480', '1135', '1514', '1868', '8453', '13371', '42161', '42220', '57073', '534352', '11155111', '1313161554', '59144', '7000'], 'posthogKey': 'phc_7O4WGsecqqDO1PeaKayHAxUWN1PjheOmQCiDxEMcmkx', 'posthogHost': 'https://us.i.posthog.com'}}
4546
NEXT_PUBLIC_MARKETPLACE_GRAPH_LINKS_URL=https://raw.githubusercontent.com/blockscout/frontend-configs/refs/heads/main/configs/marketplace-subgraph-links/subgraph-links.json
4647
NEXT_PUBLIC_MARKETPLACE_SUBMIT_FORM=https://airtable.com/appiy5yijZpMMSKjT/shr6uMGPKjj1DK7NL
4748
NEXT_PUBLIC_MARKETPLACE_SUGGEST_IDEAS_FORM=https://airtable.com/appiy5yijZpMMSKjT/pag3t82DUCyhGRZZO/form

deploy/tools/envs-validator/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const schema = yup
170170
.concat(featuresSchemas.highlightsConfigSchema)
171171
.concat(featuresSchemas.marketplaceSchema)
172172
.concat(featuresSchemas.megaEthSchema)
173+
.concat(featuresSchemas.nameServicesSchema)
173174
.concat(featuresSchemas.rollupSchema)
174175
.concat(featuresSchemas.tacSchema)
175176
.concat(featuresSchemas.userOpsSchema)

deploy/tools/envs-validator/schemas/apis.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ export default yup.object({
1616

1717
NEXT_PUBLIC_CONTRACT_INFO_API_HOST: yup.string().test(urlTest),
1818

19-
NEXT_PUBLIC_NAME_SERVICE_API_HOST: yup.string().test(urlTest),
20-
21-
NEXT_PUBLIC_CLUSTERS_API_HOST: yup.string().test(urlTest),
22-
NEXT_PUBLIC_CLUSTERS_CDN_URL: yup.string().test(urlTest),
23-
2419
NEXT_PUBLIC_ADMIN_SERVICE_API_HOST: yup.string().test(urlTest),
2520

2621
NEXT_PUBLIC_REWARDS_SERVICE_API_HOST: yup.string().test(urlTest),

deploy/tools/envs-validator/schemas/features/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from './defiDropdown';
99
export * from './highlights';
1010
export * from './marketplace';
1111
export * from './megaEth';
12+
export * from './nameServices';
1213
export * from './rollup';
1314
export * from './tac';
1415
export * from './userOps';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { urlTest } from "../../utils";
2+
import * as yup from 'yup';
3+
import { replaceQuotes } from 'configs/app/utils';
4+
import type { ApiDocsTabId } from 'types/views/apiDocs';
5+
import { API_DOCS_TABS } from 'types/views/apiDocs';
6+
7+
export const nameServicesSchema = yup
8+
.object()
9+
.shape({
10+
NEXT_PUBLIC_NAME_SERVICE_API_HOST: yup.string().test(urlTest),
11+
NEXT_PUBLIC_NAME_SERVICE_PROTOCOLS: yup
12+
.array()
13+
.transform(replaceQuotes)
14+
.json()
15+
.when('NEXT_PUBLIC_NAME_SERVICE_API_HOST', {
16+
is: (value: string) => Boolean(value),
17+
then: (schema) => schema.of(yup.string()).min(1).optional(),
18+
otherwise: (schema) => schema.test(
19+
'not-exist',
20+
'NEXT_PUBLIC_NAME_SERVICE_PROTOCOLS cannot not be used if NEXT_PUBLIC_NAME_SERVICE_API_HOST is not set',
21+
value => value === undefined,
22+
),
23+
}),
24+
25+
NEXT_PUBLIC_CLUSTERS_API_HOST: yup.string().test(urlTest),
26+
NEXT_PUBLIC_CLUSTERS_CDN_URL: yup
27+
.string()
28+
.when('NEXT_PUBLIC_CLUSTERS_API_HOST', {
29+
is: (value: string) => Boolean(value),
30+
then: (schema) => schema.test(urlTest).optional(),
31+
otherwise: (schema) => schema.test(
32+
'not-exist',
33+
'NEXT_PUBLIC_CLUSTERS_CDN_URL cannot not be used if NEXT_PUBLIC_CLUSTERS_API_HOST is not set',
34+
value => value === undefined,
35+
),
36+
}),
37+
});

deploy/tools/envs-validator/test/.env.base

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,7 @@ NEXT_PUBLIC_ADDRESS_3RD_PARTY_WIDGETS_CONFIG_URL=https://example.com
9393
NEXT_PUBLIC_NAVIGATION_PROMO_BANNER_CONFIG={'img_url': 'https://example.com/promo.svg', 'text': 'Promo text', 'bg_color': {'light': 'rgb(250, 245, 255)', 'dark': 'rgb(68, 51, 122)'}, 'text_color': {'light': 'rgb(107, 70, 193)', 'dark': 'rgb(233, 216, 253)'}, 'link_url': 'https://example.com'}
9494
NEXT_PUBLIC_FLASHBLOCKS_SOCKET_URL=wss://example.com/ws
9595
NEXT_PUBLIC_HOMEPAGE_HIGHLIGHTS_CONFIG=https://example.com
96+
NEXT_PUBLIC_NAME_SERVICE_API_HOST=https://example.com
97+
NEXT_PUBLIC_NAME_SERVICE_PROTOCOLS=['duck','goose']
98+
NEXT_PUBLIC_CLUSTERS_API_HOST=https://example.com
99+
NEXT_PUBLIC_CLUSTERS_CDN_URL=https://example.com

docs/ENVS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ This feature allows resolving blockchain addresses using human-readable domain n
711711
| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
712712
| --- | --- | --- | --- | --- | --- | --- |
713713
| NEXT_PUBLIC_NAME_SERVICE_API_HOST | `string` | Name Service API endpoint url | Required | - | `https://bens.services.blockscout.com` | v1.22.0+ |
714+
| NEXT_PUBLIC_NAME_SERVICE_PROTOCOLS | `Array<string>` | List of the protocols used by the chain. The protocol ids can be obtained from [/api/v1/protocols](https://bens.services.blockscout.com/api/v1/protocols) resource. | - | `['ens']` | `['rns']` | upcoming |
714715

715716
&nbsp;
716717

lib/api/resources.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,5 @@ export const b: PaginatedResourceName = 'general:addresses';
172172
export const c: PaginatedResourceResponseItems<'general:addresses'> = [];
173173

174174
export const d: ResourcePathParams<'bens:address_domain'> = {
175-
chainId: '1',
176175
address: '123',
177176
};

lib/api/services/bens.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@ import type { EnsAddressLookupFilters, EnsDomainLookupFilters, EnsLookupSorting
44

55
export const BENS_API_RESOURCES = {
66
addresses_lookup: {
7-
path: '/api/v1/:chainId/addresses\\:lookup',
8-
pathParams: [ 'chainId' as const ],
7+
path: '/api/v1/addresses\\:lookup',
98
filterFields: [ 'address' as const, 'resolved_to' as const, 'owned_by' as const, 'only_active' as const, 'protocols' as const ],
109
paginated: true,
1110
},
1211
address_domain: {
13-
path: '/api/v1/:chainId/addresses/:address',
14-
pathParams: [ 'chainId' as const, 'address' as const ],
12+
path: '/api/v1/addresses/:address',
13+
pathParams: [ 'address' as const ],
14+
filterFields: [ 'protocols' as const ],
1515
},
1616
domain_info: {
17-
path: '/api/v1/:chainId/domains/:name',
18-
pathParams: [ 'chainId' as const, 'name' as const ],
17+
path: '/api/v1/domains/:name',
18+
pathParams: [ 'name' as const ],
19+
filterFields: [ 'protocols' as const ],
1920
},
2021
domain_events: {
21-
path: '/api/v1/:chainId/domains/:name/events',
22-
pathParams: [ 'chainId' as const, 'name' as const ],
22+
path: '/api/v1/domains/:name/events',
23+
pathParams: [ 'name' as const ],
24+
filterFields: [ 'protocols' as const ],
2325
},
2426
domains_lookup: {
25-
path: '/api/v1/:chainId/domains\\:lookup',
26-
pathParams: [ 'chainId' as const ],
27+
path: '/api/v1/domains\\:lookup',
2728
filterFields: [ 'name' as const, 'only_active' as const, 'protocols' as const ],
2829
paginated: true,
2930
},
30-
domain_protocols: {
31-
path: '/api/v1/:chainId/protocols',
32-
pathParams: [ 'chainId' as const ],
31+
protocols: {
32+
path: '/api/v1/protocols',
3333
},
3434
} satisfies Record<string, ApiResource>;
3535

@@ -42,7 +42,7 @@ R extends 'bens:address_domain' ? bens.GetAddressResponse :
4242
R extends 'bens:domain_info' ? bens.DetailedDomain :
4343
R extends 'bens:domain_events' ? bens.ListDomainEventsResponse :
4444
R extends 'bens:domains_lookup' ? bens.LookupDomainNameResponse :
45-
R extends 'bens:domain_protocols' ? bens.GetProtocolsResponse :
45+
R extends 'bens:protocols' ? bens.GetProtocolsResponse :
4646
never;
4747
/* eslint-enable @stylistic/indent */
4848

0 commit comments

Comments
 (0)