Claim Management Kit

⚙️ How to Install and Setup the Mojito Claim-management SDK module.

Overview

The Mojito Claim Management SDK offers abstractions that facilitate interactions with claim tokens in a TypeScript/JavaScript environment. This SDK primarily focuses on handling claim tokens. It also provides various options for connecting to a wallet, such as an email connection, crossmint, Metamask, Email wallet, and Wallet Connect.

This guide will help you better understand how to use and integrate the Claim-management SDK into your application.

Prerequisite

Before proceeding with the installation steps, ensure that you have the following prerequisites in place:

  1. Node.js and NPM/Yarn: Make sure you have Node.js installed on your machine, and the Node.js version should be 18 or higher, along with either NPM (Node Package Manager) or Yarn. You can download and install Node.js from the official website here.
  2. Authentication Provider: To obtain the necessary token for authentication, you need to have an authentication provider set up. This can be a JWT (JSON Web Token) or an Auth0 token, which will be passed as the "token" property in the configuration.
  3. API URL: Determine the appropriate API URL to use based on your environment.
  4. NEXT js: We are recommended to use Next.js for this SDK.
  5. Wallet: Connecting with the Mojito Claim Management SDK requires a wallet. Choose one of the following wallet options:
    1. MetaMask
    2. Wallet Connect
    3. Email Wallet
    4. Crossmint

Installation and Setup

Step 1: Install the Claim-management Module

Install the Mojito Claim-management SDK module on your project by using one of the following methods below:

Install using NPM:

npm install @mojito-inc/claim-management

Install using Yarn:

yarn add @mojito-inc/claim-management

Step 2: Connect Wallet

  1. After installing, connect your wallet by clicking the Connect your existing wallet button.

Connect Wallet Button

  1. Select the wallet that you want to connect to Mojito.
Wallet Selection
  1. Read and Agree to the terms and click on the claim now to claim an item.

Claim My Pass

  1. After claimed you will get an success modal.

Success Claim Modal

Step 3: Wrap the Provider in the Root File

To integrate the Mojito Claim Management SDK into your application, follow these steps:

  1. In the root file of your application, wrap the provider component. This step allows you to connect to the claim management APIs.

  2. Choose the appropriate API URL based on your environment:

    • Sandbox Environment: Use the API URL https://api-sandbox.mojito.xyz/query.
    • Production Environment: Use the API URL https://api.mojito.xyz/query.
  3. Obtain a JWT token or Auth0 token from your authentication provider. This token will be used for authorization purposes.

  4. Wrap the provider using the ClaimManagementProvider component from the Mojito Claim Management SDK.

Basic setup example:

import { ClaimManagementProvider } from "@mojito-inc/claim-management";
import { useState, useMemo } from "react";

function App() {
  const token = useState();
  const client = useMemo(function() {
    return {
      uri: "API_URL", // API url
      token: token || undefined // bearer token
    };
  }, [token]);

  // Note: you can get the bearer token from local storage with a key "token"
}

Provider configuration:

// ClaimManagementProvider component usage
const providerProps = {
  theme: theme, // To customise the theme refer below document
  clientOptions: client,
  onAuthenticated: setToken,
  activeChain: activeChain,
  clientId: clientId,
  walletConnectProjectId: walletConnectProjectId // project id from wallet connect
};

Step 4: Using the ClaimTokenModal Component

To utilize the ClaimTokenModal component from the Mojito Claim Management SDK, follow these steps:

  1. Import the ClaimTokenModal component from the @mojito-inc/claim-management module.
import { ClaimTokenModal } from "@mojito-inc/claim-management";
  1. Pass the required parameters to the ClaimTokenModal component.

Basic configuration:

const claimModalConfig = {
  open: true,
  name: "tokenName",
  userEmail: "[email protected]",
  config: configuration,
  onCloseModal: handleCloseModal,
  onSuccess: handleSuccess,
  onClickBuyToken: handleBuyToken,
  isDisConnect: false,
  walletOptions: walletOptions,
  link: linkConfig,
  claimCode: "CLAIM123",
  content: contentConfig,
  claimType: "customcode"
};

