@cookill/wallet-adapter 3.1.7 → 3.1.8

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.
package/dist/react.cjs CHANGED
@@ -742,10 +742,7 @@ function WalletProvider({
742
742
  }
743
743
  if (!wallet.isInstalled) {
744
744
  dispatch({ type: "OPEN_MODAL" });
745
- const err = new Error("Sheep Wallet not installed");
746
- dispatch({ type: "ERROR", error: err });
747
- onError?.(err);
748
- throw err;
745
+ return [];
749
746
  }
750
747
  connectingRef.current = true;
751
748
  dispatch({ type: "CONNECTING" });
@@ -1046,6 +1043,12 @@ function WalletModal({ scanConnectRelay, dispatch }) {
1046
1043
  const { state, wallets, connect, closeModal, isInstalled: installed } = useWallet();
1047
1044
  const [activeTab, setActiveTab] = React.useState("extension");
1048
1045
  const [scanMode, setScanMode] = React.useState("show-qr");
1046
+ const [webWalletMode, setWebWalletMode] = React.useState("menu");
1047
+ const [webWalletPassword, setWebWalletPassword] = React.useState("");
1048
+ const [webWalletMnemonic, setWebWalletMnemonic] = React.useState("");
1049
+ const [webWalletGeneratedMnemonic, setWebWalletGeneratedMnemonic] = React.useState("");
1050
+ const [webWalletError, setWebWalletError] = React.useState("");
1051
+ const [webWalletLoading, setWebWalletLoading] = React.useState(false);
1049
1052
  const [generatedURI, setGeneratedURI] = React.useState(null);
1050
1053
  const [qrReady, setQRReady] = React.useState(false);
1051
1054
  const canvasRef = React.useRef(null);
@@ -1075,6 +1078,53 @@ function WalletModal({ scanConnectRelay, dispatch }) {
1075
1078
  } catch {
1076
1079
  }
1077
1080
  };
1081
+ const handleWebWalletConnect = async (action) => {
1082
+ setWebWalletError("");
1083
+ setWebWalletLoading(true);
1084
+ try {
1085
+ const provider = window.rialo;
1086
+ if (!provider?.isWebWallet) {
1087
+ throw new Error("Web wallet provider not available. Make sure registerWebWallet() is called.");
1088
+ }
1089
+ if (action === "create") {
1090
+ if (!webWalletPassword || webWalletPassword.length < 6) {
1091
+ throw new Error("Password must be at least 6 characters");
1092
+ }
1093
+ const result = await provider.createWallet(webWalletPassword);
1094
+ setWebWalletGeneratedMnemonic(result.mnemonic);
1095
+ try {
1096
+ await connect();
1097
+ } catch {
1098
+ }
1099
+ } else if (action === "import") {
1100
+ if (!webWalletMnemonic.trim()) {
1101
+ throw new Error("Please enter your recovery phrase");
1102
+ }
1103
+ if (!webWalletPassword || webWalletPassword.length < 6) {
1104
+ throw new Error("Password must be at least 6 characters");
1105
+ }
1106
+ await provider.importWallet(webWalletMnemonic.trim(), webWalletPassword);
1107
+ try {
1108
+ await connect();
1109
+ } catch {
1110
+ }
1111
+ } else if (action === "unlock") {
1112
+ if (!webWalletPassword) {
1113
+ throw new Error("Please enter your password");
1114
+ }
1115
+ const unlocked = await provider.unlock(webWalletPassword);
1116
+ if (!unlocked) throw new Error("Incorrect password");
1117
+ try {
1118
+ await connect();
1119
+ } catch {
1120
+ }
1121
+ }
1122
+ } catch (err) {
1123
+ setWebWalletError(err?.message || "Web wallet operation failed");
1124
+ } finally {
1125
+ setWebWalletLoading(false);
1126
+ }
1127
+ };
1078
1128
  const generateScanSession = async () => {
1079
1129
  dispatch({ type: "SET_SCAN_STATUS", status: "generating" });
1080
1130
  const sessionId = crypto.randomUUID();
@@ -1237,7 +1287,32 @@ function WalletModal({ scanConnectRelay, dispatch }) {
1237
1287
  },
1238
1288
  children: [
1239
1289
  /* @__PURE__ */ jsxRuntime.jsx(QrIcon, {}),
1240
- " Scan to Connect"
1290
+ " Scan"
1291
+ ]
1292
+ }
1293
+ ),
1294
+ /* @__PURE__ */ jsxRuntime.jsxs(
1295
+ "button",
1296
+ {
1297
+ type: "button",
1298
+ onClick: (e) => {
1299
+ stop(e);
1300
+ setActiveTab("webwallet");
1301
+ },
1302
+ style: {
1303
+ ...tabBaseStyle,
1304
+ backgroundColor: activeTab === "webwallet" ? "rgba(255,255,255,0.08)" : "transparent",
1305
+ color: activeTab === "webwallet" ? "#6EB9A8" : "rgba(255,255,255,0.4)",
1306
+ fontWeight: activeTab === "webwallet" ? 600 : 400
1307
+ },
1308
+ children: [
1309
+ /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1310
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "2", y: "3", width: "20", height: "14", rx: "2" }),
1311
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 10h20" }),
1312
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 17v4" }),
1313
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 21h8" })
1314
+ ] }),
1315
+ "Web Wallet"
1241
1316
  ]
