@rabby-wallet/rabby-api 0.6.16 → 0.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { AxiosAdapter } from 'axios';
2
2
  import { RateLimitedAxiosInstance } from 'axios-rate-limit';
3
- import { ServerChain, TotalBalanceResponse, ChainWithPendingCount, SecurityCheckResponse, Tx, ExplainTxResponse, GasLevel, GetTxResponse, TokenItem, AssetItem, NFTItem, Collection, TxHistoryResult, TokenApproval, NFTApprovalResponse, ApprovalStatus, UsedChain, Protocol, ComplexProtocol, ExplainTypedDataResponse, SwapTradeList, SlippageStatus, CEXQuote, Summary, Cex, ContractCredit, AddrDescResponse, ParseTxResponse, CollectionWithFloorPrice, ParseTypedDataResponse, ParseTextResponse, CollectionList } from './types';
3
+ import { AddrDescResponse, ApprovalStatus, AssetItem, CEXQuote, Cex, ChainWithPendingCount, Collection, CollectionList, CollectionWithFloorPrice, ComplexProtocol, ContractCredit, ExplainTxResponse, ExplainTypedDataResponse, GasLevel, GetTxResponse, NFTApprovalResponse, NFTItem, ParseTextResponse, ParseTxResponse, ParseTypedDataResponse, Protocol, SecurityCheckResponse, ServerChain, SlippageStatus, Summary, SwapTradeList, TokenApproval, TokenItem, TotalBalanceResponse, Tx, TxHistoryResult, UsedChain } from './types';
4
4
  interface OpenApiStore {
5
5
  host: string;
6
+ testnetHost?: string;
6
7
  }
