Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@opendapps/evm-modal

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opendapps/evm-modal

EVM wallets connecting modal

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

🧊 EVM modal

This package is designed to simplify the process of connecting ethereum web3 wallets.

Installation

Package installation is done in the standard way:

yarn[npm, pnpm] add -D @opendapps/evm-modal@latest

Integration

You can specify your own configuration for the modal if you wish, but the default configurations are already defined, so if not use configuration prop, there will be default config.

function MyCoolApplication () {
  return (
    <EvmModal connectors={ [ new MetaMaskConnector() ] } connectedWalletKey={ null } />
  )
}

 

List of available props of EvmModal component:

PropTypeDescription
connectorsEvmWalletConnector[]List of available connectors
connectedWalletKeystringConnected wallet key
ConfigurationEvmModalConfigurationConfiguration object

Creating new connector

To create a new connector, it is enough to create a new class inherited from the EvmWalletConnector class and override its connectToWallet method. Also, you can use one of the available utilities to get a specific provider:

Note that in these examples, the evmWallet variable is the wallet controller from @knownout/evm-wallet-controller package, however you can use any other controller or logic

import { EvmWalletConnector } from "@opendapps/evm-modal"
import { getCoinbaseProvider } from "@opendapps/evm-modal/connector-utils"

class CoinbaseConnector extends EvmWalletConnector {
  constructor () {
    super("CoinbaseWallet", false, CoinbaseWalletIcon)
  }

  public override async connectToWallet (): Promise<boolean> {
    // Use utility function to get Coinbase provider
    const coinbaseProvider = await getCoinbaseProvider(this.provider)

    return evmWallet.connectWallet(coinbaseProvider as any, "CoinbaseWallet")
  }
}

About a metamask, no additional functions need to be used:

import { EvmWalletConnector } from "@opendapps/evm-modal"

class MetaMaskConnector extends EvmWalletConnector {
  constructor () {
    super("MetaMask", false, MetamaskIcon)
  }

  public override async connectToWallet (): Promise<boolean> {
    return evmWallet.connectWallet(this.provider as any, "MetaMask")
  }
}

Configure

Some modal options can be reconfigured:

const ModalConfiguration: EvmModalConfiguration = {
  walletLinks: {
    MetaMask: {
      chrome: "Link to chrome extensions market",
      firefox: "Link to firefox extensions market (if exists)",
      android: "...",
      ios: "..."
    },
    CoinbaseWallet: {
      chrome: "Link to chrome extensions market"
    }
  },

  // List of rpc links for wallet-connect
  walletConnectRPCs: [
    "https://bsc-dataseed.binance.org/",
    "https://rpc.ankr.com/fantom/"
  ],

  modalTitle: "Chose the way to connect:"
}

Interaction

This component is based on @opendapps/modal-window and has the same interface as modal-window, so if you want to open evm modal, just call modal window controller:

import { ModalKeys } from "@opendapps/evm-modal/misc"
import { useModalWindowController } from "@opendapps/modal-window"

const controller = useModalWindowController()

controller.openModal(ModalKeys.EvmModal)

 

You can find usage example in the sandbox folder

Keywords

modal

FAQs

Package last updated on 04 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts