0.2.5 • Published 8 months ago

zkey-react v0.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

zKey-react

The zKey-react component is based on the React framework and enables users to quickly create and log in to a Web3 wallet using third-party accounts such as Google or Facebook.

Features

  • Offers comprehensive Web3 wallet functionality
  • Easy to use without requiring Web3 knowledge
  • Simple and compatible with React and Next frameworks
  • Highly extensible, with prototype instances available for further development

Flowchart

Install

yarn add zkey-react

Or

npm install zkey-react

How to Run

The SDK provides a global provider to manage the application's login state and wallet instance. Make sure to include it at the outermost level of the app.

import { ZKeyLoginProvider, WalletProvider } from "zkey-react";

export default App({ children }){
  return (
    <ZKeyLoginProvider>
      <WalletProvider>
        {children}
      </WalletProvider>
    </ZKeyLoginProvider>
  )
}

Log in

Import it into the desired page and pass the application's clientId.

import { GoogleLoginButton } from "zkey-react"
export default function Login {
  return (
    <div className='container'>
     <GoogleLoginButton clientId='xxx-xxx' />
    </div>
  );
};

API

ZKeyLoginProvider

PropTypeDescription
handleLogInCallback(userInfo) => voidCallback function after user login (data reference: userInfo)
handleLogOutCallbackfunctionCallback function after user logout

useZkState (User information and wallet instance)

PropTypeDescription
providerRpcProviderWallet RPC instance (for further development and interaction with internal components)
userInfoemail:string; family_name:string; given_name:string;name: string;picture: string;User information
globalAccountAccountInterfaceUser wallet instance (for further development and interaction with internal components)
globalL3AccountAccountInterfaceWallet instance for L3 version transactions, which can use STRK for gas settlement
walletDetailaddress: string;callData: string[];exp: string;input: any;isDeploy: boolean;privateKey: string;pub_hash: string;publicKey: string;salt: string;sub: any;Wallet-related configuration parameters(for further development and interaction with internal components)
loginLoadingbooleanLogin status
loadingContentstringLogin status message used to notify the user

useZkDispatcher (Methods to change state and log out)

PropTypeDescription
handleChangeDeploy(state:boolean) => voidUsed to switch account deployment status
handleUserLogOutfunctionLog out

useWalletState (Wallet-related data)

PropTypeDescription
walletLoadingbooleanWallet status query
currencyList{prices:number;balance:number; sum:number;walletName:string}[]List of currencies (includes user balances, exchange rates, and USD equivalent value)
overallBalancenumberUser's total currency balance (in USD equivalent)
activeWalletContractThe currently selected currency instance
gasLoadingbooleanLoading state for gas query
activeWalletGasstring numberEstimated gas for the current transaction
transferLoadingbooleanLoading state for the transfer process
transferStateTextstringTransaction status message

useWalletDispatcher (Wallet Operations)

PropTypeDescription
handleChangeActiveContract(address:string) => voidChange the address of the currency to operate on
handleAddCurrency(address:string) => promise<T>Add the currency address to query
handleWalletBalance() => Promise<T>Manually trigger a refresh of the currency balance and other information
handleChangActiveGasAddress(address:string) => promise<T>Change the gas payment currency address (supports only ETH or STRK)
handleGetGasFree(amount: number, toAddress: string) => promise<T>Trigger a query for gas fees
handleTransfer(amount: number, toAddress: string) => promise<T>Initiate a transaction

Maintainer

@peiliang wang

License

MIT

0.2.0

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.1.14

8 months ago

0.1.15

8 months ago

0.1.16

8 months ago

0.1.13

9 months ago

0.1.12

9 months ago

0.1.11

9 months ago

0.1.10

9 months ago

0.1.9

9 months ago

0.1.8

9 months ago

0.1.7

10 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago