@pollar/react 0.5.0 → 0.5.3

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
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { PollarClient, StellarClient, AUTH_ERROR_CODES, WalletType } from '@pollar/core';
2
+ import { AUTH_ERROR_CODES, WalletType, PollarClient } from '@pollar/core';
3
3
  import { createContext, useState, useEffect, useMemo, useContext, useRef, Component } from 'react';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
5
 
@@ -7,7 +7,6 @@ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
7
7
 
8
8
  // src/constants.ts
9
9
  var LOGO_POLLAR = "https://pollar.xyz/assets/logo_pollar.png";
10
- var LOGO_GITHUB = "https://pollar.xyz/assets/GitHub_Invertocat_White.png";
11
10
  var LOGO_FREIGHTER = "https://pollar.xyz/assets/logo_freighter.png";
12
11
  var LOGO_ALBEDO = "https://pollar.xyz/assets/logo_albedo.svg";
13
12
  var ModalErrorBoundary = class extends Component {
@@ -37,7 +36,7 @@ var PollarModalFooter = () => {
37
36
  /* @__PURE__ */ jsx("span", { className: "pollar-footer-name", children: "Pollar" }),
38
37
  /* @__PURE__ */ jsxs("span", { className: "pollar-footer-version", children: [
39
38
  "v",
40
- "0.4.5"
39
+ "0.5.3"
41
40
  ] })
42
41
  ] })
43
42
  ] });
@@ -53,7 +52,7 @@ function ModalStatusBanner({ message, status, onCancel, onRetry }) {
53
52
  ] }) : status === "SUCCESS" ? /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: [
54
53
  /* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "7", fill: "currentColor" }),
55
54
  /* @__PURE__ */ jsx("path", { d: "M3.5 7l2.5 2.5 4.5-5", stroke: "white", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
56
- ] }) : status === "LOADING" ? /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "5.5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeDasharray: "22 10" }) }) : null;
55
+ ] }) : status === "LOADING" ? /* @__PURE__ */ jsx(Fragment, {}) : null;
57
56
  return /* @__PURE__ */ jsxs("div", { className: "pollar-status", "data-kind": status, children: [
58
57
  icon,
59
58
  /* @__PURE__ */ jsx("span", { children: message }),
@@ -97,15 +96,25 @@ function KycModalTemplate({
97
96
  const isDark = theme === "dark";
98
97
  const cssVars = {
99
98
  "--pollar-accent": accentColor,
100
- "--pollar-buttons-border-radius": "6px",
101
- "--pollar-buttons-height": "44px",
102
99
  "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
103
100
  "--pollar-border": isDark ? "#374151" : "#e5e7eb",
104
101
  "--pollar-text": isDark ? "#ffffff" : "#111827",
105
102
  "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
106
- "--pollar-input-bg": isDark ? "#374151" : "#f9fafb"
103
+ "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
104
+ "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
105
+ "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
106
+ "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
107
+ "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
108
+ "--pollar-buttons-border-radius": "6px",
109
+ "--pollar-buttons-height": "44px",
110
+ "--pollar-input-height": "44px",
111
+ "--pollar-input-border-radius": "0.5rem",
112
+ "--pollar-card-border-radius": "10px",
113
+ "--pollar-modal-padding": "2rem",
114
+ "--pollar-modal-heading-size": "1.375rem",
115
+ "--pollar-modal-subtitle-size": "0.9rem"
107
116
  };
108
- return /* @__PURE__ */ jsxs("div", { className: "pollar-kyc-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
117
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-modal-card pollar-kyc-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
109
118
  /* @__PURE__ */ jsxs("div", { className: "pollar-kyc-header", children: [
110
119
  /* @__PURE__ */ jsx("h2", { className: "pollar-kyc-title", children: "Identity verification" }),
111
120
  /* @__PURE__ */ jsxs("p", { className: "pollar-kyc-subtitle", children: [
@@ -264,8 +273,8 @@ function EmailCodeInput({ email, onSubmit }) {
264
273
  }
265
274
  var GithubButton = ({ disabled, onClick }) => {
266
275
  return /* @__PURE__ */ jsxs("button", { className: "github-button", disabled, onClick, children: [
267
- /* @__PURE__ */ jsx("img", { src: LOGO_GITHUB, alt: "GitHub", className: "github-button-icon" }),
268
- /* @__PURE__ */ jsx("span", { className: "github-button-contents", children: "Continue with GitHub" })
276
+ /* @__PURE__ */ jsx("svg", { className: "github-button-icon", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { fillRule: "evenodd", d: "M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z", clipRule: "evenodd" }) }),
277
+ /* @__PURE__ */ jsx("span", { className: "github-button-contents", children: "GitHub" })
269
278
  ] });
270
279
  };
271
280
  var GoogleButton = ({ disabled, onClick }) => {
@@ -312,8 +321,8 @@ var GoogleButton = ({ disabled, onClick }) => {
312
321
  ]
313
322
  }
314
323
  ) }),
315
- /* @__PURE__ */ jsx("span", { className: "gsi-material-button-contents", children: "Continue with Google" }),
316
- /* @__PURE__ */ jsx("span", { style: { display: "none" }, children: "Continue with Google" })
324
+ /* @__PURE__ */ jsx("span", { className: "gsi-material-button-contents", children: "Google" }),
325
+ /* @__PURE__ */ jsx("span", { style: { display: "none" }, children: "Google" })
317
326
  ] })
318
327
  ] });
319
328
  };
@@ -370,36 +379,76 @@ function LoginModalTemplate({
370
379
  onCancel,
371
380
  onRetry
372
381
  }) {
382
+ const [showWalletPicker, setShowWalletPicker] = useState(false);
373
383
  const isDark = theme === "dark";
374
384
  const enabledSocial = Object.entries(providers).filter(([, enabled]) => enabled);
375
385
  const cssVars = {
376
386
  "--pollar-accent": accentColor,
377
- "--pollar-buttons-border-radius": "6px",
378
- "--pollar-buttons-height": "44px",
379
387
  "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
380
388
  "--pollar-border": isDark ? "#374151" : "#e5e7eb",
381
389
  "--pollar-text": isDark ? "#ffffff" : "#111827",
382
390
  "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
383
- "--pollar-input-bg": isDark ? "#374151" : "#ffffff",
391
+ "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
384
392
  "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
385
393
  "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
386
- "--pollar-error-text": isDark ? "#f87171" : "#dc2626"
394
+ "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
395
+ "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
396
+ "--pollar-buttons-border-radius": "6px",
397
+ "--pollar-buttons-height": "44px",
398
+ "--pollar-input-height": "44px",
399
+ "--pollar-input-border-radius": "0.5rem",
400
+ "--pollar-card-border-radius": "10px",
401
+ "--pollar-modal-padding": "2rem",
402
+ "--pollar-modal-heading-size": "1.375rem",
403
+ "--pollar-modal-subtitle-size": "0.9rem"
387
404
  };
388
405
  const status = authStateToStatus(authState.step);
389
406
  const isLoading = status === "LOADING";
390
407
  const isEmailCodeError = authState.step === "error" && (authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_EXPIRED || authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_INVALID);
391
408
  const awaitingEmailCode = authState.step === "entering_code" || authState.step === "verifying_email_code" || isEmailCodeError;
392
409
  const statusMessage = authState.step === "error" ? authState.message : AUTH_STATE_MESSAGES[authState.step];
393
- return /* @__PURE__ */ jsxs("div", { className: "pollar-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
410
+ const BackButton = ({ onClick }) => /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-back-btn", onClick, "aria-label": "Back", children: /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("path", { d: "M15 19l-7-7 7-7" }) }) });
411
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-modal-card pollar-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
412
+ /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-close-btn", onClick: onCancel, "aria-label": "Close", children: /* @__PURE__ */ jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) }) }),
394
413
  /* @__PURE__ */ jsxs("div", { className: "pollar-header", children: [
395
414
  /* @__PURE__ */ jsx("div", { className: "pollar-logo-wrap", children: /* @__PURE__ */ jsx("img", { src: logoUrl ?? LOGO_POLLAR, alt: "Logo", className: "pollar-logo" }) }),
396
415
  /* @__PURE__ */ jsx("h2", { className: "pollar-title", children: appName }),
397
416
  /* @__PURE__ */ jsx("p", { className: "pollar-subtitle", children: "Log in or sign up" })
398
417
  ] }),
399
418
  awaitingEmailCode ? /* @__PURE__ */ jsxs(Fragment, { children: [
400
- /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-back-btn", onClick: onBack, children: "\u2190 Back" }),
419
+ /* @__PURE__ */ jsx(BackButton, { onClick: onBack }),
401
420
  /* @__PURE__ */ jsx(EmailCodeInput, { email, onSubmit: onCodeSubmit ?? (() => {
402
421
  }) }, codeInputKey)
422
+ ] }) : showWalletPicker ? /* @__PURE__ */ jsxs(Fragment, { children: [
423
+ /* @__PURE__ */ jsx(BackButton, { onClick: () => setShowWalletPicker(false) }),
424
+ /* @__PURE__ */ jsxs("div", { className: "pollar-wallet-list", children: [
425
+ /* @__PURE__ */ jsxs(
426
+ "button",
427
+ {
428
+ type: "button",
429
+ disabled: isLoading,
430
+ className: "pollar-wallet-list-btn",
431
+ onClick: onFreighterConnect,
432
+ children: [
433
+ /* @__PURE__ */ jsx("img", { src: LOGO_FREIGHTER, alt: "Freighter", className: "pollar-wallet-list-icon" }),
434
+ /* @__PURE__ */ jsx("span", { className: "pollar-wallet-list-name", children: "Freighter" })
435
+ ]
436
+ }
437
+ ),
438
+ /* @__PURE__ */ jsxs(
439
+ "button",
440
+ {
441
+ type: "button",
442
+ disabled: isLoading,
443
+ className: "pollar-wallet-list-btn",
444
+ onClick: onAlbedoConnect,
445
+ children: [
446
+ /* @__PURE__ */ jsx("img", { src: LOGO_ALBEDO, alt: "Albedo", className: "pollar-wallet-list-icon" }),
447
+ /* @__PURE__ */ jsx("span", { className: "pollar-wallet-list-name", children: "Albedo" })
448
+ ]
449
+ }
450
+ )
451
+ ] })
403
452
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
404
453
  emailEnabled && /* @__PURE__ */ jsxs("div", { className: "pollar-email-section", children: [
405
454
  /* @__PURE__ */ jsx(
@@ -414,7 +463,7 @@ function LoginModalTemplate({
414
463
  onKeyDown: (e) => e.key === "Enter" && onEmailSubmit?.()
415
464
  }
416
465
  ),
417
- /* @__PURE__ */ jsx("button", { type: "button", disabled: isLoading || !email, className: "pollar-submit-btn", onClick: onEmailSubmit, children: "Submit" })
466
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: isLoading || !email, className: "pollar-btn-primary", style: { marginTop: "0.75rem", width: "100%" }, onClick: onEmailSubmit, children: "Submit" })
418
467
  ] }),
419
468
  emailEnabled && enabledSocial.length > 0 && /* @__PURE__ */ jsxs("div", { className: "pollar-divider", children: [
420
469
  /* @__PURE__ */ jsx("div", { className: "pollar-divider-line" }),
@@ -424,17 +473,19 @@ function LoginModalTemplate({
424
473
  enabledSocial.some(([key]) => key === "google") && /* @__PURE__ */ jsx(GoogleButton, { disabled: isLoading, onClick: () => onSocialLogin?.("google") }),
425
474
  enabledSocial.some(([key]) => key === "github") && /* @__PURE__ */ jsx(GithubButton, { disabled: isLoading, onClick: () => onSocialLogin?.("github") })
426
475
  ] }),
427
- embeddedWallets && /* @__PURE__ */ jsxs("div", { className: "pollar-wallet-section", children: [
428
- /* @__PURE__ */ jsx("p", { className: "pollar-wallet-label", children: "Continue with a wallet" }),
429
- /* @__PURE__ */ jsxs("button", { type: "button", disabled: isLoading, className: "pollar-wallet-btn", onClick: onFreighterConnect, children: [
430
- /* @__PURE__ */ jsx("img", { src: LOGO_FREIGHTER, alt: "Freighter", className: "pollar-wallet-icon" }),
431
- "Freighter"
432
- ] }),
433
- /* @__PURE__ */ jsxs("button", { type: "button", disabled: isLoading, className: "pollar-wallet-btn", onClick: onAlbedoConnect, children: [
434
- /* @__PURE__ */ jsx("img", { src: LOGO_ALBEDO, alt: "Albedo", className: "pollar-wallet-icon" }),
435
- "Albedo"
436
- ] })
437
- ] })
476
+ embeddedWallets && /* @__PURE__ */ jsx("div", { className: "pollar-wallet-section", children: /* @__PURE__ */ jsxs(
477
+ "button",
478
+ {
479
+ type: "button",
480
+ disabled: isLoading,
481
+ className: "pollar-wallet-entry-btn",
482
+ onClick: () => setShowWalletPicker(true),
483
+ children: [
484
+ /* @__PURE__ */ jsx("svg", { width: "18", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ 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" }) }),
485
+ "Wallet"
486
+ ]
487
+ }
488
+ ) })
438
489
  ] }),
439
490
  /* @__PURE__ */ jsx(
440
491
  ModalStatusBanner,
@@ -525,7 +576,7 @@ function LoginModal({ onClose }) {
525
576
  codeInputKey,
526
577
  onCodeSubmit: handleVerifyCode,
527
578
  onBack: handleBack,
528
- onCancel: () => getClient().cancelLogin(),
579
+ onCancel: handleClose,
529
580
  onRetry: handleRetry
530
581
  }
531
582
  ) });
@@ -600,13 +651,23 @@ function RampWidgetTemplate({
600
651
  const isDark = theme === "dark";
601
652
  const cssVars = {
602
653
  "--pollar-accent": accentColor,
603
- "--pollar-buttons-border-radius": "6px",
604
- "--pollar-buttons-height": "44px",
605
654
  "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
606
655
  "--pollar-border": isDark ? "#374151" : "#e5e7eb",
607
656
  "--pollar-text": isDark ? "#ffffff" : "#111827",
608
657
  "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
609
- "--pollar-input-bg": isDark ? "#374151" : "#f9fafb"
658
+ "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
659
+ "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
660
+ "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
661
+ "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
662
+ "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
663
+ "--pollar-buttons-border-radius": "6px",
664
+ "--pollar-buttons-height": "44px",
665
+ "--pollar-input-height": "44px",
666
+ "--pollar-input-border-radius": "0.5rem",
667
+ "--pollar-card-border-radius": "10px",
668
+ "--pollar-modal-padding": "2rem",
669
+ "--pollar-modal-heading-size": "1.375rem",
670
+ "--pollar-modal-subtitle-size": "0.9rem"
610
671
  };
611
672
  const stepTitle = {
612
673
  input: direction === "onramp" ? "Buy crypto" : "Sell crypto",
@@ -620,7 +681,7 @@ function RampWidgetTemplate({
620
681
  select_route: "All prices include fees",
621
682
  payment_instructions: "Send the exact amount to complete your transaction"
622
683
  };
623
- return /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
684
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-modal-card pollar-ramp-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
624
685
  /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-header", children: [
625
686
  /* @__PURE__ */ jsx("h2", { className: "pollar-ramp-title", children: stepTitle[step] }),
626
687
  /* @__PURE__ */ jsx("p", { className: "pollar-ramp-subtitle", children: stepSubtitle[step] })
@@ -834,28 +895,46 @@ function RampWidget({ onClose }) {
834
895
  }
835
896
  ) });
836
897
  }
898
+ var STATUS_MESSAGES = {
899
+ idle: "",
900
+ building: "Building transaction\u2026",
901
+ built: "Ready to sign and send",
902
+ signing: "Signing and sending transaction\u2026",
903
+ success: "Transaction sent successfully",
904
+ error: "Transaction failed"
905
+ };
837
906
  function TransactionModalTemplate({
838
907
  theme,
839
908
  accentColor,
840
909
  transaction,
910
+ showXdr,
911
+ copied,
912
+ explorerUrl,
913
+ walletType,
841
914
  onClose,
842
- onSignAndSend
915
+ onSignAndSend,
916
+ onToggleXdr,
917
+ onCopyHash,
918
+ onRetry
843
919
  }) {
844
920
  const isDark = theme === "dark";
845
921
  const cssVars = {
846
922
  "--pollar-accent": accentColor,
847
- "--pollar-buttons-border-radius": "8px",
848
- "--pollar-buttons-height": "44px",
849
923
  "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
850
924
  "--pollar-border": isDark ? "#374151" : "#e5e7eb",
851
925
  "--pollar-text": isDark ? "#ffffff" : "#111827",
852
926
  "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
853
- "--pollar-input-bg": isDark ? "#374151" : "rgba(0,0,0,0.04)",
927
+ "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
928
+ "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
929
+ "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
854
930
  "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
855
- "--pollar-success-text": isDark ? "#4ade80" : "#16a34a"
931
+ "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
932
+ "--pollar-buttons-border-radius": "6px",
933
+ "--pollar-buttons-height": "44px",
934
+ "--pollar-input-height": "44px",
935
+ "--pollar-input-border-radius": "0.5rem",
936
+ "--pollar-card-border-radius": "10px"
856
937
  };
857
- const [showXdr, setShowXdr] = useState(false);
858
- const [copied, setCopied] = useState(false);
859
938
  const buildData = "buildData" in transaction ? transaction.buildData : null;
860
939
  const hash = transaction.step === "success" ? transaction.hash : null;
861
940
  const errorDetails = transaction.step === "error" ? transaction.details ?? null : null;
@@ -864,28 +943,23 @@ function TransactionModalTemplate({
864
943
  const isSuccess = transaction.step === "success";
865
944
  const isError = transaction.step === "error";
866
945
  const showDetails = buildData !== null && (isBuilt || isSigning || isSuccess);
867
- const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : "public";
868
- const explorerUrl = hash ? `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}` : null;
869
- function handleCopyHash() {
870
- if (!hash) return;
871
- navigator.clipboard.writeText(hash).then(() => {
872
- setCopied(true);
873
- setTimeout(() => setCopied(false), 2e3);
874
- });
875
- }
876
- const statusMessage = {
877
- idle: "",
878
- building: "Building transaction\u2026",
879
- built: "Ready to sign and send",
880
- signing: "Signing and sending transaction\u2026",
881
- success: "Transaction sent successfully",
882
- error: "Transaction failed"
883
- };
884
- return /* @__PURE__ */ jsxs("div", { className: "pollar-tx-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
885
- /* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
886
- /* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: "Transaction" }),
887
- /* @__PURE__ */ jsx("button", { className: "pollar-modal-close", onClick: onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M2 2l12 12M14 2L2 14", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) })
888
- ] }),
946
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-modal-card pollar-tx-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
947
+ /* @__PURE__ */ jsx("div", { className: "pollar-modal-header", children: /* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: "Transaction" }) }),
948
+ /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-close-btn", onClick: onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx(
949
+ "svg",
950
+ {
951
+ width: "18",
952
+ height: "18",
953
+ viewBox: "0 0 24 24",
954
+ fill: "none",
955
+ stroke: "currentColor",
956
+ strokeWidth: "2.5",
957
+ strokeLinecap: "round",
958
+ strokeLinejoin: "round",
959
+ "aria-hidden": true,
960
+ children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" })
961
+ }
962
+ ) }),
889
963
  showDetails && buildData && /* @__PURE__ */ jsxs(Fragment, { children: [
890
964
  /* @__PURE__ */ jsxs("div", { className: "pollar-tx-summary", children: [
891
965
  /* @__PURE__ */ jsx("p", { className: "pollar-tx-summary-title", children: "Details" }),
@@ -902,7 +976,7 @@ function TransactionModalTemplate({
902
976
  ] })
903
977
  ] }),
904
978
  /* @__PURE__ */ jsxs("div", { className: "pollar-tx-xdr", children: [
905
- /* @__PURE__ */ jsxs("button", { className: "pollar-tx-xdr-toggle", onClick: () => setShowXdr((v) => !v), children: [
979
+ /* @__PURE__ */ jsxs("button", { className: "pollar-tx-xdr-toggle", onClick: onToggleXdr, children: [
906
980
  /* @__PURE__ */ jsx(
907
981
  "svg",
908
982
  {
@@ -920,48 +994,147 @@ function TransactionModalTemplate({
920
994
  showXdr && /* @__PURE__ */ jsx("pre", { className: "pollar-tx-xdr-content", children: buildData.unsignedXdr })
921
995
  ] })
922
996
  ] }),
997
+ isError && errorDetails && /* @__PURE__ */ jsxs("div", { className: "pollar-tx-error-details", children: [
998
+ /* @__PURE__ */ jsx("p", { className: "pollar-tx-error-details-label", children: "Error details" }),
999
+ /* @__PURE__ */ jsx("pre", { className: "pollar-tx-error-details-content", children: errorDetails })
1000
+ ] }),
1001
+ isBuilt && /* @__PURE__ */ jsx("button", { className: "pollar-btn-primary pollar-tx-sign-btn", onClick: onSignAndSend, children: "Sign & Send" }),
1002
+ (isSigning || isSuccess || isError) && /* @__PURE__ */ jsxs("div", { className: "pollar-tx-wallet-spinner", children: [
1003
+ /* @__PURE__ */ jsxs("div", { className: "pollar-tx-spinner-ring", children: [
1004
+ /* @__PURE__ */ jsxs(
1005
+ "svg",
1006
+ {
1007
+ viewBox: "0 0 88 88",
1008
+ width: "88",
1009
+ height: "88",
1010
+ className: `pollar-tx-spinner-svg${isSigning ? " pollar-tx-spinner-rotating" : ""}`,
1011
+ "aria-hidden": true,
1012
+ children: [
1013
+ /* @__PURE__ */ jsx("circle", { cx: "44", cy: "44", r: "36", fill: "none", stroke: "var(--pollar-border)", strokeWidth: "3" }),
1014
+ /* @__PURE__ */ jsx(
1015
+ "circle",
1016
+ {
1017
+ cx: "44",
1018
+ cy: "44",
1019
+ r: "36",
1020
+ fill: "none",
1021
+ stroke: isSuccess ? "var(--pollar-success-text)" : isError ? "var(--pollar-error-text)" : "var(--pollar-accent)",
1022
+ strokeWidth: "3",
1023
+ strokeLinecap: "round",
1024
+ strokeDasharray: isSigning ? "169.6 56.6" : "999 0",
1025
+ transform: "rotate(-90 44 44)",
1026
+ style: { transition: isSigning ? "none" : "stroke 400ms, stroke-dasharray 400ms" }
1027
+ }
1028
+ )
1029
+ ]
1030
+ }
1031
+ ),
1032
+ /* @__PURE__ */ jsx("div", { className: "pollar-tx-wallet-icon", children: /* @__PURE__ */ jsx(
1033
+ "img",
1034
+ {
1035
+ src: walletType === WalletType.FREIGHTER ? LOGO_FREIGHTER : walletType === WalletType.ALBEDO ? LOGO_ALBEDO : LOGO_POLLAR,
1036
+ alt: walletType === WalletType.FREIGHTER ? "Freighter" : walletType === WalletType.ALBEDO ? "Albedo" : "Pollar",
1037
+ className: "pollar-tx-wallet-img"
1038
+ }
1039
+ ) })
1040
+ ] }),
1041
+ isSigning && /* @__PURE__ */ jsx("p", { className: "pollar-tx-spinner-label", children: walletType === WalletType.FREIGHTER ? "Waiting for Freighter\u2026" : walletType === WalletType.ALBEDO ? "Waiting for Albedo\u2026" : "Signing and sending\u2026" }),
1042
+ isError && onRetry && "buildData" in transaction && transaction.buildData && /* @__PURE__ */ jsx("button", { className: "pollar-btn-secondary pollar-tx-retry-btn", onClick: onRetry, children: "Try again" })
1043
+ ] }),
923
1044
  isSuccess && hash && /* @__PURE__ */ jsxs("div", { className: "pollar-tx-result", children: [
924
1045
  /* @__PURE__ */ jsx("span", { className: "pollar-tx-result-label", children: "Transaction hash" }),
925
1046
  /* @__PURE__ */ jsx("span", { className: "pollar-tx-result-hash", children: hash }),
926
1047
  /* @__PURE__ */ jsxs("div", { className: "pollar-tx-result-actions", children: [
927
- /* @__PURE__ */ jsx("button", { className: "pollar-tx-result-btn", onClick: handleCopyHash, children: copied ? /* @__PURE__ */ jsxs(Fragment, { children: [
1048
+ /* @__PURE__ */ jsx("button", { className: "pollar-tx-result-btn", onClick: onCopyHash, children: copied ? /* @__PURE__ */ jsxs(Fragment, { children: [
928
1049
  /* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: [
929
1050
  /* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "7", fill: "currentColor" }),
930
- /* @__PURE__ */ jsx("path", { d: "M3.5 7l2.5 2.5 4.5-5", stroke: "white", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
1051
+ /* @__PURE__ */ jsx(
1052
+ "path",
1053
+ {
1054
+ d: "M3.5 7l2.5 2.5 4.5-5",
1055
+ stroke: "white",
1056
+ strokeWidth: "1.5",
1057
+ strokeLinecap: "round",
1058
+ strokeLinejoin: "round"
1059
+ }
1060
+ )
931
1061
  ] }),
932
1062
  "Copied!"
933
1063
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
934
1064
  /* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 13 13", fill: "none", "aria-hidden": true, children: [
935
1065
  /* @__PURE__ */ jsx("rect", { x: "4", y: "4", width: "8", height: "8", rx: "1.5", stroke: "currentColor", strokeWidth: "1.5" }),
936
- /* @__PURE__ */ jsx("path", { d: "M3 9H2a1 1 0 01-1-1V2a1 1 0 011-1h6a1 1 0 011 1v1", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
1066
+ /* @__PURE__ */ jsx(
1067
+ "path",
1068
+ {
1069
+ d: "M3 9H2a1 1 0 01-1-1V2a1 1 0 011-1h6a1 1 0 011 1v1",
1070
+ stroke: "currentColor",
1071
+ strokeWidth: "1.5",
1072
+ strokeLinecap: "round"
1073
+ }
1074
+ )
937
1075
  ] }),
938
1076
  "Copy hash"
939
1077
  ] }) }),
940
1078
  explorerUrl && /* @__PURE__ */ jsxs("a", { className: "pollar-tx-result-btn", href: explorerUrl, target: "_blank", rel: "noopener noreferrer", children: [
941
1079
  /* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 13 13", fill: "none", "aria-hidden": true, children: [
942
- /* @__PURE__ */ jsx("path", { d: "M5 2H2a1 1 0 00-1 1v8a1 1 0 001 1h8a1 1 0 001-1V8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }),
943
- /* @__PURE__ */ jsx("path", { d: "M8 1h4m0 0v4m0-4L6 7", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
1080
+ /* @__PURE__ */ jsx(
1081
+ "path",
1082
+ {
1083
+ d: "M5 2H2a1 1 0 00-1 1v8a1 1 0 001 1h8a1 1 0 001-1V8",
1084
+ stroke: "currentColor",
1085
+ strokeWidth: "1.5",
1086
+ strokeLinecap: "round"
1087
+ }
1088
+ ),
1089
+ /* @__PURE__ */ jsx(
1090
+ "path",
1091
+ {
1092
+ d: "M8 1h4m0 0v4m0-4L6 7",
1093
+ stroke: "currentColor",
1094
+ strokeWidth: "1.5",
1095
+ strokeLinecap: "round",
1096
+ strokeLinejoin: "round"
1097
+ }
1098
+ )
944
1099
  ] }),
945
1100
  "View on Explorer"
946
1101
  ] })
947
1102
  ] })
948
1103
  ] }),
949
- isError && errorDetails && /* @__PURE__ */ jsxs("div", { className: "pollar-tx-error-details", children: [
950
- /* @__PURE__ */ jsx("p", { className: "pollar-tx-error-details-label", children: "Error details" }),
951
- /* @__PURE__ */ jsx("pre", { className: "pollar-tx-error-details-content", children: errorDetails })
952
- ] }),
953
- isBuilt && /* @__PURE__ */ jsx("button", { className: "pollar-btn-primary pollar-tx-sign-btn", onClick: onSignAndSend, children: "Sign & Send" }),
954
- isSigning && /* @__PURE__ */ jsx("button", { className: "pollar-btn-primary pollar-tx-sign-btn", disabled: true, children: "Signing & sending\u2026" }),
955
1104
  isSuccess && /* @__PURE__ */ jsx("button", { className: "pollar-btn-primary pollar-tx-sign-btn", onClick: onClose, children: "Done" }),
956
- /* @__PURE__ */ jsx(ModalStatusBanner, { message: statusMessage[transaction.step], status: isError ? "ERROR" : isSigning || transaction.step === "building" ? "LOADING" : isSuccess ? "SUCCESS" : "NONE" }),
1105
+ /* @__PURE__ */ jsx(
1106
+ ModalStatusBanner,
1107
+ {
1108
+ message: STATUS_MESSAGES[transaction.step],
1109
+ status: isError ? "ERROR" : isSigning || transaction.step === "building" ? "LOADING" : isSuccess ? "SUCCESS" : "NONE"
1110
+ }
1111
+ ),
957
1112
  /* @__PURE__ */ jsx(PollarModalFooter, {})
958
1113
  ] });
959
1114
  }
960
1115
  function TransactionModal({ onClose }) {
961
- const { getClient, styles, transaction } = usePollar();
1116
+ const { getClient, styles, transaction, network, walletType } = usePollar();
962
1117
  const { theme = "light", accentColor = "#005DB4" } = styles;
963
- async function handleSignAndSend() {
1118
+ const [showXdr, setShowXdr] = useState(false);
1119
+ const [copied, setCopied] = useState(false);
1120
+ const hash = transaction.step === "success" ? transaction.hash : null;
1121
+ const buildData = "buildData" in transaction ? transaction.buildData : null;
1122
+ const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : buildData ? "public" : network === "testnet" ? "testnet" : "public";
1123
+ const explorerUrl = hash ? `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}` : null;
1124
+ function handleSignAndSend() {
964
1125
  if (transaction.step === "built") {
1126
+ void getClient().signAndSubmitTx(transaction.buildData.unsignedXdr);
1127
+ }
1128
+ }
1129
+ function handleCopyHash() {
1130
+ if (!hash) return;
1131
+ navigator.clipboard.writeText(hash).then(() => {
1132
+ setCopied(true);
1133
+ setTimeout(() => setCopied(false), 2e3);
1134
+ });
1135
+ }
1136
+ async function handleRetry() {
1137
+ if (transaction.step === "error" && transaction.buildData) {
965
1138
  await getClient().signAndSubmitTx(transaction.buildData.unsignedXdr);
966
1139
  }
967
1140
  }
@@ -971,8 +1144,15 @@ function TransactionModal({ onClose }) {
971
1144
  theme,
972
1145
  accentColor,
973
1146
  transaction,
1147
+ showXdr,
1148
+ copied,
1149
+ explorerUrl,
1150
+ walletType,
974
1151
  onClose,
975
- onSignAndSend: handleSignAndSend
1152
+ onSignAndSend: handleSignAndSend,
1153
+ onToggleXdr: () => setShowXdr((v) => !v),
1154
+ onCopyHash: handleCopyHash,
1155
+ onRetry: handleRetry
976
1156
  }
977
1157
  ) });
978
1158
  }
@@ -996,15 +1176,20 @@ function TxHistoryModalTemplate({
996
1176
  const isDark = theme === "dark";
997
1177
  const cssVars = {
998
1178
  "--pollar-accent": accentColor,
999
- "--pollar-buttons-border-radius": "8px",
1000
- "--pollar-buttons-height": "44px",
1001
1179
  "--pollar-bg": isDark ? "#1a1a1a" : "#ffffff",
1002
1180
  "--pollar-border": isDark ? "#374151" : "#e5e7eb",
1003
1181
  "--pollar-text": isDark ? "#ffffff" : "#111827",
1004
1182
  "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
1005
- "--pollar-input-bg": isDark ? "#374151" : "rgba(0,0,0,0.04)",
1183
+ "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
1184
+ "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
1185
+ "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
1006
1186
  "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
1007
- "--pollar-success-text": isDark ? "#4ade80" : "#16a34a"
1187
+ "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
1188
+ "--pollar-buttons-border-radius": "6px",
1189
+ "--pollar-buttons-height": "44px",
1190
+ "--pollar-input-height": "44px",
1191
+ "--pollar-input-border-radius": "0.5rem",
1192
+ "--pollar-card-border-radius": "10px"
1008
1193
  };
1009
1194
  const isLoading = txHistory.step === "loading";
1010
1195
  const records = txHistory.step === "loaded" ? txHistory.data.records : [];
@@ -1012,7 +1197,7 @@ function TxHistoryModalTemplate({
1012
1197
  const hasPrev = offset > 0;
1013
1198
  const hasNext = offset + PAGE_SIZE < total;
1014
1199
  const showPagination = txHistory.step === "loaded" && total > PAGE_SIZE;
1015
- return /* @__PURE__ */ jsxs("div", { className: "pollar-hist-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
1200
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-modal-card pollar-hist-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
1016
1201
  /* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
1017
1202
  /* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: "Transaction History" }),
1018
1203
  /* @__PURE__ */ jsxs("div", { className: "pollar-modal-header-actions", children: [
@@ -1050,22 +1235,33 @@ function TxHistoryModalTemplate({
1050
1235
  isLoading && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: "Loading\u2026" }),
1051
1236
  txHistory.step === "error" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: txHistory.message }),
1052
1237
  txHistory.step === "loaded" && records.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: "No transactions yet." }),
1053
- records.map((record) => /* @__PURE__ */ jsxs("div", { className: "pollar-hist-item", children: [
1054
- /* @__PURE__ */ jsx("span", { className: "pollar-hist-item-summary", children: record.summary }),
1055
- /* @__PURE__ */ jsx(StatusBadge, { status: record.status }),
1056
- /* @__PURE__ */ jsxs("span", { className: "pollar-hist-item-meta", children: [
1057
- /* @__PURE__ */ jsx("span", { children: record.operation }),
1058
- record.feeXlm && /* @__PURE__ */ jsxs("span", { children: [
1059
- "\xB7 ",
1060
- record.feeXlm,
1061
- " XLM"
1062
- ] }),
1063
- /* @__PURE__ */ jsxs("span", { children: [
1064
- "\xB7 ",
1065
- formatDate(record.createdAt)
1238
+ records.map((record) => {
1239
+ const explorerUrl = `https://stellar.expert/explorer/${record.network === "testnet" ? "testnet" : "public"}/tx/${record.hash}`;
1240
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-hist-item", children: [
1241
+ /* @__PURE__ */ jsx("span", { className: "pollar-hist-item-summary", children: record.summary }),
1242
+ /* @__PURE__ */ jsx(StatusBadge, { status: record.status }),
1243
+ /* @__PURE__ */ jsxs("span", { className: "pollar-hist-item-meta", children: [
1244
+ /* @__PURE__ */ jsx("span", { children: record.operation }),
1245
+ record.feeXlm && /* @__PURE__ */ jsxs("span", { children: [
1246
+ "\xB7 ",
1247
+ record.feeXlm,
1248
+ " XLM"
1249
+ ] }),
1250
+ /* @__PURE__ */ jsxs("span", { children: [
1251
+ "\xB7 ",
1252
+ formatDate(record.createdAt)
1253
+ ] }),
1254
+ /* @__PURE__ */ jsx("span", { children: "\xB7" }),
1255
+ /* @__PURE__ */ jsxs("a", { className: "pollar-hist-item-explorer", href: explorerUrl, target: "_blank", rel: "noopener noreferrer", "aria-label": "View on Stellar Explorer", children: [
1256
+ /* @__PURE__ */ jsxs("svg", { width: "11", height: "11", viewBox: "0 0 13 13", fill: "none", "aria-hidden": true, children: [
1257
+ /* @__PURE__ */ jsx("path", { d: "M5 2H2a1 1 0 00-1 1v8a1 1 0 001 1h8a1 1 0 001-1V8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }),
1258
+ /* @__PURE__ */ jsx("path", { d: "M8 1h4m0 0v4m0-4L6 7", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
1259
+ ] }),
1260
+ "Explorer"
1261
+ ] })
1066
1262
  ] })
1067
- ] })
1068
- ] }, record.id))
1263
+ ] }, record.id);
1264
+ })
1069
1265
  ] }),
1070
1266
  showPagination && /* @__PURE__ */ jsxs("div", { className: "pollar-hist-pagination", children: [
1071
1267
  /* @__PURE__ */ jsxs("span", { className: "pollar-hist-pagination-info", children: [
@@ -1127,9 +1323,14 @@ function BalanceItem({ record }) {
1127
1323
  ] })
1128
1324
  ] });
1129
1325
  }
1130
- function WalletBalanceModal({ onClose }) {
1131
- const { getBalance, walletAddress, styles } = usePollar();
1132
- const { theme = "light", accentColor = "#005DB4" } = styles;
1326
+ function WalletBalanceModalTemplate({
1327
+ theme,
1328
+ accentColor,
1329
+ walletBalance,
1330
+ walletAddress,
1331
+ onRefresh,
1332
+ onClose
1333
+ }) {
1133
1334
  const isDark = theme === "dark";
1134
1335
  const cssVars = {
1135
1336
  "--pollar-accent": accentColor,
@@ -1137,30 +1338,24 @@ function WalletBalanceModal({ onClose }) {
1137
1338
  "--pollar-border": isDark ? "#374151" : "#e5e7eb",
1138
1339
  "--pollar-text": isDark ? "#ffffff" : "#111827",
1139
1340
  "--pollar-muted": isDark ? "#9ca3af" : "#6b7280",
1140
- "--pollar-input-bg": isDark ? "#374151" : "rgba(0,0,0,0.04)",
1141
- "--pollar-error-text": isDark ? "#f87171" : "#dc2626"
1341
+ "--pollar-input-bg": isDark ? "#374151" : "#f9fafb",
1342
+ "--pollar-error-bg": isDark ? "#2a1515" : "#fef2f2",
1343
+ "--pollar-error-border": isDark ? "#7f1d1d" : "#fecaca",
1344
+ "--pollar-error-text": isDark ? "#f87171" : "#dc2626",
1345
+ "--pollar-success-text": isDark ? "#4ade80" : "#16a34a",
1346
+ "--pollar-buttons-border-radius": "6px",
1347
+ "--pollar-buttons-height": "44px",
1348
+ "--pollar-input-height": "44px",
1349
+ "--pollar-input-border-radius": "0.5rem",
1350
+ "--pollar-card-border-radius": "10px"
1142
1351
  };
1143
- const [status, setStatus] = useState("loading");
1144
- const [data, setData] = useState(null);
1145
- async function load() {
1146
- setStatus("loading");
1147
- const result = await getBalance();
1148
- if (result) {
1149
- setData(result);
1150
- setStatus("loaded");
1151
- } else {
1152
- setStatus("error");
1153
- }
1154
- }
1155
- useEffect(() => {
1156
- void load();
1157
- }, []);
1158
- const isLoading = status === "loading";
1159
- return /* @__PURE__ */ jsx("div", { className: "pollar-overlay", onClick: onClose, children: /* @__PURE__ */ jsxs("div", { className: "pollar-bal-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
1352
+ const isLoading = walletBalance.step === "loading";
1353
+ const data = walletBalance.step === "loaded" ? walletBalance.data : null;
1354
+ return /* @__PURE__ */ jsxs("div", { className: "pollar-modal-card pollar-bal-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
1160
1355
  /* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
1161
1356
  /* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: "Wallet Balance" }),
1162
1357
  /* @__PURE__ */ jsxs("div", { className: "pollar-modal-header-actions", children: [
1163
- /* @__PURE__ */ jsxs("button", { className: "pollar-modal-refresh-btn", onClick: load, disabled: isLoading, children: [
1358
+ /* @__PURE__ */ jsxs("button", { className: "pollar-modal-refresh-btn", onClick: onRefresh, disabled: isLoading, children: [
1164
1359
  /* @__PURE__ */ jsxs(
1165
1360
  "svg",
1166
1361
  {
@@ -1183,16 +1378,34 @@ function WalletBalanceModal({ onClose }) {
1183
1378
  ] }),
1184
1379
  walletAddress && /* @__PURE__ */ jsx("div", { className: "pollar-bal-address", children: cropAddress(walletAddress) }),
1185
1380
  isLoading && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: "Loading\u2026" }),
1186
- status === "error" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: "Failed to load balances. Check your connection." }),
1187
- status === "loaded" && data && !data.exists && /* @__PURE__ */ jsxs("div", { className: "pollar-modal-empty", children: [
1381
+ walletBalance.step === "error" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: walletBalance.message }),
1382
+ data && !data.exists && /* @__PURE__ */ jsxs("div", { className: "pollar-modal-empty", children: [
1188
1383
  "Account not found on ",
1189
1384
  data.network,
1190
1385
  "."
1191
1386
  ] }),
1192
- status === "loaded" && data?.exists && data.balances.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: "No balances found." }),
1193
- status === "loaded" && data?.exists && data.balances.length > 0 && /* @__PURE__ */ jsx("div", { className: "pollar-bal-list", children: data.balances.map((b) => /* @__PURE__ */ jsx(BalanceItem, { record: b }, b.code + (b.issuer ?? ""))) }),
1387
+ data?.exists && data.balances.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: "No balances found." }),
1388
+ data?.exists && data.balances.length > 0 && /* @__PURE__ */ jsx("div", { className: "pollar-bal-list", children: data.balances.map((b) => /* @__PURE__ */ jsx(BalanceItem, { record: b }, b.code + (b.issuer ?? ""))) }),
1194
1389
  /* @__PURE__ */ jsx(PollarModalFooter, {})
1195
- ] }) });
1390
+ ] });
1391
+ }
1392
+ function WalletBalanceModal({ onClose }) {
1393
+ const { walletBalance, refreshBalance, walletAddress, styles } = usePollar();
1394
+ const { theme = "light", accentColor = "#005DB4" } = styles;
1395
+ useEffect(() => {
1396
+ void refreshBalance();
1397
+ }, []);
1398
+ return /* @__PURE__ */ jsx("div", { className: "pollar-overlay", onClick: onClose, children: /* @__PURE__ */ jsx(
1399
+ WalletBalanceModalTemplate,
1400
+ {
1401
+ theme,
1402
+ accentColor,
1403
+ walletBalance,
1404
+ walletAddress,
1405
+ onRefresh: () => refreshBalance(),
1406
+ onClose
1407
+ }
1408
+ ) });
1196
1409
  }
1197
1410
  var emptyResponse = {
1198
1411
  application: {
@@ -1205,16 +1418,13 @@ async function fetchRemoteConfig(client) {
1205
1418
  return content ?? emptyResponse;
1206
1419
  }
1207
1420
  var PollarContext = createContext(null);
1208
- function PollarProvider({ config, styles: propStyles, children }) {
1421
+ function PollarProvider({ config, styles: propStyles, adapters, children }) {
1209
1422
  const [pollarClient] = useState(() => new PollarClient(config));
1210
1423
  const [networkState, setNetworkState] = useState(() => pollarClient.getNetworkState());
1211
- const stellarClient = useMemo(() => {
1212
- const network = networkState.step === "connected" ? networkState.network : "testnet";
1213
- return new StellarClient(network);
1214
- }, [networkState]);
1215
1424
  const [sessionState, setSessionState] = useState(null);
1216
1425
  const [transaction, setTransaction] = useState({ step: "idle" });
1217
1426
  const [txHistory, setTxHistory] = useState({ step: "idle" });
1427
+ const [walletBalance, setWalletBalance] = useState({ step: "idle" });
1218
1428
  const [remoteConfig, setRemoteConfig] = useState(emptyResponse);
1219
1429
  const [styles, setStyles] = useState(propStyles ?? {});
1220
1430
  useEffect(() => {
@@ -1223,6 +1433,9 @@ function PollarProvider({ config, styles: propStyles, children }) {
1223
1433
  useEffect(() => {
1224
1434
  return pollarClient.onTxHistoryStateChange(setTxHistory);
1225
1435
  }, [pollarClient]);
1436
+ useEffect(() => {
1437
+ return pollarClient.onWalletBalanceStateChange(setWalletBalance);
1438
+ }, [pollarClient]);
1226
1439
  useEffect(() => {
1227
1440
  return pollarClient.onNetworkStateChange((state) => {
1228
1441
  setNetworkState(state);
@@ -1263,14 +1476,15 @@ function PollarProvider({ config, styles: propStyles, children }) {
1263
1476
  const [walletBalanceModalOpen, setWalletBalanceModalOpen] = useState(false);
1264
1477
  const contextValue = useMemo(
1265
1478
  () => ({
1266
- walletAddress: sessionState?.wallet?.publicKey || "",
1479
+ walletAddress: sessionState?.data?.providers?.wallet?.address || sessionState?.wallet?.publicKey || "",
1267
1480
  getClient: () => pollarClient,
1268
1481
  transaction,
1269
1482
  login: (options) => pollarClient.login(options),
1270
1483
  logout: () => pollarClient.logout(),
1271
1484
  isAuthenticated: !!sessionState?.wallet?.publicKey,
1272
1485
  buildTx: (operation, params, options) => pollarClient.buildTx(operation, params, options),
1273
- signAndSubmitTx: (signedXdr) => pollarClient.signAndSubmitTx(signedXdr),
1486
+ signAndSubmitTx: (unsignedXdr) => pollarClient.signAndSubmitTx(unsignedXdr),
1487
+ walletType: pollarClient.getWalletType(),
1274
1488
  openTransactionModal: () => setTransactionModalOpen(true),
1275
1489
  openLoginModal: () => setLoginModalOpen(true),
1276
1490
  openKycModal: (options = {}) => {
@@ -1281,13 +1495,15 @@ function PollarProvider({ config, styles: propStyles, children }) {
1281
1495
  txHistory,
1282
1496
  openTxHistoryModal: () => setTxHistoryModalOpen(true),
1283
1497
  openWalletBalanceModal: () => setWalletBalanceModalOpen(true),
1498
+ walletBalance,
1499
+ refreshBalance: (publicKey) => pollarClient.refreshBalance(publicKey),
1284
1500
  network: networkState.step === "connected" ? networkState.network : "testnet",
1285
1501
  setNetwork: (network) => pollarClient.setNetwork(network),
1286
1502
  config: remoteConfig,
1287
1503
  styles,
1288
- getBalance: (publicKey) => pollarClient.getWalletBalance(publicKey)
1504
+ adapters
1289
1505
  }),
1290
- [sessionState, remoteConfig, styles, pollarClient, transaction, txHistory, networkState, stellarClient]
1506
+ [sessionState, remoteConfig, styles, pollarClient, transaction, txHistory, networkState, walletBalance]
1291
1507
  );
1292
1508
  return /* @__PURE__ */ jsxs(PollarContext.Provider, { value: contextValue, children: [
1293
1509
  children,
@@ -1314,50 +1530,57 @@ function usePollar() {
1314
1530
  }
1315
1531
  return ctx;
1316
1532
  }
1317
- function cropWallet(address) {
1318
- if (address.length <= 12) return address;
1319
- return `${address.slice(0, 6)}...${address.slice(-4)}`;
1533
+
1534
+ // src/usePollarAdapter.ts
1535
+ function createPollarAdapterHook(key) {
1536
+ return function usePollarAdapter() {
1537
+ const { adapters, signAndSubmitTx } = usePollar();
1538
+ const adapter = adapters?.[key];
1539
+ if (!adapter) {
1540
+ throw new Error(`No adapter "${key}" provided to PollarProvider`);
1541
+ }
1542
+ return Object.fromEntries(
1543
+ Object.entries(adapter).map(([name, fn]) => [
1544
+ name,
1545
+ async (params) => {
1546
+ const { unsignedTransaction } = await fn(params);
1547
+ await signAndSubmitTx(unsignedTransaction);
1548
+ }
1549
+ ])
1550
+ );
1551
+ };
1320
1552
  }
1321
1553
  function ButtonLogo() {
1322
1554
  return /* @__PURE__ */ jsx("img", { src: LOGO_POLLAR, alt: "Pollar", width: 22, height: 22, className: "wallet-btn-logo" });
1323
1555
  }
1324
- function WalletButton() {
1325
- const { getClient, walletAddress, styles, openLoginModal, openTxHistoryModal, openWalletBalanceModal } = usePollar();
1326
- const [open, setOpen] = useState(false);
1327
- const [copied, setCopied] = useState(false);
1328
- const wrapperRef = useRef(null);
1329
- const { theme = "light", accentColor = "#005DB4" } = styles;
1330
- const isDark = theme === "dark";
1331
- const dropdownBg = isDark ? "#18181b" : "#fff";
1332
- const dropdownBorder = isDark ? "#3f3f46" : "#e4e4e7";
1333
- const itemColor = isDark ? "#fafafa" : "#18181b";
1334
- useEffect(() => {
1335
- function handleClickOutside(e) {
1336
- if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
1337
- setOpen(false);
1338
- }
1339
- }
1340
- document.addEventListener("mousedown", handleClickOutside);
1341
- return () => document.removeEventListener("mousedown", handleClickOutside);
1342
- }, []);
1343
- async function handleCopy() {
1344
- if (!walletAddress) return;
1345
- await navigator.clipboard.writeText(walletAddress);
1346
- setCopied(true);
1347
- setTimeout(() => setCopied(false), 1500);
1348
- }
1349
- function handleLogout() {
1350
- setOpen(false);
1351
- getClient().logout();
1352
- }
1556
+ function cropWallet(address) {
1557
+ if (address.length <= 12) return address;
1558
+ return `${address.slice(0, 6)}...${address.slice(-4)}`;
1559
+ }
1560
+ function WalletButtonTemplate({
1561
+ walletAddress,
1562
+ accentColor,
1563
+ open,
1564
+ copied,
1565
+ dropdownBg,
1566
+ dropdownBorder,
1567
+ itemColor,
1568
+ wrapperRef,
1569
+ onToggleOpen,
1570
+ onCopy,
1571
+ onWalletBalance,
1572
+ onTxHistory,
1573
+ onLogout,
1574
+ onLogin
1575
+ }) {
1353
1576
  if (!walletAddress) {
1354
- return /* @__PURE__ */ jsxs("button", { type: "button", className: "wallet-login-btn", style: { backgroundColor: accentColor }, onClick: openLoginModal, children: [
1577
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: "wallet-login-btn", style: { backgroundColor: accentColor }, onClick: onLogin, children: [
1355
1578
  /* @__PURE__ */ jsx(ButtonLogo, {}),
1356
1579
  "Login with Pollar"
1357
1580
  ] });
1358
1581
  }
1359
1582
  return /* @__PURE__ */ jsxs("div", { className: "wallet-wrapper", ref: wrapperRef, children: [
1360
- /* @__PURE__ */ jsxs("button", { className: "wallet-btn", style: { backgroundColor: accentColor }, onClick: () => setOpen((v) => !v), children: [
1583
+ /* @__PURE__ */ jsxs("button", { className: "wallet-btn", style: { backgroundColor: accentColor }, onClick: onToggleOpen, children: [
1361
1584
  cropWallet(walletAddress),
1362
1585
  /* @__PURE__ */ jsx(
1363
1586
  "svg",
@@ -1374,7 +1597,7 @@ function WalletButton() {
1374
1597
  )
1375
1598
  ] }),
1376
1599
  open && /* @__PURE__ */ jsxs("div", { className: "wallet-dropdown", style: { backgroundColor: dropdownBg, borderColor: dropdownBorder }, children: [
1377
- /* @__PURE__ */ jsxs("button", { className: "wallet-dropdown-item", style: { color: itemColor }, onClick: handleCopy, children: [
1600
+ /* @__PURE__ */ jsxs("button", { className: "wallet-dropdown-item", style: { color: itemColor }, onClick: onCopy, children: [
1378
1601
  /* @__PURE__ */ jsxs(
1379
1602
  "svg",
1380
1603
  {
@@ -1399,10 +1622,7 @@ function WalletButton() {
1399
1622
  {
1400
1623
  className: "wallet-dropdown-item",
1401
1624
  style: { color: itemColor },
1402
- onClick: () => {
1403
- setOpen(false);
1404
- openWalletBalanceModal();
1405
- },
1625
+ onClick: onWalletBalance,
1406
1626
  children: [
1407
1627
  /* @__PURE__ */ jsxs(
1408
1628
  "svg",
@@ -1431,10 +1651,7 @@ function WalletButton() {
1431
1651
  {
1432
1652
  className: "wallet-dropdown-item",
1433
1653
  style: { color: itemColor },
1434
- onClick: () => {
1435
- setOpen(false);
1436
- openTxHistoryModal();
1437
- },
1654
+ onClick: onTxHistory,
1438
1655
  children: [
1439
1656
  /* @__PURE__ */ jsxs(
1440
1657
  "svg",
@@ -1460,7 +1677,7 @@ function WalletButton() {
1460
1677
  ]
1461
1678
  }
1462
1679
  ),
1463
- /* @__PURE__ */ jsxs("button", { className: "wallet-dropdown-item danger", onClick: handleLogout, children: [
1680
+ /* @__PURE__ */ jsxs("button", { className: "wallet-dropdown-item danger", onClick: onLogout, children: [
1464
1681
  /* @__PURE__ */ jsxs(
1465
1682
  "svg",
1466
1683
  {
@@ -1484,7 +1701,64 @@ function WalletButton() {
1484
1701
  ] })
1485
1702
  ] });
1486
1703
  }
1704
+ function WalletButton() {
1705
+ const { getClient, walletAddress, styles, openLoginModal, openTxHistoryModal, openWalletBalanceModal } = usePollar();
1706
+ const [open, setOpen] = useState(false);
1707
+ const [copied, setCopied] = useState(false);
1708
+ const wrapperRef = useRef(null);
1709
+ const { theme = "light", accentColor = "#005DB4" } = styles;
1710
+ const isDark = theme === "dark";
1711
+ const dropdownBg = isDark ? "#18181b" : "#fff";
1712
+ const dropdownBorder = isDark ? "#3f3f46" : "#e4e4e7";
1713
+ const itemColor = isDark ? "#fafafa" : "#18181b";
1714
+ useEffect(() => {
1715
+ function handleClickOutside(e) {
1716
+ if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
1717
+ setOpen(false);
1718
+ }
1719
+ }
1720
+ document.addEventListener("mousedown", handleClickOutside);
1721
+ return () => document.removeEventListener("mousedown", handleClickOutside);
1722
+ }, []);
1723
+ async function handleCopy() {
1724
+ if (!walletAddress) return;
1725
+ await navigator.clipboard.writeText(walletAddress);
1726
+ setCopied(true);
1727
+ setTimeout(() => setCopied(false), 1500);
1728
+ }
1729
+ function handleLogout() {
1730
+ setOpen(false);
1731
+ getClient().logout();
1732
+ }
1733
+ function handleWalletBalance() {
1734
+ setOpen(false);
1735
+ openWalletBalanceModal();
1736
+ }
1737
+ function handleTxHistory() {
1738
+ setOpen(false);
1739
+ openTxHistoryModal();
1740
+ }
1741
+ return /* @__PURE__ */ jsx(
1742
+ WalletButtonTemplate,
1743
+ {
1744
+ walletAddress: walletAddress ?? null,
1745
+ accentColor,
1746
+ open,
1747
+ copied,
1748
+ dropdownBg,
1749
+ dropdownBorder,
1750
+ itemColor,
1751
+ wrapperRef,
1752
+ onToggleOpen: () => setOpen((v) => !v),
1753
+ onCopy: handleCopy,
1754
+ onWalletBalance: handleWalletBalance,
1755
+ onTxHistory: handleTxHistory,
1756
+ onLogout: handleLogout,
1757
+ onLogin: openLoginModal
1758
+ }
1759
+ );
1760
+ }
1487
1761
 
1488
- export { KycModal, KycStatus, PollarProvider, RampWidget, RouteDisplay, WalletButton, usePollar };
1762
+ export { KycModal, KycModalTemplate, KycStatus, LoginModalTemplate, PollarProvider, RampWidget, RampWidgetTemplate, RouteDisplay, TransactionModalTemplate, TxHistoryModalTemplate, WalletBalanceModal, WalletBalanceModalTemplate, WalletButton, createPollarAdapterHook, usePollar };
1489
1763
  //# sourceMappingURL=index.mjs.map
1490
1764
  //# sourceMappingURL=index.mjs.map