1.0.5-beta.2 • Published 1 month ago

@mojito-inc/connect-wallet v1.0.5-beta.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

Using this library in your project

You can install this project with one of these commands:

npm install @mojito-inc/connect-wallet
yarn add @mojito-inc/connect-wallet

Install following dependency also

yarn add @mui/material@5.11.11 @mui/icons-material@5.11.11 @apollo/client graphql

Config theme for your project

To config custom theme please follow below steps:

Step 1:

Note: If you encounter any type errors in the themes config, create a file named mui.d.ts and add the following code:

  import '@mui/material/styles';

  declare module '@mui/material/styles' {
    export interface Palette {
      backgroundColor?: {
        primary?: string
        secondary?: string
      }
      toastError?: ColorPartial
      toastSuccess?: ColorPartial
      toastWarning?: ColorPartial
      iconColor?: string
    }
    // allow configuration using `createTheme`
    export interface PaletteOptions {
      backgroundColor?: {
        primary?: string
        secondary?: string
      }
      toastError?: ColorPartial
      toastSuccess?: ColorPartial
      toastWarning?: ColorPartial
      iconColor?: string
    }
  }

Create a new file and place the following code and replace the colors with your custom colors. export the theme and add into the provider.

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

  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',
      },
      backgroundColor: {
        primary: '#ffffff',
        secondary: '#000000',
      },
      grey: {
        100: '#868b93',
        500: '#A1A5AB',
      },
      toastError: {
        500: '#CE2818',
      },
      iconColor: '#000',
    },
  });

API URL:

  import { ConnectWalletProvider } from '@mojito-inc/connect-wallet';

  const WalletProvider = ({ children }: WalletProviderProps) => {

    const [token, setToken] = useState<string>();
    const client = useMemo(
      () => ({
        uri: API_HOSTNAME,
        token: token || undefined,
      }),
      [token],
    );

    return (
      <ConnectWalletProvider
        theme={ theme }
        clientId={ clientId }
        activeChain={ activeChain }
        walletConnectProjectId={ walletConnectProjectId }
        onAuthenticated={ setToken }
        clientOptions={ client }>
        { children }
      </ConnectWalletProvider>
    );
  };

  export default WalletProvider;
ParamtypeRequiredDescription
themeThemeTo Customize the theme
clientIdstringPass the client id for email wallet
activeChainenumpass the network name to connect with email
walletConnectProjectIdstringPass the wallet connect project id
onAuthenticatedfunctionin callback you will get an auth token
clientOptionsobjectpass the bearer token and api url
metaDataobjectTo customize the wallet connect Modal metadata

After setup ConnectWallet Provider

Following step: 1. Connect Wallet Container

ConnectWalletContainer

  import { ConnectWalletContainer } from '@mojito-inc/connect-wallet';

  const ConnectWalletPage = () => {

    return (
      <ConnectWalletContainer
        open={ openModal }
        organizationId: organizationId,
        walletOptions={{
          enableMetamask: true,
          enableEmail: true,
          enableWalletConnect: true,
        }}
        image={{
          logo: YOUR_LOGO, // pass URL or path, if you are importing an image from local please add ".src" at end
          metamask: Images.METAMASK.src,
          error: Images.METAMASK.src,
          walletConnect: Images.METAMASK.src,
        }}
        isDisConnect={ disconnect }
        isRefetchBalance={ isRefetchBalance }
        onCloseModal={ onClickCloseModal } />
    );
  };

  export default ConnectWalletPage;
ParamtypeRequiredDescription
openbooleanif true it will open modal if false modal will close
configObjectconfig
walletOptionsObjectwalletOptions
imageObjectimage To customize the image
isDisConnectbooleanif true it will disconnect the wallet
isRefetchBalancebooleanif true it will refetch the wallet balance
onCloseModalfunctionTo close the Modal
contentObjectcontent to customize the title, description in modal
isPaperWalletbooleanif true it will work as paper wallet with email else it will work as thirdweb embedded wallet.
isWeb2Loginbooleanif true it will work as web2 login example auth0.
skipSignaturebooleanif true it will skip the signature process for connect wallet.
userEmailstringPass user email address to pre populate email in input fields.

interface

config

ParamtypeRequiredDescription
organizationIdstringPass the organization id
paperClientIdstring
paperNetworkNameenumpaper Network Name

walletOptions

ParamtypeRequiredDescription
enableMetamaskboolean
enableEmailboolean
enableWalletConnectboolean

image

ParamtypeRequiredDescription
logostring
metamaskstring
errorstring
walletConnectstring

Paper Network Name

Enum
Ethereum
Sepolia
Goerli
Polygon
Mumbai

content

ParamtypeRequiredDescription
walletOptionsContentDataobjectContentData
otpContentDataobjectContentData
emailContentDataobjectContentData
loadingContentDataobjectContentData
recoverCodeContentDataobjectContentData

ContentData

ParamtypeRequiredDescription
titlestring
descriptionstring

Hooks

To get the connected wallet details use these following hooks:

Wallet Details Hooks

  import { useWallet } from '@mojitoinc/mojito-connect-wallet';

  const { address, balance } = useWallet();

Network Hooks

  import { useNetwork } from '@mojitoinc/mojito-connect-wallet';

  const { chainID, id, isTestnet, name } = useNetwork();

Provider Hooks

  import { useProvider } from '@mojitoinc/mojito-connect-wallet';

  const { provider, providerType } = useProvider();

