@pollar/react 0.5.0 → 0.5.2
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.css +215 -63
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +117 -4
- package/dist/index.d.ts +117 -4
- package/dist/index.js +343 -139
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +338 -141
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
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.
|
|
39
|
+
"0.5.2"
|
|
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(
|
|
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 }),
|
|
@@ -264,8 +263,8 @@ function EmailCodeInput({ email, onSubmit }) {
|
|
|
264
263
|
}
|
|
265
264
|
var GithubButton = ({ disabled, onClick }) => {
|
|
266
265
|
return /* @__PURE__ */ jsxs("button", { className: "github-button", disabled, onClick, children: [
|
|
267
|
-
/* @__PURE__ */ jsx("
|
|
268
|
-
/* @__PURE__ */ jsx("span", { className: "github-button-contents", children: "
|
|
266
|
+
/* @__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" }) }),
|
|
267
|
+
/* @__PURE__ */ jsx("span", { className: "github-button-contents", children: "GitHub" })
|
|
269
268
|
] });
|
|
270
269
|
};
|
|
271
270
|
var GoogleButton = ({ disabled, onClick }) => {
|
|
@@ -312,8 +311,8 @@ var GoogleButton = ({ disabled, onClick }) => {
|
|
|
312
311
|
]
|
|
313
312
|
}
|
|
314
313
|
) }),
|
|
315
|
-
/* @__PURE__ */ jsx("span", { className: "gsi-material-button-contents", children: "
|
|
316
|
-
/* @__PURE__ */ jsx("span", { style: { display: "none" }, children: "
|
|
314
|
+
/* @__PURE__ */ jsx("span", { className: "gsi-material-button-contents", children: "Google" }),
|
|
315
|
+
/* @__PURE__ */ jsx("span", { style: { display: "none" }, children: "Google" })
|
|
317
316
|
] })
|
|
318
317
|
] });
|
|
319
318
|
};
|
|
@@ -370,6 +369,7 @@ function LoginModalTemplate({
|
|
|
370
369
|
onCancel,
|
|
371
370
|
onRetry
|
|
372
371
|
}) {
|
|
372
|
+
const [showWalletPicker, setShowWalletPicker] = useState(false);
|
|
373
373
|
const isDark = theme === "dark";
|
|
374
374
|
const enabledSocial = Object.entries(providers).filter(([, enabled]) => enabled);
|
|
375
375
|
const cssVars = {
|
|
@@ -390,16 +390,48 @@ function LoginModalTemplate({
|
|
|
390
390
|
const isEmailCodeError = authState.step === "error" && (authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_EXPIRED || authState.errorCode === AUTH_ERROR_CODES.EMAIL_CODE_INVALID);
|
|
391
391
|
const awaitingEmailCode = authState.step === "entering_code" || authState.step === "verifying_email_code" || isEmailCodeError;
|
|
392
392
|
const statusMessage = authState.step === "error" ? authState.message : AUTH_STATE_MESSAGES[authState.step];
|
|
393
|
+
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" }) }) });
|
|
393
394
|
return /* @__PURE__ */ jsxs("div", { className: "pollar-modal", style: cssVars, onClick: (e) => e.stopPropagation(), children: [
|
|
395
|
+
/* @__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
396
|
/* @__PURE__ */ jsxs("div", { className: "pollar-header", children: [
|
|
395
397
|
/* @__PURE__ */ jsx("div", { className: "pollar-logo-wrap", children: /* @__PURE__ */ jsx("img", { src: logoUrl ?? LOGO_POLLAR, alt: "Logo", className: "pollar-logo" }) }),
|
|
396
398
|
/* @__PURE__ */ jsx("h2", { className: "pollar-title", children: appName }),
|
|
397
399
|
/* @__PURE__ */ jsx("p", { className: "pollar-subtitle", children: "Log in or sign up" })
|
|
398
400
|
] }),
|
|
399
401
|
awaitingEmailCode ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
400
|
-
/* @__PURE__ */ jsx(
|
|
402
|
+
/* @__PURE__ */ jsx(BackButton, { onClick: onBack }),
|
|
401
403
|
/* @__PURE__ */ jsx(EmailCodeInput, { email, onSubmit: onCodeSubmit ?? (() => {
|
|
402
404
|
}) }, codeInputKey)
|
|
405
|
+
] }) : showWalletPicker ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
406
|
+
/* @__PURE__ */ jsx(BackButton, { onClick: () => setShowWalletPicker(false) }),
|
|
407
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-wallet-list", children: [
|
|
408
|
+
/* @__PURE__ */ jsxs(
|
|
409
|
+
"button",
|
|
410
|
+
{
|
|
411
|
+
type: "button",
|
|
412
|
+
disabled: isLoading,
|
|
413
|
+
className: "pollar-wallet-list-btn",
|
|
414
|
+
onClick: onFreighterConnect,
|
|
415
|
+
children: [
|
|
416
|
+
/* @__PURE__ */ jsx("img", { src: LOGO_FREIGHTER, alt: "Freighter", className: "pollar-wallet-list-icon" }),
|
|
417
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-wallet-list-name", children: "Freighter" })
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
),
|
|
421
|
+
/* @__PURE__ */ jsxs(
|
|
422
|
+
"button",
|
|
423
|
+
{
|
|
424
|
+
type: "button",
|
|
425
|
+
disabled: isLoading,
|
|
426
|
+
className: "pollar-wallet-list-btn",
|
|
427
|
+
onClick: onAlbedoConnect,
|
|
428
|
+
children: [
|
|
429
|
+
/* @__PURE__ */ jsx("img", { src: LOGO_ALBEDO, alt: "Albedo", className: "pollar-wallet-list-icon" }),
|
|
430
|
+
/* @__PURE__ */ jsx("span", { className: "pollar-wallet-list-name", children: "Albedo" })
|
|
431
|
+
]
|
|
432
|
+
}
|
|
433
|
+
)
|
|
434
|
+
] })
|
|
403
435
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
404
436
|
emailEnabled && /* @__PURE__ */ jsxs("div", { className: "pollar-email-section", children: [
|
|
405
437
|
/* @__PURE__ */ jsx(
|
|
@@ -424,17 +456,19 @@ function LoginModalTemplate({
|
|
|
424
456
|
enabledSocial.some(([key]) => key === "google") && /* @__PURE__ */ jsx(GoogleButton, { disabled: isLoading, onClick: () => onSocialLogin?.("google") }),
|
|
425
457
|
enabledSocial.some(([key]) => key === "github") && /* @__PURE__ */ jsx(GithubButton, { disabled: isLoading, onClick: () => onSocialLogin?.("github") })
|
|
426
458
|
] }),
|
|
427
|
-
embeddedWallets && /* @__PURE__ */
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
459
|
+
embeddedWallets && /* @__PURE__ */ jsx("div", { className: "pollar-wallet-section", children: /* @__PURE__ */ jsxs(
|
|
460
|
+
"button",
|
|
461
|
+
{
|
|
462
|
+
type: "button",
|
|
463
|
+
disabled: isLoading,
|
|
464
|
+
className: "pollar-wallet-entry-btn",
|
|
465
|
+
onClick: () => setShowWalletPicker(true),
|
|
466
|
+
children: [
|
|
467
|
+
/* @__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" }) }),
|
|
468
|
+
"Wallet"
|
|
469
|
+
]
|
|
470
|
+
}
|
|
471
|
+
) })
|
|
438
472
|
] }),
|
|
439
473
|
/* @__PURE__ */ jsx(
|
|
440
474
|
ModalStatusBanner,
|
|
@@ -525,7 +559,7 @@ function LoginModal({ onClose }) {
|
|
|
525
559
|
codeInputKey,
|
|
526
560
|
onCodeSubmit: handleVerifyCode,
|
|
527
561
|
onBack: handleBack,
|
|
528
|
-
onCancel:
|
|
562
|
+
onCancel: handleClose,
|
|
529
563
|
onRetry: handleRetry
|
|
530
564
|
}
|
|
531
565
|
) });
|
|
@@ -834,12 +868,27 @@ function RampWidget({ onClose }) {
|
|
|
834
868
|
}
|
|
835
869
|
) });
|
|
836
870
|
}
|
|
871
|
+
var STATUS_MESSAGES = {
|
|
872
|
+
idle: "",
|
|
873
|
+
building: "Building transaction\u2026",
|
|
874
|
+
built: "Ready to sign and send",
|
|
875
|
+
signing: "Signing and sending transaction\u2026",
|
|
876
|
+
success: "Transaction sent successfully",
|
|
877
|
+
error: "Transaction failed"
|
|
878
|
+
};
|
|
837
879
|
function TransactionModalTemplate({
|
|
838
880
|
theme,
|
|
839
881
|
accentColor,
|
|
840
882
|
transaction,
|
|
883
|
+
showXdr,
|
|
884
|
+
copied,
|
|
885
|
+
explorerUrl,
|
|
886
|
+
walletType,
|
|
841
887
|
onClose,
|
|
842
|
-
onSignAndSend
|
|
888
|
+
onSignAndSend,
|
|
889
|
+
onToggleXdr,
|
|
890
|
+
onCopyHash,
|
|
891
|
+
onRetry
|
|
843
892
|
}) {
|
|
844
893
|
const isDark = theme === "dark";
|
|
845
894
|
const cssVars = {
|
|
@@ -854,8 +903,6 @@ function TransactionModalTemplate({
|
|
|
854
903
|
"--pollar-error-text": isDark ? "#f87171" : "#dc2626",
|
|
855
904
|
"--pollar-success-text": isDark ? "#4ade80" : "#16a34a"
|
|
856
905
|
};
|
|
857
|
-
const [showXdr, setShowXdr] = useState(false);
|
|
858
|
-
const [copied, setCopied] = useState(false);
|
|
859
906
|
const buildData = "buildData" in transaction ? transaction.buildData : null;
|
|
860
907
|
const hash = transaction.step === "success" ? transaction.hash : null;
|
|
861
908
|
const errorDetails = transaction.step === "error" ? transaction.details ?? null : null;
|
|
@@ -864,28 +911,23 @@ function TransactionModalTemplate({
|
|
|
864
911
|
const isSuccess = transaction.step === "success";
|
|
865
912
|
const isError = transaction.step === "error";
|
|
866
913
|
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
914
|
return /* @__PURE__ */ jsxs("div", { className: "pollar-tx-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
|
|
885
|
-
/* @__PURE__ */
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
915
|
+
/* @__PURE__ */ jsx("div", { className: "pollar-modal-header", children: /* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: "Transaction" }) }),
|
|
916
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pollar-close-btn", onClick: onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx(
|
|
917
|
+
"svg",
|
|
918
|
+
{
|
|
919
|
+
width: "18",
|
|
920
|
+
height: "18",
|
|
921
|
+
viewBox: "0 0 24 24",
|
|
922
|
+
fill: "none",
|
|
923
|
+
stroke: "currentColor",
|
|
924
|
+
strokeWidth: "2.5",
|
|
925
|
+
strokeLinecap: "round",
|
|
926
|
+
strokeLinejoin: "round",
|
|
927
|
+
"aria-hidden": true,
|
|
928
|
+
children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" })
|
|
929
|
+
}
|
|
930
|
+
) }),
|
|
889
931
|
showDetails && buildData && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
890
932
|
/* @__PURE__ */ jsxs("div", { className: "pollar-tx-summary", children: [
|
|
891
933
|
/* @__PURE__ */ jsx("p", { className: "pollar-tx-summary-title", children: "Details" }),
|
|
@@ -902,7 +944,7 @@ function TransactionModalTemplate({
|
|
|
902
944
|
] })
|
|
903
945
|
] }),
|
|
904
946
|
/* @__PURE__ */ jsxs("div", { className: "pollar-tx-xdr", children: [
|
|
905
|
-
/* @__PURE__ */ jsxs("button", { className: "pollar-tx-xdr-toggle", onClick:
|
|
947
|
+
/* @__PURE__ */ jsxs("button", { className: "pollar-tx-xdr-toggle", onClick: onToggleXdr, children: [
|
|
906
948
|
/* @__PURE__ */ jsx(
|
|
907
949
|
"svg",
|
|
908
950
|
{
|
|
@@ -920,48 +962,147 @@ function TransactionModalTemplate({
|
|
|
920
962
|
showXdr && /* @__PURE__ */ jsx("pre", { className: "pollar-tx-xdr-content", children: buildData.unsignedXdr })
|
|
921
963
|
] })
|
|
922
964
|
] }),
|
|
965
|
+
isError && errorDetails && /* @__PURE__ */ jsxs("div", { className: "pollar-tx-error-details", children: [
|
|
966
|
+
/* @__PURE__ */ jsx("p", { className: "pollar-tx-error-details-label", children: "Error details" }),
|
|
967
|
+
/* @__PURE__ */ jsx("pre", { className: "pollar-tx-error-details-content", children: errorDetails })
|
|
968
|
+
] }),
|
|
969
|
+
isBuilt && /* @__PURE__ */ jsx("button", { className: "pollar-btn-primary pollar-tx-sign-btn", onClick: onSignAndSend, children: "Sign & Send" }),
|
|
970
|
+
(isSigning || isSuccess || isError) && /* @__PURE__ */ jsxs("div", { className: "pollar-tx-wallet-spinner", children: [
|
|
971
|
+
/* @__PURE__ */ jsxs("div", { className: "pollar-tx-spinner-ring", children: [
|
|
972
|
+
/* @__PURE__ */ jsxs(
|
|
973
|
+
"svg",
|
|
974
|
+
{
|
|
975
|
+
viewBox: "0 0 88 88",
|
|
976
|
+
width: "88",
|
|
977
|
+
height: "88",
|
|
978
|
+
className: `pollar-tx-spinner-svg${isSigning ? " pollar-tx-spinner-rotating" : ""}`,
|
|
979
|
+
"aria-hidden": true,
|
|
980
|
+
children: [
|
|
981
|
+
/* @__PURE__ */ jsx("circle", { cx: "44", cy: "44", r: "36", fill: "none", stroke: "var(--pollar-border)", strokeWidth: "3" }),
|
|
982
|
+
/* @__PURE__ */ jsx(
|
|
983
|
+
"circle",
|
|
984
|
+
{
|
|
985
|
+
cx: "44",
|
|
986
|
+
cy: "44",
|
|
987
|
+
r: "36",
|
|
988
|
+
fill: "none",
|
|
989
|
+
stroke: isSuccess ? "var(--pollar-success-text)" : isError ? "var(--pollar-error-text)" : "var(--pollar-accent)",
|
|
990
|
+
strokeWidth: "3",
|
|
991
|
+
strokeLinecap: "round",
|
|
992
|
+
strokeDasharray: isSigning ? "169.6 56.6" : "999 0",
|
|
993
|
+
transform: "rotate(-90 44 44)",
|
|
994
|
+
style: { transition: isSigning ? "none" : "stroke 400ms, stroke-dasharray 400ms" }
|
|
995
|
+
}
|
|
996
|
+
)
|
|
997
|
+
]
|
|
998
|
+
}
|
|
999
|
+
),
|
|
1000
|
+
/* @__PURE__ */ jsx("div", { className: "pollar-tx-wallet-icon", children: /* @__PURE__ */ jsx(
|
|
1001
|
+
"img",
|
|
1002
|
+
{
|
|
1003
|
+
src: walletType === WalletType.FREIGHTER ? LOGO_FREIGHTER : walletType === WalletType.ALBEDO ? LOGO_ALBEDO : LOGO_POLLAR,
|
|
1004
|
+
alt: walletType === WalletType.FREIGHTER ? "Freighter" : walletType === WalletType.ALBEDO ? "Albedo" : "Pollar",
|
|
1005
|
+
className: "pollar-tx-wallet-img"
|
|
1006
|
+
}
|
|
1007
|
+
) })
|
|
1008
|
+
] }),
|
|
1009
|
+
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" }),
|
|
1010
|
+
isError && onRetry && "buildData" in transaction && transaction.buildData && /* @__PURE__ */ jsx("button", { className: "pollar-btn-secondary pollar-tx-retry-btn", onClick: onRetry, children: "Try again" })
|
|
1011
|
+
] }),
|
|
923
1012
|
isSuccess && hash && /* @__PURE__ */ jsxs("div", { className: "pollar-tx-result", children: [
|
|
924
1013
|
/* @__PURE__ */ jsx("span", { className: "pollar-tx-result-label", children: "Transaction hash" }),
|
|
925
1014
|
/* @__PURE__ */ jsx("span", { className: "pollar-tx-result-hash", children: hash }),
|
|
926
1015
|
/* @__PURE__ */ jsxs("div", { className: "pollar-tx-result-actions", children: [
|
|
927
|
-
/* @__PURE__ */ jsx("button", { className: "pollar-tx-result-btn", onClick:
|
|
1016
|
+
/* @__PURE__ */ jsx("button", { className: "pollar-tx-result-btn", onClick: onCopyHash, children: copied ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
928
1017
|
/* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: [
|
|
929
1018
|
/* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "7", fill: "currentColor" }),
|
|
930
|
-
/* @__PURE__ */ jsx(
|
|
1019
|
+
/* @__PURE__ */ jsx(
|
|
1020
|
+
"path",
|
|
1021
|
+
{
|
|
1022
|
+
d: "M3.5 7l2.5 2.5 4.5-5",
|
|
1023
|
+
stroke: "white",
|
|
1024
|
+
strokeWidth: "1.5",
|
|
1025
|
+
strokeLinecap: "round",
|
|
1026
|
+
strokeLinejoin: "round"
|
|
1027
|
+
}
|
|
1028
|
+
)
|
|
931
1029
|
] }),
|
|
932
1030
|
"Copied!"
|
|
933
1031
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
934
1032
|
/* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 13 13", fill: "none", "aria-hidden": true, children: [
|
|
935
1033
|
/* @__PURE__ */ jsx("rect", { x: "4", y: "4", width: "8", height: "8", rx: "1.5", stroke: "currentColor", strokeWidth: "1.5" }),
|
|
936
|
-
/* @__PURE__ */ jsx(
|
|
1034
|
+
/* @__PURE__ */ jsx(
|
|
1035
|
+
"path",
|
|
1036
|
+
{
|
|
1037
|
+
d: "M3 9H2a1 1 0 01-1-1V2a1 1 0 011-1h6a1 1 0 011 1v1",
|
|
1038
|
+
stroke: "currentColor",
|
|
1039
|
+
strokeWidth: "1.5",
|
|
1040
|
+
strokeLinecap: "round"
|
|
1041
|
+
}
|
|
1042
|
+
)
|
|
937
1043
|
] }),
|
|
938
1044
|
"Copy hash"
|
|
939
1045
|
] }) }),
|
|
940
1046
|
explorerUrl && /* @__PURE__ */ jsxs("a", { className: "pollar-tx-result-btn", href: explorerUrl, target: "_blank", rel: "noopener noreferrer", children: [
|
|
941
1047
|
/* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 13 13", fill: "none", "aria-hidden": true, children: [
|
|
942
|
-
/* @__PURE__ */ jsx(
|
|
943
|
-
|
|
1048
|
+
/* @__PURE__ */ jsx(
|
|
1049
|
+
"path",
|
|
1050
|
+
{
|
|
1051
|
+
d: "M5 2H2a1 1 0 00-1 1v8a1 1 0 001 1h8a1 1 0 001-1V8",
|
|
1052
|
+
stroke: "currentColor",
|
|
1053
|
+
strokeWidth: "1.5",
|
|
1054
|
+
strokeLinecap: "round"
|
|
1055
|
+
}
|
|
1056
|
+
),
|
|
1057
|
+
/* @__PURE__ */ jsx(
|
|
1058
|
+
"path",
|
|
1059
|
+
{
|
|
1060
|
+
d: "M8 1h4m0 0v4m0-4L6 7",
|
|
1061
|
+
stroke: "currentColor",
|
|
1062
|
+
strokeWidth: "1.5",
|
|
1063
|
+
strokeLinecap: "round",
|
|
1064
|
+
strokeLinejoin: "round"
|
|
1065
|
+
}
|
|
1066
|
+
)
|
|
944
1067
|
] }),
|
|
945
1068
|
"View on Explorer"
|
|
946
1069
|
] })
|
|
947
1070
|
] })
|
|
948
1071
|
] }),
|
|
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
1072
|
isSuccess && /* @__PURE__ */ jsx("button", { className: "pollar-btn-primary pollar-tx-sign-btn", onClick: onClose, children: "Done" }),
|
|
956
|
-
/* @__PURE__ */ jsx(
|
|
1073
|
+
/* @__PURE__ */ jsx(
|
|
1074
|
+
ModalStatusBanner,
|
|
1075
|
+
{
|
|
1076
|
+
message: STATUS_MESSAGES[transaction.step],
|
|
1077
|
+
status: isError ? "ERROR" : isSigning || transaction.step === "building" ? "LOADING" : isSuccess ? "SUCCESS" : "NONE"
|
|
1078
|
+
}
|
|
1079
|
+
),
|
|
957
1080
|
/* @__PURE__ */ jsx(PollarModalFooter, {})
|
|
958
1081
|
] });
|
|
959
1082
|
}
|
|
960
1083
|
function TransactionModal({ onClose }) {
|
|
961
|
-
const { getClient, styles, transaction } = usePollar();
|
|
1084
|
+
const { getClient, styles, transaction, network, walletType } = usePollar();
|
|
962
1085
|
const { theme = "light", accentColor = "#005DB4" } = styles;
|
|
963
|
-
|
|
1086
|
+
const [showXdr, setShowXdr] = useState(false);
|
|
1087
|
+
const [copied, setCopied] = useState(false);
|
|
1088
|
+
const hash = transaction.step === "success" ? transaction.hash : null;
|
|
1089
|
+
const buildData = "buildData" in transaction ? transaction.buildData : null;
|
|
1090
|
+
const explorerNetwork = buildData?.summary.network?.toLowerCase().includes("testnet") ? "testnet" : "public";
|
|
1091
|
+
const explorerUrl = hash ? `https://stellar.expert/explorer/${explorerNetwork}/tx/${hash}` : null;
|
|
1092
|
+
function handleSignAndSend() {
|
|
964
1093
|
if (transaction.step === "built") {
|
|
1094
|
+
void getClient().signAndSubmitTx(transaction.buildData.unsignedXdr);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
function handleCopyHash() {
|
|
1098
|
+
if (!hash) return;
|
|
1099
|
+
navigator.clipboard.writeText(hash).then(() => {
|
|
1100
|
+
setCopied(true);
|
|
1101
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
async function handleRetry() {
|
|
1105
|
+
if (transaction.step === "error" && transaction.buildData) {
|
|
965
1106
|
await getClient().signAndSubmitTx(transaction.buildData.unsignedXdr);
|
|
966
1107
|
}
|
|
967
1108
|
}
|
|
@@ -971,8 +1112,15 @@ function TransactionModal({ onClose }) {
|
|
|
971
1112
|
theme,
|
|
972
1113
|
accentColor,
|
|
973
1114
|
transaction,
|
|
1115
|
+
showXdr,
|
|
1116
|
+
copied,
|
|
1117
|
+
explorerUrl,
|
|
1118
|
+
walletType,
|
|
974
1119
|
onClose,
|
|
975
|
-
onSignAndSend: handleSignAndSend
|
|
1120
|
+
onSignAndSend: handleSignAndSend,
|
|
1121
|
+
onToggleXdr: () => setShowXdr((v) => !v),
|
|
1122
|
+
onCopyHash: handleCopyHash,
|
|
1123
|
+
onRetry: handleRetry
|
|
976
1124
|
}
|
|
977
1125
|
) });
|
|
978
1126
|
}
|
|
@@ -1127,9 +1275,14 @@ function BalanceItem({ record }) {
|
|
|
1127
1275
|
] })
|
|
1128
1276
|
] });
|
|
1129
1277
|
}
|
|
1130
|
-
function
|
|
1131
|
-
|
|
1132
|
-
|
|
1278
|
+
function WalletBalanceModalTemplate({
|
|
1279
|
+
theme,
|
|
1280
|
+
accentColor,
|
|
1281
|
+
walletBalance,
|
|
1282
|
+
walletAddress,
|
|
1283
|
+
onRefresh,
|
|
1284
|
+
onClose
|
|
1285
|
+
}) {
|
|
1133
1286
|
const isDark = theme === "dark";
|
|
1134
1287
|
const cssVars = {
|
|
1135
1288
|
"--pollar-accent": accentColor,
|
|
@@ -1140,27 +1293,13 @@ function WalletBalanceModal({ onClose }) {
|
|
|
1140
1293
|
"--pollar-input-bg": isDark ? "#374151" : "rgba(0,0,0,0.04)",
|
|
1141
1294
|
"--pollar-error-text": isDark ? "#f87171" : "#dc2626"
|
|
1142
1295
|
};
|
|
1143
|
-
const
|
|
1144
|
-
const
|
|
1145
|
-
|
|
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: [
|
|
1296
|
+
const isLoading = walletBalance.step === "loading";
|
|
1297
|
+
const data = walletBalance.step === "loaded" ? walletBalance.data : null;
|
|
1298
|
+
return /* @__PURE__ */ jsxs("div", { className: "pollar-bal-modal", "data-theme": theme, style: cssVars, onClick: (e) => e.stopPropagation(), children: [
|
|
1160
1299
|
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header", children: [
|
|
1161
1300
|
/* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: "Wallet Balance" }),
|
|
1162
1301
|
/* @__PURE__ */ jsxs("div", { className: "pollar-modal-header-actions", children: [
|
|
1163
|
-
/* @__PURE__ */ jsxs("button", { className: "pollar-modal-refresh-btn", onClick:
|
|
1302
|
+
/* @__PURE__ */ jsxs("button", { className: "pollar-modal-refresh-btn", onClick: onRefresh, disabled: isLoading, children: [
|
|
1164
1303
|
/* @__PURE__ */ jsxs(
|
|
1165
1304
|
"svg",
|
|
1166
1305
|
{
|
|
@@ -1183,16 +1322,34 @@ function WalletBalanceModal({ onClose }) {
|
|
|
1183
1322
|
] }),
|
|
1184
1323
|
walletAddress && /* @__PURE__ */ jsx("div", { className: "pollar-bal-address", children: cropAddress(walletAddress) }),
|
|
1185
1324
|
isLoading && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: "Loading\u2026" }),
|
|
1186
|
-
|
|
1187
|
-
|
|
1325
|
+
walletBalance.step === "error" && /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: walletBalance.message }),
|
|
1326
|
+
data && !data.exists && /* @__PURE__ */ jsxs("div", { className: "pollar-modal-empty", children: [
|
|
1188
1327
|
"Account not found on ",
|
|
1189
1328
|
data.network,
|
|
1190
1329
|
"."
|
|
1191
1330
|
] }),
|
|
1192
|
-
|
|
1193
|
-
|
|
1331
|
+
data?.exists && data.balances.length === 0 && /* @__PURE__ */ jsx("div", { className: "pollar-modal-empty", children: "No balances found." }),
|
|
1332
|
+
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
1333
|
/* @__PURE__ */ jsx(PollarModalFooter, {})
|
|
1195
|
-
] })
|
|
1334
|
+
] });
|
|
1335
|
+
}
|
|
1336
|
+
function WalletBalanceModal({ onClose }) {
|
|
1337
|
+
const { walletBalance, refreshBalance, walletAddress, styles } = usePollar();
|
|
1338
|
+
const { theme = "light", accentColor = "#005DB4" } = styles;
|
|
1339
|
+
useEffect(() => {
|
|
1340
|
+
void refreshBalance();
|
|
1341
|
+
}, []);
|
|
1342
|
+
return /* @__PURE__ */ jsx("div", { className: "pollar-overlay", onClick: onClose, children: /* @__PURE__ */ jsx(
|
|
1343
|
+
WalletBalanceModalTemplate,
|
|
1344
|
+
{
|
|
1345
|
+
theme,
|
|
1346
|
+
accentColor,
|
|
1347
|
+
walletBalance,
|
|
1348
|
+
walletAddress,
|
|
1349
|
+
onRefresh: () => refreshBalance(),
|
|
1350
|
+
onClose
|
|
1351
|
+
}
|
|
1352
|
+
) });
|
|
1196
1353
|
}
|
|
1197
1354
|
var emptyResponse = {
|
|
1198
1355
|
application: {
|
|
@@ -1208,13 +1365,10 @@ var PollarContext = createContext(null);
|
|
|
1208
1365
|
function PollarProvider({ config, styles: propStyles, children }) {
|
|
1209
1366
|
const [pollarClient] = useState(() => new PollarClient(config));
|
|
1210
1367
|
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
1368
|
const [sessionState, setSessionState] = useState(null);
|
|
1216
1369
|
const [transaction, setTransaction] = useState({ step: "idle" });
|
|
1217
1370
|
const [txHistory, setTxHistory] = useState({ step: "idle" });
|
|
1371
|
+
const [walletBalance, setWalletBalance] = useState({ step: "idle" });
|
|
1218
1372
|
const [remoteConfig, setRemoteConfig] = useState(emptyResponse);
|
|
1219
1373
|
const [styles, setStyles] = useState(propStyles ?? {});
|
|
1220
1374
|
useEffect(() => {
|
|
@@ -1223,6 +1377,9 @@ function PollarProvider({ config, styles: propStyles, children }) {
|
|
|
1223
1377
|
useEffect(() => {
|
|
1224
1378
|
return pollarClient.onTxHistoryStateChange(setTxHistory);
|
|
1225
1379
|
}, [pollarClient]);
|
|
1380
|
+
useEffect(() => {
|
|
1381
|
+
return pollarClient.onWalletBalanceStateChange(setWalletBalance);
|
|
1382
|
+
}, [pollarClient]);
|
|
1226
1383
|
useEffect(() => {
|
|
1227
1384
|
return pollarClient.onNetworkStateChange((state) => {
|
|
1228
1385
|
setNetworkState(state);
|
|
@@ -1263,14 +1420,15 @@ function PollarProvider({ config, styles: propStyles, children }) {
|
|
|
1263
1420
|
const [walletBalanceModalOpen, setWalletBalanceModalOpen] = useState(false);
|
|
1264
1421
|
const contextValue = useMemo(
|
|
1265
1422
|
() => ({
|
|
1266
|
-
walletAddress: sessionState?.wallet?.publicKey || "",
|
|
1423
|
+
walletAddress: sessionState?.data?.providers?.wallet?.address || sessionState?.wallet?.publicKey || "",
|
|
1267
1424
|
getClient: () => pollarClient,
|
|
1268
1425
|
transaction,
|
|
1269
1426
|
login: (options) => pollarClient.login(options),
|
|
1270
1427
|
logout: () => pollarClient.logout(),
|
|
1271
1428
|
isAuthenticated: !!sessionState?.wallet?.publicKey,
|
|
1272
1429
|
buildTx: (operation, params, options) => pollarClient.buildTx(operation, params, options),
|
|
1273
|
-
signAndSubmitTx: (
|
|
1430
|
+
signAndSubmitTx: (unsignedXdr) => pollarClient.signAndSubmitTx(unsignedXdr),
|
|
1431
|
+
walletType: pollarClient.getWalletType(),
|
|
1274
1432
|
openTransactionModal: () => setTransactionModalOpen(true),
|
|
1275
1433
|
openLoginModal: () => setLoginModalOpen(true),
|
|
1276
1434
|
openKycModal: (options = {}) => {
|
|
@@ -1281,13 +1439,14 @@ function PollarProvider({ config, styles: propStyles, children }) {
|
|
|
1281
1439
|
txHistory,
|
|
1282
1440
|
openTxHistoryModal: () => setTxHistoryModalOpen(true),
|
|
1283
1441
|
openWalletBalanceModal: () => setWalletBalanceModalOpen(true),
|
|
1442
|
+
walletBalance,
|
|
1443
|
+
refreshBalance: (publicKey) => pollarClient.refreshBalance(publicKey),
|
|
1284
1444
|
network: networkState.step === "connected" ? networkState.network : "testnet",
|
|
1285
1445
|
setNetwork: (network) => pollarClient.setNetwork(network),
|
|
1286
1446
|
config: remoteConfig,
|
|
1287
|
-
styles
|
|
1288
|
-
getBalance: (publicKey) => pollarClient.getWalletBalance(publicKey)
|
|
1447
|
+
styles
|
|
1289
1448
|
}),
|
|
1290
|
-
[sessionState, remoteConfig, styles, pollarClient, transaction, txHistory, networkState,
|
|
1449
|
+
[sessionState, remoteConfig, styles, pollarClient, transaction, txHistory, networkState, walletBalance]
|
|
1291
1450
|
);
|
|
1292
1451
|
return /* @__PURE__ */ jsxs(PollarContext.Provider, { value: contextValue, children: [
|
|
1293
1452
|
children,
|
|
@@ -1314,50 +1473,37 @@ function usePollar() {
|
|
|
1314
1473
|
}
|
|
1315
1474
|
return ctx;
|
|
1316
1475
|
}
|
|
1476
|
+
function ButtonLogo() {
|
|
1477
|
+
return /* @__PURE__ */ jsx("img", { src: LOGO_POLLAR, alt: "Pollar", width: 22, height: 22, className: "wallet-btn-logo" });
|
|
1478
|
+
}
|
|
1317
1479
|
function cropWallet(address) {
|
|
1318
1480
|
if (address.length <= 12) return address;
|
|
1319
1481
|
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
1320
1482
|
}
|
|
1321
|
-
function
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
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
|
-
}
|
|
1483
|
+
function WalletButtonTemplate({
|
|
1484
|
+
walletAddress,
|
|
1485
|
+
accentColor,
|
|
1486
|
+
open,
|
|
1487
|
+
copied,
|
|
1488
|
+
dropdownBg,
|
|
1489
|
+
dropdownBorder,
|
|
1490
|
+
itemColor,
|
|
1491
|
+
wrapperRef,
|
|
1492
|
+
onToggleOpen,
|
|
1493
|
+
onCopy,
|
|
1494
|
+
onWalletBalance,
|
|
1495
|
+
onTxHistory,
|
|
1496
|
+
onLogout,
|
|
1497
|
+
onLogin
|
|
1498
|
+
}) {
|
|
1353
1499
|
if (!walletAddress) {
|
|
1354
|
-
return /* @__PURE__ */ jsxs("button", { type: "button", className: "wallet-login-btn", style: { backgroundColor: accentColor }, onClick:
|
|
1500
|
+
return /* @__PURE__ */ jsxs("button", { type: "button", className: "wallet-login-btn", style: { backgroundColor: accentColor }, onClick: onLogin, children: [
|
|
1355
1501
|
/* @__PURE__ */ jsx(ButtonLogo, {}),
|
|
1356
1502
|
"Login with Pollar"
|
|
1357
1503
|
] });
|
|
1358
1504
|
}
|
|
1359
1505
|
return /* @__PURE__ */ jsxs("div", { className: "wallet-wrapper", ref: wrapperRef, children: [
|
|
1360
|
-
/* @__PURE__ */ jsxs("button", { className: "wallet-btn", style: { backgroundColor: accentColor }, onClick:
|
|
1506
|
+
/* @__PURE__ */ jsxs("button", { className: "wallet-btn", style: { backgroundColor: accentColor }, onClick: onToggleOpen, children: [
|
|
1361
1507
|
cropWallet(walletAddress),
|
|
1362
1508
|
/* @__PURE__ */ jsx(
|
|
1363
1509
|
"svg",
|
|
@@ -1374,7 +1520,7 @@ function WalletButton() {
|
|
|
1374
1520
|
)
|
|
1375
1521
|
] }),
|
|
1376
1522
|
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:
|
|
1523
|
+
/* @__PURE__ */ jsxs("button", { className: "wallet-dropdown-item", style: { color: itemColor }, onClick: onCopy, children: [
|
|
1378
1524
|
/* @__PURE__ */ jsxs(
|
|
1379
1525
|
"svg",
|
|
1380
1526
|
{
|
|
@@ -1399,10 +1545,7 @@ function WalletButton() {
|
|
|
1399
1545
|
{
|
|
1400
1546
|
className: "wallet-dropdown-item",
|
|
1401
1547
|
style: { color: itemColor },
|
|
1402
|
-
onClick:
|
|
1403
|
-
setOpen(false);
|
|
1404
|
-
openWalletBalanceModal();
|
|
1405
|
-
},
|
|
1548
|
+
onClick: onWalletBalance,
|
|
1406
1549
|
children: [
|
|
1407
1550
|
/* @__PURE__ */ jsxs(
|
|
1408
1551
|
"svg",
|
|
@@ -1431,10 +1574,7 @@ function WalletButton() {
|
|
|
1431
1574
|
{
|
|
1432
1575
|
className: "wallet-dropdown-item",
|
|
1433
1576
|
style: { color: itemColor },
|
|
1434
|
-
onClick:
|
|
1435
|
-
setOpen(false);
|
|
1436
|
-
openTxHistoryModal();
|
|
1437
|
-
},
|
|
1577
|
+
onClick: onTxHistory,
|
|
1438
1578
|
children: [
|
|
1439
1579
|
/* @__PURE__ */ jsxs(
|
|
1440
1580
|
"svg",
|
|
@@ -1460,7 +1600,7 @@ function WalletButton() {
|
|
|
1460
1600
|
]
|
|
1461
1601
|
}
|
|
1462
1602
|
),
|
|
1463
|
-
/* @__PURE__ */ jsxs("button", { className: "wallet-dropdown-item danger", onClick:
|
|
1603
|
+
/* @__PURE__ */ jsxs("button", { className: "wallet-dropdown-item danger", onClick: onLogout, children: [
|
|
1464
1604
|
/* @__PURE__ */ jsxs(
|
|
1465
1605
|
"svg",
|
|
1466
1606
|
{
|
|
@@ -1484,7 +1624,64 @@ function WalletButton() {
|
|
|
1484
1624
|
] })
|
|
1485
1625
|
] });
|
|
1486
1626
|
}
|
|
1627
|
+
function WalletButton() {
|
|
1628
|
+
const { getClient, walletAddress, styles, openLoginModal, openTxHistoryModal, openWalletBalanceModal } = usePollar();
|
|
1629
|
+
const [open, setOpen] = useState(false);
|
|
1630
|
+
const [copied, setCopied] = useState(false);
|
|
1631
|
+
const wrapperRef = useRef(null);
|
|
1632
|
+
const { theme = "light", accentColor = "#005DB4" } = styles;
|
|
1633
|
+
const isDark = theme === "dark";
|
|
1634
|
+
const dropdownBg = isDark ? "#18181b" : "#fff";
|
|
1635
|
+
const dropdownBorder = isDark ? "#3f3f46" : "#e4e4e7";
|
|
1636
|
+
const itemColor = isDark ? "#fafafa" : "#18181b";
|
|
1637
|
+
useEffect(() => {
|
|
1638
|
+
function handleClickOutside(e) {
|
|
1639
|
+
if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
|
|
1640
|
+
setOpen(false);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
1644
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
1645
|
+
}, []);
|
|
1646
|
+
async function handleCopy() {
|
|
1647
|
+
if (!walletAddress) return;
|
|
1648
|
+
await navigator.clipboard.writeText(walletAddress);
|
|
1649
|
+
setCopied(true);
|
|
1650
|
+
setTimeout(() => setCopied(false), 1500);
|
|
1651
|
+
}
|
|
1652
|
+
function handleLogout() {
|
|
1653
|
+
setOpen(false);
|
|
1654
|
+
getClient().logout();
|
|
1655
|
+
}
|
|
1656
|
+
function handleWalletBalance() {
|
|
1657
|
+
setOpen(false);
|
|
1658
|
+
openWalletBalanceModal();
|
|
1659
|
+
}
|
|
1660
|
+
function handleTxHistory() {
|
|
1661
|
+
setOpen(false);
|
|
1662
|
+
openTxHistoryModal();
|
|
1663
|
+
}
|
|
1664
|
+
return /* @__PURE__ */ jsx(
|
|
1665
|
+
WalletButtonTemplate,
|
|
1666
|
+
{
|
|
1667
|
+
walletAddress: walletAddress ?? null,
|
|
1668
|
+
accentColor,
|
|
1669
|
+
open,
|
|
1670
|
+
copied,
|
|
1671
|
+
dropdownBg,
|
|
1672
|
+
dropdownBorder,
|
|
1673
|
+
itemColor,
|
|
1674
|
+
wrapperRef,
|
|
1675
|
+
onToggleOpen: () => setOpen((v) => !v),
|
|
1676
|
+
onCopy: handleCopy,
|
|
1677
|
+
onWalletBalance: handleWalletBalance,
|
|
1678
|
+
onTxHistory: handleTxHistory,
|
|
1679
|
+
onLogout: handleLogout,
|
|
1680
|
+
onLogin: openLoginModal
|
|
1681
|
+
}
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1487
1684
|
|
|
1488
|
-
export { KycModal, KycStatus, PollarProvider, RampWidget, RouteDisplay, WalletButton, usePollar };
|
|
1685
|
+
export { KycModal, KycModalTemplate, KycStatus, LoginModalTemplate, PollarProvider, RampWidget, RampWidgetTemplate, RouteDisplay, TransactionModalTemplate, TxHistoryModalTemplate, WalletBalanceModal, WalletBalanceModalTemplate, WalletButton, usePollar };
|
|
1489
1686
|
//# sourceMappingURL=index.mjs.map
|
|
1490
1687
|
//# sourceMappingURL=index.mjs.map
|