@rhinestone/deposit-modal 0.5.1 → 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.
@@ -414,15 +414,12 @@ function depositRowToEvent(row) {
414
414
  const time = row.completedAt ?? row.createdAt ?? void 0;
415
415
  if (status === "completed") {
416
416
  return {
417
- type: "post-bridge-swap-complete",
417
+ type: "bridge-complete",
418
418
  time: time ?? void 0,
419
419
  data: {
420
420
  deposit,
421
421
  source,
422
- ...destination && { destination },
423
- ...destination && {
424
- swap: { transactionHash: destination.transactionHash }
425
- }
422
+ ...destination && { destination }
426
423
  }
427
424
  };
428
425
  }
@@ -541,15 +538,18 @@ function createDepositService(baseUrl, options) {
541
538
  }
542
539
  const PORTFOLIO_CACHE_TTL_MS = 3e4;
543
540
  const portfolioCache = /* @__PURE__ */ new Map();
544
- function cachedPortfolio(key, fetcher) {
541
+ function cachedPortfolio(key, fetcher, forceRefresh = false) {
545
542
  const now = Date.now();
546
543
  const entry = portfolioCache.get(key);
547
- if (entry && entry.expiresAt > now) {
544
+ if (!forceRefresh && entry && entry.expiresAt > now) {
548
545
  debugLog(debug, scope, "portfolio:cache-hit", { key });
549
546
  return entry.promise;
550
547
  }
551
- const promise = fetcher().catch((err) => {
552
- portfolioCache.delete(key);
548
+ let promise;
549
+ promise = fetcher().catch((err) => {
550
+ if (portfolioCache.get(key)?.promise === promise) {
551
+ portfolioCache.delete(key);
552
+ }
553
553
  throw err;
554
554
  });
555
555
  portfolioCache.set(key, {
@@ -567,7 +567,6 @@ function createDepositService(baseUrl, options) {
567
567
  targetChain: params.targetChain,
568
568
  targetToken: params.targetToken,
569
569
  recipient: params.recipient ? shortRef(params.recipient) : void 0,
570
- postBridgeActionCount: params.postBridgeActions?.length ?? 0,
571
570
  forceRegister: params.forceRegister
572
571
  });
573
572
  const response = await fetch(url, {
@@ -641,7 +640,7 @@ function createDepositService(baseUrl, options) {
641
640
  });
642
641
  return result;
643
642
  },
644
- async fetchPortfolio(address) {
643
+ async fetchPortfolio(address, options2) {
645
644
  return cachedPortfolio(`evm:${address.toLowerCase()}`, async () => {
646
645
  const url = apiUrl(`/portfolio/${address}`);
647
646
  debugLog(debug, scope, "fetchPortfolio:request", { url, address });
@@ -686,9 +685,9 @@ function createDepositService(baseUrl, options) {
686
685
  }
687
686
  debugLog(debug, scope, "fetchPortfolio:empty", { address });
688
687
  return { tokens: [], totalUsd: 0 };
689
- });
688
+ }, options2?.forceRefresh);
690
689
  },
691
- async fetchSolanaPortfolio(address) {
690
+ async fetchSolanaPortfolio(address, options2) {
692
691
  return cachedPortfolio(`sol:${address}`, async () => {
693
692
  const url = apiUrl(`/portfolio/solana/${address}`);
694
693
  debugLog(debug, scope, "fetchSolanaPortfolio:request", { url, address });
@@ -717,7 +716,7 @@ function createDepositService(baseUrl, options) {
717
716
  totalUsd: normalized.totalUsd
718
717
  });
719
718
  return normalized;
720
- });
719
+ }, options2?.forceRefresh);
721
720
  },
722
721
  async checkAccount(address) {
723
722
  const url = apiUrl(`/check/${address}`);
@@ -1736,7 +1735,7 @@ function Spinner({ className }) {
1736
1735
  }
1737
1736
 
1738
1737
  // src/components/steps/ConnectStep.tsx
1739
- import { useState } from "react";
1738
+ import { useEffect as useEffect3, useState } from "react";
1740
1739
 
1741
1740
  // src/components/ui/ListRow.tsx
1742
1741
  import { Fragment, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
@@ -2340,6 +2339,24 @@ function formatBalanceUsd(value) {
2340
2339
  if (!Number.isFinite(value) || value <= 0) return "$0.00";
2341
2340
  return `$${value.toFixed(2)}`;
2342
2341
  }
2342
+ function rankUsd(value) {
2343
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
2344
+ }
2345
+ function rankCryptoRows(descriptors) {
2346
+ return descriptors.map((descriptor, index) => ({ descriptor, index })).sort((a, b) => {
2347
+ const first = a.descriptor;
2348
+ const second = b.descriptor;
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
+ return second.balanceUsd - first.balanceUsd;
2356
+ }
2357
+ return a.index - b.index;
2358
+ }).map(({ descriptor }) => descriptor.node);
2359
+ }
2343
2360
  function fiatIcon(name) {
2344
2361
  if (name === "apple") return /* @__PURE__ */ jsx18(AppleIcon, {});
2345
2362
  if (name === "bank") return /* @__PURE__ */ jsx18(BankIcon, {});
@@ -2397,6 +2414,7 @@ function ConnectStep({
2397
2414
  onSelectPayWithCard,
2398
2415
  fiatPaymentMethods,
2399
2416
  onSelectFiatMethod,
2417
+ onPrefetchFiatMethod,
2400
2418
  onSelectFundFromExchange,
2401
2419
  onRequestConnect,
2402
2420
  onConnect,
@@ -2414,9 +2432,21 @@ function ConnectStep({
2414
2432
  );
2415
2433
  const showDappImports = (dappImports?.length ?? 0) > 0;
2416
2434
  const defaultSubtitle = onSelectTransferCrypto ? "Add money to your balance" : "Choose a wallet to continue";
2417
- const cryptoRows = [];
2435
+ const cryptoDescriptors = [];
2436
+ const pushAction = (node) => cryptoDescriptors.push({
2437
+ node,
2438
+ isBalanceSource: false,
2439
+ resolved: false,
2440
+ balanceUsd: 0
2441
+ });
2442
+ const pushBalanceSource = (node, resolved, balanceUsd) => cryptoDescriptors.push({
2443
+ node,
2444
+ isBalanceSource: true,
2445
+ resolved,
2446
+ balanceUsd: rankUsd(balanceUsd)
2447
+ });
2418
2448
  if (onSelectTransferCrypto) {
2419
- cryptoRows.push(
2449
+ pushAction(
2420
2450
  /* @__PURE__ */ jsx18(
2421
2451
  ListRow,
2422
2452
  {
@@ -2432,8 +2462,8 @@ function ConnectStep({
2432
2462
  }
2433
2463
  for (const row of rows) {
2434
2464
  const collapseToExternal = Boolean(onSelectTransferCrypto) && row.kind !== "solana";
2435
- const subtitleText = row.state === "loading" ? "Preparing\u2026" : row.state === "error" ? row.errorReason ?? "Couldn't prepare wallet \u2014 tap to retry" : shorten(row.address);
2436
- cryptoRows.push(
2465
+ const subtitleText = row.state === "loading" ? "Preparing\u2026" : row.state === "error" ? row.errorReason ?? "Couldn't prepare wallet \u2014 tap to retry" : row.balanceStatus === "ready" && row.balanceUsd != null ? formatBalanceUsd(row.balanceUsd) : row.balanceStatus === "loading" ? "Checking balance\u2026" : shorten(row.address);
2466
+ pushBalanceSource(
2437
2467
  /* @__PURE__ */ jsx18(
2438
2468
  ListRow,
2439
2469
  {
@@ -2445,11 +2475,13 @@ function ConnectStep({
2445
2475
  trailing: renderRowTrailing(row.state)
2446
2476
  },
2447
2477
  row.id
2448
- )
2478
+ ),
2479
+ row.balanceStatus === "ready",
2480
+ row.balanceUsd ?? 0
2449
2481
  );
2450
2482
  }
2451
2483
  if (!hasReownWallet && handleConnect) {
2452
- cryptoRows.push(
2484
+ pushAction(
2453
2485
  /* @__PURE__ */ jsx18(
2454
2486
  ListRow,
2455
2487
  {
@@ -2464,7 +2496,7 @@ function ConnectStep({
2464
2496
  );
2465
2497
  }
2466
2498
  if (onSelectFundFromExchange) {
2467
- cryptoRows.push(
2499
+ pushAction(
2468
2500
  /* @__PURE__ */ jsx18(
2469
2501
  ListRow,
2470
2502
  {
@@ -2481,7 +2513,7 @@ function ConnectStep({
2481
2513
  if (showDappImports) {
2482
2514
  for (const row of dappImports ?? []) {
2483
2515
  if (!hasReownWallet) {
2484
- cryptoRows.push(
2516
+ pushBalanceSource(
2485
2517
  /* @__PURE__ */ jsx18(
2486
2518
  ListRow,
2487
2519
  {
@@ -2492,12 +2524,14 @@ function ConnectStep({
2492
2524
  disabled: !handleConnect
2493
2525
  },
2494
2526
  row.id
2495
- )
2527
+ ),
2528
+ false,
2529
+ 0
2496
2530
  );
2497
2531
  continue;
2498
2532
  }
2499
2533
  if (row.status === "loading" || row.status === "needs-connect") {
2500
- cryptoRows.push(
2534
+ pushBalanceSource(
2501
2535
  /* @__PURE__ */ jsx18(
2502
2536
  ListRow,
2503
2537
  {
@@ -2508,12 +2542,14 @@ function ConnectStep({
2508
2542
  trailing: SMALL_SPINNER
2509
2543
  },
2510
2544
  row.id
2511
- )
2545
+ ),
2546
+ false,
2547
+ 0
2512
2548
  );
2513
2549
  continue;
2514
2550
  }
2515
2551
  if (row.status.enabled) {
2516
- cryptoRows.push(
2552
+ pushBalanceSource(
2517
2553
  /* @__PURE__ */ jsx18(
2518
2554
  ListRow,
2519
2555
  {
@@ -2523,12 +2559,14 @@ function ConnectStep({
2523
2559
  onClick: () => onSelectDappImport?.(row.id)
2524
2560
  },
2525
2561
  row.id
2526
- )
2562
+ ),
2563
+ true,
2564
+ row.status.balanceUsd
2527
2565
  );
2528
2566
  continue;
2529
2567
  }
2530
2568
  if (row.status.retryable) {
2531
- cryptoRows.push(
2569
+ pushBalanceSource(
2532
2570
  /* @__PURE__ */ jsx18(
2533
2571
  ListRow,
2534
2572
  {
@@ -2538,11 +2576,13 @@ function ConnectStep({
2538
2576
  onClick: () => onSelectDappImport?.(row.id)
2539
2577
  },
2540
2578
  row.id
2541
- )
2579
+ ),
2580
+ false,
2581
+ 0
2542
2582
  );
2543
2583
  continue;
2544
2584
  }
2545
- cryptoRows.push(
2585
+ pushBalanceSource(
2546
2586
  /* @__PURE__ */ jsx18(
2547
2587
  ListRow,
2548
2588
  {
@@ -2552,10 +2592,13 @@ function ConnectStep({
2552
2592
  disabled: true
2553
2593
  },
2554
2594
  row.id
2555
- )
2595
+ ),
2596
+ false,
2597
+ 0
2556
2598
  );
2557
2599
  }
2558
2600
  }
2601
+ const cryptoRows = rankCryptoRows(cryptoDescriptors);
2559
2602
  const cashRows = [];
2560
2603
  if (fiatPaymentMethods && fiatPaymentMethods.length > 0 && onSelectFiatMethod) {
2561
2604
  for (const opt of fiatPaymentMethods) {
@@ -2594,6 +2637,14 @@ function ConnectStep({
2594
2637
  const [tab, setTab] = useState(defaultMethodTab);
2595
2638
  const activeTab = showToggle ? tab : hasCash && !hasCrypto ? "cash" : "crypto";
2596
2639
  const activeRows = activeTab === "cash" ? cashRows : cryptoRows;
2640
+ useEffect3(() => {
2641
+ if (activeTab !== "cash" || !onPrefetchFiatMethod || !fiatPaymentMethods) {
2642
+ return;
2643
+ }
2644
+ for (const opt of fiatPaymentMethods) {
2645
+ onPrefetchFiatMethod(opt.method);
2646
+ }
2647
+ }, [activeTab, onPrefetchFiatMethod, fiatPaymentMethods]);
2597
2648
  return /* @__PURE__ */ jsxs16("div", { className: "rs-screen", children: [
2598
2649
  /* @__PURE__ */ jsxs16("div", { className: "rs-screen-body rs-screen-body--gap-32", children: [
2599
2650
  /* @__PURE__ */ jsx18(
@@ -2633,7 +2684,7 @@ function ConnectStep({
2633
2684
  ConnectStep.displayName = "ConnectStep";
2634
2685
 
2635
2686
  // src/components/steps/ProcessingStep.tsx
2636
- import { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
2687
+ import { useCallback as useCallback3, useEffect as useEffect6, useRef as useRef4, useState as useState5 } from "react";
2637
2688
 
2638
2689
  // src/components/ui/Button.tsx
2639
2690
  import { Fragment as Fragment3, jsx as jsx19, jsxs as jsxs17 } from "react/jsx-runtime";
@@ -2679,7 +2730,7 @@ Button.displayName = "Button";
2679
2730
  import {
2680
2731
  useState as useState2,
2681
2732
  useRef as useRef3,
2682
- useEffect as useEffect3,
2733
+ useEffect as useEffect4,
2683
2734
  useCallback as useCallback2
2684
2735
  } from "react";
2685
2736
  import { createPortal as createPortal2 } from "react-dom";
@@ -2698,7 +2749,7 @@ function Tooltip({ content, children, className }) {
2698
2749
  left: rect.left + rect.width / 2
2699
2750
  });
2700
2751
  }, []);
2701
- useEffect3(() => {
2752
+ useEffect4(() => {
2702
2753
  if (!open) return;
2703
2754
  updatePosition();
2704
2755
  function handleOutside(event) {
@@ -2905,10 +2956,6 @@ function getEventTxHash(event) {
2905
2956
  const source = isRecord(event.data?.source) ? event.data.source : void 0;
2906
2957
  return asString(deposit?.transactionHash) ?? asString(source?.transactionHash);
2907
2958
  }
2908
- if (event.type === "post-bridge-swap-complete" || event.type === "post-bridge-swap-failed") {
2909
- const deposit = isRecord(event.data?.deposit) ? event.data.deposit : void 0;
2910
- return asString(deposit?.transactionHash);
2911
- }
2912
2959
  return void 0;
2913
2960
  }
2914
2961
  function getEventSourceDetails(event) {
@@ -2922,7 +2969,7 @@ function getEventSourceDetails(event) {
2922
2969
  }
2923
2970
  const source = isRecord(event.data.source) ? event.data.source : void 0;
2924
2971
  const deposit = isRecord(event.data.deposit) ? event.data.deposit : void 0;
2925
- if (event.type === "bridge-started" || event.type === "bridge-complete" || event.type === "bridge-failed" || event.type === "error" || event.type === "post-bridge-swap-complete" || event.type === "post-bridge-swap-failed") {
2972
+ if (event.type === "bridge-started" || event.type === "bridge-complete" || event.type === "bridge-failed" || event.type === "error") {
2926
2973
  return {
2927
2974
  chainId: asNumber(source?.chain) ?? asNumber(deposit?.chain),
2928
2975
  amount: asAmount(source?.amount) ?? asAmount(deposit?.amount),
@@ -2939,7 +2986,7 @@ function asChain(value) {
2939
2986
  }
2940
2987
  function getEventDestinationDetails(event) {
2941
2988
  if (!event?.type || !isRecord(event.data)) return {};
2942
- if (event.type !== "bridge-started" && event.type !== "bridge-complete" && event.type !== "post-bridge-swap-complete") {
2989
+ if (event.type !== "bridge-started" && event.type !== "bridge-complete") {
2943
2990
  return {};
2944
2991
  }
2945
2992
  const destination = isRecord(event.data.destination) ? event.data.destination : void 0;
@@ -2952,10 +2999,10 @@ function getEventDestinationDetails(event) {
2952
2999
  };
2953
3000
  }
2954
3001
  function isDepositEvent(event) {
2955
- return event?.type === "deposit-received" || event?.type === "bridge-started" || event?.type === "bridge-complete" || event?.type === "bridge-failed" || event?.type === "post-bridge-swap-complete" || event?.type === "post-bridge-swap-failed" || event?.type === "error";
3002
+ return event?.type === "deposit-received" || event?.type === "bridge-started" || event?.type === "bridge-complete" || event?.type === "bridge-failed" || event?.type === "error";
2956
3003
  }
2957
3004
  function isFailedEvent(event) {
2958
- return event?.type === "bridge-failed" || event?.type === "post-bridge-swap-failed" || event?.type === "error";
3005
+ return event?.type === "bridge-failed" || event?.type === "error";
2959
3006
  }
2960
3007
  function isHexString(value) {
2961
3008
  return value.startsWith("0x") || value.startsWith("0X");
@@ -3116,7 +3163,7 @@ function formatReceiveEstimate(params) {
3116
3163
  }
3117
3164
 
3118
3165
  // src/core/useTokenPrices.ts
3119
- import { useEffect as useEffect4, useState as useState4 } from "react";
3166
+ import { useEffect as useEffect5, useState as useState4 } from "react";
3120
3167
  function useTokenPrices(service, symbols) {
3121
3168
  const [prices, setPrices] = useState4({});
3122
3169
  const symbolsKey = [
@@ -3124,7 +3171,7 @@ function useTokenPrices(service, symbols) {
3124
3171
  symbols.filter((symbol) => Boolean(symbol)).map((symbol) => symbol.toUpperCase())
3125
3172
  )
3126
3173
  ].sort().join(",");
3127
- useEffect4(() => {
3174
+ useEffect5(() => {
3128
3175
  if (!symbolsKey) return;
3129
3176
  let cancelled = false;
3130
3177
  service.fetchPrices(symbolsKey.split(",")).then((result) => {
@@ -3270,9 +3317,9 @@ function parseWebhookTimestamp(event) {
3270
3317
  function syncPhaseTimings(previous, event) {
3271
3318
  if (!event?.type) return previous;
3272
3319
  const timestamp = parseWebhookTimestamp(event) ?? Date.now();
3273
- const setReceived = (event.type === "deposit-received" || event.type === "bridge-started" || event.type === "bridge-complete" || event.type === "bridge-failed" || event.type === "post-bridge-swap-complete" || event.type === "post-bridge-swap-failed" || event.type === "error") && previous.receivedAt === void 0;
3274
- const setBridging = (event.type === "bridge-started" || event.type === "bridge-complete" || event.type === "post-bridge-swap-complete") && previous.bridgingAt === void 0;
3275
- const setCompleted = (event.type === "bridge-complete" || event.type === "post-bridge-swap-complete") && previous.completedAt === void 0;
3320
+ const setReceived = (event.type === "deposit-received" || event.type === "bridge-started" || event.type === "bridge-complete" || event.type === "bridge-failed" || event.type === "error") && previous.receivedAt === void 0;
3321
+ const setBridging = (event.type === "bridge-started" || event.type === "bridge-complete") && previous.bridgingAt === void 0;
3322
+ const setCompleted = event.type === "bridge-complete" && previous.completedAt === void 0;
3276
3323
  if (!setReceived && !setBridging && !setCompleted) return previous;
3277
3324
  return {
3278
3325
  ...previous,
@@ -3291,7 +3338,7 @@ function TickerChar({ value }) {
3291
3338
  const [current, setCurrent] = useState5(value);
3292
3339
  const [previous, setPrevious] = useState5(null);
3293
3340
  const [animKey, setAnimKey] = useState5(0);
3294
- useEffect5(() => {
3341
+ useEffect6(() => {
3295
3342
  if (value === current) return;
3296
3343
  setPrevious(current);
3297
3344
  setCurrent(value);
@@ -3335,6 +3382,59 @@ function getCurrentPhaseId(state, phaseTimings) {
3335
3382
  if (state.lastEvent?.type === "deposit-received") return "received";
3336
3383
  return "confirming";
3337
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
+ }
3338
3438
  function ProcessingStep({
3339
3439
  smartAccount,
3340
3440
  solanaDepositAddress,
@@ -3346,9 +3446,9 @@ function ProcessingStep({
3346
3446
  sourceSymbol: providedSourceSymbol,
3347
3447
  sourceDecimals: providedSourceDecimals,
3348
3448
  amountUsd,
3349
- hasPostBridgeActions,
3350
3449
  service,
3351
3450
  directTransfer,
3451
+ initialEvent,
3352
3452
  flowLabel = "deposit",
3353
3453
  debug,
3354
3454
  targetToken,
@@ -3376,15 +3476,26 @@ function ProcessingStep({
3376
3476
  sourceDecimals: providedSourceDecimals,
3377
3477
  amountUsd,
3378
3478
  targetChain,
3379
- targetToken,
3380
- hasPostBridgeActions
3479
+ targetToken
3381
3480
  });
3382
3481
  const onDepositCompleteRef = useLatestRef(onDepositComplete);
3383
3482
  const onDepositFailedRef = useLatestRef(onDepositFailed);
3384
3483
  const onErrorRef = useLatestRef(onError);
3385
- const [state, setState] = useState5(
3386
- directTransfer ? { type: "complete" } : { type: "processing" }
3387
- );
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
+ });
3388
3499
  const [elapsedSeconds, setElapsedSeconds] = useState5(0);
3389
3500
  const [phaseTimings, setPhaseTimings] = useState5(() => {
3390
3501
  const saved = loadPhaseTimings(txHash);
@@ -3405,7 +3516,7 @@ function ProcessingStep({
3405
3516
  },
3406
3517
  [txHash]
3407
3518
  );
3408
- useEffect5(() => {
3519
+ useEffect6(() => {
3409
3520
  if (!directTransfer) return;
3410
3521
  const completedAt = Date.now();
3411
3522
  updatePhaseTimings(() => ({
@@ -3436,7 +3547,44 @@ function ProcessingStep({
3436
3547
  txHash,
3437
3548
  updatePhaseTimings
3438
3549
  ]);
3439
- useEffect5(() => {
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
+ ]);
3587
+ useEffect6(() => {
3440
3588
  if (directTransfer || state.type !== "processing") return;
3441
3589
  const updateElapsed = () => {
3442
3590
  setElapsedSeconds(
@@ -3447,7 +3595,7 @@ function ProcessingStep({
3447
3595
  const intervalId = setInterval(updateElapsed, 1e3);
3448
3596
  return () => clearInterval(intervalId);
3449
3597
  }, [directTransfer, state.type]);
3450
- useEffect5(() => {
3598
+ useEffect6(() => {
3451
3599
  if (state.type === "processing") return;
3452
3600
  const endedAt = state.type === "complete" ? phaseTimings.completedAt ?? Date.now() : Date.now();
3453
3601
  setElapsedSeconds(Math.floor((endedAt - startTimeRef.current) / 1e3));
@@ -3455,14 +3603,14 @@ function ProcessingStep({
3455
3603
  (previous) => previous.endedAt !== void 0 ? previous : { ...previous, endedAt }
3456
3604
  );
3457
3605
  }, [phaseTimings.completedAt, state.type, updatePhaseTimings]);
3458
- useEffect5(() => {
3606
+ useEffect6(() => {
3459
3607
  if (!state.lastEvent) return;
3460
3608
  updatePhaseTimings(
3461
3609
  (previous) => syncPhaseTimings(previous, state.lastEvent)
3462
3610
  );
3463
3611
  }, [state.lastEvent?.time, state.lastEvent?.type, updatePhaseTimings]);
3464
3612
  const [swappedFiatContext, setSwappedFiatContext] = useState5(null);
3465
- useEffect5(() => {
3613
+ useEffect6(() => {
3466
3614
  let cancelled = false;
3467
3615
  service.fetchSwappedOrderStatus(smartAccount).then((res) => {
3468
3616
  if (cancelled || !res) return;
@@ -3485,7 +3633,7 @@ function ProcessingStep({
3485
3633
  cancelled = true;
3486
3634
  };
3487
3635
  }, [service, smartAccount, txHash, isSwappedOrder, swappedContext?.variant]);
3488
- useEffect5(() => {
3636
+ useEffect6(() => {
3489
3637
  if (directTransfer) return;
3490
3638
  if (state.type !== "processing") {
3491
3639
  pollIntervalRef.current = INITIAL_POLL_INTERVAL;
@@ -3513,43 +3661,7 @@ function ProcessingStep({
3513
3661
  });
3514
3662
  }
3515
3663
  if (!isMounted) return;
3516
- const awaitingPostBridgeSwap = processingContextRef.current.hasPostBridgeActions;
3517
- if (eventForCurrentTx?.type === "post-bridge-swap-complete") {
3518
- setState({ type: "complete", lastEvent: eventForCurrentTx });
3519
- const swapTxHash = eventForCurrentTx.data?.swap?.transactionHash;
3520
- debugLog(debug, "processing", "state:complete", {
3521
- txHash,
3522
- destinationTxHash: swapTxHash,
3523
- event: eventForCurrentTx.type
3524
- });
3525
- const context = processingContextRef.current;
3526
- onDepositCompleteRef.current?.(txHash, swapTxHash, {
3527
- amount: context.amount,
3528
- sourceChain: context.sourceChain,
3529
- sourceToken: context.sourceToken,
3530
- sourceDecimals: context.sourceDecimals,
3531
- amountUsd: context.amountUsd,
3532
- targetChain: context.targetChain,
3533
- targetToken: context.targetToken
3534
- });
3535
- return;
3536
- }
3537
- if (eventForCurrentTx?.type === "post-bridge-swap-failed") {
3538
- const formatted = formatBridgeFailedMessage(eventForCurrentTx);
3539
- setState({
3540
- type: "failed",
3541
- message: formatted.message,
3542
- lastEvent: eventForCurrentTx
3543
- });
3544
- debugLog(debug, "processing", "state:failed", {
3545
- txHash,
3546
- message: formatted.message,
3547
- code: formatted.code
3548
- });
3549
- onDepositFailedRef.current?.(txHash, formatted.message);
3550
- return;
3551
- }
3552
- if (eventForCurrentTx?.type === "bridge-complete" && !awaitingPostBridgeSwap) {
3664
+ if (eventForCurrentTx?.type === "bridge-complete") {
3553
3665
  setState({ type: "complete", lastEvent: eventForCurrentTx });
3554
3666
  const destinationTxHash2 = eventForCurrentTx.data?.destination?.transactionHash;
3555
3667
  debugLog(debug, "processing", "state:complete", {
@@ -3645,7 +3757,7 @@ function ProcessingStep({
3645
3757
  state.type,
3646
3758
  txHash
3647
3759
  ]);
3648
- useEffect5(() => {
3760
+ useEffect6(() => {
3649
3761
  if (directTransfer || state.type !== "processing") return;
3650
3762
  const timeoutId = setTimeout(() => {
3651
3763
  if (escalatedDelayRef.current) return;
@@ -3668,8 +3780,7 @@ function ProcessingStep({
3668
3780
  const timelineNowMs = phaseTimings.endedAt ?? Date.now();
3669
3781
  const flowNoun = flowLabel === "withdraw" ? "withdrawal" : "deposit";
3670
3782
  const flowCapitalized = flowLabel === "withdraw" ? "Withdrawal" : "Deposit";
3671
- const isPostBridgeSwapEvent = lastEvent?.type === "post-bridge-swap-complete" || lastEvent?.type === "post-bridge-swap-failed";
3672
- const destinationTxHash = isPostBridgeSwapEvent ? lastEvent?.data?.swap?.transactionHash || null : lastEvent?.data?.destination?.transactionHash || null;
3783
+ const destinationTxHash = lastEvent?.data?.destination?.transactionHash || null;
3673
3784
  const sourceDetails = getEventSourceDetails(lastEvent);
3674
3785
  const displaySourceChain = sourceDetails.chainId ?? sourceChain;
3675
3786
  const displaySourceToken = sourceDetails.token ?? sourceToken;
@@ -3689,8 +3800,7 @@ function ProcessingStep({
3689
3800
  const sourceSymbol = sourceDisplay.symbol;
3690
3801
  const formattedSentAmount = formatRawTokenAmount(displayAmount, sourceDisplay) ?? // Not raw base units (e.g. a decimal string) — render the number as-is.
3691
3802
  formatTokenAmount(Number(displayAmount), sourceDisplay.symbol) ?? displayAmount;
3692
- const isBridgeHopDestination = hasPostBridgeActions && (lastEvent?.type === "bridge-started" || lastEvent?.type === "bridge-complete");
3693
- const eventDestination = isBridgeHopDestination ? {} : getEventDestinationDetails(lastEvent);
3803
+ const eventDestination = getEventDestinationDetails(lastEvent);
3694
3804
  const targetDisplay = resolveTokenDisplay(
3695
3805
  eventDestination.token ?? targetToken,
3696
3806
  eventDestination.chainId ?? targetChain,