From edee24a77cc7baf61b75f3d2c542f77f6c3750a5 Mon Sep 17 00:00:00 2001 From: Ashis Kumar Pradhan <38760485+akp111@users.noreply.github.com> Date: Fri, 29 Sep 2023 14:13:58 +0530 Subject: [PATCH] 720 pushstream class implementation (#737) * fix: stream changes * fix: stream changes * fix: stream changes * fix: PUSH Stream Changes * fix: chat classes split * fix: Notification socket initialisations and rules backward compatibility * fix: added message decrypt * fix: review comments * fix: socket events * fix: test case fix and UserInfo to user * fix: rip PushNotification class * fix: additional check * fix: minor fixes --------- Co-authored-by: Mohammed S --- packages/restapi/src/lib/config.ts | 14 +++--- .../src/lib/pushNotification/channel.ts | 2 +- .../pushNotification/pushNotificationBase.ts | 6 +-- .../lib/pushNotification/channel.test.ts | 45 ++++++++++++++++--- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/packages/restapi/src/lib/config.ts b/packages/restapi/src/lib/config.ts index 96a80c793..e597c22bc 100644 --- a/packages/restapi/src/lib/config.ts +++ b/packages/restapi/src/lib/config.ts @@ -108,7 +108,7 @@ export const VIEM_CORE_CONFIG = { [ENV.PROD]: { NETWORK: mainnet, API_BASE_URL: API_BASE_URL[ENV.PROD], - EPNS_CORE_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + EPNS_CORE_CONTRACT: '0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE', }, [ENV.STAGING]: { NETWORK: goerli, @@ -118,19 +118,19 @@ export const VIEM_CORE_CONFIG = { [ENV.DEV]: { NETWORK: goerli, API_BASE_URL: API_BASE_URL[ENV.DEV], - EPNS_CORE_CONTRACT: '0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0', + EPNS_CORE_CONTRACT: '0x23346B732d56d34EC4e890419fBFB8548216a799', }, [ENV.LOCAL]: { NETWORK: goerli, API_BASE_URL: API_BASE_URL[ENV.DEV], - EPNS_CORE_CONTRACT: '0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0', + EPNS_CORE_CONTRACT: '0x23346B732d56d34EC4e890419fBFB8548216a799', }, }; export const CORE_CONFIG = { [ENV.PROD]: { API_BASE_URL: API_BASE_URL[ENV.PROD], - EPNS_CORE_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + EPNS_CORE_CONTRACT: '0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE', }, [ENV.STAGING]: { API_BASE_URL: API_BASE_URL[ENV.STAGING], @@ -138,11 +138,11 @@ export const CORE_CONFIG = { }, [ENV.DEV]: { API_BASE_URL: API_BASE_URL[ENV.DEV], - EPNS_CORE_CONTRACT: '0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0', + EPNS_CORE_CONTRACT: '0x23346B732d56d34EC4e890419fBFB8548216a799', }, [ENV.LOCAL]: { API_BASE_URL: API_BASE_URL[ENV.DEV], - EPNS_CORE_CONTRACT: '0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0', + EPNS_CORE_CONTRACT: '0x23346B732d56d34EC4e890419fBFB8548216a799', }, }; @@ -239,7 +239,7 @@ const CONFIG = { export default CONFIG; export const TOKEN = { - [ENV.PROD]: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + [ENV.PROD]: '0xf418588522d5dd018b425E472991E52EBBeEEEEE', [ENV.STAGING]: '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33', [ENV.DEV]: '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33', [ENV.LOCAL]: '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33', diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index 6fc5ea0d3..b21fa4e3a 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -393,7 +393,7 @@ export class Channel extends PushNotificationBaseClass { ); // if allowance is not greater than the fees, dont call approval again if (!allowanceAmount.gte(fees)) { - const approveRes = this.approveToken( + const approveRes = await this.approveToken( pushTokenContract, config.CORE_CONFIG[this.env!].EPNS_CORE_CONTRACT, fees diff --git a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts index 59fc4df4d..c081b2f0e 100644 --- a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts +++ b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts @@ -634,7 +634,7 @@ export class PushNotificationBaseClass { SETTING_DELIMITER + ele.default; notificationSettingDescription = - notificationSettingDescription + ele.description; + notificationSettingDescription + SETTING_SEPARATOR + ele.description; } if (ele.type == 1) { if (ele.data) { @@ -650,13 +650,13 @@ export class PushNotificationBaseClass { ele.data.upper; notificationSettingDescription = - notificationSettingDescription + ele.description; + notificationSettingDescription + SETTING_SEPARATOR + ele.description; } } } return { setting: notificationSetting.replace(/^\+/, ''), - description: notificationSettingDescription, + description: notificationSettingDescription.replace(/^\+/, ''), }; } } diff --git a/packages/restapi/tests/lib/pushNotification/channel.test.ts b/packages/restapi/tests/lib/pushNotification/channel.test.ts index 5f70e1036..579fcb3c4 100644 --- a/packages/restapi/tests/lib/pushNotification/channel.test.ts +++ b/packages/restapi/tests/lib/pushNotification/channel.test.ts @@ -2,7 +2,6 @@ import * as path from 'path'; import * as dotenv from 'dotenv'; dotenv.config({ path: path.resolve(__dirname, '../../../.env') }); - import { PushAPI } from '../../../src/lib/pushapi/PushAPI'; import { expect } from 'chai'; import { ethers } from 'ethers'; @@ -30,7 +29,15 @@ describe('PushAPI.channel functionality', () => { provider ); account2 = await signer2.getAddress(); - + enum ENV { + PROD = 'prod', + STAGING = 'staging', + DEV = 'dev', + /** + * **This is for local development only** + */ + LOCAL = 'local', + } // initialisation with signer and provider userKate = await PushAPI.initialize(signer2) // initialisation with signer @@ -105,9 +112,9 @@ describe('PushAPI.channel functionality', () => { }); it('Without signer and account : Should return response without passing the options', async () => { - const res = await userKate.channel.subscribers(); - expect(res).not.null; - }); + const res = await userKate.channel.subscribers(); + expect(res).not.null; + }); it('Without signer and account : Should throw error for invalid caip', async () => { await expect(() => @@ -260,8 +267,32 @@ describe('PushAPI.channel functionality', () => { url: 'https://google.com', icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAz0lEQVR4AcXBsU0EQQyG0e+saWJ7oACiKYDMEZVs6GgSpC2BIhzRwAS0sgk9HKn3gpFOAv3v3V4/3+4U4Z1q5KTy42Ql940qvFONnFSGmCFmiN2+fj7uCBlihpgh1ngwcvKfwjuVIWaIGWKNB+GdauSk8uNkJfeNKryzYogZYoZY40m5b/wlQ8wQM8TayMlKeKcaOVkJ71QjJyuGmCFmiDUe+HFy4VyEd57hx0mV+0ZliBlihlgL71w4FyMnVXhnZeSkiu93qheuDDFDzBD7BcCyMAOfy204AAAAAElFTkSuQmCC', }); - // console.log(res) - expect(res).not.null + // console.log(res) + expect(res).not.null; + }, 10000000000); + }); + + describe.skip('channel :: create', () => { + it('Should create channel', async () => { + const res = await userKate.channel.create({ + name: 'SDK Test', + description: 'Testing new description', + url: 'https://google.com', + icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAz0lEQVR4AcXBsU0EQQyG0e+saWJ7oACiKYDMEZVs6GgSpC2BIhzRwAS0sgk9HKn3gpFOAv3v3V4/3+4U4Z1q5KTy42Ql940qvFONnFSGmCFmiN2+fj7uCBlihpgh1ngwcvKfwjuVIWaIGWKNB+GdauSk8uNkJfeNKryzYogZYoZY40m5b/wlQ8wQM8TayMlKeKcaOVkJ71QjJyuGmCFmiDUe+HFy4VyEd57hx0mV+0ZliBlihlgL71w4FyMnVXhnZeSkiu93qheuDDFDzBD7BcCyMAOfy204AAAAAElFTkSuQmCC', + }); + // console.log(res) + expect(res).not.null; + }, 10000000000); + }); + + describe.skip('channel :: settings', () => { + it('Should create channel', async () => { + const res = await userKate.channel.setting([ + { type: 0, default: 1, description: 'My Notif Settings' }, + {type: 1, default: 5, description: "My notif setting 2", data: {upper:100, lower:5}} + ]); + // console.log(res) + expect(res).not.null; }, 10000000000); }); });