1.0.2-beta.62 • Published 3 months ago

@mojito-inc/claim-management v1.0.2-beta.62

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Using this library in your project Claim Management

You can install this project with one of these commands:

npm install --save @mojito-inc/claim-management

yarn add @mojito-inc/claim-management

Install the following packages:

npm i @mui/material@5.11.11 @mui/icons-material@5.11.11 @apollo/client graphql @web3modal/ethers5 @walletconnect/modal

yarn add @mui/material@5.11.11 @mui/icons-material@5.11.11 @apollo/client graphql @web3modal/ethers5 @walletconnect/modal

Theme Config

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

  export const theme = createTheme({
    typography: {
      fontFamily: 'Slate',
    },
    components: {
      MuiTextField: {
        styleOverrides: {
          root: {
            '& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button':
              {
                display: 'none',
              },
            '& input[type=number]': {
              MozAppearance: 'textfield',
            },
          },
        },
      },
      MuiCssBaseline: {
        styleOverrides: `
                @font-face {
                  font-family: "Slate";
                  font-style: normal;
                  font-display: swap;
                  font-weight: 400;
                  text-transform: none;
                  font-size: 16px;
                }
              `,
      },
      MuiButton: {
        styleOverrides: {
          root: {
            fontFamily: 'Slate',
            textTransform: 'none',
            borderRadius: '4px',
            fontWeight: 700,
            fontSize: '16px',
            backgroundColor: '#FDCC35',
            color: '#000',
            '&:hover': {
              backgroundColor: '#FDCC35',
              color: '#000',
              opacity: 0.5,
            },
          },
        },
      },
      MuiDialog: {
        styleOverrides: {
          paper: {
            border: '1px solid #D7D8DB',
            boxShadow: '0px 8px 16px rgba(0, 0, 0, 0.08)',
            borderRadius: '4px',
          },
        },
      },
      MuiDivider: {
        variants: [
          {
            props: { orientation: 'horizontal' },
            style: {
              ':before': {
                borderTop: 'thin solid #D7D8DB',
              },
              ':after': {
                borderTop: 'thin solid #D7D8DB',
              },
            },
          },
        ],
      },
    },
    palette: {
      primary: {
        main: '#FDCC35',
      },
      secondary: {
        main: '#356045',
        light: '#F5F5F5',
      },
      background: {
        default: '#000',
      },
      text: {
        primary: '#000',
      },
      grey: {
        100: '#868b93',
        500: '#A1A5AB',
      },
      divider: '#fff',
      toastWarning: {
        50: '#FFFFE5',
        100: '#FFFEC0',
        200: '#FCFB99',
        300: '#F8F676',
        400: '#F5F15C',
        500: '#F0EB47',
        600: '#FBDF47',
        700: '#FDC740',
        800: '#FCAD36',
        900: '#F98028',
      },
    },
    MojitoClaim: {
      Header: {
        background: '#000',
      },
      Footer: {
        background: '#000',
        color: '#fff',
      },
      Hero: {
        background: '#356045',
        color: '#fff',
      },
      Discount: {
        inProgressColor: '#F98028',
        inProgressBackground: '#FFFEC0',
      },
      error: '#BF1E18',
      success: '#3E8045',
      deliveryBackgroundColor: '#FAFBFB',
      linkColor: '#6563FD',
      textTertiary: '#868b93',
      borderColor: '#242629'
    },
    MojitoCoreUI: {
      font: {
        primary: 'Slate',
        secondary: 'Slate',
        tertiary: 'Sneak',
      },
    },
  });

Theme Notes for typescript error

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

import '@mui/material/styles';
import { MojitoClaimManagementTheme } from './MojitoClaimManagementTheme';

declare module '@mui/material/styles' {
  export interface Theme {
    MojitoClaim?: MojitoClaimManagementTheme
  }
  // allow configuration using `createTheme`
  export interface ThemeOptions {
    MojitoClaim?: MojitoClaimManagementTheme
  }
}

Once the package is installed, you can import the library using import;

For theme configuration Ref above: Theme Config

  import { ClaimManagementProvider } from '@mojito-inc/claim-management';

  const [token, setToken] = useState<string>();
  const client = useMemo(
    () => ({
      uri: 'https://api-sandbox.mojito.xyz/query', // API url
      token: token || undefined, // bearer token
    }),
    [token],
  );

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

  <ClaimManagementProvider
    theme={theme}
    clientOptions={client}
    activeChain={activeChain}
    clientId={clientId}
    onAuthenticated={setToken}
    walletConnectProjectId={ walletConnectProjectId } // project id from wallet connect
    walletOptions={{         // Optional parameter
      enableCrossmint: false,
      enableMetamask: true,
      enableWalletConnect: true,
      enableEmailWallet: true,
    }}
  >
    <Component {...pageProps} />
  </ClaimManagementProvider>

onAuthenticated

