@pollar/react 0.11.0 → 0.11.1-rc.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.
package/dist/index.mjs CHANGED
@@ -1033,7 +1033,7 @@ var PollarModalFooter = () => {
1033
1033
  /* @__PURE__ */ jsx("span", { className: "pollar-footer-name", children: "Pollar" }),
1034
1034
  /* @__PURE__ */ jsxs("span", { className: "pollar-footer-version", children: [
1035
1035
  "v",
1036
- "0.11.0"
1036
+ "0.11.1-rc.1"
1037
1037
  ] })
1038
1038
  ] })
1039
1039
  ] });
@@ -2052,6 +2052,29 @@ function authStateToStatus(step) {
2052
2052
  if (error.includes(step)) return "ERROR";
2053
2053
  return "NONE";
2054
2054
  }
2055
+ function buildModalCssVars(theme, accentColor) {
2056
+ const isDark = theme === "dark";
2057
+ return {
2058
+ "--pollar-accent": accentColor,
2059
+ "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
2060
+ "--pollar-border": isDark ? "#374151" : "#e5e7eb",
2061
+ "--pollar-text": isDark ? "#ffffff" : "#111827",
2062
+ "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
2063
+ "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
2064
+ "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
2065
+ "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
2066
+ "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
2067
+ "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
2068
+ "--pollar-buttons-border-radius": "6px",
2069
+ "--pollar-buttons-height": "44px",
2070
+ "--pollar-input-height": "44px",
2071
+ "--pollar-input-border-radius": "0.5rem",
2072
+ "--pollar-card-border-radius": "10px",
2073
+ "--pollar-modal-padding": "2rem",
2074
+ "--pollar-modal-heading-size": "1.375rem",
2075
+ "--pollar-modal-subtitle-size": "0.9rem"
2076
+ };
2077
+ }
2055
2078
  function LoginModalTemplate({
2056
2079
  theme,
2057
2080
  accentColor,
@@ -2078,7 +2101,6 @@ function LoginModalTemplate({
2078
2101
  }) {
2079
2102
  const [showPasskeyChooser, setShowPasskeyChooser] = useState(false);
2080
2103
  const [activeGroup, setActiveGroup] = useState(null);
2081
- const isDark = theme === "dark";
2082
2104
  const enabledSocial = Object.entries(providers).filter(([, enabled]) => enabled);
2083
2105
  const rootAdapters = walletAdapters.filter((a) => !a.meta.group);
2084
2106
  const walletGroups = walletAdapters.filter((a) => a.meta.group).reduce((acc, a) => {
@@ -2089,26 +2111,7 @@ function LoginModalTemplate({
2089
2111
  return acc;
2090
2112
  }, []);
2091
2113
  const activeGroupAdapters = walletGroups.find((g) => g.label === activeGroup)?.adapters ?? [];
2092
- const cssVars = {
2093
- "--pollar-accent": accentColor,
2094
- "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
2095
- "--pollar-border": isDark ? "#374151" : "#e5e7eb",
2096
- "--pollar-text": isDark ? "#ffffff" : "#111827",
2097
- "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
2098
- "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
2099
- "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
2100
- "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
2101
- "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
2102
- "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
2103
- "--pollar-buttons-border-radius": "6px",
2104
- "--pollar-buttons-height": "44px",
2105
- "--pollar-input-height": "44px",
2106
- "--pollar-input-border-radius": "0.5rem",
2107
- "--pollar-card-border-radius": "10px",
2108
- "--pollar-modal-padding": "2rem",
2109
- "--pollar-modal-heading-size": "1.375rem",
2110
- "--pollar-modal-subtitle-size": "0.9rem"
2111
- };
2114
+ const cssVars = buildModalCssVars(theme, accentColor);
2112
2115
  const status = authStateToStatus(authState.step);
2113
2116
  const isLoading = status === "LOADING";
2114
2117
  const isEmailCodeError = authState.step === "error" && (authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_EXPIRED || authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_INVALID);
@@ -2283,6 +2286,46 @@ function LoginModalTemplate({
2283
2286
  /* @__PURE__ */ jsx(PollarModalFooter, {})
2284
2287
  ] });
2285
2288
  }
2289
+ function LoginModalStatus({
2290
+ status,
2291
+ theme,
2292
+ accentColor,
2293
+ logoUrl,
2294
+ appName,
2295
+ onRetry,
2296
+ onCancel
2297
+ }) {
2298
+ const cssVars = buildModalCssVars(theme, accentColor);
2299
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-modal-card pollar-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
2300
+ /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-close-btn", onClick: onCancel, "aria-label": "Close", children: /* @__PURE__ */ jsx(
2301
+ "svg",
2302
+ {
2303
+ width: "18",
2304
+ height: "18",
2305
+ viewBox: "0 0 24 24",
2306
+ fill: "none",
2307
+ stroke: "currentColor",
2308
+ strokeWidth: "2.5",
2309
+ strokeLinecap: "round",
2310
+ strokeLinejoin: "round",
2311
+ children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" })
2312
+ }
2313
+ ) }),
2314
+ /* @__PURE__ */ jsxs("div", { className: "pollar-header", children: [
2315
+ /* @__PURE__ */ jsx("div", { className: "pollar-logo-wrap", children: /* @__PURE__ */ jsx("img", { src: logoUrl ?? LOGO_POLLAR, alt: "Logo", className: "pollar-logo" }) }),
2316
+ /* @__PURE__ */ jsx("h2", { className: "pollar-title", children: appName }),
2317
+ /* @__PURE__ */ jsx("p", { className: "pollar-subtitle", children: "Log in or sign up" })
2318
+ ] }),
2319
+ status === "loading" ? /* @__PURE__ */ jsxs("div", { className: "pollar-loading-block", children: [
2320
+ /* @__PURE__ */ jsx("div", { className: "pollar-spinner" }),
2321
+ /* @__PURE__ */ jsx("span", { children: "Loading..." })
2322
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "pollar-wallet-section", children: [
2323
+ /* @__PURE__ */ jsx("p", { className: "pollar-modal-error", children: "Could not load sign-in options. Check your connection and try again." }),
2324
+ /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: onRetry, children: "Try again" })
2325
+ ] }),
2326
+ /* @__PURE__ */ jsx(PollarModalFooter, {})
2327
+ ] });
2328
+ }
2286
2329
  function PrivyLoginSubmodal({
2287
2330
  adapter,
2288
2331
  theme,
@@ -2439,7 +2482,7 @@ function PrivyLoginSubmodal({
2439
2482
  }
2440
2483
  function LoginModal({ onClose }) {
2441
2484
  const [email, setEmail] = useState("");
2442
- const { getClient, styles, appConfig: config } = usePollar();
2485
+ const { getClient, styles, appConfig: config, configStatus, retryConfig } = usePollar();
2443
2486
  const [authState, setAuthState] = useState(() => getClient().getAuthState());
2444
2487
  const walletAdapters = useMemo(() => getClient().listWalletAdapters(), [getClient]);
2445
2488
  const [codeInputKey, setCodeInputKey] = useState(0);
@@ -2525,7 +2568,18 @@ function LoginModal({ onClose }) {
2525
2568
  getClient().login({ provider });
2526
2569
  }
2527
2570
  }
2528
- return /* @__PURE__ */ jsx("div", { className: "pollar-overlay", onClick: handleClose, children: interactiveAdapter ? /* @__PURE__ */ jsx(
2571
+ return /* @__PURE__ */ jsx("div", { className: "pollar-overlay", onClick: handleClose, children: configStatus !== "ready" ? /* @__PURE__ */ jsx(
2572
+ LoginModalStatus,
2573
+ {
2574
+ status: configStatus === "error" ? "error" : "loading",
2575
+ theme,
2576
+ accentColor,
2577
+ logoUrl: logoUrl ?? null,
2578
+ appName: config.application?.name ?? "Pollar",
2579
+ onRetry: retryConfig,
2580
+ onCancel: handleClose
2581
+ }
2582
+ ) : interactiveAdapter ? /* @__PURE__ */ jsx(
2529
2583
  PrivyLoginSubmodal,
2530
2584
  {
2531
2585
  adapter: interactiveAdapter,
@@ -5861,6 +5915,11 @@ function PollarProvider({
5861
5915
  const [walletBalance, setWalletBalance] = useState({ step: "idle" });
5862
5916
  const [enabledAssets, setEnabledAssets] = useState({ step: "idle" });
5863
5917
  const [resolvedConfig, setResolvedConfig] = useState(() => appConfigProp ?? DEFAULT_APP_CONFIG);
5918
+ const [configStatus, setConfigStatus] = useState(
5919
+ appConfigProp !== void 0 ? "ready" : "loading"
5920
+ );
5921
+ const [configRetry, setConfigRetry] = useState(0);
5922
+ const retryConfig = useCallback(() => setConfigRetry((n) => n + 1), []);
5864
5923
  useEffect(() => {
5865
5924
  return pollarClient.onTransactionStateChange(setTransaction);
5866
5925
  }, [pollarClient]);
@@ -5924,18 +5983,29 @@ function PollarProvider({
5924
5983
  setModalErrorLogger(pollarClient.getLogger());
5925
5984
  }, [pollarClient]);
5926
5985
  useEffect(() => {
5927
- if (appConfigProp !== void 0) return;
5986
+ if (appConfigProp !== void 0) {
5987
+ setConfigStatus("ready");
5988
+ return;
5989
+ }
5928
5990
  let cancelled = false;
5991
+ setConfigStatus("loading");
5929
5992
  pollarClient.getAppConfig().then((fetched) => {
5930
- if (cancelled || !fetched) return;
5993
+ if (cancelled) return;
5994
+ if (!fetched) {
5995
+ setConfigStatus("error");
5996
+ return;
5997
+ }
5931
5998
  setResolvedConfig(fetched);
5999
+ setConfigStatus("ready");
5932
6000
  }).catch((err) => {
6001
+ if (cancelled) return;
5933
6002
  pollarClient.getLogger().error("[PollarProvider] getAppConfig failed", err);
6003
+ setConfigStatus("error");
5934
6004
  });
5935
6005
  return () => {
5936
6006
  cancelled = true;
5937
6007
  };
5938
- }, [pollarClient, appConfigProp]);
6008
+ }, [pollarClient, appConfigProp, configRetry]);
5939
6009
  const [loginModalOpen, setLoginModalOpen] = useState(false);
5940
6010
  const [transactionModalOpen, setTransactionModalOpen] = useState(false);
5941
6011
  const [kycModalOpen, setKycModalOpen] = useState(false);
@@ -6037,6 +6107,8 @@ function PollarProvider({
6037
6107
  // config
6038
6108
  appConfig: resolvedConfig,
6039
6109
  styles,
6110
+ configStatus,
6111
+ retryConfig,
6040
6112
  adapters
6041
6113
  };
6042
6114
  }, [
@@ -6053,6 +6125,8 @@ function PollarProvider({
6053
6125
  refreshAssets,
6054
6126
  networkState,
6055
6127
  resolvedConfig,
6128
+ configStatus,
6129
+ retryConfig,
6056
6130
  adapters
6057
6131
  ]);
6058
6132
  return /* @__PURE__ */ jsxs(PollarContext.Provider, { value: contextValue, children: [