{"version":3,"file":"index.cjs","sources":["../src/utils/web.ts","../src/components/TonConnectUIProvider.tsx","../src/errors/ton-connect-ui-react.error.ts","../src/errors/ton-connect-provider-not-set.error.ts","../src/utils/errors.ts","../src/hooks/useTonConnectUI.ts","../src/components/TonConnectButton.tsx","../src/hooks/useTonWallet.ts","../src/hooks/useTonAddress.ts","../src/hooks/useTonConnectModal.ts","../src/hooks/useIsConnectionRestored.ts"],"sourcesContent":["export function isClientSide(): boolean {\n    return typeof window !== 'undefined';\n}\n\nexport function isServerSide(): boolean {\n    return !isClientSide();\n}\n","import { createContext, FunctionComponent, memo, ReactNode, useState } from 'react';\nimport {\n    ActionConfiguration,\n    Locales,\n    TonConnectUI,\n    UIPreferences,\n    WalletsListConfiguration\n} from '@tonconnect/ui';\nimport type { ITonConnect, RequiredFeatures, AnalyticsSettings } from '@tonconnect/ui';\nimport { isClientSide } from '../utils/web';\n\nexport const TonConnectUIContext = createContext<TonConnectUI | null>(null);\n\n/**\n * Props for `<TonConnectUIProvider>`. Pick one of three shapes:\n *\n * - {@link TonConnectUIProviderPropsWithManifest} — most common: pass a\n *   `manifestUrl`, the provider builds a `TonConnectUI` for you.\n * - {@link TonConnectUIProviderPropsWithConnector} — pass a pre-built\n *   `ITonConnect` (from `@tonconnect/sdk`); the provider wraps it in UI.\n * - {@link TonConnectUIProviderPropsWithInstance} — pass an externally\n *   constructed `TonConnectUI`.\n *\n * The manifest / connector variants accept the same UI-level options as the\n * vanilla `TonConnectUiOptions` (theme, language, wallet filters,\n * analytics).\n */\nexport type TonConnectUIProviderProps = {\n    children: ReactNode;\n} & (\n    | Partial<\n          TonConnectUIProviderPropsBase &\n              (TonConnectUIProviderPropsWithManifest | TonConnectUIProviderPropsWithConnector)\n      >\n    | TonConnectUIProviderPropsWithInstance\n);\n\n/**\n * Pass a `manifestUrl` and let the provider build a `TonConnectUI` from\n * the merged UI options.\n */\nexport interface TonConnectUIProviderPropsWithManifest {\n    /**\n     * HTTPS URL of the dApp's\n     * [`tonconnect-manifest.json`](https://github.com/ton-blockchain/ton-connect/blob/main/spec/manifest.md).\n     * The provider builds the `TonConnectUI` connector from it.\n     */\n    manifestUrl: string;\n}\n\n/**\n * Pass a pre-built `ITonConnect` (typically from `@tonconnect/sdk`) — the\n * provider wraps it in a `TonConnectUI`. Useful when the dApp drives the\n * underlying SDK directly and only wants the React UI on top.\n */\nexport interface TonConnectUIProviderPropsWithConnector {\n    /** Existing `ITonConnect` instance. The provider will not create its own. */\n    connector: ITonConnect;\n}\n\n/**\n * Pass an externally-constructed `TonConnectUI`.\n *\n * Note: `TonConnectUI` is a singleton inside this package. The instance you\n * pass is stored in the global singleton and reused by all hooks.\n */\nexport interface TonConnectUIProviderPropsWithInstance {\n    instance: TonConnectUI;\n}\n\n/**\n * Common UI options accepted in addition to the constructor selector\n * (`manifestUrl` / `connector`). All optional; mirror the fields on\n * `TonConnectUiOptions` from `@tonconnect/ui`.\n */\nexport interface TonConnectUIProviderPropsBase {\n    /**\n     * Attempt to restore the previous session from storage on mount. Set to\n     * `false` for flows that prefer an explicit connect step.\n     *\n     * @default true\n     */\n    restoreConnection: boolean;\n\n    /**\n     * Language for SDK-rendered strings.\n     *\n     * @default 'en'\n     */\n    language: Locales;\n\n    /**\n     * HTML element id under which the modal root is attached. Defaults to\n     * `tc-widget-root` (created at the end of `<body>`).\n     */\n    widgetRootId: string;\n\n    /** Visual configuration — theme, border radius, color overrides. */\n    uiPreferences?: UIPreferences;\n\n    /** Wallets-list overrides — include extra wallets, reorder existing ones. */\n    walletsListConfiguration?: WalletsListConfiguration;\n\n    /**\n     * Hide wallets from the picker that don't advertise the listed\n     * features. Non-matching entries are greyed out below the separator and\n     * rejected at connect time with `WalletMissingRequiredFeaturesError`.\n     */\n    walletsRequiredFeatures?: RequiredFeatures;\n\n    /**\n     * Soft preference filter — non-matching wallets remain clickable but\n     * sorted below the separator. The SDK does NOT enforce the match at\n     * connect time.\n     */\n    walletsPreferredFeatures?: RequiredFeatures;\n\n    /**\n     * Modal / notification behavior and the return strategy for action\n     * deep links. See `ActionConfiguration`.\n     */\n    actionsConfiguration?: ActionConfiguration;\n\n    /**\n     * Close modals and notifications when the Android back button is\n     * pressed. Disable when the dApp manages browser history manually.\n     *\n     * @default true\n     */\n    enableAndroidBackHandler?: boolean;\n\n    /**\n     * Analytics configuration forwarded to the underlying `TonConnect`\n     * instance. See `AnalyticsSettings` from `@tonconnect/sdk`.\n     */\n    analytics?: AnalyticsSettings;\n}\n\nlet tonConnectUI: TonConnectUI | null = null;\n\n/**\n * Root provider for `@tonconnect/ui-react`. Place it once near the top of\n * the React tree. All `useTonConnectUI` / `useTonAddress` / `useTonWallet`\n * etc. hooks and `<TonConnectButton />` must be rendered inside.\n *\n * Internally constructs a singleton `TonConnectUI` instance;\n * mounting a second `<TonConnectUIProvider>` with different props has no\n * effect once the instance is built.\n *\n * @example\n * ```tsx\n * import { TonConnectUIProvider } from '@tonconnect/ui-react';\n *\n * export default function App() {\n *     return (\n *         <TonConnectUIProvider manifestUrl=\"https://example.com/tonconnect-manifest.json\">\n *             <Router />\n *         </TonConnectUIProvider>\n *     );\n * }\n * ```\n */\nconst TonConnectUIProvider: FunctionComponent<TonConnectUIProviderProps> = ({\n    children,\n    ...options\n}) => {\n    const [uiInstance] = useState<TonConnectUI | null>(() => {\n        if (!isClientSide()) {\n            return null;\n        }\n\n        if (tonConnectUI !== null) {\n            return tonConnectUI;\n        }\n\n        if ('instance' in options) {\n            tonConnectUI = options.instance;\n        } else {\n            tonConnectUI = new TonConnectUI(options);\n        }\n\n        return tonConnectUI;\n    });\n\n    return (\n        <TonConnectUIContext.Provider value={uiInstance}>{children}</TonConnectUIContext.Provider>\n    );\n};\n\nexport default memo(TonConnectUIProvider);\n","import { TonConnectUIError } from '@tonconnect/ui';\n\n/**\n * Base class for every error thrown by `@tonconnect/ui-react`. Extends\n * `TonConnectUIError` from `@tonconnect/ui`, which itself extends\n * `TonConnectError` from `@tonconnect/sdk` — a single\n * `catch (e instanceof TonConnectError)` branch covers them all.\n */\nexport class TonConnectUIReactError extends TonConnectUIError {\n    constructor(...args: ConstructorParameters<typeof Error>) {\n        super(...args);\n\n        Object.setPrototypeOf(this, TonConnectUIReactError.prototype);\n    }\n}\n","import { TonConnectUIReactError } from './ton-connect-ui-react.error';\n\n/**\n * Thrown when a hook from `@tonconnect/ui-react` (or `<TonConnectButton />`)\n * is used outside the subtree rendered by `<TonConnectUIProvider>`. Add the\n * provider near the top of your React tree.\n */\nexport class TonConnectProviderNotSetError extends TonConnectUIReactError {\n    constructor(...args: ConstructorParameters<typeof Error>) {\n        super(...args);\n\n        Object.setPrototypeOf(this, TonConnectProviderNotSetError.prototype);\n    }\n}\n","import { TonConnectUI } from '@tonconnect/ui';\nimport { TonConnectProviderNotSetError } from '../errors/ton-connect-provider-not-set.error';\n\nexport function checkProvider(provider: TonConnectUI | null): provider is TonConnectUI {\n    if (!provider) {\n        throw new TonConnectProviderNotSetError(\n            'You should add <TonConnectUIProvider> on the top of the app to use TonConnect'\n        );\n    }\n\n    return true;\n}\n","import { useCallback, useContext } from 'react';\nimport { TonConnectUIContext } from '../components/TonConnectUIProvider';\nimport { TonConnectUI, TonConnectUiOptions } from '@tonconnect/ui';\nimport { checkProvider } from '../utils/errors';\nimport { isServerSide } from '../utils/web';\n\n/**\n * Returns a tuple of:\n *\n * - the singleton `TonConnectUI` instance — call every method (`connectWallet`,\n *   `sendTransaction`, `signData`, `signMessage`, modal helpers) on it;\n * - a `setOptions(options)` callback that merges the partial\n *   `TonConnectUiOptions` into the live instance via its `uiOptions`\n *   setter, triggering an immediate re-render.\n *\n * Must be called inside a `<TonConnectUIProvider>`. On the server side,\n * the hook returns a no-op pair — call sites can render shells\n * without crashing, but the real wiring only kicks in once the component\n * hydrates in the browser.\n *\n * @example\n * ```tsx\n * const [tonConnectUI, setOptions] = useTonConnectUI();\n *\n * await tonConnectUI.sendTransaction(tx, { traceId });\n * setOptions({ language: 'ru' });\n * ```\n */\nexport function useTonConnectUI(): [TonConnectUI, (options: TonConnectUiOptions) => void] {\n    const tonConnectUI = useContext(TonConnectUIContext);\n    const setOptions = useCallback(\n        (options: TonConnectUiOptions) => {\n            if (tonConnectUI) {\n                tonConnectUI!.uiOptions = options;\n            }\n        },\n        [tonConnectUI]\n    );\n\n    if (isServerSide()) {\n        return [null as unknown as TonConnectUI, () => {}];\n    }\n\n    checkProvider(tonConnectUI);\n    return [tonConnectUI!, setOptions];\n}\n","import { CSSProperties, FunctionComponent, memo, useEffect } from 'react';\nimport { useTonConnectUI } from '../hooks/useTonConnectUI';\n\nconst buttonRootId = 'ton-connect-button';\n\n/** Props for {@link TonConnectButton}. */\nexport interface TonConnectButtonProps {\n    /** Extra class name applied to the button container. */\n    className?: string;\n\n    /** Inline styles merged with the button container's `width: fit-content` default. */\n    style?: CSSProperties;\n}\n\n/**\n * Universal \"Connect Wallet\" button.\n *\n * When connected, the button transforms into a wallet-account dropdown\n * (address, copy, disconnect). Style via `className` / `style` or via the\n * data-attribute selectors documented in `@tonconnect/ui`'s README.\n *\n * Must be rendered inside a <{@link TonConnectUIProvider}>.\n *\n * @example\n * ```tsx\n * <header>\n *     <span>My App</span>\n *     <TonConnectButton className=\"my-class\" style={{ float: 'right' }} />\n * </header>\n * ```\n */\nconst TonConnectButton: FunctionComponent<TonConnectButtonProps> = ({ className, style }) => {\n    const [_, setOptions] = useTonConnectUI();\n\n    useEffect(() => {\n        setOptions({ buttonRootId });\n        return () => setOptions({ buttonRootId: null });\n    }, [setOptions]);\n\n    return (\n        <div\n            id={buttonRootId}\n            className={className}\n            style={{ width: 'fit-content', ...style }}\n        ></div>\n    );\n};\n\nexport default memo(TonConnectButton);\n","import { useEffect, useState } from 'react';\nimport { ConnectedWallet, Wallet, WalletInfoWithOpenMethod } from '@tonconnect/ui';\nimport { useTonConnectUI } from './useTonConnectUI';\n\n/**\n * Reactive accessor for the currently connected wallet. Returns `null`\n * while disconnected and refreshes on every `onStatusChange` event.\n *\n * The shape mirrors `tonConnectUI.wallet` — `Wallet` (from `@tonconnect/sdk`)\n * merged with the picker entry for the wallet (icon, name, open method).\n *\n * Must be called inside a `<TonConnectUIProvider>`.\n *\n * @example\n * ```tsx\n * const wallet = useTonWallet();\n *\n * if (!wallet) return <ConnectButton />;\n * return <span>{wallet.device.appName} · {wallet.account.address}</span>;\n * ```\n */\nexport function useTonWallet(): Wallet | (Wallet & WalletInfoWithOpenMethod) | null {\n    const [tonConnectUI] = useTonConnectUI();\n    const [wallet, setWallet] = useState<Wallet | (Wallet & WalletInfoWithOpenMethod) | null>(\n        tonConnectUI?.wallet || null\n    );\n\n    useEffect(() => {\n        if (tonConnectUI) {\n            setWallet(tonConnectUI.wallet);\n            return tonConnectUI.onStatusChange((value: ConnectedWallet | null) => {\n                setWallet(value);\n            });\n        }\n    }, [tonConnectUI]);\n\n    return wallet;\n}\n","import { CHAIN, toUserFriendlyAddress } from '@tonconnect/ui';\nimport { useTonWallet } from './useTonWallet';\nimport { useMemo } from 'react';\n\n/**\n * Reactive accessor for the connected account's TON address. Returns an\n * empty string while disconnected.\n *\n * @param userFriendly — `true` (default) returns the non-bounceable base64url\n *   user-friendly form (`UQ…` on mainnet, `0Q…` on testnet).\n *   Pass `false` to get the raw `<workchain>:<hex>` form.\n *\n * @example\n * ```tsx\n * const address = useTonAddress();      // user-friendly\n * const rawAddress = useTonAddress(false);\n * ```\n */\nexport function useTonAddress(userFriendly = true): string {\n    const wallet = useTonWallet();\n    return useMemo(() => {\n        if (wallet) {\n            return userFriendly\n                ? toUserFriendlyAddress(\n                      wallet.account.address,\n                      wallet.account.chain === CHAIN.TESTNET\n                  )\n                : wallet.account.address;\n        } else {\n            return '';\n        }\n    }, [wallet, userFriendly, wallet?.account.address, wallet?.account.chain]);\n}\n","import { WalletsModal, WalletsModalState } from '@tonconnect/ui';\nimport { useTonConnectUI } from './useTonConnectUI';\nimport { useEffect, useState } from 'react';\n\n/**\n * Reactive wrapper around `tonConnectUI.modal`. Returns `{ state, open,\n * close }` — `state` mirrors `WalletsModalState` and re-renders on every\n * modal lifecycle event; `open` / `close` are convenience bindings.\n *\n * Must be called inside a `<TonConnectUIProvider>`. Use this hook when the\n * dApp wants its own \"Connect\" UI separate from `<TonConnectButton />`.\n *\n * @example\n * ```tsx\n * const { state, open, close } = useTonConnectModal();\n *\n * return (\n *     <>\n *         <div>Modal status: {state?.status}</div>\n *         <button onClick={open}>Open modal</button>\n *         <button onClick={close}>Close modal</button>\n *     </>\n * );\n * ```\n */\nexport function useTonConnectModal(): Omit<WalletsModal, 'onStateChange'> {\n    const [tonConnectUI] = useTonConnectUI();\n    const [state, setState] = useState(tonConnectUI?.modal.state || null);\n\n    useEffect(() => {\n        if (tonConnectUI) {\n            setState(tonConnectUI.modal.state);\n            return tonConnectUI.onModalStateChange((value: WalletsModalState) => {\n                setState(value);\n            });\n        }\n    }, [tonConnectUI]);\n\n    return {\n        state: state,\n        open: () => tonConnectUI?.modal.open(),\n        close: () => tonConnectUI?.modal.close()\n    };\n}\n","import { useEffect, useState } from 'react';\nimport { useTonConnectUI } from './useTonConnectUI';\n\n/**\n * Indicates current status of the connection restoring process.\n */\nexport function useIsConnectionRestored(): boolean {\n    const [restored, setRestored] = useState(false);\n    const [tonConnectUI] = useTonConnectUI();\n\n    useEffect(() => {\n        if (tonConnectUI) {\n            tonConnectUI.connectionRestored.then(() => setRestored(true));\n        }\n    }, [tonConnectUI]);\n\n    return restored;\n}\n"],"names":["createContext","useState","TonConnectUI","memo","TonConnectUIError","tonConnectUI","useContext","useCallback","useEffect","jsx","useMemo","toUserFriendlyAddress","CHAIN"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,eAAwB;AACpC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,eAAwB;AACpC,SAAO,CAAC,aAAA;AACZ;ACKO,MAAM,sBAAsBA,MAAAA,cAAmC,IAAI;AA+H1E,IAAI,eAAoC;AAwBxC,MAAM,uBAAqE,CAAC,OAGtE;AAHsE,eACx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