@rabby-wallet/rabby-api 0.6.15-alpha.0 → 0.6.15-alpha.2
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 +1 -0
- package/dist/index.js +39 -14
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +8 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export declare class OpenApiService {
|
|
|
71
71
|
timeAt?: number;
|
|
72
72
|
dateAt?: string;
|
|
73
73
|
}) => Promise<TokenItem[]>;
|
|
74
|
+
_customListToken: (uuids: string[], id: string, isTestnet?: boolean) => Promise<TokenItem[]>;
|
|
74
75
|
customListToken: (uuids: string[], id: string) => Promise<TokenItem[]>;
|
|
75
76
|
listChainAssets: (id: string) => Promise<AssetItem[]>;
|
|
76
77
|
listNFT: (id: string, isAll?: boolean) => Promise<NFTItem[]>;
|
package/dist/index.js
CHANGED
|
@@ -10,9 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import axios from 'axios';
|
|
11
11
|
import rateLimit from 'axios-rate-limit';
|
|
12
12
|
import { ethErrors } from 'eth-rpc-errors';
|
|
13
|
-
import { getChain, INITIAL_OPENAPI_URL, CHAINS, SIGN_HDS, genSignParams, INITIAL_TESTNET_OPENAPI_URL, } from './utils';
|
|
13
|
+
import { getChain, INITIAL_OPENAPI_URL, CHAINS, SIGN_HDS, genSignParams, INITIAL_TESTNET_OPENAPI_URL, getChainByNetwork, } from './utils';
|
|
14
14
|
import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
|
|
15
|
-
import { TESTNET_CHAINS_LIST } from '@debank/common';
|
|
16
15
|
const maxRPS = 500;
|
|
17
16
|
export class OpenApiService {
|
|
18
17
|
constructor({ store, adapter }) {
|
|
@@ -161,35 +160,39 @@ export class OpenApiService {
|
|
|
161
160
|
return data;
|
|
162
161
|
});
|
|
163
162
|
this.checkTx = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
var _f;
|
|
164
164
|
const { data } = yield this.request.post('/v1/wallet/check_tx', {
|
|
165
165
|
user_addr: address,
|
|
166
166
|
origin,
|
|
167
167
|
tx,
|
|
168
168
|
update_nonce,
|
|
169
|
-
});
|
|
169
|
+
}, this._getRequestOptions((_f = getChainByNetwork(tx.chainId)) === null || _f === void 0 ? void 0 : _f.serverId));
|
|
170
170
|
return data;
|
|
171
171
|
});
|
|
172
172
|
this.preExecTx = ({ tx, origin, address, updateNonce = false, pending_tx_list = [], }) => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
var _g;
|
|
173
174
|
const { data } = yield this.request.post('/v1/wallet/pre_exec_tx', {
|
|
174
175
|
tx,
|
|
175
176
|
user_addr: address,
|
|
176
177
|
origin,
|
|
177
178
|
update_nonce: updateNonce,
|
|
178
179
|
pending_tx_list,
|
|
179
|
-
});
|
|
180
|
+
}, this._getRequestOptions((_g = getChainByNetwork(tx.chainId)) === null || _g === void 0 ? void 0 : _g.serverId));
|
|
180
181
|
return data;
|
|
181
182
|
});
|
|
182
183
|
this.historyGasUsed = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
|
|
184
|
+
var _h, _j;
|
|
185
|
+
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));
|
|
184
186
|
return data;
|
|
185
187
|
});
|
|
186
188
|
this.pendingTxList = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
var _k;
|
|
187
190
|
const { data } = yield this.request.post('/v1/wallet/pending_tx_list', {
|
|
188
191
|
tx,
|
|
189
192
|
user_addr: address,
|
|
190
193
|
origin,
|
|
191
194
|
update_nonce,
|
|
192
|
-
});
|
|
195
|
+
}, this._getRequestOptions((_k = getChainByNetwork(tx.chainId)) === null || _k === void 0 ? void 0 : _k.serverId));
|
|
193
196
|
return data;
|
|
194
197
|
});
|
|
195
198
|
this.traceTx = (txId, traceId, chainId) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -201,11 +204,11 @@ export class OpenApiService {
|
|
|
201
204
|
return data;
|
|
202
205
|
});
|
|
203
206
|
this.pushTx = (tx, traceId) => __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
|
|
207
|
+
var _l;
|
|
205
208
|
const { data } = yield this.request.post('/v1/wallet/push_tx', {
|
|
206
209
|
tx,
|
|
207
210
|
trace_id: traceId,
|
|
208
|
-
}, this._getRequestOptions(
|
|
211
|
+
}, this._getRequestOptions((_l = getChainByNetwork(tx.chainId)) === null || _l === void 0 ? void 0 : _l.serverId));
|
|
209
212
|
return data;
|
|
210
213
|
});
|
|
211
214
|
this.explainText = (origin, address, text) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -291,16 +294,37 @@ export class OpenApiService {
|
|
|
291
294
|
} }, this._getRequestOptions(params.chainId)));
|
|
292
295
|
return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
|
|
293
296
|
});
|
|
294
|
-
this.
|
|
295
|
-
|
|
296
|
-
return
|
|
297
|
-
}
|
|
297
|
+
this._customListToken = (uuids, id, isTestnet = false) => __awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
if ((uuids === null || uuids === void 0 ? void 0 : uuids.length) || !id) {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
298
301
|
const { data } = yield this.request.post('/v1/user/specific_token_list', {
|
|
299
302
|
id,
|
|
300
303
|
uuids,
|
|
301
|
-
},
|
|
304
|
+
}, isTestnet && this.store.testnetHost
|
|
305
|
+
? { baseURL: this.store.testnetHost }
|
|
306
|
+
: undefined);
|
|
302
307
|
return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
|
|
303
308
|
});
|
|
309
|
+
this.customListToken = (uuids, id) => __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
const mainnetIds = [];
|
|
311
|
+
const testnetIds = [];
|
|
312
|
+
uuids.forEach((uuid) => {
|
|
313
|
+
const serverId = uuid.split(':')[0];
|
|
314
|
+
const chain = getChain(serverId);
|
|
315
|
+
if (chain === null || chain === void 0 ? void 0 : chain.isTestnet) {
|
|
316
|
+
testnetIds.push(uuid);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
mainnetIds.push(uuid);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
const res = yield Promise.all([
|
|
323
|
+
this._customListToken(mainnetIds, id),
|
|
324
|
+
this._customListToken(testnetIds, id, true),
|
|
325
|
+
]);
|
|
326
|
+
return res.flat();
|
|
327
|
+
});
|
|
304
328
|
this.listChainAssets = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
305
329
|
const { data } = yield this.request.get('/v1/user/simple_protocol_list', {
|
|
306
330
|
params: {
|
|
@@ -513,7 +537,8 @@ export class OpenApiService {
|
|
|
513
537
|
return data;
|
|
514
538
|
});
|
|
515
539
|
this.postSwap = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
516
|
-
|
|
540
|
+
var _m, _o;
|
|
541
|
+
const { data } = yield this.request.post('/v1/wallet/swap_trade', params, this._getRequestOptions((_o = getChainByNetwork((_m = params === null || params === void 0 ? void 0 : params.tx) === null || _m === void 0 ? void 0 : _m.chainId)) === null || _o === void 0 ? void 0 : _o.serverId));
|
|
517
542
|
return data;
|
|
518
543
|
});
|
|
519
544
|
this.checkSlippage = (params) => __awaiter(this, void 0, void 0, function* () {
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
5
6
|
export declare const INITIAL_TESTNET_OPENAPI_URL = "https://api.testnet.rabby.io/";
|
|
6
7
|
export { CHAINS };
|
package/dist/utils.js
CHANGED
|
@@ -8,6 +8,14 @@ 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';
|
|
12
20
|
export const INITIAL_TESTNET_OPENAPI_URL = 'https://api.testnet.rabby.io/';
|
|
13
21
|
export { CHAINS };
|