Skip to content

Commit

Permalink
fix: Merge branch 'main' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Oct 16, 2023
2 parents a0a84dc + 4acbe2a commit 118ea49
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 55 deletions.
2 changes: 1 addition & 1 deletion packages/examples/sdk-backend-node/pushAPI/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const runPushAPIChannelCases = async (): Promise<void> => {
// -------------------------------------------------------------------
console.log('PushAPI.channel.setting');
const channelSettingTrx = await userAlice.channel.setting([
{ type: 0, default: 1, description: 'My Notif Settings' },
{ type: 1, default: 1, description: 'My Notif Settings' },
]);
if (showAPIResponse) {
console.log(channelSettingTrx);
Expand Down
4 changes: 3 additions & 1 deletion packages/restapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6582,7 +6582,7 @@ const verifyChannelRes = await userAlice.channel.verify(channelToBeVerified)
```tsx
// creates channel settings
const createChannelSettingRes = userAlice.channel.settings([{ type: 0, default: 1, description: 'marketing' }, {type: 2, default: 10, description: 'loan liquidation threshold', data: {upper: 100, lower: 5}}])
const createChannelSettingRes = userAlice.channel.settings([{ type: 0, default: 1, description: 'marketing' }, {type: 2, default: 10, description: 'loan liquidation threshold', data: {upper: 100, lower: 5, enabled: true, ticker: 5}}])

```
Expand All @@ -6595,6 +6595,8 @@ const createChannelSettingRes = userAlice.channel.settings([{ type: 0, default:
| description | string | - | A description of the setting. |
| data.upper* | number | - | Valid for slider type only. The upper limit for the setting. |
| data.lower* | number | - | Valid for slider type only. The lower limit for the setting. |
| data.enabled* | boolean | - | Valid for slider type only. If the settting should be enabled by default. |
| data.ticker* | number | - | Valid for slider type only. Offset for slider values |
<details>
<summary><b>Expected response (Create Channel Setting)</b></summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export type NotificationSetting = {
data?: {
upper: number;
lower: number;
enabled?: boolean;
ticker?: number;
};
};

Expand Down
16 changes: 12 additions & 4 deletions packages/restapi/src/lib/pushNotification/pushNotificationBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const SETTING_DELIMITER = '-';
const SETTING_SEPARATOR = '+';
const SLIDER_TYPE = 2;
const BOOLEAN_TYPE = 1;
const DEFAULT_ENABLE_VALUE = '1';
const DEFAULT_TICKER_VALUE = '1';

export const FEED_MAP = {
INBOX: false,
Expand Down Expand Up @@ -664,28 +666,34 @@ export class PushNotificationBaseClass {
let notificationSettingDescription = '';
for (let i = 0; i < configuration.length; i++) {
const ele = configuration[i];
if (ele.type == 0) {
if (ele.type == BOOLEAN_TYPE) {
notificationSetting =
notificationSetting +
SETTING_SEPARATOR +
ele.type +
BOOLEAN_TYPE +
SETTING_DELIMITER +
ele.default;
notificationSettingDescription =
notificationSettingDescription + SETTING_SEPARATOR + ele.description;
}
if (ele.type == 1) {
if (ele.data) {
const enabled = (ele.data && ele.data.enabled != undefined) ? Number(ele.data.enabled).toString() : DEFAULT_ENABLE_VALUE
const ticker = ele.data.ticker ?? DEFAULT_TICKER_VALUE
notificationSetting =
notificationSetting +
SETTING_SEPARATOR +
ele.type +
SLIDER_TYPE +
SETTING_DELIMITER+
enabled+
SETTING_DELIMITER +
ele.default +
SETTING_DELIMITER +
ele.data.lower +
SETTING_DELIMITER +
ele.data.upper;
ele.data.upper +
SETTING_DELIMITER+
ticker

notificationSettingDescription =
notificationSettingDescription +
Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/tests/lib/chat/send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CHAT } from '../../../src/lib/types/messageTypes';

chai.use(chaiAsPromised);
const _env = Constants.ENV.DEV;
describe.only('PushAPI.chat.send', () => {
describe('PushAPI.chat.send', () => {
const provider = ethers.getDefaultProvider(5);
let _signer1: any;
let walletAddress1: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/restapi/tests/lib/pushNotification/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('PushAPI.channel functionality', () => {
LOCAL = 'local',
}
// initialisation with signer and provider
userKate = await PushAPI.initialize(signer2)
userKate = await PushAPI.initialize(signer2, {env: ENV.DEV})
// initialisation with signer
userAlice = await PushAPI.initialize(signer2);
// TODO: remove signer1 after chat makes signer as optional
Expand Down Expand Up @@ -288,8 +288,8 @@ describe('PushAPI.channel functionality', () => {
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}}
{ type: 1, default: 1, description: 'My Notif Settings' },
{type: 2, default: 5, description: "My notif setting 2", data: {upper:100, lower:5, ticker: 10}}
]);
// console.log(res)
expect(res).not.null;
Expand Down
48 changes: 3 additions & 45 deletions packages/restapi/tests/lib/pushNotification/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,48 +202,6 @@ describe('PushAPI.notification functionality', () => {
// await userAlice.uploadToIPFSViaPushNode("test")
// })

// it('Should get proper minnimal payload', () => {
// const inputData = [
// {
// type: 0,
// default: 1,
// description: 'test1',
// },
// {
// type: 1,
// default: 10,
// description: 'test2',
// data: {
// upper: 100,
// lower: 1,
// },
// },
// ];

// const minimalSettings = userAlice.getMinimalSetting(inputData);
// console.log(minimalSettings);
// });

// it('Should get proper minnimal payload', () => {
// const inputData = [
// {
// type: 1,
// default: 10,
// description: 'test2',
// data: {
// upper: 100,
// lower: 1,
// },
// },
// {
// type: 0,
// default: 1,
// description: 'test1',
// },
// ];

// const minimalSettings = userAlice.getMinimalSetting(inputData);
// console.log(minimalSettings);
// });
// });
});

});
// });
114 changes: 114 additions & 0 deletions packages/restapi/tests/lib/pushNotification/onchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,120 @@
// console.log(addDelegate);
// });

// it.only('test with ethers', async () => {
// const account2 = await signer2.getAddress();
// const userEthers = new PushNotificationBaseClass(signer2, ENV.STAGING, account2,);
// const contract = userEthers.createContractInstance("0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C", config.ABIS.CORE, goerli)
// const res = await userEthers.fetchUpdateCounter(contract, account2);
// console.log(res)
// const ethersContract = await userEthers.createContractInstance(
// '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33',
// abi,
// goerli
// );
// const balance2 = await userEthers.fetchBalance(
// ethersContract,
// '0xD8634C39BBFd4033c0d3289C4515275102423681'
// );
// console.log(balance2);
// const allowance2 = await userEthers.fetchAllownace(
// ethersContract,
// '0xD8634C39BBFd4033c0d3289C4515275102423681',
// '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C'
// );
// console.log(allowance2);
// const approveAmount2 = ethers.BigNumber.from(10000);
// const approveRes2 = await userEthers.approveToken(
// ethersContract,
// '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C',
// approveAmount2
// );
// console.log(approveRes2);
// });
// it.only('Should get proper minnimal payload', async() => {
// const inputData = [
// {
// type: 0,
// default: 1,
// description: 'test1',
// },
// {
// type: 1,
// default: 10,
// description: 'test2',
// data: {
// upper: 100,
// lower: 1,

// ticker: 10
// },
// },
// ];
// const account2 = await signer2.getAddress();
// const userAlice = new PushNotificationBaseClass(signer2, ENV.STAGING, account2,);
// const minimalSettings = userAlice.getMinimalSetting(inputData);
// console.log(minimalSettings);
// });

// it.only('Should get proper minnimal payload', async() => {
// const inputData = [
// {
// type: 1,
// default: 10,
// description: 'test2',
// data: {
// upper: 100,
// lower: 1,
// enabled: false
// },
// },
// {
// type: 0,
// default: 1,
// description: 'test1',
// },
// ];
// const account2 = await signer2.getAddress();
// const userAlice = new PushNotificationBaseClass(signer2, ENV.STAGING, account2,);
// const minimalSettings = userAlice.getMinimalSetting(inputData);
// console.log(minimalSettings);
// });
// it('testing with viem', async () => {
// const account2 = await signer2.getAddress();
// const viemUser = new PushNotificationBaseClass(signer, ENV.STAGING, account2)
// const contract = viemUser.createContractInstance("0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C", config.ABIS.CORE, goerli)
// const res = await viemUser.fetchUpdateCounter(contract, account2);
// console.log(res)
// const viemContract = await userViem.createContractInstance(
// '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33',
// abi,
// goerli
// );
// const balance = await userViem.fetchBalance(
// viemContract,
// '0xD8634C39BBFd4033c0d3289C4515275102423681'
// );
// console.log(balance);
// const allowance = await userViem.fetchAllownace(
// viemContract,
// '0xD8634C39BBFd4033c0d3289C4515275102423681',
// '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C'
// );
// console.log(allowance);
// const approveAmount = ethers.BigNumber.from(10000);
// const approveRes = await userViem.approveToken(
// viemContract,
// '0xd4E3ceC407cD36d9e3767cD189ccCaFBF549202C',
// approveAmount
// );
// console.log(approveRes);

// const addDelegate = await userViem.delegate.add(
// 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );
// console.log(addDelegate);
// });

// it.only('test with ethers', async () => {
// const account2 = await signer2.getAddress();
// const userEthers = new PushNotificationBaseClass(signer2, ENV.STAGING, account2,);
Expand Down

0 comments on commit 118ea49

Please sign in to comment.