1.2.11 • Published 3 days ago

@pushprotocol/uiweb v1.2.11

Weekly downloads
-
License
-
Repository
-
Last release
3 days ago

uiweb

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

How to use in your app?

Installation

  yarn add @pushprotocol/uiweb

or

  npm install @pushprotocol/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 "@pushprotocol/uiweb";

After you get the Notification data from the API or otherwise

const notifications = await PushAPI.user.getFeeds({
  user: 'eip155:11155111: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 PushAPI.user.getFeeds({
  user: 'eip155:11155111: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 @pushprotocol/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 @pushprotocol/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_SEPOLIA", "POLYGON_MAINNET", "POLYGON_TEST_AMOY", "BSC_MAINNET, "BSC_TESTNET", "OPTIMISM_MAINNET", "OPTIMISM_TESTNET", "POLYGON_ZK_EVM_TESTNET", "POLYGON_ZK_EVM_MAINNET", "ARBITRUM_TESTNET", "ARBITRUMONE_MAINNET", "FUSE_TESTNET", "FUSE_MAINNET", "BERACHIAN_TESTNET", "THE_GRAPH"
themestring'light' or 'dark' (customization to be given by the dApp)
customThemeINotificationItemThemecustom theme object for the component
isSpambooleanwhether a spam notification or not
subscribeFnPromiseFunction to subscribe to the channel
isSubscribedFnPromiseFunction that returns the subscription status of a channel

Theming in NotificationItem component

import { INotificationItemTheme,notificationLightTheme } from '@pushprotocol/uiweb';

const customTheme: INotificationItemTheme = {...notificationLightTheme,...{
  borderRadius:{
    ...notificationLightTheme.borderRadius,
    modal:'12px',
  },
  color:{
    ...notificationLightTheme.color,
      channelNameText:'#62626A',
      notificationTitleText:'#000',
      notificationContentText:'#62626A',
      modalBorder:'#C8C8CB',
      timestamp:'#62626A',
  },
  fontWeight:{
    ...notificationLightTheme.fontWeight,
    channelNameText:600,
    notificationTitleText:600,
    notificationContentText:500,
    timestamp:400
  },
  fontSize:{
    ...notificationLightTheme.fontSize,
    channelNameText:'16px',
    notificationTitleText:'16px',
    notificationContentText:'16px',
    timestamp:'12px'
  },
  modalDivider:'none'
}};

List of all theme variables

Notification SDK Diagram

Support Chat Item component

Import the SDK package in the component file where you want to render the support chat component.

import { Chat } from "@pushprotocol/uiweb";
import { ITheme } from '@pushprotocol/uiweb';

Render the Chat Component as follows

<Chat
   account="0x6430C47973FA053fc8F055e7935EC6C2271D5174" //user address
   signer={librarySigner}
   supportAddress="0xd9c1CCAcD4B8a745e191b62BA3fcaD87229CB26d" //support address
   env="staging"
 />

Allowed Options (props with * are mandatory)

PropTypeDefaultRemarks
account*string-user address(sender)
supportAddress*string-support user's address(receiver)
greetingMsgstring'Hi there!'first message in chat scree
themeITheme<lightTheme>theme for chat modal (only lightTheme available now)
modalTitlestring'Chat with us!'Modal header title
apiKeystring''api key
envstring'prod'API env - 'prod', 'staging', 'dev'

Example code for using custom theme

import React from 'react';
import { Chat, ITheme } from '@pushprotocol/uiweb';


export const ChatSupportTest = () => {
  const theme: ITheme = {
    bgColorPrimary: 'gray',
    bgColorSecondary: 'purple',
    textColorPrimary: 'white',
    textColorSecondary: 'green',
    btnColorPrimary: 'red',
    btnColorSecondary: 'purple',
    border: '1px solid black',
    borderRadius: '40px',
    moduleColor: 'pink',
  };

  return (
    <Chat
      account='0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7'
      supportAddress="0xFe6C8E9e25f7bcF374412c5C81B2578aC473C0F7"
      apiKey="tAWEnggQ9Z.UaDBNjrvlJZx3giBTIQDcT8bKQo1O1518uF1Tea7rPwfzXv2ouV5rX9ViwgJUrXm"
      env='staging'
      theme={theme}
    />
  );
};

List of all theme variables

image

Chat and Notification Widget

Import the SDK package in the component file where you want to render the chat and notification component.

import { ChatAndNotificationWidget,PUSH_TABS } from "@pushprotocol/uiweb";
import * as PushAPI from '@pushprotocol/restapi';
import { ChatAndNotificationWidget } from '@pushprotocol/uiweb';
import { IUser } from '@pushprotocol/restapi';

To use this component, we need to have our PGP keys created. Then decrypt the encrypted pgp private key.

const account = 'eip155:0xD8634C39BBFd4033c0d3289C4515275102423681';
  const pvtkey = null;
  const user = await PushAPI.user.get({ account: account, env });
        if (user?.encryptedPrivateKey) {
            const response = await PushAPI.chat.decryptPGPKey({
                encryptedPGPPrivateKey: (user as IUser).encryptedPrivateKey,
                account: account,
                signer: signer_,
                env,
                toUpgrade: true,
              });
         pvtkey= response;
        }
  });