Token Gating Container

  import { TokenGatingContainer } from '@mojito-inc/connect-wallet';

  const TokenGatingPage = () => {
    return (
      <TokenGatingContainer
          onCloseModal={ onCloseModal }
          open={ openModal }
          config={{
            orgId: Configuration.ORG_ID ?? '',
            paperClientId: Configuration.PAPER_CLIENT_ID ?? '',
            paperNetworkName: Configuration.PAPER_NETWORK_NAME ?? '',
            groupId: tokenGatingDetails?.groupId,
            ruleId: tokenGatingDetails?.ruleId,
            isClaimToken: false,
            collectionItemId: tokenGatingDetails?.collectionItemId,
            invoiceId,
          }}
          screenConfig={{
            title: ,
            subTitle: 'Holders of the Myers Manx collection can now get 50%. Connect your wallet to proceed.',
          }}
          gatingErrorDetails={ gatingErrorDetails }
          walletConnectScreenDetails={ walletConnectScreenDetails }
          errorScreenDetails={ errorScreenDetails }
          claimTokenScreenDetails={ claimTokenScreenDetails }
          setInvoice={ setInvoice } />
    )
  }
ParamtypeRequiredDescription
openBoolean
configObjectConfiguration
walletConnectScreenDetailsObjectwalletConnectScreenDetails
errorScreenDetailsObjecterrorScreenDetails
screenConfigObjectscreenConfig
claimTokenScreenDetailsObjectclaimTokenScreenDetails
gatingLoaderDetailsObject
gatingErrorDetailsObject
invoiceIDstring
onCloseModalfunction
onChangeWalletAddressfunction
setInvoicefunction
getInvoiceDetailsfunction

interface

Configuration

ParamtypeRequiredDescription
orgIdstringorganization id
chainIdNumber
paperClientIdstringpaper client id to connect with email
paperNetworkNameany
groupIdstringfor Checking Token Gating based on GroupId
ruleIdstringfor Checking Token Gating based on ruleId
isClaimTokenbooleanif true, call mojito claim api
collectionItemIdstring
invoiceIdstring

walletConnectScreenDetails

ParamtypeRequiredDescription
titlestring
subTitlestring
walletOptionswalletOptionswalletOptions
imageWalletImagesWalletImages

errorScreenDetails

ParamtypeRequiredDescription
titlestring
primaryButtonTitlestring
secondaryButtonTitlestring
tertiaryButtonTitlestring
onClickTertiaryButtonfunction
onClickSecondaryButtonfunction
onClickPrimaryButtonfunction

screenConfig

ParamtypeRequiredDescription
titlestring
subTitlestring

claimTokenScreenDetails

ParamtypeRequiredDescription
tokenDetailObjecttokenDetail
redirectionPageURLstring
onSuccessfunction
tokenDetail
ParamtypeRequiredDescription
tokenImagestring
tokenNamestring
tokenSubtitlestring
tokenButtonTextstring

WalletImages

ParamtypeRequiredDescription
errorstringerror icon in svg, png, jpeg or gif format
metamaskstringmetamask icon in svg, png, jpeg or gif format
logostringlogo icon in svg, png, jpeg or gif format

walletOptions

ParamtypeRequiredDescription
enableMetamaskbooleanto enable or disable metamask
enableEmailbooleanto enable or disable email connect
1.0.5-beta.1

1 month ago

1.0.5-beta.2

1 month ago

1.0.4

1 month ago

1.0.5-beta.0

1 month ago

1.0.3-bet.0

3 months ago

1.0.3-beta.18

4 months ago

1.0.3-beta.17

4 months ago

1.0.3-beta.16

5 months ago

1.0.3-beta.15

5 months ago

1.0.3-beta.14

5 months ago

1.0.3-beta.11

5 months ago

1.0.3-beta.13

5 months ago

1.0.3-beta.12

5 months ago

1.0.3-beta.10

5 months ago

1.0.3-beta.9

5 months ago

1.0.3-beta.8

5 months ago

1.0.3-beta.7

6 months ago

1.0.3-beta.6

6 months ago

1.0.3-beta.5

6 months ago

1.0.3-beta.4

6 months ago

1.0.3-beta.3

6 months ago

1.0.3-beta.2

6 months ago

1.0.3-beta.1

6 months ago

1.0.3-beta.0

6 months ago

1.0.2

7 months ago

1.0.1-beta.31

7 months ago

1.0.1-beta.29

8 months ago

1.0.1-beta.28

8 months ago

1.0.1-beta.27

8 months ago

1.0.1-beta.26

8 months ago

1.0.1-beta.25

8 months ago

1.0.1-beta.24

8 months ago

1.0.1-beta.23

8 months ago

1.0.1-beta.22

8 months ago

1.0.1-beta.21

8 months ago

1.0.1-beta.20

8 months ago

1.0.1-beta.19

8 months ago

1.0.1-beta.18

8 months ago

1.0.1-beta.17

8 months ago

1.0.1-beta.16

8 months ago

1.0.1-beta.15

9 months ago

1.0.1-beta.14

9 months ago

1.0.1-beta.13

9 months ago

1.0.1-beta.12

9 months ago

1.0.1-beta.11

9 months ago

1.0.1-beta.10

9 months ago

1.0.1-beta.9

9 months ago

1.0.1-beta.8

9 months ago

1.0.1-beta.7

9 months ago

1.0.1-beta.6

10 months ago

1.0.1-beta.5

10 months ago

1.0.1-beta.4

10 months ago

1.0.1-beta.3

10 months ago

1.0.1-beta.2

10 months ago

1.0.1-beta.1

10 months ago

1.0.1-beta.0

10 months ago

1.0.3

10 months ago

1.0.1

10 months ago