@avail-project/widgets 0.0.1
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/README.md +34 -0
- package/dist/common/components/ErrorBoundary.d.ts +44 -0
- package/dist/common/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/common/components/ErrorBoundary.js +65 -0
- package/dist/common/hooks/useDebouncedCallback.d.ts +13 -0
- package/dist/common/hooks/useDebouncedCallback.d.ts.map +1 -0
- package/dist/common/hooks/useDebouncedCallback.js +42 -0
- package/dist/common/hooks/useDebouncedValue.d.ts +5 -0
- package/dist/common/hooks/useDebouncedValue.d.ts.map +1 -0
- package/dist/common/hooks/useDebouncedValue.js +15 -0
- package/dist/common/hooks/useInterval.d.ts +11 -0
- package/dist/common/hooks/useInterval.d.ts.map +1 -0
- package/dist/common/hooks/useInterval.js +25 -0
- package/dist/common/hooks/useLatest.d.ts +12 -0
- package/dist/common/hooks/useLatest.d.ts.map +1 -0
- package/dist/common/hooks/useLatest.js +19 -0
- package/dist/common/hooks/useNexusError.d.ts +20 -0
- package/dist/common/hooks/useNexusError.d.ts.map +1 -0
- package/dist/common/hooks/useNexusError.js +120 -0
- package/dist/common/hooks/usePolling.d.ts +7 -0
- package/dist/common/hooks/usePolling.d.ts.map +1 -0
- package/dist/common/hooks/usePolling.js +29 -0
- package/dist/common/hooks/useStableCallback.d.ts +6 -0
- package/dist/common/hooks/useStableCallback.d.ts.map +1 -0
- package/dist/common/hooks/useStableCallback.js +13 -0
- package/dist/common/hooks/useStopwatch.d.ts +17 -0
- package/dist/common/hooks/useStopwatch.d.ts.map +1 -0
- package/dist/common/hooks/useStopwatch.js +44 -0
- package/dist/common/hooks/useTransactionExecution.d.ts +62 -0
- package/dist/common/hooks/useTransactionExecution.d.ts.map +1 -0
- package/dist/common/hooks/useTransactionExecution.js +273 -0
- package/dist/common/hooks/useTransactionFlow.d.ts +71 -0
- package/dist/common/hooks/useTransactionFlow.d.ts.map +1 -0
- package/dist/common/hooks/useTransactionFlow.js +435 -0
- package/dist/common/index.d.ts +17 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +16 -0
- package/dist/common/tx/steps.d.ts +19 -0
- package/dist/common/tx/steps.d.ts.map +1 -0
- package/dist/common/tx/steps.js +89 -0
- package/dist/common/tx/types.d.ts +11 -0
- package/dist/common/tx/types.d.ts.map +1 -0
- package/dist/common/tx/types.js +19 -0
- package/dist/common/tx/useTransactionSteps.d.ts +21 -0
- package/dist/common/tx/useTransactionSteps.d.ts.map +1 -0
- package/dist/common/tx/useTransactionSteps.js +40 -0
- package/dist/common/types/transaction-flow.d.ts +48 -0
- package/dist/common/types/transaction-flow.d.ts.map +1 -0
- package/dist/common/types/transaction-flow.js +2 -0
- package/dist/common/utils/constant.d.ts +99 -0
- package/dist/common/utils/constant.d.ts.map +1 -0
- package/dist/common/utils/constant.js +370 -0
- package/dist/common/utils/token-pricing.d.ts +33 -0
- package/dist/common/utils/token-pricing.d.ts.map +1 -0
- package/dist/common/utils/token-pricing.js +255 -0
- package/dist/common/utils/transaction-flow.d.ts +35 -0
- package/dist/common/utils/transaction-flow.d.ts.map +1 -0
- package/dist/common/utils/transaction-flow.js +65 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +8 -0
- package/dist/nexus/NexusProvider.d.ts +50 -0
- package/dist/nexus/NexusProvider.d.ts.map +1 -0
- package/dist/nexus/NexusProvider.js +572 -0
- package/dist/nexus-widget/components/address-identicon.d.ts +5 -0
- package/dist/nexus-widget/components/address-identicon.d.ts.map +1 -0
- package/dist/nexus-widget/components/address-identicon.js +39 -0
- package/dist/nexus-widget/components/amount-input-unified.d.ts +18 -0
- package/dist/nexus-widget/components/amount-input-unified.d.ts.map +1 -0
- package/dist/nexus-widget/components/amount-input-unified.js +88 -0
- package/dist/nexus-widget/components/deposit-idle-form.d.ts +29 -0
- package/dist/nexus-widget/components/deposit-idle-form.d.ts.map +1 -0
- package/dist/nexus-widget/components/deposit-idle-form.js +506 -0
- package/dist/nexus-widget/components/nexus-widget-progress-screen.d.ts +36 -0
- package/dist/nexus-widget/components/nexus-widget-progress-screen.d.ts.map +1 -0
- package/dist/nexus-widget/components/nexus-widget-progress-screen.js +737 -0
- package/dist/nexus-widget/components/pay-using-selector.d.ts +9 -0
- package/dist/nexus-widget/components/pay-using-selector.d.ts.map +1 -0
- package/dist/nexus-widget/components/pay-using-selector.js +37 -0
- package/dist/nexus-widget/components/pay-with-sources.d.ts +11 -0
- package/dist/nexus-widget/components/pay-with-sources.d.ts.map +1 -0
- package/dist/nexus-widget/components/pay-with-sources.js +266 -0
- package/dist/nexus-widget/components/receive-asset-selector.d.ts +28 -0
- package/dist/nexus-widget/components/receive-asset-selector.d.ts.map +1 -0
- package/dist/nexus-widget/components/receive-asset-selector.js +1178 -0
- package/dist/nexus-widget/components/recipient-input.d.ts +10 -0
- package/dist/nexus-widget/components/recipient-input.d.ts.map +1 -0
- package/dist/nexus-widget/components/recipient-input.js +44 -0
- package/dist/nexus-widget/components/send-idle-form.d.ts +29 -0
- package/dist/nexus-widget/components/send-idle-form.d.ts.map +1 -0
- package/dist/nexus-widget/components/send-idle-form.js +548 -0
- package/dist/nexus-widget/components/status-alerts.d.ts +7 -0
- package/dist/nexus-widget/components/status-alerts.d.ts.map +1 -0
- package/dist/nexus-widget/components/status-alerts.js +17 -0
- package/dist/nexus-widget/components/swap-asset-selector.d.ts +74 -0
- package/dist/nexus-widget/components/swap-asset-selector.d.ts.map +1 -0
- package/dist/nexus-widget/components/swap-asset-selector.js +1910 -0
- package/dist/nexus-widget/components/swap-idle-form.d.ts +29 -0
- package/dist/nexus-widget/components/swap-idle-form.d.ts.map +1 -0
- package/dist/nexus-widget/components/swap-idle-form.js +1289 -0
- package/dist/nexus-widget/components/swap-intent-preview.d.ts +95 -0
- package/dist/nexus-widget/components/swap-intent-preview.d.ts.map +1 -0
- package/dist/nexus-widget/components/swap-intent-preview.js +1050 -0
- package/dist/nexus-widget/nexus-widget.d.ts +4 -0
- package/dist/nexus-widget/nexus-widget.d.ts.map +1 -0
- package/dist/nexus-widget/nexus-widget.js +7819 -0
- package/dist/nexus-widget/sdk-types.d.ts +13 -0
- package/dist/nexus-widget/sdk-types.d.ts.map +1 -0
- package/dist/nexus-widget/sdk-types.js +1 -0
- package/dist/nexus-widget/theme.d.ts +156 -0
- package/dist/nexus-widget/theme.d.ts.map +1 -0
- package/dist/nexus-widget/theme.js +159 -0
- package/dist/nexus-widget/types.d.ts +141 -0
- package/dist/nexus-widget/types.d.ts.map +1 -0
- package/dist/nexus-widget/types.js +1 -0
- package/dist/nexus-widget/utils/citrea-tokens.d.ts +82 -0
- package/dist/nexus-widget/utils/citrea-tokens.d.ts.map +1 -0
- package/dist/nexus-widget/utils/citrea-tokens.js +136 -0
- package/dist/nexus-widget/utils/deposit-source-selection.d.ts +55 -0
- package/dist/nexus-widget/utils/deposit-source-selection.d.ts.map +1 -0
- package/dist/nexus-widget/utils/deposit-source-selection.js +219 -0
- package/dist/swaps/components/stacked-token-icons.d.ts +15 -0
- package/dist/swaps/components/stacked-token-icons.d.ts.map +1 -0
- package/dist/swaps/components/stacked-token-icons.js +38 -0
- package/dist/swaps/components/step-flow.d.ts +32 -0
- package/dist/swaps/components/step-flow.d.ts.map +1 -0
- package/dist/swaps/components/step-flow.js +54 -0
- package/dist/swaps/components/token-icon.d.ts +11 -0
- package/dist/swaps/components/token-icon.d.ts.map +1 -0
- package/dist/swaps/components/token-icon.js +16 -0
- package/dist/swaps/components/transaction-progress.d.ts +43 -0
- package/dist/swaps/components/transaction-progress.d.ts.map +1 -0
- package/dist/swaps/components/transaction-progress.js +94 -0
- package/dist/ui/button.d.ts +11 -0
- package/dist/ui/button.d.ts.map +1 -0
- package/dist/ui/button.js +34 -0
- package/dist/ui/dialog.d.ts +17 -0
- package/dist/ui/dialog.d.ts.map +1 -0
- package/dist/ui/dialog.js +47 -0
- package/package.json +60 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import {} from "@avail-project/nexus-core";
|
|
2
|
+
import { useEffect, useMemo, useCallback, useRef, useState, useReducer, } from "react";
|
|
3
|
+
import { isAddress, parseUnits } from "viem";
|
|
4
|
+
import { CHAIN_METADATA } from "../utils/constant";
|
|
5
|
+
import { useNexusError } from "./useNexusError";
|
|
6
|
+
import { useTransactionExecution } from "./useTransactionExecution";
|
|
7
|
+
import { usePolling } from "./usePolling";
|
|
8
|
+
import { useStopwatch } from "./useStopwatch";
|
|
9
|
+
import { useDebouncedCallback } from "./useDebouncedCallback";
|
|
10
|
+
import {} from "../tx/types";
|
|
11
|
+
import { useTransactionSteps } from "../tx/useTransactionSteps";
|
|
12
|
+
import {} from "../types/transaction-flow";
|
|
13
|
+
import { MAX_AMOUNT_DEBOUNCE_MS, buildInitialInputs, clampAmountToMax, formatAmountForDisplay, getCoverageDecimals, normalizeMaxAmount, } from "../utils/transaction-flow";
|
|
14
|
+
export function useTransactionFlow(props) {
|
|
15
|
+
const { type, network, nexusSDK, intent, bridgableBalance, prefill, onComplete, onStart, onError, fetchBalance, allowance, maxAmount, isSourceMenuOpen = false, notifyHistoryRefresh, executeTransaction, } = props;
|
|
16
|
+
const connectedAddress = props.connectedAddress;
|
|
17
|
+
const operationName = type === "bridge" ? "bridge" : "transfer";
|
|
18
|
+
const handleNexusError = useNexusError();
|
|
19
|
+
const initialState = {
|
|
20
|
+
inputs: buildInitialInputs({ type, network, connectedAddress, prefill }),
|
|
21
|
+
status: "idle",
|
|
22
|
+
};
|
|
23
|
+
function reducer(state, action) {
|
|
24
|
+
switch (action.type) {
|
|
25
|
+
case "setInputs":
|
|
26
|
+
return { ...state, inputs: { ...state.inputs, ...action.payload } };
|
|
27
|
+
case "resetInputs":
|
|
28
|
+
return {
|
|
29
|
+
...state,
|
|
30
|
+
inputs: buildInitialInputs({
|
|
31
|
+
type,
|
|
32
|
+
network,
|
|
33
|
+
connectedAddress,
|
|
34
|
+
prefill,
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
case "setStatus":
|
|
38
|
+
return { ...state, status: action.payload };
|
|
39
|
+
default:
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
|
44
|
+
const inputs = state.inputs;
|
|
45
|
+
const setInputs = (next) => {
|
|
46
|
+
dispatch({
|
|
47
|
+
type: "setInputs",
|
|
48
|
+
payload: next,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const loading = state.status === "executing";
|
|
52
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
53
|
+
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
54
|
+
const [txError, setTxError] = useState(null);
|
|
55
|
+
const [lastExplorerUrl, setLastExplorerUrl] = useState("");
|
|
56
|
+
const previousConnectedAddressRef = useRef(connectedAddress);
|
|
57
|
+
const maxAmountRequestIdRef = useRef(0);
|
|
58
|
+
const [selectedSourceChains, setSelectedSourceChains] = useState(null);
|
|
59
|
+
const [selectedSourcesMaxAmount, setSelectedSourcesMaxAmount] = useState(null);
|
|
60
|
+
const [appliedSourceSelectionKey, setAppliedSourceSelectionKey] = useState("ALL");
|
|
61
|
+
const { steps, onStepsList, onStepComplete, reset: resetSteps, } = useTransactionSteps();
|
|
62
|
+
const configuredMaxAmount = useMemo(() => normalizeMaxAmount(maxAmount), [maxAmount]);
|
|
63
|
+
const areInputsValid = useMemo(() => {
|
|
64
|
+
const hasToken = inputs?.token !== undefined && inputs?.token !== null;
|
|
65
|
+
const hasChain = inputs?.chain !== undefined && inputs?.chain !== null;
|
|
66
|
+
const hasAmount = Boolean(inputs?.amount) && Number(inputs?.amount) > 0;
|
|
67
|
+
const hasValidRecipient = Boolean(inputs?.recipient) && isAddress(inputs.recipient);
|
|
68
|
+
return hasToken && hasChain && hasAmount && hasValidRecipient;
|
|
69
|
+
}, [inputs]);
|
|
70
|
+
const filteredBridgableBalance = useMemo(() => {
|
|
71
|
+
const found = bridgableBalance?.find((bal) => inputs?.token === "USDM"
|
|
72
|
+
? bal?.symbol === "USDC"
|
|
73
|
+
: bal?.symbol === inputs?.token);
|
|
74
|
+
if (!found)
|
|
75
|
+
return undefined;
|
|
76
|
+
const breakdown = found.chainBalances?.map((cb) => ({
|
|
77
|
+
balance: cb.balance,
|
|
78
|
+
balanceInFiat: Number.parseFloat(cb.value),
|
|
79
|
+
chain: cb.chain,
|
|
80
|
+
})) ?? found.breakdown ?? [];
|
|
81
|
+
return {
|
|
82
|
+
...found,
|
|
83
|
+
breakdown,
|
|
84
|
+
};
|
|
85
|
+
}, [bridgableBalance, inputs?.token]);
|
|
86
|
+
const availableSources = useMemo(() => {
|
|
87
|
+
const breakdown = filteredBridgableBalance?.breakdown ?? [];
|
|
88
|
+
const destinationChainId = inputs?.chain;
|
|
89
|
+
const nonZero = breakdown.filter((source) => {
|
|
90
|
+
if (Number.parseFloat(source.balance ?? "0") <= 0)
|
|
91
|
+
return false;
|
|
92
|
+
if (typeof destinationChainId === "number") {
|
|
93
|
+
return source.chain.id !== destinationChainId;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
const decimals = filteredBridgableBalance?.decimals;
|
|
98
|
+
if (!nexusSDK || typeof decimals !== "number") {
|
|
99
|
+
return nonZero.sort((a, b) => Number.parseFloat(b.balance) - Number.parseFloat(a.balance));
|
|
100
|
+
}
|
|
101
|
+
return nonZero.sort((a, b) => {
|
|
102
|
+
try {
|
|
103
|
+
const aRaw = parseUnits(a.balance ?? "0", decimals);
|
|
104
|
+
const bRaw = parseUnits(b.balance ?? "0", decimals);
|
|
105
|
+
if (aRaw === bRaw)
|
|
106
|
+
return 0;
|
|
107
|
+
return aRaw > bRaw ? -1 : 1;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return Number.parseFloat(b.balance) - Number.parseFloat(a.balance);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}, [
|
|
114
|
+
inputs?.chain,
|
|
115
|
+
filteredBridgableBalance?.breakdown,
|
|
116
|
+
filteredBridgableBalance?.decimals,
|
|
117
|
+
nexusSDK,
|
|
118
|
+
]);
|
|
119
|
+
const allAvailableSourceChainIds = useMemo(() => availableSources.map((source) => source.chain.id), [availableSources]);
|
|
120
|
+
const effectiveSelectedSourceChains = useMemo(() => {
|
|
121
|
+
if (selectedSourceChains && selectedSourceChains.length > 0) {
|
|
122
|
+
const availableSet = new Set(allAvailableSourceChainIds);
|
|
123
|
+
const filteredSelection = selectedSourceChains.filter((id) => availableSet.has(id));
|
|
124
|
+
if (filteredSelection.length > 0) {
|
|
125
|
+
return filteredSelection;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return allAvailableSourceChainIds;
|
|
129
|
+
}, [selectedSourceChains, allAvailableSourceChainIds]);
|
|
130
|
+
const sourceChainsForSdk = effectiveSelectedSourceChains.length > 0
|
|
131
|
+
? effectiveSelectedSourceChains
|
|
132
|
+
: undefined;
|
|
133
|
+
const sourceSelectionKey = useMemo(() => {
|
|
134
|
+
if (allAvailableSourceChainIds.length === 0)
|
|
135
|
+
return "NONE";
|
|
136
|
+
if (!selectedSourceChains || selectedSourceChains.length === 0) {
|
|
137
|
+
return "ALL";
|
|
138
|
+
}
|
|
139
|
+
return [...effectiveSelectedSourceChains].sort((a, b) => a - b).join("|");
|
|
140
|
+
}, [
|
|
141
|
+
allAvailableSourceChainIds.length,
|
|
142
|
+
effectiveSelectedSourceChains,
|
|
143
|
+
selectedSourceChains,
|
|
144
|
+
]);
|
|
145
|
+
const hasPendingSourceSelectionChanges = sourceSelectionKey !== appliedSourceSelectionKey;
|
|
146
|
+
const intentSourceSpendAmount = intent.current?.intent?.sourcesTotal;
|
|
147
|
+
const getMaxForCurrentSelection = useCallback(async () => {
|
|
148
|
+
if (!nexusSDK || !inputs?.token || !inputs?.chain)
|
|
149
|
+
return undefined;
|
|
150
|
+
let totalMax = 0;
|
|
151
|
+
const selectedChainSet = new Set(sourceChainsForSdk ?? allAvailableSourceChainIds);
|
|
152
|
+
for (const source of availableSources) {
|
|
153
|
+
if (!selectedChainSet.has(source.chain.id))
|
|
154
|
+
continue;
|
|
155
|
+
const balVal = Number.parseFloat(source.balance ?? "0");
|
|
156
|
+
if (balVal <= 0)
|
|
157
|
+
continue;
|
|
158
|
+
let chainMax = balVal;
|
|
159
|
+
const chainMeta = CHAIN_METADATA[source.chain.id];
|
|
160
|
+
const nativeSymbol = chainMeta?.nativeCurrency?.symbol;
|
|
161
|
+
if (nativeSymbol && inputs.token === nativeSymbol) {
|
|
162
|
+
chainMax = Math.max(0, chainMax - 0.003);
|
|
163
|
+
}
|
|
164
|
+
totalMax += chainMax;
|
|
165
|
+
}
|
|
166
|
+
const amountStr = totalMax.toString();
|
|
167
|
+
return clampAmountToMax({
|
|
168
|
+
amount: amountStr,
|
|
169
|
+
maxAmount: configuredMaxAmount,
|
|
170
|
+
nexusSDK,
|
|
171
|
+
token: inputs.token,
|
|
172
|
+
chainId: inputs.chain,
|
|
173
|
+
});
|
|
174
|
+
}, [
|
|
175
|
+
configuredMaxAmount,
|
|
176
|
+
inputs?.chain,
|
|
177
|
+
inputs?.token,
|
|
178
|
+
nexusSDK,
|
|
179
|
+
sourceChainsForSdk,
|
|
180
|
+
allAvailableSourceChainIds,
|
|
181
|
+
availableSources,
|
|
182
|
+
]);
|
|
183
|
+
const toggleSourceChain = useCallback((chainId) => {
|
|
184
|
+
setSelectedSourceChains((prev) => {
|
|
185
|
+
if (allAvailableSourceChainIds.length === 0)
|
|
186
|
+
return prev;
|
|
187
|
+
const current = prev && prev.length > 0 ? prev : allAvailableSourceChainIds;
|
|
188
|
+
const next = current.includes(chainId)
|
|
189
|
+
? current.filter((id) => id !== chainId)
|
|
190
|
+
: [...current, chainId];
|
|
191
|
+
if (next.length === 0) {
|
|
192
|
+
return current;
|
|
193
|
+
}
|
|
194
|
+
const isAllSelected = next.length === allAvailableSourceChainIds.length &&
|
|
195
|
+
allAvailableSourceChainIds.every((id) => next.includes(id));
|
|
196
|
+
return isAllSelected ? null : next;
|
|
197
|
+
});
|
|
198
|
+
}, [allAvailableSourceChainIds]);
|
|
199
|
+
const sourceSelection = useMemo(() => {
|
|
200
|
+
const amount = intentSourceSpendAmount?.trim() ?? inputs?.amount?.trim() ?? "";
|
|
201
|
+
const decimals = getCoverageDecimals({
|
|
202
|
+
type,
|
|
203
|
+
token: inputs?.token,
|
|
204
|
+
chainId: inputs?.chain,
|
|
205
|
+
fallback: filteredBridgableBalance?.decimals,
|
|
206
|
+
});
|
|
207
|
+
const selectedChainSet = new Set(effectiveSelectedSourceChains);
|
|
208
|
+
const selectedTotalRaw = !nexusSDK || typeof decimals !== "number"
|
|
209
|
+
? BigInt(0)
|
|
210
|
+
: availableSources.reduce((sum, source) => {
|
|
211
|
+
if (!selectedChainSet.has(source.chain.id))
|
|
212
|
+
return sum;
|
|
213
|
+
try {
|
|
214
|
+
return sum + parseUnits(source.balance ?? "0", decimals);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return sum;
|
|
218
|
+
}
|
|
219
|
+
}, BigInt(0));
|
|
220
|
+
const selectedTotal = !nexusSDK || typeof decimals !== "number"
|
|
221
|
+
? "0"
|
|
222
|
+
: formatAmountForDisplay(selectedTotalRaw, decimals, nexusSDK);
|
|
223
|
+
const baseSelection = {
|
|
224
|
+
selectedTotal,
|
|
225
|
+
requiredTotal: amount || "0",
|
|
226
|
+
requiredSafetyTotal: amount || "0",
|
|
227
|
+
missingToProceed: "0",
|
|
228
|
+
missingToSafety: "0",
|
|
229
|
+
coverageState: "healthy",
|
|
230
|
+
coverageToSafetyPercent: 100,
|
|
231
|
+
isBelowRequired: false,
|
|
232
|
+
isBelowSafetyBuffer: false,
|
|
233
|
+
};
|
|
234
|
+
if (!nexusSDK || !inputs?.token || !inputs?.chain || !amount) {
|
|
235
|
+
return baseSelection;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const requiredRaw = nexusSDK.convertTokenReadableAmountToBigInt(amount, inputs.token, inputs.chain);
|
|
239
|
+
if (requiredRaw <= BigInt(0)) {
|
|
240
|
+
return baseSelection;
|
|
241
|
+
}
|
|
242
|
+
const missingToProceedRaw = selectedTotalRaw >= requiredRaw
|
|
243
|
+
? BigInt(0)
|
|
244
|
+
: requiredRaw - selectedTotalRaw;
|
|
245
|
+
const missingToSafetyRaw = missingToProceedRaw;
|
|
246
|
+
const coverageState = selectedTotalRaw < requiredRaw ? "error" : "healthy";
|
|
247
|
+
const coverageBasisPoints = requiredRaw === BigInt(0)
|
|
248
|
+
? 10_000
|
|
249
|
+
: selectedTotalRaw >= requiredRaw
|
|
250
|
+
? 10_000
|
|
251
|
+
: Number((selectedTotalRaw * BigInt(10_000)) / requiredRaw);
|
|
252
|
+
return {
|
|
253
|
+
selectedTotal,
|
|
254
|
+
requiredTotal: amount,
|
|
255
|
+
requiredSafetyTotal: amount,
|
|
256
|
+
missingToProceed: formatAmountForDisplay(missingToProceedRaw, decimals, nexusSDK),
|
|
257
|
+
missingToSafety: formatAmountForDisplay(missingToSafetyRaw, decimals, nexusSDK),
|
|
258
|
+
coverageState,
|
|
259
|
+
coverageToSafetyPercent: coverageBasisPoints / 100,
|
|
260
|
+
isBelowRequired: coverageState === "error",
|
|
261
|
+
isBelowSafetyBuffer: coverageState === "error",
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return baseSelection;
|
|
266
|
+
}
|
|
267
|
+
}, [
|
|
268
|
+
type,
|
|
269
|
+
filteredBridgableBalance?.decimals,
|
|
270
|
+
nexusSDK,
|
|
271
|
+
inputs?.chain,
|
|
272
|
+
inputs?.amount,
|
|
273
|
+
inputs?.token,
|
|
274
|
+
intentSourceSpendAmount,
|
|
275
|
+
availableSources,
|
|
276
|
+
effectiveSelectedSourceChains,
|
|
277
|
+
]);
|
|
278
|
+
const stopwatch = useStopwatch({ intervalMs: 100 });
|
|
279
|
+
const setStatus = useCallback((status) => dispatch({ type: "setStatus", payload: status }), []);
|
|
280
|
+
const resetInputs = useCallback(() => {
|
|
281
|
+
dispatch({ type: "resetInputs" });
|
|
282
|
+
}, []);
|
|
283
|
+
const { refreshIntent, handleTransaction, startTransaction, commitAmount, reset, invalidatePendingExecution, } = useTransactionExecution({
|
|
284
|
+
operationName,
|
|
285
|
+
nexusSDK,
|
|
286
|
+
intent,
|
|
287
|
+
allowance,
|
|
288
|
+
inputs,
|
|
289
|
+
configuredMaxAmount,
|
|
290
|
+
allAvailableSourceChainIds,
|
|
291
|
+
sourceChainsForSdk,
|
|
292
|
+
sourceSelectionKey,
|
|
293
|
+
sourceSelection,
|
|
294
|
+
loading,
|
|
295
|
+
txError,
|
|
296
|
+
areInputsValid,
|
|
297
|
+
executeTransaction,
|
|
298
|
+
getMaxForCurrentSelection,
|
|
299
|
+
onStepsList,
|
|
300
|
+
onStepComplete,
|
|
301
|
+
resetSteps,
|
|
302
|
+
setStatus,
|
|
303
|
+
resetInputs,
|
|
304
|
+
setRefreshing,
|
|
305
|
+
setIsDialogOpen,
|
|
306
|
+
setTxError,
|
|
307
|
+
setLastExplorerUrl,
|
|
308
|
+
setSelectedSourceChains,
|
|
309
|
+
setAppliedSourceSelectionKey,
|
|
310
|
+
stopwatch,
|
|
311
|
+
handleNexusError,
|
|
312
|
+
onStart,
|
|
313
|
+
onComplete,
|
|
314
|
+
onError,
|
|
315
|
+
fetchBalance,
|
|
316
|
+
notifyHistoryRefresh,
|
|
317
|
+
});
|
|
318
|
+
usePolling(Boolean(intent.current) &&
|
|
319
|
+
!isDialogOpen &&
|
|
320
|
+
!isSourceMenuOpen &&
|
|
321
|
+
!hasPendingSourceSelectionChanges, async () => {
|
|
322
|
+
await refreshIntent();
|
|
323
|
+
}, 15000);
|
|
324
|
+
const debouncedRefreshMaxForSelection = useDebouncedCallback(async (requestId) => {
|
|
325
|
+
try {
|
|
326
|
+
const maxForCurrentSelection = await getMaxForCurrentSelection();
|
|
327
|
+
if (requestId !== maxAmountRequestIdRef.current)
|
|
328
|
+
return;
|
|
329
|
+
setSelectedSourcesMaxAmount(maxForCurrentSelection ?? "0");
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
if (requestId !== maxAmountRequestIdRef.current)
|
|
333
|
+
return;
|
|
334
|
+
console.error("Unable to calculate max for selected sources:", error);
|
|
335
|
+
setSelectedSourcesMaxAmount("0");
|
|
336
|
+
}
|
|
337
|
+
}, MAX_AMOUNT_DEBOUNCE_MS);
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
debouncedRefreshMaxForSelection.cancel();
|
|
340
|
+
if (!nexusSDK || !inputs?.token || !inputs?.chain) {
|
|
341
|
+
maxAmountRequestIdRef.current += 1;
|
|
342
|
+
setSelectedSourcesMaxAmount(null);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (allAvailableSourceChainIds.length === 0) {
|
|
346
|
+
maxAmountRequestIdRef.current += 1;
|
|
347
|
+
setSelectedSourcesMaxAmount("0");
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const requestId = ++maxAmountRequestIdRef.current;
|
|
351
|
+
debouncedRefreshMaxForSelection(requestId);
|
|
352
|
+
}, [
|
|
353
|
+
allAvailableSourceChainIds.length,
|
|
354
|
+
configuredMaxAmount,
|
|
355
|
+
debouncedRefreshMaxForSelection,
|
|
356
|
+
inputs?.recipient,
|
|
357
|
+
sourceSelectionKey,
|
|
358
|
+
inputs?.chain,
|
|
359
|
+
inputs?.token,
|
|
360
|
+
nexusSDK,
|
|
361
|
+
]);
|
|
362
|
+
useEffect(() => {
|
|
363
|
+
if (type !== "bridge" || !connectedAddress)
|
|
364
|
+
return;
|
|
365
|
+
const previousConnectedAddress = previousConnectedAddressRef.current;
|
|
366
|
+
if (!previousConnectedAddress) {
|
|
367
|
+
previousConnectedAddressRef.current = connectedAddress;
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
if (connectedAddress === previousConnectedAddress)
|
|
371
|
+
return;
|
|
372
|
+
previousConnectedAddressRef.current = connectedAddress;
|
|
373
|
+
if (prefill?.recipient)
|
|
374
|
+
return;
|
|
375
|
+
if (!inputs?.recipient || inputs.recipient === previousConnectedAddress) {
|
|
376
|
+
dispatch({ type: "setInputs", payload: { recipient: connectedAddress } });
|
|
377
|
+
}
|
|
378
|
+
}, [type, connectedAddress, inputs?.recipient, prefill?.recipient]);
|
|
379
|
+
useEffect(() => {
|
|
380
|
+
invalidatePendingExecution();
|
|
381
|
+
}, [inputs, invalidatePendingExecution]);
|
|
382
|
+
useEffect(() => {
|
|
383
|
+
setSelectedSourceChains(null);
|
|
384
|
+
}, [inputs?.token]);
|
|
385
|
+
useEffect(() => {
|
|
386
|
+
if (isDialogOpen)
|
|
387
|
+
return;
|
|
388
|
+
stopwatch.stop();
|
|
389
|
+
stopwatch.reset();
|
|
390
|
+
if (state.status === "success" || state.status === "error") {
|
|
391
|
+
resetSteps();
|
|
392
|
+
setLastExplorerUrl("");
|
|
393
|
+
setStatus("idle");
|
|
394
|
+
}
|
|
395
|
+
}, [isDialogOpen, resetSteps, setStatus, state.status, stopwatch]);
|
|
396
|
+
useEffect(() => {
|
|
397
|
+
if (txError) {
|
|
398
|
+
setTxError(null);
|
|
399
|
+
}
|
|
400
|
+
}, [inputs, txError]);
|
|
401
|
+
return {
|
|
402
|
+
inputs,
|
|
403
|
+
setInputs,
|
|
404
|
+
timer: stopwatch.seconds,
|
|
405
|
+
setIsDialogOpen,
|
|
406
|
+
setTxError,
|
|
407
|
+
loading,
|
|
408
|
+
refreshing,
|
|
409
|
+
isDialogOpen,
|
|
410
|
+
txError,
|
|
411
|
+
handleTransaction,
|
|
412
|
+
reset,
|
|
413
|
+
filteredBridgableBalance,
|
|
414
|
+
startTransaction,
|
|
415
|
+
commitAmount,
|
|
416
|
+
lastExplorerUrl,
|
|
417
|
+
steps,
|
|
418
|
+
status: state.status,
|
|
419
|
+
availableSources,
|
|
420
|
+
selectedSourceChains: effectiveSelectedSourceChains,
|
|
421
|
+
toggleSourceChain,
|
|
422
|
+
isSourceSelectionInsufficient: sourceSelection.isBelowRequired,
|
|
423
|
+
isSourceSelectionBelowSafetyBuffer: sourceSelection.isBelowSafetyBuffer,
|
|
424
|
+
isSourceSelectionReadyForAccept: sourceSelection.coverageState === "healthy",
|
|
425
|
+
sourceCoverageState: sourceSelection.coverageState,
|
|
426
|
+
sourceCoveragePercent: sourceSelection.coverageToSafetyPercent,
|
|
427
|
+
missingToProceed: sourceSelection.missingToProceed,
|
|
428
|
+
missingToSafety: sourceSelection.missingToSafety,
|
|
429
|
+
selectedTotal: sourceSelection.selectedTotal,
|
|
430
|
+
requiredTotal: sourceSelection.requiredTotal,
|
|
431
|
+
requiredSafetyTotal: sourceSelection.requiredSafetyTotal,
|
|
432
|
+
maxAvailableAmount: selectedSourcesMaxAmount ?? undefined,
|
|
433
|
+
isInputsValid: areInputsValid,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./hooks/useStopwatch";
|
|
2
|
+
export * from "./hooks/usePolling";
|
|
3
|
+
export * from "./hooks/useInterval";
|
|
4
|
+
export * from "./hooks/useStableCallback";
|
|
5
|
+
export * from "./hooks/useLatest";
|
|
6
|
+
export * from "./hooks/useDebouncedValue";
|
|
7
|
+
export * from "./hooks/useDebouncedCallback";
|
|
8
|
+
export * from "./hooks/useNexusError";
|
|
9
|
+
export * from "./hooks/useTransactionFlow";
|
|
10
|
+
export * from "./types/transaction-flow";
|
|
11
|
+
export * from "./tx/types";
|
|
12
|
+
export * from "./tx/steps";
|
|
13
|
+
export * from "./tx/useTransactionSteps";
|
|
14
|
+
export * from "./utils/constant";
|
|
15
|
+
export * from "./utils/token-pricing";
|
|
16
|
+
export * from "./components/ErrorBoundary";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../.build-src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./hooks/useStopwatch";
|
|
2
|
+
export * from "./hooks/usePolling";
|
|
3
|
+
export * from "./hooks/useInterval";
|
|
4
|
+
export * from "./hooks/useStableCallback";
|
|
5
|
+
export * from "./hooks/useLatest";
|
|
6
|
+
export * from "./hooks/useDebouncedValue";
|
|
7
|
+
export * from "./hooks/useDebouncedCallback";
|
|
8
|
+
export * from "./hooks/useNexusError";
|
|
9
|
+
export * from "./hooks/useTransactionFlow";
|
|
10
|
+
export * from "./types/transaction-flow";
|
|
11
|
+
export * from "./tx/types";
|
|
12
|
+
export * from "./tx/steps";
|
|
13
|
+
export * from "./tx/useTransactionSteps";
|
|
14
|
+
export * from "./utils/constant";
|
|
15
|
+
export * from "./utils/token-pricing";
|
|
16
|
+
export * from "./components/ErrorBoundary";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SwapStepType } from "../types/transaction-flow";
|
|
2
|
+
import type { GenericStep } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Predefined expected steps for swaps to seed UI before events arrive.
|
|
5
|
+
* Kept here to avoid duplication across exact-in and exact-out hooks.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SWAP_EXPECTED_STEPS: SwapStepType[];
|
|
8
|
+
export declare function seedSteps<T>(expected: T[]): Array<GenericStep<T>>;
|
|
9
|
+
export declare function computeAllCompleted<T>(steps: Array<GenericStep<T>>): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Replace the current list of steps with a new list, preserving completion
|
|
12
|
+
* for any steps that were already marked completed (matched by key).
|
|
13
|
+
*/
|
|
14
|
+
export declare function mergeStepsList<T>(prev: Array<GenericStep<T>>, list: T[]): Array<GenericStep<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* Mark a step complete in-place; if the step doesn't yet exist, append it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mergeStepComplete<T>(prev: Array<GenericStep<T>>, step: T): Array<GenericStep<T>>;
|
|
19
|
+
//# sourceMappingURL=steps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../../.build-src/common/tx/steps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAAY,EA0B7C,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAMjE;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAE5E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAC3B,IAAI,EAAE,CAAC,EAAE,GACR,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAkBvB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAC3B,IAAI,EAAE,CAAC,GACN,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAoBvB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { getStepKey } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Predefined expected steps for swaps to seed UI before events arrive.
|
|
4
|
+
* Kept here to avoid duplication across exact-in and exact-out hooks.
|
|
5
|
+
*/
|
|
6
|
+
export const SWAP_EXPECTED_STEPS = [
|
|
7
|
+
{ type: "SWAP_START", typeID: "SWAP_START" },
|
|
8
|
+
{ type: "DETERMINING_SWAP", typeID: "DETERMINING_SWAP" },
|
|
9
|
+
{
|
|
10
|
+
type: "CREATE_PERMIT_FOR_SOURCE_SWAP",
|
|
11
|
+
typeID: "CREATE_PERMIT_FOR_SOURCE_SWAP",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
type: "SOURCE_SWAP_BATCH_TX",
|
|
15
|
+
typeID: "SOURCE_SWAP_BATCH_TX",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: "SOURCE_SWAP_HASH",
|
|
19
|
+
typeID: "SOURCE_SWAP_HASH",
|
|
20
|
+
},
|
|
21
|
+
{ type: "RFF_ID", typeID: "RFF_ID" },
|
|
22
|
+
{
|
|
23
|
+
type: "DESTINATION_SWAP_BATCH_TX",
|
|
24
|
+
typeID: "DESTINATION_SWAP_BATCH_TX",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "DESTINATION_SWAP_HASH",
|
|
28
|
+
typeID: "DESTINATION_SWAP_HASH",
|
|
29
|
+
},
|
|
30
|
+
{ type: "SWAP_COMPLETE", typeID: "SWAP_COMPLETE" },
|
|
31
|
+
];
|
|
32
|
+
export function seedSteps(expected) {
|
|
33
|
+
return expected.map((st, index) => ({
|
|
34
|
+
id: index,
|
|
35
|
+
completed: false,
|
|
36
|
+
step: st,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
export function computeAllCompleted(steps) {
|
|
40
|
+
return steps.length > 0 && steps.every((s) => s.completed);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Replace the current list of steps with a new list, preserving completion
|
|
44
|
+
* for any steps that were already marked completed (matched by key).
|
|
45
|
+
*/
|
|
46
|
+
export function mergeStepsList(prev, list) {
|
|
47
|
+
const completedKeys = new Set();
|
|
48
|
+
for (const prevStep of prev) {
|
|
49
|
+
if (prevStep.completed) {
|
|
50
|
+
completedKeys.add(getStepKey(prevStep.step));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const next = [];
|
|
54
|
+
for (let index = 0; index < list.length; index++) {
|
|
55
|
+
const step = list[index];
|
|
56
|
+
const key = getStepKey(step);
|
|
57
|
+
next.push({
|
|
58
|
+
id: index,
|
|
59
|
+
completed: completedKeys.has(key),
|
|
60
|
+
step,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return next;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Mark a step complete in-place; if the step doesn't yet exist, append it.
|
|
67
|
+
*/
|
|
68
|
+
export function mergeStepComplete(prev, step) {
|
|
69
|
+
const key = getStepKey(step);
|
|
70
|
+
const updated = [];
|
|
71
|
+
let found = false;
|
|
72
|
+
for (const s of prev) {
|
|
73
|
+
if (getStepKey(s.step) === key) {
|
|
74
|
+
updated.push({ ...s, completed: true, step: { ...s.step, ...step } });
|
|
75
|
+
found = true;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
updated.push(s);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!found) {
|
|
82
|
+
updated.push({
|
|
83
|
+
id: updated.length,
|
|
84
|
+
completed: true,
|
|
85
|
+
step,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return updated;
|
|
89
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type TransactionStatus = "idle" | "preview" | "awaiting-approval" | "executing" | "success" | "error";
|
|
2
|
+
export type GenericStep<TStep> = {
|
|
3
|
+
id: number;
|
|
4
|
+
completed: boolean;
|
|
5
|
+
step: TStep;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes a step to a stable key. Prefers typeID, then type, otherwise JSON.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getStepKey(step: any): string;
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../.build-src/common/tx/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,SAAS,GACT,mBAAmB,GACnB,WAAW,GACX,SAAS,GACT,OAAO,CAAC;AAEZ,MAAM,MAAM,WAAW,CAAC,KAAK,IAAI;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,KAAK,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAa5C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a step to a stable key. Prefers typeID, then type, otherwise JSON.
|
|
3
|
+
*/
|
|
4
|
+
export function getStepKey(step) {
|
|
5
|
+
if (!step)
|
|
6
|
+
return "";
|
|
7
|
+
if (typeof step.typeID === "string" && step.typeID.length > 0) {
|
|
8
|
+
return step.typeID;
|
|
9
|
+
}
|
|
10
|
+
if (typeof step.type === "string" && step.type.length > 0) {
|
|
11
|
+
return step.type;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(step);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return String(step);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { GenericStep } from "./types";
|
|
2
|
+
interface UseTransactionStepsOptions<T> {
|
|
3
|
+
expected?: T[];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Manages transaction steps with utilities to seed from expected steps,
|
|
7
|
+
* replace the list on "steps list" events, and mark individual steps complete.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useTransactionSteps<T extends {
|
|
10
|
+
typeID?: string;
|
|
11
|
+
type?: string;
|
|
12
|
+
}>(options?: UseTransactionStepsOptions<T>): {
|
|
13
|
+
steps: GenericStep<T>[];
|
|
14
|
+
allCompleted: boolean;
|
|
15
|
+
onStepsList: (list: T[]) => void;
|
|
16
|
+
onStepComplete: (step: T) => void;
|
|
17
|
+
seed: (expectedSteps: T[]) => void;
|
|
18
|
+
reset: () => void;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=useTransactionSteps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTransactionSteps.d.ts","sourceRoot":"","sources":["../../../.build-src/common/tx/useTransactionSteps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAS3C,UAAU,0BAA0B,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,CAAC,SAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAC5C,OAAO,GAAE,0BAA0B,CAAC,CAAC,CAAM;;;wBAOhB,CAAC,EAAE;2BAUA,CAAC;0BAIF,CAAC,EAAE;;EAmBjC"}
|