7
8
  interface Options {
8
9
  store: OpenApiStore;
@@ -13,6 +14,8 @@ export declare class OpenApiService {
13
14
  request: RateLimitedAxiosInstance;
14
15
  setHost: (host: string) => Promise<void>;
15
16
  getHost: () => string;
17
+ setTestnetHost: (host: string) => Promise<void>;
18
+ getTestnetHost: () => string | undefined;
16
19
  ethRpc: ((chainId: string, arg: {
17
20
  method: string;
18
21
  params: Array<any>;
@@ -21,6 +24,7 @@ export declare class OpenApiService {
21
24
  adapter?: AxiosAdapter;
22
25
  constructor({ store, adapter }: Options);
23
26
  init: (hf?: string) => Promise<void>;
27
+ private _getRequestOptions;
24
28
  private _mountMethods;
25
29
  getRecommendChains: (address: string, origin: string) => Promise<ServerChain[]>;
26
30
  getTotalBalance: (address: string) => Promise<TotalBalanceResponse>;
@@ -67,6 +71,7 @@ export declare class OpenApiService {
67
71
  timeAt?: number;
68
72
  dateAt?: string;
69
73
  }) => Promise<TokenItem[]>;
74
+ _customListToken: (uuids: string[], id: string, isTestnet?: boolean) => Promise<TokenItem[]>;
70
75
  customListToken: (uuids: string[], id: string) => Promise<TokenItem[]>;
71
76
  listChainAssets: (id: string) => Promise<AssetItem[]>;
72
77
  listNFT: (id: string, isAll?: boolean) => Promise<NFTItem[]>;
package/dist/index.js CHANGED
@@ -7,11 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
10
11
  import axios from 'axios';
11
12
  import rateLimit from 'axios-rate-limit';
12
13
  import { ethErrors } from 'eth-rpc-errors';
13
- import { getChain, INITIAL_OPENAPI_URL, CHAINS, SIGN_HDS, genSignParams, } from './utils';
14
- import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
14
+ import { CHAINS, SIGN_HDS, genSignParams, getChain, getChainByNetwork, } from './utils';
15
15
  const maxRPS = 500;
16
16
  export class OpenApiService {
17
17
  constructor({ store, adapter }) {
@@ -30,15 +30,18 @@ export class OpenApiService {
30
30
  this.getHost = () => {
31
31
  return this.store.host;
32
32
  };
33
+ this.setTestnetHost = (host) => __awaiter(this, void 0, void 0, function* () {
34
+ this.store.testnetHost = host;
35
+ });
36
+ this.getTestnetHost = () => {
37
+ return this.store.testnetHost;
38
+ };
33
39
  this.ethRpc = () => __awaiter(this, void 0, void 0, function* () {
34
40
  throw ethErrors.provider.disconnected();
35
41
  });
36
42
  this.init = (hf) => __awaiter(this, void 0, void 0, function* () {
37
43
  var _e;
38
44
  yield sign.lW(hf);
39
- if (!process.env.DEBUG) {
40
- this.store.host = INITIAL_OPENAPI_URL;
41
- }
42
45
  const request = axios.create({
43
46
  baseURL: this.store.host,
44
47
  adapter: this.adapter,
@@ -80,6 +83,22 @@ export class OpenApiService {
80
83
  });
81
84
  this._mountMethods();
82
85
  });
86
+ this._getRequestOptions = (chainId) => {
87
+ if (!chainId) {
88
+ return;
89
+ }
90
+ const testnetHost = this.getTestnetHost();
91
+ if (!testnetHost) {
92
+ return;
93
+ }
94
+ const chain = getChain(chainId);
95
+ if (!(chain === null || chain === void 0 ? void 0 : chain.isTestnet)) {
96
+ return;
97
+ }
98
+ return {
99
+ baseURL: testnetHost,
100
+ };
101
+ };
83
102
  this._mountMethods = () => {
84
103
  this.ethRpc = (chain_id, { origin = 'rabby', method, params }) => {
85
104
  return this.request
@@ -87,7 +106,7 @@ export class OpenApiService {
87
106
  chain_id,
88
107
  method,
89
108
  params,
90
- })
109
+ }, this._getRequestOptions(chain_id))
91
110
  .then(({ data }) => {
92
111
  if (data === null || data === void 0 ? void 0 : data.error) {
93
112
  throw data.error;
@@ -137,35 +156,39 @@ export class OpenApiService {
137
156
  return data;
138
157
  });
139
158
  this.checkTx = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
159
+ var _f;
140
160
  const { data } = yield this.request.post('/v1/wallet/check_tx', {
141
161
  user_addr: address,
142
162
  origin,
143
163
  tx,
144
164
  update_nonce,
145
- });
165
+ }, this._getRequestOptions((_f = getChainByNetwork(tx.chainId)) === null || _f === void 0 ? void 0 : _f.serverId));
146
166
  return data;
147
167
  });
148
168
  this.preExecTx = ({ tx, origin, address, updateNonce = false, pending_tx_list = [], }) => __awaiter(this, void 0, void 0, function* () {
169
+ var _g;
149
170
  const { data } = yield this.request.post('/v1/wallet/pre_exec_tx', {
150
171
  tx,
151
172
  user_addr: address,
152
173
  origin,
153
174
  update_nonce: updateNonce,
154
175
  pending_tx_list,
155
- });
176
+ }, this._getRequestOptions((_g = getChainByNetwork(tx.chainId)) === null || _g === void 0 ? void 0 : _g.serverId));
156
177
  return data;
157
178
  });
158
179
  this.historyGasUsed = (params) => __awaiter(this, void 0, void 0, function* () {
159
- const { data } = yield this.request.post('/v1/wallet/history_tx_used_gas', Object.assign({}, params));
180
+ var _h, _j;
181
+ const { data } = yield this.request.post('/v1/wallet/history_tx_used_gas', Object.assign({}, params), this._getRequestOptions((_j = getChainByNetwork((_h = params === null || params === void 0 ? void 0 : params.tx) === null || _h === void 0 ? void 0 : _h.chainId)) === null || _j === void 0 ? void 0 : _j.serverId));
160
182
  return data;
161
183
  });
162
184
  this.pendingTxList = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
185
+ var _k;
163
186
  const { data } = yield this.request.post('/v1/wallet/pending_tx_list', {
164
187
  tx,
165
188
  user_addr: address,
166
189
  origin,
167
190
  update_nonce,
168
- });
191
+ }, this._getRequestOptions((_k = getChainByNetwork(tx.chainId)) === null || _k === void 0 ? void 0 : _k.serverId));
169
192
  return data;
170
193
  });
