Skip to content

Commit a836a47

Browse files
committed
add more info tonconnect/react doc
1 parent 5033be1 commit a836a47

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

docs/develop/dapps/ton-connect/react.mdx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ export const Header = () => {
6969
};
7070
```
7171

72-
You can connect to a specific wallet using the `openSingleWalletModal` method:
72+
#### Connect with a specific wallet
73+
To open a modal window for a specific wallet, use the `openSingleWalletModal()` method. This method takes the wallet's `app_name` as a parameter (refer to the [wallets-list.json]('https://github.com/ton-blockchain/wallets-list/blob/main/wallets-v2.json') file) and opens the corresponding wallet modal. It returns a promise that resolves once the modal window has successfully opened.
7374

7475
```tsx
75-
<button onClick={() => tonConnectUI.openSingleWalletModal('tonwallet)}>
76+
<button onClick={() => tonConnectUI.openSingleWalletModal('tonwallet')}>
7677
Connect Wallet
7778
</button>
7879
```
@@ -127,15 +128,32 @@ export const Address = () => {
127128
};
128129
```
129130

130-
### useTonWallet
131+
### useTonConnectModal
132+
Use this hook to access the functions for opening and closing the modal window. The hook returns an object with the current modal state and methods to open and close the modal.
131133

132-
Use it to get user's current ton wallet. If wallet is not connected hook will return null.
134+
```tsx
135+
import { useTonConnectModal } from '@tonconnect/ui-react';
133136

134-
See all wallet's properties:
137+
export const ModalControl = () => {
138+
const { state, open, close } = useTonConnectModal();
135139

136-
[Wallet interface](https://ton-connect.github.io/sdk/interfaces/_tonconnect_sdk.Wallet.html)
140+
return (
141+
<div>
142+
<div>Modal state: {state?.status}</div>
143+
<button onClick={open}>Open modal</button>
144+
<button onClick={close}>Close modal</button>
145+
</div>
146+
);
147+
};
148+
```
149+
150+
### useTonWallet
151+
152+
Use this hook to retrieve the user's current TON wallet.
153+
If the wallet is not connected, the hook will return `null`. The `wallet` object provides common data such as the user's address, provider, [TON proof](/develop/dapps/ton-connect/sign), and other attributes (see the [Wallet interface](https://ton-connect.github.io/sdk/interfaces/_tonconnect_sdk.Wallet.html)).
154+
155+
Additionally, you can access more specific details about the connected wallet, such as its name, image, and other attributes (refer to the [WalletInfo interface](https://ton-connect.github.io/sdk/types/_tonconnect_sdk.WalletInfo.html)).
137156

138-
[WalletInfo interface](https://ton-connect.github.io/sdk/types/_tonconnect_sdk.WalletInfo.html)
139157

140158
```tsx
141159
import { useTonWallet } from '@tonconnect/ui-react';
@@ -149,6 +167,12 @@ export const Wallet = () => {
149167
<span>Connected wallet address: {wallet.account.address}</span>
150168
<span>Device: {wallet.device.appName}</span>
151169
<span>Connected via: {wallet.provider}</span>
170+
{wallet.connectItems?.tonProof?.proof && <span>Ton proof: {wallet.connectItems.tonProof.proof}</span>}
171+
172+
<div>Connected wallet info:</div>
173+
<div>
174+
{wallet.name} <img src={wallet.imageUrl} />
175+
</div>
152176
</div>
153177
)
154178
);
@@ -299,7 +323,7 @@ useEffect(() => {
299323
);
300324
}
301325
});
302-
}, []);
326+
}, [tonConnectUI]);
303327
```
304328

305329
#### Structure of ton_proof

0 commit comments

Comments
 (0)