@rhinestone/deposit-modal 0.4.2 → 0.5.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.
@@ -1395,31 +1395,49 @@ function formatUserError(raw) {
1395
1395
  return cleaned;
1396
1396
  }
1397
1397
 
1398
+ // src/core/rpc.ts
1399
+ import { createContext, useContext } from "react";
1400
+ function rpcUrlFor(rpcUrls, chain) {
1401
+ const url = rpcUrls?.[chain]?.trim();
1402
+ return url ? url : void 0;
1403
+ }
1404
+ var RpcUrlsContext = createContext(void 0);
1405
+ var RpcUrlsProvider = RpcUrlsContext.Provider;
1406
+ function useRpcUrls() {
1407
+ return useContext(RpcUrlsContext);
1408
+ }
1409
+
1398
1410
  // src/core/public-client.ts
1399
1411
  import { createPublicClient, http } from "viem";
1400
1412
  import { hyperliquid } from "viem/chains";
1401
1413
  var clientCache = /* @__PURE__ */ new Map();
1402
- function getPublicClient(chainId) {
1403
- let client = clientCache.get(chainId);
1414
+ function getPublicClient(chainId, rpcUrls) {
1415
+ const url = rpcUrlFor(rpcUrls, chainId);
1416
+ const cacheKey = `${chainId}|${url ?? ""}`;
1417
+ let client = clientCache.get(cacheKey);
1404
1418
  if (!client) {
1405
1419
  const chain = CHAIN_BY_ID[chainId];
1406
1420
  client = createPublicClient({
1407
1421
  chain,
1408
- transport: http()
1422
+ transport: http(url)
1409
1423
  });
1410
- clientCache.set(chainId, client);
1424
+ clientCache.set(cacheKey, client);
1411
1425
  }
1412
1426
  return client;
1413
1427
  }
1414
- var hyperEvmClient;
1415
- function getHyperEvmReadClient() {
1416
- if (!hyperEvmClient) {
1417
- hyperEvmClient = createPublicClient({
1428
+ var hyperEvmClientCache = /* @__PURE__ */ new Map();
1429
+ function getHyperEvmReadClient(rpcUrls) {
1430
+ const url = rpcUrlFor(rpcUrls, hyperliquid.id);
1431
+ const cacheKey = url ?? "";
1432
+ let client = hyperEvmClientCache.get(cacheKey);
1433
+ if (!client) {
1434
+ client = createPublicClient({
1418
1435
  chain: hyperliquid,
1419
- transport: http()
1436
+ transport: http(url)
1420
1437
  });
1438
+ hyperEvmClientCache.set(cacheKey, client);
1421
1439
  }
1422
- return hyperEvmClient;
1440
+ return client;
1423
1441
  }
1424
1442
 
1425
1443
  // src/core/theme.ts
@@ -2789,6 +2807,7 @@ FeesAccordion.displayName = "FeesAccordion";
2789
2807
  import { jsx as jsx22, jsxs as jsxs20 } from "react/jsx-runtime";
2790
2808
  function SwappedReceipt({
2791
2809
  onrampMethod,
2810
+ onrampMethodIcon,
2792
2811
  amountPaid,
2793
2812
  depositedAmount,
2794
2813
  depositedIcon,
@@ -2804,14 +2823,17 @@ function SwappedReceipt({
2804
2823
  /* @__PURE__ */ jsxs20("div", { className: "rs-review-details", children: [
2805
2824
  onrampMethod && /* @__PURE__ */ jsxs20("div", { className: "rs-review-detail-row", children: [
2806
2825
  /* @__PURE__ */ jsx22("span", { children: "Onramp method" }),
2807
- /* @__PURE__ */ jsx22("span", { className: "rs-review-detail-value", children: onrampMethod })
2826
+ /* @__PURE__ */ jsxs20("span", { className: "rs-review-detail-value", children: [
2827
+ /* @__PURE__ */ jsx22("span", { children: onrampMethod }),
2828
+ onrampMethodIcon && /* @__PURE__ */ jsx22("span", { className: "rs-review-detail-icon rs-review-detail-icon--square", children: /* @__PURE__ */ jsx22("img", { src: onrampMethodIcon, alt: "" }) })
2829
+ ] })
2808
2830
  ] }),
2809
2831
  amountPaid && /* @__PURE__ */ jsxs20("div", { className: "rs-review-detail-row", children: [
2810
2832
  /* @__PURE__ */ jsx22("span", { children: "Amount paid" }),
2811
2833
  /* @__PURE__ */ jsx22("span", { className: "rs-review-detail-value", children: amountPaid })
2812
2834
  ] }),
2813
2835
  /* @__PURE__ */ jsxs20("div", { className: "rs-review-detail-row", children: [
2814
- /* @__PURE__ */ jsx22("span", { children: "Deposited amount" }),
2836
+ /* @__PURE__ */ jsx22("span", { children: "Receive" }),
2815
2837
  /* @__PURE__ */ jsxs20("span", { className: "rs-review-detail-value", children: [
2816
2838
  /* @__PURE__ */ jsx22("span", { children: depositedAmount }),
2817
2839
  depositedIcon && /* @__PURE__ */ jsx22("span", { className: "rs-review-detail-icon", children: /* @__PURE__ */ jsx22("img", { src: depositedIcon, alt: "" }) })
@@ -3327,6 +3349,7 @@ function ProcessingStep({
3327
3349
  quotedFeeSymbol,
3328
3350
  balanceAfterUsd,
3329
3351
  isSwappedOrder,
3352
+ swappedContext,
3330
3353
  onClose,
3331
3354
  onNewDeposit,
3332
3355
  onRetry,
@@ -3437,10 +3460,12 @@ function ProcessingStep({
3437
3460
  if (cancelled || !res) return;
3438
3461
  if (res.transactionId != null) {
3439
3462
  if (res.transactionId.toLowerCase() !== txHash.toLowerCase()) return;
3440
- } else if (!isSwappedOrder) {
3463
+ } else if (!isSwappedOrder || swappedContext?.variant === "connect") {
3441
3464
  return;
3442
3465
  }
3443
3466
  setSwappedFiatContext({
3467
+ orderCrypto: res.orderCrypto,
3468
+ orderCryptoAmount: res.orderCryptoAmount,
3444
3469
  paidAmountUsd: res.paidAmountUsd,
3445
3470
  paidAmountEur: res.paidAmountEur,
3446
3471
  onrampFeeUsd: res.onrampFeeUsd,
@@ -3451,7 +3476,7 @@ function ProcessingStep({
3451
3476
  return () => {
3452
3477
  cancelled = true;
3453
3478
  };
3454
- }, [service, smartAccount, txHash, isSwappedOrder]);
3479
+ }, [service, smartAccount, txHash, isSwappedOrder, swappedContext?.variant]);
3455
3480
  useEffect5(() => {
3456
3481
  if (directTransfer) return;
3457
3482
  if (state.type !== "processing") {
@@ -3727,8 +3752,14 @@ function ProcessingStep({
3727
3752
  /* @__PURE__ */ jsx23("div", { className: "rs-body-header-text", children: /* @__PURE__ */ jsx23("h2", { className: "rs-body-header-title", children: stateTitle }) })
3728
3753
  ] }) : /* @__PURE__ */ jsx23(BodyHeader, { icon: /* @__PURE__ */ jsx23(WalletIcon, {}), title: stateTitle });
3729
3754
  if (isComplete && isSwappedOrder) {
3730
- const onrampMethod = swappedFiatContext?.paymentMethod ? formatPaymentMethod(swappedFiatContext.paymentMethod) : null;
3731
- const amountPaid = swappedFiatContext?.paidAmountUsd != null ? `$${swappedFiatContext.paidAmountUsd.toFixed(2)}` : null;
3755
+ const effectivePaymentMethod = swappedContext?.method ?? swappedFiatContext?.paymentMethod ?? null;
3756
+ const onrampMethod = effectivePaymentMethod ? formatPaymentMethod(effectivePaymentMethod) : null;
3757
+ const onrampMethodIcon = swappedContext?.variant === "connect" && effectivePaymentMethod ? getExchangeLogoSrc(
3758
+ onrampMethod ?? effectivePaymentMethod,
3759
+ effectivePaymentMethod
3760
+ ) : null;
3761
+ const connectPaidAmount = swappedContext?.variant === "connect" ? `${formattedSentAmount} ${sourceSymbol}` : null;
3762
+ const amountPaid = connectPaidAmount ?? (swappedFiatContext?.paidAmountUsd != null ? `$${swappedFiatContext.paidAmountUsd.toFixed(2)}` : null);
3732
3763
  const depositedAmount = receiveDisplay;
3733
3764
  const onrampFeeUsd = swappedFiatContext?.onrampFeeUsd ?? null;
3734
3765
  const networkFeeUsd = quotedFeeAmount !== void 0 && Number.isFinite(Number(quotedFeeAmount)) ? Number(quotedFeeAmount) : null;
@@ -3750,6 +3781,7 @@ function ProcessingStep({
3750
3781
  SwappedReceipt,
3751
3782
  {
3752
3783
  onrampMethod,
3784
+ onrampMethodIcon,
3753
3785
  amountPaid,
3754
3786
  depositedAmount,
3755
3787
  depositedIcon: targetTokenIcon,
@@ -4041,6 +4073,9 @@ export {
4041
4073
  failureMessageForEvent,
4042
4074
  useTokenPrices,
4043
4075
  ProcessingStep,
4076
+ rpcUrlFor,
4077
+ RpcUrlsProvider,
4078
+ useRpcUrls,
4044
4079
  getPublicClient,
4045
4080
  getHyperEvmReadClient,
4046
4081
  loadSessionOwnerFromStorage,
@@ -10,6 +10,7 @@ import {
10
10
  Modal,
11
11
  PoweredBy,
12
12
  ProcessingStep,
13
+ RpcUrlsProvider,
13
14
  Spinner,
14
15
  WalletIcon,
15
16
  accountFromPrivateKey,
@@ -29,8 +30,9 @@ import {
29
30
  loadSessionOwnerFromStorage,
30
31
  saveSessionOwnerToStorage,
31
32
  useLatestRef,
33
+ useRpcUrls,
32
34
  useTokenPrices
33
- } from "./chunk-7EQQD7B4.mjs";
35
+ } from "./chunk-PS7HJ62M.mjs";
34
36
  import {
35
37
  buildSafeTransaction,
36
38
  executeSafeErc20Transfer,
@@ -200,6 +202,7 @@ function WithdrawFormStep({
200
202
  publicClient,
201
203
  connectedRecipient,
202
204
  safeAddress,
205
+ depositAddress,
203
206
  asset,
204
207
  defaultRecipient,
205
208
  defaultAmount,
@@ -361,6 +364,13 @@ function WithdrawFormStep({
361
364
  setError("Enter a valid recipient address");
362
365
  return;
363
366
  }
367
+ const lowerRecipient = recipient.toLowerCase();
368
+ if (lowerRecipient === safeAddress.toLowerCase() || lowerRecipient === depositAddress?.toLowerCase()) {
369
+ setError(
370
+ "Recipient can't be your own account. Send to a different wallet."
371
+ );
372
+ return;
373
+ }
364
374
  const parsed = Number(amount);
365
375
  if (!amount || !Number.isFinite(parsed) || parsed <= 0) {
366
376
  setError("Enter a valid amount");
@@ -388,7 +398,15 @@ function WithdrawFormStep({
388
398
  } finally {
389
399
  setIsSubmitting(false);
390
400
  }
391
- }, [recipient, amount, balance, asset.decimals, onSubmit]);
401
+ }, [
402
+ recipient,
403
+ amount,
404
+ balance,
405
+ asset.decimals,
406
+ safeAddress,
407
+ depositAddress,
408
+ onSubmit
409
+ ]);
392
410
  if (isBalanceLoading) {
393
411
  return /* @__PURE__ */ jsxs("div", { className: "rs-screen", children: [
394
412
  /* @__PURE__ */ jsxs("div", { className: "rs-screen-body rs-withdraw-loading", children: [
@@ -829,6 +847,7 @@ function WithdrawFlow({
829
847
  onError,
830
848
  debug
831
849
  }) {
850
+ const rpcUrls = useRpcUrls();
832
851
  const onStepChangeRef = useLatestRef(onStepChange);
833
852
  const onEventRef = useLatestRef(onEvent);
834
853
  const onLifecycleRef = useLatestRef(onLifecycle);
@@ -925,14 +944,14 @@ function WithdrawFlow({
925
944
  return {
926
945
  ownerAddress: dappAddress,
927
946
  walletClient: dappWalletClient ?? void 0,
928
- publicClient: dappPublicClient ?? getPublicClient(sourceChain),
947
+ publicClient: dappPublicClient ?? getPublicClient(sourceChain, rpcUrls),
929
948
  switchChain: dappSwitchChain
930
949
  };
931
950
  }
932
951
  return {
933
952
  ownerAddress: dappWalletClient.account.address,
934
953
  walletClient: dappWalletClient,
935
- publicClient: dappPublicClient ?? getPublicClient(sourceChain),
954
+ publicClient: dappPublicClient ?? getPublicClient(sourceChain, rpcUrls),
936
955
  switchChain: dappSwitchChain
937
956
  };
938
957
  }
@@ -943,7 +962,7 @@ function WithdrawFlow({
943
962
  return {
944
963
  ownerAddress: dappWalletClient.account.address,
945
964
  walletClient: dappWalletClient,
946
- publicClient: dappPublicClient ?? getPublicClient(sourceChain),
965
+ publicClient: dappPublicClient ?? getPublicClient(sourceChain, rpcUrls),
947
966
  switchChain: dappSwitchChain
948
967
  };
949
968
  }
@@ -967,7 +986,8 @@ function WithdrawFlow({
967
986
  dappSwitchChain,
968
987
  dappAddress,
969
988
  reownWallet,
970
- sourceChain
989
+ sourceChain,
990
+ rpcUrls
971
991
  ]);
972
992
  const ownerAddress = signerContext?.ownerAddress;
973
993
  const recipientForRegistration = useMemo2(() => {
@@ -1209,6 +1229,12 @@ function WithdrawFlow({
1209
1229
  throw new Error("Withdrawal target is still being prepared");
1210
1230
  }
1211
1231
  const smartAccount = matchingRegistration.smartAccount;
1232
+ const lowerRecipient = recipient.toLowerCase();
1233
+ if (lowerRecipient === safeAddress.toLowerCase() || lowerRecipient === smartAccount.toLowerCase()) {
1234
+ throw new Error(
1235
+ "Recipient can't be your own account. Send to a different wallet."
1236
+ );
1237
+ }
1212
1238
  if (!onSignTransaction && !signerContext?.walletClient) {
1213
1239
  throw new Error("Wallet not connected");
1214
1240
  }
@@ -1232,7 +1258,7 @@ function WithdrawFlow({
1232
1258
  targetToken
1233
1259
  });
1234
1260
  const amountUnits = parseUnits2(amountValue, asset.decimals);
1235
- const pc = signerContext?.publicClient ?? getPublicClient(sourceChain);
1261
+ const pc = signerContext?.publicClient ?? getPublicClient(sourceChain, rpcUrls);
1236
1262
  let result;
1237
1263
  if (onSignTransaction) {
1238
1264
  const transferTarget = isSameRoute ? recipient : smartAccount;
@@ -1340,7 +1366,8 @@ function WithdrawFlow({
1340
1366
  logFlow,
1341
1367
  logFlowError,
1342
1368
  onLifecycleRef,
1343
- storeApi
1369
+ storeApi,
1370
+ rpcUrls
1344
1371
  ]
1345
1372
  );
1346
1373
  const handleWithdrawComplete = useCallback2(
@@ -1477,7 +1504,8 @@ function WithdrawFlow({
1477
1504
  if (!signerContext) return null;
1478
1505
  if (!onSignTransaction && !signerContext.walletClient) return null;
1479
1506
  const resolvedConnectedRecipient = selectedWalletOption?.kind === "external" ? selectedWalletOption.address : void 0;
1480
- const formPublicClient = signerContext.publicClient ?? getPublicClient(sourceChain);
1507
+ const formPublicClient = signerContext.publicClient ?? getPublicClient(sourceChain, rpcUrls);
1508
+ const depositAddress = registration.kind === "ready" || registration.kind === "stale" ? registration.smartAccount : void 0;
1481
1509
  const stepView = deriveStepView(flowStep, registration);
1482
1510
  return /* @__PURE__ */ jsxs3("div", { className: "rs-modal-body", children: [
1483
1511
  stepView === "form" && /* @__PURE__ */ jsx3(
@@ -1487,6 +1515,7 @@ function WithdrawFlow({
1487
1515
  publicClient: formPublicClient,
1488
1516
  connectedRecipient: resolvedConnectedRecipient,
1489
1517
  safeAddress,
1518
+ depositAddress,
1490
1519
  asset,
1491
1520
  defaultRecipient,
1492
1521
  defaultAmount,
@@ -1564,7 +1593,7 @@ function deriveStepView(step, _registration) {
1564
1593
  // src/WithdrawModal.tsx
1565
1594
  import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1566
1595
  var ReownWithdrawInner = lazy(
1567
- () => import("./WithdrawModalReown-L4SWLONE.mjs").then((m) => ({
1596
+ () => import("./WithdrawModalReown-FRMD2ACH.mjs").then((m) => ({
1568
1597
  default: m.WithdrawModalReown
1569
1598
  }))
1570
1599
  );
@@ -1593,6 +1622,7 @@ function WithdrawModalInner({
1593
1622
  closeOnOverlayClick,
1594
1623
  allowedRoutes,
1595
1624
  backendUrl = DEFAULT_BACKEND_URL,
1625
+ rpcUrls,
1596
1626
  signerAddress = DEFAULT_SIGNER_ADDRESS,
1597
1627
  sessionChainIds,
1598
1628
  forceRegister = false,
@@ -1651,7 +1681,7 @@ function WithdrawModalInner({
1651
1681
  }, []);
1652
1682
  const showBackButton = uiConfig?.showBackButton ?? true;
1653
1683
  const canGoBack = backHandler !== void 0;
1654
- return /* @__PURE__ */ jsx4(WithdrawStoreProvider, { store, children: /* @__PURE__ */ jsx4(
1684
+ return /* @__PURE__ */ jsx4(RpcUrlsProvider, { value: rpcUrls, children: /* @__PURE__ */ jsx4(WithdrawStoreProvider, { store, children: /* @__PURE__ */ jsx4(
1655
1685
  Modal,
1656
1686
  {
1657
1687
  isOpen,
@@ -1715,7 +1745,7 @@ function WithdrawModalInner({
1715
1745
  )
1716
1746
  ] })
1717
1747
  }
1718
- ) });
1748
+ ) }) });
1719
1749
  }
1720
1750
 
1721
1751
  export {