diff --git a/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx b/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx index d2c2501f6..72f09c750 100644 --- a/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx +++ b/packages/examples/sdk-frontend-react/src/app/ChatUITest/ChatViewComponent.tsx @@ -20,7 +20,7 @@ const ChatViewComponentTest = () => { console.log("Verification Failed")} - chatId='bd01307fa75e738842b474e0c0aa00385e9aa886ebd33ed246182141f377be5f' + chatId='0x56A734ba4C7c7b117774C9aAcCEf521eBE66d65b' chatProfileLeftHelperComponent={console.debug('clicked')}/>} chatProfileRightHelperComponent={
right component
} diff --git a/packages/examples/sdk-frontend-react/src/app/ListChannelsTest.tsx b/packages/examples/sdk-frontend-react/src/app/ListChannelsTest.tsx new file mode 100644 index 000000000..1eaff946f --- /dev/null +++ b/packages/examples/sdk-frontend-react/src/app/ListChannelsTest.tsx @@ -0,0 +1,140 @@ +import * as PushAPI from '@pushprotocol/restapi'; +import { CONSTANTS } from '@pushprotocol/restapi'; +import React, { useContext, useEffect, useState } from 'react'; +import Loader from './components/Loader'; +import { + CodeFormatter, + Section, + SectionButton, + SectionItem, +} from './components/StyledComponents'; +import { EnvContext, Web3Context } from './context'; + +import { getCAIPAddress } from './helpers'; + +const ChannelsTest = () => { + const { library, account, chainId } = useContext(Web3Context); + const { env, isCAIP } = useContext(EnvContext); + + const [isLoading, setLoading] = useState(false); + + const [page, setPage] = useState(1); + const [limit, setLimit] = useState(10); + const [sort, setSort] = useState(CONSTANTS.FILTER.CHANNEL_LIST.SORT.SUBSCRIBER); + const [order, setOrder] = useState(CONSTANTS.FILTER.CHANNEL_LIST.ORDER.DESCENDING); + + const [channelListData, setChannelListData] = useState(); + + const updatePage = (e: React.SyntheticEvent) => { + setPage(parseInt((e.target as HTMLInputElement).value)); + }; + + const updateLimit = (e: React.SyntheticEvent) => { + setLimit(parseInt((e.target as HTMLInputElement).value)); + }; + + const updateSort = (e: React.SyntheticEvent) => { + setSort((e.target as HTMLInputElement).value); + }; + + const updateOrder = (e: React.SyntheticEvent) => { + setOrder((e.target as HTMLInputElement).value); + }; + + const testGetChannelByAddress = async () => { + try { + setLoading(true); + + // object for channel data + const response = await PushAPI.channels.getChannels({ + env: env, + page: page, + limit: limit, + sort: sort, + order: order, + }); + + setChannelListData(response); + } catch (e) { + console.error(e); + } finally { + setLoading(false); + } + }; + + + + return ( +
+

List Channels Test page

+ + + +
+
+ + + + +
+ + + + + + + + + + + + + + + + +
+ + Get Channels List + +
+
+ +
+ {channelListData ? ( + + {JSON.stringify(channelListData, null, 4)} + + ) : null} +
+
+
+ ); +}; + +export default ChannelsTest; diff --git a/packages/examples/sdk-frontend-react/src/app/app.tsx b/packages/examples/sdk-frontend-react/src/app/app.tsx index 8579dbbd0..a021edfba 100644 --- a/packages/examples/sdk-frontend-react/src/app/app.tsx +++ b/packages/examples/sdk-frontend-react/src/app/app.tsx @@ -1,9 +1,9 @@ import { useWeb3React } from '@web3-react/core'; import { - Web3Context, + AccountContext, EnvContext, SocketContext, - AccountContext, + Web3Context, } from './context'; import { Buffer } from 'buffer'; @@ -33,8 +33,10 @@ import RemoveMembersFromGroupTest from './ChatTest/RemoveMembersFromGroupTest'; import SendMessageTest from './ChatTest/SendMessageTest'; import UpdateGroupTest from './ChatTest/UpdateGroupTest'; import UpdateUserProfile from './ChatTest/UpdateUserProfile'; +import { ChatWidgetTest } from './ChatWidgetTest'; import DelegationTest from './DelegationTest'; import EmbedTest from './EmbedTest'; +import ListChannelsTest from './ListChannelsTest'; import NotificationsTest from './NotificationsTest'; import PayloadsTest from './PayloadsTest'; import SecretNotificationsTest from './SecretNotificationsTest'; @@ -55,18 +57,17 @@ import SpaceTest from './SpaceTest/SpaceTest'; import StartSpaceTest from './SpaceTest/StartSpaceTest'; import StopSpaceTest from './SpaceTest/StopSpaceTest'; import UpdateSpaceTest from './SpaceTest/UpdateSpaceTest'; -import { Checkbox } from './components/Checkbox'; -import ConnectButtonComp from './components/Connect'; -import Dropdown from './components/Dropdown'; import { - SpaceWidget, + CreateSpaceComponent, SpaceBanner, SpaceFeed, - CreateSpaceComponent, SpaceInvitesComponent, + SpaceWidget, } from './SpaceUITest'; import { useSpaceComponents } from './SpaceUITest/useSpaceComponents'; -import { ChatWidgetTest } from './ChatWidgetTest'; +import { Checkbox } from './components/Checkbox'; +import ConnectButtonComp from './components/Connect'; +import Dropdown from './components/Dropdown'; import { ENV } from './helpers'; import { useSDKSocket } from './hooks'; @@ -80,8 +81,8 @@ import { WidgetUIProvider, darkChatTheme, darkWidgetTheme, - lightWidgetTheme, lightChatTheme, + lightWidgetTheme, } from '@pushprotocol/uiweb'; import { ChatSupportTest } from './ChatSupportTest'; import GetGroupMemberStatusTest from './ChatTest/GetGroupMemberStatusTest'; @@ -96,13 +97,13 @@ import ChatViewComponentTest from './ChatUITest/ChatViewComponent'; import ChatViewListTest from './ChatUITest/ChatViewListTest'; import SearchSpaceTest from './SpaceTest/SearchSpaceTest'; -import SpaceUITest from './SpaceUITest/SpaceUITest'; -import GetGroupMemberCountTest from './ChatTest/GetGroupMemberCountTest'; import GetGroupInfoTest from './ChatTest/GetGroupInfoTest'; +import GetGroupMemberCountTest from './ChatTest/GetGroupMemberCountTest'; import GetGroupMembersTest from './ChatTest/GetGroupMembersTest'; +import SpaceUITest from './SpaceUITest/SpaceUITest'; import VideoV2 from './Video'; -import Widget from './widget/Widget'; import { SubscriptionManagerTest } from './widget/SubscriptionManagerTest'; +import Widget from './widget/Widget'; // import { SubscriptionManagerTest } from './widget/SubscriptionManagerTest'; import { UserProfileTest } from './ChatUITest/UserProfileTest'; @@ -361,6 +362,9 @@ export function App() { CHANNELS + + LIST CHANNELS + ALIAS @@ -406,6 +410,7 @@ export function App() { element={} /> } /> + } /> } /> { + const { + env = CONSTANTS.ENV.PROD, + page = 1, + limit = 10, + sort = CONSTANTS.FILTER.CHANNEL_LIST.SORT.SUBSCRIBER, + order = CONSTANTS.FILTER.CHANNEL_LIST.ORDER.DESCENDING, + } = options || {}; + + const API_BASE_URL = getAPIBaseUrls(env); + const apiEndpoint = `${API_BASE_URL}/v1/channels`; + const requestUrl = `${apiEndpoint}?page=${page}&limit=${limit}&sort=${sort}&order=${order}`; + + return await axiosGet(requestUrl) + .then((response) => { + return response.data; + }) + .catch((err) => { + console.error(`[Push SDK] - API ${requestUrl}: `, err); + throw Error(`[Push SDK] - API - Error - API ${requestUrl} -: ${err}`); + }); +}; diff --git a/packages/restapi/src/lib/channels/index.ts b/packages/restapi/src/lib/channels/index.ts index c5431857a..8728fc02a 100644 --- a/packages/restapi/src/lib/channels/index.ts +++ b/packages/restapi/src/lib/channels/index.ts @@ -1,10 +1,12 @@ +export * from './_getSubscribers'; export * from './getChannel'; +export * from './getChannelNotifications'; +export * from './getChannels'; export * from './getDelegates'; +export * from './getSubscribers'; export * from './search'; export * from './subscribe'; -export * from './unsubscribe'; -export * from './_getSubscribers'; -export * from './getSubscribers'; export * from './subscribeV2'; +export * from './unsubscribe'; export * from './unsubscribeV2'; -export * from './getChannelNotifications'; + diff --git a/packages/restapi/src/lib/constantsV2.ts b/packages/restapi/src/lib/constantsV2.ts index f58fa8dfd..a1c98d81e 100644 --- a/packages/restapi/src/lib/constantsV2.ts +++ b/packages/restapi/src/lib/constantsV2.ts @@ -1,4 +1,5 @@ -import { ENV, MessageType, ALPHA_FEATURES, ENCRYPTION_TYPE } from './constants'; +import { ALPHA_FEATURES, ENCRYPTION_TYPE, ENV, MessageType } from './constants'; +import { ChannelListOrderType, ChannelListSortType, ChannelListType } from './pushNotification/PushNotificationTypes'; import { ChatListType } from './pushapi/pushAPITypes'; import { STREAM, SpaceEventType, VideoEventType } from './pushstream/pushStreamTypes'; import { initSpaceData } from './space'; @@ -48,6 +49,15 @@ const CONSTANTS = { BROADCAST: 1, SUBSET: 4, TARGETTED: 3 + }, + CHANNEL: { + LIST_TYPE: ChannelListType, + } + }, + FILTER: { + CHANNEL_LIST: { + SORT: ChannelListSortType, + ORDER: ChannelListOrderType } } }; diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index dbdab6063..9eca06d8e 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -1,6 +1,6 @@ -import { NotifictaionType, ProgressHookType } from '../types'; -import { GetAliasInfoOptionsType } from '../alias'; import { ADDITIONAL_META_TYPE } from '../../lib/payloads/constants'; +import { GetAliasInfoOptionsType } from '../alias'; +import { NotifictaionType, ProgressHookType } from '../types'; export type SubscriptionOptions = { account?: string; @@ -126,3 +126,25 @@ export type ChannelFeedsOptions = { export type ChannelOptions = { raw: boolean } + +export type ChannelListOptions = { + page?: number; + limit?: number; + sort?: ChannelListSortType; + order?: ChannelListOrderType; +}; + +export enum ChannelListType { + ALL = 'all', + VERIFIED = 'verified', + UNVERIFIED = 'unverified', +}; + +export enum ChannelListSortType { + SUBSCRIBER = 'subscribers', +}; + +export enum ChannelListOrderType { + ASCENDING = 'asc', + DESCENDING = 'desc', +}; \ No newline at end of file diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index 762a563a5..abe037cd1 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -1,33 +1,37 @@ import Constants, { ENV } from '../constants'; + +import * as viem from 'viem'; +import * as PUSH_CHANNEL from '../channels'; +import * as config from '../config'; +import { + getCAIPDetails, + getFallbackETHCAIPAddress, + pCAIP10ToWallet, + validateCAIP, +} from '../helpers'; +import * as PUSH_PAYLOAD from '../payloads'; +import PROGRESSHOOK from '../progressHook'; import { - SignerType, ProgressHookType, ProgressHookTypeFunction, + SignerType, } from '../types'; import { + ChannelFeedsOptions, ChannelInfoOptions, + ChannelListOptions, + ChannelListOrderType, + ChannelListSortType, + ChannelOptions, ChannelSearchOptions, - NotificationOptions, CreateChannelOptions, - NotificationSettings, - ChannelFeedsOptions, - ChannelOptions + NotificationOptions, + NotificationSettings } from './PushNotificationTypes'; -import * as config from '../config'; -import * as PUSH_PAYLOAD from '../payloads'; -import * as PUSH_CHANNEL from '../channels'; -import { - getCAIPDetails, - validateCAIP, - getFallbackETHCAIPAddress, - pCAIP10ToWallet, -} from '../helpers'; -import PROGRESSHOOK from '../progressHook'; -import * as viem from 'viem'; -import { PushNotificationBaseClass } from './pushNotificationBase'; -import { Delegate } from './delegate'; import { Alias } from './alias'; +import { Delegate } from './delegate'; +import { PushNotificationBaseClass } from './pushNotificationBase'; export class Channel extends PushNotificationBaseClass { public delegate!: Delegate; @@ -432,10 +436,30 @@ export class Channel extends PushNotificationBaseClass { page, limit }) - - }catch(error){ + } catch(error){ throw new Error(`Push SDK Error: Contract : channel::notifications : ${error}`); } + } + list = async (options?: ChannelListOptions) => { + try{ + const { + page, + limit, + sort = ChannelListSortType.SUBSCRIBER, + order = ChannelListOrderType.DESCENDING, + } = options || {} + + return await PUSH_CHANNEL.getChannels({ + env: this.env, + page, + limit, + sort, + order, + }) + + } catch(error){ + throw new Error(`Push SDK Error: Contract : channel::list : ${error}`); + } } } diff --git a/packages/restapi/src/lib/pushapi/pushAPITypes.ts b/packages/restapi/src/lib/pushapi/pushAPITypes.ts index 311f19fd9..fd31f058c 100644 --- a/packages/restapi/src/lib/pushapi/pushAPITypes.ts +++ b/packages/restapi/src/lib/pushapi/pushAPITypes.ts @@ -1,4 +1,5 @@ import Constants, { ENV } from '../constants'; +import type { PushStream } from '../pushstream/PushStream'; import { ChatStatus, ProgressHookType, @@ -6,7 +7,6 @@ import { SpaceData, SpaceRules, } from '../types'; -import type { PushStream } from '../pushstream/PushStream'; export enum ChatListType { CHATS = 'CHATS',