171
194
  this.traceTx = (txId, traceId, chainId) => __awaiter(this, void 0, void 0, function* () {
@@ -173,14 +196,15 @@ export class OpenApiService {
173
196
  tx_id: txId,
174
197
  trace_id: traceId,
175
198
  chain_id: chainId,
176
- });
199
+ }, this._getRequestOptions(chainId));
177
200
  return data;
178
201
  });
179
202
  this.pushTx = (tx, traceId) => __awaiter(this, void 0, void 0, function* () {
203
+ var _l;
180
204
  const { data } = yield this.request.post('/v1/wallet/push_tx', {
181
205
  tx,
182
206
  trace_id: traceId,
183
- });
207
+ }, this._getRequestOptions((_l = getChainByNetwork(tx.chainId)) === null || _l === void 0 ? void 0 : _l.serverId));
184
208
  return data;
185
209
  });
186
210
  this.explainText = (origin, address, text) => __awaiter(this, void 0, void 0, function* () {
@@ -192,22 +216,18 @@ export class OpenApiService {
192
216
  return data;
193
217
  });
194
218
  this.gasMarket = (chainId, customGas) => __awaiter(this, void 0, void 0, function* () {
195
- const { data } = yield this.request.get('/v1/wallet/gas_market', {
196
- params: {
219
+ const { data } = yield this.request.get('/v1/wallet/gas_market', Object.assign({ params: {
197
220
  chain_id: chainId,
198
221
  custom_price: customGas,
199
- },
200
- });
222
+ } }, this._getRequestOptions(chainId)));
201
223
  return data;
202
224
  });
203
225
  this.getTx = (chainId, hash, gasPrice) => __awaiter(this, void 0, void 0, function* () {
204
- const { data } = yield this.request.get('/v1/wallet/get_tx', {
205
- params: {
226
+ const { data } = yield this.request.get('/v1/wallet/get_tx', Object.assign({ params: {
206
227
  chain_id: chainId,
207
228
  gas_price: gasPrice,
208
229
  tx_id: hash,
209
- },
210
- });
230
+ } }, this._getRequestOptions(chainId)));
211
231
  return data;
212
232
  });
213
233
  this.getEnsAddressByName = (name) => __awaiter(this, void 0, void 0, function* () {
@@ -219,36 +239,30 @@ export class OpenApiService {
219
239
  return data;
220
240
  });
221
241
  this.searchToken = (id, q, chainId, is_all = false) => __awaiter(this, void 0, void 0, function* () {
222
- const { data } = yield this.request.get('/v1/user/token_search', {
223
- params: {
242
+ const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
224
243
  id,
225
244
  q,
226
245
  has_balance: false,
227
246
  is_all,
228
247
  chain_id: chainId,
229
- },
230
- });
248
+ } }, this._getRequestOptions(chainId)));
231
249
  return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
232
250
  });
233
251
  this.searchSwapToken = (id, chainId, q, is_all = false) => __awaiter(this, void 0, void 0, function* () {
234
- const { data } = yield this.request.get('/v1/user/token_search', {
235
- params: {
252
+ const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
236
253
  id,
237
254
  chain_id: chainId,
238
255
  q,
239
256
  is_all,
240
- },
241
- });
257
+ } }, this._getRequestOptions(chainId)));
242
258
  return data;
243
259
  });
244
260
  this.getToken = (id, chainId, tokenId) => __awaiter(this, void 0, void 0, function* () {
245
- const { data } = yield this.request.get('/v1/user/token', {
246
- params: {
261
+ const { data } = yield this.request.get('/v1/user/token', Object.assign({ params: {
247
262
  id,
248
263
  chain_id: chainId,
249
264
  token_id: tokenId,
250
- },
251
- });
265
+ } }, this._getRequestOptions(chainId)));
252
266
  return data;
253
267
  });
254
268
  this.getCachedTokenList = (id) => __awaiter(this, void 0, void 0, function* () {
@@ -260,33 +274,53 @@ export class OpenApiService {
260
274
  return data;
261
275
  });
262
276
  this.listToken = (id, chainId, isAll = false) => __awaiter(this, void 0, void 0, function* () {
263
- const { data } = yield this.request.get('/v1/user/token_list', {
264
- params: {
277
+ const { data } = yield this.request.get('/v1/user/token_list', Object.assign({ params: {
265
278
  id,
266
279
  is_all: isAll,
267
280
  chain_id: chainId,
268
- },
269
- });
281
+ } }, this._getRequestOptions(chainId)));
270
282
  return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
271
283
  });
272
284
  this.getHistoryTokenList = (params) => __awaiter(this, void 0, void 0, function* () {
273
- const { data } = yield this.request.get('/v1/user/history_token_list', {
274
- params: {
285
+ const { data } = yield this.request.get('/v1/user/history_token_list', Object.assign({ params: {
275
286
  id: params.id,
276
287
  chain_id: params.chainId,
277
288
  time_at: params.timeAt,
278
289
  date_at: params.dateAt,
279
- },
280
- });
290
+ } }, this._getRequestOptions(params.chainId)));
281
291
  return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
282
292
  });
283
- this.customListToken = (uuids, id) => __awaiter(this, void 0, void 0, function* () {
293
+ this._customListToken = (uuids, id, isTestnet = false) => __awaiter(this, void 0, void 0, function* () {
294
+ if (!(uuids === null || uuids === void 0 ? void 0 : uuids.length) || !id) {
295
+ return [];
296
+ }
284
297
  const { data } = yield this.request.post('/v1/user/specific_token_list', {
285
298
  id,
286
299
  uuids,
287
- });
300
+ }, isTestnet && this.store.testnetHost
301
+ ? { baseURL: this.store.testnetHost }
302
+ : undefined);
288
303
  return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
289
304
  });
305
+ this.customListToken = (uuids, id) => __awaiter(this, void 0, void 0, function* () {
306
+ const mainnetIds = [];
307
+ const testnetIds = [];
308
+ uuids.forEach((uuid) => {
309
+ const serverId = uuid.split(':')[0];
310
+ const chain = getChain(serverId);
311
+ if (chain === null || chain === void 0 ? void 0 : chain.isTestnet) {
312
+ testnetIds.push(uuid);
313
+ }
314
+ else {
315
+ mainnetIds.push(uuid);
316
+ }
317
+ });
318
+ const res = yield Promise.all([
319
+ this._customListToken(mainnetIds, id),
320
+ this._customListToken(testnetIds, id, true),
321
+ ]);
322
+ return res.flat();
323
+ });
290
324
  this.listChainAssets = (id) => __awaiter(this, void 0, void 0, function* () {
291
325
  const { data } = yield this.request.get('/v1/user/simple_protocol_list', {
292
326
  params: {
@@ -311,59 +345,46 @@ export class OpenApiService {
311
345
  return data;
312
346
  });
313
347
  this.listTxHisotry = (params) => __awaiter(this, void 0, void 0, function* () {
314
- const { data } = yield this.request.get('/v1/user/history_list', {
315
- params,
316
- });
348
+ const { data } = yield this.request.get('/v1/user/history_list', Object.assign({ params }, this._getRequestOptions(params.chain_id)));
317
349
  return data;
318
350
  });
319
351
  this.tokenPrice = (tokenName) => __awaiter(this, void 0, void 0, function* () {
320
- const { data } = yield this.request.get('/v1/token/price_change', {
321
- params: {
352
+ var _m;
353
+ const { data } = yield this.request.get('/v1/token/price_change', Object.assign({ params: {
322
354
  token: tokenName,
323
- },
324
- });
355
+ } }, this._getRequestOptions((_m = tokenName === null || tokenName === void 0 ? void 0 : tokenName.split(':')) === null || _m === void 0 ? void 0 : _m[0])));
325
356
  return data;
326
357
  });
327
358
  this.tokenAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
328
- const { data } = yield this.request.get('/v1/user/token_authorized_list', {
329
- params: {
359
+ const { data } = yield this.request.get('/v1/user/token_authorized_list', Object.assign({ params: {
330
360
  id,
331
361
  chain_id,
332
- },
333
- });
362
+ } }, this._getRequestOptions(chain_id)));
334
363
  return data;
335
364
  });
336
365
  this.userNFTAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
337
- const { data } = yield this.request.get('/v1/user/nft_authorized_list', {
338
- params: {
366
+ const { data } = yield this.request.get('/v1/user/nft_authorized_list', Object.assign({ params: {
339
367
  id,
340
368
  chain_id,
341
- },
342
- });
369
+ } }, this._getRequestOptions(chain_id)));
343
370
  return data;
344
371
  });
345
372
  this.getDEXList = (chain_id) => __awaiter(this, void 0, void 0, function* () {
346
- const { data } = yield this.request.get('/v1/wallet/swap_dex_list', {
347
- params: {
373
+ const { data } = yield this.request.get('/v1/wallet/swap_dex_list', Object.assign({ params: {
348
374
  chain_id,
349
- },
350
- });
375
+ } }, this._getRequestOptions(chain_id)));
351
376
  return data;
352
377
  });
353
378
  this.getSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
354
- const { data } = yield this.request.get('/v1/wallet/swap_quote', {
355
- params,
356
- });
379
+ const { data } = yield this.request.get('/v1/wallet/swap_quote', Object.assign({ params }, this._getRequestOptions(params === null || params === void 0 ? void 0 : params.chain_id)));
357
380
  return data;
358
381
  });
