@rabby-wallet/rabby-api 0.6.23 → 0.6.24
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/const.d.ts +2 -0
- package/dist/const.js +2 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +20 -1
- package/dist/types.d.ts +17 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +17 -0
- package/package.json +1 -1
package/dist/const.d.ts
ADDED
package/dist/const.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AxiosAdapter } from 'axios';
|
|
1
|
+
import { AxiosAdapter, AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { RateLimitedAxiosInstance } from 'axios-rate-limit';
|
|
3
|
-
import { AddrDescResponse, ApprovalStatus, AssetItem, CEXQuote, Cex, ChainWithPendingCount, Collection, CollectionList, CollectionWithFloorPrice, ComplexProtocol, ContractCredit, ExplainTxResponse, ExplainTypedDataResponse, GasLevel, GetTxResponse, MempoolCheckDetail, NFTApprovalResponse, NFTItem, ParseTextResponse, ParseTxResponse, ParseTypedDataResponse, Protocol, SecurityCheckResponse, ServerChain, SlippageStatus, Summary, SwapTradeList, TokenApproval, TokenItem, TotalBalanceResponse, Tx, TxHistoryResult, TxPushType, TxRequest, UsedChain } from './types';
|
|
3
|
+
import { AddrDescResponse, ApprovalStatus, AssetItem, CEXQuote, Cex, ChainWithPendingCount, Collection, CollectionList, CollectionWithFloorPrice, ComplexProtocol, ContractCredit, ExplainTxResponse, ExplainTypedDataResponse, GasLevel, GetTxResponse, MempoolCheckDetail, NFTApprovalResponse, NFTItem, ParseTextResponse, ParseTxResponse, ParseTypedDataResponse, Protocol, SecurityCheckResponse, ServerChain, SlippageStatus, Summary, SwapTradeList, TokenApproval, TokenItem, TotalBalanceResponse, Tx, TxAllHistoryResult, TxHistoryResult, TxPushType, TxRequest, UsedChain } from './types';
|
|
4
4
|
interface OpenApiStore {
|
|
5
5
|
host: string;
|
|
6
6
|
testnetHost?: string;
|
|
@@ -24,6 +24,9 @@ export declare class OpenApiService {
|
|
|
24
24
|
adapter?: AxiosAdapter;
|
|
25
25
|
constructor({ store, adapter }: Options);
|
|
26
26
|
init: (hf?: string) => Promise<void>;
|
|
27
|
+
asyncJob: <T = any>(url: string, options?: AxiosRequestConfig & {
|
|
28
|
+
retryDelay?: number;
|
|
29
|
+
}) => Promise<T>;
|
|
27
30
|
private _getRequestOptions;
|
|
28
31
|
private _mountMethods;
|
|
29
32
|
getRecommendChains: (address: string, origin: string) => Promise<ServerChain[]>;
|
|
@@ -86,6 +89,10 @@ export declare class OpenApiService {
|
|
|
86
89
|
start_time?: number;
|
|
87
90
|
page_count?: number;
|
|
88
91
|
}) => Promise<TxHistoryResult>;
|
|
92
|
+
getAllTxHistory: (params: {
|
|
93
|
+
id: string;
|
|
94
|
+
start_time?: number;
|
|
95
|
+
}, options?: Parameters<typeof this.asyncJob>[1]) => Promise<TxAllHistoryResult>;
|
|
89
96
|
tokenPrice: (tokenName: string) => Promise<{
|
|
90
97
|
change_percent: number;
|
|
91
98
|
last_price: number;
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,9 @@ import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
|
|
|
11
11
|
import axios from 'axios';
|
|
12
12
|
import rateLimit from 'axios-rate-limit';
|
|
13
13
|
import { ethErrors } from 'eth-rpc-errors';
|
|
14
|
-
import { CHAINS, SIGN_HDS, genSignParams, getChain, getChainByNetwork, } from './utils';
|
|
14
|
+
import { CHAINS, SIGN_HDS, genSignParams, getChain, getChainByNetwork, sleep, } from './utils';
|
|
15
|
+
import { ASYNC_JOB_RETRY_DELAY, ASYNC_JOB_TIMEOUT } from './const';
|
|
16
|
+
import { omit } from 'lodash';
|
|
15
17
|
const maxRPS = 500;
|
|
16
18
|
export class OpenApiService {
|
|
17
19
|
constructor({ store, adapter }) {
|
|
@@ -83,6 +85,19 @@ export class OpenApiService {
|
|
|
83
85
|
});
|
|
84
86
|
this._mountMethods();
|
|
85
87
|
});
|
|
88
|
+
this.asyncJob = (url, options) => {
|
|
89
|
+
const _option = Object.assign({ timeout: ASYNC_JOB_TIMEOUT, retryDelay: ASYNC_JOB_RETRY_DELAY }, options);
|
|
90
|
+
const startTime = +new Date();
|
|
91
|
+
return this.request(url, omit(Object.assign({ method: 'GET' }, _option), 'retryDelay')).then((res) => {
|
|
92
|
+
const data = res.data;
|
|
93
|
+
if (data.result) {
|
|
94
|
+
return data.result.data;
|
|
95
|
+
}
|
|
96
|
+
const deltaTime = +new Date() - startTime;
|
|
97
|
+
_option.timeout = _option.timeout - deltaTime - _option.retryDelay;
|
|
98
|
+
return sleep(_option.retryDelay, _option.signal).then(() => this.asyncJob(url, _option));
|
|
99
|
+
});
|
|
100
|
+
};
|
|
86
101
|
this._getRequestOptions = (chainId) => {
|
|
87
102
|
if (!chainId) {
|
|
88
103
|
return;
|
|
@@ -348,6 +363,10 @@ export class OpenApiService {
|
|
|
348
363
|
const { data } = yield this.request.get('/v1/user/history_list', Object.assign({ params }, this._getRequestOptions(params.chain_id)));
|
|
349
364
|
return data;
|
|
350
365
|
});
|
|
366
|
+
this.getAllTxHistory = (params, options) => __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
const data = yield this.asyncJob('/v1/user/history_all_list', Object.assign({ method: 'GET', params }, options));
|
|
368
|
+
return data;
|
|
369
|
+
});
|
|
351
370
|
this.tokenPrice = (tokenName) => __awaiter(this, void 0, void 0, function* () {
|
|
352
371
|
var _m;
|
|
353
372
|
const { data } = yield this.request.get('/v1/token/price_change', Object.assign({ params: {
|
package/dist/types.d.ts
CHANGED
|
@@ -357,6 +357,9 @@ export interface TxHistoryResult {
|
|
|
357
357
|
}>;
|
|
358
358
|
token_dict: Record<string, TokenItem>;
|
|
359
359
|
}
|
|
360
|
+
export interface TxAllHistoryResult extends Omit<TxHistoryResult, 'token_dict'> {
|
|
361
|
+
token_uuid_dict: Record<string, TokenItem>;
|
|
362
|
+
}
|
|
360
363
|
export interface GasResult {
|
|
361
364
|
estimated_gas_cost_usd_value: number;
|
|
362
365
|
estimated_gas_cost_value: number;
|
|
@@ -993,4 +996,18 @@ export interface MempoolCheckDetail {
|
|
|
993
996
|
check_success: boolean;
|
|
994
997
|
rpc: string;
|
|
995
998
|
}
|
|
999
|
+
export interface JobResponse<T = any> {
|
|
1000
|
+
create_at: number;
|
|
1001
|
+
id: string;
|
|
1002
|
+
result: {
|
|
1003
|
+
create_at: number;
|
|
1004
|
+
id: string;
|
|
1005
|
+
data: T;
|
|
1006
|
+
};
|
|
1007
|
+
job: {
|
|
1008
|
+
create_at: number;
|
|
1009
|
+
id: string;
|
|
1010
|
+
status: 'pending' | 'running';
|
|
1011
|
+
} | null;
|
|
1012
|
+
}
|
|
996
1013
|
export {};
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -42,3 +42,20 @@ export function genSignParams(config) {
|
|
|
42
42
|
params,
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
export function sleep(ms = 0, signal) {
|
|
46
|
+
if ((signal === null || signal === void 0 ? void 0 : signal.aborted) || ms < 0) {
|
|
47
|
+
return Promise.reject(new DOMException('Aborted', 'AbortError'));
|
|
48
|
+
}
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
const abortHandler = () => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
reject(new DOMException('Aborted', 'AbortError'));
|
|
53
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', abortHandler);
|
|
54
|
+
};
|
|
55
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', abortHandler);
|
|
56
|
+
const timer = setTimeout(() => {
|
|
57
|
+
resolve();
|
|
58
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', abortHandler);
|
|
59
|
+
}, ms);
|
|
60
|
+
});
|
|
61
|
+
}
|