@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.
@@ -68,7 +68,7 @@ import {
68
68
  useLatestRef,
69
69
  useRpcUrls,
70
70
  useStableRpcUrls
71
- } from "./chunk-4YLVKTSU.mjs";
71
+ } from "./chunk-GBOCV2LQ.mjs";
72
72
  import {
73
73
  SAFE_ABI
74
74
  } from "./chunk-F7P4MV72.mjs";
@@ -1174,7 +1174,6 @@ function DepositNotification({
1174
1174
  solanaDepositAddress,
1175
1175
  targetChain,
1176
1176
  targetToken,
1177
- hasPostBridgeActions,
1178
1177
  service,
1179
1178
  onComplete,
1180
1179
  onFailed,
@@ -1208,8 +1207,7 @@ function DepositNotification({
1208
1207
  sourceToken: token,
1209
1208
  sourceDecimals,
1210
1209
  targetChain,
1211
- targetToken,
1212
- hasPostBridgeActions
1210
+ targetToken
1213
1211
  });
1214
1212
  const onCompleteRef = useLatestRef(onComplete);
1215
1213
  const onFailedRef = useLatestRef(onFailed);
@@ -1255,17 +1253,7 @@ function DepositNotification({
1255
1253
  if (!isMounted) return;
1256
1254
  const lastEvent = data.lastEvent;
1257
1255
  const eventForTx = isEventForTx(lastEvent, txHash) ? lastEvent : void 0;
1258
- const awaitingPostBridgeSwap = depositContextRef.current.hasPostBridgeActions;
1259
- if (eventForTx?.type === "post-bridge-swap-complete") {
1260
- const swapTxHash = eventForTx.data?.swap?.transactionHash;
1261
- handleComplete(swapTxHash);
1262
- return;
1263
- }
1264
- if (eventForTx?.type === "post-bridge-swap-failed") {
1265
- handleFailed(formatBridgeFailedMessage(eventForTx));
1266
- return;
1267
- }
1268
- if (eventForTx?.type === "bridge-complete" && !awaitingPostBridgeSwap) {
1256
+ if (eventForTx?.type === "bridge-complete") {
1269
1257
  const destTx = eventForTx.data?.destination?.transactionHash;
1270
1258
  handleComplete(destTx);
1271
1259
  return;
@@ -1530,7 +1518,6 @@ function DepositAddressStep({
1530
1518
  allowedRoutes,
1531
1519
  targetChain,
1532
1520
  targetToken,
1533
- hasPostBridgeActions,
1534
1521
  uiConfig,
1535
1522
  onDepositSubmitted,
1536
1523
  onDepositComplete,
@@ -2037,7 +2024,6 @@ function DepositAddressStep({
2037
2024
  solanaDepositAddress,
2038
2025
  targetChain,
2039
2026
  targetToken,
2040
- hasPostBridgeActions,
2041
2027
  service,
2042
2028
  onComplete: handleNotificationComplete,
2043
2029
  onFailed: handleNotificationFailed,
@@ -2053,6 +2039,20 @@ DepositAddressStep.displayName = "DepositAddressStep";
2053
2039
  // src/components/steps/FiatOnrampStep.tsx
2054
2040
  import { useCallback as useCallback3 } from "react";
2055
2041
 
2042
+ // src/core/swapped.ts
2043
+ var SWAPPED_ORIGINS = [
2044
+ "https://connect.swapped.com",
2045
+ "https://sandbox.swapped.com",
2046
+ "https://widget.swapped.com"
2047
+ ];
2048
+ var WIDGET_URL_EXPIRY_BUFFER_MS = 1e4;
2049
+ function isSwappedWidgetUrlFresh(res, now = Date.now()) {
2050
+ if (!res.expiresAt) return false;
2051
+ const expiry = Date.parse(res.expiresAt);
2052
+ if (!Number.isFinite(expiry)) return false;
2053
+ return expiry - now > WIDGET_URL_EXPIRY_BUFFER_MS;
2054
+ }
2055
+
2056
2056
  // src/components/steps/SwappedIframeStep.tsx
2057
2057
  import { useState as useState6, useEffect as useEffect6, useRef as useRef6, useMemo as useMemo4 } from "react";
2058
2058
 
@@ -2176,11 +2176,7 @@ var DEPOSIT_POLL_INTERVAL_MS = 2e3;
2176
2176
  var DEPOSIT_POLL_FAST_INITIAL_DELAY_MS = 1e3;
2177
2177
  var DEPOSIT_POLL_FAST_INTERVAL_MS = 500;
2178
2178
  var IFRAME_LOAD_TIMEOUT_MS = 15e3;
2179
- var SWAPPED_IFRAME_ORIGINS = /* @__PURE__ */ new Set([
2180
- "https://connect.swapped.com",
2181
- "https://sandbox.swapped.com",
2182
- "https://widget.swapped.com"
2183
- ]);
2179
+ var SWAPPED_IFRAME_ORIGINS = new Set(SWAPPED_ORIGINS);
2184
2180
  var SWAPPED_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
2185
2181
  "order_completed",
2186
2182
  "order_broadcasted"
@@ -2191,6 +2187,24 @@ var SWAPPED_STATUS_VALUES = /* @__PURE__ */ new Set([
2191
2187
  "order_broadcasted",
2192
2188
  "order_cancelled"
2193
2189
  ]);
2190
+ var SWAPPED_GO_BACK_KEY = "SWAPPED_GO_BACK";
2191
+ function parseMaybeJsonString(raw) {
2192
+ try {
2193
+ return JSON.parse(raw);
2194
+ } catch {
2195
+ return raw;
2196
+ }
2197
+ }
2198
+ function isSwappedGoBackMessage(raw) {
2199
+ let data = raw;
2200
+ if (typeof data === "string") {
2201
+ data = parseMaybeJsonString(data);
2202
+ }
2203
+ if (data === SWAPPED_GO_BACK_KEY) return true;
2204
+ if (!data || typeof data !== "object") return false;
2205
+ const obj = data;
2206
+ return obj.key === SWAPPED_GO_BACK_KEY || obj.type === SWAPPED_GO_BACK_KEY;
2207
+ }
2194
2208
  function parseSwappedIframeMessage(raw) {
2195
2209
  let data = raw;
2196
2210
  if (typeof data === "string") {
@@ -2211,6 +2225,7 @@ function parseSwappedIframeMessage(raw) {
2211
2225
  return {
2212
2226
  status: rawStatus,
2213
2227
  orderId: asString2(inner.order_id) ?? asString2(obj.orderId),
2228
+ externalCustomerId: asString2(inner.external_customer_id) ?? asString2(obj.external_customer_id) ?? asString2(inner.externalCustomerId) ?? asString2(obj.externalCustomerId),
2214
2229
  orderCrypto: asString2(inner.order_crypto) ?? asString2(obj.orderCrypto),
2215
2230
  orderCryptoAmount: asString2(inner.order_crypto_amount) ?? asString2(obj.orderCryptoAmount),
2216
2231
  transactionId: asString2(inner.transaction_id) ?? asString2(obj.transactionId)
@@ -2228,6 +2243,7 @@ function SwappedIframeStep({
2228
2243
  onSwappedComplete,
2229
2244
  onSwappedFailed,
2230
2245
  onClose,
2246
+ onGoBack,
2231
2247
  onError
2232
2248
  }) {
2233
2249
  const [widgetUrl, setWidgetUrl] = useState6(null);
@@ -2241,6 +2257,7 @@ function SwappedIframeStep({
2241
2257
  const completeFiredRef = useRef6(false);
2242
2258
  const failedFiredRef = useRef6(false);
2243
2259
  const expectedOrderUuidRef = useRef6(null);
2260
+ const expectedExternalCustomerIdRef = useRef6(null);
2244
2261
  const baselineDepositTxHashRef = useRef6(void 0);
2245
2262
  const currentDepositTxHashRef = useRef6(null);
2246
2263
  const fastDepositPollEnabledRef = useRef6(false);
@@ -2253,6 +2270,8 @@ function SwappedIframeStep({
2253
2270
  onSwappedFailedRef.current = onSwappedFailed;
2254
2271
  const onErrorRef = useRef6(onError);
2255
2272
  onErrorRef.current = onError;
2273
+ const onGoBackRef = useRef6(onGoBack);
2274
+ onGoBackRef.current = onGoBack;
2256
2275
  const loadUrlRef = useRef6(loadUrl);
2257
2276
  loadUrlRef.current = loadUrl;
2258
2277
  useEffect6(() => {
@@ -2264,6 +2283,7 @@ function SwappedIframeStep({
2264
2283
  setLatestEvent(null);
2265
2284
  setPhase("iframe");
2266
2285
  expectedOrderUuidRef.current = null;
2286
+ expectedExternalCustomerIdRef.current = null;
2267
2287
  completeFiredRef.current = false;
2268
2288
  failedFiredRef.current = false;
2269
2289
  baselineDepositTxHashRef.current = void 0;
@@ -2272,6 +2292,7 @@ function SwappedIframeStep({
2272
2292
  loadUrlRef.current().then((res) => {
2273
2293
  if (cancelled) return;
2274
2294
  setWidgetUrl(res.url);
2295
+ expectedExternalCustomerIdRef.current = res.externalCustomerId;
2275
2296
  const sep = res.externalCustomerId.indexOf(":");
2276
2297
  expectedOrderUuidRef.current = sep >= 0 ? res.externalCustomerId.slice(sep + 1) : null;
2277
2298
  }).catch((err) => {
@@ -2361,14 +2382,21 @@ function SwappedIframeStep({
2361
2382
  function onMessage(e) {
2362
2383
  if (!SWAPPED_IFRAME_ORIGINS.has(e.origin)) return;
2363
2384
  if (e.source !== iframeRef.current?.contentWindow) return;
2385
+ if (isSwappedGoBackMessage(e.data)) {
2386
+ onGoBackRef.current();
2387
+ return;
2388
+ }
2364
2389
  const parsed = parseSwappedIframeMessage(e.data);
2365
2390
  if (!parsed) return;
2366
- const orderId = parsed.orderId;
2367
- if (!orderId || orderId !== expectedOrderUuidRef.current) {
2391
+ const ext = parsed.externalCustomerId;
2392
+ const expected = expectedExternalCustomerIdRef.current;
2393
+ if (!ext || !expected || ext.toLowerCase() !== expected.toLowerCase()) {
2368
2394
  return;
2369
2395
  }
2370
2396
  setOrderState((prev) => ({
2371
- orderId,
2397
+ // Normalise to the uuid the backend poll also keys on, so orderState
2398
+ // is consistent regardless of which path set it.
2399
+ orderId: expectedOrderUuidRef.current ?? prev?.orderId ?? ext,
2372
2400
  status: parsed.status,
2373
2401
  orderCrypto: parsed.orderCrypto ?? prev?.orderCrypto ?? null,
2374
2402
  orderCryptoAmount: parsed.orderCryptoAmount ?? prev?.orderCryptoAmount ?? null,
@@ -2384,10 +2412,10 @@ function SwappedIframeStep({
2384
2412
  return () => window.removeEventListener("message", onMessage);
2385
2413
  }, []);
2386
2414
  useEffect6(() => {
2387
- if (phase === "iframe" && orderState !== null) {
2415
+ if (phase === "iframe" && (orderState !== null || latestEvent !== null)) {
2388
2416
  setPhase("tracker");
2389
2417
  }
2390
- }, [phase, orderState]);
2418
+ }, [phase, orderState, latestEvent]);
2391
2419
  const stepStates = useMemo4(
2392
2420
  () => deriveStepStates(orderState?.status ?? null, latestEvent),
2393
2421
  [orderState, latestEvent]
@@ -2408,7 +2436,7 @@ function SwappedIframeStep({
2408
2436
  useEffect6(() => {
2409
2437
  if (completeFiredRef.current || failedFiredRef.current) return;
2410
2438
  const t = latestEvent?.type;
2411
- const isSuccess = t === "bridge-complete" || t === "post-bridge-swap-complete";
2439
+ const isSuccess = t === "bridge-complete";
2412
2440
  if (!isSuccess) return;
2413
2441
  const txHash = currentDepositTxHashRef.current;
2414
2442
  if (!txHash) return;
@@ -2418,7 +2446,8 @@ function SwappedIframeStep({
2418
2446
  orderCrypto: orderState?.orderCrypto ?? null,
2419
2447
  // Base-unit source amount from the deposit row/event, consistent with the
2420
2448
  // wallet/QR path. ProcessingStep + onLifecycle expect base units.
2421
- amount: getEventSourceDetails(latestEvent ?? void 0).amount ?? null
2449
+ amount: getEventSourceDetails(latestEvent ?? void 0).amount ?? null,
2450
+ initialEvent: latestEvent ?? void 0
2422
2451
  });
2423
2452
  }, [latestEvent, orderState]);
2424
2453
  useEffect6(() => {
@@ -2491,7 +2520,7 @@ function deriveStepStates(swappedStatus, latestEvent) {
2491
2520
  }
2492
2521
  const step1Complete = swappedStatus === "order_completed" || swappedStatus === "order_broadcasted";
2493
2522
  const step2Complete = latestEvent !== null;
2494
- const step3Complete = latestEvent?.type === "bridge-complete" || latestEvent?.type === "post-bridge-swap-complete";
2523
+ const step3Complete = latestEvent?.type === "bridge-complete";
2495
2524
  if (step3Complete) {
2496
2525
  return ["complete", "complete", "complete", "pending"];
2497
2526
  }
@@ -2537,18 +2566,27 @@ function FiatOnrampStep({
2537
2566
  smartAccount,
2538
2567
  service,
2539
2568
  paymentMethod,
2569
+ consumePrefetchedUrl,
2540
2570
  onSwappedComplete,
2541
2571
  onSwappedFailed,
2542
2572
  onClose,
2573
+ onGoBack,
2543
2574
  onError
2544
2575
  }) {
2545
2576
  const loadUrl = useCallback3(async () => {
2546
- const res = await service.getSwappedWidgetUrl({
2577
+ const prefetched = consumePrefetchedUrl?.(smartAccount, paymentMethod);
2578
+ if (prefetched) {
2579
+ try {
2580
+ const cached = await prefetched;
2581
+ if (isSwappedWidgetUrlFresh(cached)) return cached;
2582
+ } catch {
2583
+ }
2584
+ }
2585
+ return service.getSwappedWidgetUrl({
2547
2586
  smartAccount,
2548
2587
  method: paymentMethod
2549
2588
  });
2550
- return res;
2551
- }, [service, smartAccount, paymentMethod]);
2589
+ }, [service, smartAccount, paymentMethod, consumePrefetchedUrl]);
2552
2590
  return /* @__PURE__ */ jsx10(
2553
2591
  SwappedIframeStep,
2554
2592
  {
@@ -2563,6 +2601,7 @@ function FiatOnrampStep({
2563
2601
  onSwappedComplete,
2564
2602
  onSwappedFailed,
2565
2603
  onClose,
2604
+ onGoBack,
2566
2605
  onError
2567
2606
  }
2568
2607
  );
@@ -2608,6 +2647,7 @@ function ExchangeConnectStep({
2608
2647
  onSwappedComplete,
2609
2648
  onSwappedFailed,
2610
2649
  onClose,
2650
+ onGoBack,
2611
2651
  onError
2612
2652
  }) {
2613
2653
  const loadUrl = useCallback4(async () => {
@@ -2631,6 +2671,7 @@ function ExchangeConnectStep({
2631
2671
  onSwappedComplete,
2632
2672
  onSwappedFailed,
2633
2673
  onClose,
2674
+ onGoBack,
2634
2675
  onError
2635
2676
  }
2636
2677
  );
@@ -4105,6 +4146,68 @@ function getEnabledProviders(config) {
4105
4146
  );
4106
4147
  }
4107
4148
 
4149
+ // src/store/state.ts
4150
+ function portfolioKey(network, address) {
4151
+ return network === "evm" ? `evm:${address.toLowerCase()}` : `solana:${address}`;
4152
+ }
4153
+ function createInitialState(overrides) {
4154
+ return {
4155
+ flow: {
4156
+ step: "connect",
4157
+ mode: null,
4158
+ isConnectSelectionConfirmed: false,
4159
+ hasNavigatedBack: false
4160
+ },
4161
+ wallet: {
4162
+ selectedWalletId: null
4163
+ },
4164
+ deposit: {
4165
+ targetChain: overrides.targetChain,
4166
+ targetToken: overrides.targetToken,
4167
+ sourceChain: null,
4168
+ sourceToken: null,
4169
+ sourceSymbol: null,
4170
+ sourceDecimals: null,
4171
+ selectedAsset: null,
4172
+ selectedSolanaToken: null,
4173
+ amount: null,
4174
+ targetAmount: null,
4175
+ targetTokenPriceUsd: null,
4176
+ balance: null,
4177
+ balanceUsd: null,
4178
+ inputAmountUsd: null,
4179
+ liquidityWarning: null
4180
+ },
4181
+ processing: {
4182
+ txHash: null,
4183
+ directTransfer: false,
4184
+ swappedContext: null,
4185
+ initialEvent: null
4186
+ },
4187
+ dappImport: {
4188
+ activeProviderId: null,
4189
+ availabilityOwner: null,
4190
+ availability: {},
4191
+ selectedAsset: null,
4192
+ bootError: false,
4193
+ attemptNonce: 0
4194
+ },
4195
+ setup: {
4196
+ byOwner: {}
4197
+ },
4198
+ portfolio: {
4199
+ byKey: {},
4200
+ nextRequestId: 0
4201
+ },
4202
+ fiat: {
4203
+ selectedMethod: null
4204
+ },
4205
+ exchange: {
4206
+ selectedConnection: null
4207
+ }
4208
+ };
4209
+ }
4210
+
4108
4211
  // src/store/selectors.ts
4109
4212
  var selectedWalletIdSelector = (state) => state.wallet.selectedWalletId;
4110
4213
  var IDLE_SETUP_ENTRY = {
@@ -4124,6 +4227,10 @@ function readSetupForOwner(setup, owner) {
4124
4227
  const entry = setup.byOwner[owner.toLowerCase()];
4125
4228
  return entry ?? { ...IDLE_SETUP_ENTRY, owner };
4126
4229
  }
4230
+ function readPortfolioEntry(portfolio, network, address) {
4231
+ if (!address) return void 0;
4232
+ return portfolio.byKey[portfolioKey(network, address)];
4233
+ }
4127
4234
 
4128
4235
  // src/core/dapp-imports/status.ts
4129
4236
  function computeDappImportStatus(providerId, inputs) {
@@ -4531,6 +4638,79 @@ function applyAction(state, action) {
4531
4638
  message: null,
4532
4639
  attemptNonce: entry.attemptNonce + 1
4533
4640
  }));
4641
+ case "portfolio/loading": {
4642
+ const key = portfolioKey(action.network, action.address);
4643
+ const requestId = state.portfolio.nextRequestId + 1;
4644
+ return {
4645
+ ...state,
4646
+ portfolio: {
4647
+ nextRequestId: requestId,
4648
+ byKey: {
4649
+ ...state.portfolio.byKey,
4650
+ [key]: { status: "loading", requestId, totalUsd: null }
4651
+ }
4652
+ }
4653
+ };
4654
+ }
4655
+ case "portfolio/reconciled": {
4656
+ const retainedKeys = new Set(
4657
+ action.wallets.map(
4658
+ ({ network, address }) => portfolioKey(network, address)
4659
+ )
4660
+ );
4661
+ const entries = Object.entries(state.portfolio.byKey);
4662
+ const retainedEntries = entries.filter(([key]) => retainedKeys.has(key));
4663
+ if (retainedEntries.length === entries.length) return state;
4664
+ return {
4665
+ ...state,
4666
+ portfolio: {
4667
+ ...state.portfolio,
4668
+ byKey: Object.fromEntries(retainedEntries)
4669
+ }
4670
+ };
4671
+ }
4672
+ case "portfolio/loaded": {
4673
+ const key = portfolioKey(action.network, action.address);
4674
+ const existing = state.portfolio.byKey[key];
4675
+ if (!existing || existing.status !== "loading" || existing.requestId !== action.requestId) {
4676
+ return state;
4677
+ }
4678
+ return {
4679
+ ...state,
4680
+ portfolio: {
4681
+ ...state.portfolio,
4682
+ byKey: {
4683
+ ...state.portfolio.byKey,
4684
+ [key]: {
4685
+ status: "ready",
4686
+ requestId: action.requestId,
4687
+ totalUsd: action.totalUsd
4688
+ }
4689
+ }
4690
+ }
4691
+ };
4692
+ }
4693
+ case "portfolio/failed": {
4694
+ const key = portfolioKey(action.network, action.address);
4695
+ const existing = state.portfolio.byKey[key];
4696
+ if (!existing || existing.status !== "loading" || existing.requestId !== action.requestId) {
4697
+ return state;
4698
+ }
4699
+ return {
4700
+ ...state,
4701
+ portfolio: {
4702
+ ...state.portfolio,
4703
+ byKey: {
4704
+ ...state.portfolio.byKey,
4705
+ [key]: {
4706
+ status: "error",
4707
+ requestId: action.requestId,
4708
+ totalUsd: existing.totalUsd
4709
+ }
4710
+ }
4711
+ }
4712
+ };
4713
+ }
4534
4714
  case "asset/selected":
4535
4715
  return {
4536
4716
  ...state,
@@ -4611,7 +4791,8 @@ function applyAction(state, action) {
4611
4791
  ...state.processing,
4612
4792
  txHash: action.txHash,
4613
4793
  directTransfer: action.directTransfer ?? false,
4614
- swappedContext: action.swappedContext ?? null
4794
+ swappedContext: action.swappedContext ?? null,
4795
+ initialEvent: action.initialEvent ?? null
4615
4796
  },
4616
4797
  flow: { ...state.flow, step: "processing" }
4617
4798
  };
@@ -4781,7 +4962,8 @@ function applyAction(state, action) {
4781
4962
  processing: {
4782
4963
  txHash: null,
4783
4964
  directTransfer: false,
4784
- swappedContext: null
4965
+ swappedContext: null,
4966
+ initialEvent: null
4785
4967
  },
4786
4968
  // Drop fetched availability wholesale. The fetch effect refetches
4787
4969
  // unconditionally on remount (so keeping the map saves nothing),
@@ -4797,6 +4979,13 @@ function applyAction(state, action) {
4797
4979
  attemptNonce: 0
4798
4980
  },
4799
4981
  setup: { byOwner: preservedByOwner },
4982
+ // Ephemeral fetched balances — drop wholesale on close so a reopen
4983
+ // refetches rather than surfacing a stale balance (same hazard the
4984
+ // dappImport drop above guards against).
4985
+ portfolio: {
4986
+ byKey: {},
4987
+ nextRequestId: state.portfolio.nextRequestId
4988
+ },
4800
4989
  fiat: { selectedMethod: null },
4801
4990
  exchange: { selectedConnection: null }
4802
4991
  };
@@ -4831,60 +5020,6 @@ function applyAction(state, action) {
4831
5020
  }
4832
5021
  }
4833
5022
 
4834
- // src/store/state.ts
4835
- function createInitialState(overrides) {
4836
- return {
4837
- flow: {
4838
- step: "connect",
4839
- mode: null,
4840
- isConnectSelectionConfirmed: false,
4841
- hasNavigatedBack: false
4842
- },
4843
- wallet: {
4844
- selectedWalletId: null
4845
- },
4846
- deposit: {
4847
- targetChain: overrides.targetChain,
4848
- targetToken: overrides.targetToken,
4849
- sourceChain: null,
4850
- sourceToken: null,
4851
- sourceSymbol: null,
4852
- sourceDecimals: null,
4853
- selectedAsset: null,
4854
- selectedSolanaToken: null,
4855
- amount: null,
4856
- targetAmount: null,
4857
- targetTokenPriceUsd: null,
4858
- balance: null,
4859
- balanceUsd: null,
4860
- inputAmountUsd: null,
4861
- liquidityWarning: null
4862
- },
4863
- processing: {
4864
- txHash: null,
4865
- directTransfer: false,
4866
- swappedContext: null
4867
- },
4868
- dappImport: {
4869
- activeProviderId: null,
4870
- availabilityOwner: null,
4871
- availability: {},
4872
- selectedAsset: null,
4873
- bootError: false,
4874
- attemptNonce: 0
4875
- },
4876
- setup: {
4877
- byOwner: {}
4878
- },
4879
- fiat: {
4880
- selectedMethod: null
4881
- },
4882
- exchange: {
4883
- selectedConnection: null
4884
- }
4885
- };
4886
- }
4887
-
4888
5023
  // src/store/index.ts
4889
5024
  function createDepositStore(overrides) {
4890
5025
  const store = createStore(() => createInitialState(overrides));
@@ -4968,8 +5103,7 @@ function computeRequestKey(input, sessionOwnerAddress) {
4968
5103
  signerAddress: input.signerAddress.toLowerCase(),
4969
5104
  sessionChainIds: input.sessionChainIds ?? null,
4970
5105
  enableSolana: input.enableSolana ?? true,
4971
- forceRegister: input.forceRegister ?? false,
4972
- postBridgeActions: input.postBridgeActions ?? null
5106
+ forceRegister: input.forceRegister ?? false
4973
5107
  });
4974
5108
  }
4975
5109
  function computeCacheKey(input, sessionOwnerAddress) {
@@ -4987,7 +5121,7 @@ function computeCacheKey(input, sessionOwnerAddress) {
4987
5121
  });
4988
5122
  }
4989
5123
  function computeIsCacheable(input) {
4990
- return !input.forceRegister && !(input.postBridgeActions?.length ?? 0);
5124
+ return !input.forceRegister;
4991
5125
  }
4992
5126
  var SETUP_REQUEST_DEDUPE_TTL_MS = 3e4;
4993
5127
  var setupRequestDedupe = /* @__PURE__ */ new Map();
@@ -5008,7 +5142,6 @@ async function runAccountSetup(input, deps) {
5008
5142
  debugLog(debug, "account-setup", "setup:start", {
5009
5143
  owner: input.ownerAddress,
5010
5144
  sessionOwner: sessionOwner.address,
5011
- hasPostBridgeActions: Boolean(input.postBridgeActions?.length),
5012
5145
  forceRegister: input.forceRegister ?? false
5013
5146
  });
5014
5147
  const setup = await service.setupAccount({
@@ -5017,7 +5150,6 @@ async function runAccountSetup(input, deps) {
5017
5150
  targetChain: targetChainToCaip2(input.targetChain),
5018
5151
  targetToken: input.targetToken,
5019
5152
  recipient: input.recipient,
5020
- postBridgeActions: input.postBridgeActions,
5021
5153
  outputTokenRules: input.outputTokenRules,
5022
5154
  rejectUnmapped: input.rejectUnmapped,
5023
5155
  signerAddress: input.signerAddress,
@@ -5070,9 +5202,6 @@ async function runAccountSetup(input, deps) {
5070
5202
  chain: targetChainToCaip2(input.targetChain),
5071
5203
  token: input.targetToken,
5072
5204
  ...input.recipient && { recipient: input.recipient },
5073
- ...input.postBridgeActions?.length && {
5074
- postBridgeActions: input.postBridgeActions
5075
- },
5076
5205
  ...input.outputTokenRules?.length && {
5077
5206
  outputTokenRules: input.outputTokenRules
5078
5207
  },
@@ -5330,7 +5459,8 @@ function deriveStep(flow, d, p, activeEntry, fiat, exchange) {
5330
5459
  sourceDecimals: d.sourceDecimals ?? void 0,
5331
5460
  inputAmountUsd: d.inputAmountUsd ?? void 0,
5332
5461
  directTransfer: p.directTransfer,
5333
- swappedContext: p.swappedContext ?? void 0
5462
+ swappedContext: p.swappedContext ?? void 0,
5463
+ initialEvent: p.initialEvent ?? void 0
5334
5464
  };
5335
5465
  }
5336
5466
  }
@@ -5362,7 +5492,6 @@ function DepositFlow({
5362
5492
  amount: defaultAmount,
5363
5493
  recipient,
5364
5494
  appBalanceUsd,
5365
- postBridgeActions,
5366
5495
  outputTokenRules,
5367
5496
  rejectUnmapped,
5368
5497
  signerAddress = DEFAULT_SIGNER_ADDRESS,
@@ -5398,6 +5527,7 @@ function DepositFlow({
5398
5527
  const depositSlice = useDepositStore((s) => s.deposit);
5399
5528
  const processingSlice = useDepositStore((s) => s.processing);
5400
5529
  const setupSlice = useDepositStore((s) => s.setup);
5530
+ const portfolioSlice = useDepositStore((s) => s.portfolio);
5401
5531
  const fiatSlice = useDepositStore((s) => s.fiat);
5402
5532
  const exchangeSlice = useDepositStore((s) => s.exchange);
5403
5533
  const flowMode = flowSlice.mode;
@@ -5418,6 +5548,25 @@ function DepositFlow({
5418
5548
  },
5419
5549
  [debug]
5420
5550
  );
5551
+ const enableSwappedPreconnect = enableFiatOnramp || enableExchangeConnect;
5552
+ useEffect10(() => {
5553
+ if (!enableSwappedPreconnect) return;
5554
+ if (typeof document === "undefined") return;
5555
+ const links = [];
5556
+ for (const origin of SWAPPED_ORIGINS) {
5557
+ for (const rel of ["preconnect", "dns-prefetch"]) {
5558
+ const link = document.createElement("link");
5559
+ link.rel = rel;
5560
+ link.href = origin;
5561
+ link.dataset.rsSwappedPreconnect = "";
5562
+ document.head.appendChild(link);
5563
+ links.push(link);
5564
+ }
5565
+ }
5566
+ return () => {
5567
+ for (const link of links) link.remove();
5568
+ };
5569
+ }, [enableSwappedPreconnect]);
5421
5570
  const dappSwitchChain = useMemo7(() => {
5422
5571
  if (!dappWalletClient?.switchChain) return void 0;
5423
5572
  return async (chainId) => {
@@ -6126,6 +6275,46 @@ function DepositFlow({
6126
6275
  },
6127
6276
  [storeApi]
6128
6277
  );
6278
+ const swappedUrlPrefetchRef = useRef8(/* @__PURE__ */ new Map());
6279
+ const prefetchSwappedWidgetUrl = useCallback7(
6280
+ (smartAccount, method) => {
6281
+ const cache = swappedUrlPrefetchRef.current;
6282
+ const key = method ?? "";
6283
+ const owner = smartAccount.toLowerCase();
6284
+ const existing = cache.get(key);
6285
+ if (existing && existing.smartAccount === owner) return;
6286
+ const promise = service.getSwappedWidgetUrl({ smartAccount, method });
6287
+ promise.catch(() => {
6288
+ });
6289
+ cache.set(key, { smartAccount: owner, promise });
6290
+ logFlow("swapped:prefetch", { method: method ?? null });
6291
+ },
6292
+ [service, logFlow]
6293
+ );
6294
+ const consumeSwappedWidgetUrlPrefetch = useCallback7(
6295
+ (smartAccount, method) => {
6296
+ const cache = swappedUrlPrefetchRef.current;
6297
+ const key = method ?? "";
6298
+ const entry = cache.get(key);
6299
+ if (!entry) return null;
6300
+ cache.delete(key);
6301
+ if (entry.smartAccount !== smartAccount.toLowerCase()) return null;
6302
+ return entry.promise;
6303
+ },
6304
+ []
6305
+ );
6306
+ const handlePrefetchFiatMethod = useCallback7(
6307
+ (method) => {
6308
+ if (!enableFiatOnramp || !dappAddress) return;
6309
+ const entry = readSetupForOwner(setupSlice, dappAddress);
6310
+ if (entry.status !== "ready" || !entry.smartAccount) return;
6311
+ prefetchSwappedWidgetUrl(entry.smartAccount, method);
6312
+ },
6313
+ [enableFiatOnramp, dappAddress, setupSlice, prefetchSwappedWidgetUrl]
6314
+ );
6315
+ useEffect10(() => {
6316
+ swappedUrlPrefetchRef.current.clear();
6317
+ }, [dappAddress]);
6129
6318
  const handleNewDeposit = useCallback7(() => {
6130
6319
  onLifecycleRef.current?.({
6131
6320
  type: "smart-account-changed",
@@ -6135,6 +6324,7 @@ function DepositFlow({
6135
6324
  storeApi.dispatch({ type: "flow/reset" });
6136
6325
  stableWalletSignerRef.current = null;
6137
6326
  stableWalletSelectionKeyRef.current = null;
6327
+ swappedUrlPrefetchRef.current.clear();
6138
6328
  }, [onLifecycleRef, storeApi]);
6139
6329
  const setupInputBase = useMemo7(
6140
6330
  () => ({
@@ -6143,7 +6333,6 @@ function DepositFlow({
6143
6333
  signerAddress,
6144
6334
  sessionChainIds,
6145
6335
  recipient,
6146
- postBridgeActions,
6147
6336
  outputTokenRules,
6148
6337
  rejectUnmapped,
6149
6338
  forceRegister,
@@ -6155,7 +6344,6 @@ function DepositFlow({
6155
6344
  signerAddress,
6156
6345
  sessionChainIds,
6157
6346
  recipient,
6158
- postBridgeActions,
6159
6347
  outputTokenRules,
6160
6348
  rejectUnmapped,
6161
6349
  forceRegister,
@@ -6278,6 +6466,58 @@ function DepositFlow({
6278
6466
  storeApi,
6279
6467
  setupSlice.byOwner
6280
6468
  ]);
6469
+ const walletOptionsKey = useMemo7(
6470
+ () => walletOptions.map((option) => option.id).join(","),
6471
+ [walletOptions]
6472
+ );
6473
+ const desiredPortfolios = useMemo7(
6474
+ () => walletOptions.flatMap((option) => {
6475
+ const network = option.kind === "solana" ? "solana" : "evm";
6476
+ const address = option.kind === "solana" ? option.solanaAddress : option.address;
6477
+ return address ? [{ network, address }] : [];
6478
+ }),
6479
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- keyed on the stable id-join, not the walletOptions array identity
6480
+ [walletOptionsKey]
6481
+ );
6482
+ useEffect10(() => {
6483
+ storeApi.dispatch({
6484
+ type: "portfolio/reconciled",
6485
+ wallets: desiredPortfolios
6486
+ });
6487
+ desiredPortfolios.forEach(({ network, address }) => {
6488
+ if (readPortfolioEntry(storeApi.getState().portfolio, network, address)) {
6489
+ return;
6490
+ }
6491
+ storeApi.dispatch({ type: "portfolio/loading", network, address });
6492
+ const requestId = readPortfolioEntry(
6493
+ storeApi.getState().portfolio,
6494
+ network,
6495
+ address
6496
+ )?.requestId;
6497
+ if (requestId === void 0) return;
6498
+ void (async () => {
6499
+ try {
6500
+ const portfolio = network === "solana" ? await service.fetchSolanaPortfolio(address, {
6501
+ forceRefresh: true
6502
+ }) : await service.fetchPortfolio(address, { forceRefresh: true });
6503
+ storeApi.dispatch({
6504
+ type: "portfolio/loaded",
6505
+ network,
6506
+ address,
6507
+ requestId,
6508
+ totalUsd: portfolio.totalUsd
6509
+ });
6510
+ } catch {
6511
+ storeApi.dispatch({
6512
+ type: "portfolio/failed",
6513
+ network,
6514
+ address,
6515
+ requestId
6516
+ });
6517
+ }
6518
+ })();
6519
+ });
6520
+ }, [desiredPortfolios, service, storeApi, portfolioSlice.byKey]);
6281
6521
  const handleDepositAddressSubmitted = useCallback7(
6282
6522
  (data) => {
6283
6523
  logFlow("deposit-address:detected", {
@@ -6443,7 +6683,8 @@ function DepositFlow({
6443
6683
  amount,
6444
6684
  sourceSymbol: info.orderCrypto ?? "USDC",
6445
6685
  sourceDecimals: SWAPPED_SOURCE_DECIMALS,
6446
- swappedContext
6686
+ swappedContext,
6687
+ initialEvent: info.initialEvent
6447
6688
  });
6448
6689
  onLifecycleRef.current?.({
6449
6690
  type: "submitted",
@@ -6498,10 +6739,6 @@ function DepositFlow({
6498
6739
  const handleTotalBalanceComputed = useCallback7((total) => {
6499
6740
  setTotalBalanceUsd(total);
6500
6741
  }, []);
6501
- const walletOptionsKey = useMemo7(
6502
- () => walletOptions.map((option) => option.id).join(","),
6503
- [walletOptions]
6504
- );
6505
6742
  useEffect10(() => {
6506
6743
  if (storeApi.getState().flow.mode) {
6507
6744
  return;
@@ -6538,6 +6775,13 @@ function DepositFlow({
6538
6775
  const ownerForRow = option.kind === "solana" ? dappAddress : option.address ?? null;
6539
6776
  const entry = readSetupForOwner(setupSlice, ownerForRow ?? null);
6540
6777
  const state = entry.status === "ready" ? "ready" : entry.status === "error" ? "error" : "loading";
6778
+ const network = option.kind === "solana" ? "solana" : "evm";
6779
+ const balanceAddress = option.kind === "solana" ? option.solanaAddress : option.address;
6780
+ const portfolioEntry = readPortfolioEntry(
6781
+ portfolioSlice,
6782
+ network,
6783
+ balanceAddress
6784
+ );
6541
6785
  return {
6542
6786
  id: option.id,
6543
6787
  kind: option.kind,
@@ -6545,10 +6789,12 @@ function DepositFlow({
6545
6789
  icon: option.icon,
6546
6790
  address: option.address ?? option.solanaAddress ?? option.id,
6547
6791
  state,
6548
- errorReason: entry.message ?? void 0
6792
+ errorReason: entry.message ?? void 0,
6793
+ balanceStatus: portfolioEntry?.status ?? "loading",
6794
+ balanceUsd: portfolioEntry?.status === "ready" ? portfolioEntry.totalUsd : null
6549
6795
  };
6550
6796
  });
6551
- }, [walletOptions, setupSlice, dappAddress]);
6797
+ }, [walletOptions, setupSlice, dappAddress, portfolioSlice]);
6552
6798
  const transferCryptoEntry = useMemo7(
6553
6799
  () => readSetupForOwner(setupSlice, dappAddress),
6554
6800
  [setupSlice, dappAddress]
@@ -6576,6 +6822,7 @@ function DepositFlow({
6576
6822
  } : void 0,
6577
6823
  fiatPaymentMethods: enableFiatOnramp && dappAddress ? fiatOnrampMethods && fiatOnrampMethods.length > 0 ? fiatOnrampMethods : DEFAULT_FIAT_ONRAMP_METHODS : void 0,
6578
6824
  onSelectFiatMethod: enableFiatOnramp && dappAddress ? (method) => handleSelectFiatMethod(method) : void 0,
6825
+ onPrefetchFiatMethod: enableFiatOnramp && dappAddress ? handlePrefetchFiatMethod : void 0,
6579
6826
  onSelectFundFromExchange: enableExchangeConnect && dappAddress ? () => handleSelectExchange() : void 0,
6580
6827
  onRequestConnect,
6581
6828
  onConnect,
@@ -6640,7 +6887,6 @@ function DepositFlow({
6640
6887
  allowedRoutes,
6641
6888
  targetChain,
6642
6889
  targetToken,
6643
- hasPostBridgeActions: Boolean(postBridgeActions?.length),
6644
6890
  uiConfig,
6645
6891
  onDepositSubmitted: handleDepositAddressSubmitted,
6646
6892
  onDepositComplete: handleDepositComplete,
@@ -6684,10 +6930,12 @@ function DepositFlow({
6684
6930
  smartAccount: step.smartAccount,
6685
6931
  service,
6686
6932
  paymentMethod: step.paymentMethod,
6933
+ consumePrefetchedUrl: consumeSwappedWidgetUrlPrefetch,
6687
6934
  onSwappedComplete: handleSwappedComplete,
6688
6935
  onSwappedFailed: handleDepositFailed,
6689
6936
  onClose: onClose ?? (() => {
6690
6937
  }),
6938
+ onGoBack: handleBack,
6691
6939
  onError: handleError
6692
6940
  }
6693
6941
  ),
@@ -6706,9 +6954,9 @@ function DepositFlow({
6706
6954
  sourceDecimals: step.sourceDecimals,
6707
6955
  amountUsd: step.inputAmountUsd,
6708
6956
  swappedContext: step.swappedContext,
6709
- hasPostBridgeActions: Boolean(postBridgeActions?.length),
6710
6957
  service,
6711
6958
  directTransfer: step.directTransfer,
6959
+ initialEvent: step.initialEvent,
6712
6960
  isSwappedOrder: true,
6713
6961
  onClose,
6714
6962
  onNewDeposit: handleNewDeposit,
@@ -6756,6 +7004,7 @@ function DepositFlow({
6756
7004
  onSwappedFailed: handleDepositFailed,
6757
7005
  onClose: onClose ?? (() => {
6758
7006
  }),
7007
+ onGoBack: handleBack,
6759
7008
  onError: handleError
6760
7009
  }
6761
7010
  ),
@@ -6774,9 +7023,9 @@ function DepositFlow({
6774
7023
  sourceDecimals: step.sourceDecimals,
6775
7024
  amountUsd: step.inputAmountUsd,
6776
7025
  swappedContext: step.swappedContext,
6777
- hasPostBridgeActions: Boolean(postBridgeActions?.length),
6778
7026
  service,
6779
7027
  directTransfer: step.directTransfer,
7028
+ initialEvent: step.initialEvent,
6780
7029
  isSwappedOrder: true,
6781
7030
  onClose,
6782
7031
  onNewDeposit: handleNewDeposit,
@@ -6904,9 +7153,9 @@ function DepositFlow({
6904
7153
  sourceSymbol: effectiveStep.sourceSymbol,
6905
7154
  sourceDecimals: effectiveStep.sourceDecimals,
6906
7155
  amountUsd: effectiveStep.inputAmountUsd,
6907
- hasPostBridgeActions: Boolean(postBridgeActions?.length),
6908
7156
  service,
6909
7157
  directTransfer: effectiveStep.directTransfer,
7158
+ initialEvent: effectiveStep.initialEvent,
6910
7159
  onClose,
6911
7160
  onNewDeposit: handleNewDeposit,
6912
7161
  onDepositComplete: handleDepositComplete,
@@ -7066,9 +7315,9 @@ function DepositFlow({
7066
7315
  sourceSymbol: effectiveStep.sourceSymbol,
7067
7316
  sourceDecimals: effectiveStep.sourceDecimals,
7068
7317
  amountUsd: effectiveStep.inputAmountUsd,
7069
- hasPostBridgeActions: Boolean(postBridgeActions?.length),
7070
7318
  service,
7071
7319
  directTransfer: effectiveStep.directTransfer,
7320
+ initialEvent: effectiveStep.initialEvent,
7072
7321
  uiConfig,
7073
7322
  onClose,
7074
7323
  onNewDeposit: handleNewDeposit,
@@ -7369,7 +7618,7 @@ DepositHistoryPanel.displayName = "DepositHistoryPanel";
7369
7618
  // src/DepositModal.tsx
7370
7619
  import { jsx as jsx21, jsxs as jsxs19 } from "react/jsx-runtime";
7371
7620
  var ReownDepositInner = lazy2(
7372
- () => import("./DepositModalReown-YJBDBCRA.mjs").then((m) => ({ default: m.DepositModalReown }))
7621
+ () => import("./DepositModalReown-IVRDXQAA.mjs").then((m) => ({ default: m.DepositModalReown }))
7373
7622
  );
7374
7623
  function sortByCreatedAtDesc(items) {
7375
7624
  return [...items].sort((a, b) => {
@@ -7430,7 +7679,6 @@ function DepositModalInner({
7430
7679
  enableQrTransfer = true,
7431
7680
  fiatOnrampMethods,
7432
7681
  enableExchangeConnect = false,
7433
- postBridgeActions,
7434
7682
  outputTokenRules,
7435
7683
  rejectUnmapped,
7436
7684
  reownWallet,
@@ -7680,7 +7928,6 @@ function DepositModalInner({
7680
7928
  amount: defaultAmount,
7681
7929
  recipient,
7682
7930
  appBalanceUsd,
7683
- postBridgeActions,
7684
7931
  outputTokenRules,
7685
7932
  rejectUnmapped,
7686
7933
  signerAddress,