359
382
  this.getSwapTokenList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
360
- const { data } = yield this.request.get('/v1/wallet/swap_token_list', {
361
- params: {
383
+ const { data } = yield this.request.get('/v1/wallet/swap_token_list', Object.assign({ params: {
362
384
  id,
363
385
  chain_id: chainId,
364
386
  is_all: false,
365
- },
366
- });
387
+ } }, this._getRequestOptions(chainId)));
367
388
  return data;
368
389
  });
369
390
  this.postGasStationOrder = (params) => __awaiter(this, void 0, void 0, function* () {
@@ -378,16 +399,14 @@ export class OpenApiService {
378
399
  to_token_amount: params.toTokenAmount,
379
400
  from_usd_value: params.fromUsdValue,
380
401
  },
381
- });
402
+ }, this._getRequestOptions(params.fromChainId));
382
403
  return data;
383
404
  });
384
405
  this.getGasStationChainBalance = (chain_id, addr) => __awaiter(this, void 0, void 0, function* () {
385
- const { data } = yield this.request.get('/v1/wallet/gas_station_usd_value', {
386
- params: {
406
+ const { data } = yield this.request.get('/v1/wallet/gas_station_usd_value', Object.assign({ params: {
387
407
  chain_id,
388
408
  addr,
389
- },
390
- });
409
+ } }, this._getRequestOptions(chain_id)));
391
410
  return data;
392
411
  });
