0.5.10 • Published 2 months ago

@roninnetwork/walletgo v0.5.10

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

Ronin Walletgo

Walletgo is the simplest way to integrate Ronin into your web application by connecting a user's wallet to your DApp.

Features

  • 💡 Any Wallet — Connect any wallet (Ronin, Ronin Mobile, Metamask, Gnosis, ...) to your app.
  • 🌱 Simple, seamless UI/UX — simple UX with attractive UI.
  • 🎨 Theme — Predesigned theme or full customization.

Before you start

Before you install the SDK, make sure you have the following:

Install

From you project directory, install the SDK using yarn or npm:

$ npm install @roninnetwork/walletgo
$ yarn add @roninnetwork/walletgo

API Key

Ronin Wallet uses WalletConnect's SDK for connecting wallets. Head over WalletConnect Cloud to obtain your projectID.

Basic usage

  1. Wrap your App with WalletgoProvider.
// App.jsx
import { WalletgoProvider } from "@roninnetwork/walletgo"
import App, { AppContext, AppProps } from "next/app"

const App = (props: AppProps) => {
  const { Component, pageProps } = props

  return (
    <WalletgoProvider defaultChainId={2020}>
      <Component {...pageProps} />
    </WalletgoProvider>
  )
}
  1. Create needed wallet connectors - Ronin, Ronin Mobile, Metamask, Gnosis.
// connectors.js
import { createDefaultWallets } from "@roninnetwork/walletgo"
const WC_PROJECT_ID = "YOUR_WALLETCONNECT_PROJECT_ID"

const connectors = createDefaultWallets({
  projectId: WC_PROJECT_ID,
  clientMeta: {
    name: "App Name",
    description: "App description",
    icons: ["https://cdn.skymavis.com/explorer-cdn/asset/favicon/apple-touch-icon.png"],
    url: "https://app.roninchain.com",
  },
})
  1. Include Connect Wallet dialog in your App
// MyComponent.tsx
import { createDefaultWallets, WalletWidget } from "@roninnetwork/walletgo"

const WC_PROJECT_ID = "YOUR_WALLETCONNECT_PROJECT_ID"

const connectors = createDefaultWallets({
  projectId: WC_PROJECT_ID,
  clientMeta: {
    name: "App Name",
    description: "App description",
    icons: ["https://cdn.skymavis.com/explorer-cdn/asset/favicon/apple-touch-icon.png"],
    url: "https://app.roninchain.com",
  },
})

export const MyComponent = () => {
  const [showWidget, setShowWidget] = useState(false)

  return (
    <div>
      <WalletWidget
        isOpen={showWidget}
        handleClose={() => setShowWidget(false)}
        wallets={connectors}
      />
      <button onClick={() => setShowWidget(true)}>Open Widget</button>
    </div>
  )
}
  1. Get wallet infomation in your App
// Address.tsx
import { useWalletgo } from "@roninnetwork/walletgo"

export const Address = () => {
  const { account, walletChainId, walletProvider, deactivate } = useWalletgo()

  return <div>{account}</div>
}

And that's it — just simple as that! Now, you have your app ready to connect to Ronin!

Example

Source: github.com/8ailurus/walletgo-demo-nextjs Live demo : walletgo-demo-nextjs.vercel.app

Customization

Theme

Walletgo exposes a few basic CSS variables to help quickly restyle the default UI.

