@@ -30,6 +30,16 @@ import { ConstantsUtil } from '../utils/ConstantsUtil';
30
30
// -- Helpers ------------------------------------------- //
31
31
const baseUrl = CoreHelperUtil . getBlockchainApiUrl ( ) ;
32
32
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
+
33
43
// -- Types --------------------------------------------- //
34
44
export interface BlockchainApiControllerState {
35
45
clientId : string | null ;
@@ -47,18 +57,12 @@ export const BlockchainApiController = {
47
57
state,
48
58
49
59
fetchIdentity ( { address } : BlockchainApiIdentityRequest ) {
50
- const { sdkType, sdkVersion } = OptionsController . state ;
51
-
52
60
return state . api . get < BlockchainApiIdentityResponse > ( {
53
61
path : `/v1/identity/${ address } ` ,
54
62
params : {
55
63
projectId : OptionsController . state . projectId
56
64
} ,
57
- headers : {
58
- 'Content-Type' : 'application/json' ,
59
- 'x-sdk-type' : sdkType ,
60
- 'x-sdk-version' : sdkVersion
61
- }
65
+ headers : getHeaders ( )
62
66
} ) ;
63
67
} ,
64
68
@@ -70,15 +74,9 @@ export const BlockchainApiController = {
70
74
signal,
71
75
cache
72
76
} : BlockchainApiTransactionsRequest ) {
73
- const { sdkType, sdkVersion } = OptionsController . state ;
74
-
75
77
return state . api . get < BlockchainApiTransactionsResponse > ( {
76
78
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 ( ) ,
82
80
params : {
83
81
projectId,
84
82
cursor,
@@ -90,51 +88,33 @@ export const BlockchainApiController = {
90
88
} ,
91
89
92
90
fetchTokenPrice ( { projectId, addresses } : BlockchainApiTokenPriceRequest ) {
93
- const { sdkType, sdkVersion } = OptionsController . state ;
94
-
95
91
return state . api . post < BlockchainApiTokenPriceResponse > ( {
96
92
path : '/v1/fungible/price' ,
97
93
body : {
98
94
projectId,
99
95
currency : 'usd' ,
100
96
addresses
101
97
} ,
102
- headers : {
103
- 'Content-Type' : 'application/json' ,
104
- 'x-sdk-type' : sdkType ,
105
- 'x-sdk-version' : sdkVersion
106
- }
98
+ headers : getHeaders ( )
107
99
} ) ;
108
100
} ,
109
101
110
102
fetchSwapAllowance ( { projectId, tokenAddress, userAddress } : BlockchainApiSwapAllowanceRequest ) {
111
- const { sdkType, sdkVersion } = OptionsController . state ;
112
-
113
103
return state . api . get < BlockchainApiSwapAllowanceResponse > ( {
114
104
path : `/v1/convert/allowance` ,
115
105
params : {
116
106
projectId,
117
107
tokenAddress,
118
108
userAddress
119
109
} ,
120
- headers : {
121
- 'Content-Type' : 'application/json' ,
122
- 'x-sdk-type' : sdkType ,
123
- 'x-sdk-version' : sdkVersion
124
- }
110
+ headers : getHeaders ( )
125
111
} ) ;
126
112
} ,
127
113
128
114
fetchGasPrice ( { projectId, chainId } : BlockchainApiGasPriceRequest ) {
129
- const { sdkType, sdkVersion } = OptionsController . state ;
130
-
131
115
return state . api . get < BlockchainApiGasPriceResponse > ( {
132
116
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 ( ) ,
138
118
params : {
139
119
projectId,
140
120
chainId
@@ -150,15 +130,9 @@ export const BlockchainApiController = {
150
130
to,
151
131
gasPrice
152
132
} : BlockchainApiSwapQuoteRequest ) {
153
- const { sdkType, sdkVersion } = OptionsController . state ;
154
-
155
133
return state . api . get < BlockchainApiSwapQuoteResponse > ( {
156
134
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 ( ) ,
162
136
params : {
163
137
projectId,
164
138
amount,
@@ -171,15 +145,9 @@ export const BlockchainApiController = {
171
145
} ,
172
146
173
147
fetchSwapTokens ( { projectId, chainId } : BlockchainApiSwapTokensRequest ) {
174
- const { sdkType, sdkVersion } = OptionsController . state ;
175
-
176
148
return state . api . get < BlockchainApiSwapTokensResponse > ( {
177
149
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 ( ) ,
183
151
params : {
184
152
projectId,
185
153
chainId
@@ -194,15 +162,9 @@ export const BlockchainApiController = {
194
162
to,
195
163
userAddress
196
164
} : BlockchainApiGenerateSwapCalldataRequest ) {
197
- const { sdkType, sdkVersion } = OptionsController . state ;
198
-
199
165
return state . api . post < BlockchainApiGenerateSwapCalldataResponse > ( {
200
166
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 ( ) ,
206
168
body : {
207
169
amount,
208
170
eip155 : {
@@ -222,15 +184,9 @@ export const BlockchainApiController = {
222
184
to,
223
185
userAddress
224
186
} : BlockchainApiGenerateApproveCalldataRequest ) {
225
- const { sdkType, sdkVersion } = OptionsController . state ;
226
-
227
187
return state . api . get < BlockchainApiGenerateApproveCalldataResponse > ( {
228
188
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 ( ) ,
234
190
params : {
235
191
projectId,
236
192
userAddress,
@@ -241,14 +197,9 @@ export const BlockchainApiController = {
241
197
} ,
242
198
243
199
async getBalance ( address : string , chainId ?: string , forceUpdate ?: string ) {
244
- const { sdkType, sdkVersion } = OptionsController . state ;
245
-
246
200
return state . api . get < BlockchainApiBalanceResponse > ( {
247
201
path : `/v1/account/${ address } /balance` ,
248
- headers : {
249
- 'x-sdk-type' : sdkType ,
250
- 'x-sdk-version' : sdkVersion
251
- } ,
202
+ headers : getHeaders ( ) ,
252
203
params : {
253
204
currency : 'usd' ,
254
205
projectId : OptionsController . state . projectId ,
@@ -259,15 +210,9 @@ export const BlockchainApiController = {
259
210
} ,
260
211
261
212
async lookupEnsName ( name : string ) {
262
- const { sdkType, sdkVersion } = OptionsController . state ;
263
-
264
213
return state . api . get < BlockchainApiLookupEnsName > ( {
265
214
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 ( ) ,
271
216
params : {
272
217
projectId : OptionsController . state . projectId ,
273
218
apiVersion : '2'
0 commit comments