Skip to content

Commit

Permalink
chore(uiweb): add old sdk code for uiweb
Browse files Browse the repository at this point in the history
copied the old uiweb code to new sdk
  • Loading branch information
subhranshudas committed Oct 5, 2022
1 parent baa94af commit c67b950
Show file tree
Hide file tree
Showing 46 changed files with 7,468 additions and 96 deletions.
3 changes: 3 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"babelrcRoots": ["*"]
}
16 changes: 9 additions & 7 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
"defaultBase": "main"
},
"cli": {
"defaultCollection": "@nrwl/workspace"
"defaultCollection": "@nrwl/react"
},
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": [
"build",
"lint",
"test",
"e2e"
]
"cacheableOperations": ["build", "lint", "test", "e2e"]
}
}
},
"generators": {
"@nrwl/react": {
"application": {
"babel": true
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@
"private": true,
"dependencies": {
"axios": "^0.27.2",
"core-js": "^3.6.5",
"date-fns": "^2.28.0",
"ethers": "^5.7.1",
"html-react-parser": "^1.4.13",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-is": "17.0.2",
"regenerator-runtime": "0.13.7",
"socket.io-client": "^4.5.2",
"styled-components": "5.3.5",
"tslib": "^2.3.0",
"uuid": "^9.0.0"
},
Expand All @@ -28,20 +36,34 @@
"@nrwl/jest": "14.1.7",
"@nrwl/js": "14.1.7",
"@nrwl/linter": "14.1.7",
"@nrwl/react": "14.1.7",
"@nrwl/web": "14.1.7",
"@nrwl/workspace": "14.1.7",
"@testing-library/react": "12.1.5",
"@types/jest": "27.4.1",
"@types/node": "16.11.7",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-is": "17.0.3",
"@types/styled-components": "5.1.25",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "~5.18.0",
"@typescript-eslint/parser": "~5.18.0",
"babel-jest": "27.5.1",
"babel-plugin-styled-components": "1.10.7",
"commitizen": "^4.2.5",
"cz-conventional-changelog": "^3.3.0",
"eslint": "~8.12.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react": "7.29.4",
"eslint-plugin-react-hooks": "4.5.0",
"husky": "^8.0.0",
"jest": "27.5.1",
"nx": "14.1.7",
"prettier": "^2.5.1",
"react-test-renderer": "17.0.2",
"ts-jest": "27.1.4",
"ts-node": "9.1.1",
"typescript": "~4.6.2"
Expand Down
12 changes: 12 additions & 0 deletions packages/uiweb/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": [["styled-components", { "pure": true, "ssr": true }]]
}
18 changes: 18 additions & 0 deletions packages/uiweb/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
156 changes: 156 additions & 0 deletions packages/uiweb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# uiweb

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

## How to use in your app?

### Installation
```
yarn add @pushprotocol/uiweb
```
or
```
npm install @pushprotocol/uiweb
```
<br />

***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
```

<br />

### Notification Item component

Import the sdk package in the component file where you want to render notification(s)
```typescript
import { NotificationItem, chainNameType } from "@pushprotocol/uiweb";
```

After you get the Notification data from the [API](../restapi/README.md#fetching-user-notifications) or otherwise

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

render the Notification UI as follows
```typescript
<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](../restapi/README.md#fetching-user-spam-notifications)

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

render the Spam UI as follows
```typescript
{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
/>
);
})}
```

```typescript
const subscribeFn = async () => {
// opt in to the spam notification item channel
}
```
we can use this `@pushprotocol/restapi` method to do that - [subscribe](../restapi/README.md#opt-in-to-a-channel)


```typescript
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](../restapi/README.md#fetching-user-subscriptions)

where

| Prop | Type | Remarks |
|----------|--------|--------------------------------------------|
| notificationTitle | string | Title of the notification (given during notification creation) |
| notificationBody | number | Message body of the notification (given during notification creation) |
| icon | string | Channel Icon (IPFS url) (given during channel setup) |
| app | string | Channel Name (given during channel setup) |
| cta | string | Call To Action Link (given during notification creation) |
| image | string | Any media link (given during notification creation) |
| url | string | Channel Link (given during channel setup) |
| chainName | string | Can 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" |
| theme | string | 'light' or 'dark' (customization to be given by the dApp) |
| isSpam | boolean | whether a spam notification or not |
| subscribeFn | Promise | Function to subscribe to the channel |
| isSubscribedFn | Promise | Function that returns the subscription status of a channel |
10 changes: 10 additions & 0 deletions packages/uiweb/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'uiweb',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/uiweb',
};
15 changes: 15 additions & 0 deletions packages/uiweb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@pushprotocol/uiweb",
"version": "0.0.1",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"date-fns": "^2.28.0",
"html-react-parser": "^1.4.13"
},
"peerDependencies": {
"react": ">=16.8.0",
"styled-components": "5.3.5"
}
}
61 changes: 61 additions & 0 deletions packages/uiweb/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/uiweb/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nrwl/web:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/uiweb",
"tsConfig": "packages/uiweb/tsconfig.lib.json",
"project": "packages/uiweb/package.json",
"entryFile": "packages/uiweb/src/index.ts",
"external": ["react/jsx-runtime"],
"rollupConfig": "@nrwl/react/plugins/bundle-rollup",
"compiler": "babel",
"assets": [
{
"glob": "packages/uiweb/README.md",
"input": ".",
"output": "."
}
],
"format": [
"esm",
"cjs"
]
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/uiweb/**/*.{ts,tsx,js,jsx}"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/packages/uiweb"],
"options": {
"jestConfig": "packages/uiweb/jest.config.ts",
"passWithNoTests": true
}
},
"ci-version": {
"executor": "@jscutlery/semver:version",
"options": {
"preset": "angular",
"commitMessageFormat": "ci(${projectName}): 🎉 cut release to ${projectName}-v${version}",
"postTargets": ["uiweb:build", "uiweb:ci-publish"]
}
},
"ci-publish": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "node tools/scripts/publish.mjs uiweb"
}
}
}
}
1 change: 1 addition & 0 deletions packages/uiweb/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib';
3 changes: 3 additions & 0 deletions packages/uiweb/src/lib/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './notification';
export * from './parsetext';
export * from './subscribemodal';
Loading

0 comments on commit c67b950

Please sign in to comment.