diff --git a/packages/examples/sdk-frontend-react/src/app/ChatTest/ChatTest.tsx b/packages/examples/sdk-frontend-react/src/app/ChatTest/ChatTest.tsx index 5cad4618e..f68a1b7a5 100644 --- a/packages/examples/sdk-frontend-react/src/app/ChatTest/ChatTest.tsx +++ b/packages/examples/sdk-frontend-react/src/app/ChatTest/ChatTest.tsx @@ -53,6 +53,9 @@ const ChatTest = () => { CHAT.REQUESTS + + CHAT.INFO + CHAT.CONVERSATIONHASH @@ -71,6 +74,9 @@ const ChatTest = () => { CHAT.GETGROUPACCESS + + CHAT.MODIFYROLES + CHAT.GETGROUPMEMBERSTATUS @@ -80,7 +86,7 @@ const ChatTest = () => { CHAT.GetGroupInfoTest - + CHAT.GetGroupMembersTest diff --git a/packages/examples/sdk-frontend-react/src/app/ChatTest/GetChatInfo.tsx b/packages/examples/sdk-frontend-react/src/app/ChatTest/GetChatInfo.tsx new file mode 100644 index 000000000..7e02e5bd0 --- /dev/null +++ b/packages/examples/sdk-frontend-react/src/app/ChatTest/GetChatInfo.tsx @@ -0,0 +1,92 @@ +import { useState, useContext } from 'react'; +import { + Section, + SectionItem, + CodeFormatter, + SectionButton, +} from '../components/StyledComponents'; +import Loader from '../components/Loader'; +import { EnvContext } from '../context'; +import * as PushAPI from '@pushprotocol/restapi'; +import ChatTest from './ChatTest'; + +const GetChatInfoTest = () => { + const { env } = useContext(EnvContext); + const [isLoading, setLoading] = useState(false); + const [getChatInfoReponse, setGetChatInfoResponse] = useState(''); + const [chatId, setChatId] = useState(''); + const [address, setAddress] = useState(''); + const updateChatId = (e: React.SyntheticEvent) => { + setChatId((e.target as HTMLInputElement).value); + }; + const updateAddress = (e: React.SyntheticEvent) => { + setAddress((e.target as HTMLInputElement).value); + }; + + const testGetChatInfo = async () => { + try { + setLoading(true); + + const response = await PushAPI.chat.getChatInfo({ + chatId: chatId, + address: address, + env: env, + }); + + setGetChatInfoResponse(response); + } catch (e) { + console.error(e); + } finally { + setLoading(false); + } + }; + + return ( +
+ +

Get Chat Info Test page

+ + + +
+
+ + + + + + + + + + + + get chat info + + +
+ +
+ {getChatInfoReponse ? ( + + {JSON.stringify(getChatInfoReponse, null, 4)} + + ) : null} +
+
+
+
+ ); +}; + +export default GetChatInfoTest; diff --git a/packages/examples/sdk-frontend-react/src/app/ChatTest/ModifyRoles.tsx b/packages/examples/sdk-frontend-react/src/app/ChatTest/ModifyRoles.tsx new file mode 100644 index 000000000..afed95013 --- /dev/null +++ b/packages/examples/sdk-frontend-react/src/app/ChatTest/ModifyRoles.tsx @@ -0,0 +1,113 @@ +import { useState, useContext } from 'react'; +import { + Section, + SectionItem, + CodeFormatter, + SectionButton, +} from '../components/StyledComponents'; +import Loader from '../components/Loader'; +import { EnvContext, Web3Context } from '../context'; +import * as PushAPI from '@pushprotocol/restapi'; +import ChatTest from './ChatTest'; + +const ModifyRolesTest = () => { + const { account: acc, library } = useContext(Web3Context); + const { env } = useContext(EnvContext); + const [isLoading, setLoading] = useState(false); + const [modifyRolesResponse, setModifyRolesResponse] = useState(''); + const [chatId, setChatId] = useState(''); + const [addresses, setAddresses] = useState([]); + const [role, setRole] = useState(''); + const updateChatId = (e: React.SyntheticEvent) => { + setChatId((e.target as HTMLInputElement).value); + }; + const updateRole = (e: React.SyntheticEvent) => { + setRole((e.target as HTMLInputElement).value); + }; + const updateAddress = (e: React.SyntheticEvent) => { + const inputAddresses = (e.target as HTMLInputElement).value + .split(',') + .map((item) => item.trim()); + + setAddresses(inputAddresses); + }; + + const testModifyRoles = async () => { + try { + setLoading(true); + const librarySigner = library.getSigner(); + const response = await PushAPI.chat.modifyRoles({ + chatId: chatId, + newRole: role, + members: addresses, + env, + signer: librarySigner, + account: acc, + }); + + setModifyRolesResponse(response); + } catch (e) { + console.error(e); + } finally { + setLoading(false); + } + }; + + return ( +
+ +

Modify Roles Test page

+ + + +
+
+ + + + + + + + + + + + + + + + Modify Roles + + +
+ +
+ {modifyRolesResponse ? ( + + {JSON.stringify(modifyRolesResponse, null, 4)} + + ) : null} +
+
+
+
+ ); +}; + +export default ModifyRolesTest; diff --git a/packages/examples/sdk-frontend-react/src/app/app.tsx b/packages/examples/sdk-frontend-react/src/app/app.tsx index 2074d5514..ed1f9c03d 100644 --- a/packages/examples/sdk-frontend-react/src/app/app.tsx +++ b/packages/examples/sdk-frontend-react/src/app/app.tsx @@ -2,7 +2,7 @@ import { useContext, useEffect, useMemo, useState } from 'react'; import styled from 'styled-components'; import { Route, Routes, Link } from 'react-router-dom'; import { useWeb3React } from '@web3-react/core'; -import { PushAPI } from "@pushprotocol/restapi"; +import { PushAPI } from '@pushprotocol/restapi'; import ConnectButtonComp from './components/Connect'; import { Checkbox } from './components/Checkbox'; import Dropdown from './components/Dropdown'; @@ -94,7 +94,8 @@ import GetGroupMemberCountTest from './ChatTest/GetGroupMemberCountTest'; import GetGroupInfoTest from './ChatTest/GetGroupInfoTest'; import GetGroupMembersTest from './ChatTest/GetGroupMembersTest'; import VideoV2 from './Video'; - +import GetChatInfoTest from './ChatTest/GetChatInfo'; +import ModifyRolesTest from './ChatTest/ModifyRoles'; window.Buffer = window.Buffer || Buffer; @@ -260,8 +261,8 @@ export function App() { env: env, account: account, alpha: { feature: ['SCALABILITY_V2'] }, - }) - setPushUser(pushUser); + }); + setPushUser(pushUser); setSigner(librarySigner); if (user?.encryptedPrivateKey) { pgpPrivateKey = await PushApi.chat.decryptPGPKey({ @@ -422,6 +423,7 @@ export function App() { } /> } /> } /> + } /> } @@ -447,6 +449,10 @@ export function App() { path="/updateGroup" element={} /> + } + /> {/* chat method routes */} } />