when user gets Authenticated gets token as response

Provider parameters

ParamtypeRequiredDescription
themetheme
clientobject
activeChainenum
clientIdstringclient id for email wallet
walletConnectProjectIdstringwallet connect project id
onAuthenticatedfunction
walletOptionsobjectwalletOptions

ClaimTokenModal

present claim token modal for following setup

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

  <ClaimTokenModal
    open=<open>
    name=<name>
    userEmail=<userEmail>
    config=<Configuration>
    onCloseModal=<onCloseModal>
    onSuccess=<onSuccess>
    onClickBuyToken=<onClickBuyToken>
    isDisConnect=<isDisConnect>
    walletOptions=<walletOptions>
    link=<link>
    claimCode=<claimCode>
    tokenGatingConfig={{
      groupId: <groupId>,
      ruleId: <ruleId>,
    }}
    content=<content>
    claimType=<claimType>
  />
ParamtypeRequiredDescription
openbooleanif true it will open the modal if false the modal will close
configObjectConfiguration
isDisConnectbooleanto disconnect wallet
onCloseModalfunctionto close the modal
linkObjectlink
claimCodestringpass the claim code
listingIdstringpass the item id for claim process
contentObjectcontent to define the content for the popup
onSuccessfunctionfunction for handle your own logic in success modal button
skipClaimModalbooleanif true it will skip the claim process after connect connect
skipSuccessModalbooleanif true it will skip the success screen after claim completed
skipConfirmClaimModalbooleanif true it will skip the claim confirmation screen and claim will happen automatically once wallet connected
isPaperWalletbooleanif true it will work as paper wallet with email else it will work as thirdweb embedded wallet.
tokenGatingConfigObjecttokenGatingConfig config for token gating
tokenNamestringpass the token name for token gating
onclickBuyTokenfunctionfunction to make custom redirection when click on buy token button
showDisconnectButtonbooleanif true it will show Disconnect Wallet button in token gating modal
showBuyButtonbooleanif false it will hide buy now button in token gating modal
isClaimWithGasbooleanif true the claim process will execute with metamask
pricestringpass price to display in claim UI
claimTypeenumpass claim type
loginWithPersonalInformationbooleanif true means personal information should be provided by user
firstNamestringpass the first name of the user
lastNamestringpass the last name of the user
userEmailstringpass the email of the user

Hooks

useWallet hooks

To get the connected wallet details:

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

  const { address, balance, networkDetails, provider, providerType } = useWallet();

useTransaction hooks

To get the transaction details:

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

  const { error, fetchInvoiceDetail, transactionDetails } = useTransaction();

Transaction interface

ParamtypeRequiredDescription
errorbooleanreturn true if invoice API fail
fetchInvoiceDetailasync function(invoiceId)to fetch the invoice details. you should pass the invoiceId
transactionDetailsobjectafter successfully claim or refetch the invoice API (fetchInvoiceDetail) you will get transaction object

interface

Configuration

ParamtypeRequiredDescription
chainIdnumber
orgIdstring
crossmintApiKeystring
crossmintEnvstring
paperClientIdstring
paperNetworkNamestring

walletOptions

ParamtypeRequiredDescription
enableCrossmintboolean
enableMetamaskboolean
enableWalletConnectboolean
enableEmailWalletboolean

link

ParamtypeRequiredDescription
viewTokenTrackerURLstring
termsUrlstringterms and condition url for claim
privacyUrlstringprivacy policy url for claim
additionalTermsUrlstringif more than one terms and condition url for claim
logoUrlstringto define app logo

content

ParamtypeRequiredDescription
ClaimCodeContentObjectcontentData
SuccessContentObjectcontentData
ConnectWalletContentObjectcontentData
LoaderContentObject
RecoveryCodeModalObject
ClaimWithGasContentObject
TokenGatingContentObject
TokenGatingNotEligibleContentObject
ClaimErrorContentObject

tokenGatingConfig

ParamtypeRequiredDescription
groupIdstring
ruleIdstring

walletOptions

ParamtypeRequiredDescription
enableMetamaskboolean
enableWalletConnectboolean
enableEmailWalletboolean

paymentOptions

ParamtypeRequiredDescription
creditCardboolean
walletConnectboolean
wireboolean
coinbaseboolean

mixersConfig

ParamtypeRequiredDescription
lotIdstring
paymentIdstring
discountCodestring
walletOptionsobjectwalletOptions
paymentOptionsobjectpaymentOptions
errorPageUrlstringredirection url during checkout payment error
successPageUrlstringredirection url for success page
isAutoFillCountryCodebooleanTo enable or disable auto country code import
breadCrumbsarrayCustom bread crumbs name
onClickGoToMarketPlacefunctioncustom function when click on back to marketplace after payment in mixers

contentData

