@pollar/react 0.8.1 → 0.9.0-rc.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.
- package/dist/index.d.mts +42 -26
- package/dist/index.d.ts +42 -26
- package/dist/index.js +302 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +302 -111
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
var core = require('@pollar/core');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var browser = require('@simplewebauthn/browser');
|
|
7
8
|
|
|
8
9
|
var __create = Object.create;
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
@@ -1012,7 +1013,7 @@ var ModalErrorBoundary = class extends react.Component {
|
|
|
1012
1013
|
return { crashed: true };
|
|
1013
1014
|
}
|
|
1014
1015
|
componentDidCatch(error) {
|
|
1015
|
-
console.error("[
|
|
1016
|
+
console.error("[PollarProvider] Modal crashed:", error);
|
|
1016
1017
|
}
|
|
1017
1018
|
render() {
|
|
1018
1019
|
if (this.state.crashed) {
|
|
@@ -1030,7 +1031,7 @@ var PollarModalFooter = () => {
|
|
|
1030
1031
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "pollar-footer-name", children: "Pollar" }),
|
|
1031
1032
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pollar-footer-version", children: [
|
|
1032
1033
|
"v",
|
|
1033
|
-
"0.
|
|
1034
|
+
"0.9.0-rc.0"
|
|
1034
1035
|
] })
|
|
1035
1036
|
] })
|
|
1036
1037
|
] });
|
|
@@ -1067,7 +1068,8 @@ var REASON_LABEL = {
|
|
|
1067
1068
|
DISTRIBUTION_RULE_NOT_STARTED: "Not started yet",
|
|
1068
1069
|
DISTRIBUTION_RULE_EXPIRED: "Expired",
|
|
1069
1070
|
DISTRIBUTION_RULE_EXHAUSTED: "Fully claimed",
|
|
1070
|
-
|
|
1071
|
+
// Per-user, per-window claim limit (resets next period) — not permanent.
|
|
1072
|
+
DISTRIBUTION_RATE_LIMIT_EXCEEDED: "Claimed for this period"
|
|
1071
1073
|
};
|
|
1072
1074
|
function reasonLabel(reason) {
|
|
1073
1075
|
if (!reason) return "Not available";
|
|
@@ -1344,11 +1346,7 @@ function KycModalTemplate({
|
|
|
1344
1346
|
step === "verifying" && selectedProvider && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1345
1347
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pollar-kyc-iframe-wrap", children: session?.kycUrl ? /* @__PURE__ */ jsxRuntime.jsx("iframe", { className: "pollar-kyc-iframe", src: session.kycUrl, title: "KYC verification", allow: "camera; microphone" }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-kyc-iframe-mock", children: [
|
|
1346
1348
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u{1F512}" }),
|
|
1347
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: selectedProvider.flow === "form" ? "
|
|
1348
|
-
/* @__PURE__ */ jsxRuntime.jsxs("code", { style: { fontSize: "0.7rem", opacity: 0.6 }, children: [
|
|
1349
|
-
"provider: ",
|
|
1350
|
-
selectedProvider.id
|
|
1351
|
-
] })
|
|
1349
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: selectedProvider.flow === "form" ? "The identity verification form will appear here." : "Identity verification will open here." })
|
|
1352
1350
|
] }) }),
|
|
1353
1351
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-modal-actions", children: [
|
|
1354
1352
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: onClose, children: "Cancel" }),
|
|
@@ -1497,46 +1495,37 @@ var GoogleButton = ({ disabled, onClick }) => {
|
|
|
1497
1495
|
return /* @__PURE__ */ jsxRuntime.jsxs("button", { className: "gsi-material-button", disabled, onClick, children: [
|
|
1498
1496
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "gsi-material-button-state" }),
|
|
1499
1497
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gsi-material-button-content-wrapper", children: [
|
|
1500
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "gsi-material-button-icon", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
{
|
|
1532
|
-
fill: "#34A853",
|
|
1533
|
-
d: "M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"
|
|
1534
|
-
}
|
|
1535
|
-
),
|
|
1536
|
-
/* @__PURE__ */ jsxRuntime.jsx("path", { fill: "none", d: "M0 0h48v48H0z" })
|
|
1537
|
-
]
|
|
1538
|
-
}
|
|
1539
|
-
) }),
|
|
1498
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "gsi-material-button-icon", children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { version: "1.1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 48 48", style: { display: "block" }, children: [
|
|
1499
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1500
|
+
"path",
|
|
1501
|
+
{
|
|
1502
|
+
fill: "#EA4335",
|
|
1503
|
+
d: "M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"
|
|
1504
|
+
}
|
|
1505
|
+
),
|
|
1506
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1507
|
+
"path",
|
|
1508
|
+
{
|
|
1509
|
+
fill: "#4285F4",
|
|
1510
|
+
d: "M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"
|
|
1511
|
+
}
|
|
1512
|
+
),
|
|
1513
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1514
|
+
"path",
|
|
1515
|
+
{
|
|
1516
|
+
fill: "#FBBC05",
|
|
1517
|
+
d: "M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"
|
|
1518
|
+
}
|
|
1519
|
+
),
|
|
1520
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1521
|
+
"path",
|
|
1522
|
+
{
|
|
1523
|
+
fill: "#34A853",
|
|
1524
|
+
d: "M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"
|
|
1525
|
+
}
|
|
1526
|
+
),
|
|
1527
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { fill: "none", d: "M0 0h48v48H0z" })
|
|
1528
|
+
] }) }),
|
|
1540
1529
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "gsi-material-button-contents", children: "Google" }),
|
|
1541
1530
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { display: "none" }, children: "Google" })
|
|
1542
1531
|
] })
|
|
@@ -1583,6 +1572,8 @@ var AUTH_STATE_MESSAGES = {
|
|
|
1583
1572
|
connecting_wallet: "Connecting wallet\u2026",
|
|
1584
1573
|
wallet_not_installed: "Wallet not installed",
|
|
1585
1574
|
authenticating_wallet: "Signing in with wallet\u2026",
|
|
1575
|
+
creating_passkey: "Waiting for passkey\u2026",
|
|
1576
|
+
deploying_smart_account: "Creating your wallet\u2026",
|
|
1586
1577
|
authenticating: "Authenticating\u2026",
|
|
1587
1578
|
authenticated: "Welcome!",
|
|
1588
1579
|
error: ""
|
|
@@ -1595,6 +1586,8 @@ function authStateToStatus(step) {
|
|
|
1595
1586
|
"opening_oauth",
|
|
1596
1587
|
"connecting_wallet",
|
|
1597
1588
|
"authenticating_wallet",
|
|
1589
|
+
"creating_passkey",
|
|
1590
|
+
"deploying_smart_account",
|
|
1598
1591
|
"authenticating"
|
|
1599
1592
|
];
|
|
1600
1593
|
const success = ["authenticated", "entering_code"];
|
|
@@ -1610,6 +1603,7 @@ function LoginModalTemplate({
|
|
|
1610
1603
|
logoUrl,
|
|
1611
1604
|
emailEnabled,
|
|
1612
1605
|
embeddedWallets,
|
|
1606
|
+
smartWallet = false,
|
|
1613
1607
|
providers,
|
|
1614
1608
|
appName,
|
|
1615
1609
|
email = "",
|
|
@@ -1617,6 +1611,7 @@ function LoginModalTemplate({
|
|
|
1617
1611
|
onEmailSubmit,
|
|
1618
1612
|
onSocialLogin,
|
|
1619
1613
|
onWalletConnect,
|
|
1614
|
+
onSmartWallet,
|
|
1620
1615
|
renderWallets,
|
|
1621
1616
|
authState,
|
|
1622
1617
|
codeInputKey,
|
|
@@ -1730,32 +1725,60 @@ function LoginModalTemplate({
|
|
|
1730
1725
|
enabledSocial.some(([key]) => key === "google") && /* @__PURE__ */ jsxRuntime.jsx(GoogleButton, { disabled: isLoading, onClick: () => onSocialLogin?.("google") }),
|
|
1731
1726
|
enabledSocial.some(([key]) => key === "github") && /* @__PURE__ */ jsxRuntime.jsx(GithubButton, { disabled: isLoading, onClick: () => onSocialLogin?.("github") })
|
|
1732
1727
|
] }),
|
|
1733
|
-
embeddedWallets && /* @__PURE__ */ jsxRuntime.
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1728
|
+
(embeddedWallets || smartWallet) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-wallet-section", children: [
|
|
1729
|
+
embeddedWallets && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1730
|
+
"button",
|
|
1731
|
+
{
|
|
1732
|
+
type: "button",
|
|
1733
|
+
disabled: isLoading,
|
|
1734
|
+
className: "pollar-wallet-entry-btn",
|
|
1735
|
+
onClick: () => setShowWalletPicker(true),
|
|
1736
|
+
children: [
|
|
1737
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1738
|
+
"svg",
|
|
1739
|
+
{
|
|
1740
|
+
width: "18",
|
|
1741
|
+
height: "20",
|
|
1742
|
+
viewBox: "0 0 24 24",
|
|
1743
|
+
fill: "none",
|
|
1744
|
+
stroke: "currentColor",
|
|
1745
|
+
strokeWidth: "2",
|
|
1746
|
+
strokeLinecap: "round",
|
|
1747
|
+
strokeLinejoin: "round",
|
|
1748
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" })
|
|
1749
|
+
}
|
|
1750
|
+
),
|
|
1751
|
+
"Wallet"
|
|
1752
|
+
]
|
|
1753
|
+
}
|
|
1754
|
+
),
|
|
1755
|
+
smartWallet && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1756
|
+
"button",
|
|
1757
|
+
{
|
|
1758
|
+
type: "button",
|
|
1759
|
+
disabled: isLoading,
|
|
1760
|
+
className: "pollar-wallet-entry-btn",
|
|
1761
|
+
onClick: onSmartWallet,
|
|
1762
|
+
children: [
|
|
1763
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1764
|
+
"svg",
|
|
1765
|
+
{
|
|
1766
|
+
width: "18",
|
|
1767
|
+
height: "20",
|
|
1768
|
+
viewBox: "0 0 24 24",
|
|
1769
|
+
fill: "none",
|
|
1770
|
+
stroke: "currentColor",
|
|
1771
|
+
strokeWidth: "2",
|
|
1772
|
+
strokeLinecap: "round",
|
|
1773
|
+
strokeLinejoin: "round",
|
|
1774
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16 8V6a4 4 0 00-8 0v2M5 8h14a1 1 0 011 1v10a1 1 0 01-1 1H5a1 1 0 01-1-1V9a1 1 0 011-1zm7 5v2" })
|
|
1775
|
+
}
|
|
1776
|
+
),
|
|
1777
|
+
"Smart Wallet"
|
|
1778
|
+
]
|
|
1779
|
+
}
|
|
1780
|
+
)
|
|
1781
|
+
] })
|
|
1759
1782
|
] }),
|
|
1760
1783
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1761
1784
|
ModalStatusBanner,
|
|
@@ -1804,6 +1827,7 @@ function LoginModal({ onClose }) {
|
|
|
1804
1827
|
};
|
|
1805
1828
|
}, [getClient]);
|
|
1806
1829
|
const { theme = "light", accentColor = "#005DB4", logoUrl, emailEnabled, embeddedWallets, providers } = styles;
|
|
1830
|
+
const smartWallet = styles.smartWallet ?? true;
|
|
1807
1831
|
function handleClose() {
|
|
1808
1832
|
setEmail("");
|
|
1809
1833
|
getClient().cancelLogin();
|
|
@@ -1820,6 +1844,9 @@ function LoginModal({ onClose }) {
|
|
|
1820
1844
|
function handleWalletConnect(type) {
|
|
1821
1845
|
getClient().loginWallet(type);
|
|
1822
1846
|
}
|
|
1847
|
+
function handleSmartWallet() {
|
|
1848
|
+
getClient().loginSmartWallet();
|
|
1849
|
+
}
|
|
1823
1850
|
function handleVerifyCode(code) {
|
|
1824
1851
|
getClient().verifyEmailCode(code);
|
|
1825
1852
|
}
|
|
@@ -1841,6 +1868,7 @@ function LoginModal({ onClose }) {
|
|
|
1841
1868
|
logoUrl: logoUrl ?? null,
|
|
1842
1869
|
emailEnabled: !!emailEnabled,
|
|
1843
1870
|
embeddedWallets: !!embeddedWallets,
|
|
1871
|
+
smartWallet,
|
|
1844
1872
|
providers: {
|
|
1845
1873
|
google: !!providers?.google,
|
|
1846
1874
|
discord: !!providers?.discord,
|
|
@@ -1854,6 +1882,7 @@ function LoginModal({ onClose }) {
|
|
|
1854
1882
|
onEmailSubmit: handleEmailSubmit,
|
|
1855
1883
|
onSocialLogin: handleSocialLogin,
|
|
1856
1884
|
onWalletConnect: handleWalletConnect,
|
|
1885
|
+
onSmartWallet: handleSmartWallet,
|
|
1857
1886
|
...renderWallets !== void 0 && { renderWallets },
|
|
1858
1887
|
authState,
|
|
1859
1888
|
codeInputKey,
|
|
@@ -3080,18 +3109,16 @@ function SessionsModalTemplate({
|
|
|
3080
3109
|
);
|
|
3081
3110
|
}
|
|
3082
3111
|
function SessionsModal({ onClose }) {
|
|
3083
|
-
const { getClient, styles } = usePollar();
|
|
3112
|
+
const { getClient, styles, sessions } = usePollar();
|
|
3084
3113
|
const { theme = "light", accentColor = "#005DB4" } = styles;
|
|
3085
|
-
const [state, setState] = react.useState({ step: "idle" });
|
|
3086
3114
|
const [revokingFamilyId, setRevokingFamilyId] = react.useState(null);
|
|
3087
3115
|
const [signingOutEverywhere, setSigningOutEverywhere] = react.useState(false);
|
|
3088
|
-
const
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
);
|
|
3116
|
+
const load = react.useCallback(() => {
|
|
3117
|
+
void getClient().fetchSessions();
|
|
3118
|
+
}, [getClient]);
|
|
3119
|
+
react.useEffect(() => {
|
|
3120
|
+
load();
|
|
3121
|
+
}, [load]);
|
|
3095
3122
|
const onCloseRef = react.useRef(onClose);
|
|
3096
3123
|
onCloseRef.current = onClose;
|
|
3097
3124
|
react.useEffect(() => {
|
|
@@ -3099,33 +3126,15 @@ function SessionsModal({ onClose }) {
|
|
|
3099
3126
|
if (authState.step === "idle") onCloseRef.current();
|
|
3100
3127
|
});
|
|
3101
3128
|
}, [getClient]);
|
|
3102
|
-
const load = react.useCallback(async () => {
|
|
3103
|
-
setState({ step: "loading" });
|
|
3104
|
-
try {
|
|
3105
|
-
const sessions = await getClient().listSessions();
|
|
3106
|
-
if (!mountedRef.current) return;
|
|
3107
|
-
setState({ step: "loaded", sessions });
|
|
3108
|
-
} catch (err) {
|
|
3109
|
-
if (!mountedRef.current) return;
|
|
3110
|
-
const message = err instanceof Error ? err.message : "Failed to load sessions";
|
|
3111
|
-
setState({ step: "error", message });
|
|
3112
|
-
}
|
|
3113
|
-
}, [getClient]);
|
|
3114
|
-
react.useEffect(() => {
|
|
3115
|
-
void load();
|
|
3116
|
-
}, [load]);
|
|
3117
3129
|
const handleRevoke = react.useCallback(
|
|
3118
3130
|
async (familyId) => {
|
|
3119
3131
|
setRevokingFamilyId(familyId);
|
|
3120
3132
|
try {
|
|
3121
3133
|
await getClient().revokeSession(familyId);
|
|
3122
|
-
if (!mountedRef.current) return;
|
|
3123
|
-
await load();
|
|
3124
3134
|
} catch {
|
|
3125
|
-
if (!mountedRef.current) return;
|
|
3126
|
-
setState((prev) => prev.step === "loaded" ? { step: "error", message: "Failed to revoke session" } : prev);
|
|
3127
3135
|
} finally {
|
|
3128
|
-
|
|
3136
|
+
setRevokingFamilyId(null);
|
|
3137
|
+
load();
|
|
3129
3138
|
}
|
|
3130
3139
|
},
|
|
3131
3140
|
[getClient, load]
|
|
@@ -3136,7 +3145,6 @@ function SessionsModal({ onClose }) {
|
|
|
3136
3145
|
await getClient().logoutEverywhere();
|
|
3137
3146
|
onClose();
|
|
3138
3147
|
} catch {
|
|
3139
|
-
if (!mountedRef.current) return;
|
|
3140
3148
|
setSigningOutEverywhere(false);
|
|
3141
3149
|
}
|
|
3142
3150
|
}, [getClient, onClose]);
|
|
@@ -3145,10 +3153,10 @@ function SessionsModal({ onClose }) {
|
|
|
3145
3153
|
{
|
|
3146
3154
|
theme,
|
|
3147
3155
|
accentColor,
|
|
3148
|
-
state,
|
|
3156
|
+
state: sessions,
|
|
3149
3157
|
revokingFamilyId,
|
|
3150
3158
|
signingOutEverywhere,
|
|
3151
|
-
onRefresh: () =>
|
|
3159
|
+
onRefresh: () => load(),
|
|
3152
3160
|
onRevoke: (familyId) => void handleRevoke(familyId),
|
|
3153
3161
|
onLogoutEverywhere: () => void handleLogoutEverywhere(),
|
|
3154
3162
|
onClose
|
|
@@ -3562,6 +3570,60 @@ function WalletBalanceModal({ onClose }) {
|
|
|
3562
3570
|
}
|
|
3563
3571
|
) });
|
|
3564
3572
|
}
|
|
3573
|
+
function hexToBase64url(hex) {
|
|
3574
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
3575
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
3576
|
+
let bin = "";
|
|
3577
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
3578
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
3579
|
+
}
|
|
3580
|
+
function randomUserId() {
|
|
3581
|
+
const bytes = new Uint8Array(16);
|
|
3582
|
+
crypto.getRandomValues(bytes);
|
|
3583
|
+
let bin = "";
|
|
3584
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
3585
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
3586
|
+
}
|
|
3587
|
+
var browserPasskeyCeremony = async ({ challenge }) => {
|
|
3588
|
+
const rpId = window.location.hostname;
|
|
3589
|
+
try {
|
|
3590
|
+
const response2 = await browser.startAuthentication({
|
|
3591
|
+
optionsJSON: { challenge, rpId, userVerification: "required" }
|
|
3592
|
+
});
|
|
3593
|
+
return { kind: "login", response: response2 };
|
|
3594
|
+
} catch {
|
|
3595
|
+
}
|
|
3596
|
+
const userId = randomUserId();
|
|
3597
|
+
const response = await browser.startRegistration({
|
|
3598
|
+
optionsJSON: {
|
|
3599
|
+
challenge,
|
|
3600
|
+
rp: { id: rpId, name: rpId },
|
|
3601
|
+
user: { id: userId, name: "Smart Wallet", displayName: "Smart Wallet" },
|
|
3602
|
+
// ES256 (secp256r1) — the curve the on-chain WebAuthn verifier expects.
|
|
3603
|
+
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
|
|
3604
|
+
authenticatorSelection: { residentKey: "required", userVerification: "required" },
|
|
3605
|
+
attestation: "none",
|
|
3606
|
+
timeout: 6e4
|
|
3607
|
+
}
|
|
3608
|
+
});
|
|
3609
|
+
return { kind: "register", response };
|
|
3610
|
+
};
|
|
3611
|
+
var browserPasskeySigner = async ({ credentialId, challenge }) => {
|
|
3612
|
+
const rpId = window.location.hostname;
|
|
3613
|
+
const { response } = await browser.startAuthentication({
|
|
3614
|
+
optionsJSON: {
|
|
3615
|
+
challenge: hexToBase64url(challenge),
|
|
3616
|
+
rpId,
|
|
3617
|
+
allowCredentials: [{ id: credentialId, type: "public-key" }],
|
|
3618
|
+
userVerification: "required"
|
|
3619
|
+
}
|
|
3620
|
+
});
|
|
3621
|
+
return {
|
|
3622
|
+
authenticatorData: response.authenticatorData,
|
|
3623
|
+
clientDataJSON: response.clientDataJSON,
|
|
3624
|
+
signature: response.signature
|
|
3625
|
+
};
|
|
3626
|
+
};
|
|
3565
3627
|
var DEFAULT_APP_CONFIG = {
|
|
3566
3628
|
application: { name: "" },
|
|
3567
3629
|
styles: {}
|
|
@@ -3569,7 +3631,7 @@ var DEFAULT_APP_CONFIG = {
|
|
|
3569
3631
|
function sessionsEqual(a, b) {
|
|
3570
3632
|
if (a === b) return true;
|
|
3571
3633
|
if (!a || !b) return false;
|
|
3572
|
-
return a.clientSessionId === b.clientSessionId && a.userId === b.userId && a.status === b.status && a.token?.accessToken === b.token?.accessToken && a.token?.refreshToken === b.token?.refreshToken && a.token?.expiresAt === b.token?.expiresAt && a.wallet?.
|
|
3634
|
+
return a.clientSessionId === b.clientSessionId && a.userId === b.userId && a.status === b.status && a.token?.accessToken === b.token?.accessToken && a.token?.refreshToken === b.token?.refreshToken && a.token?.expiresAt === b.token?.expiresAt && a.wallet?.address === b.wallet?.address;
|
|
3573
3635
|
}
|
|
3574
3636
|
var PollarContext = react.createContext(null);
|
|
3575
3637
|
function PollarProvider({
|
|
@@ -3580,11 +3642,15 @@ function PollarProvider({
|
|
|
3580
3642
|
onStorageDegrade,
|
|
3581
3643
|
children
|
|
3582
3644
|
}) {
|
|
3583
|
-
const [pollarClient] = react.useState(
|
|
3645
|
+
const [pollarClient] = react.useState(
|
|
3646
|
+
() => client instanceof core.PollarClient ? client : new core.PollarClient({ passkey: browserPasskeyCeremony, passkeySign: browserPasskeySigner, ...client })
|
|
3647
|
+
);
|
|
3584
3648
|
const [networkState, setNetworkState] = react.useState(() => pollarClient.getNetworkState());
|
|
3585
3649
|
const [sessionState, setSessionState] = react.useState(null);
|
|
3650
|
+
const [verified, setVerified] = react.useState(false);
|
|
3586
3651
|
const [transaction, setTransaction] = react.useState({ step: "idle" });
|
|
3587
3652
|
const [txHistory, setTxHistory] = react.useState({ step: "idle" });
|
|
3653
|
+
const [sessions, setSessions] = react.useState({ step: "idle" });
|
|
3588
3654
|
const [walletBalance, setWalletBalance] = react.useState({ step: "idle" });
|
|
3589
3655
|
const [resolvedConfig, setResolvedConfig] = react.useState(() => appConfigProp ?? DEFAULT_APP_CONFIG);
|
|
3590
3656
|
react.useEffect(() => {
|
|
@@ -3593,6 +3659,9 @@ function PollarProvider({
|
|
|
3593
3659
|
react.useEffect(() => {
|
|
3594
3660
|
return pollarClient.onTxHistoryStateChange(setTxHistory);
|
|
3595
3661
|
}, [pollarClient]);
|
|
3662
|
+
react.useEffect(() => {
|
|
3663
|
+
return pollarClient.onSessionsStateChange(setSessions);
|
|
3664
|
+
}, [pollarClient]);
|
|
3596
3665
|
react.useEffect(() => {
|
|
3597
3666
|
return pollarClient.onWalletBalanceStateChange(setWalletBalance);
|
|
3598
3667
|
}, [pollarClient]);
|
|
@@ -3609,8 +3678,10 @@ function PollarProvider({
|
|
|
3609
3678
|
return pollarClient.onAuthStateChange((authState) => {
|
|
3610
3679
|
if (authState.step === "authenticated") {
|
|
3611
3680
|
setSessionState((prev) => sessionsEqual(prev, authState.session) ? prev : authState.session);
|
|
3681
|
+
setVerified(authState.verified);
|
|
3612
3682
|
} else if (authState.step === "idle") {
|
|
3613
3683
|
setSessionState(null);
|
|
3684
|
+
setVerified(false);
|
|
3614
3685
|
}
|
|
3615
3686
|
});
|
|
3616
3687
|
}, [pollarClient]);
|
|
@@ -3638,9 +3709,9 @@ function PollarProvider({
|
|
|
3638
3709
|
const [receiveModalOpen, setReceiveModalOpen] = react.useState(false);
|
|
3639
3710
|
const [sessionsModalOpen, setSessionsModalOpen] = react.useState(false);
|
|
3640
3711
|
const [distributionRulesModalOpen, setDistributionRulesModalOpen] = react.useState(false);
|
|
3641
|
-
const walletAddress = sessionState?.wallet?.
|
|
3712
|
+
const walletAddress = sessionState?.wallet?.address || "";
|
|
3642
3713
|
const getClient = react.useCallback(() => pollarClient, [pollarClient]);
|
|
3643
|
-
const refreshWalletBalance = react.useCallback(() => pollarClient.refreshBalance(
|
|
3714
|
+
const refreshWalletBalance = react.useCallback(() => pollarClient.refreshBalance(), [pollarClient, walletAddress]);
|
|
3644
3715
|
const renderWallets = ui?.renderWallets;
|
|
3645
3716
|
const contextValue = react.useMemo(() => {
|
|
3646
3717
|
const styles = resolvedConfig.styles ?? {};
|
|
@@ -3648,6 +3719,7 @@ function PollarProvider({
|
|
|
3648
3719
|
// session
|
|
3649
3720
|
walletAddress,
|
|
3650
3721
|
isAuthenticated: !!walletAddress,
|
|
3722
|
+
verified,
|
|
3651
3723
|
walletType: pollarClient.getWalletType(),
|
|
3652
3724
|
// client
|
|
3653
3725
|
getClient,
|
|
@@ -3675,6 +3747,7 @@ function PollarProvider({
|
|
|
3675
3747
|
openSendModal: () => setSendModalOpen(true),
|
|
3676
3748
|
openReceiveModal: () => setReceiveModalOpen(true),
|
|
3677
3749
|
// sessions
|
|
3750
|
+
sessions,
|
|
3678
3751
|
openSessionsModal: () => setSessionsModalOpen(true),
|
|
3679
3752
|
// distribution
|
|
3680
3753
|
openDistributionRulesModal: () => setDistributionRulesModalOpen(true),
|
|
@@ -3696,10 +3769,12 @@ function PollarProvider({
|
|
|
3696
3769
|
};
|
|
3697
3770
|
}, [
|
|
3698
3771
|
walletAddress,
|
|
3772
|
+
verified,
|
|
3699
3773
|
pollarClient,
|
|
3700
3774
|
getClient,
|
|
3701
3775
|
transaction,
|
|
3702
3776
|
txHistory,
|
|
3777
|
+
sessions,
|
|
3703
3778
|
walletBalance,
|
|
3704
3779
|
refreshWalletBalance,
|
|
3705
3780
|
networkState,
|
|
@@ -3779,6 +3854,10 @@ function WalletButtonTemplate({
|
|
|
3779
3854
|
onTxHistory,
|
|
3780
3855
|
onSend,
|
|
3781
3856
|
onReceive,
|
|
3857
|
+
onSessions,
|
|
3858
|
+
onKyc,
|
|
3859
|
+
onRamp,
|
|
3860
|
+
onDistributionRules,
|
|
3782
3861
|
onLogout,
|
|
3783
3862
|
onLogin
|
|
3784
3863
|
}) {
|
|
@@ -3938,6 +4017,94 @@ function WalletButtonTemplate({
|
|
|
3938
4017
|
"Transaction history"
|
|
3939
4018
|
] }),
|
|
3940
4019
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "wallet-dropdown-divider" }),
|
|
4020
|
+
/* @__PURE__ */ jsxRuntime.jsxs("button", { className: "wallet-dropdown-item", style: { color: itemColor }, onClick: onRamp, children: [
|
|
4021
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4022
|
+
"svg",
|
|
4023
|
+
{
|
|
4024
|
+
width: "14",
|
|
4025
|
+
height: "14",
|
|
4026
|
+
viewBox: "0 0 24 24",
|
|
4027
|
+
fill: "none",
|
|
4028
|
+
stroke: "currentColor",
|
|
4029
|
+
strokeWidth: "2",
|
|
4030
|
+
strokeLinecap: "round",
|
|
4031
|
+
strokeLinejoin: "round",
|
|
4032
|
+
children: [
|
|
4033
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "17 1 21 5 17 9" }),
|
|
4034
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 11V9a4 4 0 0 1 4-4h14" }),
|
|
4035
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "7 23 3 19 7 15" }),
|
|
4036
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 13v2a4 4 0 0 1-4 4H3" })
|
|
4037
|
+
]
|
|
4038
|
+
}
|
|
4039
|
+
),
|
|
4040
|
+
"Buy / Sell"
|
|
4041
|
+
] }),
|
|
4042
|
+
/* @__PURE__ */ jsxRuntime.jsxs("button", { className: "wallet-dropdown-item", style: { color: itemColor }, onClick: onKyc, children: [
|
|
4043
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4044
|
+
"svg",
|
|
4045
|
+
{
|
|
4046
|
+
width: "14",
|
|
4047
|
+
height: "14",
|
|
4048
|
+
viewBox: "0 0 24 24",
|
|
4049
|
+
fill: "none",
|
|
4050
|
+
stroke: "currentColor",
|
|
4051
|
+
strokeWidth: "2",
|
|
4052
|
+
strokeLinecap: "round",
|
|
4053
|
+
strokeLinejoin: "round",
|
|
4054
|
+
children: [
|
|
4055
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z" }),
|
|
4056
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 21v-1a6 6 0 0 1 6-6h2" }),
|
|
4057
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "16 11 18 13 22 9" })
|
|
4058
|
+
]
|
|
4059
|
+
}
|
|
4060
|
+
),
|
|
4061
|
+
"Identity verification"
|
|
4062
|
+
] }),
|
|
4063
|
+
/* @__PURE__ */ jsxRuntime.jsxs("button", { className: "wallet-dropdown-item", style: { color: itemColor }, onClick: onDistributionRules, children: [
|
|
4064
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4065
|
+
"svg",
|
|
4066
|
+
{
|
|
4067
|
+
width: "14",
|
|
4068
|
+
height: "14",
|
|
4069
|
+
viewBox: "0 0 24 24",
|
|
4070
|
+
fill: "none",
|
|
4071
|
+
stroke: "currentColor",
|
|
4072
|
+
strokeWidth: "2",
|
|
4073
|
+
strokeLinecap: "round",
|
|
4074
|
+
strokeLinejoin: "round",
|
|
4075
|
+
children: [
|
|
4076
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "18", cy: "5", r: "3" }),
|
|
4077
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "6", cy: "12", r: "3" }),
|
|
4078
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "18", cy: "19", r: "3" }),
|
|
4079
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "8.59", y1: "13.51", x2: "15.42", y2: "17.49" }),
|
|
4080
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "15.41", y1: "6.51", x2: "8.59", y2: "10.49" })
|
|
4081
|
+
]
|
|
4082
|
+
}
|
|
4083
|
+
),
|
|
4084
|
+
"Distribution rules"
|
|
4085
|
+
] }),
|
|
4086
|
+
/* @__PURE__ */ jsxRuntime.jsxs("button", { className: "wallet-dropdown-item", style: { color: itemColor }, onClick: onSessions, children: [
|
|
4087
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4088
|
+
"svg",
|
|
4089
|
+
{
|
|
4090
|
+
width: "14",
|
|
4091
|
+
height: "14",
|
|
4092
|
+
viewBox: "0 0 24 24",
|
|
4093
|
+
fill: "none",
|
|
4094
|
+
stroke: "currentColor",
|
|
4095
|
+
strokeWidth: "2",
|
|
4096
|
+
strokeLinecap: "round",
|
|
4097
|
+
strokeLinejoin: "round",
|
|
4098
|
+
children: [
|
|
4099
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "2", y: "3", width: "20", height: "14", rx: "2", ry: "2" }),
|
|
4100
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "8", y1: "21", x2: "16", y2: "21" }),
|
|
4101
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "17", x2: "12", y2: "21" })
|
|
4102
|
+
]
|
|
4103
|
+
}
|
|
4104
|
+
),
|
|
4105
|
+
"Active sessions"
|
|
4106
|
+
] }),
|
|
4107
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "wallet-dropdown-divider" }),
|
|
3941
4108
|
/* @__PURE__ */ jsxRuntime.jsxs("button", { className: "wallet-dropdown-item danger", onClick: onLogout, children: [
|
|
3942
4109
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3943
4110
|
"svg",
|
|
@@ -3972,6 +4139,10 @@ function WalletButton() {
|
|
|
3972
4139
|
openWalletBalanceModal,
|
|
3973
4140
|
openSendModal,
|
|
3974
4141
|
openReceiveModal,
|
|
4142
|
+
openSessionsModal,
|
|
4143
|
+
openKycModal,
|
|
4144
|
+
openRampModal,
|
|
4145
|
+
openDistributionRulesModal,
|
|
3975
4146
|
tx: transaction,
|
|
3976
4147
|
walletType
|
|
3977
4148
|
} = usePollar();
|
|
@@ -4030,6 +4201,22 @@ function WalletButton() {
|
|
|
4030
4201
|
setOpen(false);
|
|
4031
4202
|
openReceiveModal();
|
|
4032
4203
|
}
|
|
4204
|
+
function handleSessions() {
|
|
4205
|
+
setOpen(false);
|
|
4206
|
+
openSessionsModal();
|
|
4207
|
+
}
|
|
4208
|
+
function handleKyc() {
|
|
4209
|
+
setOpen(false);
|
|
4210
|
+
openKycModal();
|
|
4211
|
+
}
|
|
4212
|
+
function handleRamp() {
|
|
4213
|
+
setOpen(false);
|
|
4214
|
+
openRampModal();
|
|
4215
|
+
}
|
|
4216
|
+
function handleDistributionRules() {
|
|
4217
|
+
setOpen(false);
|
|
4218
|
+
openDistributionRulesModal();
|
|
4219
|
+
}
|
|
4033
4220
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4034
4221
|
WalletButtonTemplate,
|
|
4035
4222
|
{
|
|
@@ -4049,6 +4236,10 @@ function WalletButton() {
|
|
|
4049
4236
|
onTxHistory: handleTxHistory,
|
|
4050
4237
|
onSend: handleSend,
|
|
4051
4238
|
onReceive: handleReceive,
|
|
4239
|
+
onSessions: handleSessions,
|
|
4240
|
+
onKyc: handleKyc,
|
|
4241
|
+
onRamp: handleRamp,
|
|
4242
|
+
onDistributionRules: handleDistributionRules,
|
|
4052
4243
|
onLogout: handleLogout,
|
|
4053
4244
|
onLogin: openLoginModal
|
|
4054
4245
|
}
|
|
@@ -4077,6 +4268,7 @@ exports.TxStatusView = TxStatusView;
|
|
|
4077
4268
|
exports.WalletBalanceModal = WalletBalanceModal;
|
|
4078
4269
|
exports.WalletBalanceModalTemplate = WalletBalanceModalTemplate;
|
|
4079
4270
|
exports.WalletButton = WalletButton;
|
|
4271
|
+
exports.WalletButtonTemplate = WalletButtonTemplate;
|
|
4080
4272
|
exports.createPollarAdapterHook = createPollarAdapterHook;
|
|
4081
4273
|
exports.usePollar = usePollar;
|
|
4082
4274
|
//# sourceMappingURL=index.js.map
|