1242
1317
  }
1243
1318
  )
@@ -1492,6 +1567,238 @@ function WalletModal({ scanConnectRelay, dispatch }) {
1492
1567
  ] })
1493
1568
  ] })
1494
1569
  ] }),
1570
+ activeTab === "webwallet" && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1571
+ (() => {
1572
+ const webProvider = typeof window !== "undefined" ? window.rialo : null;
1573
+ const hasWebWallet = webProvider?.isWebWallet && webProvider?.hasWallet?.();
1574
+ const isUnlocked = webProvider?.isWebWallet && webProvider?.isUnlocked?.();
1575
+ if (webWalletGeneratedMnemonic) {
1576
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1577
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1578
+ padding: "14px",
1579
+ backgroundColor: "rgba(110,185,168,0.08)",
1580
+ border: "1px solid rgba(110,185,168,0.2)",
1581
+ borderRadius: "12px",
1582
+ marginBottom: "16px"
1583
+ }, children: [
1584
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#6EB9A8", fontSize: "12px", fontWeight: 600, marginBottom: "8px" }, children: "Wallet Created & Connected!" }),
1585
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "rgba(255,255,255,0.6)", fontSize: "11px", marginBottom: "8px" }, children: "Save your recovery phrase securely:" }),
1586
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1587
+ padding: "10px",
1588
+ backgroundColor: "rgba(0,0,0,0.3)",
1589
+ borderRadius: "8px",
1590
+ color: "#fff",
1591
+ fontSize: "12px",
1592
+ fontFamily: "monospace",
1593
+ wordBreak: "break-word",
1594
+ lineHeight: 1.6
1595
+ }, children: webWalletGeneratedMnemonic })
1596
+ ] }),
1597
+ /* @__PURE__ */ jsxRuntime.jsx(
1598
+ "button",
1599
+ {
1600
+ type: "button",
1601
+ onClick: (e) => {
1602
+ stop(e);
1603
+ setWebWalletGeneratedMnemonic("");
1604
+ closeModal();
1605
+ },
1606
+ style: { width: "100%", padding: "12px", backgroundColor: "#6EB9A8", border: "none", borderRadius: "12px", color: "#011B29", fontSize: "14px", fontWeight: 600, cursor: "pointer" },
1607
+ children: "I've Saved It \u2014 Continue"
1608
+ }
1609
+ )
1610
+ ] });
1611
+ }
1612
+ if (hasWebWallet && !isUnlocked) {
1613
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1614
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "rgba(255,255,255,0.5)", fontSize: "13px", marginBottom: "16px" }, children: "Web wallet locked. Enter password to connect." }),
1615
+ /* @__PURE__ */ jsxRuntime.jsx(
1616
+ "input",
1617
+ {
1618
+ type: "password",
1619
+ placeholder: "Password",
1620
+ value: webWalletPassword,
1621
+ onChange: (e) => setWebWalletPassword(e.target.value),
1622
+ onClick: stop,
1623
+ onKeyDown: (e) => {
1624
+ if (e.key === "Enter") handleWebWalletConnect("unlock");
1625
+ },
1626
+ style: { width: "100%", padding: "12px 14px", backgroundColor: "rgba(255,255,255,0.04)", border: "1px solid rgba(255,255,255,0.1)", borderRadius: "12px", color: "#fff", fontSize: "14px", marginBottom: "12px", outline: "none", boxSizing: "border-box" }
1627
+ }
1628
+ ),
1629
+ /* @__PURE__ */ jsxRuntime.jsx(
1630
+ "button",
1631
+ {
1632
+ type: "button",
1633
+ onClick: (e) => {
1634
+ stop(e);
1635
+ handleWebWalletConnect("unlock");
1636
+ },
1637
+ disabled: webWalletLoading,
1638
+ style: { width: "100%", padding: "12px", backgroundColor: "#6EB9A8", border: "none", borderRadius: "12px", color: "#011B29", fontSize: "14px", fontWeight: 600, cursor: webWalletLoading ? "wait" : "pointer", opacity: webWalletLoading ? 0.6 : 1 },
1639
+ children: webWalletLoading ? "Unlocking..." : "Unlock & Connect"
1640
+ }
1641
+ )
1642
+ ] });
1643
+ }
1644
+ if (hasWebWallet && isUnlocked) {
1645
+ return /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: async (e) => {
1646
+ stop(e);
1647
+ setWebWalletLoading(true);
1648
+ try {
1649
+ await connect();
1650
+ } catch (err) {
1651
+ setWebWalletError(err?.message || "Failed");
1652
+ } finally {
1653
+ setWebWalletLoading(false);
1654
+ }
1655
+ }, disabled: webWalletLoading, style: {
1656
+ width: "100%",
1657
+ display: "flex",
1658
+ alignItems: "center",
1659
+ gap: "14px",
1660
+ padding: "16px",
1661
+ backgroundColor: "rgba(255,255,255,0.04)",
1662
+ border: "1px solid rgba(255,255,255,0.08)",
1663
+ borderRadius: "14px",
1664
+ cursor: webWalletLoading ? "wait" : "pointer"
1665
+ }, children: [
1666
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: "44px", height: "44px", borderRadius: "12px", background: "linear-gradient(135deg, #3B82F6, #6366F1)", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff" }, children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1667
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "2", y: "3", width: "20", height: "14", rx: "2" }),
1668
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 10h20" })
1669
+ ] }) }),
1670
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1, textAlign: "left" }, children: [
1671
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#fff", fontWeight: 500, fontSize: "15px" }, children: "Web Wallet" }),
1672
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: "12px", color: "#6EB9A8" }, children: webWalletLoading ? "Connecting..." : "Ready \u2014 Click to connect" })
1673
+ ] })
1674
+ ] });
1675
+ }
1676
+ if (webWalletMode === "create") {
1677
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1678
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: (e) => {
1679
+ stop(e);
1680
+ setWebWalletMode("menu");
1681
+ }, style: { background: "none", border: "none", color: "rgba(255,255,255,0.4)", cursor: "pointer", fontSize: "12px", marginBottom: "12px", padding: 0 }, children: "\u2190 Back" }),
1682
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "rgba(255,255,255,0.5)", fontSize: "13px", marginBottom: "16px" }, children: "Create a new web wallet with a generated recovery phrase." }),
1683
+ /* @__PURE__ */ jsxRuntime.jsx(
1684
+ "input",
1685
+ {
1686
+ type: "password",
1687
+ placeholder: "Set password (min 6 chars)",
1688
+ value: webWalletPassword,
1689
+ onChange: (e) => setWebWalletPassword(e.target.value),
1690
+ onClick: stop,
1691
+ style: { width: "100%", padding: "12px 14px", backgroundColor: "rgba(255,255,255,0.04)", border: "1px solid rgba(255,255,255,0.1)", borderRadius: "12px", color: "#fff", fontSize: "14px", marginBottom: "12px", outline: "none", boxSizing: "border-box" }
1692
+ }
1693
+ ),
1694
+ /* @__PURE__ */ jsxRuntime.jsx(
1695
+ "button",
1696
+ {
1697
+ type: "button",
1698
+ onClick: (e) => {
1699
+ stop(e);
1700
+ handleWebWalletConnect("create");
1701
+ },
1702
+ disabled: webWalletLoading,
1703
+ style: { width: "100%", padding: "12px", backgroundColor: "#6EB9A8", border: "none", borderRadius: "12px", color: "#011B29", fontSize: "14px", fontWeight: 600, cursor: webWalletLoading ? "wait" : "pointer", opacity: webWalletLoading ? 0.6 : 1 },
1704
+ children: webWalletLoading ? "Creating..." : "Create Wallet"
1705
+ }
1706
+ )
1707
+ ] });
1708
+ }
1709
+ if (webWalletMode === "import") {
1710
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1711
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: (e) => {
1712
+ stop(e);
1713
+ setWebWalletMode("menu");
1714
+ }, style: { background: "none", border: "none", color: "rgba(255,255,255,0.4)", cursor: "pointer", fontSize: "12px", marginBottom: "12px", padding: 0 }, children: "\u2190 Back" }),
1715
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "rgba(255,255,255,0.5)", fontSize: "13px", marginBottom: "16px" }, children: "Import wallet from recovery phrase." }),
1716
+ /* @__PURE__ */ jsxRuntime.jsx(
1717
+ "textarea",
1718
+ {
1719
+ placeholder: "Enter 12 or 24 word recovery phrase",
1720
+ value: webWalletMnemonic,
1721
+ onChange: (e) => setWebWalletMnemonic(e.target.value),
1722
+ onClick: stop,
1723
+ style: { width: "100%", padding: "12px 14px", backgroundColor: "rgba(255,255,255,0.04)", border: "1px solid rgba(255,255,255,0.1)", borderRadius: "12px", color: "#fff", fontSize: "13px", marginBottom: "12px", outline: "none", boxSizing: "border-box", minHeight: "80px", resize: "vertical", fontFamily: "monospace" }
1724
+ }
1725
+ ),
1726
+ /* @__PURE__ */ jsxRuntime.jsx(
1727
+ "input",
1728
+ {
1729
+ type: "password",
1730
+ placeholder: "Set password (min 6 chars)",
1731
+ value: webWalletPassword,
1732
+ onChange: (e) => setWebWalletPassword(e.target.value),
1733
+ onClick: stop,
1734
+ style: { width: "100%", padding: "12px 14px", backgroundColor: "rgba(255,255,255,0.04)", border: "1px solid rgba(255,255,255,0.1)", borderRadius: "12px", color: "#fff", fontSize: "14px", marginBottom: "12px", outline: "none", boxSizing: "border-box" }
1735
+ }
1736
+ ),
1737
+ /* @__PURE__ */ jsxRuntime.jsx(
1738
+ "button",
1739
+ {
1740
+ type: "button",
1741
+ onClick: (e) => {
1742
+ stop(e);
1743
+ handleWebWalletConnect("import");
1744
+ },
1745
+ disabled: webWalletLoading,
1746
+ style: { width: "100%", padding: "12px", backgroundColor: "#6EB9A8", border: "none", borderRadius: "12px", color: "#011B29", fontSize: "14px", fontWeight: 600, cursor: webWalletLoading ? "wait" : "pointer", opacity: webWalletLoading ? 0.6 : 1 },
1747
+ children: webWalletLoading ? "Importing..." : "Import & Connect"
1748
+ }
1749
+ )
1750
+ ] });
1751
+ }
1752
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1753
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "rgba(255,255,255,0.5)", fontSize: "13px", marginBottom: "16px", lineHeight: 1.5 }, children: webProvider?.isWebWallet ? "Create or import a web wallet \u2014 no extension needed." : "Web wallet not available. Call registerWebWallet() at app startup." }),
1754
+ webProvider?.isWebWallet && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "10px" }, children: [
1755
+ /* @__PURE__ */ jsxRuntime.jsxs(
1756
+ "button",
1757
+ {
1758
+ type: "button",
1759
+ onClick: (e) => {
1760
+ stop(e);
1761
+ setWebWalletMode("create");
1762
+ setWebWalletError("");
1763
+ },
1764
+ style: { width: "100%", display: "flex", alignItems: "center", gap: "14px", padding: "16px", backgroundColor: "rgba(255,255,255,0.04)", border: "1px solid rgba(255,255,255,0.08)", borderRadius: "14px", cursor: "pointer" },
1765
+ children: [
1766
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: "40px", height: "40px", borderRadius: "10px", background: "linear-gradient(135deg, #3B82F6, #6366F1)", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff", fontSize: "18px" }, children: "+" }),
1767
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "left" }, children: [
1768
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#fff", fontWeight: 500, fontSize: "14px" }, children: "Create New Wallet" }),
1769
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "rgba(255,255,255,0.4)", fontSize: "11px" }, children: "Generate a new recovery phrase" })
1770
+ ] })
1771
+ ]
1772
+ }
1773
+ ),
1774
+ /* @__PURE__ */ jsxRuntime.jsxs(
1775
+ "button",
1776
+ {
1777
+ type: "button",
1778
+ onClick: (e) => {
1779
+ stop(e);
1780
+ setWebWalletMode("import");
1781
+ setWebWalletError("");
1782
+ },
1783
+ style: { width: "100%", display: "flex", alignItems: "center", gap: "14px", padding: "16px", backgroundColor: "rgba(255,255,255,0.04)", border: "1px solid rgba(255,255,255,0.08)", borderRadius: "14px", cursor: "pointer" },
1784
+ children: [
1785
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: "40px", height: "40px", borderRadius: "10px", background: "linear-gradient(135deg, #F59E0B, #EF4444)", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff" }, children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1786
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 3v12" }),
1787
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m8 11 4 4 4-4" }),
1788
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 5H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-4" })
1789
+ ] }) }),
1790
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "left" }, children: [
1791
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#fff", fontWeight: 500, fontSize: "14px" }, children: "Import Wallet" }),
1792
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "rgba(255,255,255,0.4)", fontSize: "11px" }, children: "Use existing recovery phrase" })
1793
+ ] })
1794
+ ]
1795
+ }
1796
+ )
1797
+ ] })
1798
+ ] });
1799
+ })(),
1800
+ webWalletError && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: "12px", padding: "10px 12px", backgroundColor: "rgba(239,68,68,0.08)", border: "1px solid rgba(239,68,68,0.15)", borderRadius: "10px", color: "#f87171", fontSize: "12px" }, children: webWalletError })
1801
+ ] }),
1495
1802
  state.error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
1496
1803
  marginTop: "16px",
1497
1804
  padding: "12px 14px",
@@ -1659,14 +1966,7 @@ function ConnectButton({
1659
1966
  if (connected) {
1660
1967
  setShowMenu(!showMenu);
1661
1968
  } else {
1662
- if (installed) {
1663
- try {
1664
- await connect();
1665
- } catch {
1666
- }
1667
- } else {
1668
- openModal();
1669
- }
1969
+ openModal();
1670
1970
  }
1671
1971
  };
1672
1972
  const displayText = connected && activeAccount && showAddress ? `${activeAccount.address.slice(0, 6)}...${activeAccount.address.slice(-4)}` : connecting ? "Connecting..." : connectLabel;