@rabby-wallet/rabby-api 0.9.45-beta.1 → 0.9.47

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
@@ -5,6 +5,8 @@ import { AddrDescResponse, BridgeAggregator, ApprovalStatus, AssetItem, BasicDap
5
5
  interface OpenApiStore {
6
6
  host: string;
7
7
  testnetHost?: string;
8
+ apiKey: string | null;
9
+ apiTime: number | null;
8
10
  }
9
11
  interface Options {
10
12
  store: OpenApiStore | Promise<OpenApiStore>;
@@ -28,6 +30,9 @@ export declare class OpenApiService {
28
30
  constructor({ store, plugin, adapter, clientName, clientVersion, }: Options);
29
31
  setHost: (host: string) => Promise<void>;
30
32
  setHostSync: (host: string) => void;
33
+ setAPIKey: (apiKey: string) => Promise<void>;
34
+ setAPITime: (apiTime: number) => Promise<void>;
35
+ removeAPIKey: () => Promise<void>;
31
36
  getHost: () => string;
32
37
  setTestnetHost: (host: string) => Promise<void>;
33
38
  getTestnetHost: () => string | undefined;
@@ -52,6 +57,9 @@ export declare class OpenApiService {
52
57
  excluded_protocol_ids: string[];
53
58
  excluded_chain_ids: string[];
54
59
  }) => Promise<TotalBalanceResponse>;
60
+ get24hTotalBalance: (address: string) => Promise<{
61
+ total_usd_value: number;
62
+ }>;
55
63
  getPendingCount: (address: string) => Promise<{
56
64
  total_count: number;
57
65
  chains: ChainWithPendingCount[];
@@ -108,6 +116,12 @@ export declare class OpenApiService {
108
116
  listCollection: (params: {
109
117
  collection_ids: string;
110
118
  }) => Promise<Collection[]>;
119
+ hasNewTxFrom: (params: {
120
+ address: string;
121
+ startTime: number;
122
+ }) => Promise<{
123
+ has_new_tx: boolean;
124
+ }>;
111
125
  listTxHisotry: (params: {
112
126
  id?: string;
113
127
  chain_id?: string;
package/dist/index.js CHANGED
@@ -58,6 +58,19 @@ export class OpenApiService {
58
58
  this.store.host = host;
59
59
  this.initSync();
60
60
  };
61
+ this.setAPIKey = (apiKey) => __awaiter(this, void 0, void 0, function* () {
62
+ this.store.apiKey = apiKey;
63
+ yield this.init();
64
+ });
65
+ this.setAPITime = (apiTime) => __awaiter(this, void 0, void 0, function* () {
66
+ this.store.apiTime = apiTime;
67
+ yield this.init();
68
+ });
69
+ this.removeAPIKey = () => __awaiter(this, void 0, void 0, function* () {
70
+ this.store.apiKey = null;
71
+ this.store.apiTime = null;
72
+ yield this.init();
73
+ });
61
74
  this.getHost = () => {
62
75
  return this.store.host;
63
76
  };
@@ -134,6 +147,14 @@ export class OpenApiService {
134
147
  });
135
148
  return data;
136
149
  });
150
+ this.get24hTotalBalance = (address) => __awaiter(this, void 0, void 0, function* () {
151
+ const { data } = yield this.request.get('/v1/user/total_balance_24h', {
152
+ params: {
153
+ id: address,
154
+ },
155
+ });
156
+ return data;
157
+ });
137
158
  this.getPendingCount = (address) => __awaiter(this, void 0, void 0, function* () {
138
159
  const { data } = yield this.request.get('/v1/wallet/pending_tx_count', {
139
160
  params: {
@@ -356,6 +377,15 @@ export class OpenApiService {
356
377
  });
357
378
  return data;
358
379
  });
380
+ this.hasNewTxFrom = (params) => __awaiter(this, void 0, void 0, function* () {
381
+ const { data } = yield this.request.get('/v1/user/has_new_tx', {
382
+ params: {
383
+ id: params.address,
384
+ start_time: params.startTime,
385
+ },
386
+ });
387
+ return data;
388
+ });
359
389
  this.listTxHisotry = (params) => __awaiter(this, void 0, void 0, function* () {
360
390
  const { data } = yield this.request.get('/v1/user/history_list', {
361
391
  params,
@@ -1763,13 +1793,18 @@ export class OpenApiService {
1763
1793
  initSync(options) {
1764
1794
  var _a, _b;
1765
1795
  (_b = (_a = __classPrivateFieldGet(this, _OpenApiService_plugin, "f")).onInitiate) === null || _b === void 0 ? void 0 : _b.call(_a, Object.assign({}, options));
1796
+ const headers = {
1797
+ 'X-Client': __classPrivateFieldGet(this, _OpenApiService_clientName, "f"),
1798
+ 'X-Version': __classPrivateFieldGet(this, _OpenApiService_clientVersion, "f"),
1799
+ };
1800
+ if (this.store.apiKey && this.store.apiTime) {
1801
+ headers['X-API-Key'] = this.store.apiKey;
1802
+ headers['X-API-Time'] = this.store.apiTime;
1803
+ }
1766
1804
  const request = axios.create({
1767
1805
  baseURL: this.store.host,
1768
1806
  adapter: __classPrivateFieldGet(this, _OpenApiService_adapter, "f"),
1769
- headers: {
1770
- 'X-Client': __classPrivateFieldGet(this, _OpenApiService_clientName, "f"),
1771
- 'X-Version': __classPrivateFieldGet(this, _OpenApiService_clientVersion, "f"),
1772
- },
1807
+ headers,
1773
1808
  });
1774
1809
  // sign after rateLimit, timestamp is the latest
1775
1810
  request.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () {
@@ -1782,9 +1817,13 @@ export class OpenApiService {
1782
1817
  }));
1783
1818
  this.request = rateLimit(request, { maxRPS });
1784
1819
  this.request.interceptors.response.use((response) => {
1785
- var _a, _b, _c, _d;
1786
- const code = ((_a = response.data) === null || _a === void 0 ? void 0 : _a.err_code) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.error_code);
1787
- const msg = ((_c = response.data) === null || _c === void 0 ? void 0 : _c.err_msg) || ((_d = response.data) === null || _d === void 0 ? void 0 : _d.error_msg);
1820
+ var _a, _b, _c, _d, _e;
1821
+ const newAPIKey = (_a = response.headers) === null || _a === void 0 ? void 0 : _a['x-set-api-key'];
1822
+ if (newAPIKey) {
1823
+ this.setAPIKey(newAPIKey);
1824
+ }
1825
+ const code = ((_b = response.data) === null || _b === void 0 ? void 0 : _b.err_code) || ((_c = response.data) === null || _c === void 0 ? void 0 : _c.error_code);
1826
+ const msg = ((_d = response.data) === null || _d === void 0 ? void 0 : _d.err_msg) || ((_e = response.data) === null || _e === void 0 ? void 0 : _e.error_msg);
1788
1827
  if (code && code !== 200) {
1789
1828
  if (msg) {
1790
1829
  let err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-api",
3
- "version": "0.9.45-beta.1",
3
+ "version": "0.9.47",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [