-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,131 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PRIVATE_KEY=your_private_key | ||
RPC=your_rpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Notification Setting Example | ||
|
||
|
||
## Usecase highlighted | ||
|
||
This example shows the end-to-end process of | ||
- Creating a channel | ||
- Defining the setting, | ||
- Make user subscribe to the channel for the settings they are interested, | ||
- Trigger a notification | ||
- At last list down the notifications | ||
|
||
Note: It is recommended to use the `.env` to put your private key for testing and make sure the wallet is funded with ether and PUSH tokens. For this, rename `.env.sample` to `.env`. | ||
|
||
## Install instructions | ||
1. Navigate to this directory from the terminal | ||
2. do `npm install` or `yarn install` | ||
3. do `yarn start` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { PushAPI } from '@pushprotocol/restapi'; | ||
import { ethers } from 'ethers'; | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
// initialise the provider | ||
const provider = new ethers.providers.JsonRpcProvider( | ||
// PUBLIC RPC | ||
process.env?.RPC?? 'https://goerli.blockpi.network/v1/rpc/public' | ||
); | ||
|
||
let signer; | ||
if (process.env.PRIVATE_KEY) { | ||
signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider); | ||
console.log('Using the wallet from .env: %s', signer.address); | ||
} else { | ||
signer = ethers.Wallet.createRandom().connect(provider); | ||
console.log('Fund your wallet with eth and PUSH token: %s', signer.address); | ||
} | ||
|
||
// initialise the sdk with the signer and env | ||
// for channel | ||
const userAlice = await PushAPI.initialize(signer, { env: 'staging' }); | ||
// for subscribers | ||
const userBob = await PushAPI.initialize( | ||
ethers.Wallet.createRandom().connect(provider), | ||
{ env: 'staging' } | ||
); | ||
|
||
|
||
const userKate = await PushAPI.initialize( | ||
ethers.Wallet.createRandom().connect(provider), | ||
{ env: 'staging' } | ||
); | ||
|
||
const main = async () => { | ||
try { | ||
// create the channel | ||
const createChannelRes = await userAlice.channel.create({ | ||
// name of the channel | ||
name: 'Test 123', | ||
// channel description | ||
description: 'Gm gm PUSH fam', | ||
// url of the channel | ||
url: 'https://push.org', | ||
// base64 icon | ||
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAz0lEQVR4AcXBsU0EQQyG0e+saWJ7oACiKYDMEZVs6GgSpC2BIhzRwAS0sgk9HKn3gpFOAv3v3V4/3+4U4Z1q5KTy42Ql940qvFONnFSGmCFmiN2+fj7uCBlihpgh1ngwcvKfwjuVIWaIGWKNB+GdauSk8uNkJfeNKryzYogZYoZY40m5b/wlQ8wQM8TayMlKeKcaOVkJ71QjJyuGmCFmiDUe+HFy4VyEd57hx0mV+0ZliBlihlgL71w4FyMnVXhnZeSkiu93qheuDDFDzBD7BcCyMAOfy204AAAAAElFTkSuQmCC', | ||
}); | ||
console.log("Channel created with hash: %s", createChannelRes.transactionHash); | ||
|
||
// create settings | ||
const settingRes = await userAlice.channel.setting([ | ||
{ | ||
type: 1, | ||
description: 'Setting1', | ||
default: 1, | ||
}, | ||
{ | ||
type: 2, | ||
description: 'Setting2', | ||
default: 10, | ||
data: { | ||
upper: 100, | ||
lower: 1, | ||
enabled: true, | ||
ticker: 5, | ||
}, | ||
}, | ||
]); | ||
|
||
console.log(settingRes) | ||
|
||
// fetch channel info with the settings | ||
const channelInfoWithSetting = await userAlice.channel.info(); | ||
console.log('Channel info with settings'); | ||
console.log(channelInfoWithSetting); | ||
|
||
// make bob and kate subscribe to the channel | ||
// bob wants to opt in to all the settings | ||
await userBob.notification.subscribe( | ||
`eip155:5:${userAlice.account}`, | ||
{ | ||
settings: [ | ||
// enabled for boolean type | ||
{ | ||
enabled: true, | ||
}, | ||
{ | ||
// enabled for slider type when value is 10 | ||
enabled: true, | ||
value: 10, | ||
}, | ||
], | ||
} | ||
); | ||
// kate doesnot want to opt in to any settings | ||
await userKate.notification.subscribe( | ||
`eip155:5:${userAlice.account}`, | ||
{ | ||
settings: [ | ||
// disabled for boolean type | ||
{ | ||
enabled: false, | ||
}, | ||
{ | ||
// disabled for slider type and pass 0 as value | ||
enabled: false, | ||
value: 0, | ||
}, | ||
], | ||
} | ||
); | ||
|
||
// fetch Bob's subscription | ||
const bobSubscriptions = await userBob.notification.subscriptions(); | ||
console.log("Bob's subcriptions: "); | ||
console.log(bobSubscriptions); | ||
|
||
// fetch Kate's subscription | ||
const kateSubscriptions = await userKate.notification.subscriptions(); | ||
console.log("Kate's subcriptions: "); | ||
console.log(kateSubscriptions); | ||
|
||
// Trigger broadcast for slider type | ||
const notifResForSlider = await userAlice.channel.send(['*'], { | ||
notification: { | ||
title: 'gm gm slider', | ||
body: 'Sending notification with category 2', | ||
}, | ||
payload: { | ||
title: 'testing first notification', | ||
body: 'testing with random body', | ||
cta: 'https://google.com/', | ||
embed: 'https://avatars.githubusercontent.com/u/64157541?s=200&v=4', | ||
// index of the notification the channel wants to trigger, in this for 2nd index which is for Setting2 type | ||
category: 2, | ||
}, | ||
}); | ||
|
||
// Trigger broadcast for boolean type | ||
const notifResForBoolean = await userAlice.channel.send(['*'], { | ||
notification: { | ||
title: 'gm gm boolean', | ||
body: 'Sending notification with category 1', | ||
}, | ||
payload: { | ||
title: 'testing first notification', | ||
body: 'testing with random body', | ||
cta: 'https://google.com/', | ||
embed: 'https://avatars.githubusercontent.com/u/64157541?s=200&v=4', | ||
// index of the notification the channel wants to trigger, in this for 1st index which is for Setting12 type | ||
category: 1, | ||
}, | ||
}); | ||
|
||
// List the inbox of Bob | ||
const bobList = await userBob.notification.list() | ||
console.log("Bob's notification list") | ||
console.log(bobList) | ||
|
||
// List down inbox of Kate | ||
const kateList = await userKate.notification.list() | ||
console.log("Kate's notification list") | ||
console.log(kateList) | ||
|
||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "notification-setting", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"build": "rimraf ./build && tsc", | ||
"start": "nodemon", | ||
"inspect": "nodemon --inspect index.js", | ||
"dev": "node-dev --respawn --transpile-only index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@pushprotocol/restapi": "^1.4.30" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^3.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# push-notitifcations-on-subgraph-mainnet | ||
Integrating Push Protocol notifications on to The Graph Network |
126 changes: 126 additions & 0 deletions
126
packages/examples/subgraph-notification/abis/EPNSCore.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ "internalType": "address", "name": "_logic", "type": "address" }, | ||
{ "internalType": "address", "name": "_governance", "type": "address" }, | ||
{ | ||
"internalType": "address", | ||
"name": "_pushChannelAdmin", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "_pushTokenAddress", | ||
"type": "address" | ||
}, | ||
{ "internalType": "address", "name": "_wethAddress", "type": "address" }, | ||
{ | ||
"internalType": "address", | ||
"name": "_uniswapRouterAddress", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "_lendingPoolProviderAddress", | ||
"type": "address" | ||
}, | ||
{ "internalType": "address", "name": "_daiAddress", "type": "address" }, | ||
{ "internalType": "address", "name": "_aDaiAddress", "type": "address" }, | ||
{ "internalType": "uint256", "name": "_referralCode", "type": "uint256" } | ||
], | ||
"stateMutability": "payable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "previousAdmin", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "newAdmin", | ||
"type": "address" | ||
} | ||
], | ||
"name": "AdminChanged", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "implementation", | ||
"type": "address" | ||
} | ||
], | ||
"name": "Upgraded", | ||
"type": "event" | ||
}, | ||
{ "stateMutability": "payable", "type": "fallback" }, | ||
{ | ||
"inputs": [], | ||
"name": "admin", | ||
"outputs": [ | ||
{ "internalType": "address", "name": "admin_", "type": "address" } | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ "internalType": "address", "name": "newAdmin", "type": "address" } | ||
], | ||
"name": "changeAdmin", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "implementation", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "implementation_", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "newImplementation", | ||
"type": "address" | ||
} | ||
], | ||
"name": "upgradeTo", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "newImplementation", | ||
"type": "address" | ||
}, | ||
{ "internalType": "bytes", "name": "data", "type": "bytes" } | ||
], | ||
"name": "upgradeToAndCall", | ||
"outputs": [], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ "stateMutability": "payable", "type": "receive" } | ||
] |
Oops, something went wrong.