393
412
  this.getGasStationTokenList = () => __awaiter(this, void 0, void 0, function* () {
@@ -475,23 +494,19 @@ export class OpenApiService {
475
494
  return data;
476
495
  });
477
496
  this.getTokenHistoryPrice = ({ chainId, id, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
478
- const { data } = yield this.request.get('/v1/token/history_price', {
479
- params: {
497
+ const { data } = yield this.request.get('/v1/token/history_price', Object.assign({ params: {
480
498
  chain_id: chainId,
481
499
  id,
482
500
  time_at: timeAt,
483
- },
484
- });
501
+ } }, this._getRequestOptions(chainId)));
485
502
  return data;
486
503
  });
487
504
  this.getTokenHistoryDict = ({ chainId, ids, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
488
- const { data } = yield this.request.get('/v1/token/history_price_dict', {
489
- params: {
505
+ const { data } = yield this.request.get('/v1/token/history_price_dict', Object.assign({ params: {
490
506
  chain_id: chainId,
491
507
  ids,
492
508
  time_at: timeAt,
493
- },
494
- });
509
+ } }, this._getRequestOptions(chainId)));
495
510
  return data;
496
511
  });
497
512
  this.getNetCurve = (addr) => __awaiter(this, void 0, void 0, function* () {
@@ -507,9 +522,7 @@ export class OpenApiService {
507
522
  return data;
508
523
  });
509
524
  this.getCEXSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
510
- const { data } = yield this.request.get('/v1/wallet/cex_swap_quote', {
511
- params,
512
- });
525
+ const { data } = yield this.request.get('/v1/wallet/cex_swap_quote', Object.assign({ params }, this._getRequestOptions(params === null || params === void 0 ? void 0 : params.chain_id)));
513
526
  return data;
514
527
  });
515
528
  this.getSwapTradeList = (params) => __awaiter(this, void 0, void 0, function* () {
@@ -519,13 +532,12 @@ export class OpenApiService {
519
532
  return data;
520
533
  });
521
534
  this.postSwap = (params) => __awaiter(this, void 0, void 0, function* () {
522
- const { data } = yield this.request.post('/v1/wallet/swap_trade', params);
535
+ var _o, _p;
536
+ const { data } = yield this.request.post('/v1/wallet/swap_trade', params, this._getRequestOptions((_p = getChainByNetwork((_o = params === null || params === void 0 ? void 0 : params.tx) === null || _o === void 0 ? void 0 : _o.chainId)) === null || _p === void 0 ? void 0 : _p.serverId));
523
537
  return data;
524
538
  });
525
539
  this.checkSlippage = (params) => __awaiter(this, void 0, void 0, function* () {
526
- const { data } = yield this.request.get('/v1/wallet/check_slippage', {
527
- params,
528
- });
540
+ const { data } = yield this.request.get('/v1/wallet/check_slippage', Object.assign({ params }, this._getRequestOptions(params === null || params === void 0 ? void 0 : params.chain_id)));
529
541
  return data;
530
542
  });
531
543
  this.getOriginPopularityLevel = (origin) => __awaiter(this, void 0, void 0, function* () {
@@ -554,12 +566,10 @@ export class OpenApiService {
554
566
  return data;
555
567
  });
556
568
  this.getSummarizedAssetList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
557
- const { data } = yield this.request.get('/v1/user/summarized_asset_list', {
558
- params: {
569
+ const { data } = yield this.request.get('/v1/user/summarized_asset_list', Object.assign({ params: {
559
570
  id,
560
571
  chain_id,
561
- },
562
- });
572
+ } }, this._getRequestOptions(chain_id)));
563
573
  return data;
564
574
  });
565
575
  this.parseTx = ({ chainId, tx, origin, addr, }) => __awaiter(this, void 0, void 0, function* () {
@@ -568,67 +578,55 @@ export class OpenApiService {
568
578
  tx,
569
579
  origin,
570
580
  user_addr: addr,
571
- });
581
+ }, this._getRequestOptions(chainId));
572
582
  return data;
573
583
  });
574
584
  this.isSuspiciousToken = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
575
- const { data } = yield this.request.get('/v1/engine/token/is_suspicious', {
576
- params: {
585
+ const { data } = yield this.request.get('/v1/engine/token/is_suspicious', Object.assign({ params: {
577
586
  chain_id: chainId,
578
587
  id,
579
- },
580
- });
588
+ } }, this._getRequestOptions(chainId)));
581
589
  return data;
582
590
  });
583
591
  this.depositCexSupport = (id, chainId, cexId) => __awaiter(this, void 0, void 0, function* () {
584
- const { data } = yield this.request.get('/v1/engine/token/deposit_cex_support', {
585
- params: {
592
+ const { data } = yield this.request.get('/v1/engine/token/deposit_cex_support', Object.assign({ params: {
586
593
  chain_id: chainId,
587
594
  id,
588
595
  cex_id: cexId,
589
- },
590
- });
596
+ } }, this._getRequestOptions(chainId)));
591
597
  return data;
592
598
  });
