LogoLogo
CSPR.build PortalCSPR.click Website
CSPR.click v1.2
CSPR.click v1.2
  • Introduction (v1.2)
    • CSPR.click overview
    • Get your application Id
    • Changelog
  • UI SDK
    • Getting started with the template application
    • Integrating the UI SDK into your application
    • Integrating the UI SDK into a non-React application
    • Customizing the top bar
      • Account dropdown menu
      • Theme selector
      • Network selector
      • Language selector
      • Currency selector
      • Custom selector
    • useClickRef() hook
    • Handling events
    • Signing transactions
  • Core JS SDK
    • Getting started
    • Properties
    • Methods
    • Types
    • Events
  • Get support
    • Contact us
Powered by GitBook
On this page
  • Install CSPR.click dependencies
  • ClickProvider context provider
  • Add <ClickTopBar> component to your app
  • Add CSPR.click styles
  • Option 1: your application uses styled-components
  • Option 2: your application doesn't use styled-components
  • Bind callbacks to respond to connection events
  • Request transaction approvals
  1. UI SDK

Integrating the UI SDK into your application

This page guides you through the steps required to integrate the UI SDK into your existing web application.

Install CSPR.click dependencies

Run the following command in a terminal window to install CSPR.click libraries:

npm install --save-dev @make-software/csprclick-ui @make-software/csprclick-core-client @make-software/csprclick-core-types

If you're using Typescript, the command above also installs type definitions for CSPR.click.

ClickProvider context provider

First, define the initialization options for the CSPR.click library:

import { CONTENT_MODE } from '@make-software/csprclick-core-types';

const clickOptions: CsprClickInitOptions = {
    appName: 'Casper dApp',
    appId: 'csprclick-template',
    contentMode: CONTENT_MODE.IFRAME,
    providers: [
        'casper-wallet',
        'ledger',
        'casper-signer',
    ]
};

Next, wrap your main application component with the <ClickProvider> context provider:

<ClickProvider options={clickOptions}>
  <App />
</ClickProvider>

This component will download the Core JS SDK and initialize it with the options defined.

Add <ClickTopBar> component to your app

All the CSPR.click UI elements are managed from the <ClickTopBar> component. This component must be added to the very beginning of your main UI component and it's responsible for displaying the top bar and all the modal windows and pop-ups needed for connecting with wallets, showing information to the user, etc.

<ClickTopBar
  onThemeSwitch={toggleTheme}
  themeMode={themeMode}
  accountMenuItems={accountMenuItems}
  languageSettings={languageSettings}
  currencySettings={currencySettings}
  networkSettings={networkSettings}
/>

Add CSPR.click styles

Option 1: your application uses styled-components

When your application already uses the <ThemeProvider> component from styled-components library, you need to add CSPR.click styles to your themes.

Considering as an example that your application has light and dark themes, you may merge our styles into your themes like this:

import { CsprClickThemes } from '@make-software/csprclick-react';

const YourAppThemes = {
	dark: {
		...CsprClickThemes.dark,
		// your styles for dark theme here
	},
	light: {
		...CsprClickThemes.light,
		// your styles for light theme here
	},
};

Option 2: your application doesn't use styled-components

Since CSPR.click depends on styled-components library, add it to your dependencies by running the command:

npm install --save styled-components

Now, add the theme provider to your application. It must wrap at least the <ClickTopBar> component you added in the previous step:

import { CsprClickThemes } from '@make-software/csprclick-react';

<ThemeProvider theme={CsprClickThemes['dark']}>
  <ClickTopBar
    ...
  />
</ThemeProvider>

Note you can choose between two themes: light and dark.

Bind callbacks to respond to connection events

In your application, you'll need to listen and respond to some events triggered when the user connects an account, switches to a different one, or closes the session.

Request transaction approvals

At some point, your application will need to interact with the Casper network by sending a transaction (aka deploy). CSPR.click manages this process communicating with the active wallet to request the user to approve or reject the transaction. The UI depends on the wallet.

PreviousGetting started with the template applicationNextIntegrating the UI SDK into a non-React application

Last updated 1 year ago

You can use the default csprclick-template application identifier while you're working locally on your application. But to upload your new project to a server, you'll need to .

Update the properties in the example according to your needs. Read more about the type in the Core JS SDK reference.

Refer to the section in this guide for complete reference on how to work with each of the settings added as props to this component.

Refer to the page for information on how to listen to these events.

Refer to the page for information on how to request the user a transaction approval.

get your own application id
Customizing the top bar
Handling events
Signing transactions
CsprClickInitOptions