@tonconnect/ui-react 2.2.0 → 2.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +196 -1
- package/lib/components/TonConnectUIProvider.d.ts +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +7 -12
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ You can find more details and the protocol specification in the [docs](https://d
|
|
|
12
12
|
|
|
13
13
|
# Getting started
|
|
14
14
|
|
|
15
|
-
[Latest API documentation](https://ton-connect.github.io/sdk/modules/
|
|
15
|
+
[Latest API documentation](https://ton-connect.github.io/sdk/modules/_tonconnect_ui_react.html)
|
|
16
16
|
|
|
17
17
|
# Getting started
|
|
18
18
|
|
|
@@ -39,6 +39,48 @@ export function App() {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
```
|
|
42
|
+
### Using with Next.js
|
|
43
|
+
|
|
44
|
+
`TonConnectUIProvider` relies on browser APIs and should be rendered only on the client side. In a Next.js application mark the component that wraps the provider with `"use client"` or dynamically import the provider to disable server side rendering.
|
|
45
|
+
|
|
46
|
+
Example for the `app` router:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
// app/providers.tsx
|
|
50
|
+
'use client';
|
|
51
|
+
|
|
52
|
+
import { TonConnectUIProvider } from '@tonconnect/ui-react';
|
|
53
|
+
|
|
54
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
55
|
+
return (
|
|
56
|
+
<TonConnectUIProvider manifestUrl="https://<YOUR_APP_URL>/tonconnect-manifest.json">
|
|
57
|
+
{children}
|
|
58
|
+
</TonConnectUIProvider>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For the `pages` router you can dynamically import the provider:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import dynamic from 'next/dynamic';
|
|
67
|
+
|
|
68
|
+
const TonConnectUIProvider = dynamic(
|
|
69
|
+
() => import('@tonconnect/ui-react').then(m => m.TonConnectUIProvider),
|
|
70
|
+
{ ssr: false }
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
function MyApp({ Component, pageProps }) {
|
|
74
|
+
return (
|
|
75
|
+
<TonConnectUIProvider manifestUrl="https://<YOUR_APP_URL>/tonconnect-manifest.json">
|
|
76
|
+
<Component {...pageProps} />
|
|
77
|
+
</TonConnectUIProvider>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
With both approaches the provider is executed only in the browser and works correctly.
|
|
83
|
+
|
|
42
84
|
|
|
43
85
|
You can also specify required wallet features to filter wallets that will be displayed in the connect wallet modal:
|
|
44
86
|
|
|
@@ -229,6 +271,152 @@ export const Settings = () => {
|
|
|
229
271
|
};
|
|
230
272
|
```
|
|
231
273
|
|
|
274
|
+
## Sign data
|
|
275
|
+
|
|
276
|
+
Sign arbitrary data with the user's wallet. The wallet will display the data to the user for confirmation before signing. Wallet must be connected when you call `signData`, otherwise an error will be thrown.
|
|
277
|
+
|
|
278
|
+
### Data Types
|
|
279
|
+
|
|
280
|
+
You can sign three types of data. Choose the right format based on your use case:
|
|
281
|
+
|
|
282
|
+
- **Text** - Use for human-readable text that users should see and understand
|
|
283
|
+
- **Cell** - Use for TON Blockchain data that should be used in smart contracts (wallet may show unknown content warning)
|
|
284
|
+
- **Binary** - For other arbitrary data (least preferred due to security warnings)
|
|
285
|
+
|
|
286
|
+
#### Text Format
|
|
287
|
+
|
|
288
|
+
Use when you need to sign human-readable text. The wallet displays the text to the user.
|
|
289
|
+
|
|
290
|
+
**Parameters:**
|
|
291
|
+
- `type` (string, required): Must be `"text"`
|
|
292
|
+
- `text` (string, required): UTF-8 text to sign
|
|
293
|
+
- `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
|
|
294
|
+
- `from` (string, optional): Signer address in raw format `"0:<hex>"`
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
import { useTonConnectUI } from '@tonconnect/ui-react';
|
|
298
|
+
|
|
299
|
+
export const SignTextData = () => {
|
|
300
|
+
const [tonConnectUI] = useTonConnectUI();
|
|
301
|
+
|
|
302
|
+
const handleSignText = async () => {
|
|
303
|
+
const textData = {
|
|
304
|
+
type: "text",
|
|
305
|
+
text: "Confirm new 2fa number:\n+1 234 567 8901",
|
|
306
|
+
network: "-239", // MAINNET = '-239', TESTNET = '-3'
|
|
307
|
+
from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
const result = await tonConnectUI.signData(textData);
|
|
312
|
+
console.log('Signed:', result);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
console.error('Error:', e);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
return <button onClick={handleSignText}>Sign Text Data</button>;
|
|
319
|
+
};
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
#### Binary Format
|
|
323
|
+
|
|
324
|
+
Use for arbitrary binary data. The wallet shows a warning about unknown content.
|
|
325
|
+
|
|
326
|
+
**Parameters:**
|
|
327
|
+
- `type` (string, required): Must be `"binary"`
|
|
328
|
+
- `bytes` (string, required): Base64 encoded binary data (not url-safe)
|
|
329
|
+
- `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
|
|
330
|
+
- `from` (string, optional): Signer address in raw format `"0:<hex>"`
|
|
331
|
+
|
|
332
|
+
```tsx
|
|
333
|
+
import { useTonConnectUI } from '@tonconnect/ui-react';
|
|
334
|
+
|
|
335
|
+
export const SignBinaryData = () => {
|
|
336
|
+
const [tonConnectUI] = useTonConnectUI();
|
|
337
|
+
|
|
338
|
+
const handleSignBinary = async () => {
|
|
339
|
+
const binaryData = {
|
|
340
|
+
type: "binary",
|
|
341
|
+
bytes: "1Z/SGh+3HFMKlVHSkN91DpcCzT4C5jzHT3sA/24C5A==",
|
|
342
|
+
network: "-239", // MAINNET = '-239', TESTNET = '-3'
|
|
343
|
+
from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
try {
|
|
347
|
+
const result = await tonConnectUI.signData(binaryData);
|
|
348
|
+
console.log('Signed:', result);
|
|
349
|
+
} catch (e) {
|
|
350
|
+
console.error('Error:', e);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
return <button onClick={handleSignBinary}>Sign Binary Data</button>;
|
|
355
|
+
};
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### Cell Format
|
|
359
|
+
|
|
360
|
+
Use for TON Blockchain data with TL-B schema. The wallet can parse and display the content if the schema is valid.
|
|
361
|
+
|
|
362
|
+
**Parameters:**
|
|
363
|
+
- `type` (string, required): Must be `"cell"`
|
|
364
|
+
- `schema` (string, required): TL-B schema of the cell payload
|
|
365
|
+
- `cell` (string, required): Base64 encoded BoC (not url-safe) with single-root cell
|
|
366
|
+
- `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
|
|
367
|
+
- `from` (string, optional): Signer address in raw format `"0:<hex>"`
|
|
368
|
+
|
|
369
|
+
```tsx
|
|
370
|
+
import { useTonConnectUI } from '@tonconnect/ui-react';
|
|
371
|
+
|
|
372
|
+
export const SignCellData = () => {
|
|
373
|
+
const [tonConnectUI] = useTonConnectUI();
|
|
374
|
+
|
|
375
|
+
const handleSignCell = async () => {
|
|
376
|
+
const cellData = {
|
|
377
|
+
type: "cell",
|
|
378
|
+
schema: "transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16) destination:MsgAddress response_destination:MsgAddress custom_payload:(Maybe ^Cell) forward_ton_amount:(VarUInteger 16) forward_payload:(Either Cell ^Cell) = InternalMsgBody;",
|
|
379
|
+
cell: "te6ccgEBAQEAVwAAqg+KfqVUbeTvKqB4h0AcnDgIAZucsOi6TLrfP6FcuPKEeTI6oB3fF/NBjyqtdov/KtutACCLqvfmyV9kH+Pyo5lcsrJzJDzjBJK6fd+ZnbFQe4+XggI=",
|
|
380
|
+
network: "-239", // MAINNET = '-239', TESTNET = '-3'
|
|
381
|
+
from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const result = await tonConnectUI.signData(cellData);
|
|
386
|
+
console.log('Signed:', result);
|
|
387
|
+
} catch (e) {
|
|
388
|
+
console.error('Error:', e);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
return <button onClick={handleSignCell}>Sign Cell Data</button>;
|
|
393
|
+
};
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### Response
|
|
397
|
+
|
|
398
|
+
All signData calls return the same response structure:
|
|
399
|
+
|
|
400
|
+
```ts
|
|
401
|
+
interface SignDataResult {
|
|
402
|
+
signature: string; // Base64 encoded signature
|
|
403
|
+
address: string; // Wallet address in raw format
|
|
404
|
+
timestamp: number; // UNIX timestamp in seconds (UTC)
|
|
405
|
+
domain: string; // App domain name
|
|
406
|
+
payload: object; // Original payload from the request
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Signature Verification
|
|
411
|
+
|
|
412
|
+
After receiving the signed data, you need to verify the signature to ensure it's authentic and was signed by the claimed wallet address.
|
|
413
|
+
|
|
414
|
+
**For backend verification:** See [TypeScript verification example](https://github.com/ton-connect/demo-dapp-with-react-ui/blob/master/src/server/services/sign-data-service.ts#L32-L109) showing how to verify signatures on your server.
|
|
415
|
+
|
|
416
|
+
**For smart contract verification:** See [FunC verification example](https://github.com/p0lunin/sign-data-contract-verify-example/blob/master/contracts/sign_data_example.fc) showing how to verify signatures in TON smart contracts.
|
|
417
|
+
|
|
418
|
+
**For complete technical details:** See the [Sign Data specification](https://github.com/ton-blockchain/ton-connect/blob/main/requests-responses.md#sign-data) for full signature verification requirements.
|
|
419
|
+
|
|
232
420
|
### useIsConnectionRestored
|
|
233
421
|
Indicates current status of the connection restoring process.
|
|
234
422
|
You can use it to detect when connection restoring process if finished.
|
|
@@ -403,3 +591,10 @@ Please note that this is just a warning and should not affect the functionality
|
|
|
403
591
|
```shell
|
|
404
592
|
npm install encoding
|
|
405
593
|
```
|
|
594
|
+
|
|
595
|
+
## How to find a sent transaction on the blockchain
|
|
596
|
+
|
|
597
|
+
See the detailed guide: [Transaction-by-external-message](../../guidelines/transaction-by-external-message.md)
|
|
598
|
+
|
|
599
|
+
This guide explains how to find the corresponding transaction on the TON blockchain by the BOC of an external-in message.
|
|
600
|
+
|
|
@@ -2,7 +2,7 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
import { ActionConfiguration, Locales, TonConnectUI, UIPreferences, WalletsListConfiguration } from '@tonconnect/ui';
|
|
3
3
|
import type { ITonConnect, RequiredFeatures } from '@tonconnect/ui';
|
|
4
4
|
export declare const TonConnectUIContext: import("react").Context<TonConnectUI | null>;
|
|
5
|
-
export
|
|
5
|
+
export type TonConnectUIProviderProps = {
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
} & Partial<TonConnectUIProviderPropsBase> & Partial<TonConnectUIProviderPropsWithManifest | TonConnectUIProviderPropsWithConnector>;
|
|
8
8
|
export interface TonConnectUIProviderPropsWithManifest {
|
package/lib/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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 } from 'react';\nimport {\n ActionConfiguration,\n Locales,\n TonConnectUI,\n UIPreferences,\n WalletsListConfiguration\n} from '@tonconnect/ui';\nimport type { ITonConnect, RequiredFeatures } from '@tonconnect/ui';\nimport { isClientSide } from '../utils/web';\n\nexport const TonConnectUIContext = createContext<TonConnectUI | null>(null);\n\nexport type TonConnectUIProviderProps = {\n children: ReactNode;\n} & Partial<TonConnectUIProviderPropsBase> &\n Partial<TonConnectUIProviderPropsWithManifest | TonConnectUIProviderPropsWithConnector>;\n\nexport interface TonConnectUIProviderPropsWithManifest {\n /**\n * Url to the [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest} with the Dapp metadata that will be displayed in the user's wallet.\n * If not passed, manifest from `${window.location.origin}/tonconnect-manifest.json` will be taken.\n */\n manifestUrl: string;\n}\n\nexport interface TonConnectUIProviderPropsWithConnector {\n /**\n * TonConnect instance. Can be helpful if you use custom ITonConnect implementation, or use both of @tonconnect/sdk and @tonconnect/ui in your app.\n */\n connector: ITonConnect;\n}\n\nexport interface TonConnectUIProviderPropsBase {\n /**\n * Try to restore existing session and reconnect to the corresponding wallet.\n * @default true.\n */\n restoreConnection: boolean;\n\n /**\n * Language for the phrases it the UI elements.\n * @default system\n */\n language: Locales;\n\n /**\n * HTML element id to attach the modal window element. If not passed, `div#tc-widget-root` in the end of the <body> will be added and used.\n * @default `div#tc-widget-root`.\n */\n widgetRootId: string;\n\n /**\n * UI elements configuration.\n */\n uiPreferences?: UIPreferences;\n\n /**\n * Configuration for the wallets list in the connect wallet modal.\n */\n walletsListConfiguration?: WalletsListConfiguration;\n\n /**\n * Required features for wallets to be displayed in the connect wallet modal.\n */\n walletsRequiredFeatures?: RequiredFeatures;\n\n /**\n * Preferred features for wallets to be displayed in the connect wallet modal.\n */\n walletsPreferredFeatures?: RequiredFeatures;\n\n /**\n * Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications and wallet behaviour (return strategy).\n */\n actionsConfiguration?: ActionConfiguration;\n\n /**\n * Specifies whether the Android back button should be used to close modals and notifications on Android devices.\n * @default true\n */\n enableAndroidBackHandler?: boolean;\n}\n\nlet tonConnectUI: TonConnectUI | null = null;\n\n/**\n * Add TonConnectUIProvider to the root of the app. You can specify UI options using props.\n * All TonConnect UI hooks calls and `<TonConnectButton />` component must be placed inside `<TonConnectUIProvider>`.\n * @param children JSX to insert.\n * @param [options] additional options.\n * @constructor\n */\nconst TonConnectUIProvider: FunctionComponent<TonConnectUIProviderProps> = ({\n children,\n ...options\n}) => {\n if (isClientSide() && !tonConnectUI) {\n tonConnectUI = new TonConnectUI(options);\n }\n\n return (\n <TonConnectUIContext.Provider value={tonConnectUI}>{children}</TonConnectUIContext.Provider>\n );\n};\n\nexport default memo(TonConnectUIProvider);\n","import { TonConnectUIError } from '@tonconnect/ui';\n\n/**\n * Base class for TonConnectUIReact errors. You can check if the error was triggered by the @tonconnect/ui-react using `err instanceof TonConnectUIReactError`.\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 either <TonConnectProvider> not added to the top of the tags tree,\n * either there is an attempt using TonConnect UI hook or <TonConnectButton> inside <TonConnectProvider>\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 * Use it to get access to the `TonConnectUI` instance and UI options updating function.\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\nexport interface TonConnectButtonProps {\n className?: string;\n\n style?: CSSProperties;\n}\n\n/**\n * TonConnect Button is universal UI component for initializing connection. After wallet is connected it transforms to a wallet menu.\n * It is recommended to place it in the top right corner of your app.\n * @param [className] css class to add to the button container.\n * @param [style] style to add to the button container.\n * @constructor\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 * Use it to get user's current ton wallet. If wallet is not connected hook will return null.\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 * Use it to get user's current ton wallet address. If wallet is not connected hook will return empty string.\n * @param [userFriendly=true] allows to choose format of the address.\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 * Use it to get access to the open/close modal functions.\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","TonConnectUI","memo","TonConnectUIError","tonConnectUI","useContext","useCallback","useEffect","jsx","useState","useMemo","toUserFriendlyAddress","CHAIN"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,eAAwB;AACpC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,eAAwB;AACpC,SAAO,CAAC,aAAa;AACzB;ACKa,MAAA,sBAAsBA,oBAAmC,IAAI;AAyE1E,IAAI,eAAoC;AASxC,MAAM,uBAAqE,CAAC,OAGtE;AAHsE,eACxE;AAAA;AAAA,MADwE,IAErE,oBAFqE,IAErE;AAAA,IADH;AAAA;AAGI,MAAA,aAAA,KAAkB,CAAC,cAAc;AAClB,mBAAA,IAAIC,gBAAa,OAAO;AAAA,EAAA;AAG3C,wCACK,oBAAoB,UAApB,EAA6B,OAAO,cAAe,UAAS;AAErE;AAEA,MAAeC,yBAAAA,MAAAA,KAAK,oBAAoB;ACrGjC,MAAM,+BAA+BC,GAAAA,kBAAkB;AAAA,EAC1D,eAAe,MAA2C;AACtD,UAAM,GAAG,IAAI;AAEN,WAAA,eAAe,MAAM,uBAAuB,SAAS;AAAA,EAAA;AAEpE;ACLO,MAAM,sCAAsC,uBAAuB;AAAA,EACtE,eAAe,MAA2C;AACtD,UAAM,GAAG,IAAI;AAEN,WAAA,eAAe,MAAM,8BAA8B,SAAS;AAAA,EAAA;AAE3E;ACTO,SAAS,cAAc,UAAyD;AACnF,MAAI,CAAC,UAAU;AACX,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EAAA;AAGG,SAAA;AACX;ACFO,SAAS,kBAA0E;AAChF,QAAAC,gBAAeC,iBAAW,mBAAmB;AACnD,QAAM,aAAaC,MAAA;AAAA,IACf,CAAC,YAAiC;AAC9B,UAAIF,eAAc;AACd,QAAAA,cAAc,YAAY;AAAA,MAAA;AAAA,IAElC;AAAA,IACA,CAACA,aA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Q,cAAc,iCAAQ,QAAQ,SAAS,iCAAQ,QAAQ,KAAK,CAAC;AAC7E;ACfO,SAAS,qBAA0D;AAChE,QAAA,CAACR,aAAY,IAAI,gBAAgB;AACjC,QAAA,CAAC,OAAO,QAAQ,IAAIK,MAAAA,UAASL,iBAAA,gBAAAA,cAAc,MAAM,UAAS,IAAI;AAEpEG,QAAAA,UAAU,MAAM;AACZ,QAAIH,eAAc;AACL,eAAAA,cAAa,MAAM,KAAK;AAC1B,aAAAA,cAAa,mBAAmB,CAAC,UAA6B;AACjE,iBAAS,KAAK;AAAA,MAAA,CACjB;AAAA,IAAA;AAAA,EACL,GACD,CAACA,aAAY,CAAC;AAEV,SAAA;AAAA,IACH;AAAA,IACA,MAAM,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,IAChC,OAAO,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,EACrC;AACJ;ACnBO,SAAS,0BAAmC;AAC/C,QAAM,CAAC,UAAU,WAAW,IAAIK,MAAAA,SAAS,KAAK;AACxC,QAAA,CAACL,aAAY,IAAI,gBAAgB;AAEvCG,QAAAA,UAAU,MAAM;AACZ,QAAIH,eAAc;AACd,MAAAA,cAAa,mBAAmB,KAAK,MAAM,YAAY,IAAI,CAAC;AAAA,IAAA;AAAA,EAChE,GACD,CAACA,aAAY,CAAC;AAEV,SAAA;AACX;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"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 } from 'react';\nimport {\n ActionConfiguration,\n Locales,\n TonConnectUI,\n UIPreferences,\n WalletsListConfiguration\n} from '@tonconnect/ui';\nimport type { ITonConnect, RequiredFeatures } from '@tonconnect/ui';\nimport { isClientSide } from '../utils/web';\n\nexport const TonConnectUIContext = createContext<TonConnectUI | null>(null);\n\nexport type TonConnectUIProviderProps = {\n children: ReactNode;\n} & Partial<TonConnectUIProviderPropsBase> &\n Partial<TonConnectUIProviderPropsWithManifest | TonConnectUIProviderPropsWithConnector>;\n\nexport interface TonConnectUIProviderPropsWithManifest {\n /**\n * Url to the [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest} with the Dapp metadata that will be displayed in the user's wallet.\n * If not passed, manifest from `${window.location.origin}/tonconnect-manifest.json` will be taken.\n */\n manifestUrl: string;\n}\n\nexport interface TonConnectUIProviderPropsWithConnector {\n /**\n * TonConnect instance. Can be helpful if you use custom ITonConnect implementation, or use both of @tonconnect/sdk and @tonconnect/ui in your app.\n */\n connector: ITonConnect;\n}\n\nexport interface TonConnectUIProviderPropsBase {\n /**\n * Try to restore existing session and reconnect to the corresponding wallet.\n * @default true.\n */\n restoreConnection: boolean;\n\n /**\n * Language for the phrases it the UI elements.\n * @default system\n */\n language: Locales;\n\n /**\n * HTML element id to attach the modal window element. If not passed, `div#tc-widget-root` in the end of the <body> will be added and used.\n * @default `div#tc-widget-root`.\n */\n widgetRootId: string;\n\n /**\n * UI elements configuration.\n */\n uiPreferences?: UIPreferences;\n\n /**\n * Configuration for the wallets list in the connect wallet modal.\n */\n walletsListConfiguration?: WalletsListConfiguration;\n\n /**\n * Required features for wallets to be displayed in the connect wallet modal.\n */\n walletsRequiredFeatures?: RequiredFeatures;\n\n /**\n * Preferred features for wallets to be displayed in the connect wallet modal.\n */\n walletsPreferredFeatures?: RequiredFeatures;\n\n /**\n * Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications and wallet behaviour (return strategy).\n */\n actionsConfiguration?: ActionConfiguration;\n\n /**\n * Specifies whether the Android back button should be used to close modals and notifications on Android devices.\n * @default true\n */\n enableAndroidBackHandler?: boolean;\n}\n\nlet tonConnectUI: TonConnectUI | null = null;\n\n/**\n * Add TonConnectUIProvider to the root of the app. You can specify UI options using props.\n * All TonConnect UI hooks calls and `<TonConnectButton />` component must be placed inside `<TonConnectUIProvider>`.\n * @param children JSX to insert.\n * @param [options] additional options.\n * @constructor\n */\nconst TonConnectUIProvider: FunctionComponent<TonConnectUIProviderProps> = ({\n children,\n ...options\n}) => {\n if (isClientSide() && !tonConnectUI) {\n tonConnectUI = new TonConnectUI(options);\n }\n\n return (\n <TonConnectUIContext.Provider value={tonConnectUI}>{children}</TonConnectUIContext.Provider>\n );\n};\n\nexport default memo(TonConnectUIProvider);\n","import { TonConnectUIError } from '@tonconnect/ui';\n\n/**\n * Base class for TonConnectUIReact errors. You can check if the error was triggered by the @tonconnect/ui-react using `err instanceof TonConnectUIReactError`.\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 either <TonConnectProvider> not added to the top of the tags tree,\n * either there is an attempt using TonConnect UI hook or <TonConnectButton> inside <TonConnectProvider>\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 * Use it to get access to the `TonConnectUI` instance and UI options updating function.\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\nexport interface TonConnectButtonProps {\n className?: string;\n\n style?: CSSProperties;\n}\n\n/**\n * TonConnect Button is universal UI component for initializing connection. After wallet is connected it transforms to a wallet menu.\n * It is recommended to place it in the top right corner of your app.\n * @param [className] css class to add to the button container.\n * @param [style] style to add to the button container.\n * @constructor\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 * Use it to get user's current ton wallet. If wallet is not connected hook will return null.\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 * Use it to get user's current ton wallet address. If wallet is not connected hook will return empty string.\n * @param [userFriendly=true] allows to choose format of the address.\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 * Use it to get access to the open/close modal functions.\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","TonConnectUI","memo","TonConnectUIError","tonConnectUI","useContext","useCallback","useEffect","jsx","useState","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;AAyE1E,IAAI,eAAoC;AASxC,MAAM,uBAAqE,CAAC,OAGtE;AAHsE,eACxE;AAAA;AAAA,MADwE,IAErE,oBAFqE,IAErE;AAAA,IADH;AAAA;AAGA,MAAI,aAAA,KAAkB,CAAC,cAAc;AACjC,mBAAe,IAAIC,GAAAA,aAAa,OAAO;AAAA,EAC3C;AAEA,wCACK,oBAAoB,UAApB,EAA6B,OAAO,cAAe,UAAS;AAErE;AAEA,MAAA,yBAAeC,MAAAA,KAAK,oBAAoB;ACrGjC,MAAM,+BAA+BC,GAAAA,kBAAkB;AAAA,EAC1D,eAAe,MAA2C;AACtD,UAAM,GAAG,IAAI;AAEb,WAAO,eAAe,MAAM,uBAAuB,SAAS;AAAA,EAChE;AACJ;ACLO,MAAM,sCAAsC,uBAAuB;AAAA,EACtE,eAAe,MAA2C;AACtD,UAAM,GAAG,IAAI;AAEb,WAAO,eAAe,MAAM,8BAA8B,SAAS;AAAA,EACvE;AACJ;ACTO,SAAS,cAAc,UAAyD;AACnF,MAAI,CAAC,UAAU;AACX,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAAA,EAER;AAEA,SAAO;AACX;ACFO,SAAS,kBAA0E;AACtF,QAAMC,gBAAeC,MAAAA,WAAW,mBAAmB;AACnD,QAAM,aAAaC,MAAAA;AAAAA,IACf,CAAC,YAAiC;AAC9B,UAAIF,eAAc;AACd,QAAAA,cAAc,YAAY;AAAA,MAC9B;AAAA,IACJ;AAAA,IACA,CAACA,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GAAG,CAAC,QAAQ,cAAc,iCAAQ,QAAQ,SAAS,iCAAQ,QAAQ,KAAK,CAAC;AAC7E;ACfO,SAAS,qBAA0D;AACtE,QAAM,CAACR,aAAY,IAAI,gBAAA;AACvB,QAAM,CAAC,OAAO,QAAQ,IAAIK,MAAAA,UAASL,iBAAA,gBAAAA,cAAc,MAAM,UAAS,IAAI;AAEpEG,QAAAA,UAAU,MAAM;AACZ,QAAIH,eAAc;AACd,eAASA,cAAa,MAAM,KAAK;AACjC,aAAOA,cAAa,mBAAmB,CAAC,UAA6B;AACjE,iBAAS,KAAK;AAAA,MAClB,CAAC;AAAA,IACL;AAAA,EACJ,GAAG,CAACA,aAAY,CAAC;AAEjB,SAAO;AAAA,IACH;AAAA,IACA,MAAM,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,IAChC,OAAO,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,EAAM;AAE/C;ACnBO,SAAS,0BAAmC;AAC/C,QAAM,CAAC,UAAU,WAAW,IAAIK,MAAAA,SAAS,KAAK;AAC9C,QAAM,CAACL,aAAY,IAAI,gBAAA;AAEvBG,QAAAA,UAAU,MAAM;AACZ,QAAIH,eAAc;AACd,MAAAA,cAAa,mBAAmB,KAAK,MAAM,YAAY,IAAI,CAAC;AAAA,IAChE;AAAA,EACJ,GAAG,CAACA,aAAY,CAAC;AAEjB,SAAO;AACX;;;;;;;;;;;;;;;;;"}
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","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 } from 'react';\nimport {\n ActionConfiguration,\n Locales,\n TonConnectUI,\n UIPreferences,\n WalletsListConfiguration\n} from '@tonconnect/ui';\nimport type { ITonConnect, RequiredFeatures } from '@tonconnect/ui';\nimport { isClientSide } from '../utils/web';\n\nexport const TonConnectUIContext = createContext<TonConnectUI | null>(null);\n\nexport type TonConnectUIProviderProps = {\n children: ReactNode;\n} & Partial<TonConnectUIProviderPropsBase> &\n Partial<TonConnectUIProviderPropsWithManifest | TonConnectUIProviderPropsWithConnector>;\n\nexport interface TonConnectUIProviderPropsWithManifest {\n /**\n * Url to the [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest} with the Dapp metadata that will be displayed in the user's wallet.\n * If not passed, manifest from `${window.location.origin}/tonconnect-manifest.json` will be taken.\n */\n manifestUrl: string;\n}\n\nexport interface TonConnectUIProviderPropsWithConnector {\n /**\n * TonConnect instance. Can be helpful if you use custom ITonConnect implementation, or use both of @tonconnect/sdk and @tonconnect/ui in your app.\n */\n connector: ITonConnect;\n}\n\nexport interface TonConnectUIProviderPropsBase {\n /**\n * Try to restore existing session and reconnect to the corresponding wallet.\n * @default true.\n */\n restoreConnection: boolean;\n\n /**\n * Language for the phrases it the UI elements.\n * @default system\n */\n language: Locales;\n\n /**\n * HTML element id to attach the modal window element. If not passed, `div#tc-widget-root` in the end of the <body> will be added and used.\n * @default `div#tc-widget-root`.\n */\n widgetRootId: string;\n\n /**\n * UI elements configuration.\n */\n uiPreferences?: UIPreferences;\n\n /**\n * Configuration for the wallets list in the connect wallet modal.\n */\n walletsListConfiguration?: WalletsListConfiguration;\n\n /**\n * Required features for wallets to be displayed in the connect wallet modal.\n */\n walletsRequiredFeatures?: RequiredFeatures;\n\n /**\n * Preferred features for wallets to be displayed in the connect wallet modal.\n */\n walletsPreferredFeatures?: RequiredFeatures;\n\n /**\n * Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications and wallet behaviour (return strategy).\n */\n actionsConfiguration?: ActionConfiguration;\n\n /**\n * Specifies whether the Android back button should be used to close modals and notifications on Android devices.\n * @default true\n */\n enableAndroidBackHandler?: boolean;\n}\n\nlet tonConnectUI: TonConnectUI | null = null;\n\n/**\n * Add TonConnectUIProvider to the root of the app. You can specify UI options using props.\n * All TonConnect UI hooks calls and `<TonConnectButton />` component must be placed inside `<TonConnectUIProvider>`.\n * @param children JSX to insert.\n * @param [options] additional options.\n * @constructor\n */\nconst TonConnectUIProvider: FunctionComponent<TonConnectUIProviderProps> = ({\n children,\n ...options\n}) => {\n if (isClientSide() && !tonConnectUI) {\n tonConnectUI = new TonConnectUI(options);\n }\n\n return (\n <TonConnectUIContext.Provider value={tonConnectUI}>{children}</TonConnectUIContext.Provider>\n );\n};\n\nexport default memo(TonConnectUIProvider);\n","import { TonConnectUIError } from '@tonconnect/ui';\n\n/**\n * Base class for TonConnectUIReact errors. You can check if the error was triggered by the @tonconnect/ui-react using `err instanceof TonConnectUIReactError`.\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 either <TonConnectProvider> not added to the top of the tags tree,\n * either there is an attempt using TonConnect UI hook or <TonConnectButton> inside <TonConnectProvider>\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 * Use it to get access to the `TonConnectUI` instance and UI options updating function.\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\nexport interface TonConnectButtonProps {\n className?: string;\n\n style?: CSSProperties;\n}\n\n/**\n * TonConnect Button is universal UI component for initializing connection. After wallet is connected it transforms to a wallet menu.\n * It is recommended to place it in the top right corner of your app.\n * @param [className] css class to add to the button container.\n * @param [style] style to add to the button container.\n * @constructor\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 * Use it to get user's current ton wallet. If wallet is not connected hook will return null.\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 * Use it to get user's current ton wallet address. If wallet is not connected hook will return empty string.\n * @param [userFriendly=true] allows to choose format of the address.\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 * Use it to get access to the open/close modal functions.\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":["tonConnectUI"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,eAAwB;AACpC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,eAAwB;AACpC,SAAO,CAAC,aAAa;AACzB;ACKa,MAAA,sBAAsB,cAAmC,IAAI;AAyE1E,IAAI,eAAoC;AASxC,MAAM,uBAAqE,CAAC,OAGtE;AAHsE,eACxE;AAAA;AAAA,MADwE,IAErE,oBAFqE,IAErE;AAAA,IADH;AAAA;AAGI,MAAA,aAAA,KAAkB,CAAC,cAAc;AAClB,mBAAA,IAAI,aAAa,OAAO;AAAA,EAAA;AAG3C,6BACK,oBAAoB,UAApB,EAA6B,OAAO,cAAe,UAAS;AAErE;AAEA,MAAe,yBAAA,KAAK,oBAAoB;ACrGjC,MAAM,+BAA+B,kBAAkB;AAAA,EAC1D,eAAe,MAA2C;AACtD,UAAM,GAAG,IAAI;AAEN,WAAA,eAAe,MAAM,uBAAuB,SAAS;AAAA,EAAA;AAEpE;ACLO,MAAM,sCAAsC,uBAAuB;AAAA,EACtE,eAAe,MAA2C;AACtD,UAAM,GAAG,IAAI;AAEN,WAAA,eAAe,MAAM,8BAA8B,SAAS;AAAA,EAAA;AAE3E;ACTO,SAAS,cAAc,UAAyD;AACnF,MAAI,CAAC,UAAU;AACX,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EAAA;AAGG,SAAA;AACX;ACFO,SAAS,kBAA0E;AAChF,QAAAA,gBAAe,WAAW,mBAAmB;AACnD,QAAM,aAAa;AAAA,IACf,CAAC,YAAiC;AAC9B,UAAIA,eAAc;AACd,QAAAA,cAAc,YAAY;AAAA,MAAA;AAAA,IAElC;AAAA,IACA,CAACA,aAAY;AAAA,EACjB;AAEA,MAAI,gBAAgB;AACT,WAAA,CAAC,MAAiC,MAAM;A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AAgB;AACjC,QAAA,CAAC,OAAO,QAAQ,IAAI,UAASA,iBAAA,gBAAAA,cAAc,MAAM,UAAS,IAAI;AAEpE,YAAU,MAAM;AACZ,QAAIA,eAAc;AACL,eAAAA,cAAa,MAAM,KAAK;AAC1B,aAAAA,cAAa,mBAAmB,CAAC,UAA6B;AACjE,iBAAS,KAAK;AAAA,MAAA,CACjB;AAAA,IAAA;AAAA,EACL,GACD,CAACA,aAAY,CAAC;AAEV,SAAA;AAAA,IACH;AAAA,IACA,MAAM,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,IAChC,OAAO,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,EACrC;AACJ;ACnBO,SAAS,0BAAmC;AAC/C,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AACxC,QAAA,CAACA,aAAY,IAAI,gBAAgB;AAEvC,YAAU,MAAM;AACZ,QAAIA,eAAc;AACd,MAAAA,cAAa,mBAAmB,KAAK,MAAM,YAAY,IAAI,CAAC;AAAA,IAAA;AAAA,EAChE,GACD,CAACA,aAAY,CAAC;AAEV,SAAA;AACX;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","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 } from 'react';\nimport {\n ActionConfiguration,\n Locales,\n TonConnectUI,\n UIPreferences,\n WalletsListConfiguration\n} from '@tonconnect/ui';\nimport type { ITonConnect, RequiredFeatures } from '@tonconnect/ui';\nimport { isClientSide } from '../utils/web';\n\nexport const TonConnectUIContext = createContext<TonConnectUI | null>(null);\n\nexport type TonConnectUIProviderProps = {\n children: ReactNode;\n} & Partial<TonConnectUIProviderPropsBase> &\n Partial<TonConnectUIProviderPropsWithManifest | TonConnectUIProviderPropsWithConnector>;\n\nexport interface TonConnectUIProviderPropsWithManifest {\n /**\n * Url to the [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest} with the Dapp metadata that will be displayed in the user's wallet.\n * If not passed, manifest from `${window.location.origin}/tonconnect-manifest.json` will be taken.\n */\n manifestUrl: string;\n}\n\nexport interface TonConnectUIProviderPropsWithConnector {\n /**\n * TonConnect instance. Can be helpful if you use custom ITonConnect implementation, or use both of @tonconnect/sdk and @tonconnect/ui in your app.\n */\n connector: ITonConnect;\n}\n\nexport interface TonConnectUIProviderPropsBase {\n /**\n * Try to restore existing session and reconnect to the corresponding wallet.\n * @default true.\n */\n restoreConnection: boolean;\n\n /**\n * Language for the phrases it the UI elements.\n * @default system\n */\n language: Locales;\n\n /**\n * HTML element id to attach the modal window element. If not passed, `div#tc-widget-root` in the end of the <body> will be added and used.\n * @default `div#tc-widget-root`.\n */\n widgetRootId: string;\n\n /**\n * UI elements configuration.\n */\n uiPreferences?: UIPreferences;\n\n /**\n * Configuration for the wallets list in the connect wallet modal.\n */\n walletsListConfiguration?: WalletsListConfiguration;\n\n /**\n * Required features for wallets to be displayed in the connect wallet modal.\n */\n walletsRequiredFeatures?: RequiredFeatures;\n\n /**\n * Preferred features for wallets to be displayed in the connect wallet modal.\n */\n walletsPreferredFeatures?: RequiredFeatures;\n\n /**\n * Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications and wallet behaviour (return strategy).\n */\n actionsConfiguration?: ActionConfiguration;\n\n /**\n * Specifies whether the Android back button should be used to close modals and notifications on Android devices.\n * @default true\n */\n enableAndroidBackHandler?: boolean;\n}\n\nlet tonConnectUI: TonConnectUI | null = null;\n\n/**\n * Add TonConnectUIProvider to the root of the app. You can specify UI options using props.\n * All TonConnect UI hooks calls and `<TonConnectButton />` component must be placed inside `<TonConnectUIProvider>`.\n * @param children JSX to insert.\n * @param [options] additional options.\n * @constructor\n */\nconst TonConnectUIProvider: FunctionComponent<TonConnectUIProviderProps> = ({\n children,\n ...options\n}) => {\n if (isClientSide() && !tonConnectUI) {\n tonConnectUI = new TonConnectUI(options);\n }\n\n return (\n <TonConnectUIContext.Provider value={tonConnectUI}>{children}</TonConnectUIContext.Provider>\n );\n};\n\nexport default memo(TonConnectUIProvider);\n","import { TonConnectUIError } from '@tonconnect/ui';\n\n/**\n * Base class for TonConnectUIReact errors. You can check if the error was triggered by the @tonconnect/ui-react using `err instanceof TonConnectUIReactError`.\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 either <TonConnectProvider> not added to the top of the tags tree,\n * either there is an attempt using TonConnect UI hook or <TonConnectButton> inside <TonConnectProvider>\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 * Use it to get access to the `TonConnectUI` instance and UI options updating function.\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\nexport interface TonConnectButtonProps {\n className?: string;\n\n style?: CSSProperties;\n}\n\n/**\n * TonConnect Button is universal UI component for initializing connection. After wallet is connected it transforms to a wallet menu.\n * It is recommended to place it in the top right corner of your app.\n * @param [className] css class to add to the button container.\n * @param [style] style to add to the button container.\n * @constructor\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 * Use it to get user's current ton wallet. If wallet is not connected hook will return null.\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 * Use it to get user's current ton wallet address. If wallet is not connected hook will return empty string.\n * @param [userFriendly=true] allows to choose format of the address.\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 * Use it to get access to the open/close modal functions.\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":["tonConnectUI"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,eAAwB;AACpC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,eAAwB;AACpC,SAA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A,IACL;AAAA,EACJ,GAAG,CAACA,aAAY,CAAC;AAEjB,SAAO;AAAA,IACH;AAAA,IACA,MAAM,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,IAChC,OAAO,MAAMA,iBAAA,gBAAAA,cAAc,MAAM;AAAA,EAAM;AAE/C;ACnBO,SAAS,0BAAmC;AAC/C,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,CAACA,aAAY,IAAI,gBAAA;AAEvB,YAAU,MAAM;AACZ,QAAIA,eAAc;AACd,MAAAA,cAAa,mBAAmB,KAAK,MAAM,YAAY,IAAI,CAAC;AAAA,IAChE;AAAA,EACJ,GAAG,CAACA,aAAY,CAAC;AAEjB,SAAO;AACX;"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonconnect/ui-react",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"scripts": {
|
|
5
|
-
"dev": "vite",
|
|
6
|
-
"build": "tsc && vite build"
|
|
7
|
-
},
|
|
3
|
+
"version": "2.3.0-beta.1",
|
|
8
4
|
"repository": {
|
|
9
5
|
"type": "git",
|
|
10
6
|
"url": "git+https://github.com/ton-connect/sdk.git"
|
|
@@ -52,18 +48,17 @@
|
|
|
52
48
|
"vite-plugin-dts": "^1.7.1"
|
|
53
49
|
},
|
|
54
50
|
"dependencies": {
|
|
55
|
-
"@tonconnect/ui": "2.
|
|
51
|
+
"@tonconnect/ui": "2.3.0-beta.1"
|
|
56
52
|
},
|
|
57
53
|
"peerDependencies": {
|
|
58
54
|
"react": ">=17.0.0",
|
|
59
55
|
"react-dom": ">=17.0.0"
|
|
60
56
|
},
|
|
61
|
-
"nx": {
|
|
62
|
-
"tags": [
|
|
63
|
-
"scope:ui-react"
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
57
|
"typedoc": {
|
|
67
58
|
"entryPoint": "./src/library.ts"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"dev": "vite",
|
|
62
|
+
"build": "tsc && vite build"
|
|
68
63
|
}
|
|
69
|
-
}
|
|
64
|
+
}
|