connect requests and terminated via disconnect requests.
Connection flow
Standard flow looks as follows:- User clicks a “Connect wallet” button in the dApp, selecting the desired wallet service
- WalletKit processes the connection URL and triggers the
onConnectRequest()method - There, WalletKit instructs the wallet service to show a connection request preview, waiting for the user’s approval
- User approves or rejects a connection
disconnect request will be issued and the onDisconnect() method of the WalletKit will handle it.
Handlers
To work with connection-specific requests, the WalletKit offers three methods which expect processing functions as callbacks:- The
onConnectRequest()method processes connection requests - The
onDisconnect()method processes disconnection requests - The
onRequestError()method allows to handle errors arising in any of the requests
Handle onConnectRequest
When a user wants to connect a TON wallet from the dApp, the dApp fires the connect request over the bridge. The wallet service then handles it with the onConnectRequest method of the WalletKit.
On the dApp side, this flow is often initiated by pressing the “Connect a wallet” button, followed by selecting the user’s wallet service. Additionally, a dApp can produce a QR code or a deep link, which initiate the connection flow from within the wallet service.
TypeScript
Wallet selection
When there are several TON wallets added, ask the user to select one before approving the connection request.TypeScript
QR codes and deep links
ThehandleTonConnectUrl() method of the WalletKit parses a TON Connect link and creates a new connection request event.
Usually, this link comes from a QR code generated on the dApp side, but it can also be provided within the mobile dApp as a deep link.
TypeScript
Handle onDisconnect
When a user disconnects a wallet service and its TON wallet from the dApp, the dApp fires the disconnect request over the bridge. The wallet service then handles it with the onDisconnect method of the WalletKit.
TypeScript