variabledescriptiondefault
--wg-wallet-btn-font-sizeConnect button font size16px
--wg-wallet-btn-radiusConnect button border radius12px
--wg-wallet-btn-colorConnect button text color#e2e4e9
--wg-wallet-btn-bgConnect button backgroundrgba(147, 176, 236, 0.1)
--wg-wallet-btn-sdConnect button box shadownone
--wg-wallet-btn-hover-colorConnect button text color on hover#e2e4e9
--wg-wallet-btn-hover-bgConnect button background on hover#93b0ec0d
--wg-wallet-btn-hover-sdConnect button box shadow on hover0px 0px 1px #2b2f3b
--wg-btn-radiusCommon button border radius8px
--wg-primary-btn-colorPrimary button text color#fff
--wg-primary-btn-bgPrimary button background#2662d9
--wg-primary-btn-sdPrimary button box shadownone
--wg-primary-btn-hover-colorPrimary button text color on hover#fff
--wg-primary-btn-hover-bgPrimary button background on hover#173b82
--wg-primary-btn-hover-sdPrimary button box shadow on hovernone
--wg-secondary-btn-colorSecondary button text color#c4c8d4
--wg-secondary-btn-bgSecondary button backgroundrgba(147, 176, 236, 0.1)
--wg-secondary-btn-sdSecondary button box shadownone
--wg-secondary-btn-hover-colorSecondary button font color on hover#c4c8d4
--wg-secondary-btn-hover-bgSecondary button background on hoverrgba(147, 176, 236, 0.05)
--wg-secondary-btn-hover-sdSecondary button box shadow on hovernone
--wg-overlay-bgDialog overlay colorrgba(12, 12, 13, 0.8)
--wg-overlay-backdrop-filterBackdrop filter for the Dialog overlayunset
--wg-z-overlayz-index of Dialog overlayunset
--wg-dialog-bgDialog background color#1a1c23
--wg-dialog-sdDialog box shadow0px 0px 1px #2b2f3b
--wg-dialog-radiusDialog border radius20px
--wg-z-dialogz-index of Dialogunset
--wg-body-font-sizeBody text font size16px
--wg-sheading-font-sizeSubheading text font size18px
--wg-heading-font-sizeDialog title text font size20px
--wg-font-familyText fontunset
--wg-colorText color#fff
--wg-color-dimDim text color#6c7693
--wg-color-dim-hoverDim text color on hover#c4c8d4
--wg-color-criticalCritical text color#ff401a
--wg-color-successSuccess text color#11d473
--wg-qr-dot-colorColor of dots in QR#111417
--wg-qr-sdQR box shadowunset
--wg-qr-radiusQR border radius20px
--wg-qr-bgQR background color#fff
--wg-focus-sdFocused element box shadow0px 0px 1px #2662d9
--wg-spinner-colorSpinner color#e2e4e9

UI

Comming soon!

Connectors

Comming soon!

Multi Context

Comming soon!

Props Table & Type

WalletgoProvider

prop nametyperequireddefaultdescription
childrenReact.ReactNodeoptionalundefinedYour application component
defaultChainIdnumberrequiredDefault chainId is used for etherjs provider
configRecord<number, IChainInfo>optionalDEFAULT_CHAINS_CONFIGChains configuration
walletOrientedbooleanoptionalfalseDetermine walletgo to create readProvider base on walletChainId. By default, readProvider is always respect defaultChainId
contextReact.Context<IWalletgoContextValue>optionalDefaultWalletgoContextCustom React.Context for Provider to get
interface IChainInfo {
  chainId: number
  blockExplorerUrl?: string
  chainName?: string
  iconUrl?: string
  nativeCurrency?: {
    name: string
    symbol: string
    decimals: number
  }
  rpcUrl?: string
}

const DEFAULT_CHAINS_CONFIG: IChainsConfig = {
  [SupportedChainIds.RoninMainet]: {
    chainId: SupportedChainIds.RoninMainet,
    blockExplorerUrl: "https://app.roninchain.com",
    chainName: "Ronin Mainnet",
    iconUrl: "https://cdn.skymavis.com/explorer-cdn/asset/favicon/apple-touch-icon.png",
    nativeCurrency: {
      name: "Ronin",
      symbol: "RON",
      decimals: 18,
    },
    rpcUrl: DEFAULT_RPC_CONFIG[SupportedChainIds.RoninMainet],
  },
  [SupportedChainIds.RoninTestnet]: {
    chainId: SupportedChainIds.RoninTestnet,
    blockExplorerUrl: "https://saigon-app.roninchain.com",
    chainName: "Saigon Testnet",
    iconUrl: "https://cdn.skymavis.com/explorer-cdn/asset/favicon/apple-touch-icon.png",
    nativeCurrency: {
      name: "tRonin",
      symbol: "tRON",
      decimals: 18,
    },
    rpcUrl: DEFAULT_RPC_CONFIG[SupportedChainIds.RoninTestnet],
  },
  [SupportedChainIds.Ethereum]: {
    chainId: SupportedChainIds.Ethereum,
    blockExplorerUrl: "https://etherscan.io",
    chainName: "Ethereum",
    nativeCurrency: {
      name: "Ethereum",
      symbol: "ETH",
      decimals: 18,
    },
  },
  [SupportedChainIds.Goerli]: {
    chainId: SupportedChainIds.Goerli,
    blockExplorerUrl: "https://goerli.etherscan.io/",
    chainName: "Goerli",
    nativeCurrency: {
      name: "GoerliETH",
      symbol: "GTH",
      decimals: 18,
    },
  },
}

