LogoLogo
CSPR.build PortalCSPR.click Website
CSPR.click (latest)
CSPR.click (latest)
  • Documentation
    • Introduction
    • Overview
    • Getting started
    • Changelog
  • CSPR.click SDK
    • React
      • Handling events
      • Connecting a wallet
      • Signing transactions
      • Customizing the top bar
        • Account dropdown menu
        • Theme selector
        • Network selector
        • Language selector
        • Currency selector
        • Custom selector
      • Hooks and Components
    • JavaScript
      • Handling events
      • Connecting a wallet
      • Signing transactions
      • Customizing the top bar
        • Account dropdown menu
        • Theme selector
        • Network selector
      • Examples
    • Reference
      • Properties
      • Methods
      • Types
      • Events
  • Get support
    • Contact us
Powered by GitBook
On this page
  • Network selector set up
  • Customize the network icons
  1. CSPR.click SDK
  2. React
  3. Customizing the top bar

Network selector

Last updated 1 year ago

If your application can switch between Mainnet and Testnet networks you may want to add the network selector widget to the CSPR.click navigation bar.

Network selector set up

Define an array with the list of networks your application supports:

export const NETWORKS = ['Mainnet', 'Testnet'];

Create a state value to store the current network. For example, with useState() hook, but you can use any other method.

const [network, setNetwork] = useState<string>(NETWORKS[1]);

Define a networkSettings object with the list of networks, the current network, and a callback method to handle network selection by the user. Add this object to the topBarSettings prop in the <ClickUI> component:

const networkSettings = {
  networks: NETWORKS,
  currentNetwork: network,
  onNetworkSwitch: (n: string) => { setNetwork(n); },
}
<ClickUI 
    topBarSettings={{
        networkSettings
    }}
/>

Customize the network icons

You can also specify your custom icons for each of the networks:

import mainnetIcon from './assets/ico-mainnet.svg'
import testnetIcon from './assets/ico-testnet.svg'

const NETWORKS = [
  { title: 'Mainnet', icon: mainnetIcon },
  { title: 'Testnet', icon: testnetIcon }
];
Network selector widget