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

zigap-utils

v0.0.801

Published

It is a library that collects utils that help communicate between dapp and zigap.<br /> You can find out more at https://seoul-labs.gitbook.io/zigap-utils

Downloads

97

Readme

zigap-utils

It is a library that collects utils that help communicate between dapp and zigap. You can find out more at https://seoul-labs.gitbook.io/zigap-utils

Installation

npm i zigap-utils

Usage

_ INDEX

  1. Login
  2. Payment QR (Send) >

1. Login

import { LoginQR } from 'zigap-utils';

const App = () => {

  ...

  return (
    <div>
      <LoginQR
        dapp='your Dapp Name'
        url='http://sample.yours.com'
        availableNetworks={['xphere']}
        isShowLogo={false}
        logoSize={25}
        validSeconds={600}
        sigMessage="hello world"
        expire={{ type: 'EXTEND', seconds: 3600 }}
        icon="http://sample.icon-url.com"
        onReceive={({ status }) => {
          if(status === 'SUCCESS') {
            // something to do after login (refresh page...)
            // status type: 'REQUEST' | 'ACCOUNT' | 'SUCCESS' | 'ERROR'
          }
        }}
      />
    </div>
  );
}

2. Payment QR

import { PaymentQR } from 'zigap-utils';

const App = () => {
  const [result1, setResult1] = useState<undefined | string>(undefined);

  ...

  return (
    <div>
      <PaymentQR
        network={'network name'}
        dapp='your dapp name'
        address='address'
        amount='100'
        validSeconds={10000}
        onReceive={({ status }) => {
          if (status === 'SUCCESS') {
            setResult1('succeed');
          } else if (status === 'REQUEST' || status === 'ACCOUNT') {
            setResult1(`processing - ${status}`);
          } else {
            setResult1('failed');
          }
        }}
        size={200}
        processingMark={{
          type: 'NONE',
        }}
      />

      <div>
        {result1 === undefined ? <span>before start</span> : <span>{result1}</span>}
      </div>
    </div>
  )
}


LoginQR props

| prop | type | description | | --- | --- | --- | | dapp | string | Name of the dapp to use | | url | string | The url of dapp to connect | | availableNetworks | string[] | List of connectable networks in dapp | | sigMessage | string | Messages signed to verify the identity of the user | | validSeconds | number | QR code valid time(minutes) | | onReceive | (res) => void | Function called after login request | | expire | {type: "NONE / FIX / EXTEND", seconds: number} | time and type for user login to expire | | icon | string | Your dapp icon url to be displayed on zigap app | | processingMark | {type: "DEFAULT" / "CUSTOM" / "NONE", component: React.ReactNode} | How to show the QR image when it's being processed |

AddressProvideQR props

| prop type | required | type | default value | description | | ------------------------ | -------- | --------------- | ------------- | --------------------------------------- | | dapp | true | string | | Name of the dapp to use | | url | true | string | | The url of dapp to connect | | availavailableNetworks | true | string[] | | List of connectable networks in dapp | | validTime | true | number | | QR code valid time(seconds) | | onReceive | true | (value) => void | | Function called after login request | | size | false | number | 128 | canvas width | | bgColor | false | string | #fff | background color | | fgColor | false | string | #000 | foreground color | | style | false | CSSProperties | custom | css style | | isShowLogo | false | boolean | false | Zigap logo in the middle of the QR code | | logoSize | false | number | 30 | logo width & height |

CommonStyle props (optional)

| prop | type | default value | description | | ------------ | ------------- | ------------- | --------------------------------------- | | size | number | 128 | canvas width | | bgColor | string | #fff | background color | | fgColor | string | #000 | foreground color | | style | CSSProperties | | custom css style | | isShowLogo | boolean | false | Zigap logo in the middle of the QR code | | logoSize | number | 30 | logo width & height |

PaymentQR props

| Prop | Required | Type | Description | | --- | --- | --- | --- | | network | true | string | The name of the network to use (e.g., "xphere"). | | dapp | true | string | The name of the DApp initiating the payment request. | | address | true | string | The recipient's address for the payment. | | amount | true | string | The amount to be paid. | | description | false | string | A brief description of the payment. | | info | false | object | Additional information related to the payment. | | validSeconds | true | number | The duration (in seconds) for which the QR code is valid. | | isShowLogo | false | boolean | Whether to display your DApp’s logo in the QR code. | | logoSize | false | number | The size of the logo displayed in the QR code (in pixels). | | size | true | number | The size of the generated QR code (in pixels). | | onReceive | true | (res : { status: string }) => void | Callback function that handles payment status updates. | | processingMark | false | type: DEFAULT or CUSTOM or NONE | Configures the appearance of the QR code while processing. |

Payment Statuses

The onReceive callback provides the following statuses:

  • SUCCESS : Payment was successful.
  • REQUEST : Payment has been requested and is in progress.
  • ACCOUNT : Account selection or preparation is in progress.
  • ERROR : An error occurred during payment.

Processing Mark Options

  • DEFAULT : Displays a default "processing..." message during payment.
  • CUSTOM : Allows you to pass a custom React component to display during processing.
  • NONE : No visual indicator is shown during processing.

Example Usage of processingMark

To use a custom component:

 <PaymentQR
   ...
   processingMark={{
     type: 'CUSTOM',
     component: <div>Loading your payment...</div>,
   }}
 />


useZigap

useZigap is a hook that fetches the information of the logged-in user in the zigap app and provides a logout function.

import { useZigap } from 'zigap-utils';

...

const Component = () => {
  const { userInfo, logout, isWindowLoaded } = useZigap();

  const handleLogout = () => {
    if(isWindowLoaded) {
      logout();
      window.location.reload();
    }
  }

  return (
    <div>
      <p>Address: {userInfo.address}</p>
      <p>Network: {userInfo.network}</p>
      <p>Nickname: {userInfo.nickName}</p>
      <p>Token: {userInfo.token}</p>
      <p>Issued DateTime: {userInfo.issuedDateTime}</p>
      <p>Expire DateTime: {userInfo.expireDateTime}</p>

      <button onClick={handleLogout}> LOGOUT </button>
    </div>
  );
}