diff --git a/packages/restapi/src/lib/channels/subscribe.ts b/packages/restapi/src/lib/channels/subscribe.ts index a99723472..00b6216f9 100644 --- a/packages/restapi/src/lib/channels/subscribe.ts +++ b/packages/restapi/src/lib/channels/subscribe.ts @@ -4,14 +4,15 @@ import { getDomainInformation, getSubscriptionMessage, } from './signature.helpers'; -import Constants, {ENV} from '../constants'; -import { SignerType } from "../types"; -import { axiosPost } from "../utils/axiosUtil"; +import Constants, { ENV } from '../constants'; +import { SignerType } from '../types'; +import { axiosPost } from '../utils/axiosUtil'; export type SubscribeOptionsType = { signer: SignerType; channelAddress: string; userAddress: string; verifyingContractAddress?: string; + origin?: string; env?: ENV; onSuccess?: () => void; onError?: (err: Error) => void; @@ -23,6 +24,7 @@ export const subscribe = async (options: SubscribeOptionsType) => { channelAddress, userAddress, verifyingContractAddress, + origin, env = Constants.ENV.PROD, onSuccess, onError, @@ -86,6 +88,7 @@ export const subscribe = async (options: SubscribeOptionsType) => { channel: _channelAddress, subscriber: _userAddress, }, + origin: origin }; await axiosPost(requestUrl, body); diff --git a/packages/restapi/src/lib/channels/subscribeV2.ts b/packages/restapi/src/lib/channels/subscribeV2.ts index e37188c10..c38fdc456 100644 --- a/packages/restapi/src/lib/channels/subscribeV2.ts +++ b/packages/restapi/src/lib/channels/subscribeV2.ts @@ -15,6 +15,7 @@ export type SubscribeOptionsV2Type = { settings?: string | null; verifyingContractAddress?: string; env?: ENV; + origin?: string; onSuccess?: () => void; onError?: (err: Error) => void; }; @@ -27,6 +28,7 @@ export const subscribeV2 = async (options: SubscribeOptionsV2Type) => { settings = undefined, verifyingContractAddress, env = Constants.ENV.PROD, + origin, onSuccess, onError, } = options || {}; @@ -85,6 +87,7 @@ export const subscribeV2 = async (options: SubscribeOptionsV2Type) => { const body = { verificationProof: `eip712v2:${verificationProof}`, message: messageInformation.data, + origin: origin }; const res = await axiosPost(requestUrl, body); diff --git a/packages/restapi/src/lib/pushNotification/notification.ts b/packages/restapi/src/lib/pushNotification/notification.ts index c1e5a1438..6e7b245c5 100644 --- a/packages/restapi/src/lib/pushNotification/notification.ts +++ b/packages/restapi/src/lib/pushNotification/notification.ts @@ -14,6 +14,7 @@ import { getCAIPWithChainId, validateCAIP, getFallbackETHCAIPAddress, + pCAIP10ToWallet, } from '../helpers'; import { PushNotificationBaseClass } from './pushNotificationBase'; @@ -50,11 +51,16 @@ export class Notification extends PushNotificationBaseClass { raw = false, } = options || {}; try { - const account = options?.account - ? options.account - : this.account - ? getFallbackETHCAIPAddress(this.env!, this.account!) - : null; + let account: string | null; + if (options?.account) { + if (this.isValidPCaip(options.account)) { + account = pCAIP10ToWallet(options.account); + } else { + account = options.account; + } + } else if(this.account){ + account = getFallbackETHCAIPAddress(this.env!, this.account!) + } // guest mode and valid address check this.checkUserAddressExists(account!); const nonCaipAccount = this.getAddressFromCaip(account!); @@ -99,11 +105,16 @@ export class Notification extends PushNotificationBaseClass { channel = null, raw, } = options || {}; - const account = options?.account - ? options.account - : this.account - ? getFallbackETHCAIPAddress(this.env!, this.account!) - : null; + let account: string | null; + if (options?.account) { + if (this.isValidPCaip(options.account)) { + account = pCAIP10ToWallet(options.account); + } else { + account = options.account; + } + } else if(this.account){ + account = getFallbackETHCAIPAddress(this.env!, this.account!) + } this.checkUserAddressExists(account!); return await PUSH_USER.getSubscriptions({ user: account!, diff --git a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts index 7fe081696..1e8f1bbde 100644 --- a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts +++ b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts @@ -33,6 +33,8 @@ import { import { axiosGet, axiosPost } from '../utils/axiosUtil'; import { PushAPI } from '../pushapi/PushAPI'; import { channel } from 'diagnostics_channel'; +import * as viem from 'viem'; + // ERROR CONSTANTS const ERROR_ACCOUNT_NEEDED = 'Account is required'; @@ -843,7 +845,7 @@ export class PushNotificationBaseClass { throw new Error('Signer is not provided'); } const pushSigner = new Signer(this.signer); - let addAliasRes + let addAliasRes; if (!pushSigner.isViemSigner(this.signer)) { if (!this.signer.provider) { throw new Error('ethers provider is not provided'); @@ -875,12 +877,13 @@ export class PushNotificationBaseClass { throw new Error('Signer is not provided'); } const pushSigner = new Signer(this.signer); - let verifyAliasRes + let verifyAliasRes; if (!pushSigner.isViemSigner(this.signer)) { if (!this.signer.provider) { throw new Error('ethers provider is not provided'); } - const addAliasTrxPromise = contract!['verifyChannelAlias'](channelAddress); + const addAliasTrxPromise = + contract!['verifyChannelAlias'](channelAddress); const addAliasTrx = await addAliasTrxPromise; await this.signer?.provider?.waitForTransaction(addAliasTrx.hash); verifyAliasRes = addAliasTrx.hash; @@ -926,4 +929,13 @@ export class PushNotificationBaseClass { protected getAddressFromCaip(caipAddress: string): string { return caipAddress?.split(':')[caipAddress?.split(':').length - 1]; } + + protected isValidPCaip(address: string): boolean { + const addressComponents = address.split(':'); + return ( + addressComponents.length == 2 && + addressComponents[0] == 'eip155' && + viem.isAddress(addressComponents[1]) + ); + } } diff --git a/packages/restapi/src/lib/pushapi/PushAPI.ts b/packages/restapi/src/lib/pushapi/PushAPI.ts index e0bd220c7..a071234f1 100644 --- a/packages/restapi/src/lib/pushapi/PushAPI.ts +++ b/packages/restapi/src/lib/pushapi/PushAPI.ts @@ -28,6 +28,7 @@ export class PushAPI { private readMode: boolean; private alpha: { feature: string[] }; public account: string; + public chainWiseAccount: string; public decryptedPgpPvtKey?: string; public pgpPublicKey?: string; public env: ENV; @@ -65,6 +66,7 @@ export class PushAPI { this.alpha = alpha; this.env = env; this.account = account; + this.chainWiseAccount = walletToPCAIP10(account); this.decryptedPgpPvtKey = decryptedPgpPvtKey; this.pgpPublicKey = pgpPublicKey; this.progressHook = progressHook; @@ -274,7 +276,6 @@ export class PushAPI { readMode = true; } } - derivedAccount = walletToPCAIP10(derivedAccount); // Initialize PushAPI instance const api = new PushAPI( settings.env as ENV, diff --git a/packages/restapi/tests/lib/channel/subscribeV2.test.ts b/packages/restapi/tests/lib/channel/subscribeV2.test.ts index ba5453c85..ef2c9cb03 100644 --- a/packages/restapi/tests/lib/channel/subscribeV2.test.ts +++ b/packages/restapi/tests/lib/channel/subscribeV2.test.ts @@ -30,6 +30,7 @@ describe('PUSH_CHANNEL.subscribeV2 functionality', () => { channelAddress: 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681', userAddress: `eip155:11155111:${account1}`, env: _env, + origin: 'test' }); expect(res.status).to.be.equal(204); }); diff --git a/packages/restapi/tests/lib/notification/notification.test.ts b/packages/restapi/tests/lib/notification/notification.test.ts index 9e98fb390..36a6f7b0b 100644 --- a/packages/restapi/tests/lib/notification/notification.test.ts +++ b/packages/restapi/tests/lib/notification/notification.test.ts @@ -89,6 +89,15 @@ 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', + }); + // console.log(response) + expect(response).not.null; + }); + it('Should return feeds when viem is used', async () => { const response = await userViem.notification.list('SPAM'); // console.log(response); @@ -267,11 +276,18 @@ describe('PushAPI.notification functionality', () => { expect(response.length).not.equal(0); }); + it('Signer with account: Should return response', async () => { + const response = await userKate.notification.subscriptions({ + account: 'eip155:0xD8634C39BBFd4033c0d3289C4515275102423681', + }); + expect(response).not.null; + expect(response.length).not.equal(0); + }); + it('Signer with account: Should return response', async () => { const response = await userKate.notification.subscriptions({ account: '0xD8634C39BBFd4033c0d3289C4515275102423681', }); - // console.log(JSON.stringify(response)); expect(response).not.null; expect(response.length).not.equal(0); }); @@ -282,7 +298,6 @@ describe('PushAPI.notification functionality', () => { raw: false, channel: '0xD8634C39BBFd4033c0d3289C4515275102423681', }); - console.log(JSON.stringify(response)); expect(response).not.null; }); }); diff --git a/packages/uiweb/src/lib/components/notification/index.tsx b/packages/uiweb/src/lib/components/notification/index.tsx index 565347d2f..1f0e6767b 100644 --- a/packages/uiweb/src/lib/components/notification/index.tsx +++ b/packages/uiweb/src/lib/components/notification/index.tsx @@ -2,11 +2,7 @@ import * as PropTypes from 'prop-types'; import * as React from 'react'; import styled, { css } from 'styled-components'; -import { - MediaHelper, - convertTimeStamp, - extractTimeStamp, -} from '../../utilities'; +import { MediaHelper, convertTimeStamp, extractTimeStamp } from '../../utilities'; import IPFSIcon from '../ipfsicon'; import Loader from '../loader/loader'; import ImageOverlayComponent from '../overlay'; @@ -15,12 +11,17 @@ import chainDetails from './chainDetails'; import { DecryptButton, useDecrypt } from './decrypt'; import ActionButton from './styled/ActionButton'; -import { useDivOffsetWidth } from "../../hooks"; -import { LinkIcon } from "../../icons/Link"; +import { useDivOffsetWidth } from '../../hooks'; +import { LinkIcon } from '../../icons/Link'; import type { INotificationItemTheme } from './theme'; import { getCustomTheme } from './theme'; -export { baseTheme as notificationBaseTheme, darkTheme as notificationDarkTheme, lightTheme as notificationLightTheme, type INotificationItemTheme } from './theme'; +export { + baseTheme as notificationBaseTheme, + darkTheme as notificationDarkTheme, + lightTheme as notificationLightTheme, + type INotificationItemTheme, +} from './theme'; // ================= Define types export type chainNameType = @@ -67,7 +68,7 @@ export type NotificationItemProps = { type ContainerDataType = { timestamp?: string; -}& OffsetWidthType; +} & OffsetWidthType; type OffsetWidthType = { offsetWidth: number; }; @@ -103,20 +104,13 @@ export const NotificationItem: React.FC = ({ isSecret, decryptFn, }) => { - const { notificationBody: parsedBody, timeStamp } = extractTimeStamp( - notificationBody || '' - ); - const themeObject = getCustomTheme(theme,customTheme!); - + const { notificationBody: parsedBody, timeStamp } = extractTimeStamp(notificationBody || ''); + const themeObject = getCustomTheme(theme, customTheme!); - const { - notifTitle, - notifBody, - notifCta, - notifImage, - setDecryptedValues, - isSecretRevealed, - } = useDecrypt({ notificationTitle, parsedBody, cta, image }, isSecret); + const { notifTitle, notifBody, notifCta, notifImage, setDecryptedValues, isSecretRevealed } = useDecrypt( + { notificationTitle, parsedBody, cta, image }, + isSecret + ); const isCtaURLValid = MediaHelper.validURL(notifCta); const isChannelURLValid = MediaHelper.validURL(url); @@ -126,7 +120,7 @@ export const NotificationItem: React.FC = ({ const [subscribeLoading, setSubscribeLoading] = React.useState(false); const [isSubscribed, setIsSubscribed] = React.useState(true); //use this to confirm if this is s const [divRef, offsetWidth] = useDivOffsetWidth(); - + const showMetaInfo = isSecret || timeStamp; // console.log({ // chainName, @@ -190,7 +184,6 @@ export const NotificationItem: React.FC = ({ return ( = ({ {/* header that only pops up on small devices */} - - + + {app} {chainName && chainDetails[chainName] ? ( - {chainDetails[chainName].icon} + {chainDetails[chainName].icon} ) : null} {/* header that only pops up on small devices */} {/* content of the component */} - + {/* section for media content */} {notifImage && // if its an image then render this (!MediaHelper.isMediaSupportedVideo(notifImage) ? ( setImageOverlay(notifImage || '')} > - + ) : // if its a youtube url, RENDER THIS MediaHelper.isMediaYoutube(notifImage) ? ( - +