ParamtypeRequiredDescription
titlestring
descriptionstring
buttonNamestring
breadcrumbsLabelstring;
agreeTermsAndConditionsMessagestring;
additionalTermsAndConditionsLabelstring;
privacyPolicyLabelstring;
termsandConditionsLabelstring;
titleImageURLstring;

To use Mixers SDK for BuyNow Flow

Note:

In the _app.tsx file, please add the following line: <Script src="https://cdn.checkout.com/js/framesv2.min.js" />. if it was not added, credit card payments won't work.

ClaimTokenModal

present claim token modal for following setup

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

  <ClaimTokenModal
    open=<open>
    name=<name>
    userEmail=<userEmail>
    config=<Configuration>
    mixersConfig=<MixersConfiguration>
    onCloseModal=<onCloseModal>
    onSuccess=<onSuccess>
    isDisConnect=<isDisConnect>
    walletOptions=<walletOptions>
    content=<content>
    claimType="BuyNow"
  />
ParamtypeRequiredDescription
openbooleanif true it will open the modal if false the modal will close
configObjectConfiguration
isDisConnectbooleanto disconnect wallet
walletOptionsObjectwalletOptions
onCloseModalfunctionto close the modal
linkObjectlink
listingIdstringpass the item id for claim process
contentObjectcontent to define the content for the popup
onSuccessfunctionfunction for handle your own logic in success modal button
showDisconnectButtonbooleanif true it will show Disconnect Wallet button in token gating modal
showBuyButtonbooleanif false it will hide buy now button in token gating modal
isClaimWithGasbooleanif true the claim process will execute with metamask
claimTypeenumpass claim type
loginWithPersonalInformationbooleanif true means personal information should be provided by user
firstNamestringpass the first name of the user
lastNamestringpass the last name of the user
userEmailstringpass the email of the user
mixersConfigObjectmixersConfig config for mixers buy now

Error page

Create an error page with the page path /payments/failure:

Success page

Create an success page with the page path /payments/success:

Retrieve the paymentId from the query parameters of the URL and pass it as a parameter to the MojitoCheckout component

  <PaymentMixersSuccess
    onClickGoToMarketPlace={onClickGoToMarketPlace} />

Claim Service development

Development setup

1.0.2-beta.62

3 months ago

1.0.2-beta.61

3 months ago

1.0.2-beta.60

3 months ago

1.0.2-beta.59

3 months ago

1.0.2-beta.57

3 months ago

1.0.2-beta.58

3 months ago

1.0.2-beta.55

3 months ago

1.0.2-beta.56

3 months ago

1.0.2-beta.54

3 months ago

1.0.2-beta.53

3 months ago

1.0.2-beta.51

3 months ago

1.0.2-beta.52

3 months ago

1.0.2-beta.50

3 months ago

1.0.2-beta.48

3 months ago

1.0.2-beta.49

3 months ago

1.0.2-beta.46

3 months ago

1.0.2-beta.47

3 months ago

1.0.2-beta.45

3 months ago

1.0.2-beta.44

4 months ago

1.0.2-beta.43

4 months ago

1.0.2-beta.42

4 months ago

1.0.2-beta.41

4 months ago

1.0.2-beta.40

4 months ago

1.0.2-beta.39

4 months ago

1.0.2-beta.38

4 months ago

1.0.2-beta.37

4 months ago

1.0.2-beta.36

4 months ago

1.0.2-beta.35

4 months ago

1.0.2-beta.33

4 months ago

1.0.2-beta.34

4 months ago

1.0.2-beta.32

4 months ago

1.0.2-beta.29

4 months ago

1.0.2-beta.31

4 months ago

1.0.2-beta.30

4 months ago

1.0.2-beta.28

4 months ago

1.0.2-beta.27

4 months ago

1.0.2-beta.26

5 months ago

1.0.2-beta.24

5 months ago

1.0.2-beta.25

5 months ago

1.0.2-beta.23

5 months ago

1.0.2-beta.22

5 months ago

1.0.2-beta.21

5 months ago

1.0.2-beta.20

5 months ago

1.0.2-beta.19

5 months ago

1.0.2-beta.18

5 months ago

1.0.2-beta.17

5 months ago

1.0.2-beta.16

5 months ago

1.0.2-beta.15

5 months ago

1.0.2-beta.14

5 months ago

1.0.2-beta.13

5 months ago

1.0.2-beta.12

6 months ago

1.0.2-beta.11

6 months ago

1.0.2-beta.10

6 months ago

1.0.2-beta.9

6 months ago

1.0.2-beta.8

6 months ago

1.0.2-beta.7

6 months ago

1.0.2-beta.6

6 months ago

1.0.2-beta.5

6 months ago

1.0.2-beta.4

6 months ago

1.0.2-beta.3

6 months ago

1.0.2-beta.2

7 months ago

1.0.2-beta.1

7 months ago

1.0.2-beta.0

7 months ago

1.0.1

10 months ago