Skip to content

Commit

Permalink
fix: Merge branch 'main' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Nov 28, 2023
2 parents 0ca7c59 + 0145aed commit 429132c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 65 deletions.
7 changes: 6 additions & 1 deletion packages/restapi/src/lib/channels/getSubscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type GetChannelSubscribersOptionsType = {
channel: string; // plain ETH Format only
page?: number,
limit?: number,
category?: number,
env?: ENV
}

Expand All @@ -28,6 +29,7 @@ export const getSubscribers = async (
channel,
page = 1,
limit = 10,
category,
env = Constants.ENV.PROD,
} = options || {};

Expand All @@ -49,7 +51,10 @@ export const getSubscribers = async (
}
const _channel = await getCAIPAddress(env, channel, 'Channel');
const API_BASE_URL = getAPIBaseUrls(env);
const apiEndpoint = `${API_BASE_URL}/v1/channels/${_channel}/subscribers?page=${page}&limit=${limit}`;
let apiEndpoint = `${API_BASE_URL}/v1/channels/${_channel}/subscribers?page=${page}&limit=${limit}`;
if(category){
apiEndpoint = apiEndpoint+`&category=${category}`
}
return await axios.get(apiEndpoint)
.then((response) => response.data)
.catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ChannelInfoOptions = {
channel?: string;
page?: number;
limit?: number;
category?: number
};

