UNPKG

@roochnetwork/rooch-sdk-kit

Version:
1,308 lines (1,220 loc) 86.7 kB
// src/components/DropdownMenu.tsx import clsx10 from "clsx"; import { useCallback as useCallback4, useEffect as useEffect10, useState as useState14 } from "react"; import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; import { ErrorValidateCantPayGasDeposit } from "@roochnetwork/rooch-sdk"; // src/components/DropdownMenu.css.ts var addressContainer = "DropdownMenu_addressContainer__uignk48"; var connectedAddress = "DropdownMenu_connectedAddress__uignk40"; var menuContainer = "DropdownMenu_menuContainer__uignk41"; var menuContent = "DropdownMenu_menuContent__uignk42"; var menuItem = "DropdownMenu_menuItem__uignk43"; var menuItemText = "DropdownMenu_menuItemText__uignk44"; var progressBar = "DropdownMenu_progressBar__uignk47"; var rgasBalance = "DropdownMenu_rgasBalance__uignk49"; var switchMenuItem = "DropdownMenu_switchMenuItem__uignk45"; // src/components/ui/Text.tsx import { Slot } from "@radix-ui/react-slot"; import clsx from "clsx"; import { forwardRef } from "react"; // src/components/ui/Text.css.ts import { createRuntimeFn as _7a468 } from "@vanilla-extract/recipes/createRuntimeFn"; var textVariants = _7a468({ defaultClassName: "Text__1utg4wj0", variantClassNames: { size: { sm: "Text_textVariants_size_sm__1utg4wj1" }, weight: { normal: "Text_textVariants_weight_normal__1utg4wj2", medium: "Text_textVariants_weight_medium__1utg4wj3", bold: "Text_textVariants_weight_bold__1utg4wj4" }, color: { muted: "Text_textVariants_color_muted__1utg4wj5", danger: "Text_textVariants_color_danger__1utg4wj6", warning: "Text_textVariants_color_warning__1utg4wj7" }, mono: { true: "Text_textVariants_mono_true__1utg4wj8" } }, defaultVariants: { size: "sm", weight: "normal" }, compoundVariants: [] }); // src/components/ui/Text.tsx import { jsx } from "react/jsx-runtime"; var Text = forwardRef( ({ children, className, asChild = false, as: Tag = "div", size, weight, color, mono, ...textProps }, forwardedRef) => { return /* @__PURE__ */ jsx( Slot, { ...textProps, ref: forwardedRef, className: clsx(textVariants({ size, weight, color, mono }), className), children: asChild ? children : /* @__PURE__ */ jsx(Tag, { children }) } ); } ); Text.displayName = "Text"; // src/components/ui/Button.tsx import { Slot as Slot2 } from "@radix-ui/react-slot"; import clsx2 from "clsx"; import { forwardRef as forwardRef2 } from "react"; // src/components/ui/Button.css.ts import { createRuntimeFn as _7a4682 } from "@vanilla-extract/recipes/createRuntimeFn"; var buttonVariants = _7a4682({ defaultClassName: "Button_buttonVariants__1vdhm2g0", variantClassNames: { variant: { primary: "Button_buttonVariants_variant_primary__1vdhm2g1", outline: "Button_buttonVariants_variant_outline__1vdhm2g2" }, size: { md: "Button_buttonVariants_size_md__1vdhm2g3", lg: "Button_buttonVariants_size_lg__1vdhm2g4" } }, defaultVariants: { variant: "primary", size: "md" }, compoundVariants: [] }); // src/components/ui/Button.tsx import { jsx as jsx2 } from "react/jsx-runtime"; var Button = forwardRef2( ({ className, variant, size, asChild = false, ...props }, forwardedRef) => { const Comp = asChild ? Slot2 : "button"; return /* @__PURE__ */ jsx2( Comp, { ...props, className: clsx2(buttonVariants({ variant, size }), className), ref: forwardedRef } ); } ); Button.displayName = "Button"; // src/components/icons/ChevronIcon.tsx import { jsx as jsx3 } from "react/jsx-runtime"; function ChevronIcon(props) { return /* @__PURE__ */ jsx3("svg", { xmlns: "http://www.w3.org/2000/svg", width: 16, height: 16, fill: "none", ...props, children: /* @__PURE__ */ jsx3( "path", { stroke: "#A0B6C3", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, d: "m4 6 4 4 4-4" } ) }); } // src/components/styling/StyleMarker.tsx import { Slot as Slot3 } from "@radix-ui/react-slot"; import { forwardRef as forwardRef3 } from "react"; // src/constants/styleDataAttribute.ts var styleDataAttributeName = "data-sdk-kit"; var styleDataAttributeSelector = `[${styleDataAttributeName}]`; var styleDataAttribute = { [styleDataAttributeName]: "" }; // src/components/styling/StyleMarker.tsx import { jsx as jsx4 } from "react/jsx-runtime"; var StyleMarker = forwardRef3(({ children, ...props }, forwardedRef) => /* @__PURE__ */ jsx4(Slot3, { ref: forwardedRef, ...props, ...styleDataAttribute, children })); StyleMarker.displayName = "StyleMarker"; // src/components/session-modal/SessionModal.tsx import * as Dialog3 from "@radix-ui/react-dialog"; import clsx8 from "clsx"; import { useEffect as useEffect5, useState as useState8 } from "react"; // src/components/icons/BackIcon.tsx import { jsx as jsx5 } from "react/jsx-runtime"; function BackIcon(props) { return /* @__PURE__ */ jsx5("svg", { width: 24, height: 24, fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx5( "path", { d: "M7.57 12.262c0 .341.13.629.403.895l5.175 5.059c.204.205.45.307.751.307.609 0 1.101-.485 1.101-1.087 0-.293-.123-.574-.349-.8L10.14 12.27l4.511-4.375A1.13 1.13 0 0 0 15 7.087C15 6.485 14.508 6 13.9 6c-.295 0-.54.103-.752.308l-5.175 5.058c-.28.28-.404.56-.404.896Z", fill: "currentColor" } ) }); } // src/components/icons/CloseIcon.tsx import { jsx as jsx6 } from "react/jsx-runtime"; function CloseIcon(props) { return /* @__PURE__ */ jsx6("svg", { width: 10, height: 10, fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx6( "path", { d: "M9.708.292a.999.999 0 0 0-1.413 0l-3.289 3.29L1.717.291A.999.999 0 0 0 .305 1.705l3.289 3.289-3.29 3.289a.999.999 0 1 0 1.413 1.412l3.29-3.289 3.288 3.29a.999.999 0 0 0 1.413-1.413l-3.29-3.29 3.29-3.288a.999.999 0 0 0 0-1.413Z", fill: "currentColor" } ) }); } // src/components/ui/Heading.tsx import { Slot as Slot4 } from "@radix-ui/react-slot"; import clsx3 from "clsx"; import { forwardRef as forwardRef4 } from "react"; // src/components/ui/Heading.css.ts import { createRuntimeFn as _7a4683 } from "@vanilla-extract/recipes/createRuntimeFn"; var headingVariants = _7a4683({ defaultClassName: "Heading__1v58k1t0", variantClassNames: { size: { sm: "Heading_headingVariants_size_sm__1v58k1t1", md: "Heading_headingVariants_size_md__1v58k1t2", lg: "Heading_headingVariants_size_lg__1v58k1t3", xl: "Heading_headingVariants_size_xl__1v58k1t4" }, weight: { normal: "Heading_headingVariants_weight_normal__1v58k1t5", bold: "Heading_headingVariants_weight_bold__1v58k1t6" }, truncate: { true: "Heading_headingVariants_truncate_true__1v58k1t7" } }, defaultVariants: { size: "lg", weight: "bold" }, compoundVariants: [] }); // src/components/ui/Heading.tsx import { jsx as jsx7 } from "react/jsx-runtime"; var Heading = forwardRef4( ({ children, className, asChild = false, as: Tag = "h1", size, weight, truncate, ...headingProps }, forwardedRef) => { return /* @__PURE__ */ jsx7( Slot4, { ...headingProps, ref: forwardedRef, className: clsx3(headingVariants({ size, weight, truncate }), className), children: asChild ? children : /* @__PURE__ */ jsx7(Tag, { children }) } ); } ); Heading.displayName = "Heading"; // src/components/ui/IconButton.tsx import { Slot as Slot5 } from "@radix-ui/react-slot"; import clsx4 from "clsx"; import { forwardRef as forwardRef5 } from "react"; // src/components/ui/IconButton.css.ts var container = "IconButton_container__5zr4fg0"; // src/components/ui/IconButton.tsx import { jsx as jsx8 } from "react/jsx-runtime"; var IconButton = forwardRef5( ({ className, asChild = false, ...props }, forwardedRef) => { const Comp = asChild ? Slot5 : "button"; return /* @__PURE__ */ jsx8(Comp, { ...props, className: clsx4(container, className), ref: forwardedRef }); } ); IconButton.displayName = "Button"; // src/components/session-modal/SessionModal.css.ts var backButtonContainer = "SessionModal_backButtonContainer__18jzcrv6"; var closeButtonContainer = "SessionModal_closeButtonContainer__18jzcrv7"; var content = "SessionModal_content__18jzcrv2"; var overlay = "SessionModal_overlay__18jzcrv0"; var selectedViewContainer = "SessionModal_selectedViewContainer__18jzcrv5"; var sessionListContainer = "SessionModal_sessionListContainer__18jzcrv9"; var sessionListContainerWithViewSelected = "SessionModal_sessionListContainerWithViewSelected__18jzcrva"; var sessionListContent = "SessionModal_sessionListContent__18jzcrv8"; var title = "SessionModal_title__18jzcrv1"; var viewContainer = "SessionModal_viewContainer__18jzcrv4"; var whatIsASessionButton = "SessionModal_whatIsASessionButton__18jzcrv3"; // src/components/session-modal/views/WhatIsASessionView.tsx import { useEffect as useEffect2, useState as useState3 } from "react"; import { toShortStr } from "@roochnetwork/rooch-sdk"; // src/components/session-modal/views/WhatIsASessionView.css.ts var actionButtonContainer = "WhatIsASessionView_actionButtonContainer__9cleo57"; var createSessionContainer = "WhatIsASessionView_createSessionContainer__9cleo53"; var createSessionContent = "WhatIsASessionView_createSessionContent__9cleo54"; var createSessionScopeContent = "WhatIsASessionView_createSessionScopeContent__9cleo55"; var createSessionStatus = "WhatIsASessionView_createSessionStatus__9cleo56"; var moreInfo = "WhatIsASessionView_moreInfo__9cleo58"; var sessionItemContent = "WhatIsASessionView_sessionItemContent__9cleo59"; var whatContent = "WhatIsASessionView_whatContent__9cleo51"; var whatMoreContent = "WhatIsASessionView_whatMoreContent__9cleo52"; // src/components/ProgressProvider.tsx import { createContext, useCallback, useContext, useState } from "react"; // src/components/fauct-modal/views/FaucetView.css.ts var container2 = "FaucetView_container__1ff62y00"; var content2 = "FaucetView_content__1ff62y01"; var createButtonContainer = "FaucetView_createButtonContainer__1ff62y02"; var progressBar2 = "FaucetView_progressBar__1ff62y03"; // src/components/ui/Progress.tsx import { jsx as jsx9 } from "react/jsx-runtime"; function Progress() { const { progress } = useProgress(); return /* @__PURE__ */ jsx9("div", { className: progressBar2, style: { width: `${progress}%` } }); } // src/components/ProgressProvider.tsx import { jsx as jsx10, jsxs } from "react/jsx-runtime"; var ProgressProviderContext = createContext(null); var ProgressProvider = ({ children }) => { const [progress, setProgress] = useState(0); const [loading, setLoading] = useState(false); const start = useCallback(() => { setLoading(true); setProgress(0); const interval = setInterval(() => { setProgress((prev) => { const nextProgress = prev + 10; if (nextProgress >= 70) { clearInterval(interval); } return Math.min(nextProgress, 70); }); }, 100); }, []); const finish = useCallback((callback) => { const interval = setInterval(() => { setProgress((prev) => { const nextProgress = prev + 5; if (nextProgress >= 100) { clearInterval(interval); setTimeout(() => { setLoading(false); if (callback) { callback(); } }, 300); } return Math.min(nextProgress, 100); }); }, 50); }, []); return /* @__PURE__ */ jsxs(ProgressProviderContext.Provider, { value: { loading, progress, start, finish }, children: [ children, loading && /* @__PURE__ */ jsx10(Progress, {}) ] }); }; var useProgress = () => { const ctx = useContext(ProgressProviderContext); if (!ctx) { throw new Error("useSubscribeToError must be used within a GlobalProvider"); } return ctx; }; // src/hooks/client/useCurrentNetwork.ts function useCurrentNetwork() { return useRoochContext().network; } // src/hooks/client/useRoochContext.ts import { useContext as useContext5 } from "react"; // src/provider/clientProvider.tsx import { createContext as createContext5, useMemo, useState as useState2 } from "react"; import { getRoochNodeUrl, RoochClient } from "@roochnetwork/rooch-sdk"; // src/hooks/useSessionsStore.ts import { useContext as useContext4 } from "react"; import { useStore as useStore2 } from "zustand"; // src/provider/roochProvider.tsx import { createContext as createContext3, useRef } from "react"; // src/provider/globalProvider.tsx import { createContext as createContext2, useContext as useContext2 } from "react"; import { jsx as jsx11 } from "react/jsx-runtime"; var GlobalContext = createContext2(null); var useSubscribeOnError = () => { const ctx = useContext2(GlobalContext); if (!ctx) { throw new Error("useSubscribeToError must be used within a GlobalProvider"); } return ctx.subscribeOnError; }; var useTriggerError = () => { const ctx = useContext2(GlobalContext); if (!ctx) { throw new Error("useTriggerError must be used within a GlobalProvider"); } return ctx.triggerError; }; var useSubscribeOnRequest = () => { const ctx = useContext2(GlobalContext); if (!ctx) { throw new Error("useSubscribeToError must be used within a GlobalProvider"); } return ctx.subscribeOnRequest; }; var useTriggerRequest = () => { const ctx = useContext2(GlobalContext); if (!ctx) { throw new Error("useTriggerError must be used within a GlobalProvider"); } return ctx.triggerRequest; }; // src/provider/roochProvider.tsx import { jsx as jsx12, jsxs as jsxs2 } from "react/jsx-runtime"; var RoochContext = createContext3(null); // src/provider/walletProvider.tsx import { useCallback as useCallback2, createContext as createContext4, useEffect, useRef as useRef2 } from "react"; import { BitcoinAddress } from "@roochnetwork/rooch-sdk"; // src/hooks/wallet/useWalletStore.ts import { useContext as useContext3 } from "react"; import { useStore } from "zustand"; function useWalletStore(selector) { const store = useContext3(WalletContext); if (!store) { throw new Error("Could not find WalletContext. Ensure that you have set up the WalletProvider."); } return useStore(store, selector); } // src/provider/walletProvider.tsx import { jsx as jsx13 } from "react/jsx-runtime"; var WalletContext = createContext4(null); // src/hooks/useSessionsStore.ts function useSessionStore(selector) { const store = useContext4(RoochContext); if (!store) { throw new Error( "Could not find RoochSessionContext. Ensure that you have set up the RoochClientProvider." ); } return useStore2(store, selector); } // src/provider/clientProvider.tsx import { jsx as jsx14 } from "react/jsx-runtime"; var ClientContext = createContext5(null); var DEFAULT_NETWORKS = { localnet: { url: getRoochNodeUrl("localnet") } }; // src/hooks/client/useRoochContext.ts function useRoochContext() { const context = useContext5(ClientContext); if (!context) { throw new Error( "Could not find RoochClientContext. Ensure that you have set up the RoochClientProvider." ); } return context; } // src/hooks/client/useRoochClient.ts function useRoochClient() { return useRoochContext().client; } // src/constants/roochMutationKeys.ts function formMutationKeyFn(baseEntity) { return function mutationKeyFn(additionalKeys = []) { return [{ ...roochMutationKeys.all, baseEntity }, ...additionalKeys]; }; } var roochMutationKeys = { all: { baseScope: "rooch" }, addNetwork: formMutationKeyFn("add-network"), switchNetwork: formMutationKeyFn("switch-network"), removeNetwork: formMutationKeyFn("remove-network"), removeSession: formMutationKeyFn("remove-session"), transferObject: formMutationKeyFn("transfer-object"), transferCoin: formMutationKeyFn("transfer-coin"), signAndExecuteTransaction: formMutationKeyFn("sign-and-execute-transaction") }; // src/constants/walletMutationKeys.ts function formMutationKeyFn2(baseEntity) { return function mutationKeyFn(additionalKeys = []) { return [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys]; }; } var walletMutationKeys = { all: { baseScope: "wallet" }, connectWallet: formMutationKeyFn2("connect-wallet"), autoConnectWallet: formMutationKeyFn2("auto-connect-wallet"), switchAccount: formMutationKeyFn2("switch-account"), createSessionKey: formMutationKeyFn2("create-session-key") }; // src/hooks/useCurrentSession.ts function useCurrentSession() { return useSessionStore((state) => state.currentSession); } // src/hooks/wallet/useConnectWallet.ts import { useMutation } from "@tanstack/react-query"; // src/hooks/useSessions.ts function useSessions() { return useSessionStore( (state) => state.sessions.sort((a, b) => b.getCreateTime() - a.getCreateTime()) ); } // src/hooks/wallet/useConnectWallet.ts function useConnectWallet({ mutationKey, ...mutationOptions } = {}) { const sessions = useSessions(); const setCurrentSession = useSessionStore((state) => state.setCurrentSession); const setWalletConnected = useWalletStore((state) => state.setWalletConnected); const setWalletDisconnected = useWalletStore((state) => state.setWalletDisconnected); const setConnectionStatus = useWalletStore((state) => state.setConnectionStatus); const triggerError = useTriggerError(); return useMutation({ mutationKey: walletMutationKeys.connectWallet(mutationKey), mutationFn: async ({ wallet }) => { try { setConnectionStatus("connecting"); const connectAddress = await wallet.connect(); const selectedAddress = connectAddress[0]; setWalletConnected(wallet, connectAddress, selectedAddress); const cur = sessions.find( (item) => item.getRoochAddress().toStr() === selectedAddress?.genRoochAddress().toStr() ); setCurrentSession(cur); return connectAddress; } catch (error) { setWalletDisconnected(); if ("code" in error && "message" in error) { triggerError(error); } throw error; } }, ...mutationOptions }); } // src/hooks/wallet/useCurrentAddress.ts function useCurrentAddress() { return useWalletStore((state) => state.currentAddress); } // src/hooks/wallet/useCurrentWallet.ts function useCurrentWallet() { const currentWallet = useWalletStore((state) => state.currentWallet); const connectionStatus3 = useWalletStore((state) => state.connectionStatus); switch (connectionStatus3) { case "connecting": return { status: connectionStatus3, wallet: currentWallet, isDisconnected: false, isConnecting: true, isConnected: false }; case "disconnected": return { status: connectionStatus3, wallet: currentWallet, isDisconnected: true, isConnecting: false, isConnected: false }; case "connected": { return { status: connectionStatus3, wallet: currentWallet, isDisconnected: false, isConnecting: false, isConnected: true }; } } } // src/hooks/wallet/useWallets.ts function useWallets() { return useWalletStore((state) => state.wallets); } // src/hooks/useRemoveSession.ts import { useMutation as useMutation2 } from "@tanstack/react-query"; function useRemoveSession({ mutationKey, ...mutationOptions } = {}) { const sessionsKeys = useSessions(); const removeSession = useSessionStore((state) => state.removeSession); const setCurrentSession = useSessionStore((state) => state.setCurrentSession); const currentSession = useCurrentSession(); const client = useRoochClient(); return useMutation2({ mutationKey: roochMutationKeys.removeSession(mutationKey), mutationFn: async (args) => { try { if (!currentSession) { return; } const result = await client.removeSession({ authKey: args.authKey, signer: currentSession }); if (result) { let cacheSession = sessionsKeys.find( (item) => item.getAuthKey() === args.authKey ); if (cacheSession) { removeSession(cacheSession); if (cacheSession.getAuthKey() === currentSession?.getAuthKey()) { const substitute = sessionsKeys.filter((item) => item.getAuthKey() !== cacheSession.getAuthKey()).sort((a, b) => b.getCreateTime() - a.getCreateTime()).filter((item) => !item.isSessionExpired()); if (substitute.length > 0) { setCurrentSession(substitute[0]); } else { setCurrentSession(void 0); } } } } } catch (e) { throw e; } }, ...mutationOptions }); } // src/hooks/useCreateSession.ts import { useMutation as useMutation3 } from "@tanstack/react-query"; // src/error/walletErrors.ts var WalletNotConnectedError = class extends Error { }; // src/hooks/useCreateSession.ts function useCreateSessionKey({ mutationKey, ...mutationOptions } = {}) { const client = useRoochClient(); const { wallet } = useCurrentWallet(); const setCurrentSession = useSessionStore((state) => state.setCurrentSession); const triggerError = useTriggerError(); return useMutation3({ mutationKey: walletMutationKeys.createSessionKey(mutationKey), mutationFn: async (args) => { const signer = args.signer || wallet; if (!signer) { throw new WalletNotConnectedError("No wallet is connected."); } try { const sessionAccount = await client.createSession({ signer, sessionArgs: args }); setCurrentSession(sessionAccount); return sessionAccount; } catch (error) { if ("code" in error && "message" in error) { triggerError(error); } throw error; } }, ...mutationOptions }); } // src/utils/time.ts import dayjs from "dayjs"; function getUTCOffset() { const date = /* @__PURE__ */ new Date(); const offset = -date.getTimezoneOffset(); const hours = Math.floor(offset / 60); const minutes = offset % 60; return `UTC ${hours >= 0 ? "+" : "-"}${hours}:${minutes < 10 ? "0" : ""}${minutes}`; } var unix2str = (input) => { const timestampInSeconds = input > 1e12 ? input / 1e3 : input; return `${dayjs.unix(timestampInSeconds).format("MMM DD, YYYY HH:mm:ss")}`; }; var second2Countdown = (input) => { const days = Math.floor(input / (24 * 3600)); const hours = Math.floor(input % (24 * 3600) / 3600); const minutes = Math.floor(input % 3600 / 60); const secs = Math.floor(input % 60); return `${days} : ${hours} : ${minutes} : ${secs}`; }; // src/components/session-modal/views/WhatIsASessionView.tsx import { jsx as jsx15, jsxs as jsxs3 } from "react/jsx-runtime"; function WhatIsASessionView({ getTitle }) { const { start, finish } = useProgress(); const { mutateAsync, isError } = useCreateSessionKey(); const _sessionConf = useSessionStore((state) => state.sessionConf); const [model, setModel] = useState3("what"); useEffect2(() => { getTitle(model === "what" ? "What is a session" : "Create session"); }, [getTitle, model]); const createSession = () => { if (!_sessionConf) { return; } setModel("create"); start(); mutateAsync({ ..._sessionConf }).finally(() => finish()); }; return model === "what" ? /* @__PURE__ */ jsxs3("div", { className: whatContent, children: [ /* @__PURE__ */ jsx15(Heading, { as: "h2", children: "What is a Session" }), /* @__PURE__ */ jsxs3("div", { className: whatContent, children: [ /* @__PURE__ */ jsx15(Text, { weight: "medium", color: "muted", children: "Rooch's Session Key is a temporary key that facilitates users to interact with the chain." }), /* @__PURE__ */ jsx15(Text, { weight: "medium", color: "muted", children: "When interacting with Rooch applications, each application generates a session key. It has an expiration time and will become invalid if there is no interaction for a long time." }), /* @__PURE__ */ jsx15("div", { className: whatMoreContent, children: /* @__PURE__ */ jsx15(Text, { className: moreInfo, children: /* @__PURE__ */ jsx15( "a", { href: "https://rooch.network/learn/core-concepts/accounts/session-key", target: "_blank", rel: "noreferrer", children: "More Info" } ) }) }) ] }), _sessionConf && /* @__PURE__ */ jsx15("div", { className: actionButtonContainer, children: /* @__PURE__ */ jsx15(Button, { type: "button", variant: "outline", onClick: createSession, children: "Create" }) }) ] }) : /* @__PURE__ */ jsxs3("div", { className: createSessionContainer, children: [ /* @__PURE__ */ jsx15(Heading, { as: "h2", children: "Info" }), /* @__PURE__ */ jsxs3("div", { className: createSessionContent, children: [ /* @__PURE__ */ jsx15(Info, { name: "App name", value: _sessionConf.appName }), /* @__PURE__ */ jsx15(Info, { name: "App url", value: _sessionConf.appUrl }), /* @__PURE__ */ jsx15( Info, { name: "Expiration Interval", value: _sessionConf.maxInactiveInterval ? _sessionConf.maxInactiveInterval * 1e3 + Date.now() : 0 } ), /* @__PURE__ */ jsxs3("div", { className: createSessionScopeContent, children: [ /* @__PURE__ */ jsx15(Heading, { as: "h3", size: "sm", weight: "normal", children: "Scope" }), _sessionConf.scopes.slice(0, 3).map( (item) => typeof item === "string" ? item : `${item.address}::${item.module}::${item.function}` ).sort((a, b) => b.length - a.length).map((item) => { const _tmp = item.split("::"); return /* @__PURE__ */ jsx15(Text, { children: _tmp[0].length > 3 ? toShortStr(item, { start: 12, end: 10 + _tmp[1].length + _tmp[2].length }) : item }, item); }) ] }), /* @__PURE__ */ jsx15("div", { className: createSessionStatus, children: isError ? /* @__PURE__ */ jsx15(Text, { color: "danger", children: "Create failed" }) : /* @__PURE__ */ jsx15(Text, { color: "muted", children: "Confirm sign in the wallet..." }) }), isError ? /* @__PURE__ */ jsx15("div", { className: actionButtonContainer, children: /* @__PURE__ */ jsx15(Button, { type: "button", variant: "outline", onClick: createSession, children: "Retry Create" }) }) : null ] }) ] }); } function Info({ name, value }) { return /* @__PURE__ */ jsxs3("div", { className: sessionItemContent, children: [ /* @__PURE__ */ jsx15(Text, { color: "danger", style: { width: "130px" }, children: name }), /* @__PURE__ */ jsx15(Text, { color: "muted", children: typeof value === "number" ? `${unix2str(value)} (${getUTCOffset()})` : value }) ] }); } // src/components/session-modal/session-list/SessionList.css.ts var container3 = "SessionList_container__he8t610"; // src/components/session-modal/session-list/SessionListItem.tsx import { clsx as clsx5 } from "clsx"; // src/components/session-modal/session-list/SessionListItem.css.ts var container4 = "SessionListItem_container__128jgi30"; var selectedSessionItem = "SessionListItem_selectedSessionItem__128jgi32"; var sessionItem = "SessionListItem_sessionItem__128jgi31"; // src/components/session-modal/session-list/SessionListItem.tsx import { toShortStr as toShortStr2 } from "@roochnetwork/rooch-sdk"; import { jsx as jsx16 } from "react/jsx-runtime"; function SessionListItem({ authKey, onClick, isSelected = false }) { return /* @__PURE__ */ jsx16("li", { className: container4, children: /* @__PURE__ */ jsx16( "button", { className: clsx5(sessionItem, { [selectedSessionItem]: isSelected }), type: "button", onClick, children: /* @__PURE__ */ jsx16(Heading, { size: "md", truncate: true, asChild: true, children: /* @__PURE__ */ jsx16("div", { children: toShortStr2(authKey, { start: 12, end: 6 }) }) }) } ) }); } // src/components/session-modal/session-list/SessionList.tsx import { jsx as jsx17, jsxs as jsxs4 } from "react/jsx-runtime"; function SessionList({ selectedSessionAuthKey, onSelect }) { const sessions = useSessions(); return /* @__PURE__ */ jsxs4("ul", { className: container3, children: [ /* @__PURE__ */ jsx17( SessionListItem, { authKey: selectedSessionAuthKey?.startsWith("0x") ? "What is a session" : selectedSessionAuthKey || "", isSelected: !selectedSessionAuthKey?.startsWith("0x"), onClick: () => onSelect() }, "new" ), sessions.map((session) => /* @__PURE__ */ jsx17( SessionListItem, { authKey: session.getAuthKey(), isSelected: session.getAuthKey() === selectedSessionAuthKey, onClick: () => onSelect(session) }, session.getAuthKey() )) ] }); } // src/components/session-modal/views/SessionView.tsx import { useEffect as useEffect4, useMemo as useMemo3, useState as useState7 } from "react"; import { toShortStr as toShortStr3 } from "@roochnetwork/rooch-sdk"; // src/components/session-modal/views/SessionView.css.ts var container5 = "SessionView_container__t5n37e0"; var content3 = "SessionView_content__t5n37e3"; var moreContent = "SessionView_moreContent__t5n37e6"; var moreInfo2 = "SessionView_moreInfo__t5n37e7"; var removeBtn = "SessionView_removeBtn__t5n37e9"; var removeButtonContainer = "SessionView_removeButtonContainer__t5n37e8"; var scopeContent = "SessionView_scopeContent__t5n37e5"; var sessionItemContent2 = "SessionView_sessionItemContent__t5n37e4"; // src/components/connect-modal/ConnectModal.tsx import * as Dialog2 from "@radix-ui/react-dialog"; import clsx7 from "clsx"; import { useEffect as useEffect3, useMemo as useMemo2, useState as useState6 } from "react"; // src/components/connect-modal/ConnectModal.css.ts var backButtonContainer2 = "ConnectModal_backButtonContainer__yocf846"; var selectedViewContainer2 = "ConnectModal_selectedViewContainer__yocf845"; var title2 = "ConnectModal_title__yocf841"; var viewContainer2 = "ConnectModal_viewContainer__yocf844"; var walletListContainer = "ConnectModal_walletListContainer__yocf849"; var walletListContainerWithViewSelected = "ConnectModal_walletListContainerWithViewSelected__yocf84a"; var walletListContent = "ConnectModal_walletListContent__yocf848"; var whatIsAWalletButton = "ConnectModal_whatIsAWalletButton__yocf843"; // src/components/connect-modal/views/ConnectionStatus.css.ts var connectionStatus = "ConnectionStatus_connectionStatus__l246a63"; var container6 = "ConnectionStatus_container__l246a60"; var retryButtonContainer = "ConnectionStatus_retryButtonContainer__l246a64"; var title3 = "ConnectionStatus_title__l246a62"; var walletIcon = "ConnectionStatus_walletIcon__l246a61"; // src/components/connect-modal/views/ConnectionStatus.tsx import { jsx as jsx18, jsxs as jsxs5 } from "react/jsx-runtime"; function ConnectionStatus({ selectedWallet, info, hadConnectionError, onRetryConnection }) { return /* @__PURE__ */ jsxs5("div", { className: container6, children: [ selectedWallet.getName() && /* @__PURE__ */ jsx18( "img", { className: walletIcon, src: selectedWallet.getIcon(), alt: `${selectedWallet.getName()} logo` } ), /* @__PURE__ */ jsx18("div", { className: title3, children: /* @__PURE__ */ jsxs5(Heading, { as: "h2", size: "xl", children: [ "Opening ", selectedWallet.getName() ] }) }), /* @__PURE__ */ jsxs5("div", { className: connectionStatus, children: [ hadConnectionError ? /* @__PURE__ */ jsx18(Text, { color: "danger", children: "Connection failed" }) : /* @__PURE__ */ jsx18(Text, { color: "muted", children: "Confirm connection in the wallet..." }), info ? info.map((item, i) => /* @__PURE__ */ jsx18(Text, { color: "warning", children: item }, i)) : null ] }), hadConnectionError ? /* @__PURE__ */ jsx18("div", { className: retryButtonContainer, children: /* @__PURE__ */ jsx18(Button, { type: "button", variant: "outline", onClick: () => onRetryConnection(selectedWallet), children: "Retry Connection" }) }) : null ] }); } // src/components/connect-modal/InfoSection.css.ts var container7 = "InfoSection_container__1tyxmhu0"; // src/components/connect-modal/InfoSection.tsx import { jsx as jsx19, jsxs as jsxs6 } from "react/jsx-runtime"; function InfoSection({ title: title7, children }) { return /* @__PURE__ */ jsxs6("section", { className: container7, children: [ /* @__PURE__ */ jsx19(Heading, { as: "h3", size: "sm", weight: "normal", children: title7 }), /* @__PURE__ */ jsx19(Text, { weight: "medium", color: "muted", children }) ] }); } // src/components/connect-modal/views/WhatIsAWallet.css.ts var container8 = "WhatIsAWallet_container__18x371x0"; var content4 = "WhatIsAWallet_content__18x371x1"; // src/components/connect-modal/views/WhatIsAWallet.tsx import { jsx as jsx20, jsxs as jsxs7 } from "react/jsx-runtime"; function WhatIsAWallet() { return /* @__PURE__ */ jsxs7("div", { className: container8, children: [ /* @__PURE__ */ jsx20(Heading, { as: "h2", children: "What is a Wallet" }), /* @__PURE__ */ jsxs7("div", { className: content4, children: [ /* @__PURE__ */ jsx20(InfoSection, { title: "Easy Login", children: "No need to create new accounts and passwords for every website. Just connect your wallet and get going." }), /* @__PURE__ */ jsx20(InfoSection, { title: "Store your Digital Assets", children: "Send, receive, store, and display your digital assets like NFTs & coins." }) ] }) ] }); } // src/components/connect-modal/views/InstallStatus.css.ts var container9 = "InstallStatus_container__1hlwsco0"; var installButtonContainer = "InstallStatus_installButtonContainer__1hlwsco4"; var installStatus = "InstallStatus_installStatus__1hlwsco3"; var title4 = "InstallStatus_title__1hlwsco2"; var walletIcon2 = "InstallStatus_walletIcon__1hlwsco1"; // src/components/connect-modal/views/InstallStatus.tsx import { jsx as jsx21, jsxs as jsxs8 } from "react/jsx-runtime"; function InstallStatus({ selectedWallet }) { return /* @__PURE__ */ jsxs8("div", { className: container9, children: [ selectedWallet.getName() && /* @__PURE__ */ jsx21( "img", { className: walletIcon2, src: selectedWallet.getIcon(), alt: `${selectedWallet.getName()} logo` } ), /* @__PURE__ */ jsx21("div", { className: title4, children: /* @__PURE__ */ jsxs8(Heading, { as: "h2", size: "xl", children: [ "Opening ", selectedWallet.getName() ] }) }), /* @__PURE__ */ jsx21("div", { className: installStatus, children: /* @__PURE__ */ jsx21(Text, { color: "danger", children: "undetected Wallet" }) }), /* @__PURE__ */ jsx21("div", { className: installButtonContainer, children: /* @__PURE__ */ jsx21( Button, { type: "button", variant: "outline", onClick: () => window.open(selectedWallet.getInstallUrl(), "_blank"), children: "Install" } ) }) ] }); } // src/components/connect-modal/wallet-list/WalletList.css.ts var container10 = "WalletList_container__1wac1dp0"; // src/components/connect-modal/wallet-list/WalletListItem.tsx import { clsx as clsx6 } from "clsx"; // src/components/connect-modal/wallet-list/WalletListItem.css.ts var container11 = "WalletListItem_container__1i3e7c00"; var detectingStatus = "WalletListItem_detectingStatus__1i3e7c07"; var installedStatus = "WalletListItem_installedStatus__1i3e7c05"; var loadingSpinner = "WalletListItem_loadingSpinner__1i3e7c09"; var notInstalledStatus = "WalletListItem_notInstalledStatus__1i3e7c06"; var selectedWalletItem = "WalletListItem_selectedWalletItem__1i3e7c02"; var walletIcon3 = "WalletListItem_walletIcon__1i3e7c03"; var walletItem = "WalletListItem_walletItem__1i3e7c01"; var walletStatus = "WalletListItem_walletStatus__1i3e7c04"; // src/components/connect-modal/wallet-list/WalletListItem.tsx import { Fragment, jsx as jsx22, jsxs as jsxs9 } from "react/jsx-runtime"; function WalletListItem({ name, icon, onClick, isSelected = false, isInstalled = false, isDetecting = false }) { return /* @__PURE__ */ jsx22("li", { className: container11, children: /* @__PURE__ */ jsxs9( "button", { className: clsx6(walletItem, { [selectedWalletItem]: isSelected }), type: "button", onClick, children: [ icon && typeof icon === "string" ? /* @__PURE__ */ jsx22("img", { className: walletIcon3, src: icon, alt: `${name} logo` }) : icon, /* @__PURE__ */ jsx22(Heading, { size: "md", truncate: true, asChild: true, children: /* @__PURE__ */ jsx22("div", { children: name }) }), /* @__PURE__ */ jsx22( "span", { className: clsx6(walletStatus, { [installedStatus]: isInstalled && !isDetecting || name === "Local", [notInstalledStatus]: !isInstalled && !isDetecting, [detectingStatus]: isDetecting && name !== "Local" }), children: isDetecting && name !== "Local" ? /* @__PURE__ */ jsx22(Fragment, { children: /* @__PURE__ */ jsx22("span", { className: loadingSpinner }) }) : isInstalled ? "Installed" : "Uninstalled" } ) ] } ) }); } // src/components/connect-modal/wallet-list/WalletList.tsx import { jsx as jsx23 } from "react/jsx-runtime"; function WalletList({ wallets, selectedWalletName, onSelect, walletStatus: walletStatus2, isDetecting }) { return /* @__PURE__ */ jsx23("ul", { className: container10, children: wallets.map((wallet) => /* @__PURE__ */ jsx23( WalletListItem, { name: wallet.getName(), icon: wallet.getIcon(), isSelected: wallet.getName() === selectedWalletName, isInstalled: walletStatus2.get(wallet.getName()), isDetecting, onClick: () => onSelect(wallet) }, wallet.getName() )) }); } // src/components/ui/Modal.tsx import { useState as useState4 } from "react"; import * as Dialog from "@radix-ui/react-dialog"; // src/components/ui/Modal.css.ts var closeButtonContainer2 = "Modal_closeButtonContainer__1c5z17f2"; var content5 = "Modal_content__1c5z17f1"; var overlay2 = "Modal_overlay__1c5z17f0"; // src/components/ui/Modal.tsx import { jsx as jsx24, jsxs as jsxs10 } from "react/jsx-runtime"; function Modal({ trigger, children, open, defaultOpen, onOpenChange }) { const [isModalOpen, setModalOpen] = useState4(open ?? defaultOpen); const handleOpenChange = (open2) => { setModalOpen(open2); onOpenChange?.(open2); }; return /* @__PURE__ */ jsxs10(Dialog.Root, { open: open ?? isModalOpen, onOpenChange: handleOpenChange, children: [ /* @__PURE__ */ jsx24(Dialog.Trigger, { asChild: true, children: trigger }), /* @__PURE__ */ jsx24(Dialog.Portal, { children: /* @__PURE__ */ jsx24(StyleMarker, { children: /* @__PURE__ */ jsx24(Dialog.Overlay, { className: overlay2, children: /* @__PURE__ */ jsxs10(Dialog.Content, { className: content5, "aria-describedby": void 0, children: [ /* @__PURE__ */ jsx24(ProgressProvider, { children }), /* @__PURE__ */ jsx24(Dialog.Close, { className: closeButtonContainer2, asChild: true, children: /* @__PURE__ */ jsx24(IconButton, { type: "button", "aria-label": "Close", children: /* @__PURE__ */ jsx24(CloseIcon, {}) }) }) ] }) }) }) }) ] }); } // src/components/switch-network-modal/views/SwitchNetworkView.css.ts var connectionStatus2 = "SwitchNetworkView_connectionStatus__e4ayqy3"; var container12 = "SwitchNetworkView_container__e4ayqy0"; var retryButtonContainer2 = "SwitchNetworkView_retryButtonContainer__e4ayqy4"; var title5 = "SwitchNetworkView_title__e4ayqy2"; var walletIcon4 = "SwitchNetworkView_walletIcon__e4ayqy1"; // src/components/switch-network-modal/views/SwitchNetworkView.tsx import { useState as useState5 } from "react"; // src/components/util/wallet.ts var NETWORK_MAP = { mainnet: "livenet", testnet: "testnet", devnet: void 0, localnet: void 0 }; var checkWalletNetwork = async (wallet, roochNetwork) => { try { const walletNetwork = await wallet.getNetwork(); const target = NETWORK_MAP[roochNetwork]; if (target && walletNetwork !== target) { return target; } } catch (_) { } return void 0; }; // src/components/switch-network-modal/views/SwitchNetworkView.tsx import { jsx as jsx25, jsxs as jsxs11 } from "react/jsx-runtime"; function SwitchNetworkView({ wallet, onSuccess, targetNetWork, switchNetwork }) { const { start, finish, loading } = useProgress(); const [error, setError] = useState5(false); const [support, setSupport] = useState5(true); const roochNetwork = useCurrentNetwork(); const switch2Network = () => { start(); switchNetwork(wallet, targetNetWork).catch((e) => { if ("message" in e && e.message.includes("not support")) { setSupport(false); } setError(true); }).finally(() => { finish(); }); }; const refresh = () => { start(); checkWalletNetwork(wallet, roochNetwork).then((result) => { if (!result) { onSuccess(); } }).finally(() => finish()); }; return /* @__PURE__ */ jsxs11("div", { className: container12, children: [ wallet.getName() && /* @__PURE__ */ jsx25( "img", { className: walletIcon4, src: wallet.getIcon(), alt: `${wallet.getName()} logo` } ), /* @__PURE__ */ jsx25("div", { className: title5, children: /* @__PURE__ */ jsxs11(Heading, { as: "h2", size: "xl", children: [ "Check ", wallet.getName() ] }) }), /* @__PURE__ */ jsxs11("div", { className: connectionStatus2, children: [ /* @__PURE__ */ jsx25(Text, { color: "danger", children: !loading ? `${error ? "Switch failed" : `Wallet network is not ${targetNetWork}`}` : "being processed..." }), /* @__PURE__ */ jsx25(Text, { color: "muted", children: !loading ? `Please ${error ? "manually" : ""} switch the wallet network to ${targetNetWork}` : "" }) ] }), /* @__PURE__ */ jsx25("div", { className: retryButtonContainer2, children: /* @__PURE__ */ jsx25( Button, { disabled: loading, type: "button", variant: "outline", onClick: () => support ? switch2Network() : refresh(), children: support ? error ? "Retry Switch" : "Switch" : "Refresh" } ) }) ] }); } // src/components/connect-modal/ConnectModal.tsx import { jsx as jsx26, jsxs as jsxs12 } from "react/jsx-runtime"; function ConnectModal({ trigger, open, defaultOpen, onOpenChange, onSuccess }) { const wallets = useWallets(); const { mutateAsync, isError } = useConnectWallet(); const roochNetwork = useCurrentNetwork(); const [isModalOpen, setModalOpen] = useState6(open ?? defaultOpen); const [currentView, setCurrentView] = useState6(); const [targetNetwork, setTargetNetwork] = useState6(); const [selectedWallet, setSelectedWallet] = useState6(); const [walletStatus2, setWalletStatus] = useState6(/* @__PURE__ */ new Map()); const [isDetecting, setIsDetecting] = useState6(false); useEffect3(() => { setIsDetecting(true); const checkWallets = async () => { for (const item of wallets) { const result = await item.checkInstalled(); setWalletStatus((prev) => { const newS = new Map(prev); newS.set(item.getName(), result); return newS; }); } setIsDetecting(false); }; checkWallets(); }, [wallets, setWalletStatus]); const sortedWallet = useMemo2(() => { return wallets.toSorted((a, b) => { if (a.getName() === "Local") { walletStatus2.set(a.getName(), true); return -1; } return Number(walletStatus2.get(b.getName())) - Number(walletStatus2.get(a.getName())); }); }, [wallets, walletStatus2]); const resetSelection = () => { setSelectedWallet(void 0); setCurrentView(void 0); }; const handleOpenChange = (open2) => { if (!open2) { resetSelection(); } setModalOpen(open2); onOpenChange?.(open2); }; const switchNetwork = async (wallet, target) => { wallet.switchNetwork(target).then(() => { connectWallet(wallet); }); }; const handleSelectedWallet = async (wallet) => { if (wallet.getName() === "OneKey") { connectWallet(wallet); return; } const target = await checkWalletNetwork(wallet, roochNetwork); if (target) { setTargetNetwork(target); setCurrentView("switch-network"); } else { connectWallet(wallet); } }; const connectWallet = (wallet) => { setCurrentView("connection-status"); mutateAsync({ wallet }).then(() => { if (onSuccess) { onSuccess(); } handleOpenChange(false); }); }; let modalContent; switch (currentView) { case "what-is-a-wallet": modalContent = /* @__PURE__ */ jsx26(WhatIsAWallet, {}); break; case "switch-network": modalContent = /* @__PURE__ */ jsx26( SwitchNetworkView, { wallet: selectedWallet, targetNetWork: targetNetwork, switchNetwork, onSuccess: () => connectWallet(selectedWallet) } ); break; case "connection-status": modalContent = /* @__PURE__ */ jsx26( ConnectionStatus, { selectedWallet, hadConnectionError: isError, info: ( // TODO: Better solutions are needed to deal with it walletStatus2.get("OneKey") && walletStatus2.get("UniSat") && selectedWallet?.getName() === "UniSat" ? [ "If UniSat does not work!", "Disable One Key Wallet, Refresh the page and try again." ] : void 0 ), onRetryConnection: connectWallet } ); break; case "install-status": modalContent = /* @__PURE__ */ jsx26(InstallStatus, { selectedWallet }); break; default: modalContent = /* @__PURE__ */ jsx26(WhatIsAWallet, {}); } return /* @__PURE__ */ jsxs12( Modal, { trigger, open: isModalOpen, defaultOpen, onOpenChange, children: [ /* @__PURE__ */ jsxs12( "div", { className: clsx7(walletListContainer, { [walletListContainerWithViewSelected]: !!currentView }), children: [ /* @__PURE__ */ jsxs12("div", { className: walletListContent, children: [ /* @__PURE__ */ jsx26(Dialog2.Title, { className: title2, asChild: true, children: /* @__PURE__ */ jsx26(Heading, { as: "h2", children: "Connect a Wallet" }) }), /* @__PURE__ */ jsx26( WalletList, { walletStatus: walletStatus2, wallets: sortedWallet, selectedWalletName: selectedWallet?.getName(), isDetecting, onSelect: (wallet) => { if (selectedWallet?.getName() !== wallet.getName()) { setSelectedWallet(wallet); if (walletStatus2.get(wallet.getName())) { handleSelectedWallet(wallet); } else { setCurrentView("install-status"); } } } } ) ] }), /* @__PURE__ */ jsx26( "button", { className: whatIsAWalletButton, onClick: () => setCurrentView("what-is-a-wallet"), type: "button", children: "What is a Wallet?" } ) ] } ), /* @__PURE__ */ jsxs12( "div", { className: clsx7(viewContainer2, { [selectedViewContainer2]: !!currentView }), children: [ /* @__PURE__ */ jsx26("div", { className: backButtonContainer2, children: /* @__PURE__ */ jsx26(IconButton, { type: "button", "aria-label": "Back", onClick: () => resetSelection(), children: /* @__PURE__ */ jsx26(BackIcon, {}) }) }), modalContent ] } ) ] } ); } // src/components/SessionKeyGuard.tsx import { Fragment as Fragment2, jsx as jsx27 } from "react/jsx-runtime"; function SessionKeyGuard({ children, sessionConf, onClick }) { const session = useCurrentSession(); const curSession = useCurrentSession(); const curAddress = useCurrentAddress(); const _sessionConf = useSessionStore((state) => state.sessionConf); const { mutate } = useCreateSessionKey(); const handleCreateSession = () => { if (curSession && !curSession.isSessionExpired()) { onClick(); return; } const _conf = _sessionConf || sessionConf; if (_conf) { mutate({ ..._conf }); } else { onClick(); } }; return /* @__PURE__ */ jsx27(Fragment2, { children: curAddress ? /* @__PURE__ */ jsx27( Button, { asChild: true, onClick: () => { handleCreateSession(); }, children } ) : /* @__PURE__ */ jsx27( ConnectModal, { trigger: children, onSuccess: () => { if (!session) { handleCreateSession(); } } } ) }); } // src/components/session-modal/views/SessionView.tsx import { jsx as jsx28, jsxs as jsxs13 } from "react/jsx-runtime"; function SessionView({ selectedSession, removedCallback }) { const { loading, start, finish } = useProgress(); const { mutateAsync, isError } = useRemoveSession(); const [timeRemaining, setTimeRemaining] = useState7(-1); useEffect4(() => { if (selectedSession.i