@velora-dex/widget 0.0.21 → 0.0.22
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/components/widget/TradeOverview/MarketSwapTradeOverview.d.ts +1 -1
- package/dist/components/widget/TradeOverview/MarketSwapTradeOverview.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/MarketSwapTradeOverview.js.map +1 -1
- package/dist/components/widget/TradeOverview/Step/Step.d.ts +3 -0
- package/dist/components/widget/TradeOverview/Step/Step.d.ts.map +1 -0
- package/dist/components/widget/TradeOverview/{Step.js → Step/Step.js} +3 -3
- package/dist/components/widget/TradeOverview/Step/Step.js.map +1 -0
- package/dist/components/widget/TradeOverview/Step/types.d.ts +32 -0
- package/dist/components/widget/TradeOverview/Step/types.d.ts.map +1 -0
- package/dist/components/widget/TradeOverview/Step/utils.d.ts +12 -0
- package/dist/components/widget/TradeOverview/Step/utils.d.ts.map +1 -0
- package/dist/components/widget/TradeOverview/Step/utils.js +41 -0
- package/dist/components/widget/TradeOverview/Step/utils.js.map +1 -0
- package/dist/components/widget/TradeOverview/Stepper.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/Stepper.js +45 -82
- package/dist/components/widget/TradeOverview/Stepper.js.map +1 -1
- package/dist/components/widget/TradeOverview/TradeDetailsDisplay.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/TradeDetailsDisplay.js +1 -2
- package/dist/components/widget/TradeOverview/TradeDetailsDisplay.js.map +1 -1
- package/dist/components/widget/TradeOverview/TradeError/utils.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/TradeError/utils.js +3 -5
- package/dist/components/widget/TradeOverview/TradeError/utils.js.map +1 -1
- package/dist/components/widget/TradeOverview/TradeOverview.d.ts +2 -2
- package/dist/components/widget/TradeOverview/TradeOverview.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/TradeOverview.js.map +1 -1
- package/dist/components/widget/TradeOverview/index.d.ts +1 -1
- package/dist/components/widget/TradeOverview/index.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/steps.d.ts +60 -80
- package/dist/components/widget/TradeOverview/steps.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/steps.js +21 -24
- package/dist/components/widget/TradeOverview/steps.js.map +1 -1
- package/dist/components/widget/TradeOverview/tradeFlowContext.js +1 -1
- package/dist/components/widget/TradeOverview/tradeFlowContext.js.map +1 -1
- package/dist/hooks/permit/hooks/permit2/usePermit2TransferFromNonce.d.ts.map +1 -1
- package/dist/hooks/permit/hooks/permit2/usePermit2TransferFromNonce.js +1 -2
- package/dist/hooks/permit/hooks/permit2/usePermit2TransferFromNonce.js.map +1 -1
- package/dist/hooks/swap/prices/delta/queries/useWatchDeltaOrder.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/queries/useWatchDeltaOrder.js +1 -2
- package/dist/hooks/swap/prices/delta/queries/useWatchDeltaOrder.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useDeltaSwapStep.d.ts +2 -2
- package/dist/hooks/swap/tradeFlow/useDeltaSwapStep.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useDeltaSwapStep.js +61 -45
- package/dist/hooks/swap/tradeFlow/useDeltaSwapStep.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useMarketSwapStep.d.ts +2 -2
- package/dist/hooks/swap/tradeFlow/useMarketSwapStep.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useMarketSwapStep.js +65 -55
- package/dist/hooks/swap/tradeFlow/useMarketSwapStep.js.map +1 -1
- package/dist/hooks/tokens/balances/useInvalidateTokenData.d.ts.map +1 -1
- package/dist/hooks/tokens/balances/useInvalidateTokenData.js +1 -2
- package/dist/hooks/tokens/balances/useInvalidateTokenData.js.map +1 -1
- package/dist/hooks/txs/queries/useAwaitTx.js +1 -1
- package/dist/hooks/txs/queries/useAwaitTx.js.map +1 -1
- package/dist/lib/queryClient.d.ts +0 -1
- package/dist/lib/queryClient.d.ts.map +1 -1
- package/dist/lib/queryClient.js +2 -5
- package/dist/lib/queryClient.js.map +1 -1
- package/dist/lib/web3/wagmi/config.d.ts +1 -1
- package/dist/lib/web3/wagmi/constants.d.ts +1 -1
- package/dist/tokens/lists/state/tokenListsStateAtom.d.ts +2 -2
- package/dist/widget/state/chainToAtom.d.ts +2 -2
- package/package.json +3 -3
- package/dist/components/widget/TradeOverview/Step.d.ts +0 -22
- package/dist/components/widget/TradeOverview/Step.d.ts.map +0 -1
- package/dist/components/widget/TradeOverview/Step.js.map +0 -1
|
@@ -1,27 +1,34 @@
|
|
|
1
|
+
declare const signatureStep: {
|
|
2
|
+
readonly subSteps: [{
|
|
3
|
+
readonly title: "Approve Order Signatures (1/2)";
|
|
4
|
+
readonly description: (props: import('.').TitleFnProps) => string;
|
|
5
|
+
readonly key: "approval-signature";
|
|
6
|
+
}, {
|
|
7
|
+
readonly title: "Approve Order Signatures (2/2)";
|
|
8
|
+
readonly description: "We need your signature on your wallet to confirm the order submission.";
|
|
9
|
+
readonly key: "order-signature";
|
|
10
|
+
}, {
|
|
11
|
+
readonly title: "Approve Order Signature";
|
|
12
|
+
readonly description: "We need your signature on your wallet to confirm the order submission.";
|
|
13
|
+
readonly key: "standalone-order-signature";
|
|
14
|
+
}];
|
|
15
|
+
readonly key: "signature";
|
|
16
|
+
};
|
|
1
17
|
export declare const DeltaOrderSteps: [{
|
|
2
|
-
readonly
|
|
3
|
-
readonly
|
|
4
|
-
readonly
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
readonly done: (props: {
|
|
17
|
-
fromToken: import('./TradeDetails').MinTradeFlowToken;
|
|
18
|
-
toToken: import('./TradeDetails').MinTradeFlowToken;
|
|
19
|
-
fromAmount: string;
|
|
20
|
-
toAmount: string;
|
|
21
|
-
}) => string;
|
|
22
|
-
};
|
|
23
|
-
readonly description: "We need a signature for spending approval to be able to execute your swap on your behalf.";
|
|
24
|
-
readonly key: "approve-spending";
|
|
18
|
+
readonly subSteps: [{
|
|
19
|
+
readonly title: "Approve Order Signatures (1/2)";
|
|
20
|
+
readonly description: (props: import('.').TitleFnProps) => string;
|
|
21
|
+
readonly key: "approval-signature";
|
|
22
|
+
}, {
|
|
23
|
+
readonly title: "Approve Order Signatures (2/2)";
|
|
24
|
+
readonly description: "We need your signature on your wallet to confirm the order submission.";
|
|
25
|
+
readonly key: "order-signature";
|
|
26
|
+
}, {
|
|
27
|
+
readonly title: "Approve Order Signature";
|
|
28
|
+
readonly description: "We need your signature on your wallet to confirm the order submission.";
|
|
29
|
+
readonly key: "standalone-order-signature";
|
|
30
|
+
}];
|
|
31
|
+
readonly key: "signature";
|
|
25
32
|
}, {
|
|
26
33
|
readonly title: {
|
|
27
34
|
readonly next: "Auction is upcoming";
|
|
@@ -41,69 +48,42 @@ export declare const DeltaOrderSteps: [{
|
|
|
41
48
|
readonly description: "Sit tight and relax, your order is being executed.";
|
|
42
49
|
readonly key: "order-execution";
|
|
43
50
|
}];
|
|
44
|
-
export type DeltaOrderStepKey = (typeof DeltaOrderSteps)[number]["key"];
|
|
45
51
|
export declare const MarketSwapSteps: [{
|
|
46
|
-
readonly
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
readonly done: (props: {
|
|
61
|
-
fromToken: import('./TradeDetails').MinTradeFlowToken;
|
|
62
|
-
toToken: import('./TradeDetails').MinTradeFlowToken;
|
|
63
|
-
fromAmount: string;
|
|
64
|
-
toAmount: string;
|
|
65
|
-
}) => string;
|
|
66
|
-
};
|
|
67
|
-
readonly description: "We need a signature for spending approval to be able to execute your swap on your behalf.";
|
|
68
|
-
readonly key: "approve-spending";
|
|
69
|
-
}, {
|
|
70
|
-
readonly title: {
|
|
71
|
-
readonly next: "Swap Request is upcoming";
|
|
72
|
-
readonly upcoming: "Swap Request";
|
|
73
|
-
readonly ongoing: "Approve Swap Request";
|
|
74
|
-
readonly done: "Swap Request is confirmed";
|
|
75
|
-
};
|
|
76
|
-
readonly description: "We need a confirmation on your wallet to submit your swap";
|
|
77
|
-
readonly key: "swap-tx-confirmation";
|
|
52
|
+
readonly subSteps: [{
|
|
53
|
+
readonly title: "Approve Order Signatures (1/2)";
|
|
54
|
+
readonly description: (props: import('.').TitleFnProps) => string;
|
|
55
|
+
readonly key: "approval-signature";
|
|
56
|
+
}, {
|
|
57
|
+
readonly title: "Approve Order Signatures (2/2)";
|
|
58
|
+
readonly description: "We need your signature on your wallet to confirm the order submission.";
|
|
59
|
+
readonly key: "order-signature";
|
|
60
|
+
}, {
|
|
61
|
+
readonly title: "Approve Order Signature";
|
|
62
|
+
readonly description: "We need your signature on your wallet to confirm the order submission.";
|
|
63
|
+
readonly key: "standalone-order-signature";
|
|
64
|
+
}];
|
|
65
|
+
readonly key: "signature";
|
|
78
66
|
}, {
|
|
79
67
|
readonly title: {
|
|
80
|
-
readonly next:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
toAmount: string;
|
|
85
|
-
}) => string;
|
|
86
|
-
readonly upcoming: (props: {
|
|
87
|
-
fromToken: import('./TradeDetails').MinTradeFlowToken;
|
|
88
|
-
toToken: import('./TradeDetails').MinTradeFlowToken;
|
|
89
|
-
fromAmount: string;
|
|
90
|
-
toAmount: string;
|
|
91
|
-
}) => string;
|
|
92
|
-
readonly ongoing: (props: {
|
|
93
|
-
fromToken: import('./TradeDetails').MinTradeFlowToken;
|
|
94
|
-
toToken: import('./TradeDetails').MinTradeFlowToken;
|
|
95
|
-
fromAmount: string;
|
|
96
|
-
toAmount: string;
|
|
97
|
-
}) => string;
|
|
98
|
-
readonly done: (props: {
|
|
99
|
-
fromToken: import('./TradeDetails').MinTradeFlowToken;
|
|
100
|
-
toToken: import('./TradeDetails').MinTradeFlowToken;
|
|
101
|
-
fromAmount: string;
|
|
102
|
-
toAmount: string;
|
|
103
|
-
}) => string;
|
|
68
|
+
readonly next: "Order Execution is upcoming";
|
|
69
|
+
readonly upcoming: "Order Execution";
|
|
70
|
+
readonly ongoing: "Executing the swap order";
|
|
71
|
+
readonly done: "Order is executed";
|
|
104
72
|
};
|
|
105
73
|
readonly description: "Sit tight and relax, your swap transaction is being executed";
|
|
106
74
|
readonly key: "swap-tx-execution";
|
|
107
75
|
}];
|
|
76
|
+
export type DeltaOrderStepKey = (typeof DeltaOrderSteps)[number]["key"];
|
|
108
77
|
export type MarketSwapStepKey = (typeof MarketSwapSteps)[number]["key"];
|
|
78
|
+
export type SignatureStep = {
|
|
79
|
+
key: typeof signatureStep.key;
|
|
80
|
+
subStep: (typeof signatureStep.subSteps)[number]["key"];
|
|
81
|
+
};
|
|
82
|
+
export type DeltaOrderStep = SignatureStep | {
|
|
83
|
+
key: Exclude<DeltaOrderStepKey, SignatureStep["key"]>;
|
|
84
|
+
};
|
|
85
|
+
export type MarketSwapStep = SignatureStep | {
|
|
86
|
+
key: Exclude<MarketSwapStepKey, SignatureStep["key"]>;
|
|
87
|
+
};
|
|
88
|
+
export {};
|
|
109
89
|
//# sourceMappingURL=steps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../../../src/components/widget/TradeOverview/steps.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../../../src/components/widget/TradeOverview/steps.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;CAsBU,CAAC;AAE9B,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBG,CAAC;AAEhC,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;EAYG,CAAC;AAEhC,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;AACxE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;AAExE,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,OAAO,aAAa,CAAC,GAAG,CAAC;IAC9B,OAAO,EAAE,CAAC,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,cAAc,GACtB,aAAa,GACb;IAAE,GAAG,EAAE,OAAO,CAAC,iBAAiB,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;CAAE,CAAC;AAC9D,MAAM,MAAM,cAAc,GACtB,aAAa,GACb;IAAE,GAAG,EAAE,OAAO,CAAC,iBAAiB,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;CAAE,CAAC"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const signatureStep = {
|
|
2
|
+
subSteps: [{
|
|
3
|
+
title: "Approve Order Signatures (1/2)",
|
|
4
|
+
description: (props) => `We need your signature on your wallet to allow our smart contracts to access your ${props.fromToken.symbol} token and execute your swap on your behalf.`,
|
|
5
|
+
key: "approval-signature"
|
|
6
|
+
}, {
|
|
7
|
+
title: "Approve Order Signatures (2/2)",
|
|
8
|
+
description: "We need your signature on your wallet to confirm the order submission.",
|
|
9
|
+
key: "order-signature"
|
|
10
|
+
}, {
|
|
11
|
+
title: "Approve Order Signature",
|
|
12
|
+
description: "We need your signature on your wallet to confirm the order submission.",
|
|
13
|
+
key: "standalone-order-signature"
|
|
14
|
+
}],
|
|
15
|
+
key: "signature"
|
|
10
16
|
};
|
|
11
|
-
const DeltaOrderSteps = [
|
|
17
|
+
const DeltaOrderSteps = [signatureStep, {
|
|
12
18
|
title: {
|
|
13
19
|
next: "Auction is upcoming",
|
|
14
20
|
upcoming: "Auction",
|
|
@@ -27,21 +33,12 @@ const DeltaOrderSteps = [approvalStep, {
|
|
|
27
33
|
description: "Sit tight and relax, your order is being executed.",
|
|
28
34
|
key: "order-execution"
|
|
29
35
|
}];
|
|
30
|
-
const MarketSwapSteps = [
|
|
31
|
-
title: {
|
|
32
|
-
next: "Swap Request is upcoming",
|
|
33
|
-
upcoming: "Swap Request",
|
|
34
|
-
ongoing: "Approve Swap Request",
|
|
35
|
-
done: "Swap Request is confirmed"
|
|
36
|
-
},
|
|
37
|
-
description: "We need a confirmation on your wallet to submit your swap",
|
|
38
|
-
key: "swap-tx-confirmation"
|
|
39
|
-
}, {
|
|
36
|
+
const MarketSwapSteps = [signatureStep, {
|
|
40
37
|
title: {
|
|
41
|
-
next:
|
|
42
|
-
upcoming:
|
|
43
|
-
ongoing:
|
|
44
|
-
done:
|
|
38
|
+
next: "Order Execution is upcoming",
|
|
39
|
+
upcoming: "Order Execution",
|
|
40
|
+
ongoing: "Executing the swap order",
|
|
41
|
+
done: "Order is executed"
|
|
45
42
|
},
|
|
46
43
|
description: "Sit tight and relax, your swap transaction is being executed",
|
|
47
44
|
key: "swap-tx-execution"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.js","sources":["../../../../src/components/widget/TradeOverview/steps.ts"],"sourcesContent":["import type { FlowStep } from \"./Step\";\n\nconst
|
|
1
|
+
{"version":3,"file":"steps.js","sources":["../../../../src/components/widget/TradeOverview/steps.ts"],"sourcesContent":["import type { FlowStep } from \"./Step/types\";\n\nconst signatureStep = {\n subSteps: [\n {\n title: \"Approve Order Signatures (1/2)\",\n description: (props) =>\n `We need your signature on your wallet to allow our smart contracts to access your ${props.fromToken.symbol} token and execute your swap on your behalf.`,\n key: \"approval-signature\",\n },\n {\n title: \"Approve Order Signatures (2/2)\",\n description:\n \"We need your signature on your wallet to confirm the order submission.\",\n key: \"order-signature\",\n },\n {\n title: \"Approve Order Signature\",\n description:\n \"We need your signature on your wallet to confirm the order submission.\",\n key: \"standalone-order-signature\",\n },\n ],\n key: \"signature\",\n} as const satisfies FlowStep;\n\nexport const DeltaOrderSteps = [\n signatureStep,\n {\n title: {\n next: \"Auction is upcoming\",\n upcoming: \"Auction\",\n ongoing: \"Auction in progress\",\n done: \"Auction is completed\",\n },\n description:\n \"We send your order to our Delta agents, the one with the best price and execution offer will be picked for your trade\",\n key: \"auction\",\n },\n {\n title: {\n next: \"Order Execution is upcoming\",\n upcoming: \"Order Execution\",\n ongoing: \"Executing the Order\",\n done: \"Order is executed\",\n },\n description: \"Sit tight and relax, your order is being executed.\",\n key: \"order-execution\",\n },\n] as const satisfies FlowStep[];\n\nexport const MarketSwapSteps = [\n signatureStep,\n {\n title: {\n next: \"Order Execution is upcoming\",\n upcoming: \"Order Execution\",\n ongoing: \"Executing the swap order\",\n done: \"Order is executed\",\n },\n description: \"Sit tight and relax, your swap transaction is being executed\",\n key: \"swap-tx-execution\",\n },\n] as const satisfies FlowStep[];\n\nexport type DeltaOrderStepKey = (typeof DeltaOrderSteps)[number][\"key\"];\nexport type MarketSwapStepKey = (typeof MarketSwapSteps)[number][\"key\"];\n\nexport type SignatureStep = {\n key: typeof signatureStep.key;\n subStep: (typeof signatureStep.subSteps)[number][\"key\"];\n};\n\nexport type DeltaOrderStep =\n | SignatureStep\n | { key: Exclude<DeltaOrderStepKey, SignatureStep[\"key\"]> };\nexport type MarketSwapStep =\n | SignatureStep\n | { key: Exclude<MarketSwapStepKey, SignatureStep[\"key\"]> };\n"],"names":["signatureStep","subSteps","title","description","props","fromToken","symbol","key","DeltaOrderSteps","next","upcoming","ongoing","done","MarketSwapSteps"],"mappings":"AAEA,MAAMA,aAAAA,GAAgB;AAAA,EACpBC,UAAU,CACR;AA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@ -8,7 +8,7 @@ function useTradeFlowContext() {
|
|
|
8
8
|
if (!context) {
|
|
9
9
|
throw new Error("useTradeFlowContext must be used within a TradeFlowContext");
|
|
10
10
|
}
|
|
11
|
-
const derivedStep = context.error ? "error" : context.result ? "complete" : context.activeStep;
|
|
11
|
+
const derivedStep = context.error ? "error" : context.result ? "complete" : context.activeStep?.key;
|
|
12
12
|
let t0;
|
|
13
13
|
if ($[0] !== context || $[1] !== derivedStep) {
|
|
14
14
|
t0 = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tradeFlowContext.js","sources":["../../../../src/components/widget/TradeOverview/tradeFlowContext.ts"],"sourcesContent":["import type { TradeFlowResult } from \"@/hooks/swap/tradeFlow/common/types\";\nimport type { TradeOverviewProps } from \"./TradeOverview\";\nimport { createContext, useContext } from \"react\";\nimport type { DeltaOrderStepKey, MarketSwapStepKey } from \"./steps\";\n\n// generic to accept any result and step type\nexport type TradeFlowContextProps<\n Key extends string = string,\n Result = unknown,\n> = Pick<\n TradeOverviewProps<Key, Result>,\n | \"fromToken\"\n | \"toToken\"\n | \"fromAmount\"\n | \"toAmount\"\n | \"activeStep\"\n | \"steps\"\n | \"isCancellable\"\n | \"explorerLink\"\n | \"result\"\n | \"error\"\n | \"erroredStep\"\n>;\n\nexport const TradeFlowContext = createContext<TradeFlowContextProps | null>(\n null\n);\n\nexport type TradeFlowStep = DeltaOrderStepKey | MarketSwapStepKey;\nexport type TradeFlowDerivedStep = TradeFlowStep | \"complete\" | \"error\";\n\ntype Context = TradeFlowContextProps<TradeFlowStep, TradeFlowResult>;\ntype ContextExtra = { derivedStep?: TradeFlowDerivedStep };\n\n// specific result for supported Trade Flows\nexport function useTradeFlowContext(): Context & ContextExtra {\n const context = useContext(TradeFlowContext);\n if (!context) {\n throw new Error(\n \"useTradeFlowContext must be used within a TradeFlowContext\"\n );\n }\n\n const derivedStep = context.error\n ? \"error\"\n : context.result\n ? \"complete\"\n : context.activeStep;\n const extendedContext = {\n ...context,\n derivedStep,\n };\n\n return extendedContext as Context & ContextExtra;\n}\n"],"names":["TradeFlowContext","createContext","useTradeFlowContext","$","_c","context","useContext","Error","derivedStep","error","result","activeStep","t0","extendedContext"],"mappings":";;;AAwBO,MAAMA,gBAAAA,GAAmBC,cAC9B,IACF;AASO,SAAAC,mBAAAA,GAAA;AAAA,EAAA,MAAAC,CAAAA,GAAAC,cAAA,CAAA,CAAA;AACL,EAAA,MAAAC,OAAAA,GAAgBC,WAAAN,gBAA2B,CAAA;AAAE,EAAA,IAAA,CACxCK,OAAAA,EAAO;AAAA,IAAA,MAAA,IAAAE,MAER,4DAA4D,CAAA;AAAA;AAIhE,EAAA,MAAAC,
|
|
1
|
+
{"version":3,"file":"tradeFlowContext.js","sources":["../../../../src/components/widget/TradeOverview/tradeFlowContext.ts"],"sourcesContent":["import type { TradeFlowResult } from \"@/hooks/swap/tradeFlow/common/types\";\nimport type { TradeOverviewProps } from \"./TradeOverview\";\nimport { createContext, useContext } from \"react\";\nimport type { DeltaOrderStepKey, MarketSwapStepKey } from \"./steps\";\n\n// generic to accept any result and step type\nexport type TradeFlowContextProps<\n Key extends string = string,\n Result = unknown,\n> = Pick<\n TradeOverviewProps<Key, Result>,\n | \"fromToken\"\n | \"toToken\"\n | \"fromAmount\"\n | \"toAmount\"\n | \"activeStep\"\n | \"steps\"\n | \"isCancellable\"\n | \"explorerLink\"\n | \"result\"\n | \"error\"\n | \"erroredStep\"\n>;\n\nexport const TradeFlowContext = createContext<TradeFlowContextProps | null>(\n null\n);\n\nexport type TradeFlowStep = DeltaOrderStepKey | MarketSwapStepKey;\nexport type TradeFlowDerivedStep = TradeFlowStep | \"complete\" | \"error\";\n\ntype Context = TradeFlowContextProps<TradeFlowStep, TradeFlowResult>;\ntype ContextExtra = { derivedStep?: TradeFlowDerivedStep };\n\n// specific result for supported Trade Flows\nexport function useTradeFlowContext(): Context & ContextExtra {\n const context = useContext(TradeFlowContext);\n if (!context) {\n throw new Error(\n \"useTradeFlowContext must be used within a TradeFlowContext\"\n );\n }\n\n const derivedStep = context.error\n ? \"error\"\n : context.result\n ? \"complete\"\n : context.activeStep?.key;\n const extendedContext = {\n ...context,\n derivedStep,\n };\n\n return extendedContext as Context & ContextExtra;\n}\n"],"names":["TradeFlowContext","createContext","useTradeFlowContext","$","_c","context","useContext","Error","derivedStep","error","result","activeStep","key","t0","extendedContext"],"mappings":";;;AAwBO,MAAMA,gBAAAA,GAAmBC,cAC9B,IACF;AASO,SAAAC,mBAAAA,GAAA;AAAA,EAAA,MAAAC,CAAAA,GAAAC,cAAA,CAAA,CAAA;AACL,EAAA,MAAAC,OAAAA,GAAgBC,WAAAN,gBAA2B,CAAA;AAAE,EAAA,IAAA,CACxCK,OAAAA,EAAO;AAAA,IAAA,MAAA,IAAAE,MAER,4DAA4D,CAAA;AAAA;AAIhE,EAAA,MAAAC,WAAAA,GAAoBH,QAAOI,KAAAA,GACvB,OAAA,GACAJ,QAAOK,MAAAA,GACL,UAAA,GACAL,QAAOM,UAAAA,EAAAC,GAAAA;AAAiB,EAAA,IAAAC,EAAAA;AAAA,EAAA,IAAAV,EAAA,CAAA,CAAA,KAAAE,WAAAF,CAAAA,QAAAK,WAAAA,EAAA;AACNK,IAAAA,EAAAA,GAAA;AAAA,MAAA,GACnBR,OAAAA;AAAAA,MAAOG;AAAAA,KAAA;AAEXL,IAAAA,CAAAA,MAAAE,OAAAA;AAAAF,IAAAA,CAAAA,MAAAK,WAAAA;AAAAL,IAAAA,CAAAA,MAAAU,EAAAA;AAAAA,GAAA,MAAA;AAAAA,IAAAA,EAAAA,GAAAV,EAAA,CAAA,CAAA;AAAA;AAHD,EAAA,MAAAW,eAAAA,GAAwBD,EAAAA;AAGtB,EAAA,OAEKC,eAAAA;AAAyC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePermit2TransferFromNonce.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/permit/hooks/permit2/usePermit2TransferFromNonce.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"usePermit2TransferFromNonce.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/permit/hooks/permit2/usePermit2TransferFromNonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,MAAM,CAAC;AAQhD;;;;;;;;;;;;GAYG;AAGH,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAUF,UAAU,kCAAkC;IAC1C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,iCAAiC,GAAG;IAE9C,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,CACP,OAAO,CAAC,EAAE,cAAc,KACrB,OAAO,CAAC,mBAAmB,CAAC,UAAU,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,OAAO,EACP,QAAa,EACb,OAAc,GACf,EAAE,kCAAkC;;;;;;;;EAkFpC;AAyED,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B;;;OAGG;IACH,eAAe,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CACjD,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,wBAAwB,CAmC7D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useQueryClient, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { maxUint256 } from 'viem';
|
|
3
3
|
import { useConfig } from 'wagmi';
|
|
4
4
|
import { readContract } from '@wagmi/core';
|
|
@@ -6,7 +6,6 @@ import { assert } from 'ts-essentials';
|
|
|
6
6
|
import { PERMIT2_ABI } from '../../utils/abi.js';
|
|
7
7
|
import { PERMIT2_ADDRESS } from '../../utils/construct.js';
|
|
8
8
|
import { useLogger, getLogger } from '../../../../widget/logger.js';
|
|
9
|
-
import { useQueryClient } from '../../../../lib/queryClient.js';
|
|
10
9
|
|
|
11
10
|
const PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY = "permit2-nonce";
|
|
12
11
|
function usePermit2TransferFromNonce({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePermit2TransferFromNonce.js","sources":["../../../../../src/hooks/permit/hooks/permit2/usePermit2TransferFromNonce.ts"],"sourcesContent":["import {\n useQuery,\n type QueryObserverResult,\n type RefetchOptions,\n} from \"@tanstack/react-query\";\nimport { type Address, maxUint256 } from \"viem\";\nimport { useConfig, type Config } from \"wagmi\";\nimport { readContract } from \"@wagmi/core\";\nimport { assert } from \"ts-essentials\";\nimport { PERMIT2_ABI } from \"../../utils/abi\";\nimport { PERMIT2_ADDRESS } from \"../../utils/construct\";\nimport { getLogger, useLogger } from \"@/widget/logger\";\nimport { useQueryClient } from \"@/lib/queryClient\";\n\n/**\n * Permit2 stores nonces using a nested bitmap structure:\n *\n * mapping(address => mapping(uint256 => uint256)) public nonceBitmap;\n *\n * - The outer key (`address`) is the permit signer (the `owner`)\n * - The inner key (`uint256 word`) is the index of a 256-bit \"page\"\n * - The value (`uint256`) is the bitmap for that page — each bit (0 to 255) represents a nonce\n * - If bit `i` is `0`, then nonce `word * 256 + i` is **unused**\n * - If bit `i` is `1`, then that nonce has **already been used**\n *\n * This is what enables Permit2 to support unordered nonces while saving gas.\n */\n\n// Result of finding an available nonce\ntype NonceState = {\n word: bigint; // which 256-bit \"page\" of the bitmap we used\n bitmap: bigint; // the bitmap for that word\n nonce: bigint; // full 256-based offset: word * 256 + bit index\n};\n\nconst PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY = \"permit2-nonce\";\n\ntype Permit2TransferFromQueryKey = [\n typeof PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY,\n owner?: Address,\n chainId?: number,\n];\n\ninterface UsePermit2TransferFromNonceOptions {\n owner?: Address;\n chainId?: number;\n initWord?: bigint; // word offset to begin scanning from\n enabled?: boolean;\n}\n\nexport type UsePermit2TransferFromNonceResult = {\n // null when no can't calculate Permit2 nonce\n nonceToUse?: bigint | null;\n nonceState?: NonceState | null;\n isLoading: boolean;\n isError: boolean;\n isSuccess: boolean;\n error: Error | null;\n refetch: (\n options?: RefetchOptions\n ) => Promise<QueryObserverResult<NonceState | null, Error>>;\n};\n\n/**\n * React hook to find the next unused Permit2 nonce for `permitTransferFrom`.\n *\n * Permit2 stores nonces as a bitmap:\n * - Each address has a mapping from uint256 => uint256\n * - Each value is a 256-bit bitmap (called a \"word\")\n * - If a bit is 1, the nonce (word * 256 + bit index) is used\n * - If it's 0, it's free and can be used\n */\nexport function usePermit2TransferFromNonce({\n owner,\n chainId,\n initWord = 0n,\n enabled = true,\n}: UsePermit2TransferFromNonceOptions) {\n const queryClient = useQueryClient();\n const config = useConfig();\n const logger = useLogger(\"PERMIT2::TransferFromNonce\");\n\n const queryKey: Permit2TransferFromQueryKey = [\n PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY,\n owner,\n chainId,\n ];\n\n const {\n data: nonceState,\n isLoading,\n isError,\n isSuccess,\n error,\n refetch,\n } = useQuery<\n NonceState | null,\n Error,\n NonceState | null,\n Permit2TransferFromQueryKey\n >({\n enabled: enabled && !!(owner && chainId),\n\n queryKey,\n\n queryFn: async () => {\n // Safety checks\n assert(owner, \"owner is required\");\n assert(chainId, \"chainId is required\");\n\n // Try to resume scanning from last known state if available\n const last = queryClient.getQueryData<NonceState>(queryKey);\n\n // Find a bitmap word that has at least one unused bit (i.e. a usable nonce)\n const nextOpenWord = await getNextOpenWord({\n owner,\n config,\n startWord: last?.word ?? initWord,\n });\n\n if (!nextOpenWord) {\n logger.warn(\"No available nonce found\");\n return null;\n }\n\n const { word, bitmap } = nextOpenWord;\n // Identify the first 0-bit in the bitmap — that’s our next nonce\n const bitPos = getFirstUnsetBit(bitmap);\n if (bitPos === -1) {\n logger.warn(\"No available nonce found\");\n return null;\n }\n\n const nonceState = {\n word,\n bitmap,\n nonce: word * 256n + BigInt(bitPos),\n };\n\n logger.log(\"nonceState\", nonceState);\n\n // The final usable nonce is: word * 256 + bit index\n return nonceState;\n },\n\n // Useful defaults\n refetchOnWindowFocus: false,\n notifyOnChangeProps: [\"data\", \"isLoading\"],\n });\n\n return {\n nonceState,\n nonceToUse: nonceState === null ? null : nonceState?.nonce,\n isLoading,\n isError,\n isSuccess,\n error,\n refetch,\n };\n}\n\ninterface GetNextOpenWordInput {\n owner: Address;\n config: Config;\n startWord: bigint;\n}\n\n/**\n * Scans bitmap word-by-word starting at `startWord` until it finds\n * one with at least one unused bit (i.e., not all bits are set to 1).\n */\nasync function getNextOpenWord({\n owner,\n config,\n startWord,\n}: GetNextOpenWordInput): Promise<{ word: bigint; bitmap: bigint } | null> {\n let word = startWord;\n const MAX = maxUint256; // full 256-bit word (0xffff...ffff)\n\n while (true) {\n // Read the bitmap word for the given owner and word index\n const bitmap = await readContract(config, {\n address: PERMIT2_ADDRESS,\n abi: PERMIT2_ABI,\n functionName: \"nonceBitmap\",\n args: [owner, word],\n });\n\n // If the bitmap is not fully used (i.e., not all bits are 1)\n if (bitmap !== MAX) {\n return { word, bitmap };\n }\n\n word += 1n;\n\n // Fail-safe: don't scan more than 1024 words (262,144 nonces)\n if (word - startWord > 1024n) {\n getLogger(\"PERMIT2::getNextOpenWord\").warn(\"Exceeded nonce search limit\");\n return null;\n }\n }\n}\n\n/**\n * Returns the index (0–255) of the first unset (zero) bit in a 256-bit bitmap.\n *\n * Uses a classic bit-hack: (~bitmap) & (bitmap + 1)\n *\n * This produces a bitmask with only the lowest 0-bit set to 1.\n * Example:\n * bitmap = 0b1110 → unset bit at index 0\n * ~bitmap = 0b...0001\n * bitmap + 1 = 0b1111\n * result = 0b0001 → bitmask for index 0\n *\n * We then convert the bitmask to binary and count how many bits it takes\n * to shift that 1 into place = its position.\n */\nfunction getFirstUnsetBit(bitmap: bigint): number {\n // Create a bitmask with a 1 only at the first 0-bit (LSB side)\n const mask = ~bitmap & (bitmap + 1n);\n\n // If all bits are set (mask is zero), there are no available nonces\n if (mask === 0n) return -1;\n\n // Convert mask to binary and count digits – the length is the index + 1\n // e.g. mask = 0b1000 → \"1000\" → length = 4 → index = 3\n return mask.toString(2).length - 1;\n}\n\n/////// MARK NONCE AS USED ///////\n\ntype SetNonceInput = {\n owner: Address;\n chainId: number;\n usedNonce: bigint;\n};\n\ntype UseMarkNonceAsUsedResult = {\n /**\n * Mark a nonce as \"used\" in the local cache after submitting a transaction or order\n * This prevents reuse of the same nonce while it's still pending on-chain.\n */\n markNonceAsUsed: (input: SetNonceInput) => void;\n};\n\n/**\n * Hook to manually bump the locally cached Permit2 nonce to avoid reuse\n *\n * Permit2 allows unordered nonces, but while a tx is pending, it's safer to use\n * a strictly increasing nonce to avoid accidental replays or reuse.\n *\n * clearing an unsued nonce is not necessary because nonces are unordered\n */\nexport function useMarkNonceAsUsed(): UseMarkNonceAsUsedResult {\n const queryClient = useQueryClient();\n\n const markNonceAsUsed: UseMarkNonceAsUsedResult[\"markNonceAsUsed\"] = ({\n owner,\n chainId,\n usedNonce,\n }) => {\n const queryKey: Permit2TransferFromQueryKey = [\n PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY,\n owner,\n chainId,\n ];\n\n // Update cached nonce state if the used nonce was >= current one\n queryClient.setQueryData<NonceState>(queryKey, (oldNonceState) => {\n if (!oldNonceState) return oldNonceState; // should not happen unless cache was cleared\n\n // If we're already past this nonce, nothing to do\n if (oldNonceState.nonce > usedNonce) return oldNonceState;\n\n const newNonce = oldNonceState.nonce + 1n;\n const { word, bitPos } = splitNonce(newNonce);\n\n return {\n word,\n bitmap: 1n << bitPos, // ✅ convert bit index to actual 256-bit bitmap\n nonce: newNonce,\n };\n });\n };\n\n return {\n markNonceAsUsed,\n };\n}\n\n/**\n * Splits a Permit2 nonce into:\n * - `word`: which 256-bit bitmap page (nonce / 256)\n * - `bitPos`: position within that word (nonce % 256)\n */\nfunction splitNonce(nonce: bigint): { word: bigint; bitPos: bigint } {\n const word = nonce / 256n;\n const bitPos = nonce % 256n;\n return { word, bitPos };\n}\n"],"names":["PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY","usePermit2TransferFromNonce","owner","chainId","initWord","enabled","queryClient","useQueryClient","config","useConfig","logger","useLogger","queryKey","data","nonceState","isLoading","isError","isSuccess","error","refetch","useQuery","queryFn","assert","last","getQueryData","nextOpenWord","getNextOpenWord","startWord","word","warn","bitmap","bitPos","getFirstUnsetBit","nonce","BigInt","log","refetchOnWindowFocus","notifyOnChangeProps","nonceToUse","MAX","maxUint256","readContract","address","PERMIT2_ADDRESS","abi","PERMIT2_ABI","functionName","args","getLogger","mask","toString","length","useMarkNonceAsUsed","markNonceAsUsed","usedNonce","setQueryData","oldNonceState","newNonce","splitNonce"],"mappings":";;;;;;;;;;AAmCA,MAAMA,qCAAAA,GAAwC,eAAA;AAqCvC,SAASC,2BAAAA,CAA4B;AAAA,EAC1CC,KAAAA;AAAAA,EACAC,OAAAA;AAAAA,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AAAA;AAAAA,QACdE,KAAAA,EAAOwB;AAAAA,OACT;AAAA,KACD,CAAA;AAAA,GACH;AAEA,EAAA,OAAO;AAAA,IACLJ;AAAAA,GACF;AACF;AAOA,SAASK,WAAWzB,KAAAA,EAAiD;AACnE,EAAA,MAAML,OAAOK,KAAAA,GAAQ,IAAA;AACrB,EAAA,MAAMF,SAASE,KAAAA,GAAQ,IAAA;AACvB,EAAA,OAAO;AAAA,IAAEL,IAAAA;AAAAA,IAAMG;AAAAA,GAAO;AACxB;;;;"}
|
|
1
|
+
{"version":3,"file":"usePermit2TransferFromNonce.js","sources":["../../../../../src/hooks/permit/hooks/permit2/usePermit2TransferFromNonce.ts"],"sourcesContent":["import {\n useQuery,\n useQueryClient,\n type QueryObserverResult,\n type RefetchOptions,\n} from \"@tanstack/react-query\";\nimport { type Address, maxUint256 } from \"viem\";\nimport { useConfig, type Config } from \"wagmi\";\nimport { readContract } from \"@wagmi/core\";\nimport { assert } from \"ts-essentials\";\nimport { PERMIT2_ABI } from \"../../utils/abi\";\nimport { PERMIT2_ADDRESS } from \"../../utils/construct\";\nimport { getLogger, useLogger } from \"@/widget/logger\";\n\n/**\n * Permit2 stores nonces using a nested bitmap structure:\n *\n * mapping(address => mapping(uint256 => uint256)) public nonceBitmap;\n *\n * - The outer key (`address`) is the permit signer (the `owner`)\n * - The inner key (`uint256 word`) is the index of a 256-bit \"page\"\n * - The value (`uint256`) is the bitmap for that page — each bit (0 to 255) represents a nonce\n * - If bit `i` is `0`, then nonce `word * 256 + i` is **unused**\n * - If bit `i` is `1`, then that nonce has **already been used**\n *\n * This is what enables Permit2 to support unordered nonces while saving gas.\n */\n\n// Result of finding an available nonce\ntype NonceState = {\n word: bigint; // which 256-bit \"page\" of the bitmap we used\n bitmap: bigint; // the bitmap for that word\n nonce: bigint; // full 256-based offset: word * 256 + bit index\n};\n\nconst PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY = \"permit2-nonce\";\n\ntype Permit2TransferFromQueryKey = [\n typeof PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY,\n owner?: Address,\n chainId?: number,\n];\n\ninterface UsePermit2TransferFromNonceOptions {\n owner?: Address;\n chainId?: number;\n initWord?: bigint; // word offset to begin scanning from\n enabled?: boolean;\n}\n\nexport type UsePermit2TransferFromNonceResult = {\n // null when no can't calculate Permit2 nonce\n nonceToUse?: bigint | null;\n nonceState?: NonceState | null;\n isLoading: boolean;\n isError: boolean;\n isSuccess: boolean;\n error: Error | null;\n refetch: (\n options?: RefetchOptions\n ) => Promise<QueryObserverResult<NonceState | null, Error>>;\n};\n\n/**\n * React hook to find the next unused Permit2 nonce for `permitTransferFrom`.\n *\n * Permit2 stores nonces as a bitmap:\n * - Each address has a mapping from uint256 => uint256\n * - Each value is a 256-bit bitmap (called a \"word\")\n * - If a bit is 1, the nonce (word * 256 + bit index) is used\n * - If it's 0, it's free and can be used\n */\nexport function usePermit2TransferFromNonce({\n owner,\n chainId,\n initWord = 0n,\n enabled = true,\n}: UsePermit2TransferFromNonceOptions) {\n const queryClient = useQueryClient();\n const config = useConfig();\n const logger = useLogger(\"PERMIT2::TransferFromNonce\");\n\n const queryKey: Permit2TransferFromQueryKey = [\n PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY,\n owner,\n chainId,\n ];\n\n const {\n data: nonceState,\n isLoading,\n isError,\n isSuccess,\n error,\n refetch,\n } = useQuery<\n NonceState | null,\n Error,\n NonceState | null,\n Permit2TransferFromQueryKey\n >({\n enabled: enabled && !!(owner && chainId),\n\n queryKey,\n\n queryFn: async () => {\n // Safety checks\n assert(owner, \"owner is required\");\n assert(chainId, \"chainId is required\");\n\n // Try to resume scanning from last known state if available\n const last = queryClient.getQueryData<NonceState>(queryKey);\n\n // Find a bitmap word that has at least one unused bit (i.e. a usable nonce)\n const nextOpenWord = await getNextOpenWord({\n owner,\n config,\n startWord: last?.word ?? initWord,\n });\n\n if (!nextOpenWord) {\n logger.warn(\"No available nonce found\");\n return null;\n }\n\n const { word, bitmap } = nextOpenWord;\n // Identify the first 0-bit in the bitmap — that’s our next nonce\n const bitPos = getFirstUnsetBit(bitmap);\n if (bitPos === -1) {\n logger.warn(\"No available nonce found\");\n return null;\n }\n\n const nonceState = {\n word,\n bitmap,\n nonce: word * 256n + BigInt(bitPos),\n };\n\n logger.log(\"nonceState\", nonceState);\n\n // The final usable nonce is: word * 256 + bit index\n return nonceState;\n },\n\n // Useful defaults\n refetchOnWindowFocus: false,\n notifyOnChangeProps: [\"data\", \"isLoading\"],\n });\n\n return {\n nonceState,\n nonceToUse: nonceState === null ? null : nonceState?.nonce,\n isLoading,\n isError,\n isSuccess,\n error,\n refetch,\n };\n}\n\ninterface GetNextOpenWordInput {\n owner: Address;\n config: Config;\n startWord: bigint;\n}\n\n/**\n * Scans bitmap word-by-word starting at `startWord` until it finds\n * one with at least one unused bit (i.e., not all bits are set to 1).\n */\nasync function getNextOpenWord({\n owner,\n config,\n startWord,\n}: GetNextOpenWordInput): Promise<{ word: bigint; bitmap: bigint } | null> {\n let word = startWord;\n const MAX = maxUint256; // full 256-bit word (0xffff...ffff)\n\n while (true) {\n // Read the bitmap word for the given owner and word index\n const bitmap = await readContract(config, {\n address: PERMIT2_ADDRESS,\n abi: PERMIT2_ABI,\n functionName: \"nonceBitmap\",\n args: [owner, word],\n });\n\n // If the bitmap is not fully used (i.e., not all bits are 1)\n if (bitmap !== MAX) {\n return { word, bitmap };\n }\n\n word += 1n;\n\n // Fail-safe: don't scan more than 1024 words (262,144 nonces)\n if (word - startWord > 1024n) {\n getLogger(\"PERMIT2::getNextOpenWord\").warn(\"Exceeded nonce search limit\");\n return null;\n }\n }\n}\n\n/**\n * Returns the index (0–255) of the first unset (zero) bit in a 256-bit bitmap.\n *\n * Uses a classic bit-hack: (~bitmap) & (bitmap + 1)\n *\n * This produces a bitmask with only the lowest 0-bit set to 1.\n * Example:\n * bitmap = 0b1110 → unset bit at index 0\n * ~bitmap = 0b...0001\n * bitmap + 1 = 0b1111\n * result = 0b0001 → bitmask for index 0\n *\n * We then convert the bitmask to binary and count how many bits it takes\n * to shift that 1 into place = its position.\n */\nfunction getFirstUnsetBit(bitmap: bigint): number {\n // Create a bitmask with a 1 only at the first 0-bit (LSB side)\n const mask = ~bitmap & (bitmap + 1n);\n\n // If all bits are set (mask is zero), there are no available nonces\n if (mask === 0n) return -1;\n\n // Convert mask to binary and count digits – the length is the index + 1\n // e.g. mask = 0b1000 → \"1000\" → length = 4 → index = 3\n return mask.toString(2).length - 1;\n}\n\n/////// MARK NONCE AS USED ///////\n\ntype SetNonceInput = {\n owner: Address;\n chainId: number;\n usedNonce: bigint;\n};\n\ntype UseMarkNonceAsUsedResult = {\n /**\n * Mark a nonce as \"used\" in the local cache after submitting a transaction or order\n * This prevents reuse of the same nonce while it's still pending on-chain.\n */\n markNonceAsUsed: (input: SetNonceInput) => void;\n};\n\n/**\n * Hook to manually bump the locally cached Permit2 nonce to avoid reuse\n *\n * Permit2 allows unordered nonces, but while a tx is pending, it's safer to use\n * a strictly increasing nonce to avoid accidental replays or reuse.\n *\n * clearing an unsued nonce is not necessary because nonces are unordered\n */\nexport function useMarkNonceAsUsed(): UseMarkNonceAsUsedResult {\n const queryClient = useQueryClient();\n\n const markNonceAsUsed: UseMarkNonceAsUsedResult[\"markNonceAsUsed\"] = ({\n owner,\n chainId,\n usedNonce,\n }) => {\n const queryKey: Permit2TransferFromQueryKey = [\n PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY,\n owner,\n chainId,\n ];\n\n // Update cached nonce state if the used nonce was >= current one\n queryClient.setQueryData<NonceState>(queryKey, (oldNonceState) => {\n if (!oldNonceState) return oldNonceState; // should not happen unless cache was cleared\n\n // If we're already past this nonce, nothing to do\n if (oldNonceState.nonce > usedNonce) return oldNonceState;\n\n const newNonce = oldNonceState.nonce + 1n;\n const { word, bitPos } = splitNonce(newNonce);\n\n return {\n word,\n bitmap: 1n << bitPos, // ✅ convert bit index to actual 256-bit bitmap\n nonce: newNonce,\n };\n });\n };\n\n return {\n markNonceAsUsed,\n };\n}\n\n/**\n * Splits a Permit2 nonce into:\n * - `word`: which 256-bit bitmap page (nonce / 256)\n * - `bitPos`: position within that word (nonce % 256)\n */\nfunction splitNonce(nonce: bigint): { word: bigint; bitPos: bigint } {\n const word = nonce / 256n;\n const bitPos = nonce % 256n;\n return { word, bitPos };\n}\n"],"names":["PERMIT2_TRANSFER_FROM_NONCE_QUERY_KEY","usePermit2TransferFromNonce","owner","chainId","initWord","enabled","queryClient","useQueryClient","config","useConfig","logger","useLogger","queryKey","data","nonceState","isLoading","isError","isSuccess","error","refetch","useQuery","queryFn","assert","last","getQueryData","nextOpenWord","getNextOpenWord","startWord","word","warn","bitmap","bitPos","getFirstUnsetBit","nonce","BigInt","log","refetchOnWindowFocus","notifyOnChangeProps","nonceToUse","MAX","maxUint256","readContract","address","PERMIT2_ADDRESS","abi","PERMIT2_ABI","functionName","args","getLogger","mask","toString","length","useMarkNonceAsUsed","markNonceAsUsed","usedNonce","setQueryData","oldNonceState","newNonce","splitNonce"],"mappings":";;;;;;;;;AAmCA,MAAMA,qCAAAA,GAAwC,eAAA;AAqCvC,SAASC,2BAAAA,CAA4B;AAAA,EAC1CC,KAAAA;AAAAA,EACAC,OAAAA;AAAAA,EACAC,QAAAA,GAAW,EAAA;AAAA,EACXC,OAAAA,GAAU;AACwB,CAAA,EAAG;AACrC,EAAA,MAAMC,cAAcC,cAAAA,EAAe;AACnC,EAAA,MAAMC,SAASC,SAAAA,EAAU;AACzB,EAAA,MAAMC,MAAAA,GAASC,UAAU,4BAA4B,CAAA;AAErD,EAAA,MAAMC,QAAAA,GAAwC,CAC5CZ,qCAAAA,EACAE,KAAAA,EACAC,OAAO,CAAA;AAGT,EAAA,MAAM;AAAA,IACJU,IAAAA,EAAMC,YAAAA;AAAAA,IACNC,SAAAA;AAAAA,IACAC,OAAAA;AAAAA,IACAC,SAAAA;AAAAA,IACAC,KAAAA;AAAAA,IACAC;AAAAA,MACEC,QAAAA,CAKF;AAA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names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useWatchDeltaOrder.d.ts","sourceRoot":"","sources":["../../../../../../src/hooks/swap/prices/delta/queries/useWatchDeltaOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAQ1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAOpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAWhF,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,GAAG,IAAI,CAAC;AA8H/D,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC3D,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACzD,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,YAAY,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC;IAC9E,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC;CACrE,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,OAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,8BAA8B,GAAG,cAAc,CAAC,uBAAuB,CAAC,CA0C1E;AAED,KAAK,qBAAqB,GAAG,CAAC,OAA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,gCAAgC,GAAG,cAAc,CAAC,sBAAsB,CAAC,EAAE,CAuE7E"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { d as distExports } from '../../../../../_virtual/index.js';
|
|
2
|
-
import { useQuery, QueryObserver } from '@tanstack/react-query';
|
|
2
|
+
import { useQuery, useQueryClient, QueryObserver } from '@tanstack/react-query';
|
|
3
3
|
import { useRef, useLayoutEffect, useMemo } from 'react';
|
|
4
4
|
import { assert } from 'ts-essentials';
|
|
5
5
|
import { useDeltaSDK } from '../../../../useSDK.js';
|
|
6
6
|
import { isMetaWithTimeStart } from '../bridge/utils.js';
|
|
7
7
|
import { DeltaOrderStatusChecker, isExecutedDeltaAuction, isFailedDeltaAuction, isOrderExpired } from '../orders/utils.js';
|
|
8
8
|
import { useLogger, getLogger } from '../../../../../widget/logger.js';
|
|
9
|
-
import { useQueryClient } from '../../../../../lib/queryClient.js';
|
|
10
9
|
|
|
11
10
|
const SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX = "single_delta_auction";
|
|
12
11
|
const DELTA_ORDER_POLLING_INTERVAL = 3e3;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWatchDeltaOrder.js","sources":["../../../../../../src/hooks/swap/prices/delta/queries/useWatchDeltaOrder.ts"],"sourcesContent":["import {\n QueryObserver,\n useQueries,\n useQuery,\n type QueryMeta,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { useLayoutEffect, useMemo, useRef } from \"react\";\nimport { assert, type MarkOptional } from \"ts-essentials\";\nimport { useDeltaSDK } from \"@/hooks/useSDK\";\nimport type { DeltaOrderFromAPI } from \"./useDeltaOrders\";\nimport {\n isMetaWithTimeStart,\n type BridgedDepositResponseFailure,\n type BridgedDepositResponseSuccess,\n type GetBridgedDepositStatusInput,\n type RefetchMetaWithTiming,\n} from \"../bridge/utils\";\nimport type { BridgedDepositResponse } from \"../bridge/types\";\nimport { useBridgedDepositStatus } from \"../bridge/useBridgedDeposit\";\nimport type { DeltaAuction } from \"@velora-dex/sdk\";\nimport {\n DeltaOrderStatusChecker,\n isExecutedDeltaAuction,\n isFailedDeltaAuction,\n isOrderExpired,\n} from \"../orders/utils\";\nimport type { ExecutedDeltaAuction, FailedDeltaAuction } from \"../orders/types\";\nimport { getLogger, useLogger } from \"@/widget/logger\";\nimport { useQueryClient } from \"@/lib/queryClient\";\n\n// ------------------------------------ Single Delta Auction -----------------------------------\n\nconst SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX = \"single_delta_auction\";\ntype SingleDeltaAuctionQueryKey = [\n base: typeof SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX,\n orderId?: string,\n];\n\nexport type MaybeVeloraDeltaAuction = DeltaOrderFromAPI | null; // null is when no such Order for orderId\n\ntype UseDeltaAuctionQueryOptions<TData = MaybeVeloraDeltaAuction> =\n UseQueryOptions<\n MaybeVeloraDeltaAuction,\n Error,\n TData,\n SingleDeltaAuctionQueryKey\n >;\n\nconst DELTA_ORDER_POLLING_INTERVAL = 3_000;\n\ntype ConstructDeltaAuctionPollingQueryOptionsInput = {\n orderId?: string;\n enabled?: boolean;\n getAuction(\n orderId: string,\n requestParams: { signal?: AbortSignal }\n ): Promise<MaybeVeloraDeltaAuction>;\n} & Pick<\n UseWatchMultiDeltaAuctions,\n | \"onAuctionSuccess\"\n | \"onAuctionFailure\"\n | \"onUpdatedAuction\"\n | \"onTimeoutGettingOrder\"\n>;\n\nconst LOOK_FOR_ORDER_TIMEOUT = 60_000;\n\nfunction constructDeltaAuctionPollingQueryOptions({\n orderId,\n enabled,\n getAuction,\n onUpdatedAuction,\n onAuctionSuccess,\n onAuctionFailure,\n onTimeoutGettingOrder,\n}: ConstructDeltaAuctionPollingQueryOptionsInput): Pick<\n UseDeltaAuctionQueryOptions<MaybeVeloraDeltaAuction>,\n \"queryKey\" | \"queryFn\" | \"meta\" | \"refetchInterval\" | \"enabled\"\n> {\n const doneState = false;\n\n const isMetaWithDoneState = (\n queryMeta: QueryMeta\n ): queryMeta is { doneState: boolean } => {\n return \"doneState\" in queryMeta && typeof queryMeta.doneState === \"boolean\";\n };\n\n // queryOptions has to be memoized, otherwise queryMeta is updated on each render,\n // including startedQueryAt\n const meta: RefetchMetaWithTiming & {\n doneState: boolean;\n } = {\n startedQueryAt: Date.now(),\n doneState,\n };\n\n return {\n queryKey: [SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX, orderId],\n queryFn: ({ signal }) => {\n assert(orderId, \"orderId is required\");\n return getAuction(orderId, { signal });\n },\n meta,\n refetchInterval: (query) => {\n const maybeOrder = query.state.data;\n\n const queryMeta = query.options.meta;\n // refetchInterval is called on each render, regardless of queryOptions memoizations.\n // @TODO rework Watch Order logic to avoid callbacks inside refetchInterval,\n // or do away with these callbacks, they are unused currently.\n const isWithDoneState = !!queryMeta && isMetaWithDoneState(queryMeta);\n if (isWithDoneState && queryMeta.doneState) {\n getLogger(\"DeltaAuctionPollingQueryOptions\").log(\n \"Shortcut return for refetchInterval\"\n );\n return false;\n }\n\n // Order could have an updated status during its lifecycle\n if (maybeOrder) onUpdatedAuction?.(maybeOrder);\n\n // Order done with one way or the other\n if (\n maybeOrder &&\n DeltaOrderStatusChecker.completed.has(maybeOrder.status)\n ) {\n // Crosschain Orders are considered executed when both srcChain and destChain are executed\n if (isExecutedDeltaAuction(maybeOrder)) {\n onAuctionSuccess?.(maybeOrder);\n if (isWithDoneState) {\n queryMeta.doneState = true;\n }\n return false; // stop polling\n }\n if (isFailedDeltaAuction(maybeOrder) || isOrderExpired(maybeOrder)) {\n onAuctionFailure?.(maybeOrder);\n if (isWithDoneState) {\n queryMeta.doneState = true;\n }\n return false; // stop polling\n }\n }\n\n if (maybeOrder === null && queryMeta && isMetaWithTimeStart(queryMeta)) {\n // no Order for this orderId for a long time\n const elapsed = Date.now() - queryMeta.startedQueryAt;\n if (elapsed > LOOK_FOR_ORDER_TIMEOUT) {\n assert(orderId, \"orderId is required\");\n onTimeoutGettingOrder?.({ id: orderId });\n if (isWithDoneState) {\n queryMeta.doneState = true;\n }\n return false; // stop polling after 1 minute\n }\n }\n\n return DELTA_ORDER_POLLING_INTERVAL; // default interval for both crosschain and singlechain Orders\n },\n enabled: !!orderId && enabled,\n };\n}\n\n// ----------------- Single Delta Query -----------------------------------\n\ntype UseWatchDeltaAuctionQueryInput = {\n orderId?: string;\n enabled?: boolean;\n onAuctionSuccess?: (auction: ExecutedDeltaAuction) => void;\n onAuctionFailure?: (auction: FailedDeltaAuction) => void;\n onUpdatedAuction?: (auction: MarkOptional<DeltaAuction, \"signature\">) => void;\n onTimeoutGettingOrder?: (auction: Pick<DeltaAuction, \"id\">) => void;\n};\n\nexport function useWatchDeltaAuction({\n orderId,\n enabled = true,\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n}: UseWatchDeltaAuctionQueryInput): UseQueryResult<MaybeVeloraDeltaAuction> {\n const { sdk } = useDeltaSDK({ chainId: 1 }); // chain doesn't matter\n\n const callbacksRef = useRef({\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n });\n\n useLayoutEffect(() => {\n callbacksRef.current = {\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n };\n }, [\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n ]);\n\n const queryOptions = useMemo(() => {\n return constructDeltaAuctionPollingQueryOptions({\n orderId,\n enabled,\n getAuction: sdk.getDeltaOrderById,\n onUpdatedAuction: callbacksRef.current.onUpdatedAuction,\n onAuctionSuccess: callbacksRef.current.onAuctionSuccess,\n onAuctionFailure: callbacksRef.current.onAuctionFailure,\n onTimeoutGettingOrder: callbacksRef.current.onTimeoutGettingOrder,\n });\n }, [orderId, enabled, sdk.getDeltaOrderById]);\n\n return useQuery<\n MaybeVeloraDeltaAuction,\n Error,\n MaybeVeloraDeltaAuction,\n SingleDeltaAuctionQueryKey\n >(queryOptions);\n}\n\ntype EnsureOrderExecutedFn = (options: {\n orderId: string;\n signal?: AbortSignal;\n}) => Promise<MaybeVeloraDeltaAuction>;\n\nexport function useEnsureDeltaOrderExecuted(): EnsureOrderExecutedFn {\n const queryClient = useQueryClient();\n const logger = useLogger(\"EnsureDeltaOrderExecuted\");\n\n const ensureOrderSent: EnsureOrderExecutedFn = async ({\n orderId,\n signal,\n }): Promise<MaybeVeloraDeltaAuction> => {\n const queryKey: SingleDeltaAuctionQueryKey = [\n SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX,\n orderId,\n ];\n\n const observer = new QueryObserver<\n MaybeVeloraDeltaAuction,\n Error,\n MaybeVeloraDeltaAuction,\n SingleDeltaAuctionQueryKey\n >(queryClient, {\n queryKey,\n enabled: false, // no queryFn, just subscription\n // @TODO consider if we want queryFn to have refetching separate from useDeltaFlow\n });\n\n const promise = new Promise<MaybeVeloraDeltaAuction>((resolve, reject) => {\n const startedQueryAt = Date.now();\n\n // don't leave the promise and therefore the observer hanging,\n // if useWatchDeltaAuction doesn't finish its job and stops triggering the subscription\n let timeout: NodeJS.Timeout | null = setTimeout(() => {\n logger.log(\"QueryObserver\", queryKey, \"timeout\");\n unsubscribe();\n reject(new Error(`Order ${orderId} not found`));\n }, LOOK_FOR_ORDER_TIMEOUT + 1000); // a bit of jitter time\n\n signal?.addEventListener(\"abort\", () => {\n if (timeout) {\n clearTimeout(timeout);\n }\n unsubscribe();\n reject(new Error(`Order execution aborted: ${signal.reason}`));\n });\n\n const unsubscribe = observer.subscribe((result) => {\n const cleanup = () => {\n logger.log(\"QueryObserver\", queryKey, \"cleanup\");\n unsubscribe();\n };\n\n logger.log(\"QueryObserver\", queryKey, result);\n\n const maybeOrder = result.data;\n\n if (maybeOrder && timeout !== null) {\n // Order fetched at least once\n clearTimeout(timeout);\n timeout = null;\n }\n\n // Order done with one way or the other\n if (\n maybeOrder &&\n DeltaOrderStatusChecker.completed.has(maybeOrder.status)\n ) {\n // Crosschain Orders are considered executed when both srcChain and destChain are executed\n if (isExecutedDeltaAuction(maybeOrder)) {\n cleanup();\n resolve(maybeOrder);\n return;\n }\n if (isFailedDeltaAuction(maybeOrder)) {\n cleanup();\n reject(maybeOrder);\n return;\n }\n }\n\n if (maybeOrder === null) {\n // no Order for this orderId for a long time\n const elapsed = Date.now() - startedQueryAt;\n if (elapsed > LOOK_FOR_ORDER_TIMEOUT) {\n cleanup();\n reject(new Error(`Order ${orderId} not found`));\n return;\n }\n }\n if (result.error) {\n cleanup();\n reject(result.error);\n return;\n }\n });\n });\n\n return promise;\n };\n\n return ensureOrderSent;\n}\n\n// ----------------- Multi Delta Queries -----------------------------------\n\ntype UseWatchMultiDeltaAuctions = {\n orderIds: string[];\n enabled?: boolean;\n onAuctionSuccess?: (auction: ExecutedDeltaAuction) => void;\n onAuctionFailure?: (auction: FailedDeltaAuction) => void;\n onUpdatedAuction?: (auction: MarkOptional<DeltaAuction, \"signature\">) => void;\n onTimeoutGettingOrder?: (auction: Pick<DeltaAuction, \"id\">) => void;\n};\n\nexport function useWatchMultiDeltaAuctions({\n orderIds,\n enabled = true,\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n}: UseWatchMultiDeltaAuctions): UseQueryResult<MaybeVeloraDeltaAuction>[] {\n const { sdk } = useDeltaSDK({ chainId: 1 }); // chain doesn't matter\n\n const callbacksRef = useRef({\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n });\n\n useLayoutEffect(() => {\n callbacksRef.current = {\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n };\n }, [\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n ]);\n\n const queries = useMemo<\n UseDeltaAuctionQueryOptions<MaybeVeloraDeltaAuction>[]\n >(\n () =>\n orderIds.map((orderId) =>\n constructDeltaAuctionPollingQueryOptions({\n orderId,\n enabled,\n getAuction: sdk.getDeltaOrderById,\n onUpdatedAuction: callbacksRef.current.onUpdatedAuction,\n onAuctionSuccess: callbacksRef.current.onAuctionSuccess,\n onAuctionFailure: callbacksRef.current.onAuctionFailure,\n onTimeoutGettingOrder: callbacksRef.current.onTimeoutGettingOrder,\n })\n ),\n [enabled, orderIds, sdk.getDeltaOrderById]\n );\n\n const auctionsResults = useQueries({ queries });\n\n return auctionsResults;\n}\n\ntype MultiOrdersStatusCrossChainInput = {\n orders: DeltaOrderFromAPI[];\n onAuctionSuccess?: (order: DeltaOrderFromAPI) => void;\n onAuctionFailure?: (order: DeltaOrderFromAPI) => void;\n onUpdatedAuction?: (\n auction: MarkOptional<DeltaAuction, \"signature\">,\n bridgeResponse: BridgedDepositResponse\n ) => void;\n};\n\n// can be used for checking Crosschain Order status checking\n// if status check from API is slow to update\nexport function useWatchMultiOrdersStatusCrossChain({\n orders,\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n}: MultiOrdersStatusCrossChainInput): UseQueryResult<BridgedDepositResponse>[] {\n const { deposits, onNewResponse, onDepositSuccess, onDepositFailure } =\n useMemo(() => {\n const { deposits, depositId2Order } = orders.reduce<{\n deposits: GetBridgedDepositStatusInput[];\n depositId2Order: Record<string, DeltaOrderFromAPI>;\n }>(\n (acc, order) => {\n if (order.bridgeMetadata?.depositId) {\n acc.deposits.push({\n depositId: String(order.bridgeMetadata.depositId),\n originChainId: order.chainId,\n });\n acc.depositId2Order[order.bridgeMetadata.depositId] = order;\n }\n return acc;\n },\n { deposits: [], depositId2Order: {} }\n );\n const onNewResponse = (response: BridgedDepositResponse) => {\n const order = depositId2Order[response.depositId];\n if (order) {\n onUpdatedAuction?.(order, response);\n }\n };\n\n const onDepositSuccess = onAuctionSuccess\n ? (deposit: BridgedDepositResponseSuccess) => {\n const order = depositId2Order[deposit.depositId];\n if (order) {\n const successfulOrder = {\n ...order,\n bridgeStatus: deposit.status,\n bridgeMetadata: {\n ...order.bridgeMetadata,\n fillTx: deposit.fillTx,\n },\n } as DeltaOrderFromAPI; // order.bridgeMetadata should be filled but not according to types\n onAuctionSuccess(successfulOrder);\n }\n }\n : undefined;\n\n const onDepositFailure = onAuctionFailure\n ? (deposit: BridgedDepositResponseFailure) => {\n const order = depositId2Order[deposit.depositId];\n if (order) {\n const failedOrder = {\n ...order,\n bridgeStatus: deposit.status,\n bridgeMetadata: {\n ...order.bridgeMetadata,\n fillTx: deposit.fillTx || undefined,\n },\n } as DeltaOrderFromAPI; // order.bridgeMetadata should be filled but not according to types\n onAuctionFailure(failedOrder);\n }\n }\n : undefined;\n\n return { deposits, onNewResponse, onDepositSuccess, onDepositFailure };\n }, [orders, onAuctionSuccess, onAuctionFailure, onUpdatedAuction]);\n\n const depositStatuses = useBridgedDepositStatus({\n deposits,\n onNewResponse,\n onDepositSuccess,\n onDepositFailure,\n });\n\n return depositStatuses;\n}\n"],"names":["SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX","DELTA_ORDER_POLLING_INTERVAL","LOOK_FOR_ORDER_TIMEOUT","constructDeltaAuctionPollingQueryOptions","orderId","enabled","getAuction","onUpdatedAuction","onAuctionSuccess","onAuctionFailure","onTimeoutGettingOrder","doneState","isMetaWithDoneState","queryMeta","meta","startedQueryAt","Date","now","queryKey","queryFn","signal","assert","refetchInterval","query","maybeOrder","state","data","options","isWithDoneState","getLogger","log","DeltaOrderStatusChecker","completed","has","status","isExecutedDeltaAuction","isFailedDeltaAuction","isOrderExpired","isMetaWithTimeStart","elapsed","id","useWatchDeltaAuction","sdk","useDeltaSDK","chainId","callbacksRef","useRef","useLayoutEffect","current","queryOptions","useMemo","getDeltaOrderById","useQuery","useEnsureDeltaOrderExecuted","$","_c","queryClient","useQueryClient","logger","useLogger","t0","t1","observer","QueryObserver","promise","Promise","resolve","reject","timeout","setTimeout","unsubscribe","Error","addEventListener","clearTimeout","reason","subscribe","result","cleanup","error","ensureOrderSent"],"mappings":";;;;;;;;;;AAkCA,MAA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rC,sBAAAA,EAAyB;AAClC2E,cAAAA,OAAAA,EAAQ;AACRV,cAAAA,MAAAA,KAAMI,KAAAA,CAAW,CAAA,MAAA,EAASnE,OAAO,YAAY,CAAC,CAAA;AAAC,cAAA;AAAA;AAAA;AAAA,UAAA,IAI/CwE,OAAME,KAAAA,EAAA;AACRD,YAAAA,OAAAA,EAAQ;AACRV,YAAAA,MAAAA,CAAOS,OAAME,KAAM,CAAA;AAAC,YAAA;AAAA;AAAA,SAGvB,CAAA;AAAA,OAAE,CAAA;AACF,MAAA,OAEId,OAAAA;AAAAA,KAAO;AACfV,IAAAA,CAAAA,MAAAI,MAAAA;AAAAJ,IAAAA,CAAAA,MAAAE,WAAAA;AAAAF,IAAAA,CAAAA,MAAAM,EAAAA;AAAAA,GAAA,MAAA;AAAAA,IAAAA,EAAAA,GAAAN,EAAA,CAAA,CAAA;AAAA;AA3FD,EAAA,MAAAyB,eAAAA,GAA+CnB,EAAAA;AA2F7C,EAAA,OAEKmB,eAAAA;AAAe;;;;"}
|
|
1
|
+
{"version":3,"file":"useWatchDeltaOrder.js","sources":["../../../../../../src/hooks/swap/prices/delta/queries/useWatchDeltaOrder.ts"],"sourcesContent":["import {\n QueryObserver,\n useQueries,\n useQuery,\n useQueryClient,\n type QueryMeta,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { useLayoutEffect, useMemo, useRef } from \"react\";\nimport { assert, type MarkOptional } from \"ts-essentials\";\nimport { useDeltaSDK } from \"@/hooks/useSDK\";\nimport type { DeltaOrderFromAPI } from \"./useDeltaOrders\";\nimport {\n isMetaWithTimeStart,\n type BridgedDepositResponseFailure,\n type BridgedDepositResponseSuccess,\n type GetBridgedDepositStatusInput,\n type RefetchMetaWithTiming,\n} from \"../bridge/utils\";\nimport type { BridgedDepositResponse } from \"../bridge/types\";\nimport { useBridgedDepositStatus } from \"../bridge/useBridgedDeposit\";\nimport type { DeltaAuction } from \"@velora-dex/sdk\";\nimport {\n DeltaOrderStatusChecker,\n isExecutedDeltaAuction,\n isFailedDeltaAuction,\n isOrderExpired,\n} from \"../orders/utils\";\nimport type { ExecutedDeltaAuction, FailedDeltaAuction } from \"../orders/types\";\nimport { getLogger, useLogger } from \"@/widget/logger\";\n\n// ------------------------------------ Single Delta Auction -----------------------------------\n\nconst SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX = \"single_delta_auction\";\ntype SingleDeltaAuctionQueryKey = [\n base: typeof SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX,\n orderId?: string,\n];\n\nexport type MaybeVeloraDeltaAuction = DeltaOrderFromAPI | null; // null is when no such Order for orderId\n\ntype UseDeltaAuctionQueryOptions<TData = MaybeVeloraDeltaAuction> =\n UseQueryOptions<\n MaybeVeloraDeltaAuction,\n Error,\n TData,\n SingleDeltaAuctionQueryKey\n >;\n\nconst DELTA_ORDER_POLLING_INTERVAL = 3_000;\n\ntype ConstructDeltaAuctionPollingQueryOptionsInput = {\n orderId?: string;\n enabled?: boolean;\n getAuction(\n orderId: string,\n requestParams: { signal?: AbortSignal }\n ): Promise<MaybeVeloraDeltaAuction>;\n} & Pick<\n UseWatchMultiDeltaAuctions,\n | \"onAuctionSuccess\"\n | \"onAuctionFailure\"\n | \"onUpdatedAuction\"\n | \"onTimeoutGettingOrder\"\n>;\n\nconst LOOK_FOR_ORDER_TIMEOUT = 60_000;\n\nfunction constructDeltaAuctionPollingQueryOptions({\n orderId,\n enabled,\n getAuction,\n onUpdatedAuction,\n onAuctionSuccess,\n onAuctionFailure,\n onTimeoutGettingOrder,\n}: ConstructDeltaAuctionPollingQueryOptionsInput): Pick<\n UseDeltaAuctionQueryOptions<MaybeVeloraDeltaAuction>,\n \"queryKey\" | \"queryFn\" | \"meta\" | \"refetchInterval\" | \"enabled\"\n> {\n const doneState = false;\n\n const isMetaWithDoneState = (\n queryMeta: QueryMeta\n ): queryMeta is { doneState: boolean } => {\n return \"doneState\" in queryMeta && typeof queryMeta.doneState === \"boolean\";\n };\n\n // queryOptions has to be memoized, otherwise queryMeta is updated on each render,\n // including startedQueryAt\n const meta: RefetchMetaWithTiming & {\n doneState: boolean;\n } = {\n startedQueryAt: Date.now(),\n doneState,\n };\n\n return {\n queryKey: [SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX, orderId],\n queryFn: ({ signal }) => {\n assert(orderId, \"orderId is required\");\n return getAuction(orderId, { signal });\n },\n meta,\n refetchInterval: (query) => {\n const maybeOrder = query.state.data;\n\n const queryMeta = query.options.meta;\n // refetchInterval is called on each render, regardless of queryOptions memoizations.\n // @TODO rework Watch Order logic to avoid callbacks inside refetchInterval,\n // or do away with these callbacks, they are unused currently.\n const isWithDoneState = !!queryMeta && isMetaWithDoneState(queryMeta);\n if (isWithDoneState && queryMeta.doneState) {\n getLogger(\"DeltaAuctionPollingQueryOptions\").log(\n \"Shortcut return for refetchInterval\"\n );\n return false;\n }\n\n // Order could have an updated status during its lifecycle\n if (maybeOrder) onUpdatedAuction?.(maybeOrder);\n\n // Order done with one way or the other\n if (\n maybeOrder &&\n DeltaOrderStatusChecker.completed.has(maybeOrder.status)\n ) {\n // Crosschain Orders are considered executed when both srcChain and destChain are executed\n if (isExecutedDeltaAuction(maybeOrder)) {\n onAuctionSuccess?.(maybeOrder);\n if (isWithDoneState) {\n queryMeta.doneState = true;\n }\n return false; // stop polling\n }\n if (isFailedDeltaAuction(maybeOrder) || isOrderExpired(maybeOrder)) {\n onAuctionFailure?.(maybeOrder);\n if (isWithDoneState) {\n queryMeta.doneState = true;\n }\n return false; // stop polling\n }\n }\n\n if (maybeOrder === null && queryMeta && isMetaWithTimeStart(queryMeta)) {\n // no Order for this orderId for a long time\n const elapsed = Date.now() - queryMeta.startedQueryAt;\n if (elapsed > LOOK_FOR_ORDER_TIMEOUT) {\n assert(orderId, \"orderId is required\");\n onTimeoutGettingOrder?.({ id: orderId });\n if (isWithDoneState) {\n queryMeta.doneState = true;\n }\n return false; // stop polling after 1 minute\n }\n }\n\n return DELTA_ORDER_POLLING_INTERVAL; // default interval for both crosschain and singlechain Orders\n },\n enabled: !!orderId && enabled,\n };\n}\n\n// ----------------- Single Delta Query -----------------------------------\n\ntype UseWatchDeltaAuctionQueryInput = {\n orderId?: string;\n enabled?: boolean;\n onAuctionSuccess?: (auction: ExecutedDeltaAuction) => void;\n onAuctionFailure?: (auction: FailedDeltaAuction) => void;\n onUpdatedAuction?: (auction: MarkOptional<DeltaAuction, \"signature\">) => void;\n onTimeoutGettingOrder?: (auction: Pick<DeltaAuction, \"id\">) => void;\n};\n\nexport function useWatchDeltaAuction({\n orderId,\n enabled = true,\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n}: UseWatchDeltaAuctionQueryInput): UseQueryResult<MaybeVeloraDeltaAuction> {\n const { sdk } = useDeltaSDK({ chainId: 1 }); // chain doesn't matter\n\n const callbacksRef = useRef({\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n });\n\n useLayoutEffect(() => {\n callbacksRef.current = {\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n };\n }, [\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n ]);\n\n const queryOptions = useMemo(() => {\n return constructDeltaAuctionPollingQueryOptions({\n orderId,\n enabled,\n getAuction: sdk.getDeltaOrderById,\n onUpdatedAuction: callbacksRef.current.onUpdatedAuction,\n onAuctionSuccess: callbacksRef.current.onAuctionSuccess,\n onAuctionFailure: callbacksRef.current.onAuctionFailure,\n onTimeoutGettingOrder: callbacksRef.current.onTimeoutGettingOrder,\n });\n }, [orderId, enabled, sdk.getDeltaOrderById]);\n\n return useQuery<\n MaybeVeloraDeltaAuction,\n Error,\n MaybeVeloraDeltaAuction,\n SingleDeltaAuctionQueryKey\n >(queryOptions);\n}\n\ntype EnsureOrderExecutedFn = (options: {\n orderId: string;\n signal?: AbortSignal;\n}) => Promise<MaybeVeloraDeltaAuction>;\n\nexport function useEnsureDeltaOrderExecuted(): EnsureOrderExecutedFn {\n const queryClient = useQueryClient();\n const logger = useLogger(\"EnsureDeltaOrderExecuted\");\n\n const ensureOrderSent: EnsureOrderExecutedFn = async ({\n orderId,\n signal,\n }): Promise<MaybeVeloraDeltaAuction> => {\n const queryKey: SingleDeltaAuctionQueryKey = [\n SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX,\n orderId,\n ];\n\n const observer = new QueryObserver<\n MaybeVeloraDeltaAuction,\n Error,\n MaybeVeloraDeltaAuction,\n SingleDeltaAuctionQueryKey\n >(queryClient, {\n queryKey,\n enabled: false, // no queryFn, just subscription\n // @TODO consider if we want queryFn to have refetching separate from useDeltaFlow\n });\n\n const promise = new Promise<MaybeVeloraDeltaAuction>((resolve, reject) => {\n const startedQueryAt = Date.now();\n\n // don't leave the promise and therefore the observer hanging,\n // if useWatchDeltaAuction doesn't finish its job and stops triggering the subscription\n let timeout: NodeJS.Timeout | null = setTimeout(() => {\n logger.log(\"QueryObserver\", queryKey, \"timeout\");\n unsubscribe();\n reject(new Error(`Order ${orderId} not found`));\n }, LOOK_FOR_ORDER_TIMEOUT + 1000); // a bit of jitter time\n\n signal?.addEventListener(\"abort\", () => {\n if (timeout) {\n clearTimeout(timeout);\n }\n unsubscribe();\n reject(new Error(`Order execution aborted: ${signal.reason}`));\n });\n\n const unsubscribe = observer.subscribe((result) => {\n const cleanup = () => {\n logger.log(\"QueryObserver\", queryKey, \"cleanup\");\n unsubscribe();\n };\n\n logger.log(\"QueryObserver\", queryKey, result);\n\n const maybeOrder = result.data;\n\n if (maybeOrder && timeout !== null) {\n // Order fetched at least once\n clearTimeout(timeout);\n timeout = null;\n }\n\n // Order done with one way or the other\n if (\n maybeOrder &&\n DeltaOrderStatusChecker.completed.has(maybeOrder.status)\n ) {\n // Crosschain Orders are considered executed when both srcChain and destChain are executed\n if (isExecutedDeltaAuction(maybeOrder)) {\n cleanup();\n resolve(maybeOrder);\n return;\n }\n if (isFailedDeltaAuction(maybeOrder)) {\n cleanup();\n reject(maybeOrder);\n return;\n }\n }\n\n if (maybeOrder === null) {\n // no Order for this orderId for a long time\n const elapsed = Date.now() - startedQueryAt;\n if (elapsed > LOOK_FOR_ORDER_TIMEOUT) {\n cleanup();\n reject(new Error(`Order ${orderId} not found`));\n return;\n }\n }\n if (result.error) {\n cleanup();\n reject(result.error);\n return;\n }\n });\n });\n\n return promise;\n };\n\n return ensureOrderSent;\n}\n\n// ----------------- Multi Delta Queries -----------------------------------\n\ntype UseWatchMultiDeltaAuctions = {\n orderIds: string[];\n enabled?: boolean;\n onAuctionSuccess?: (auction: ExecutedDeltaAuction) => void;\n onAuctionFailure?: (auction: FailedDeltaAuction) => void;\n onUpdatedAuction?: (auction: MarkOptional<DeltaAuction, \"signature\">) => void;\n onTimeoutGettingOrder?: (auction: Pick<DeltaAuction, \"id\">) => void;\n};\n\nexport function useWatchMultiDeltaAuctions({\n orderIds,\n enabled = true,\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n}: UseWatchMultiDeltaAuctions): UseQueryResult<MaybeVeloraDeltaAuction>[] {\n const { sdk } = useDeltaSDK({ chainId: 1 }); // chain doesn't matter\n\n const callbacksRef = useRef({\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n });\n\n useLayoutEffect(() => {\n callbacksRef.current = {\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n };\n }, [\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n onTimeoutGettingOrder,\n ]);\n\n const queries = useMemo<\n UseDeltaAuctionQueryOptions<MaybeVeloraDeltaAuction>[]\n >(\n () =>\n orderIds.map((orderId) =>\n constructDeltaAuctionPollingQueryOptions({\n orderId,\n enabled,\n getAuction: sdk.getDeltaOrderById,\n onUpdatedAuction: callbacksRef.current.onUpdatedAuction,\n onAuctionSuccess: callbacksRef.current.onAuctionSuccess,\n onAuctionFailure: callbacksRef.current.onAuctionFailure,\n onTimeoutGettingOrder: callbacksRef.current.onTimeoutGettingOrder,\n })\n ),\n [enabled, orderIds, sdk.getDeltaOrderById]\n );\n\n const auctionsResults = useQueries({ queries });\n\n return auctionsResults;\n}\n\ntype MultiOrdersStatusCrossChainInput = {\n orders: DeltaOrderFromAPI[];\n onAuctionSuccess?: (order: DeltaOrderFromAPI) => void;\n onAuctionFailure?: (order: DeltaOrderFromAPI) => void;\n onUpdatedAuction?: (\n auction: MarkOptional<DeltaAuction, \"signature\">,\n bridgeResponse: BridgedDepositResponse\n ) => void;\n};\n\n// can be used for checking Crosschain Order status checking\n// if status check from API is slow to update\nexport function useWatchMultiOrdersStatusCrossChain({\n orders,\n onAuctionSuccess,\n onAuctionFailure,\n onUpdatedAuction,\n}: MultiOrdersStatusCrossChainInput): UseQueryResult<BridgedDepositResponse>[] {\n const { deposits, onNewResponse, onDepositSuccess, onDepositFailure } =\n useMemo(() => {\n const { deposits, depositId2Order } = orders.reduce<{\n deposits: GetBridgedDepositStatusInput[];\n depositId2Order: Record<string, DeltaOrderFromAPI>;\n }>(\n (acc, order) => {\n if (order.bridgeMetadata?.depositId) {\n acc.deposits.push({\n depositId: String(order.bridgeMetadata.depositId),\n originChainId: order.chainId,\n });\n acc.depositId2Order[order.bridgeMetadata.depositId] = order;\n }\n return acc;\n },\n { deposits: [], depositId2Order: {} }\n );\n const onNewResponse = (response: BridgedDepositResponse) => {\n const order = depositId2Order[response.depositId];\n if (order) {\n onUpdatedAuction?.(order, response);\n }\n };\n\n const onDepositSuccess = onAuctionSuccess\n ? (deposit: BridgedDepositResponseSuccess) => {\n const order = depositId2Order[deposit.depositId];\n if (order) {\n const successfulOrder = {\n ...order,\n bridgeStatus: deposit.status,\n bridgeMetadata: {\n ...order.bridgeMetadata,\n fillTx: deposit.fillTx,\n },\n } as DeltaOrderFromAPI; // order.bridgeMetadata should be filled but not according to types\n onAuctionSuccess(successfulOrder);\n }\n }\n : undefined;\n\n const onDepositFailure = onAuctionFailure\n ? (deposit: BridgedDepositResponseFailure) => {\n const order = depositId2Order[deposit.depositId];\n if (order) {\n const failedOrder = {\n ...order,\n bridgeStatus: deposit.status,\n bridgeMetadata: {\n ...order.bridgeMetadata,\n fillTx: deposit.fillTx || undefined,\n },\n } as DeltaOrderFromAPI; // order.bridgeMetadata should be filled but not according to types\n onAuctionFailure(failedOrder);\n }\n }\n : undefined;\n\n return { deposits, onNewResponse, onDepositSuccess, onDepositFailure };\n }, [orders, onAuctionSuccess, onAuctionFailure, onUpdatedAuction]);\n\n const depositStatuses = useBridgedDepositStatus({\n deposits,\n onNewResponse,\n onDepositSuccess,\n onDepositFailure,\n });\n\n return depositStatuses;\n}\n"],"names":["SINGLE_DELTA_AUCTION_QUERY_KEY_PREFIX","DELTA_ORDER_POLLING_INTERVAL","LOOK_FOR_ORDER_TIMEOUT","constructDeltaAuctionPollingQueryOptions","orderId","enabled","getAuction","onUpdatedAuction","onAuctionSuccess","onAuctionFailure","onTimeoutGettingOrder","doneState","isMetaWithDoneState","queryMeta","meta","startedQueryAt","Date","now","queryKey","queryFn","signal","assert","refetchInterval","query","maybeOrder","state","data","options","isWithDoneState","getLogger","log","DeltaOrderStatusChecker","completed","has","status","isExecutedDeltaAuction","isFailedDeltaAuction","isOrderExpired","isMetaWithTimeStart","elapsed","id","useWatchDeltaAuction","sdk","useDeltaSDK","chainId","callbacksRef","useRef","useLayoutEffect","current","queryOptions","useMemo","getDeltaOrderById","useQuery","useEnsureDeltaOrderExecuted","$","_c","queryClient","useQueryClient","logger","useLogger","t0","t1","observer","QueryObserver","promise","Promise","resolve","reject","timeout","setTimeout","unsubscribe","Error","addEventListener","clearTimeout","reason","subscribe","result","cleanup","error","ensureOrderSent"],"mappings":";;;;;;;;;AAkCA,MAAMA,qCAAAA,GAAwC,sBAAA;AAgB9C,MAAMC,4BAAAA,GAA+B,GAAA;AAiBrC,MAAMC,sBAAAA,GAAyB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A,MAAA,EAASnE,OAAO,YAAY,CAAC,CAAA;AAAC,cAAA;AAAA;AAAA;AAAA,UAAA,IAI/CwE,OAAME,KAAAA,EAAA;AACRD,YAAAA,OAAAA,EAAQ;AACRV,YAAAA,MAAAA,CAAOS,OAAME,KAAM,CAAA;AAAC,YAAA;AAAA;AAAA,SAGvB,CAAA;AAAA,OAAE,CAAA;AACF,MAAA,OAEId,OAAAA;AAAAA,KAAO;AACfV,IAAAA,CAAAA,MAAAI,MAAAA;AAAAJ,IAAAA,CAAAA,MAAAE,WAAAA;AAAAF,IAAAA,CAAAA,MAAAM,EAAAA;AAAAA,GAAA,MAAA;AAAAA,IAAAA,EAAAA,GAAAN,EAAA,CAAA,CAAA;AAAA;AA3FD,EAAA,MAAAyB,eAAAA,GAA+CnB,EAAAA;AA2F7C,EAAA,OAEKmB,eAAAA;AAAe;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeltaOrderStepKey } from '../../../components/widget/TradeOverview/steps';
|
|
1
|
+
import { DeltaOrderStep, DeltaOrderStepKey } from '../../../components/widget/TradeOverview/steps';
|
|
2
2
|
import { SubmitDeltaOrderResult, UseDeltaFlowInput, UseDeltaFlowResult } from './useDeltaFlow';
|
|
3
3
|
type UseDeltaSwapStepResult = {
|
|
4
4
|
startDeltaSwap: UseDeltaFlowResult["runDeltaOrderFlow"];
|
|
@@ -6,7 +6,7 @@ type UseDeltaSwapStepResult = {
|
|
|
6
6
|
cancelFlow: UseDeltaFlowResult["cancelFlow"];
|
|
7
7
|
retryFlow: UseDeltaFlowResult["retryFlow"];
|
|
8
8
|
isCancellable: boolean;
|
|
9
|
-
step?:
|
|
9
|
+
step?: DeltaOrderStep;
|
|
10
10
|
explorerLink?: string;
|
|
11
11
|
error: Error | null;
|
|
12
12
|
erroredStep?: DeltaOrderStepKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeltaSwapStep.d.ts","sourceRoot":"","sources":["../../../../src/hooks/swap/tradeFlow/useDeltaSwapStep.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useDeltaSwapStep.d.ts","sourceRoot":"","sources":["../../../../src/hooks/swap/tradeFlow/useDeltaSwapStep.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EAClB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAKxB,KAAK,sBAAsB,GAAG;IAC5B,cAAc,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IAExD,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAC7C,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC3C,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,MAAM,CAAC,EAAE,sBAAsB,CAAC;IAChC,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;CAC5C,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,GACzB,sBAAsB,CAmHxB"}
|