Render the ChaChatAndNotificationWidget Component as follows

<ChatAndNotificationWidget
    account={account}
    signer={signer_}
    env={'staging'}
    activeTab={PUSH_TABS.APP_NOTIFICATIONS}
    decryptedPgpPvtKey={pvtKey}
 />

Allowed Options (props with * are mandatory)

PropTypeDefaultRemarks
account*string-user address(sender)
signer_--signer object(not passing signer would not show opt-in functionality in spam notifications)
decryptedPgpPvtKey*string-decrypted pgp private key
activeTabPushTabsPUSH_TABS.CHATSset active tab when modal first opens
activeChatstring-to open a particular chat when modal first opens
onClose() => void-function to execute when modal is minimised
envstring'prod'API env - 'prod', 'staging', 'dev'
1.2.11

3 days ago

1.4.0-alpha.6

4 days ago

1.4.0-alpha.7

3 days ago

1.2.10

4 days ago

1.2.9

4 days ago

1.4.0-alpha.3

4 days ago

1.4.0-alpha.4

4 days ago

1.4.0-alpha.5

4 days ago

1.4.0-alpha.1

8 days ago

1.4.0-alpha.2

8 days ago

1.3.2-alpha.1

11 days ago

1.3.2-alpha.2

11 days ago

1.2.8

13 days ago

0.0.1-alpha.46

13 days ago

1.3.1-alpha.17

25 days ago

1.3.1-alpha.16

26 days ago

1.3.1-alpha.15

28 days ago

1.3.1-alpha.13

1 month ago

1.3.1-alpha.14

1 month ago

1.3.1-alpha.12

1 month ago

1.3.1-alpha.9

2 months ago

1.3.1-alpha.11

2 months ago

1.3.1-alpha.10

2 months ago

1.2.7

2 months ago

1.2.6

2 months ago

1.3.1-alpha.8

2 months ago

0.0.1-alpha.45

2 months ago

1.3.1-alpha.7

2 months ago

1.3.1-alpha.6

2 months ago

1.3.1-alpha.5

2 months ago

1.3.1-alpha.4

2 months ago

1.3.1-alpha.3

3 months ago

1.3.1-alpha.2

3 months ago

0.0.1-alpha.44

3 months ago

1.3.1-alpha.1

3 months ago

1.3.0-alpha.47

3 months ago

1.3.0-alpha.50

3 months ago

1.3.0-alpha.43

3 months ago

1.3.0-alpha.45

3 months ago

1.3.0-alpha.46

3 months ago

0.0.1-alpha.43

3 months ago

0.0.1-alpha.42

3 months ago

0.0.1-alpha.41

3 months ago

1.2.5

3 months ago

0.0.1-alpha.40

3 months ago

0.0.1-alpha.38

3 months ago

0.0.1-alpha.39

3 months ago

0.0.1-alpha.37

4 months ago

0.0.1-alpha.36

4 months ago

1.2.4

4 months ago

1.2.3

4 months ago

1.2.2

4 months ago

1.2.0

4 months ago

1.1.23

5 months ago

1.1.22

5 months ago

0.0.1-alpha.23

7 months ago

0.0.1-alpha.22

7 months ago

0.0.1-alpha.25

6 months ago

0.0.1-alpha.24

6 months ago

0.0.1-alpha.27

6 months ago

0.0.1-alpha.26

6 months ago

0.0.1-alpha.29

6 months ago

0.0.1-alpha.28

6 months ago

0.0.1-alpha.21

7 months ago

0.0.1-alpha.20

7 months ago

0.0.1-alpha.12

8 months ago

0.0.1-alpha.11

8 months ago

0.0.1-alpha.14

7 months ago

0.0.1-alpha.13

8 months ago

0.0.1-alpha.16

7 months ago

0.0.1-alpha.15

7 months ago

0.0.1-alpha.18

7 months ago

0.0.1-alpha.17

7 months ago

0.0.1-alpha.10

8 months ago

0.0.1-alpha.19

7 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.1.9

9 months ago

1.1.8

9 months ago

1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.4

10 months ago

0.0.1-alpha.8

8 months ago

1.1.3

10 months ago

0.0.1-alpha.9

8 months ago

1.1.2

10 months ago

0.0.1-alpha.6

9 months ago

0.0.1-alpha.7

8 months ago

0.0.1-alpha.4

9 months ago

0.0.1-alpha.5

9 months ago

0.0.1-alpha.2

9 months ago

0.0.1-alpha.3

9 months ago

0.0.1-alpha.0

9 months ago

0.0.1-alpha.1

9 months ago

1.1.11

9 months ago

1.1.10

9 months ago

1.1.16

6 months ago

1.1.15

7 months ago

1.1.14

7 months ago

1.1.13

9 months ago

1.1.19

6 months ago

1.1.18

6 months ago

1.1.17

6 months ago

0.0.1-alpha.30

6 months ago

0.0.1-alpha.31

5 months ago

1.1.21

5 months ago

1.1.20

5 months ago

1.0.2

12 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.3.0

1 year ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago