@rhinestone/deposit-modal 0.1.38 → 0.1.39

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.
@@ -13,6 +13,7 @@ import {
13
13
  currencyFormatter,
14
14
  formatUserError,
15
15
  getAssetId,
16
+ getEventSourceDetails,
16
17
  getEventTxHash,
17
18
  getPublicClient,
18
19
  isDepositEvent,
@@ -21,7 +22,7 @@ import {
21
22
  portfolioToAssets,
22
23
  saveSessionOwnerToStorage,
23
24
  tokenFormatter
24
- } from "./chunk-UBPIPY3L.mjs";
25
+ } from "./chunk-IC2M2DZ7.mjs";
25
26
  import {
26
27
  DEFAULT_BACKEND_URL,
27
28
  DEFAULT_SIGNER_ADDRESS,
@@ -37,7 +38,7 @@ import {
37
38
  getTokenIcon,
38
39
  getTokenSymbol,
39
40
  isStablecoinSymbol
40
- } from "./chunk-ZL4KPLWE.mjs";
41
+ } from "./chunk-I7RYTI4G.mjs";
41
42
 
42
43
  // src/DepositModal.tsx
43
44
  import {
@@ -1236,46 +1237,6 @@ QRCode.displayName = "QRCode";
1236
1237
  // src/components/steps/DepositAddressStep.tsx
1237
1238
  import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1238
1239
  var POLL_INTERVAL_MS = 4e3;
1239
- function isRecord(value) {
1240
- return typeof value === "object" && value !== null;
1241
- }
1242
- function asNumber(value) {
1243
- if (typeof value === "number" && Number.isFinite(value)) return value;
1244
- if (typeof value === "string" && value.trim() !== "") {
1245
- const parsed = Number(value);
1246
- return Number.isFinite(parsed) ? parsed : void 0;
1247
- }
1248
- return void 0;
1249
- }
1250
- function asAmount(value) {
1251
- if (typeof value === "string") return value;
1252
- if (typeof value === "number" && Number.isFinite(value)) {
1253
- return value.toString();
1254
- }
1255
- return void 0;
1256
- }
1257
- function asAddress(value) {
1258
- if (typeof value !== "string") return void 0;
1259
- return /^0x[a-fA-F0-9]{40}$/.test(value) ? value : void 0;
1260
- }
1261
- function getDepositEventDetails(event) {
1262
- if (!event?.type || !isRecord(event.data)) return {};
1263
- if (event.type === "deposit-received") {
1264
- return {
1265
- chainId: asNumber(event.data.chain),
1266
- amount: asAmount(event.data.amount),
1267
- token: asAddress(event.data.token)
1268
- };
1269
- }
1270
- if (event.type === "bridge-started") {
1271
- const source = isRecord(event.data.source) ? event.data.source : void 0;
1272
- return {
1273
- chainId: asNumber(source?.chain),
1274
- token: asAddress(source?.asset)
1275
- };
1276
- }
1277
- return {};
1278
- }
1279
1240
  function DepositAddressStep({
1280
1241
  smartAccount,
1281
1242
  service,
@@ -1366,7 +1327,7 @@ function DepositAddressStep({
1366
1327
  if (baselineTxHash === void 0) {
1367
1328
  baselineTxHash = eventTxHash;
1368
1329
  } else if (eventTxHash && eventTxHash !== baselineTxHash) {
1369
- const details = getDepositEventDetails(event);
1330
+ const details = getEventSourceDetails(event);
1370
1331
  const fallback = sourceSelectionRef.current;
1371
1332
  const chainId = details.chainId ?? fallback.chainId;
1372
1333
  const amount = details.amount ?? "0";
@@ -1585,6 +1546,9 @@ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1585
1546
  function isSameRoute(sourceChain, sourceToken, targetChain, targetToken) {
1586
1547
  return sourceChain === targetChain && sourceToken.toLowerCase() === targetToken.toLowerCase();
1587
1548
  }
1549
+ function getAddressKey(address) {
1550
+ return address ? address.toLowerCase() : null;
1551
+ }
1588
1552
  function DepositFlow({
1589
1553
  dappWalletClient,
1590
1554
  dappPublicClient,
@@ -1622,6 +1586,8 @@ function DepositFlow({
1622
1586
  const [isConnectSelectionConfirmed, setIsConnectSelectionConfirmed] = useState7(false);
1623
1587
  const [selectedConnectAddress, setSelectedConnectAddress] = useState7(null);
1624
1588
  const portfolioAssetsRef = useRef5([]);
1589
+ const stableWalletSignerRef = useRef5(null);
1590
+ const stableWalletSelectionKeyRef = useRef5(null);
1625
1591
  const handleAssetsLoaded = useCallback3((assets) => {
1626
1592
  portfolioAssetsRef.current = assets;
1627
1593
  }, []);
@@ -1644,16 +1610,17 @@ function DepositFlow({
1644
1610
  await dappWalletClient.switchChain?.({ id: chainId });
1645
1611
  };
1646
1612
  }, [dappWalletClient]);
1613
+ const connectedWalletAddress = dappWalletClient?.account?.address ?? null;
1647
1614
  const walletOptions = useMemo5(() => {
1648
1615
  const options = [];
1649
1616
  const seen = /* @__PURE__ */ new Set();
1650
- if (dappWalletClient?.account && dappAddress) {
1617
+ if (connectedWalletAddress && dappAddress) {
1651
1618
  options.push({
1652
- address: dappWalletClient.account.address,
1619
+ address: connectedWalletAddress,
1653
1620
  label: "Connected Wallet",
1654
1621
  kind: "connected"
1655
1622
  });
1656
- seen.add(dappWalletClient.account.address.toLowerCase());
1623
+ seen.add(connectedWalletAddress.toLowerCase());
1657
1624
  }
1658
1625
  if (reownWallet?.address && reownWallet.isConnected && reownWallet.walletClient && reownWallet.publicClient && !seen.has(reownWallet.address.toLowerCase())) {
1659
1626
  options.push({
@@ -1665,7 +1632,7 @@ function DepositFlow({
1665
1632
  }
1666
1633
  return options;
1667
1634
  }, [
1668
- dappWalletClient,
1635
+ connectedWalletAddress,
1669
1636
  dappAddress,
1670
1637
  reownWallet?.address,
1671
1638
  reownWallet?.isConnected,
@@ -1675,17 +1642,27 @@ function DepositFlow({
1675
1642
  ]);
1676
1643
  const canAutoLock = dappWalletClient?.account && dappAddress && !reownWallet;
1677
1644
  const hasWalletOptions = walletOptions.length > 0;
1678
- const hasReownSession = Boolean(reownWallet?.isConnected || reownWallet?.address);
1679
- const showConnectStep = !canAutoLock && !isConnectSelectionConfirmed;
1680
- const signerContext = useMemo5(() => {
1645
+ const hasReownSession = Boolean(
1646
+ reownWallet?.isConnected || reownWallet?.address
1647
+ );
1648
+ const showConnectStep = flowMode === null && !canAutoLock && !isConnectSelectionConfirmed;
1649
+ const walletSelectionKey = useMemo5(() => {
1650
+ if (flowMode !== "wallet") return null;
1651
+ if (canAutoLock) {
1652
+ return getAddressKey(connectedWalletAddress);
1653
+ }
1654
+ if (!isConnectSelectionConfirmed) return null;
1655
+ return getAddressKey(selectedConnectAddress);
1656
+ }, [
1657
+ flowMode,
1658
+ canAutoLock,
1659
+ connectedWalletAddress,
1660
+ isConnectSelectionConfirmed,
1661
+ selectedConnectAddress
1662
+ ]);
1663
+ const walletSignerContext = useMemo5(() => {
1681
1664
  if (flowMode === "deposit-address") {
1682
- if (!dappAddress) return null;
1683
- return {
1684
- ownerAddress: dappAddress,
1685
- walletClient: void 0,
1686
- publicClient: dappPublicClient ?? getPublicClient(targetChain),
1687
- switchChain: void 0
1688
- };
1665
+ return null;
1689
1666
  }
1690
1667
  if (canAutoLock) {
1691
1668
  const fallbackChainId = dappWalletClient?.chain?.id ?? targetChain;
@@ -1716,7 +1693,6 @@ function DepositFlow({
1716
1693
  }
1717
1694
  return null;
1718
1695
  }, [
1719
- flowMode,
1720
1696
  canAutoLock,
1721
1697
  isConnectSelectionConfirmed,
1722
1698
  selectedConnectAddress,
@@ -1727,6 +1703,49 @@ function DepositFlow({
1727
1703
  reownWallet,
1728
1704
  targetChain
1729
1705
  ]);
1706
+ useEffect7(() => {
1707
+ if (flowMode !== "wallet") {
1708
+ stableWalletSelectionKeyRef.current = null;
1709
+ stableWalletSignerRef.current = null;
1710
+ return;
1711
+ }
1712
+ if (walletSelectionKey !== stableWalletSelectionKeyRef.current) {
1713
+ stableWalletSelectionKeyRef.current = walletSelectionKey;
1714
+ stableWalletSignerRef.current = null;
1715
+ }
1716
+ if (walletSignerContext && walletSelectionKey) {
1717
+ stableWalletSelectionKeyRef.current = walletSelectionKey;
1718
+ stableWalletSignerRef.current = walletSignerContext;
1719
+ }
1720
+ }, [flowMode, walletSelectionKey, walletSignerContext]);
1721
+ const signerContext = useMemo5(() => {
1722
+ if (flowMode === "deposit-address") {
1723
+ if (!dappAddress) return null;
1724
+ return {
1725
+ ownerAddress: dappAddress,
1726
+ walletClient: void 0,
1727
+ publicClient: dappPublicClient ?? getPublicClient(targetChain),
1728
+ switchChain: void 0
1729
+ };
1730
+ }
1731
+ if (flowMode !== "wallet") {
1732
+ return null;
1733
+ }
1734
+ if (walletSignerContext) {
1735
+ return walletSignerContext;
1736
+ }
1737
+ if (walletSelectionKey && stableWalletSelectionKeyRef.current === walletSelectionKey) {
1738
+ return stableWalletSignerRef.current;
1739
+ }
1740
+ return null;
1741
+ }, [
1742
+ flowMode,
1743
+ dappAddress,
1744
+ dappPublicClient,
1745
+ targetChain,
1746
+ walletSignerContext,
1747
+ walletSelectionKey
1748
+ ]);
1730
1749
  const sessionKeyAddress = dappAddress ?? signerContext?.ownerAddress ?? null;
1731
1750
  const lastTargetRef = useRef5(null);
1732
1751
  useEffect7(() => {
@@ -1747,6 +1766,7 @@ function DepositFlow({
1747
1766
  const handleBackFromSelectAsset = useCallback3(() => {
1748
1767
  if (hasWalletOptions || reownWallet) {
1749
1768
  hasNavigatedBackRef.current = true;
1769
+ setFlowMode(null);
1750
1770
  setIsConnectSelectionConfirmed(false);
1751
1771
  }
1752
1772
  }, [hasWalletOptions, reownWallet]);
@@ -2119,7 +2139,7 @@ function DepositFlow({
2119
2139
  // src/DepositModal.tsx
2120
2140
  import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
2121
2141
  var ReownDepositInner = lazy(
2122
- () => import("./DepositModalReown-BJWM3JMC.mjs").then((m) => ({ default: m.DepositModalReown }))
2142
+ () => import("./DepositModalReown-YTUE3XAB.mjs").then((m) => ({ default: m.DepositModalReown }))
2123
2143
  );
2124
2144
  function DepositModal(props) {
2125
2145
  const needsReown = !!props.reownAppId;