React Hooks

useWallet hooks

To get the connected wallet details:

import { useWallet } from "@mojito-inc/claim-management";

const walletData = useWallet();
// walletData contains: address, balance, networkDetails, provider, providerType

useTransaction hooks

To get the transaction details:

import { useTransaction } from "@mojito-inc/claim-management";

const transactionData = useTransaction();
// transactionData contains: error, fetchInvoiceDetail, transactionDetails

Parameters

ParamsTypeRequiredDescription
openbooleanto open or close the modal
configobjectConfiguration
onCloseModalevent()to close the modal
isDisConnectbooleanpass true to disconnect wallet
walletOptionsobjectwallet Options to enable or disable wallet options
linkobjectlink: redirection in app
claimCodestringpass claim code here if saleType is customcode
listingIdstringpass the listing id if claim with no code
claimTypeenumpass the claim type
isClaimWithGasbooleanclaim free token
contentobjectcontent: to customise the content inside the modal
firstNamestringuser first name
lastNamestringuser last name
userEmailstringuser email
loginWithPersonalInformationbooleanpass true if wants to login with personal information
tokenGatingConfigobjectcreate gating and pass the group and rule id
onSuccessfunctionto handle own logic for the success modal button

Configuration

ParamsTypeRequired
chainIdnumber
orgIdstring
crossmintApiKeystring
crossmintEnvstring
paperClientIdstring
paperNetworkNameEnum

Wallet Options

ParamsTypeRequired
enableMetamaskboolean
enableWalletConnectboolean
enableCrossmintboolean
enablePaperboolean

Link

ParamsTypeRequired
viewTokenTrackerURLstring
termsUrlstring
logoUrlstring

Content

ParamsTypeRequiredDescription
ClaimCodeContentobjectcontentData: to customise the title and description of claim modal
ConnectWalletContentobjectcontentData: to customise the title and description of wallet modal
SuccessContentobjectcontentData: to customise the title and description of success modal
LoaderContentobjectcontentData: to customise the title and description of loader modal
RecoveryCodeModalobjectcontentData: to customise the description of recovery modal
TokenGatingContentobjectcontentData: to customise the description of token gating eligible modal
TokenGatingNotEligibleContentobjectcontentData: to customise the description of token gating not eligible modal
ClaimWithGasContentobjectcontentData: to customise the description of claim with gas modal
ClaimErrorContentobjectcontentData: to customise the description of claim error modal

Content Data

ParamsTypeRequired
titlestring
descriptionstring

Theme Config

Basic theme configuration:

import { createTheme } from '@mui/material/styles';

const theme = createTheme({
  typography: {
    fontFamily: 'Slate',
  },
  palette: {
    primary: {
      main: '#FDCC35',
    },
    secondary: {
      main: '#356045',
    },
    background: {
      default: '#000',
    },
    text: {
      primary: '#000',
    }
  }
});

Complete theme configuration:

For a complete theme configuration with all MUI component overrides, please refer to the full documentation or the example provided in the NPM package.

TypeScript Support:

Note: If you are faced any type issue in theme, create a file called "mui.d.ts" in root or theme folder and paste the below code:

import '@mui/material/styles';

interface MojitoClaimManagementTheme {
  delivery: {
    textColor: string;
    tokenTrackerColor: string;
  };
  Discount?: {
    inProgressColor: string;
    inProgressBackground: string;
  };
  error?: string;
  deliveryBackgroundColor?: string;
  linkColor?: string;
  success: string;
  font: {
    primary: string;
    secondary: string;
    tertiary: string;
  };
}

declare module '@mui/material/styles' {
  export interface Theme {
    MojitoClaim?: MojitoClaimManagementTheme
  }
  export interface ThemeOptions {
    MojitoClaim?: MojitoClaimManagementTheme
  }
}

📘

Note:

For complete documentation of the SDK offerings, see the claim-management.