Skip to content

Commit

Permalink
fix: merged main
Browse files Browse the repository at this point in the history
  • Loading branch information
akp111 committed Oct 26, 2023
2 parents 01b5fb8 + 325ad80 commit e1d9cf7
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 127 deletions.
13 changes: 13 additions & 0 deletions packages/examples/token-gated-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# About Token Gated Chat
Token gated chat shows you how to create group chats using Push Chat that can gated in various ways including token or NFT gating on entry of the group or when a participant of that group wants to send a message

## What's the use case
You can use this example to see the functionality of token gating. Some use cases are:

- Creating your token gated community and hosting that particular chat on your frontend
- Enabling more token use cases and ensuring that conversations that happen in your group are coming from token holders or from participants that have certain on-chain traits (for example: POAPs, ENS domain names, UD domain names, tec)

## Install instructions
1. Navigate to this directory from the terminal
2. do `npm install` or `yarn install`
3. do `yarn start`
59 changes: 59 additions & 0 deletions packages/examples/token-gated-chat/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PushAPI } from '@pushprotocol/restapi';
import { ethers } from 'ethers';

// Creating a random signer from a wallet, ideally this is the wallet you will connect
const signer = ethers.Wallet.createRandom();

console.log(`Signer address: ${signer.address} | Signer private key: ${signer.privateKey}`);

// Initialize wallet user, pass 'prod' instead of 'staging' for mainnet apps
const userAlice = await PushAPI.initialize(signer, { env: 'staging' });

// Creating your token gated community
const createTokenGatedGroup = await userAlice.chat.group.create('Push Community', {
description: 'Token gated web3 native chat example', // provide short description of group
image: 'data:image/png;base64,iVBORw0K...', // provide base64 encoded image
members: [], // not needed, rules define this, can omit
admins: [], // not needed as per problem statement, can omit
private: true,
rules: {
"entry": { // entry is based on conditions
"conditions": {
"any": [ // any of the decider should allow entry
{ // decider 1 - If admin or owner invites someone
"any": [
{ // criteria 1
"type": "PUSH",
"category": "INVITE",
"subcategory": "DEFAULT",
"data": {
"inviterRoles": [
"ADMIN",
"OWNER"
]
}
}
]
},
{ // decicder 2 - If wallet holds 1 NFT on polygon testnet
"any": [
{ // criteria 1
type: "PUSH", // define type that rules engine should go for
category: "ERC721", // define it's ERC20 token that you want to check, supports ERC721 as well
subcategory: "holder", // define if you are checking 'holder'
data: {
"contract": "eip155:80001:0x9105D95577575116948F5afcF479254f49F27939",
"comparison": ">=", // what comparison needs to pass
"amount": 1, // amount that needs to passed
"decimals": 18,
}
}
]
}
]
}
}
}
});

console.log("Chat created successfully!", createTokenGatedGroup);
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "automated-chat",
"name": "token-gated-chat",
"version": "1.0.0",
"description": "Example of Push Chat from backend, auto-responding to messages sent",
"main": "src/index.js",
"description": "Example of Push Chat token gated group in action",
"main": "index.js",
"type": "module",
"scripts": {
"build": "rimraf ./build && tsc",
"start": "nodemon",
"inspect": "nodemon --inspect src/index.js",
"dev": "node-dev --respawn --transpile-only src/index.js",
"inspect": "nodemon --inspect index.js",
"dev": "node-dev --respawn --transpile-only index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@pushprotocol/restapi": "1.4.19",
"@pushprotocol/restapi": "latest",
"@pushprotocol/socket": "0.5.2",
"ethers": "5.7.2"
},
Expand Down
Empty file.
42 changes: 0 additions & 42 deletions packages/examples/use-cases/automated-chat/src/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/restapi/src/lib/user/getFeedsPerChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getFeedsPerChannel = async (options: FeedsPerChannelOptionsType) =>
throw new Error('channels cannot be empty');
}
const _channel = await getCAIPAddress(env, channels[0], 'Channel');
const apiEndpoint = `${API_BASE_URL}/v1/users/${_channel}/channels/${_user}/feeds`;
const apiEndpoint = `${API_BASE_URL}/v1/users/${_user}/channels/${_channel}/feeds`;
const queryObj = {
page,
limit: getLimit(limit),
Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"date-fns": "^2.28.0",
"emoji-picker-react": "^4.4.9",
"ethers": "^5.6.8",
"font-awesome": "^4.7.0",

"gif-picker-react": "^1.1.0",
"html-react-parser": "^1.4.13",
"livekit-client": "^1.13.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ChatAndNotificationMainContextProvider, ChatAndNotificationPropsContext, NotificationMainStateContextProvider } from '../../context';
import 'font-awesome/css/font-awesome.min.css';
// import 'font-awesome/css/font-awesome.min.css';
import { Constants } from '../../config';
import { ChatMainStateContextProvider } from '../../context';

Expand Down
Loading

0 comments on commit e1d9cf7

Please sign in to comment.