As the CNS server will push the alerts and notifications to the wallet address and the DApp will need to integrate the compound React Component packages for showing the notifications to users, we need to provide an easy out-of-the-box React Component for DApp to integrate and save their time focusing on the DApp features. And we should give the information on the React Component's workflow.
To use the CNS notification service must need to connect the Wallet and Sign a signature to log in the CNS service. The user must sign a signature and set the header for the later API requests. If the user doesn't connect to a wallet and log in, you cannot do anything with CNS notifications, it is just a connect wallet tip.
So it will need to pass the
userAddress : identify the user and send notifications to this user
signMessage : the function to sign a message for CNS service and sign a message for subscribing or unsubscribing a channel
And there will be a env and chainId
env : Production or Staging
chainId : the number of the blockchain, a decimal number
Please know that the env is relative to the chainId. Eg. if the env is Production and the chainId is the MainNet chainId, if the env is Staging and the chainId is the TestNet chainId.
If you wanna the user bind the Telegram bot to receive the notifications, should pass tgInfo
tgInfo : it is an object variable
{ botName: "your_tg_bot_name", cornerRadius: 8,}
Note: If don't pass the tgInfo then it will don't have the tg bind flow in the SDK.
The botName is your tg bot name and the cornerRadius is the Telegram Login Widget button corner radius style.
And there is a isMobile param, which is the something customize desktop and mobile style param. true or false, it is an optional param, the default is false.
Optional and Mandatory Parameters
The mandatory parameters contain: userAddress, signMessage, env and chainId.
The optional parameters contain: tgInfo and isMobile.
Code Example
The demo code includes three component Notification, Entry and Modal.
import { useNotifiContext, NotificationContainer, Header, CloseButton, NotificationContent, ErrorTipContent, ConnectWallet, WalletIcon, ConnectWalletTip, ConnectWalletButton, Login, Subscribe, Loading, MessageContent, MessageStatus, NoMessage, MessageList, Footer,} from"@cronosid/react-bell";exportconstModal= () => {const { isMobile,modalVisible } =useNotifiContext();return ( <> {modalVisible ? ( <div// add a className for the ModalclassName="cns"style={{ maxWidth: isMobile ?undefined:"368px", width:"100%", height: isMobile ?"100vh":"640px", position: isMobile ?"fixed":"absolute", left:0, top: isMobile ?0:"110px", }} > <NotificationContainer> <Header /> <CloseButton /> <NotificationContent> <ErrorTipContent /> <ConnectWallet> <WalletIcon /> <ConnectWalletTip /> <ConnectWalletButtonconnectWallet={async () => {// the function to connect the walletawaitcurrentWallet.connect(); }} /> </ConnectWallet> <Login /> <Subscribe /> <Loading /> <MessageContent> {/* the tg bind tip, if don't pass the tgInfo, it doesn't display even you pass it */} {/* <ConnectTgTip /> */} <MessageStatus /> <NoMessage /> <MessageList /> </MessageContent> </NotificationContent> <Footer /> </NotificationContainer> </div> ) :null} </> );};
The above 👆 demo is the simple version and does not require customization. If wanna customize the SDK, please go ahead.
Customization
The SDK is the Compound React Components, we can combine the components at will.
So we can do the customized component as we want. If a component has a children props, we can pass the component or string to customize it. If we don't pass children it will have the default component.
Customization Demos
Customize the BellButton Icon
Customize the CloseButton Icon
Customize the ErrorTipContent tip
Customize the NoMessage tip
Customize the ConnectWallet tip
Customize the MessageStatus tip.
Here we just wanna customize a SettingIcon but we should pass all the children components. If we don't do that, the missing component won't display.
Customize the success tip for ConnectTgTip and TgBind, please know we should pass all the children component.
Code Example
There is a full demo for customization
The CSS Style Override
If you wanna change the UI design and the styling should be consistent with your current UI. We can change the CSS style by overriding the CSS.
Importing a CSS file into your code
CSS Style Example
The above 👆 just a demo, you can change it apply to your current UI design. The components have a className you can choose a component to override it.
<ConnectWallet>
<YourWalletIcon />
<YourConnectWalletTip />
{/* or */}
{/* <ConnectWalletTip>
Your connect tip here
</ConnectWalletTip> */}
<ConnectWalletButton
connectWallet={async () => {
// the function to connect the wallet
await currentWallet.connect();
}}
/>
</ConnectWallet>