@rabby-wallet/rabby-action 0.1.8 → 0.2.0-beta.0
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/approveNFT/fetchData.js +15 -6
- package/dist/actions/approveToken/fetchData.js +15 -6
- package/dist/actions/batchPermit2/fetchData.js +15 -6
- package/dist/actions/common/fetchData.js +15 -5
- package/dist/actions/contractCall/fetchData.js +15 -5
- package/dist/actions/swap/fetchData.js +15 -6
- package/dist/fetches/fetchHasInteraction.d.ts +17 -0
- package/dist/fetches/fetchHasInteraction.js +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/actionRequireData.d.ts +18 -6
- package/dist/types/fetchActionRequiredData.d.ts +4 -0
- package/dist/useFetchActionRequiredData.d.ts +5 -0
- package/dist/useFetchActionRequiredData.js +30 -0
- package/package.json +5 -2
|
@@ -9,9 +9,10 @@ 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 { fetchHasInteraction } from '../../fetches/fetchHasInteraction';
|
|
12
13
|
export const fetchDataApproveNFT = (options, likeAction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
14
|
const queue = new PQueue();
|
|
14
|
-
const { sender, apiProvider, chainId, actionData } = options;
|
|
15
|
+
const { sender, apiProvider, chainId, actionData, extraActionDataState } = options;
|
|
15
16
|
const action = likeAction || actionData.approveNFT;
|
|
16
17
|
if (!action) {
|
|
17
18
|
return {};
|
|
@@ -25,7 +26,10 @@ export const fetchDataApproveNFT = (options, likeAction) => __awaiter(void 0, vo
|
|
|
25
26
|
protocol: null,
|
|
26
27
|
isDanger: false,
|
|
27
28
|
tokenBalance: '0',
|
|
28
|
-
hasInteraction:
|
|
29
|
+
hasInteraction: null,
|
|
30
|
+
extraState: {
|
|
31
|
+
hasInteraction: () => undefined,
|
|
32
|
+
},
|
|
29
33
|
};
|
|
30
34
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
35
|
const contractInfo = yield apiProvider.getContractInfo(action.spender, chainId);
|
|
@@ -48,10 +52,15 @@ export const fetchDataApproveNFT = (options, likeAction) => __awaiter(void 0, vo
|
|
|
48
52
|
}));
|
|
49
53
|
}
|
|
50
54
|
}));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
fetchHasInteraction({
|
|
56
|
+
apiProvider,
|
|
57
|
+
sender,
|
|
58
|
+
chainId,
|
|
59
|
+
spender: action.spender,
|
|
60
|
+
extraActionDataState,
|
|
61
|
+
queue,
|
|
62
|
+
result,
|
|
63
|
+
});
|
|
55
64
|
yield waitQueueFinished(queue);
|
|
56
65
|
return result;
|
|
57
66
|
});
|
|
@@ -9,9 +9,10 @@ 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 { fetchHasInteraction } from '../../fetches/fetchHasInteraction';
|
|
12
13
|
export const fetchDataApproveToken = (options, likeAction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
14
|
const queue = new PQueue();
|
|
14
|
-
const { sender, apiProvider, chainId, actionData } = options;
|
|
15
|
+
const { sender, apiProvider, chainId, actionData, extraActionDataState } = options;
|
|
15
16
|
const action = likeAction || actionData.approveToken;
|
|
16
17
|
if (!action || !chainId) {
|
|
17
18
|
return {};
|
|
@@ -21,12 +22,15 @@ export const fetchDataApproveToken = (options, likeAction) => __awaiter(void 0,
|
|
|
21
22
|
isEOA: false,
|
|
22
23
|
contract: null,
|
|
23
24
|
riskExposure: 0,
|
|
24
|
-
hasInteraction:
|
|
25
|
+
hasInteraction: null,
|
|
25
26
|
rank: null,
|
|
26
27
|
bornAt: 0,
|
|
27
28
|
protocol: null,
|
|
28
29
|
isDanger: false,
|
|
29
30
|
token: Object.assign(Object.assign({}, token), { amount: 0, raw_amount_hex_str: '0x0' }),
|
|
31
|
+
extraState: {
|
|
32
|
+
hasInteraction: () => undefined,
|
|
33
|
+
},
|
|
30
34
|
};
|
|
31
35
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
36
|
const contractInfo = yield apiProvider.getContractInfo(spender, chainId);
|
|
@@ -55,10 +59,15 @@ export const fetchDataApproveToken = (options, likeAction) => __awaiter(void 0,
|
|
|
55
59
|
result.token = t;
|
|
56
60
|
}));
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
fetchHasInteraction({
|
|
63
|
+
apiProvider,
|
|
64
|
+
sender,
|
|
65
|
+
chainId,
|
|
66
|
+
spender,
|
|
67
|
+
extraActionDataState,
|
|
68
|
+
queue,
|
|
69
|
+
result,
|
|
70
|
+
});
|
|
62
71
|
yield waitQueueFinished(queue);
|
|
63
72
|
return result;
|
|
64
73
|
});
|
|
@@ -9,11 +9,12 @@ 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 { fetchHasInteraction } from '../../fetches/fetchHasInteraction';
|
|
12
13
|
export const fetchDataBatchPermit2 = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
14
|
if (options.type !== 'typed_data') {
|
|
14
15
|
return {};
|
|
15
16
|
}
|
|
16
|
-
const { actionData, apiProvider, sender, chainId } = options;
|
|
17
|
+
const { actionData, apiProvider, sender, chainId, extraActionDataState } = options;
|
|
17
18
|
if (!actionData.batchPermit2 || !chainId) {
|
|
18
19
|
return {};
|
|
19
20
|
}
|
|
@@ -29,7 +30,10 @@ export const fetchDataBatchPermit2 = (options) => __awaiter(void 0, void 0, void
|
|
|
29
30
|
protocol: null,
|
|
30
31
|
isDanger: false,
|
|
31
32
|
tokens: tokens.map((token) => (Object.assign(Object.assign({}, token), { amount: 0, raw_amount_hex_str: '0x0' }))),
|
|
32
|
-
hasInteraction:
|
|
33
|
+
hasInteraction: null,
|
|
34
|
+
extraState: {
|
|
35
|
+
hasInteraction: () => undefined,
|
|
36
|
+
},
|
|
33
37
|
};
|
|
34
38
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
39
|
const contractInfo = yield apiProvider.getContractInfo(spender, chainId);
|
|
@@ -83,10 +87,15 @@ export const fetchDataBatchPermit2 = (options) => __awaiter(void 0, void 0, void
|
|
|
83
87
|
})));
|
|
84
88
|
result.tokens = list;
|
|
85
89
|
}));
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
fetchHasInteraction({
|
|
91
|
+
apiProvider,
|
|
92
|
+
sender,
|
|
93
|
+
chainId,
|
|
94
|
+
spender,
|
|
95
|
+
extraActionDataState,
|
|
96
|
+
queue,
|
|
97
|
+
result,
|
|
98
|
+
});
|
|
90
99
|
yield waitQueueFinished(queue);
|
|
91
100
|
return result;
|
|
92
101
|
});
|
|
@@ -9,10 +9,12 @@ 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 { fetchHasInteraction } from '../../fetches/fetchHasInteraction';
|
|
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();
|
|
15
16
|
let action = likeAction;
|
|
17
|
+
const { extraActionDataState } = options;
|
|
16
18
|
if (options.type === 'typed_data' && options.actionData.contractId) {
|
|
17
19
|
action = {
|
|
18
20
|
receiver: options.actionData.contractId,
|
|
@@ -29,7 +31,10 @@ export const fetchDataCommon = (options, likeAction) => __awaiter(void 0, void 0
|
|
|
29
31
|
rank: null,
|
|
30
32
|
unexpectedAddr: null,
|
|
31
33
|
receiverInWallet: false,
|
|
32
|
-
hasInteraction:
|
|
34
|
+
hasInteraction: null,
|
|
35
|
+
extraState: {
|
|
36
|
+
hasInteraction: () => undefined,
|
|
37
|
+
},
|
|
33
38
|
};
|
|
34
39
|
if (options.type === 'typed_data') {
|
|
35
40
|
result.sender = sender;
|
|
@@ -53,10 +58,15 @@ export const fetchDataCommon = (options, likeAction) => __awaiter(void 0, void 0
|
|
|
53
58
|
result.bornAt = desc.born_at;
|
|
54
59
|
}));
|
|
55
60
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
fetchHasInteraction({
|
|
62
|
+
apiProvider,
|
|
63
|
+
sender,
|
|
64
|
+
chainId,
|
|
65
|
+
spender: receiver,
|
|
66
|
+
extraActionDataState,
|
|
67
|
+
queue,
|
|
68
|
+
result,
|
|
69
|
+
});
|
|
60
70
|
if (actionData.contractCall || actionData.common) {
|
|
61
71
|
const chain = walletProvider.findChain({
|
|
62
72
|
serverId: chainId,
|
|
@@ -10,7 +10,9 @@ 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 { fetchHasInteraction } from '../../fetches/fetchHasInteraction';
|
|
13
14
|
export const fetchDataContractCall = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const { extraActionDataState } = options;
|
|
14
16
|
if (options.type !== 'transaction') {
|
|
15
17
|
return {};
|
|
16
18
|
}
|
|
@@ -34,7 +36,10 @@ export const fetchDataContractCall = (options) => __awaiter(void 0, void 0, void
|
|
|
34
36
|
unexpectedAddr: null,
|
|
35
37
|
receiverInWallet: false,
|
|
36
38
|
isDanger: false,
|
|
37
|
-
hasInteraction:
|
|
39
|
+
hasInteraction: null,
|
|
40
|
+
extraState: {
|
|
41
|
+
hasInteraction: () => undefined,
|
|
42
|
+
},
|
|
38
43
|
};
|
|
39
44
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
45
|
const contractInfo = yield apiProvider.getContractInfo(contractCall.contract.id, chainId);
|
|
@@ -56,10 +61,15 @@ export const fetchDataContractCall = (options) => __awaiter(void 0, void 0, void
|
|
|
56
61
|
}
|
|
57
62
|
result.protocol = getProtocol(desc.protocol, chainId);
|
|
58
63
|
}));
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
fetchHasInteraction({
|
|
65
|
+
apiProvider,
|
|
66
|
+
sender,
|
|
67
|
+
chainId,
|
|
68
|
+
spender: contractCall.contract.id,
|
|
69
|
+
extraActionDataState,
|
|
70
|
+
queue,
|
|
71
|
+
result,
|
|
72
|
+
});
|
|
63
73
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
74
|
var _a, _b;
|
|
65
75
|
const addr = (_a = actionData.common) === null || _a === void 0 ? void 0 : _a.receiver;
|
|
@@ -9,13 +9,14 @@ 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 { fetchHasInteraction } from '../../fetches/fetchHasInteraction';
|
|
12
13
|
// TODO: text
|
|
13
14
|
export const fetchDataSwap = (options, likeSwapAction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
15
|
if (options.type === 'text') {
|
|
15
16
|
return {};
|
|
16
17
|
}
|
|
17
18
|
const queue = new PQueue();
|
|
18
|
-
const { actionData, walletProvider, sender, apiProvider, chainId } = options;
|
|
19
|
+
const { actionData, walletProvider, sender, apiProvider, chainId, extraActionDataState, } = options;
|
|
19
20
|
const swapAction = likeSwapAction || actionData.swap;
|
|
20
21
|
if (!swapAction) {
|
|
21
22
|
return {};
|
|
@@ -35,7 +36,10 @@ export const fetchDataSwap = (options, likeSwapAction) => __awaiter(void 0, void
|
|
|
35
36
|
rank: null,
|
|
36
37
|
sender,
|
|
37
38
|
receiverInWallet,
|
|
38
|
-
hasInteraction:
|
|
39
|
+
hasInteraction: null,
|
|
40
|
+
extraState: {
|
|
41
|
+
hasInteraction: () => undefined,
|
|
42
|
+
},
|
|
39
43
|
};
|
|
40
44
|
queue.add(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
45
|
const contractInfo = yield apiProvider.getContractInfo(id, chainId);
|
|
@@ -48,10 +52,15 @@ export const fetchDataSwap = (options, likeSwapAction) => __awaiter(void 0, void
|
|
|
48
52
|
result.protocol = contractInfo.protocol;
|
|
49
53
|
}
|
|
50
54
|
}));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
fetchHasInteraction({
|
|
56
|
+
apiProvider,
|
|
57
|
+
sender,
|
|
58
|
+
chainId,
|
|
59
|
+
spender: id,
|
|
60
|
+
extraActionDataState,
|
|
61
|
+
queue,
|
|
62
|
+
result,
|
|
63
|
+
});
|
|
55
64
|
yield waitQueueFinished(queue);
|
|
56
65
|
return result;
|
|
57
66
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OpenApiService } from '@rabby-wallet/rabby-api';
|
|
2
|
+
import { ExtraActionRequiredDataState } from '../types';
|
|
3
|
+
import PQueue from 'p-queue';
|
|
4
|
+
export declare function fetchHasInteraction({ apiProvider, sender, chainId, spender, extraActionDataState, queue, result, }: {
|
|
5
|
+
apiProvider: OpenApiService;
|
|
6
|
+
sender: string;
|
|
7
|
+
chainId: string;
|
|
8
|
+
spender: string;
|
|
9
|
+
extraActionDataState: ExtraActionRequiredDataState | undefined;
|
|
10
|
+
queue: PQueue;
|
|
11
|
+
result: {
|
|
12
|
+
hasInteraction: boolean | null;
|
|
13
|
+
extraState: {
|
|
14
|
+
hasInteraction: () => void;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
export function fetchHasInteraction({ apiProvider, sender, chainId, spender, extraActionDataState, queue, result, }) {
|
|
11
|
+
const handleHasInteraction = () => __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const hasInteraction = yield apiProvider.hasInteraction(sender, chainId, spender);
|
|
13
|
+
return hasInteraction.has_interaction;
|
|
14
|
+
});
|
|
15
|
+
if (!extraActionDataState) {
|
|
16
|
+
queue.add(() => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
result.hasInteraction = yield handleHasInteraction();
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
if (extraActionDataState === null || extraActionDataState === void 0 ? void 0 : extraActionDataState.setHasInteraction) {
|
|
21
|
+
result.extraState.hasInteraction = () => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
var _a;
|
|
23
|
+
const hasInteraction = yield handleHasInteraction();
|
|
24
|
+
(_a = extraActionDataState.setHasInteraction) === null || _a === void 0 ? void 0 : _a.call(extraActionDataState, hasInteraction);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,7 +10,10 @@ export interface SwapRequireData {
|
|
|
10
10
|
rank: number | null;
|
|
11
11
|
sender: string;
|
|
12
12
|
receiverInWallet: boolean;
|
|
13
|
-
hasInteraction: boolean;
|
|
13
|
+
hasInteraction: boolean | null;
|
|
14
|
+
extraState: {
|
|
15
|
+
hasInteraction: () => void;
|
|
16
|
+
};
|
|
14
17
|
}
|
|
15
18
|
export interface SendRequireData {
|
|
16
19
|
eoa: {
|
|
@@ -58,7 +61,10 @@ export interface ApproveTokenRequireData {
|
|
|
58
61
|
} | null;
|
|
59
62
|
isDanger: boolean | null;
|
|
60
63
|
token: TokenItem;
|
|
61
|
-
hasInteraction: boolean;
|
|
64
|
+
hasInteraction: boolean | null;
|
|
65
|
+
extraState: {
|
|
66
|
+
hasInteraction: () => void;
|
|
67
|
+
};
|
|
62
68
|
}
|
|
63
69
|
export type RevokeTokenApproveRequireData = ApproveTokenRequireData;
|
|
64
70
|
export interface WrapTokenRequireData {
|
|
@@ -71,7 +77,7 @@ export interface WrapTokenRequireData {
|
|
|
71
77
|
rank: number | null;
|
|
72
78
|
sender: string;
|
|
73
79
|
receiverInWallet: boolean;
|
|
74
|
-
hasInteraction: boolean;
|
|
80
|
+
hasInteraction: boolean | null;
|
|
75
81
|
}
|
|
76
82
|
export interface ContractCallRequireData {
|
|
77
83
|
id: string;
|
|
@@ -88,7 +94,10 @@ export interface ContractCallRequireData {
|
|
|
88
94
|
unexpectedAddr: ReceiverData | null;
|
|
89
95
|
receiverInWallet: boolean;
|
|
90
96
|
isDanger?: boolean;
|
|
91
|
-
hasInteraction: boolean;
|
|
97
|
+
hasInteraction: boolean | null;
|
|
98
|
+
extraState: {
|
|
99
|
+
hasInteraction: () => void;
|
|
100
|
+
};
|
|
92
101
|
}
|
|
93
102
|
export type ApproveNFTRequireData = Omit<ApproveTokenRequireData, 'token'> & {
|
|
94
103
|
tokenBalance: string;
|
|
@@ -144,7 +153,10 @@ export interface ContractRequireData {
|
|
|
144
153
|
rank: number | null;
|
|
145
154
|
unexpectedAddr: ReceiverData | null;
|
|
146
155
|
receiverInWallet: boolean;
|
|
147
|
-
hasInteraction: boolean;
|
|
156
|
+
hasInteraction: boolean | null;
|
|
157
|
+
extraState: {
|
|
158
|
+
hasInteraction: () => void;
|
|
159
|
+
};
|
|
148
160
|
}
|
|
149
161
|
export interface AssetOrderRequireData extends ContractRequireData {
|
|
150
162
|
sender: string;
|
|
@@ -159,4 +171,4 @@ export interface SwapTokenOrderRequireData extends ContractRequireData {
|
|
|
159
171
|
export type BatchApproveTokenRequireData = Omit<ApproveTokenRequireData, 'token'> & {
|
|
160
172
|
tokens: TokenItem[];
|
|
161
173
|
};
|
|
162
|
-
export type ActionRequireData = SwapRequireData | ApproveTokenRequireData | SendRequireData | ApproveNFTRequireData | RevokeNFTRequireData |
|
|
174
|
+
export type ActionRequireData = SwapRequireData | ApproveTokenRequireData | SendRequireData | ApproveNFTRequireData | RevokeNFTRequireData | Record<string, any> | ContractCallRequireData | CancelTxRequireData | WrapTokenRequireData | PushMultiSigRequireData | AssetOrderRequireData | BatchRevokePermit2RequireData | SwapTokenOrderRequireData | ContractRequireData | MultiSigRequireData | BatchApproveTokenRequireData | null;
|
|
@@ -3,12 +3,16 @@ import { ParsedActionData } from './parsedActionData';
|
|
|
3
3
|
import { OpenApiService } from '@rabby-wallet/rabby-api';
|
|
4
4
|
import { WalletProvider } from './walletProvider';
|
|
5
5
|
import { ActionRequireData } from './actionRequireData';
|
|
6
|
+
export type ExtraActionRequiredDataState = {
|
|
7
|
+
setHasInteraction?: (v: boolean) => void;
|
|
8
|
+
};
|
|
6
9
|
type BaseFetchActionRequiredDataParameters<T extends 'typed_data' | 'transaction' | 'text' | undefined> = {
|
|
7
10
|
actionData: ParsedActionData<T>;
|
|
8
11
|
sender: string;
|
|
9
12
|
walletProvider: WalletProvider;
|
|
10
13
|
apiProvider: OpenApiService;
|
|
11
14
|
chainId: string;
|
|
15
|
+
extraActionDataState?: ExtraActionRequiredDataState;
|
|
12
16
|
};
|
|
13
17
|
export type FetchTransactionRequiredDataParameters = BaseFetchActionRequiredDataParameters<'transaction'> & {
|
|
14
18
|
type: 'transaction';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ActionRequireData, FetchActionRequiredDataParameters } from './types';
|
|
2
|
+
export declare const useFetchActionRequiredData: () => {
|
|
3
|
+
fetchActionRequiredData: (options: FetchActionRequiredDataParameters) => Promise<ActionRequireData>;
|
|
4
|
+
requiredData: ActionRequireData;
|
|
5
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { fetchActionRequiredData } from './fetchActionRequiredData';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
export const useFetchActionRequiredData = () => {
|
|
13
|
+
const [requiredData, setRequiredData] = React.useState(null);
|
|
14
|
+
const setHasInteraction = React.useCallback((hasInteraction) => {
|
|
15
|
+
setRequiredData((prev) => {
|
|
16
|
+
return Object.assign(Object.assign({}, prev), { hasInteraction });
|
|
17
|
+
});
|
|
18
|
+
}, []);
|
|
19
|
+
const _fetchActionRequiredData = React.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const result = yield fetchActionRequiredData(Object.assign(Object.assign({}, options), { extraActionDataState: {
|
|
21
|
+
setHasInteraction,
|
|
22
|
+
} }));
|
|
23
|
+
setRequiredData(result);
|
|
24
|
+
return result;
|
|
25
|
+
}), [setHasInteraction]);
|
|
26
|
+
return {
|
|
27
|
+
fetchActionRequiredData: _fetchActionRequiredData,
|
|
28
|
+
requiredData,
|
|
29
|
+
};
|
|
30
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rabby-wallet/rabby-action",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@types/jest": "^29.0.3",
|
|
18
18
|
"@types/lodash": "^4.14.185",
|
|
19
19
|
"@types/node": "^18.7.18",
|
|
20
|
+
"@types/react": "^19.0.1",
|
|
20
21
|
"babel-jest": "^29.0.3",
|
|
21
22
|
"bignumber.js": "^9.1.2",
|
|
22
23
|
"husky": ">=6",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"lint-staged": ">=10",
|
|
27
28
|
"p-queue": "7.3.0",
|
|
28
29
|
"prettier": "^2.7.1",
|
|
30
|
+
"react": "^19.0.0",
|
|
29
31
|
"rimraf": "^3.0.2",
|
|
30
32
|
"ts-jest": "^29.2.4",
|
|
31
33
|
"ts-node": "^10.9.1",
|
|
@@ -43,7 +45,8 @@
|
|
|
43
45
|
"@rabby-wallet/rabby-api": "*",
|
|
44
46
|
"@rabby-wallet/rabby-security-engine": "*",
|
|
45
47
|
"bignumber.js": "*",
|
|
46
|
-
"p-queue": "^7.3.0"
|
|
48
|
+
"p-queue": "^7.3.0",
|
|
49
|
+
"react": "*"
|
|
47
50
|
},
|
|
48
51
|
"author": "rabby",
|
|
49
52
|
"description": "",
|