Skip to content

Commit f4a4344

Browse files
chore: code improvements
1 parent 8e26686 commit f4a4344

File tree

3 files changed

+21
-81
lines changed

3 files changed

+21
-81
lines changed

packages/core/src/controllers/BlockchainApiController.ts

Lines changed: 21 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ import { ConstantsUtil } from '../utils/ConstantsUtil';
3030
// -- Helpers ------------------------------------------- //
3131
const baseUrl = CoreHelperUtil.getBlockchainApiUrl();
3232

33+
const getHeaders = () => {
34+
const { sdkType, sdkVersion } = OptionsController.state;
35+
36+
return {
37+
'Content-Type': 'application/json',
38+
'x-sdk-type': sdkType,
39+
'x-sdk-version': sdkVersion
40+
};
41+
};
42+
3343
// -- Types --------------------------------------------- //
3444
export interface BlockchainApiControllerState {
3545
clientId: string | null;
@@ -47,18 +57,12 @@ export const BlockchainApiController = {
4757
state,
4858

4959
fetchIdentity({ address }: BlockchainApiIdentityRequest) {
50-
const { sdkType, sdkVersion } = OptionsController.state;
51-
5260
return state.api.get<BlockchainApiIdentityResponse>({
5361
path: `/v1/identity/${address}`,
5462
params: {
5563
projectId: OptionsController.state.projectId
5664
},
57-
headers: {
58-
'Content-Type': 'application/json',
59-
'x-sdk-type': sdkType,
60-
'x-sdk-version': sdkVersion
61-
}
65+
headers: getHeaders()
6266
});
6367
},
6468

@@ -70,15 +74,9 @@ export const BlockchainApiController = {
7074
signal,
7175
cache
7276
}: BlockchainApiTransactionsRequest) {
73-
const { sdkType, sdkVersion } = OptionsController.state;
74-
7577
return state.api.get<BlockchainApiTransactionsResponse>({
7678
path: `/v1/account/${account}/history`,
77-
headers: {
78-
'Content-Type': 'application/json',
79-
'x-sdk-type': sdkType,
80-
'x-sdk-version': sdkVersion
81-
},
79+
headers: getHeaders(),
8280
params: {
8381
projectId,
8482
cursor,
@@ -90,51 +88,33 @@ export const BlockchainApiController = {
9088
},
9189

9290
fetchTokenPrice({ projectId, addresses }: BlockchainApiTokenPriceRequest) {
93-
const { sdkType, sdkVersion } = OptionsController.state;
94-
9591
return state.api.post<BlockchainApiTokenPriceResponse>({
9692
path: '/v1/fungible/price',
9793
body: {
9894
projectId,
9995
currency: 'usd',
10096
addresses
10197
},
102-
headers: {
103-
'Content-Type': 'application/json',
104-
'x-sdk-type': sdkType,
105-
'x-sdk-version': sdkVersion
106-
}
98+
headers: getHeaders()
10799
});
108100
},
109101

110102
fetchSwapAllowance({ projectId, tokenAddress, userAddress }: BlockchainApiSwapAllowanceRequest) {
111-
const { sdkType, sdkVersion } = OptionsController.state;
112-
113103
return state.api.get<BlockchainApiSwapAllowanceResponse>({
114104
path: `/v1/convert/allowance`,
115105
params: {
116106
projectId,
117107
tokenAddress,
118108
userAddress
119109
},
120-
headers: {
121-
'Content-Type': 'application/json',
122-
'x-sdk-type': sdkType,
123-
'x-sdk-version': sdkVersion
124-
}
110+
headers: getHeaders()
125111
});
126112
},
127113

128114
fetchGasPrice({ projectId, chainId }: BlockchainApiGasPriceRequest) {
129-
const { sdkType, sdkVersion } = OptionsController.state;
130-
131115
return state.api.get<BlockchainApiGasPriceResponse>({
132116
path: `/v1/convert/gas-price`,
133-
headers: {
134-
'Content-Type': 'application/json',
135-
'x-sdk-type': sdkType,
136-
'x-sdk-version': sdkVersion
137-
},
117+
headers: getHeaders(),
138118
params: {
139119
projectId,
140120
chainId
@@ -150,15 +130,9 @@ export const BlockchainApiController = {
150130
to,
151131
gasPrice
152132
}: BlockchainApiSwapQuoteRequest) {
153-
const { sdkType, sdkVersion } = OptionsController.state;
154-
155133
return state.api.get<BlockchainApiSwapQuoteResponse>({
156134
path: `/v1/convert/quotes`,
157-
headers: {
158-
'Content-Type': 'application/json',
159-
'x-sdk-type': sdkType,
160-
'x-sdk-version': sdkVersion
161-
},
135+
headers: getHeaders(),
162136
params: {
163137
projectId,
164138
amount,
@@ -171,15 +145,9 @@ export const BlockchainApiController = {
171145
},
172146

173147
fetchSwapTokens({ projectId, chainId }: BlockchainApiSwapTokensRequest) {
174-
const { sdkType, sdkVersion } = OptionsController.state;
175-
176148
return state.api.get<BlockchainApiSwapTokensResponse>({
177149
path: `/v1/convert/tokens`,
178-
headers: {
179-
'Content-Type': 'application/json',
180-
'x-sdk-type': sdkType,
181-
'x-sdk-version': sdkVersion
182-
},
150+
headers: getHeaders(),
183151
params: {
184152
projectId,
185153
chainId
@@ -194,15 +162,9 @@ export const BlockchainApiController = {
194162
to,
195163
userAddress
196164
}: BlockchainApiGenerateSwapCalldataRequest) {
197-
const { sdkType, sdkVersion } = OptionsController.state;
198-
199165
return state.api.post<BlockchainApiGenerateSwapCalldataResponse>({
200166
path: '/v1/convert/build-transaction',
201-
headers: {
202-
'Content-Type': 'application/json',
203-
'x-sdk-type': sdkType,
204-
'x-sdk-version': sdkVersion
205-
},
167+
headers: getHeaders(),
206168
body: {
207169
amount,
208170
eip155: {
@@ -222,15 +184,9 @@ export const BlockchainApiController = {
222184
to,
223185
userAddress
224186
}: BlockchainApiGenerateApproveCalldataRequest) {
225-
const { sdkType, sdkVersion } = OptionsController.state;
226-
227187
return state.api.get<BlockchainApiGenerateApproveCalldataResponse>({
228188
path: `/v1/convert/build-approve`,
229-
headers: {
230-
'Content-Type': 'application/json',
231-
'x-sdk-type': sdkType,
232-
'x-sdk-version': sdkVersion
233-
},
189+
headers: getHeaders(),
234190
params: {
235191
projectId,
236192
userAddress,
@@ -241,14 +197,9 @@ export const BlockchainApiController = {
241197
},
242198

243199
async getBalance(address: string, chainId?: string, forceUpdate?: string) {
244-
const { sdkType, sdkVersion } = OptionsController.state;
245-
246200
return state.api.get<BlockchainApiBalanceResponse>({
247201
path: `/v1/account/${address}/balance`,
248-
headers: {
249-
'x-sdk-type': sdkType,
250-
'x-sdk-version': sdkVersion
251-
},
202+
headers: getHeaders(),
252203
params: {
253204
currency: 'usd',
254205
projectId: OptionsController.state.projectId,
@@ -259,15 +210,9 @@ export const BlockchainApiController = {
259210
},
260211

261212
async lookupEnsName(name: string) {
262-
const { sdkType, sdkVersion } = OptionsController.state;
263-
264213
return state.api.get<BlockchainApiLookupEnsName>({
265214
path: `/v1/profile/account/${name}`,
266-
headers: {
267-
'Content-Type': 'application/json',
268-
'x-sdk-type': sdkType,
269-
'x-sdk-version': sdkVersion
270-
},
215+
headers: getHeaders(),
271216
params: {
272217
projectId: OptionsController.state.projectId,
273218
apiVersion: '2'

packages/core/src/utils/ConnectionUtil.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const ConnectionUtil = {
1717
type: 'track',
1818
event: 'DISCONNECT_SUCCESS'
1919
});
20-
throw new Error('ERROR PA');
2120
} catch (error) {
2221
EventsController.sendEvent({
2322
type: 'track',

packages/scaffold/src/views/w3m-swap-view/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ export function SwapView() {
4949
});
5050

5151
const getActionButtonState = () => {
52-
// if (fetchError) {
53-
// return 'Swap'
54-
// }
55-
5652
if (!SwapController.state.sourceToken || !SwapController.state.toToken) {
5753
return { text: 'Select token', disabled: true };
5854
}

0 commit comments

Comments
 (0)