593
599
  // Token 可充值的 CEX 列表
594
600
  this.depositCexList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
595
- const { data } = yield this.request.get('/v1/engine/token/deposit_cex_list', {
596
- params: {
601
+ const { data } = yield this.request.get('/v1/engine/token/deposit_cex_list', Object.assign({ params: {
597
602
  chain_id: chainId,
598
603
  id,
599
- },
600
- });
604
+ } }, this._getRequestOptions(chainId)));
601
605
  return data;
602
606
  });
603
607
  // 合约信用分
604
608
  this.getContractCredit = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
605
- const { data } = yield this.request.get('/v1/engine/contract/credit', {
606
- params: {
609
+ const { data } = yield this.request.get('/v1/engine/contract/credit', Object.assign({ params: {
607
610
  chain_id: chainId,
608
611
  id,
609
- },
610
- });
612
+ } }, this._getRequestOptions(chainId)));
611
613
  return data;
612
614
  });
613
615
  // 是否跟地址交互过
614
616
  this.hasInteraction = (addr, chainId, contractId) => __awaiter(this, void 0, void 0, function* () {
615
- const { data } = yield this.request.get('/v1/engine/contract/has_interaction', {
616
- params: {
617
+ const { data } = yield this.request.get('/v1/engine/contract/has_interaction', Object.assign({ params: {
617
618
  chain_id: chainId,
618
619
  user_addr: addr,
619
620
  contract_id: contractId,
620
- },
621
- });
621
+ } }, this._getRequestOptions(chainId)));
622
622
  return data;
623
623
  });
624
624
  // 授权风险敞口
625
625
  this.tokenApproveExposure = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
626
- const { data } = yield this.request.get('/v1/engine/contract/token_approval_exposure', {
627
- params: {
626
+ const { data } = yield this.request.get('/v1/engine/contract/token_approval_exposure', Object.assign({ params: {
628
627
  chain_id: chainId,
629
628
  id,
630
- },
631
- });
629
+ } }, this._getRequestOptions(chainId)));
632
630
  return data;
633
631
  });
634
632
  // 地址描述
@@ -642,22 +640,18 @@ export class OpenApiService {
642
640
  });
643
641
  // 两个地址是否发生过转账
644
642
  this.hasTransfer = (chainId, from, to) => __awaiter(this, void 0, void 0, function* () {
645
- const { data } = yield this.request.get('/v1/engine/addr/has_transfer', {
646
- params: {
643
+ const { data } = yield this.request.get('/v1/engine/addr/has_transfer', Object.assign({ params: {
647
644
  chain_id: chainId,
648
645
  from_addr: from,
649
646
  to_addr: to,
650
- },
651
- });
647
+ } }, this._getRequestOptions(chainId)));
652
648
  return data;
653
649
  });
654
650
  this.isTokenContract = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
655
- const { data } = yield this.request.get('/v1/engine/contract/is_token', {
656
- params: {
651
+ const { data } = yield this.request.get('/v1/engine/contract/is_token', Object.assign({ params: {
657
652
  id,
658
653
  chain_id: chainId,
659
- },
660
- });
654
+ } }, this._getRequestOptions(chainId)));
661
655
  return data;
662
656
  });
663
657
  this.addrUsedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
@@ -667,21 +661,15 @@ export class OpenApiService {
667
661
  return data;
668
662
  });
669
663
  this.getTokenNFTExposure = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
670
- const { data } = yield this.request.get('/v1/engine/contract/top_nft_approval_exposure', {
671
- params: { chain_id: chainId, id },
672
- });
664
+ const { data } = yield this.request.get('/v1/engine/contract/top_nft_approval_exposure', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
673
665
  return data;
674
666
  });
675
667
  this.getCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
