npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wepin/wagmi-connector

v0.2.0

Published

Wepin wagmi connector

Downloads

35

Readme

@wepin/wagmi-connector

Wepin Wagmi Connector for React.

⏩ Get App ID and Key

Contact to [email protected]

⏩ Information

Support Version

wagmi version

  • Note for Users Still on wagmi 0.12.x

If you are currently using wagmi version 0.12.x and want to continue doing so, you can find the corresponding version of the connector library at @wepin/[email protected].

Please be aware that this version is specifically designed to work with wagmi 0.12.x.

Refer to the documentation for version 0.0.2-alpha for guidance on usage and compatibility.

Support Networks

Please refer to the following link for detailed information on the supported network list: wepin provider - supported network list

Connector Options

  • appId <string>
  • appKey <string>
  • defaultChainId <number> optional
    • defaultChainId:
      • Defines the default network that the provider connects to during initialization
      • It defaults to the network of the User's first account.
  • attributes <IWepinSDKAttributes> optional
    • The attributes type extends @wepin/sdk-js as IWepinSDKAttributes
    • type:
      • The type of display of widget as wepin is initiated (default: 'hide')
      • 'hide' | 'float'
    • defaultLanguage:
      • Specifies the language displayed on the widget (default: 'ko')
      • Currently, only 'ko' and 'en' are supported.
    • defaultCurrency:
      • Sets the currency displayed on the widget (default: 'KRW').
    • loginProviders:
      • If not provided, all available login providers will be displayed on the widget.
      • If an empty array is provided, only the email login function is available. (@wepin/sdk-js from version v0.0.3)

⚠️ Caution

Do not use this library with @wepin/sdk-js. The state management of @wepin/wagmi-connector may not be compatible with any changes in @wepin/sdk-js.

⏩ Install

@wepin/wagmi-connector

npm install wagmi viem @wepin/wagmi-connector

or

yarn add wagmi viem @wepin/wagmi-connector

⏩ Get Started

1. Import Connector

import { WepinConnector } from '@wepin/wagmi-connector'
import type { WepinConnectorOptions } from '@wepin/wagmi-connector' // ts

2. Setup Options

const connectorOptions: WepinConnectorOptions = {
  appId: 'YOUR_APP_ID',
  appKey: 'YOUR_APP_KEY',
}

3. Add to Connectors

export const config = createConfig({
  connectors: [
    // ...Other Connectors,
    new WepinConnector({
      chains,
      options: connectorOptions,
    }),
  ],
  publicClient,
})
import { configureChains, createConfig } from 'wagmi'
import { mainnet, polygon } from 'wagmi/chains'
import { publicProvider } from 'wagmi/providers/public'
import { WepinConnector, WepinConnectorOptions } from '@wepin/wagmi-connector'

const { chains, publicClient } = configureChains(
  [
    mainnet, // 1, ethereum
    polygon, // 137, evmpolygon
  ],
  [publicProvider()],
)

const connectorOptions: WepinConnectorOptions = {
  appId: 'YOUR_APP_ID',
  appKey: 'YOUR_APP_KEY',
}

export const config = createConfig({
  connectors: [
    new WepinConnector({
      chains,
      options: connectorOptions,
    }),
  ],
  publicClient,
})

// wagmi.ts

4. Wrap app with WagmiConfig

import { WagmiConfig } from 'wagmi'
import { config } from './wagmi'

function App() {
  return (
    <WagmiConfig config={config}>
      <YourRoutes />
    </WagmiConfig>
  )
}

⏩ You're good to go!

Every component inside the WagmiConfig is now set up to use the wagmi hooks with Wepin

import { BaseError } from 'viem'
import { useAccount, useConnect, useDisconnect } from 'wagmi'

export const Connect = () => {
  const { connector, isConnected } = useAccount()
  const { connect, connectors, error, isLoading, pendingConnector } =
    useConnect()
  const { disconnect } = useDisconnect()

  return (
    <div>
      <h2>useConnect</h2>
      <div>
        {isConnected && (
          <button onClick={() => disconnect()}>
            Disconnect from {connector?.name}
          </button>
        )}

        {connectors
          .filter((x) => x.ready && x.id !== connector?.id)
          .map((x) => (
            <button key={x.id} onClick={() => connect({ connector: x })}>
              {x.name}
              {isLoading && x.id === pendingConnector?.id && ' (connecting)'}
            </button>
          ))}
      </div>

      {error && <div>{(error as BaseError).shortMessage}</div>}
    </div>
  )
}

// Connector.tsx

Want to learn more? Check out other hooks to learn how to use wagmi in real-world scenarios or continue on reading the documentation.

⏩ Additional Features

getLoginData (Support from version 0.1.3)

If you need to retrieve loginData, follow these steps:

Example

import { useState } from 'react'
import { BaseError } from 'viem'
import { useAccount, useConnect, useDisconnect } from 'wagmi'
import { type IWepinUser, WepinConnector } from '@wepin/wagmi-connector'

export function Connect() {
  const [wepinUser, setWepinUser] = useState<IWepinUser | null>(null)
  const { connector, isConnected } = useAccount()
  const {
    connect,
    connectAsync,
    connectors,
    error,
    isLoading,
    pendingConnector,
  } = useConnect()
  const { disconnect } = useDisconnect()

  const handleConnect = async (connector: any) => {
    // if you want to get login data
    if (connector instanceof WepinConnector) {
      await connectAsync({ connector })
      const wepinUser = await connector.getLoginData()
      if (wepinUser) {
        setWepinUser(wepinUser)
      }
      return
    }
    // for other connectors
    connect({ connector })
  }

  return (
    <div>
      <div>
        {isConnected && (
          <button onClick={() => disconnect()}>
            Disconnect from {connector?.name}
          </button>
        )}

        {connectors
          .filter((x) => x.ready && x.id !== connector?.id)
          .map((x) => (
            <button key={x.id} onClick={() => handleConnect(x)}>
              {x.name}
              {isLoading && x.id === pendingConnector?.id && ' (connecting)'}
            </button>
          ))}
      </div>

      {isConnected && wepinUser?.status === 'success' && (
        <div>
          <div>userId: {wepinUser.userInfo?.userId}</div>
          <div>email: {wepinUser.userInfo?.email}</div>
          <div>provider: {wepinUser.userInfo?.provider}</div>
        </div>
      )}
      {error && <div>{(error as BaseError).shortMessage}</div>}
    </div>
  )
}

// Connector.tsx

Use Polygon Amoy Network (Support from version 0.1.6)

Although the Polygon Mumbai network has been discontinued, it has not been updated in the wagmi v1

If you need to use Polygon Amoy Network, follow these steps:

Example

import {
  type WepinConnectorOptions,
  WepinConnector,
  Chains, // this
} from '@wepin/wagmi-connector'

const { chains, publicClient, webSocketPublicClient } = configureChains(
  [
    mainnet,
    Chains.polygonAmoy, // this
  ],
  [publicProvider()],
)