Skip to content

Commit 24eb4fc

Browse files
authored
API resource refactoring (#2699)
* add prefix to API resources * fix pw tests * refactor config * remove unnecessary prefixes in resource names * fixes * update screenshots
1 parent b54be82 commit 24eb4fc

File tree

388 files changed

+3088
-2716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

388 files changed

+3088
-2716
lines changed

configs/app/api.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

configs/app/apis.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import type { ApiName } from 'lib/api/types';
2+
3+
import { stripTrailingSlash } from 'toolkit/utils/url';
4+
5+
import { getEnvValue } from './utils';
6+
7+
interface ApiPropsBase {
8+
endpoint: string;
9+
basePath?: string;
10+
}
11+
12+
interface ApiPropsFull extends ApiPropsBase {
13+
host: string;
14+
protocol: string;
15+
port?: string;
16+
socketEndpoint: string;
17+
}
18+
19+
const generalApi = (() => {
20+
const apiHost = getEnvValue('NEXT_PUBLIC_API_HOST');
21+
const apiSchema = getEnvValue('NEXT_PUBLIC_API_PROTOCOL') || 'https';
22+
const apiPort = getEnvValue('NEXT_PUBLIC_API_PORT');
23+
const apiEndpoint = [
24+
apiSchema || 'https',
25+
'://',
26+
apiHost,
27+
apiPort && ':' + apiPort,
28+
].filter(Boolean).join('');
29+
30+
const socketSchema = getEnvValue('NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL') || 'wss';
31+
const socketEndpoint = [
32+
socketSchema,
33+
'://',
34+
apiHost,
35+
apiPort && ':' + apiPort,
36+
].filter(Boolean).join('');
37+
38+
return Object.freeze({
39+
endpoint: apiEndpoint,
40+
basePath: stripTrailingSlash(getEnvValue('NEXT_PUBLIC_API_BASE_PATH') || ''),
41+
socketEndpoint: socketEndpoint,
42+
host: apiHost ?? '',
43+
protocol: apiSchema ?? 'https',
44+
port: apiPort,
45+
});
46+
})();
47+
48+
const adminApi = (() => {
49+
const apiHost = getEnvValue('NEXT_PUBLIC_ADMIN_SERVICE_API_HOST');
50+
if (!apiHost) {
51+
return;
52+
}
53+
54+
return Object.freeze({
55+
endpoint: apiHost,
56+
});
57+
})();
58+
59+
const bensApi = (() => {
60+
const apiHost = getEnvValue('NEXT_PUBLIC_NAME_SERVICE_API_HOST');
61+
if (!apiHost) {
62+
return;
63+
}
64+
65+
return Object.freeze({
66+
endpoint: apiHost,
67+
});
68+
})();
69+
70+
const contractInfoApi = (() => {
71+
const apiHost = getEnvValue('NEXT_PUBLIC_CONTRACT_INFO_API_HOST');
72+
if (!apiHost) {
73+
return;
74+
}
75+
76+
return Object.freeze({
77+
endpoint: apiHost,
78+
});
79+
})();
80+
81+
const metadataApi = (() => {
82+
const apiHost = getEnvValue('NEXT_PUBLIC_METADATA_SERVICE_API_HOST');
83+
if (!apiHost) {
84+
return;
85+
}
86+
87+
return Object.freeze({
88+
endpoint: apiHost,
89+
});
90+
})();
91+
92+
const rewardsApi = (() => {
93+
const apiHost = getEnvValue('NEXT_PUBLIC_REWARDS_SERVICE_API_HOST');
94+
if (!apiHost) {
95+
return;
96+
}
97+
98+
return Object.freeze({
99+
endpoint: apiHost,
100+
});
101+
})();
102+
103+
const statsApi = (() => {
104+
const apiHost = getEnvValue('NEXT_PUBLIC_STATS_API_HOST');
105+
if (!apiHost) {
106+
return;
107+
}
108+
109+
return Object.freeze({
110+
endpoint: apiHost,
111+
basePath: stripTrailingSlash(getEnvValue('NEXT_PUBLIC_STATS_API_BASE_PATH') || ''),
112+
});
113+
})();
114+
115+
const visualizeApi = (() => {
116+
const apiHost = getEnvValue('NEXT_PUBLIC_VISUALIZE_API_HOST');
117+
if (!apiHost) {
118+
return;
119+
}
120+
121+
return Object.freeze({
122+
endpoint: apiHost,
123+
basePath: stripTrailingSlash(getEnvValue('NEXT_PUBLIC_VISUALIZE_API_BASE_PATH') || ''),
124+
});
125+
})();
126+
127+
type Apis = {
128+
general: ApiPropsFull;
129+
} & Partial<Record<Exclude<ApiName, 'general'>, ApiPropsBase>>;
130+
131+
const apis: Apis = Object.freeze({
132+
general: generalApi,
133+
admin: adminApi,
134+
bens: bensApi,
135+
contractInfo: contractInfoApi,
136+
metadata: metadataApi,
137+
rewards: rewardsApi,
138+
stats: statsApi,
139+
visualize: visualizeApi,
140+
});
141+
142+
export default apis;

configs/app/features/addressMetadata.ts

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

3-
import { getEnvValue } from '../utils';
4-
5-
const apiHost = getEnvValue('NEXT_PUBLIC_METADATA_SERVICE_API_HOST');
3+
import apis from '../apis';
64

75
const title = 'Address metadata';
86

9-
const config: Feature<{ api: { endpoint: string; basePath: string } }> = (() => {
10-
if (apiHost) {
7+
const config: Feature<{}> = (() => {
8+
if (apis.metadata) {
119
return Object.freeze({
1210
title,
1311
isEnabled: true,
14-
api: {
15-
endpoint: apiHost,
16-
basePath: '',
17-
},
1812
});
1913
}
2014

configs/app/features/addressVerification.ts

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

3-
import { getEnvValue } from '../utils';
3+
import apis from '../apis';
44
import account from './account';
55
import verifiedTokens from './verifiedTokens';
66

7-
const adminServiceApiHost = getEnvValue('NEXT_PUBLIC_ADMIN_SERVICE_API_HOST');
8-
97
const title = 'Address verification in "My account"';
108

11-
const config: Feature<{ api: { endpoint: string; basePath: string } }> = (() => {
12-
if (account.isEnabled && verifiedTokens.isEnabled && adminServiceApiHost) {
9+
const config: Feature<{}> = (() => {
10+
if (account.isEnabled && verifiedTokens.isEnabled && apis.admin) {
1311
return Object.freeze({
1412
title: 'Address verification in "My account"',
1513
isEnabled: true,
16-
api: {
17-
endpoint: adminServiceApiHost,
18-
basePath: '',
19-
},
2014
});
2115
}
2216

configs/app/features/marketplace.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Feature } from './types';
22

3+
import apis from '../apis';
34
import chain from '../chain';
45
import { getEnvValue, getExternalAssetFilePath } from '../utils';
56

@@ -9,7 +10,6 @@ const configUrl = getExternalAssetFilePath('NEXT_PUBLIC_MARKETPLACE_CONFIG_URL')
910
const submitFormUrl = getEnvValue('NEXT_PUBLIC_MARKETPLACE_SUBMIT_FORM');
1011
const suggestIdeasFormUrl = getEnvValue('NEXT_PUBLIC_MARKETPLACE_SUGGEST_IDEAS_FORM');
1112
const categoriesUrl = getExternalAssetFilePath('NEXT_PUBLIC_MARKETPLACE_CATEGORIES_URL');
12-
const adminServiceApiHost = getEnvValue('NEXT_PUBLIC_ADMIN_SERVICE_API_HOST');
1313
const securityReportsUrl = getExternalAssetFilePath('NEXT_PUBLIC_MARKETPLACE_SECURITY_REPORTS_URL');
1414
const featuredApp = getEnvValue('NEXT_PUBLIC_MARKETPLACE_FEATURED_APP');
1515
const bannerContentUrl = getExternalAssetFilePath('NEXT_PUBLIC_MARKETPLACE_BANNER_CONTENT_URL');
@@ -22,7 +22,7 @@ const title = 'Marketplace';
2222

2323
const config: Feature<(
2424
{ configUrl: string } |
25-
{ api: { endpoint: string; basePath: string } }
25+
{ api: { endpoint: string; basePath?: string } }
2626
) & {
2727
submitFormUrl: string;
2828
categoriesUrl: string | undefined;
@@ -58,14 +58,11 @@ const config: Feature<(
5858
configUrl,
5959
...props,
6060
});
61-
} else if (adminServiceApiHost) {
61+
} else if (apis.admin) {
6262
return Object.freeze({
6363
title,
6464
isEnabled: true,
65-
api: {
66-
endpoint: adminServiceApiHost,
67-
basePath: '',
68-
},
65+
api: apis.admin,
6966
...props,
7067
});
7168
}

configs/app/features/nameService.ts

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

3-
import { getEnvValue } from '../utils';
4-
5-
const apiHost = getEnvValue('NEXT_PUBLIC_NAME_SERVICE_API_HOST');
3+
import apis from '../apis';
64

75
const title = 'Name service integration';
86

9-
const config: Feature<{ api: { endpoint: string; basePath: string } }> = (() => {
10-
if (apiHost) {
7+
const config: Feature<{}> = (() => {
8+
if (apis.bens) {
119
return Object.freeze({
1210
title,
1311
isEnabled: true,
14-
api: {
15-
endpoint: apiHost,
16-
basePath: '',
17-
},
1812
});
1913
}
2014

configs/app/features/pools.ts

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

3+
import apis from '../apis';
34
import { getEnvValue } from '../utils';
45

5-
const contractInfoApiHost = getEnvValue('NEXT_PUBLIC_CONTRACT_INFO_API_HOST');
66
const dexPoolsEnabled = getEnvValue('NEXT_PUBLIC_DEX_POOLS_ENABLED') === 'true';
77

88
const title = 'DEX Pools';
99

10-
const config: Feature<{ api: { endpoint: string; basePath: string } }> = (() => {
11-
if (contractInfoApiHost && dexPoolsEnabled) {
10+
const config: Feature<{ }> = (() => {
11+
if (apis.contractInfo && dexPoolsEnabled) {
1212
return Object.freeze({
1313
title,
1414
isEnabled: true,
15-
api: {
16-
endpoint: contractInfoApiHost,
17-
basePath: '',
18-
},
1915
});
2016
}
2117

configs/app/features/publicTagsSubmission.ts

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

3+
import apis from '../apis';
34
import services from '../services';
4-
import { getEnvValue } from '../utils';
55
import addressMetadata from './addressMetadata';
66

7-
const apiHost = getEnvValue('NEXT_PUBLIC_ADMIN_SERVICE_API_HOST');
8-
97
const title = 'Public tag submission';
108

11-
const config: Feature<{ api: { endpoint: string; basePath: string } }> = (() => {
12-
if (services.reCaptchaV2.siteKey && addressMetadata.isEnabled && apiHost) {
9+
const config: Feature<{}> = (() => {
10+
if (services.reCaptchaV2.siteKey && addressMetadata.isEnabled && apis.admin) {
1311
return Object.freeze({
1412
title,
1513
isEnabled: true,
16-
api: {
17-
endpoint: apiHost,
18-
basePath: '',
19-
},
2014
});
2115
}
2216

configs/app/features/rewards.ts

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

3-
import { getEnvValue } from '../utils';
3+
import apis from '../apis';
44
import account from './account';
55
import blockchainInteraction from './blockchainInteraction';
66

7-
const apiHost = getEnvValue('NEXT_PUBLIC_REWARDS_SERVICE_API_HOST');
8-
97
const title = 'Rewards service integration';
108

11-
const config: Feature<{ api: { endpoint: string; basePath: string } }> = (() => {
12-
if (apiHost && account.isEnabled && blockchainInteraction.isEnabled) {
9+
const config: Feature<{}> = (() => {
10+
if (apis.rewards && account.isEnabled && blockchainInteraction.isEnabled) {
1311
return Object.freeze({
1412
title,
1513
isEnabled: true,
16-
api: {
17-
endpoint: apiHost,
18-
basePath: '',
19-
},
2014
});
2115
}
2216

configs/app/features/sol2uml.ts

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

3-
import { stripTrailingSlash } from 'toolkit/utils/url';
4-
5-
import { getEnvValue } from '../utils';
6-
7-
const apiEndpoint = getEnvValue('NEXT_PUBLIC_VISUALIZE_API_HOST');
3+
import apis from '../apis';
84

95
const title = 'Solidity to UML diagrams';
106

11-
const config: Feature<{ api: { endpoint: string; basePath: string } }> = (() => {
12-
if (apiEndpoint) {
7+
const config: Feature<{}> = (() => {
8+
if (apis.visualize) {
139
return Object.freeze({
1410
title,
1511
isEnabled: true,
16-
api: {
17-
endpoint: apiEndpoint,
18-
basePath: stripTrailingSlash(getEnvValue('NEXT_PUBLIC_VISUALIZE_API_BASE_PATH') || ''),
19-
},
2012
});
2113
}
2214

0 commit comments

Comments
 (0)