Skip to content

Commit

Permalink
fix: fixed issue with pcaip and no caip in optin and optout
Browse files Browse the repository at this point in the history
  • Loading branch information
akp111 committed May 10, 2024
1 parent 07c4603 commit a7d42d6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
20 changes: 14 additions & 6 deletions packages/restapi/src/lib/pushNotification/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export class Notification extends PushNotificationBaseClass {
} else {
account = options.account;
}
} else if(this.account){
account = getFallbackETHCAIPAddress(this.env!, this.account!)
} else if (this.account) {
account = getFallbackETHCAIPAddress(this.env!, this.account!);
}
// guest mode and valid address check
this.checkUserAddressExists(account!);
Expand Down Expand Up @@ -112,8 +112,8 @@ export class Notification extends PushNotificationBaseClass {
} else {
account = options.account;
}
} else if(this.account){
account = getFallbackETHCAIPAddress(this.env!, this.account!)
} else if (this.account) {
account = getFallbackETHCAIPAddress(this.env!, this.account!);
}
this.checkUserAddressExists(account!);
return await PUSH_USER.getSubscriptions({
Expand Down Expand Up @@ -150,9 +150,13 @@ export class Notification extends PushNotificationBaseClass {
if (!channel && channel != '') {
throw new Error(ERROR_CHANNEL_NEEDED);
}
// convert normal partial caip to wallet
if (this.isValidPCaip(channel)) {
channel = pCAIP10ToWallet(channel);
}
// validates if caip is correct
if (!validateCAIP(channel)) {
throw new Error(ERROR_INVALID_CAIP);
channel = getFallbackETHCAIPAddress(this.env!, channel);
}
// get channel caip
const caipDetail = getCAIPDetails(channel);
Expand Down Expand Up @@ -201,9 +205,13 @@ export class Notification extends PushNotificationBaseClass {
if (!channel && channel != '') {
return new Error(ERROR_CHANNEL_NEEDED);
}
// covert partial caip to normal wallet
if (this.isValidPCaip(channel)) {
channel = pCAIP10ToWallet(channel);
}
// validates if caip is correct
if (!validateCAIP(channel)) {
return new Error(ERROR_INVALID_CAIP);
channel = getFallbackETHCAIPAddress(this.env!, channel);
}
const caipDetail = getCAIPDetails(channel);
const userAddressInCaip = getCAIPWithChainId(
Expand Down
29 changes: 22 additions & 7 deletions packages/restapi/tests/lib/notification/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ describe('PushAPI.notification functionality', () => {
expect(response).not.null;
});


it('Should return feeds when signer with provider is used', async () => {
const response = await userKate.notification.list('SPAM', {
account: 'eip155:0xD8634C39BBFd4033c0d3289C4515275102423681',
Expand Down Expand Up @@ -166,12 +165,20 @@ describe('PushAPI.notification functionality', () => {
).to.Throw;
});

it.skip('With signer object: should throw error for invalid channel caip', async () => {
await expect(() => {
userAlice.notification.subscribe(
'0xD8634C39BBFd4033c0d3289C4515275102423681'
);
}).to.Throw;
it('With signer object: should convert to eth caip for normal address', async () => {
const res = await userKate.notification.subscribe(
'0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// console.log(res);
expect(res).not.null;
});

it('With signer object: should optin with partial caip', async () => {
const res = await userKate.notification.subscribe(
'eip155:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// console.log(res);
expect(res).not.null;
});

it('With signer object: Should subscribe', async () => {
Expand Down Expand Up @@ -247,6 +254,14 @@ describe('PushAPI.notification functionality', () => {
);
expect(res.message).to.equal('successfully opted out channel');
});

it('With signer object: should convert to eth caip for normal address', async () => {
const res = await userKate.notification.unsubscribe(
'0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// console.log(res);
expect(res).not.null;
});
});

describe('notification :: subscriptions', () => {
Expand Down

0 comments on commit a7d42d6

Please sign in to comment.