export type SubscribeUnsubscribeOptions = {
Expand Down
1 change: 1 addition & 0 deletions packages/restapi/src/lib/pushNotification/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class Channel extends PushNotificationBaseClass {
env: this.env,
page: options.page,
limit: options.limit ?? 10,
category: options.category
});
} else {
/** @dev - Fallback to deprecated method when page is not provided ( to ensure backward compatibility ) */
Expand Down
39 changes: 24 additions & 15 deletions packages/restapi/src/lib/pushNotification/pushNotificationBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,6 @@ export class PushNotificationBaseClass {
BOOLEAN_TYPE +
SETTING_DELIMITER +
ele.default;
notificationSettingDescription =
notificationSettingDescription + SETTING_SEPARATOR + ele.description;
}
if (ele.type == SLIDER_TYPE) {
if (ele.data) {
Expand All @@ -717,11 +715,6 @@ export class PushNotificationBaseClass {
ele.data.upper +
SETTING_DELIMITER +
ticker;

notificationSettingDescription =
notificationSettingDescription +
SETTING_SEPARATOR +
ele.description;
}
}
if (ele.type == RANGE_TYPE) {
Expand Down Expand Up @@ -749,6 +742,9 @@ export class PushNotificationBaseClass {
ticker;
}
}

notificationSettingDescription =
notificationSettingDescription + SETTING_SEPARATOR + ele.description;
}
return {
setting: notificationSetting.replace(/^\+/, ''),
Expand All @@ -766,15 +762,28 @@ export class PushNotificationBaseClass {
const ele = setting[i];
const enabled = ele.enabled ? 1 : 0;
if (ele.enabled) numberOfSettings++;
// slider type

if (Object.keys(ele).includes('value')) {
userSetting =
userSetting +
SLIDER_TYPE +
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.value;
// slider type
if (typeof ele.value == 'number')
userSetting =
userSetting +
SLIDER_TYPE +
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.value;
else {
userSetting =
userSetting +
RANGE_TYPE +
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.value?.lower +
SETTING_DELIMITER +
ele.value?.upper;
}
} else {
// boolean type
userSetting = userSetting + BOOLEAN_TYPE + SETTING_DELIMITER + enabled;
Expand Down
40 changes: 21 additions & 19 deletions packages/restapi/tests/lib/notification/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,41 @@ enum ENV {
LOCAL = 'local',
}
describe.only('test', () => {
const signer = createWalletClient({
account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
chain: goerli,
transport: http('https://goerli.blockpi.network/v1/rpc/public'),
});
// const signer = createWalletClient({
// account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
// chain: goerli,
// transport: http('https://goerli.blockpi.network/v1/rpc/public'),
// });

const signer3 = createWalletClient({
account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
chain: polygonMumbai,
transport: http(),
});
// const signer3 = createWalletClient({
// account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
// chain: polygonMumbai,
// transport: http(),
// });

const provider = new ethers.providers.JsonRpcProvider(
'https://goerli.blockpi.network/v1/rpc/public'
);
const signer2 = new ethers.Wallet(
`0x${process.env['WALLET_PRIVATE_KEY']}`,
provider
);
// const provider = new ethers.providers.JsonRpcProvider(
// 'https://goerli.blockpi.network/v1/rpc/public'
// );
// const signer2 = new ethers.Wallet(
// `0x${process.env['WALLET_PRIVATE_KEY']}`,
// provider
// );

// it.only('Test minimal conversion', async () => {
// it('Test minimal conversion', async () => {
// const account2 = await signer2.getAddress();
// const viemUser = new PushNotificationBaseClass(
// signer,
// ENV.STAGING,
// account2
// );
// viemUser.getMinimalUserSetting([
// const res = viemUser.getMinimalUserSetting([
// { enabled: true },
// { enabled: false, value: 10 },
// { enabled: false },
// { enabled: true, value: 10 },
// {enabled: true, value: {lower:10, upper:100}}
// ]);
// console.log(res)
// });
// it('testing with viem', async () => {
// const account2 = await signer2.getAddress();
Expand Down
48 changes: 44 additions & 4 deletions packages/restapi/tests/lib/notification/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ describe('PushAPI.channel functionality', () => {
expect(res).not.null;
});

it('Without signer and account : Should return response without passing the options', async () => {
const res = await userKate.channel.subscribers({page:1, limit:10, category:2});
expect(res).not.null;
});

it('Without signer and account : Should throw error for invalid caip', async () => {
await expect(() =>
userBob.channel.subscribers({
Expand Down Expand Up @@ -380,13 +385,48 @@ describe('PushAPI.channel functionality', () => {
describe('channel :: settings', () => {
it('Should create channel', async () => {
const res = await userKate.channel.setting([
{
type: 1,
default: 1,
description: 'test1',
},
{
type: 2,
default: 5,
description: 'My notif setting 2',
data: { upper: 100, lower: 5, ticker: 10, enabled: true },
default: 10,
description: 'test2',
data: {
upper: 100,
lower: 1,
},
},
{
type: 3,
default: {
lower: 10,
upper: 50,
},
description: 'test3',
data: {
upper: 100,
lower: 1,
enabled: true,
ticker: 2,
},
},
{
type: 3,
default: {
lower: 3,
upper: 5,
},
description: 'test4',
data: {
upper: 100,
lower: 1,
enabled: false,
ticker: 2,
},
},
{ type: 1, default: 1, description: 'My Notif Settings' },
]);
// console.log(res)
expect(res).not.null;
Expand Down
98 changes: 72 additions & 26 deletions packages/restapi/tests/lib/notification/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,37 @@ describe('PushAPI.notification functionality', () => {
let userViem: PushAPI;
beforeEach(async () => {
signer1 = new ethers.Wallet(
`0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}`
`0x${process.env['WALLET_PRIVATE_KEY']}`
);
account1 = await signer1.getAddress();

const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.sepolia.org'
);

signer2 = new ethers.Wallet(
`0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}`,
`0x${process.env['WALLET_PRIVATE_KEY']}`,
provider
);
account2 = await signer2.getAddress();
viemSigner = createWalletClient({
account: privateKeyToAccount(
`0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}`
`0x${process.env['WALLET_PRIVATE_KEY']}`
),
chain: sepolia,
transport: http(),
});
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);
userKate = await PushAPI.initialize(signer2, {env:ENV.DEV});
// initialisation with signer
userAlice = await PushAPI.initialize(signer1);
// TODO: remove signer1 after signer becomes optional
Expand Down Expand Up @@ -100,23 +109,23 @@ describe('PushAPI.notification functionality', () => {

describe('notification :: subscribe', () => {
beforeEach(async () => {
await userAlice.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// await userAlice.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );

await userKate.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
});
// await userKate.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );
// });

afterEach(async () => {
await userAlice.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// afterEach(async () => {
// await userAlice.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );

await userKate.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// await userKate.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );
});
it.skip('Without signer object: should throw error', async () => {
await expect(() =>
Expand All @@ -136,13 +145,17 @@ describe('PushAPI.notification functionality', () => {

it('With signer object: Should subscribe', async () => {
const res = await userAlice.notification.subscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681', {
settings: [{
enabled: false
},{
enabled: false,
value: 0
}, ]
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681',
{
settings: [
{
enabled: false,
},
{
enabled: false,
value: 0,
},
],
}
);
// console.log(res)
Expand All @@ -157,6 +170,39 @@ describe('PushAPI.notification functionality', () => {
expect(res).not.null;
});

it('With signer and provider: Should subscribe', async () => {
const res = await userKate.notification.subscribe(
'eip155:11155111:0xC8c243a4fd7F34c49901fe441958953402b7C024',
{
settings: [
{
enabled: false,
},
{
enabled: true,
value: 15,
},
{
enabled: true,
value: {
lower: 5,
upper: 10,
},
},
{
enabled: true,
value: {
lower: 5,
upper: 10,
},
},
],
}
);
console.log(res)
expect(res).not.null;
});

it('With viem signer and provider: Should subscribe', async () => {
const res = await userViem.notification.subscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
Expand Down

0 comments on commit 429132c

Please sign in to comment.