diff --git a/packages/restapi/src/lib/pushNotification/notification.ts b/packages/restapi/src/lib/pushNotification/notification.ts index 6e7b245c5..896ba3ee7 100644 --- a/packages/restapi/src/lib/pushNotification/notification.ts +++ b/packages/restapi/src/lib/pushNotification/notification.ts @@ -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!); @@ -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({ @@ -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); @@ -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( diff --git a/packages/restapi/tests/lib/notification/notification.test.ts b/packages/restapi/tests/lib/notification/notification.test.ts index 36a6f7b0b..208d28e6e 100644 --- a/packages/restapi/tests/lib/notification/notification.test.ts +++ b/packages/restapi/tests/lib/notification/notification.test.ts @@ -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', @@ -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 () => { @@ -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', () => {