-
Notifications
You must be signed in to change notification settings - Fork 89
/
TonConnectButton.tsx
36 lines (29 loc) · 1.09 KB
/
TonConnectButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { CSSProperties, FunctionComponent, memo, useEffect } from 'react';
import { useTonConnectUI } from '../hooks/useTonConnectUI';
const buttonRootId = 'ton-connect-button';
export interface TonConnectButtonProps {
className?: string;
style?: CSSProperties;
}
/**
* TonConnect Button is universal UI component for initializing connection. After wallet is connected it transforms to a wallet menu.
* It is recommended to place it in the top right corner of your app.
* @param [className] css class to add to the button container.
* @param [style] style to add to the button container.
* @constructor
*/
const TonConnectButton: FunctionComponent<TonConnectButtonProps> = ({ className, style }) => {
const [_, setOptions] = useTonConnectUI();
useEffect(() => {
setOptions({ buttonRootId });
return () => setOptions({ buttonRootId: null });
}, [setOptions]);
return (
<div
id={buttonRootId}
className={className}
style={{ width: 'fit-content', ...style }}
></div>
);
};
export default memo(TonConnectButton);