0.0.801 • Published 10 months ago

zigap-utils v0.0.801

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

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

proptypedescription
dappstringName of the dapp to use
urlstringThe url of dapp to connect
availableNetworksstring[]List of connectable networks in dapp
sigMessagestringMessages signed to verify the identity of the user
validSecondsnumberQR code valid time(minutes)
onReceive(res) => voidFunction called after login request
expire{type: "NONE / FIX / EXTEND", seconds: number}time and type for user login to expire
iconstringYour 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 typerequiredtypedefault valuedescription
dapptruestringName of the dapp to use
urltruestringThe url of dapp to connect
availavailableNetworkstruestring[]List of connectable networks in dapp
validTimetruenumberQR code valid time(seconds)
onReceivetrue(value) => voidFunction called after login request
sizefalsenumber128canvas width
bgColorfalsestring#fffbackground color
fgColorfalsestring#000foreground color
stylefalseCSSPropertiescustomcss style
isShowLogofalsebooleanfalseZigap logo in the middle of the QR code
logoSizefalsenumber30logo width & height

CommonStyle props (optional)

proptypedefault valuedescription
sizenumber128canvas width
bgColorstring#fffbackground color
fgColorstring#000foreground color
styleCSSPropertiescustom css style
isShowLogobooleanfalseZigap logo in the middle of the QR code
logoSizenumber30logo width & height

PaymentQR props

PropRequiredTypeDescription
networktruestringThe name of the network to use (e.g., "xphere").
dapptruestringThe name of the DApp initiating the payment request.
addresstruestringThe recipient's address for the payment.
amounttruestringThe amount to be paid.
descriptionfalsestringA brief description of the payment.
infofalseobjectAdditional information related to the payment.
validSecondstruenumberThe duration (in seconds) for which the QR code is valid.
isShowLogofalsebooleanWhether to display your DApp’s logo in the QR code.
logoSizefalsenumberThe size of the logo displayed in the QR code (in pixels).
sizetruenumberThe size of the generated QR code (in pixels).
onReceivetrue(res : { status: string }) => voidCallback function that handles payment status updates.
processingMarkfalsetype: DEFAULT or CUSTOM or NONEConfigures 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>
  );
}
0.0.801

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.508

10 months ago

0.0.507

11 months ago

0.0.506

11 months ago

0.0.505

11 months ago

0.0.504

11 months ago

0.0.503

11 months ago

0.0.502

11 months ago

0.0.501

11 months ago

0.0.5

11 months ago

0.0.499

12 months ago

0.0.498

12 months ago

0.0.497

12 months ago

0.0.496

12 months ago

0.0.495

12 months ago

0.0.494

12 months ago

0.0.493

12 months ago

0.0.492

12 months ago

0.0.491

12 months ago

0.0.49

12 months ago

0.0.489

12 months ago

0.0.488

12 months ago

0.0.487

12 months ago

0.0.486

12 months ago

0.0.485

12 months ago

0.0.484

12 months ago

0.0.483

12 months ago

0.0.481

12 months ago

0.0.48

12 months ago

0.0.479

12 months ago

0.0.478

12 months ago

0.0.477

12 months ago

0.0.476

12 months ago

0.0.475

12 months ago

0.0.474

12 months ago

0.0.473

12 months ago

0.0.472

12 months ago

0.0.471

12 months ago

0.0.47

12 months ago

0.0.469

12 months ago

0.0.468

12 months ago

0.0.467

12 months ago

0.0.466

12 months ago

0.0.465

12 months ago

0.0.463

12 months ago

0.0.462

12 months ago

0.0.461

12 months ago

0.0.46

12 months ago

0.0.45

12 months ago

0.0.44

12 months ago

0.0.43

12 months ago

0.0.42

12 months ago

0.0.41

12 months ago

0.0.40

12 months ago

0.0.39

12 months ago

0.0.38

12 months ago

0.0.37

12 months ago

0.0.36

12 months ago

0.0.34

12 months ago

0.0.33

12 months ago

0.0.32

12 months ago

0.0.31

12 months ago

0.0.30

1 year ago

0.0.29

1 year ago

0.0.28

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago