0.1.11 • Published 2 years ago

@epnsproject/sdk-uiweb v0.1.11

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

uiweb

Package for React based UI web components to be used by dApp.

How to use in your app?

Installation

  yarn add @epnsproject/sdk-uiweb

or

  npm install @epnsproject/sdk-uiweb  

Note: styled-components is a peerDependency. Please install it in your dApp if you don't have it already!

  yarn add styled-components

or

  npm install styled-components  

Notification Item component

Import the sdk package in the component file where you want to render notification(s)

import { NotificationItem, chainNameType } from "@epnsproject/sdk-uiweb";

After you get the Notification data from the API or otherwise

const notifications = await EpnsAPI.user.getFeeds({
  user: 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681', // user address in CAIP
  env: 'staging'
});

render the Notification UI as follows

<div>
{notifications.map((oneNotification, i) => {
    const { 
        cta,
        title,
        message,
        app,
        icon,
        image,
        url,
        blockchain,
        notification
    } = oneNotification;

    return (
        <NotificationItem
            key={id} // any unique id
            notificationTitle={title}
            notificationBody={message}
            cta={cta}
            app={app}
            icon={icon}
            image={image}
            url={url}
            theme={theme}
            chainName={blockchain}
            // chainName={blockchain as chainNameType} // if using Typescript
        />
        );
    })}
</div>

For Spam data API

const spams = await EpnsAPI.user.getFeeds({
  user: 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681', // user address in CAIP
  spam: true,
  env: 'staging'
});

render the Spam UI as follows

 {spams.map((oneNotification, i) => {
    const { 
      cta,
      title,
      message,
      app,
      icon,
      image,
      url,
      blockchain,
      secret,
      notification
    } = oneNotification;

    return (
      <NotificationItem
        key={`spam-${i}`}
        notificationTitle={title}
        notificationBody={message}
        cta={cta}
        app={app}
        icon={icon}
        image={image}
        url={url}
        theme={theme}
        chainName={blockchain}
        // optional parameters for rendering spams
        isSpam
        subscribeFn={subscribeFn} // see below
        isSubscribedFn={isSubscribedFn} // see below
      />
    );
  })}
const subscribeFn = async () => {
  // opt in to the spam notification item channel
}

we can use this @epnsproject/sdk-restapi method to do that - subscribe

const isSubscribedFn = async () => {
  // return boolean which says whether the channel for the 
  // spam notification item is subscribed or not by the user.
}

we can use this @epnsproject/sdk-restapi method to find out that - getSubscriptions

where

PropTypeRemarks
notificationTitlestringTitle of the notification (given during notification creation)
notificationBodynumberMessage body of the notification (given during notification creation)
iconstringChannel Icon (IPFS url) (given during channel setup)
appstringChannel Name (given during channel setup)
ctastringCall To Action Link (given during notification creation)
imagestringAny media link (given during notification creation)
urlstringChannel Link (given during channel setup)
chainNamestringCan be anyone of the following blockchain networks on which the notification was sent - "ETH_MAINNET", "ETH_TEST_GOERLI", "POLYGON_MAINNET", "POLYGON_TEST_MUMBAI", "THE_GRAPH"
themestring'light' or 'dark' (customization to be given by the dApp)
isSpambooleanwhether a spam notification or not
subscribeFnPromiseFunction to subscribe to the channel
isSubscribedFnPromiseFunction that returns the subscription status of a channel
0.1.11

2 years ago

0.1.10

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago