@rhinestone/deposit-modal 0.6.0 → 0.6.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.
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunk7LVI3VALcjs = require('./chunk-7LVI3VAL.cjs');
3
+ var _chunkIZPUHIINcjs = require('./chunk-IZPUHIIN.cjs');
4
4
  require('./chunk-NRNJAQUA.cjs');
5
5
 
6
6
 
7
7
 
8
- var _chunkYYIE5U5Kcjs = require('./chunk-YYIE5U5K.cjs');
9
- require('./chunk-ZDYV536Q.cjs');
8
+ var _chunkVVKJRGX3cjs = require('./chunk-VVKJRGX3.cjs');
9
+ require('./chunk-VPWWFWZT.cjs');
10
10
  require('./chunk-UEKPBRBY.cjs');
11
11
  require('./chunk-ABVRVW3P.cjs');
12
12
 
@@ -16,7 +16,7 @@ var _react3 = require('@reown/appkit/react');
16
16
  var _react5 = require('@reown/appkit-adapter-solana/react');
17
17
  var _jsxruntime = require('react/jsx-runtime');
18
18
  function DepositModalWithReown(props) {
19
- const reown = _chunkYYIE5U5Kcjs.useReownWallet.call(void 0, );
19
+ const reown = _chunkVVKJRGX3cjs.useReownWallet.call(void 0, );
20
20
  const enableSolana = _nullishCoalesce(props.enableSolana, () => ( true));
21
21
  const { walletProvider: solanaWalletProvider } = _react3.useAppKitProvider.call(void 0,
22
22
  enableSolana ? "solana" : "eip155"
@@ -37,7 +37,7 @@ function DepositModalWithReown(props) {
37
37
  reown.disconnect();
38
38
  }, [reown.disconnect]);
39
39
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
40
- _chunk7LVI3VALcjs.DepositModalInner,
40
+ _chunkIZPUHIINcjs.DepositModalInner,
41
41
  {
42
42
  ...props,
43
43
  reownWallet: reownWithSolana,
@@ -48,7 +48,7 @@ function DepositModalWithReown(props) {
48
48
  }
49
49
  function DepositModalReown(props) {
50
50
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
51
- _chunkYYIE5U5Kcjs.ReownWalletProvider,
51
+ _chunkVVKJRGX3cjs.ReownWalletProvider,
52
52
  {
53
53
  projectId: props.reownAppId,
54
54
  theme: props.theme,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  DepositModalInner
3
- } from "./chunk-NSAODZSS.mjs";
3
+ } from "./chunk-TCLBFO3S.mjs";
4
4
  import "./chunk-FJWLC4AM.mjs";
5
5
  import {
6
6
  ReownWalletProvider,
7
7
  useReownWallet
8
- } from "./chunk-DXGM6YET.mjs";
9
- import "./chunk-GQDVHMOT.mjs";
8
+ } from "./chunk-7Q26RR6J.mjs";
9
+ import "./chunk-GBOCV2LQ.mjs";
10
10
  import "./chunk-F7P4MV72.mjs";
11
11
  import "./chunk-WJX3TJFK.mjs";
12
12
 
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkDASS33PJcjs = require('./chunk-DASS33PJ.cjs');
3
+ var _chunkSITLCMTIcjs = require('./chunk-SITLCMTI.cjs');
4
4
 
5
5
 
6
6
 
7
- var _chunkYYIE5U5Kcjs = require('./chunk-YYIE5U5K.cjs');
8
- require('./chunk-ZDYV536Q.cjs');
7
+ var _chunkVVKJRGX3cjs = require('./chunk-VVKJRGX3.cjs');
8
+ require('./chunk-VPWWFWZT.cjs');
9
9
  require('./chunk-UEKPBRBY.cjs');
10
10
  require('./chunk-ABVRVW3P.cjs');
11
11
 
@@ -13,7 +13,7 @@ require('./chunk-ABVRVW3P.cjs');
13
13
  var _react = require('react');
14
14
  var _jsxruntime = require('react/jsx-runtime');
15
15
  function WithdrawModalWithReown(props) {
16
- const reown = _chunkYYIE5U5Kcjs.useReownWallet.call(void 0, );
16
+ const reown = _chunkVVKJRGX3cjs.useReownWallet.call(void 0, );
17
17
  const handleConnect = _react.useCallback.call(void 0, () => {
18
18
  reown.openConnect();
19
19
  }, [reown.openConnect]);
@@ -21,7 +21,7 @@ function WithdrawModalWithReown(props) {
21
21
  reown.disconnect();
22
22
  }, [reown.disconnect]);
23
23
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
24
- _chunkDASS33PJcjs.WithdrawModalInner,
24
+ _chunkSITLCMTIcjs.WithdrawModalInner,
25
25
  {
26
26
  ...props,
27
27
  reownWallet: reown,
@@ -32,7 +32,7 @@ function WithdrawModalWithReown(props) {
32
32
  }
33
33
  function WithdrawModalReown(props) {
34
34
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
35
- _chunkYYIE5U5Kcjs.ReownWalletProvider,
35
+ _chunkVVKJRGX3cjs.ReownWalletProvider,
36
36
  {
37
37
  projectId: props.reownAppId,
38
38
  theme: props.theme,
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  WithdrawModalInner
3
- } from "./chunk-3JVGI7FC.mjs";
3
+ } from "./chunk-N73D3WN4.mjs";
4
4
  import {
5
5
  ReownWalletProvider,
6
6
  useReownWallet
7
- } from "./chunk-DXGM6YET.mjs";
8
- import "./chunk-GQDVHMOT.mjs";
7
+ } from "./chunk-7Q26RR6J.mjs";
8
+ import "./chunk-GBOCV2LQ.mjs";
9
9
  import "./chunk-F7P4MV72.mjs";
10
10
  import "./chunk-WJX3TJFK.mjs";
11
11
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isUnsupportedChainSwitchError,
3
3
  rpcUrlFor
4
- } from "./chunk-GQDVHMOT.mjs";
4
+ } from "./chunk-GBOCV2LQ.mjs";
5
5
  import {
6
6
  SUPPORTED_CHAINS,
7
7
  getChainName
@@ -2346,12 +2346,12 @@ function rankCryptoRows(descriptors) {
2346
2346
  return descriptors.map((descriptor, index) => ({ descriptor, index })).sort((a, b) => {
2347
2347
  const first = a.descriptor;
2348
2348
  const second = b.descriptor;
2349
- if (first.isBalanceSource !== second.isBalanceSource) {
2350
- return first.isBalanceSource ? -1 : 1;
2351
- }
2352
- if (!first.isBalanceSource) return a.index - b.index;
2353
- if (first.resolved !== second.resolved) return first.resolved ? -1 : 1;
2354
- if (first.resolved && first.balanceUsd !== second.balanceUsd) {
2349
+ const firstHasFunds = first.isBalanceSource && first.resolved && first.balanceUsd > 0;
2350
+ const secondHasFunds = second.isBalanceSource && second.resolved && second.balanceUsd > 0;
2351
+ const firstTier = firstHasFunds ? 0 : first.isBalanceSource ? 2 : 1;
2352
+ const secondTier = secondHasFunds ? 0 : second.isBalanceSource ? 2 : 1;
2353
+ if (firstTier !== secondTier) return firstTier - secondTier;
2354
+ if (firstTier === 0 && first.balanceUsd !== second.balanceUsd) {
2355
2355
  return second.balanceUsd - first.balanceUsd;
2356
2356
  }
2357
2357
  return a.index - b.index;
@@ -3382,6 +3382,59 @@ function getCurrentPhaseId(state, phaseTimings) {
3382
3382
  if (state.lastEvent?.type === "deposit-received") return "received";
3383
3383
  return "confirming";
3384
3384
  }
3385
+ function getCompletionDestinationTxHash(event) {
3386
+ const eventData = event?.data;
3387
+ const swapTxHash = eventData?.swap?.transactionHash;
3388
+ const destinationTxHash = eventData?.destination?.transactionHash;
3389
+ return swapTxHash ?? destinationTxHash;
3390
+ }
3391
+ function getTerminalProcessingOutcome(event) {
3392
+ if (event?.type === "post-bridge-swap-complete") {
3393
+ return {
3394
+ type: "complete",
3395
+ destinationTxHash: getCompletionDestinationTxHash(event)
3396
+ };
3397
+ }
3398
+ if (event?.type === "post-bridge-swap-failed") {
3399
+ return {
3400
+ type: "failed",
3401
+ message: formatBridgeFailedMessage(event).message
3402
+ };
3403
+ }
3404
+ if (event?.type === "bridge-complete") {
3405
+ return {
3406
+ type: "complete",
3407
+ destinationTxHash: getCompletionDestinationTxHash(event)
3408
+ };
3409
+ }
3410
+ if (event?.type === "bridge-failed") {
3411
+ return {
3412
+ type: "failed",
3413
+ message: formatBridgeFailedMessage(event).message
3414
+ };
3415
+ }
3416
+ if (event?.type === "error") {
3417
+ return {
3418
+ type: "failed",
3419
+ message: event.data?.message ?? "Unknown error"
3420
+ };
3421
+ }
3422
+ return null;
3423
+ }
3424
+ function getInitialProcessingState(event, txHash) {
3425
+ if (!event || !isEventForTx(event, txHash)) return null;
3426
+ const terminal = getTerminalProcessingOutcome(event);
3427
+ if (terminal?.type === "complete") {
3428
+ return { type: "complete", lastEvent: event };
3429
+ }
3430
+ if (terminal?.type === "failed") {
3431
+ return { type: "failed", message: terminal.message, lastEvent: event };
3432
+ }
3433
+ if (isDepositEvent(event)) {
3434
+ return { type: "processing", lastEvent: event };
3435
+ }
3436
+ return null;
3437
+ }
3385
3438
  function ProcessingStep({
3386
3439
  smartAccount,
3387
3440
  solanaDepositAddress,
@@ -3395,6 +3448,7 @@ function ProcessingStep({
3395
3448
  amountUsd,
3396
3449
  service,
3397
3450
  directTransfer,
3451
+ initialEvent,
3398
3452
  flowLabel = "deposit",
3399
3453
  debug,
3400
3454
  targetToken,
@@ -3427,9 +3481,21 @@ function ProcessingStep({
3427
3481
  const onDepositCompleteRef = useLatestRef(onDepositComplete);
3428
3482
  const onDepositFailedRef = useLatestRef(onDepositFailed);
3429
3483
  const onErrorRef = useLatestRef(onError);
3430
- const [state, setState] = useState5(
3431
- directTransfer ? { type: "complete" } : { type: "processing" }
3432
- );
3484
+ const initialTerminalEventRef = useRef4(null);
3485
+ const [state, setState] = useState5(() => {
3486
+ if (directTransfer) return { type: "complete" };
3487
+ const initial = getInitialProcessingState(
3488
+ initialEvent,
3489
+ txHash
3490
+ );
3491
+ if (initial) {
3492
+ if (initial.type !== "processing") {
3493
+ initialTerminalEventRef.current = initial.lastEvent ?? null;
3494
+ }
3495
+ return initial;
3496
+ }
3497
+ return { type: "processing" };
3498
+ });
3433
3499
  const [elapsedSeconds, setElapsedSeconds] = useState5(0);
3434
3500
  const [phaseTimings, setPhaseTimings] = useState5(() => {
3435
3501
  const saved = loadPhaseTimings(txHash);
@@ -3481,6 +3547,43 @@ function ProcessingStep({
3481
3547
  txHash,
3482
3548
  updatePhaseTimings
3483
3549
  ]);
3550
+ useEffect6(() => {
3551
+ const event = initialTerminalEventRef.current;
3552
+ if (!event) return;
3553
+ initialTerminalEventRef.current = null;
3554
+ const outcome = getTerminalProcessingOutcome(event);
3555
+ if (!outcome) return;
3556
+ if (outcome.type === "complete") {
3557
+ const context = processingContextRef.current;
3558
+ debugLog(debug, "processing", "initial-event:complete", {
3559
+ txHash,
3560
+ destinationTxHash: outcome.destinationTxHash,
3561
+ event: event.type
3562
+ });
3563
+ onDepositCompleteRef.current?.(txHash, outcome.destinationTxHash, {
3564
+ amount: context.amount,
3565
+ sourceChain: context.sourceChain,
3566
+ sourceToken: context.sourceToken,
3567
+ sourceDecimals: context.sourceDecimals,
3568
+ amountUsd: context.amountUsd,
3569
+ targetChain: context.targetChain,
3570
+ targetToken: context.targetToken
3571
+ });
3572
+ return;
3573
+ }
3574
+ debugLog(debug, "processing", "initial-event:failed", {
3575
+ txHash,
3576
+ message: outcome.message,
3577
+ event: event.type
3578
+ });
3579
+ onDepositFailedRef.current?.(txHash, outcome.message);
3580
+ }, [
3581
+ debug,
3582
+ onDepositCompleteRef,
3583
+ onDepositFailedRef,
3584
+ processingContextRef,
3585
+ txHash
3586
+ ]);
3484
3587
  useEffect6(() => {
3485
3588
  if (directTransfer || state.type !== "processing") return;
3486
3589
  const updateElapsed = () => {