@rhinestone/deposit-modal 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -26
- package/dist/{DepositModalReown-R37SSHUF.cjs → DepositModalReown-IFN6YLZJ.cjs} +16 -17
- package/dist/{DepositModalReown-KOJ7VEY7.mjs → DepositModalReown-R7UROJPJ.mjs} +3 -4
- package/dist/WithdrawModal-SZEAI473.cjs +11 -0
- package/dist/{WithdrawModal-QVXHMH43.mjs → WithdrawModal-XKSSHVEJ.mjs} +3 -4
- package/dist/{chunk-DTVZUBHI.cjs → chunk-24N4KMJX.cjs} +71 -73
- package/dist/{chunk-CXBMIZUF.mjs → chunk-3HCCR54R.mjs} +1 -1
- package/dist/{chunk-5P2PVLS4.cjs → chunk-5CM3ZQ5U.cjs} +1 -1
- package/dist/{chunk-5VONFVQN.mjs → chunk-EA5CE2UZ.mjs} +3944 -864
- package/dist/{chunk-IKUYZA7A.mjs → chunk-F6ROQ6RJ.mjs} +28 -30
- package/dist/{chunk-3OOY67VJ.cjs → chunk-H4O22O7Y.cjs} +4930 -1850
- package/dist/{chunk-7UQ6OUEE.mjs → chunk-HMB2XQGD.mjs} +13 -15
- package/dist/{chunk-VPDCGD2D.cjs → chunk-V466XQSG.cjs} +260 -262
- package/dist/constants.cjs +2 -2
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/deposit.cjs +4 -5
- package/dist/deposit.d.cts +2 -2
- package/dist/deposit.d.ts +2 -2
- package/dist/deposit.mjs +3 -4
- package/dist/embed.cjs +18 -59
- package/dist/embed.d.cts +2 -8
- package/dist/embed.d.ts +2 -8
- package/dist/embed.mjs +9 -50
- package/dist/index.cjs +5 -10
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.mjs +4 -9
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/styles.css +15 -0
- package/dist/{types-CQ0NHqCy.d.ts → types-B9SbZQIG.d.ts} +15 -113
- package/dist/{types-CxiLX5sv.d.cts → types-SwGGf0eH.d.cts} +15 -113
- package/dist/withdraw.cjs +4 -5
- package/dist/withdraw.d.cts +31 -3
- package/dist/withdraw.d.ts +31 -3
- package/dist/withdraw.mjs +3 -4
- package/package.json +4 -35
- package/dist/ClaimModal-GFDBVCN5.cjs +0 -11
- package/dist/ClaimModal-VQS3AKEL.mjs +0 -11
- package/dist/WithdrawModal-RY2NMFLE.cjs +0 -12
- package/dist/chunk-6HUHVXCY.cjs +0 -704
- package/dist/chunk-QJ7RCCU7.mjs +0 -704
- package/dist/chunk-UCBUCX2W.mjs +0 -3169
- package/dist/chunk-X4D52IZK.cjs +0 -3169
- package/dist/claim.cjs +0 -9
- package/dist/claim.d.cts +0 -17
- package/dist/claim.d.ts +0 -17
- package/dist/claim.mjs +0 -9
- package/dist/modal-ui-state-OD1RmKkK.d.cts +0 -30
- package/dist/modal-ui-state-OD1RmKkK.d.ts +0 -30
package/dist/chunk-QJ7RCCU7.mjs
DELETED
|
@@ -1,704 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AnalyticsSession,
|
|
3
|
-
BodyHeader,
|
|
4
|
-
Button,
|
|
5
|
-
ChainCatalogProvider,
|
|
6
|
-
ChevronLeftIcon,
|
|
7
|
-
ClaimAnalyticsControllerProvider,
|
|
8
|
-
CloseIcon,
|
|
9
|
-
CoinsIcon,
|
|
10
|
-
ListRow,
|
|
11
|
-
Modal,
|
|
12
|
-
PoweredBy,
|
|
13
|
-
RECOVERY_LOOKUP_MISS_COPY,
|
|
14
|
-
RecoveryError,
|
|
15
|
-
RecoveryLookupScreen,
|
|
16
|
-
RecoveryOutcomeScreen,
|
|
17
|
-
RecoveryReviewScreen,
|
|
18
|
-
RpcUrlsProvider,
|
|
19
|
-
applyTheme,
|
|
20
|
-
checkBackendUrl,
|
|
21
|
-
claimFailureReasonForError,
|
|
22
|
-
classifyRecoveryLookup,
|
|
23
|
-
createDepositService,
|
|
24
|
-
describeRecoveryDeposit,
|
|
25
|
-
formatTokenAmount,
|
|
26
|
-
formatUserError,
|
|
27
|
-
recoverySigningChainId,
|
|
28
|
-
sourceDepositTxHash,
|
|
29
|
-
submitSignedRecovery,
|
|
30
|
-
toRecoverableDeposit,
|
|
31
|
-
useClaimAnalyticsController,
|
|
32
|
-
useLatestRef,
|
|
33
|
-
useStableRpcUrls
|
|
34
|
-
} from "./chunk-5VONFVQN.mjs";
|
|
35
|
-
import {
|
|
36
|
-
getTokenDecimalsByAddress,
|
|
37
|
-
getTokenSymbol,
|
|
38
|
-
tokenIconUrl
|
|
39
|
-
} from "./chunk-EAGMY3QE.mjs";
|
|
40
|
-
|
|
41
|
-
// src/ClaimModal.tsx
|
|
42
|
-
import {
|
|
43
|
-
useCallback,
|
|
44
|
-
useEffect,
|
|
45
|
-
useMemo,
|
|
46
|
-
useReducer,
|
|
47
|
-
useRef,
|
|
48
|
-
useState
|
|
49
|
-
} from "react";
|
|
50
|
-
import { formatUnits } from "viem";
|
|
51
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
52
|
-
function evmChainIdFromCaip2(chain) {
|
|
53
|
-
if (!chain?.startsWith("eip155:")) return null;
|
|
54
|
-
const id = Number.parseInt(chain.slice("eip155:".length), 10);
|
|
55
|
-
return Number.isFinite(id) ? id : null;
|
|
56
|
-
}
|
|
57
|
-
function isEligible(row) {
|
|
58
|
-
return toRecoverableDeposit(row) !== null;
|
|
59
|
-
}
|
|
60
|
-
function describeDeposit(row) {
|
|
61
|
-
const chainId = evmChainIdFromCaip2(row.chain) ?? 0;
|
|
62
|
-
return {
|
|
63
|
-
chainId,
|
|
64
|
-
...describeRecoveryDeposit({
|
|
65
|
-
chainId,
|
|
66
|
-
token: row.token,
|
|
67
|
-
amountRaw: row.sourceAmount ?? row.amount
|
|
68
|
-
})
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function humanizeStatus(status) {
|
|
72
|
-
if (!status) return void 0;
|
|
73
|
-
const spaced = status.replace(/[_-]+/g, " ").trim();
|
|
74
|
-
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
75
|
-
}
|
|
76
|
-
var INITIAL_STATE = {
|
|
77
|
-
step: "lookup",
|
|
78
|
-
deposits: [],
|
|
79
|
-
selected: null,
|
|
80
|
-
result: null,
|
|
81
|
-
error: null,
|
|
82
|
-
retryable: true
|
|
83
|
-
};
|
|
84
|
-
function claimReducer(state, action) {
|
|
85
|
-
switch (action.type) {
|
|
86
|
-
case "lookup/results":
|
|
87
|
-
return {
|
|
88
|
-
...state,
|
|
89
|
-
deposits: action.deposits,
|
|
90
|
-
selected: action.autoSelect,
|
|
91
|
-
step: action.autoSelect ? "review" : "select",
|
|
92
|
-
error: null
|
|
93
|
-
};
|
|
94
|
-
case "select":
|
|
95
|
-
return { ...state, selected: action.deposit, step: "review", error: null };
|
|
96
|
-
case "back":
|
|
97
|
-
if (state.step === "failed") return { ...state, step: "review", error: null };
|
|
98
|
-
if (state.step === "review")
|
|
99
|
-
return {
|
|
100
|
-
...state,
|
|
101
|
-
step: state.deposits.length > 1 ? "select" : "lookup",
|
|
102
|
-
error: null
|
|
103
|
-
};
|
|
104
|
-
if (state.step === "select") return { ...INITIAL_STATE };
|
|
105
|
-
return state;
|
|
106
|
-
case "submit":
|
|
107
|
-
return { ...state, step: "processing", error: null };
|
|
108
|
-
case "complete":
|
|
109
|
-
return {
|
|
110
|
-
...state,
|
|
111
|
-
step: "complete",
|
|
112
|
-
result: {
|
|
113
|
-
txHash: action.txHash,
|
|
114
|
-
amount: action.amount,
|
|
115
|
-
amountDisplay: action.amountDisplay,
|
|
116
|
-
symbol: action.symbol,
|
|
117
|
-
destination: action.destination,
|
|
118
|
-
chain: action.chain
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
case "failed":
|
|
122
|
-
return {
|
|
123
|
-
...state,
|
|
124
|
-
step: "failed",
|
|
125
|
-
error: action.error,
|
|
126
|
-
retryable: action.retryable ?? true
|
|
127
|
-
};
|
|
128
|
-
case "reset":
|
|
129
|
-
return { ...INITIAL_STATE };
|
|
130
|
-
default:
|
|
131
|
-
return state;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function buildClaimAnalyticsSessionProperties({
|
|
135
|
-
inline = false,
|
|
136
|
-
closeOnOverlayClick = false,
|
|
137
|
-
defaultTxHash,
|
|
138
|
-
defaultRefundDestination
|
|
139
|
-
}) {
|
|
140
|
-
return {
|
|
141
|
-
presentation: inline ? "inline" : "overlay",
|
|
142
|
-
overlay_close_enabled: !inline && closeOnOverlayClick,
|
|
143
|
-
prefills: {
|
|
144
|
-
transaction_hash: defaultTxHash !== void 0,
|
|
145
|
-
refund_destination: defaultRefundDestination !== void 0
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
var STANDALONE_CORRELATION = {
|
|
150
|
-
entry_source: "standalone"
|
|
151
|
-
};
|
|
152
|
-
function analyticsStepForClaimStep(step) {
|
|
153
|
-
if (step === "lookup") return "lookup";
|
|
154
|
-
if (step === "select") return "select";
|
|
155
|
-
if (step === "review") return "review";
|
|
156
|
-
return "submit";
|
|
157
|
-
}
|
|
158
|
-
function ClaimModal({
|
|
159
|
-
signRecovery,
|
|
160
|
-
isOpen,
|
|
161
|
-
onClose,
|
|
162
|
-
inline,
|
|
163
|
-
closeOnOverlayClick,
|
|
164
|
-
backendUrl,
|
|
165
|
-
rpcUrls: rpcUrlsProp,
|
|
166
|
-
defaultTxHash,
|
|
167
|
-
defaultRefundDestination,
|
|
168
|
-
theme,
|
|
169
|
-
uiConfig,
|
|
170
|
-
className,
|
|
171
|
-
onReady,
|
|
172
|
-
onLifecycle,
|
|
173
|
-
onEvent,
|
|
174
|
-
onError,
|
|
175
|
-
enableAnalyticsIngest,
|
|
176
|
-
analyticsIngestUrl,
|
|
177
|
-
debug,
|
|
178
|
-
onUiState
|
|
179
|
-
}) {
|
|
180
|
-
checkBackendUrl("ClaimModal", backendUrl);
|
|
181
|
-
const modalRef = useRef(null);
|
|
182
|
-
const onReadyRef = useLatestRef(onReady);
|
|
183
|
-
const onLifecycleRef = useLatestRef(onLifecycle);
|
|
184
|
-
const onErrorRef = useLatestRef(onError);
|
|
185
|
-
const analyticsControllerRef = useRef(null);
|
|
186
|
-
const lastSubmitFailureRef = useRef(null);
|
|
187
|
-
const previousOpenRef = useRef(isOpen);
|
|
188
|
-
const rpcUrls = useStableRpcUrls(rpcUrlsProp);
|
|
189
|
-
const service = useMemo(
|
|
190
|
-
() => createDepositService(backendUrl, { debug, debugScope: "service:claim" }),
|
|
191
|
-
[backendUrl, debug]
|
|
192
|
-
);
|
|
193
|
-
const [state, dispatch] = useReducer(claimReducer, INITIAL_STATE);
|
|
194
|
-
const operationEpochRef = useRef(0);
|
|
195
|
-
const isOpenRef = useRef(isOpen);
|
|
196
|
-
isOpenRef.current = isOpen;
|
|
197
|
-
useEffect(() => {
|
|
198
|
-
if (!isOpen || !modalRef.current) return;
|
|
199
|
-
return applyTheme(modalRef.current, theme);
|
|
200
|
-
}, [isOpen, theme]);
|
|
201
|
-
useEffect(() => {
|
|
202
|
-
if (isOpen) {
|
|
203
|
-
onReadyRef.current?.();
|
|
204
|
-
}
|
|
205
|
-
}, [isOpen, onReadyRef]);
|
|
206
|
-
useEffect(() => {
|
|
207
|
-
if (previousOpenRef.current && !isOpen) {
|
|
208
|
-
const analytics = analyticsControllerRef.current;
|
|
209
|
-
analytics?.abandon("modal_close");
|
|
210
|
-
analytics?.close("host_controlled");
|
|
211
|
-
}
|
|
212
|
-
previousOpenRef.current = isOpen;
|
|
213
|
-
}, [isOpen]);
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
if (!isOpen) {
|
|
216
|
-
operationEpochRef.current += 1;
|
|
217
|
-
dispatch({ type: "reset" });
|
|
218
|
-
}
|
|
219
|
-
}, [isOpen]);
|
|
220
|
-
const closeWithSource = useCallback(
|
|
221
|
-
(source) => {
|
|
222
|
-
const analytics = analyticsControllerRef.current;
|
|
223
|
-
if (state.step === "processing") {
|
|
224
|
-
analytics?.friction("modal_close_refused_in_flight", "submit");
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
analytics?.abandon("modal_close");
|
|
228
|
-
analytics?.close(source);
|
|
229
|
-
operationEpochRef.current += 1;
|
|
230
|
-
onClose();
|
|
231
|
-
},
|
|
232
|
-
[state.step, onClose]
|
|
233
|
-
);
|
|
234
|
-
const handleModalDismiss = useCallback(
|
|
235
|
-
(reason) => {
|
|
236
|
-
closeWithSource(
|
|
237
|
-
reason === "escape" ? "escape" : reason === "overlay" ? "overlay" : "header_button"
|
|
238
|
-
);
|
|
239
|
-
},
|
|
240
|
-
[closeWithSource]
|
|
241
|
-
);
|
|
242
|
-
const goBack = useCallback(() => {
|
|
243
|
-
const analytics = analyticsControllerRef.current;
|
|
244
|
-
const previousFailure = lastSubmitFailureRef.current;
|
|
245
|
-
if (state.step === "failed" && previousFailure?.retryable) {
|
|
246
|
-
lastSubmitFailureRef.current = null;
|
|
247
|
-
analytics?.retry(previousFailure.reason, "submit");
|
|
248
|
-
} else {
|
|
249
|
-
if (state.step === "failed") {
|
|
250
|
-
lastSubmitFailureRef.current = null;
|
|
251
|
-
analytics?.rearmStep("submit");
|
|
252
|
-
}
|
|
253
|
-
analytics?.abandon("back");
|
|
254
|
-
}
|
|
255
|
-
dispatch({ type: "back" });
|
|
256
|
-
}, [state.step]);
|
|
257
|
-
const canGoBack = state.step === "select" || state.step === "review" || state.step === "failed";
|
|
258
|
-
const onUiStateRef = useLatestRef(onUiState);
|
|
259
|
-
useEffect(() => {
|
|
260
|
-
onUiStateRef.current?.({
|
|
261
|
-
screen: state.step,
|
|
262
|
-
back: canGoBack ? goBack : void 0,
|
|
263
|
-
submitting: state.step === "processing"
|
|
264
|
-
});
|
|
265
|
-
}, [state.step, canGoBack, goBack, onUiStateRef]);
|
|
266
|
-
const showBackButton = uiConfig?.showBackButton ?? true;
|
|
267
|
-
return /* @__PURE__ */ jsx(RpcUrlsProvider, { value: rpcUrls, children: /* @__PURE__ */ jsx(ChainCatalogProvider, { service, rpcUrls, children: /* @__PURE__ */ jsx(
|
|
268
|
-
Modal,
|
|
269
|
-
{
|
|
270
|
-
isOpen,
|
|
271
|
-
onClose: handleModalDismiss,
|
|
272
|
-
className,
|
|
273
|
-
inline,
|
|
274
|
-
closeOnOverlayClick,
|
|
275
|
-
ariaLabel: "Claim your deposit",
|
|
276
|
-
children: /* @__PURE__ */ jsx(
|
|
277
|
-
AnalyticsSession,
|
|
278
|
-
{
|
|
279
|
-
modal: "claim",
|
|
280
|
-
sessionProperties: buildClaimAnalyticsSessionProperties({
|
|
281
|
-
inline,
|
|
282
|
-
closeOnOverlayClick,
|
|
283
|
-
defaultTxHash,
|
|
284
|
-
defaultRefundDestination
|
|
285
|
-
}),
|
|
286
|
-
onEvent,
|
|
287
|
-
backendUrl,
|
|
288
|
-
enableIngest: enableAnalyticsIngest,
|
|
289
|
-
ingestUrl: analyticsIngestUrl,
|
|
290
|
-
children: /* @__PURE__ */ jsx(
|
|
291
|
-
ClaimAnalyticsControllerProvider,
|
|
292
|
-
{
|
|
293
|
-
controllerRef: analyticsControllerRef,
|
|
294
|
-
correlation: STANDALONE_CORRELATION,
|
|
295
|
-
children: /* @__PURE__ */ jsxs("div", { ref: modalRef, className: "rs-modal", children: [
|
|
296
|
-
/* @__PURE__ */ jsxs("div", { className: "rs-modal-header--redesigned", children: [
|
|
297
|
-
/* @__PURE__ */ jsx("div", { className: "rs-modal-header-nav-left", children: showBackButton && canGoBack && /* @__PURE__ */ jsx(
|
|
298
|
-
"button",
|
|
299
|
-
{
|
|
300
|
-
type: "button",
|
|
301
|
-
className: "rs-modal-header-back",
|
|
302
|
-
"aria-label": "Go back",
|
|
303
|
-
onClick: goBack,
|
|
304
|
-
children: /* @__PURE__ */ jsx(ChevronLeftIcon, {})
|
|
305
|
-
}
|
|
306
|
-
) }),
|
|
307
|
-
/* @__PURE__ */ jsx("div", { className: "rs-modal-header-nav-right", children: /* @__PURE__ */ jsx(
|
|
308
|
-
"button",
|
|
309
|
-
{
|
|
310
|
-
type: "button",
|
|
311
|
-
onClick: () => closeWithSource("header_button"),
|
|
312
|
-
disabled: state.step === "processing",
|
|
313
|
-
className: "rs-modal-close",
|
|
314
|
-
"aria-label": "Close",
|
|
315
|
-
children: /* @__PURE__ */ jsx(CloseIcon, {})
|
|
316
|
-
}
|
|
317
|
-
) })
|
|
318
|
-
] }),
|
|
319
|
-
/* @__PURE__ */ jsx("div", { className: "rs-modal-body", children: /* @__PURE__ */ jsx(
|
|
320
|
-
ClaimBody,
|
|
321
|
-
{
|
|
322
|
-
state,
|
|
323
|
-
dispatch,
|
|
324
|
-
service,
|
|
325
|
-
signRecovery,
|
|
326
|
-
backendUrl,
|
|
327
|
-
debug,
|
|
328
|
-
defaultTxHash,
|
|
329
|
-
defaultRefundDestination,
|
|
330
|
-
onClose: closeWithSource,
|
|
331
|
-
onBack: goBack,
|
|
332
|
-
operationEpochRef,
|
|
333
|
-
isOpenRef,
|
|
334
|
-
lastSubmitFailureRef,
|
|
335
|
-
onLifecycleRef,
|
|
336
|
-
onErrorRef
|
|
337
|
-
}
|
|
338
|
-
) })
|
|
339
|
-
] })
|
|
340
|
-
}
|
|
341
|
-
)
|
|
342
|
-
}
|
|
343
|
-
)
|
|
344
|
-
}
|
|
345
|
-
) }) });
|
|
346
|
-
}
|
|
347
|
-
function ClaimBody({
|
|
348
|
-
state,
|
|
349
|
-
dispatch,
|
|
350
|
-
service,
|
|
351
|
-
signRecovery,
|
|
352
|
-
backendUrl,
|
|
353
|
-
debug,
|
|
354
|
-
defaultTxHash,
|
|
355
|
-
defaultRefundDestination,
|
|
356
|
-
onClose,
|
|
357
|
-
onBack,
|
|
358
|
-
operationEpochRef,
|
|
359
|
-
isOpenRef,
|
|
360
|
-
lastSubmitFailureRef,
|
|
361
|
-
onLifecycleRef,
|
|
362
|
-
onErrorRef
|
|
363
|
-
}) {
|
|
364
|
-
const analytics = useClaimAnalyticsController();
|
|
365
|
-
useEffect(() => {
|
|
366
|
-
analytics.openSession();
|
|
367
|
-
analytics.openStep(analyticsStepForClaimStep(state.step));
|
|
368
|
-
}, [analytics, state.step]);
|
|
369
|
-
switch (state.step) {
|
|
370
|
-
case "lookup":
|
|
371
|
-
return /* @__PURE__ */ jsx(
|
|
372
|
-
LookupStep,
|
|
373
|
-
{
|
|
374
|
-
service,
|
|
375
|
-
defaultTxHash,
|
|
376
|
-
operationEpochRef,
|
|
377
|
-
isOpenRef,
|
|
378
|
-
onResults: (deposits) => {
|
|
379
|
-
const eligible = deposits.filter(isEligible);
|
|
380
|
-
const autoSelect = deposits.length === 1 && eligible.length === 1 ? deposits[0] : null;
|
|
381
|
-
analytics.completeStep("lookup");
|
|
382
|
-
if (autoSelect) reportSelection(autoSelect, true);
|
|
383
|
-
dispatch({ type: "lookup/results", deposits, autoSelect });
|
|
384
|
-
},
|
|
385
|
-
onLifecycleRef,
|
|
386
|
-
onErrorRef
|
|
387
|
-
}
|
|
388
|
-
);
|
|
389
|
-
case "select":
|
|
390
|
-
return /* @__PURE__ */ jsx(
|
|
391
|
-
SelectStep,
|
|
392
|
-
{
|
|
393
|
-
deposits: state.deposits,
|
|
394
|
-
onSelect: (deposit) => {
|
|
395
|
-
analytics.completeStep("select");
|
|
396
|
-
reportSelection(deposit, false);
|
|
397
|
-
dispatch({ type: "select", deposit });
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
);
|
|
401
|
-
case "review":
|
|
402
|
-
case "processing":
|
|
403
|
-
return /* @__PURE__ */ jsx(
|
|
404
|
-
ReviewStep,
|
|
405
|
-
{
|
|
406
|
-
deposit: state.selected,
|
|
407
|
-
submitting: state.step === "processing",
|
|
408
|
-
defaultRefundDestination,
|
|
409
|
-
onSubmit: (destination) => submitRecoveryRequest(destination)
|
|
410
|
-
}
|
|
411
|
-
);
|
|
412
|
-
case "complete":
|
|
413
|
-
return /* @__PURE__ */ jsx(
|
|
414
|
-
ResultStep,
|
|
415
|
-
{
|
|
416
|
-
result: state.result,
|
|
417
|
-
onClose: () => onClose("success_done"),
|
|
418
|
-
onReset: () => {
|
|
419
|
-
analytics.resetAttempt();
|
|
420
|
-
dispatch({ type: "reset" });
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
|
-
case "failed":
|
|
425
|
-
return /* @__PURE__ */ jsx(
|
|
426
|
-
ResultStep,
|
|
427
|
-
{
|
|
428
|
-
error: state.error,
|
|
429
|
-
onClose: () => onClose("failure_cancel"),
|
|
430
|
-
onRetry: state.retryable ? onBack : void 0
|
|
431
|
-
}
|
|
432
|
-
);
|
|
433
|
-
default:
|
|
434
|
-
return null;
|
|
435
|
-
}
|
|
436
|
-
function reportSelection(deposit, autoSelected) {
|
|
437
|
-
if (!deposit.id) return;
|
|
438
|
-
analytics.selectDeposit({
|
|
439
|
-
depositId: deposit.id,
|
|
440
|
-
transactionHash: deposit.txHash ?? null,
|
|
441
|
-
autoSelected
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
async function submitRecoveryRequest(destination) {
|
|
445
|
-
const deposit = state.selected;
|
|
446
|
-
if (!deposit) return;
|
|
447
|
-
const sourceChainId = evmChainIdFromCaip2(deposit.chain);
|
|
448
|
-
const signingChainId = recoverySigningChainId(deposit);
|
|
449
|
-
if (sourceChainId == null || signingChainId == null || !deposit.id || !deposit.recipient || !deposit.depositAddress || !deposit.token || !deposit.chain) {
|
|
450
|
-
analytics.failure("recovery_deposit_data_incomplete", false, "review");
|
|
451
|
-
analytics.outcome("failed");
|
|
452
|
-
dispatch({
|
|
453
|
-
type: "failed",
|
|
454
|
-
error: "Deposit is missing data required to recover it.",
|
|
455
|
-
// The missing fields come off the backend row already in memory, so a
|
|
456
|
-
// retry re-reads nothing and fails identically. Offering one would be a
|
|
457
|
-
// dead end, and would also contradict the `retryable` reported above.
|
|
458
|
-
retryable: false
|
|
459
|
-
});
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
const signer = deposit.recipient;
|
|
463
|
-
const account = deposit.depositAddress;
|
|
464
|
-
const token = deposit.token;
|
|
465
|
-
const operationEpoch = operationEpochRef.current;
|
|
466
|
-
const isCurrentOperation = () => isOpenRef.current && operationEpochRef.current === operationEpoch;
|
|
467
|
-
analytics.completeStep("review");
|
|
468
|
-
analytics.openStep("submit");
|
|
469
|
-
dispatch({ type: "submit" });
|
|
470
|
-
onLifecycleRef.current?.({
|
|
471
|
-
type: "refund_requested",
|
|
472
|
-
account,
|
|
473
|
-
destination,
|
|
474
|
-
chain: sourceChainId
|
|
475
|
-
});
|
|
476
|
-
try {
|
|
477
|
-
const result = await submitSignedRecovery({
|
|
478
|
-
backendUrl,
|
|
479
|
-
chainId: signingChainId,
|
|
480
|
-
depositId: deposit.id,
|
|
481
|
-
signer,
|
|
482
|
-
destination,
|
|
483
|
-
signRecovery,
|
|
484
|
-
debug
|
|
485
|
-
});
|
|
486
|
-
if (!isCurrentOperation()) return;
|
|
487
|
-
const paidTo = destination;
|
|
488
|
-
const decimals = getTokenDecimalsByAddress(token, sourceChainId);
|
|
489
|
-
const symbol = getTokenSymbol(token, sourceChainId);
|
|
490
|
-
const refundedRaw = BigInt(
|
|
491
|
-
result.amount ?? deposit.sourceAmount ?? deposit.amount ?? "0"
|
|
492
|
-
);
|
|
493
|
-
const amountDisplay = formatTokenAmount(Number(formatUnits(refundedRaw, decimals)), symbol) ?? formatUnits(refundedRaw, decimals);
|
|
494
|
-
dispatch({
|
|
495
|
-
type: "complete",
|
|
496
|
-
txHash: result.transactionHash,
|
|
497
|
-
amount: result.amount,
|
|
498
|
-
amountDisplay,
|
|
499
|
-
symbol,
|
|
500
|
-
destination: paidTo,
|
|
501
|
-
chain: sourceChainId
|
|
502
|
-
});
|
|
503
|
-
analytics.handoff(
|
|
504
|
-
{
|
|
505
|
-
depositId: deposit.id,
|
|
506
|
-
transactionHash: deposit.txHash ?? null,
|
|
507
|
-
refundTransactionHash: result.transactionHash
|
|
508
|
-
},
|
|
509
|
-
"submit"
|
|
510
|
-
);
|
|
511
|
-
analytics.completeStep("submit");
|
|
512
|
-
analytics.outcome("completed");
|
|
513
|
-
onLifecycleRef.current?.({
|
|
514
|
-
type: "complete",
|
|
515
|
-
txHash: result.transactionHash,
|
|
516
|
-
account,
|
|
517
|
-
destination: paidTo,
|
|
518
|
-
chain: sourceChainId,
|
|
519
|
-
token,
|
|
520
|
-
amount: result.amount
|
|
521
|
-
});
|
|
522
|
-
} catch (err) {
|
|
523
|
-
if (!isCurrentOperation()) return;
|
|
524
|
-
const recoveryError = err instanceof RecoveryError ? err : void 0;
|
|
525
|
-
const status = recoveryError?.status;
|
|
526
|
-
const message = recoveryError?.message ?? formatUserError(
|
|
527
|
-
err instanceof Error ? err.message : "Recovery failed"
|
|
528
|
-
);
|
|
529
|
-
const retryable = recoveryError?.retryable ?? true;
|
|
530
|
-
dispatch({
|
|
531
|
-
type: "failed",
|
|
532
|
-
error: message,
|
|
533
|
-
retryable
|
|
534
|
-
});
|
|
535
|
-
const reason = claimFailureReasonForError(err);
|
|
536
|
-
lastSubmitFailureRef.current = { reason, retryable };
|
|
537
|
-
analytics.failure(reason, retryable, "submit");
|
|
538
|
-
analytics.outcome("failed");
|
|
539
|
-
onLifecycleRef.current?.({ type: "failed", status, error: message });
|
|
540
|
-
onErrorRef.current?.({ message, code: "CLAIM_FAILED" });
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
function LookupStep({
|
|
545
|
-
service,
|
|
546
|
-
defaultTxHash,
|
|
547
|
-
operationEpochRef,
|
|
548
|
-
isOpenRef,
|
|
549
|
-
onResults,
|
|
550
|
-
onLifecycleRef,
|
|
551
|
-
onErrorRef
|
|
552
|
-
}) {
|
|
553
|
-
const analytics = useClaimAnalyticsController();
|
|
554
|
-
const [loading, setLoading] = useState(false);
|
|
555
|
-
const [error, setError] = useState(null);
|
|
556
|
-
const handleLookup = useCallback(
|
|
557
|
-
async (txHash) => {
|
|
558
|
-
const operationEpoch = operationEpochRef.current;
|
|
559
|
-
const isCurrentOperation = () => isOpenRef.current && operationEpochRef.current === operationEpoch;
|
|
560
|
-
setError(null);
|
|
561
|
-
setLoading(true);
|
|
562
|
-
analytics.rearmStep("lookup");
|
|
563
|
-
try {
|
|
564
|
-
const deposits = await service.lookupRecoverableDeposits({ txHash });
|
|
565
|
-
if (!isCurrentOperation()) return;
|
|
566
|
-
onLifecycleRef.current?.({
|
|
567
|
-
type: "lookup",
|
|
568
|
-
txHash,
|
|
569
|
-
matches: deposits.length
|
|
570
|
-
});
|
|
571
|
-
const { eligible, miss } = classifyRecoveryLookup(deposits);
|
|
572
|
-
analytics.lookupResult(deposits.length, eligible.length);
|
|
573
|
-
if (miss) {
|
|
574
|
-
analytics.friction(
|
|
575
|
-
miss === "not_found" ? "lookup_no_deposits_found" : "lookup_no_eligible_deposits",
|
|
576
|
-
"lookup"
|
|
577
|
-
);
|
|
578
|
-
setError(RECOVERY_LOOKUP_MISS_COPY[miss]);
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
onResults(deposits);
|
|
582
|
-
} catch (err) {
|
|
583
|
-
if (!isCurrentOperation()) return;
|
|
584
|
-
const message = formatUserError(
|
|
585
|
-
err instanceof Error ? err.message : "Lookup failed"
|
|
586
|
-
);
|
|
587
|
-
analytics.failure("lookup_failed", true, "lookup");
|
|
588
|
-
setError(message);
|
|
589
|
-
onErrorRef.current?.({ message, code: "CLAIM_LOOKUP_FAILED" });
|
|
590
|
-
} finally {
|
|
591
|
-
if (isCurrentOperation()) setLoading(false);
|
|
592
|
-
}
|
|
593
|
-
},
|
|
594
|
-
[
|
|
595
|
-
analytics,
|
|
596
|
-
service,
|
|
597
|
-
operationEpochRef,
|
|
598
|
-
isOpenRef,
|
|
599
|
-
onResults,
|
|
600
|
-
onLifecycleRef,
|
|
601
|
-
onErrorRef
|
|
602
|
-
]
|
|
603
|
-
);
|
|
604
|
-
return /* @__PURE__ */ jsx(
|
|
605
|
-
RecoveryLookupScreen,
|
|
606
|
-
{
|
|
607
|
-
title: "Claim a deposit",
|
|
608
|
-
subtitle: "Get funds from a failed deposit sent back to you on the source chain.",
|
|
609
|
-
defaultTxHash,
|
|
610
|
-
loading,
|
|
611
|
-
error,
|
|
612
|
-
onSubmit: handleLookup,
|
|
613
|
-
onInvalid: () => analytics.friction("lookup_transaction_hash_invalid", "lookup")
|
|
614
|
-
}
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
function SelectStep({
|
|
618
|
-
deposits,
|
|
619
|
-
onSelect
|
|
620
|
-
}) {
|
|
621
|
-
return /* @__PURE__ */ jsxs("div", { className: "rs-screen", children: [
|
|
622
|
-
/* @__PURE__ */ jsxs("div", { className: "rs-screen-body rs-screen-body--gap-32", children: [
|
|
623
|
-
/* @__PURE__ */ jsx(
|
|
624
|
-
BodyHeader,
|
|
625
|
-
{
|
|
626
|
-
icon: /* @__PURE__ */ jsx(CoinsIcon, {}),
|
|
627
|
-
title: "Select a deposit",
|
|
628
|
-
subtitle: "This transaction produced multiple deposits. Choose the one to claim."
|
|
629
|
-
}
|
|
630
|
-
),
|
|
631
|
-
/* @__PURE__ */ jsx("div", { className: "rs-list", children: deposits.map((row) => {
|
|
632
|
-
const { symbol, amount, chainName } = describeDeposit(row);
|
|
633
|
-
const eligible = isEligible(row);
|
|
634
|
-
return /* @__PURE__ */ jsx(
|
|
635
|
-
ListRow,
|
|
636
|
-
{
|
|
637
|
-
leadingMedia: tokenIconUrl(symbol),
|
|
638
|
-
title: `${amount} ${symbol}`,
|
|
639
|
-
subtitle: chainName,
|
|
640
|
-
meta: eligible ? void 0 : humanizeStatus(row.status),
|
|
641
|
-
disabled: !eligible,
|
|
642
|
-
onClick: () => eligible && onSelect(row)
|
|
643
|
-
},
|
|
644
|
-
row.id ?? `${row.depositAddress}:${row.token}`
|
|
645
|
-
);
|
|
646
|
-
}) })
|
|
647
|
-
] }),
|
|
648
|
-
/* @__PURE__ */ jsx(PoweredBy, {})
|
|
649
|
-
] });
|
|
650
|
-
}
|
|
651
|
-
function ReviewStep({
|
|
652
|
-
deposit,
|
|
653
|
-
submitting,
|
|
654
|
-
defaultRefundDestination,
|
|
655
|
-
onSubmit
|
|
656
|
-
}) {
|
|
657
|
-
const analytics = useClaimAnalyticsController();
|
|
658
|
-
return /* @__PURE__ */ jsx(
|
|
659
|
-
RecoveryReviewScreen,
|
|
660
|
-
{
|
|
661
|
-
chainId: evmChainIdFromCaip2(deposit.chain) ?? 0,
|
|
662
|
-
token: deposit.token,
|
|
663
|
-
amountRaw: deposit.sourceAmount ?? deposit.amount,
|
|
664
|
-
txHash: sourceDepositTxHash(deposit),
|
|
665
|
-
defaultDestination: defaultRefundDestination,
|
|
666
|
-
submitting,
|
|
667
|
-
onSubmit,
|
|
668
|
-
onDestinationInvalid: () => analytics.friction("refund_destination_invalid", "review")
|
|
669
|
-
}
|
|
670
|
-
);
|
|
671
|
-
}
|
|
672
|
-
function ResultStep({
|
|
673
|
-
result,
|
|
674
|
-
error,
|
|
675
|
-
onClose,
|
|
676
|
-
onReset,
|
|
677
|
-
onRetry
|
|
678
|
-
}) {
|
|
679
|
-
return /* @__PURE__ */ jsx(
|
|
680
|
-
RecoveryOutcomeScreen,
|
|
681
|
-
{
|
|
682
|
-
result: result ? {
|
|
683
|
-
amountDisplay: result.amountDisplay,
|
|
684
|
-
symbol: result.symbol,
|
|
685
|
-
destination: result.destination,
|
|
686
|
-
txHash: result.txHash,
|
|
687
|
-
chainId: result.chain
|
|
688
|
-
} : null,
|
|
689
|
-
error,
|
|
690
|
-
children: result ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
691
|
-
onReset && /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onReset, fullWidth: true, children: "Claim another deposit" }),
|
|
692
|
-
/* @__PURE__ */ jsx(Button, { onClick: onClose, fullWidth: true, children: "Done" })
|
|
693
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
694
|
-
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onClose, fullWidth: true, children: "Cancel" }),
|
|
695
|
-
onRetry && /* @__PURE__ */ jsx(Button, { onClick: onRetry, fullWidth: true, children: "Try again" })
|
|
696
|
-
] })
|
|
697
|
-
}
|
|
698
|
-
);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
export {
|
|
702
|
-
buildClaimAnalyticsSessionProperties,
|
|
703
|
-
ClaimModal
|
|
704
|
-
};
|