676
- const { data } = yield this.request.get('/v1/engine/collection', {
677
- params: { chain_id: chainId, id },
678
- });
668
+ const { data } = yield this.request.get('/v1/engine/collection', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
679
669
  return data;
680
670
  });
681
671
  this.isSuspiciousCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
682
- const { data } = yield this.request.get('/v1/engine/collection/is_suspicious', {
683
- params: { chain_id: chainId, id },
684
- });
672
+ const { data } = yield this.request.get('/v1/engine/collection/is_suspicious', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
685
673
  return data;
686
674
  });
687
675
  this.isOriginVerified = (origin) => __awaiter(this, void 0, void 0, function* () {
@@ -707,21 +695,17 @@ export class OpenApiService {
707
695
  return data;
708
696
  });
709
697
  this.collectionList = ({ id, chainId, isAll, }) => __awaiter(this, void 0, void 0, function* () {
710
- const { data } = yield this.request.get('/v1/user/collection_list', {
711
- params: {
698
+ const { data } = yield this.request.get('/v1/user/collection_list', Object.assign({ params: {
712
699
  id,
713
700
  chain_id: chainId,
714
701
  is_all: isAll,
715
- },
716
- });
702
+ } }, this._getRequestOptions(chainId)));
717
703
  return data;
718
704
  });
719
705
  this.gasPriceStats = (chainId) => __awaiter(this, void 0, void 0, function* () {
720
- const { data } = yield this.request.get('/v1/wallet/gas_price_stats', {
721
- params: {
706
+ const { data } = yield this.request.get('/v1/wallet/gas_price_stats', Object.assign({ params: {
722
707
  chain_id: chainId,
723
- },
724
- });
708
+ } }, this._getRequestOptions(chainId)));
725
709
  return data;
726
710
  });
727
711
  this.store = store;
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { CHAINS } from '@debank/common';
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  export declare const getChain: (chainId?: string) => import("@debank/common").Chain | null;
4
+ export declare const getChainByNetwork: (network?: string | number) => import("@debank/common").Chain | null;
4
5
  export declare const INITIAL_OPENAPI_URL = "https://api.rabby.io";
6
+ export declare const INITIAL_TESTNET_OPENAPI_URL = "https://api.testnet.rabby.io/";
5
7
  export { CHAINS };
6
8
  export declare const SIGN_HDS: readonly ["x-api-ts", "x-api-nonce", "x-api-ver", "x-api-sign"];
7
9
  export declare function genSignParams(config: AxiosRequestConfig): {
package/dist/utils.js CHANGED
@@ -8,7 +8,16 @@ export const getChain = (chainId) => {
8
8
  }
9
9
  return chainsDict[chainId];
10
10
  };
11
+ const chainNetworkDict = keyBy(CHAINS, 'network');
12
+ export const getChainByNetwork = (network) => {
13
+ if (!network) {
14
+ return null;
15
+ }
16
+ network = network.toString();
17
+ return chainNetworkDict[network.startsWith('0x') ? +network : network];
18
+ };
11
19
  export const INITIAL_OPENAPI_URL = 'https://api.rabby.io';
20
+ export const INITIAL_TESTNET_OPENAPI_URL = 'https://api.testnet.rabby.io/';
12
21
  export { CHAINS };
13
22
  export const SIGN_HDS = [
14
23
  'x-api-ts',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-api",
3
- "version": "0.6.16",
3
+ "version": "0.6.17",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@babel/preset-env": "^7.19.1",
21
- "@debank/common": "^0.3.5",
21
+ "@debank/common": "^0.3.9",
22
22
  "@types/jest": "^29.0.3",
23
23
  "@types/lodash": "^4.14.185",
24
24
  "@types/node": "^18.7.18",
@@ -43,7 +43,7 @@
43
43
  "prepare": "husky install"
44
44
  },
45
45
  "peerDependencies": {
46
- "@debank/common": "^0.3.5"
46
+ "@debank/common": "^0.3.9"
47
47
  },
48
48
  "author": "",
49
49
  "description": "",