WalletWidget

prop nametyperequireddefaultdescription
walletsIConnector[]requiredList of wallet connectors is show on Widget
isOpenbooleanrequiredWhether the Connect Wallet dialog is visible or not
onClose() => voidoptionalnoopSpecify a function that will be called when a user clicks mask, close button on top right or disconnect button
onOpen() => voidoptionalnoopSpecify a function that will be called when a Dialog open
dialogPropsIDialogCustomPropsoptional{ mask: true, maskClosable: true, destroyOnClose: false, }Custom Dialog props rc-dialog
customContextReact.Context<IWalletgoContextValue>optionalDefaultWalletgoContextCustom React.Context for Widget to get state

useWalletgo

nametypeundefinabledefaultdescription
activate(connector: IConnector, isAuto?: boolean) => Promise<boolean>falsenoopUse to establish connection to wallet
autoActivate(connectors: IConnector[]) => Promise<boolean>falsenoopUse to establish connection to many wallets - for reconnect when reload page
deactivate() => voidfalsenoopUse to disconnect from current wallet
unsafeSwitchChain(chainId: number) => Promise<boolean>falsenoopUse to switch chainId on connected wallet
errorConnectorErrortrueundefined
activatingbooleanfalsefalseCustom React.Context for Widget to get state
accountstringtrueundefinedConnected address
connectedbooleanfalsefalseWhether connected to wallet or not
connectorIConnectortrueundefinedCurrent wallet connector
readProviderStaticJsonRpcProvidertrueundefinedstatic rpc provider - direct call to RPC
walletProviderWeb3Providertrueundefinedetherjs providers - direct call to injected provider - should use when sign tx, message
walletChainIdnumbertrueundefinedCurrent wallet chainId, undefined if wallet is not connected
chainConfigRecord<number, IChainInfo>falseDEFAULT_CHAINS_CONFIGUsers config
defaultChainIdnumberfalse2020Users config
walletOrientedbooleanfalsefalseUsers config

Connector

interface IConnector<ProviderType = ExternalProvider> {
  readonly id: string
  readonly switchable: boolean
  readonly scannable: boolean

  readonly provider?: ProviderType
  readonly events: IConnectorEventEmitter

  readonly autoPriority: number
  shouldAutoConnect(): Promise<boolean>

  connect(chainId: number): Promise<IConnectResult<ProviderType>>
  disconnect(): Promise<boolean>

  switchChain(chain: IAddEthereumChainParameter): Promise<boolean>

  // NOTE: only use for UI Widget
  readonly name: ReactNode
  readonly logo: ReactNode
  readonly downloadUrls: { [key: string]: string }
  readonly hidden: boolean
}
0.5.10

2 months ago

0.5.9

2 months ago

0.5.8

3 months ago

0.5.7

3 months ago

0.5.6

3 months ago

0.5.5

3 months ago

0.5.4

3 months ago

0.5.3

4 months ago

0.5.2

4 months ago

0.5.0

4 months ago

0.5.1

4 months ago

0.4.1

4 months ago

0.4.0

6 months ago

0.3.1

6 months ago

0.3.0

6 months ago

0.2.0-alpha

8 months ago

0.1.3-alpha

9 months ago

0.1.2-alpha

9 months ago

0.1.1-alpha

9 months ago

0.1.0-alpha

9 months ago