@rabby-wallet/rabby-action 0.1.10-beta.1 → 0.1.10
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/actions/common/fetchData.js +4 -1
- package/dist/actions/contractCall/fetchData.js +4 -1
- package/dist/actions/send/fetchData.js +4 -6
- package/dist/actions/transferOwner/fetchData.js +4 -1
- package/dist/types/fetchActionRequiredData.d.ts +0 -5
- package/dist/utils/catchTimeoutError.d.ts +1 -0
- package/dist/utils/catchTimeoutError.js +23 -0
- package/dist/utils/catchTimeoutError.test.d.ts +1 -0
- package/dist/utils/catchTimeoutError.test.js +24 -0
- package/package.json +2 -2
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import PQueue from 'p-queue';
|
|
11
11
|
import { waitQueueFinished } from '../../utils/waitQueueFinished';
|
|
12
|
+
import { catchTimeoutError } from '../../utils/catchTimeoutError';
|
|
12
13
|
export const fetchDataCommon = (options, likeAction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
14
|
const { walletProvider, actionData, sender, apiProvider, chainId } = options;
|
|
14
15
|
const queue = new PQueue();
|
|
@@ -78,7 +79,9 @@ export const fetchDataCommon = (options, likeAction) => __awaiter(void 0, void 0
|
|
|
78
79
|
name: null,
|
|
79
80
|
onTransferWhitelist: false,
|
|
80
81
|
};
|
|
81
|
-
const { has_transfer } = yield apiProvider.hasTransfer(chainId, sender, addr)
|
|
82
|
+
const { has_transfer } = yield catchTimeoutError(apiProvider.hasTransfer(chainId, sender, addr), {
|
|
83
|
+
has_transfer: false,
|
|
84
|
+
});
|
|
82
85
|
receiverData.hasTransfer = has_transfer;
|
|
83
86
|
const { desc } = yield apiProvider.addrDesc(addr);
|
|
84
87
|
if ((_b = desc.cex) === null || _b === void 0 ? void 0 : _b.id) {
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import PQueue from 'p-queue';
|
|
11
11
|
import { getProtocol } from '../../utils/getProtocol';
|
|
12
12
|
import { waitQueueFinished } from '../../utils/waitQueueFinished';
|
|
13
|
+
import { catchTimeoutError } from '../../utils/catchTimeoutError';
|
|
13
14
|
export const fetchDataContractCall = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
15
|
if (options.type !== 'transaction') {
|
|
15
16
|
return {};
|
|
@@ -77,7 +78,9 @@ export const fetchDataContractCall = (options) => __awaiter(void 0, void 0, void
|
|
|
77
78
|
name: null,
|
|
78
79
|
onTransferWhitelist: false,
|
|
79
80
|
};
|
|
80
|
-
const { has_transfer } = yield apiProvider.hasTransfer(chainId, sender, addr)
|
|
81
|
+
const { has_transfer } = yield catchTimeoutError(apiProvider.hasTransfer(chainId, sender, addr), {
|
|
82
|
+
has_transfer: false,
|
|
83
|
+
});
|
|
81
84
|
receiverData.hasTransfer = has_transfer;
|
|
82
85
|
const { desc } = yield apiProvider.addrDesc(addr);
|
|
83
86
|
if ((_b = desc.cex) === null || _b === void 0 ? void 0 : _b.id) {
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import PQueue from 'p-queue';
|
|
11
11
|
import { waitQueueFinished } from '../../utils/waitQueueFinished';
|
|
12
12
|
import { KEYRING_TYPE } from '../../utils/keyring';
|
|
13
|
+
import { catchTimeoutError } from '../../utils/catchTimeoutError';
|
|
13
14
|
// send, sendNFT, typedData.send
|
|
14
15
|
export const fetchDataSend = (options, likeSendAction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
16
|
const queue = new PQueue();
|
|
@@ -42,7 +43,9 @@ export const fetchDataSend = (options, likeSendAction) => __awaiter(void 0, void
|
|
|
42
43
|
hasPrivateKeyInWallet === KEYRING_TYPE.HdKeyring;
|
|
43
44
|
}
|
|
44
45
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
const { has_transfer } = yield apiProvider.hasTransfer(chainId, sender, sendAction.to)
|
|
46
|
+
const { has_transfer } = yield catchTimeoutError(apiProvider.hasTransfer(chainId, sender, sendAction.to), {
|
|
47
|
+
has_transfer: false,
|
|
48
|
+
});
|
|
46
49
|
result.hasTransfer = has_transfer;
|
|
47
50
|
}));
|
|
48
51
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -56,11 +59,6 @@ export const fetchDataSend = (options, likeSendAction) => __awaiter(void 0, void
|
|
|
56
59
|
bornAt: desc.born_at,
|
|
57
60
|
isDeposit: desc.cex.is_deposit,
|
|
58
61
|
};
|
|
59
|
-
if (options.cex) {
|
|
60
|
-
result.cex.logo = options.cex.logo;
|
|
61
|
-
result.cex.name = options.cex.name;
|
|
62
|
-
result.cex.id = options.cex.id;
|
|
63
|
-
}
|
|
64
62
|
}
|
|
65
63
|
if (desc.contract && Object.keys(desc.contract).length > 0) {
|
|
66
64
|
result.contract = desc.contract;
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import PQueue from 'p-queue';
|
|
11
11
|
import { waitQueueFinished } from '../../utils/waitQueueFinished';
|
|
12
|
+
import { catchTimeoutError } from '../../utils/catchTimeoutError';
|
|
12
13
|
export const fetchDataTransferOwner = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
14
|
var _a;
|
|
14
15
|
if (!options.actionData.transferOwner) {
|
|
@@ -37,7 +38,9 @@ export const fetchDataTransferOwner = (options) => __awaiter(void 0, void 0, voi
|
|
|
37
38
|
onTransferWhitelist: false,
|
|
38
39
|
};
|
|
39
40
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
const { has_transfer } = yield apiProvider.hasTransfer(chainId, sender, addr)
|
|
41
|
+
const { has_transfer } = yield catchTimeoutError(apiProvider.hasTransfer(chainId, sender, addr), {
|
|
42
|
+
has_transfer: false,
|
|
43
|
+
});
|
|
41
44
|
receiverData.hasTransfer = has_transfer;
|
|
42
45
|
}));
|
|
43
46
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -9,11 +9,6 @@ type BaseFetchActionRequiredDataParameters<T extends 'typed_data' | 'transaction
|
|
|
9
9
|
walletProvider: WalletProvider;
|
|
10
10
|
apiProvider: OpenApiService;
|
|
11
11
|
chainId: string;
|
|
12
|
-
cex?: {
|
|
13
|
-
id: string;
|
|
14
|
-
name: string;
|
|
15
|
-
logo: string;
|
|
16
|
-
};
|
|
17
12
|
};
|
|
18
13
|
export type FetchTransactionRequiredDataParameters = BaseFetchActionRequiredDataParameters<'transaction'> & {
|
|
19
14
|
type: 'transaction';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const catchTimeoutError: <T>(promise: Promise<T>, timeoutResponse: T) => Promise<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { AxiosError } from 'axios';
|
|
11
|
+
export const catchTimeoutError = (promise, timeoutResponse) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
try {
|
|
13
|
+
return yield promise;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error instanceof AxiosError &&
|
|
17
|
+
(error.code === AxiosError.ECONNABORTED ||
|
|
18
|
+
error.code === AxiosError.ETIMEDOUT)) {
|
|
19
|
+
return timeoutResponse;
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
// test catchTimeoutError
|
|
11
|
+
import { catchTimeoutError } from './catchTimeoutError';
|
|
12
|
+
import axios from 'axios';
|
|
13
|
+
test('catchTimeoutError should return timeoutResponse on timeout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const timeoutResponse = { has_transfer: false };
|
|
15
|
+
const promise = axios
|
|
16
|
+
.get('http://www.google.com:81/', {
|
|
17
|
+
timeout: 1,
|
|
18
|
+
})
|
|
19
|
+
.then((response) => {
|
|
20
|
+
return response.data;
|
|
21
|
+
});
|
|
22
|
+
const result = yield catchTimeoutError(promise, timeoutResponse);
|
|
23
|
+
expect(result).toEqual(timeoutResponse);
|
|
24
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rabby-wallet/rabby-action",
|
|
3
|
-
"version": "0.1.10
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@babel/preset-env": "^7.19.1",
|
|
14
14
|
"@debank/common": "^0.3.60",
|
|
15
|
-
"@rabby-wallet/rabby-api": "0.
|
|
15
|
+
"@rabby-wallet/rabby-api": "0.9.19",
|
|
16
16
|
"@rabby-wallet/rabby-security-engine": "2.0.7",
|
|
17
17
|
"@types/jest": "^29.0.3",
|
|
18
18
|
"@types/lodash": "^4.14.185",
|