Skip to content

Commit

Permalink
fix: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Sep 6, 2023
2 parents eeefd3d + 360e387 commit 0dcf00f
Show file tree
Hide file tree
Showing 18 changed files with 3,395 additions and 2,803 deletions.
78 changes: 54 additions & 24 deletions packages/examples/sdk-backend-node/pushAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,39 @@ export const runPushAPICases = async (): Promise<void> => {
console.log('PushAPI.chat.accept | Response - 200 OK\n\n');
// -------------------------------------------------------------------
// -------------------------------------------------------------------
// TODO: Fix this
// console.log('PushAPI.chat.reject');
// const tempUser = await PushAPI.initialize(thirdSigner, { env });
// await tempUser.chat.send(secondSignerAddress, {
// content: 'Sending Malicious message to bob',
// });
// const bobRejectsRequest = await userBob.chat.reject(thirdSignerAddress);
// if (showAPIResponse) {
// console.log(bobRejectsRequest);
// }
// console.log('PushAPI.chat.reject | Response - 200 OK\n\n');
console.log('PushAPI.chat.reject');
const tempUser = await PushAPI.initialize(thirdSigner, { env });
await tempUser.chat.send(secondSignerAddress, {
content: 'Sending Malicious message to bob',
});
const bobRejectsRequest = await userBob.chat.reject(thirdSignerAddress);
if (showAPIResponse) {
console.log(bobRejectsRequest);
}
console.log('PushAPI.chat.reject | Response - 200 OK\n\n');
// -------------------------------------------------------------------
// -------------------------------------------------------------------
console.log('PushAPI.chat.block');
const AliceBlocksBob = await userAlice.chat.block([secondSignerAddress]);
if (showAPIResponse) {
console.log(AliceBlocksBob);
}
console.log('PushAPI.chat.block | Response - 200 OK\n\n');
// -------------------------------------------------------------------
// -------------------------------------------------------------------
console.log('PushAPI.chat.unblock');
const AliceUnblocksBob = await userAlice.chat.unblock([secondSignerAddress]);
if (showAPIResponse) {
console.log(AliceUnblocksBob);
}
console.log('PushAPI.chat.unblock | Response - 200 OK\n\n');
// -------------------------------------------------------------------
// -------------------------------------------------------------------
console.log('PushAPI.group.create');
const createdGroup = await userAlice.chat.group.create(groupName, {
description: groupDescription,
image: groupImage,
members: [randomWallet1, randomWallet2, secondSignerAddress],
members: [randomWallet1, randomWallet2],
admins: [],
private: false,
});
Expand Down Expand Up @@ -219,20 +234,35 @@ export const runPushAPICases = async (): Promise<void> => {
console.log('PushAPI.group.remove | Response - 200 OK\n\n');
// -------------------------------------------------------------------
// -------------------------------------------------------------------
// console.log('PushAPI.group.join');
// const joinGrp = await userBob.chat.group.join(groupChatId);
// if (showAPIResponse) {
// console.log(joinGrp);
// }
// console.log('PushAPI.group.join | Response - 200 OK\n\n');
console.log('PushAPI.group.join');
const joinGrp = await userBob.chat.group.join(groupChatId);
if (showAPIResponse) {
console.log(joinGrp);
}
console.log('PushAPI.group.join | Response - 200 OK\n\n');
//-------------------------------------------------------------------
// -------------------------------------------------------------------
//console.log('PushAPI.group.leave');
//const leaveGrp = await userBob.chat.group.leave(groupChatId);
//if (showAPIResponse) {
// console.log(leaveGrp);
//}
//console.log('PushAPI.group.leave | Response - 200 OK\n\n');
console.log('PushAPI.group.leave');
const leaveGrp = await userBob.chat.group.leave(groupChatId);
if (showAPIResponse) {
console.log(leaveGrp);
}
console.log('PushAPI.group.leave | Response - 200 OK\n\n');
// -------------------------------------------------------------------
// -------------------------------------------------------------------
console.log('PushAPI.group.reject');
const sampleGrp = await userAlice.chat.group.create('Sample Grp', {
description: groupDescription,
image: groupImage,
members: [secondSignerAddress], // invite bob
admins: [],
private: true,
});
const rejectGrpJoiningReq = await userBob.chat.group.reject(sampleGrp.chatId);
if (showAPIResponse) {
console.log(rejectGrpJoiningReq);
}
console.log('PushAPI.group.reject | Response - 200 OK\n\n');
// -------------------------------------------------------------------
// -------------------------------------------------------------------
console.log('PushAPI.encryption.info');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const ChatTest = () => {
<Link to="/removeAdminsFromGroup" className="nav-button">
CHAT.REMOVEADMINSFROMGROUP
</Link>
<Link to="/reject" className="nav-button">
CHAT.REJECT
</Link>
</NavMenu>
</Section>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { useState, useContext } from 'react';
import {
Section,
SectionItem,
CodeFormatter,
SectionButton,
} from '../components/StyledComponents';
import Loader from '../components/Loader';
import { Web3Context, EnvContext } from '../context';
import * as PushAPI from '@pushprotocol/restapi';
import { walletToPCAIP10 } from '../helpers';
import ChatTest from './ChatTest';

const RejectRequestTest = () => {
const { account: acc, library } = useContext<any>(Web3Context);
const { env, isCAIP } = useContext<any>(EnvContext);
const [isLoading, setLoading] = useState(false);
const [senderAddress, setSenderAddress] = useState<string>('');
const [rejectResponse, setApproveResponse] = useState<any>('');
const [account, setAccount] = useState<string>(acc);

const updateAccount = (e: React.SyntheticEvent<HTMLElement>) => {
setAccount((e.target as HTMLInputElement).value);
};

const updateSenderAddress = (e: React.SyntheticEvent<HTMLElement>) => {
setSenderAddress((e.target as HTMLInputElement).value);
};

const testRejectRequest = async () => {
try {
setLoading(true);
const user = await PushAPI.user.get({ account: account, env });
let pvtkey = null;
const librarySigner = await library.getSigner();
if (user?.encryptedPrivateKey) {
pvtkey = await PushAPI.chat.decryptPGPKey({
encryptedPGPPrivateKey: user.encryptedPrivateKey,
account,
signer: librarySigner,
env,
});
}

const response = await PushAPI.chat.reject({
account: isCAIP ? walletToPCAIP10(account) : account,
senderAddress,
env,
pgpPrivateKey: pvtkey,
signer: librarySigner,
});

setApproveResponse(response);
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};

return (
<div>
<ChatTest />
<h2>Reject Request Test page</h2>

<Loader show={isLoading} />

<Section>
<SectionItem>
<div>
<SectionItem style={{ marginTop: 20 }}>
<label>Sender's Address</label>
<input
type="text"
onChange={updateSenderAddress}
value={senderAddress}
style={{ width: 400, height: 30 }}
/>
</SectionItem>
<SectionItem style={{ marginTop: 20 }}>
<label>Account</label>
<input
type="text"
onChange={updateAccount}
value={account}
style={{ width: 400, height: 30 }}
/>
</SectionItem>
<SectionItem style={{ marginTop: 20 }}>
<SectionButton onClick={testRejectRequest}>
reject request
</SectionButton>
</SectionItem>
</div>
</SectionItem>

<SectionItem>
<div>
{rejectResponse ? (
<CodeFormatter>
{JSON.stringify(rejectResponse, null, 4)}
</CodeFormatter>
) : null}
</div>
</SectionItem>
</Section>
</div>
);
};

export default RejectRequestTest;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SearchSpaceTest = () => {
try {
setLoading(true);

const response = await PushAPI.space.searchSpaces({
const response = await PushAPI.space.search({
searchTerm,
pageNumber,
pageSize,
Expand Down
2 changes: 2 additions & 0 deletions packages/examples/sdk-frontend-react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import ChatViewComponentTest from './ChatUITest/ChatViewComponent';
import { lightChatTheme } from '@pushprotocol/uiweb';
import SearchSpaceTest from './SpaceTest/SearchSpaceTest';
import SearchGroupTest from './ChatTest/SearchGroupTest';
import RejectRequestTest from './ChatTest/RejectRequestTest';

window.Buffer = window.Buffer || Buffer;

Expand Down Expand Up @@ -445,6 +446,7 @@ export function App() {
/>
<Route path="/send" element={<SendMessageTest />} />
<Route path="/approve" element={<ApproveRequestTest />} />
<Route path="/reject" element={<RejectRequestTest />} />
<Route path="/chats" element={<GetChatsTest />} />
<Route path="/hash" element={<ConversationHashTest />} />
<Route path="/history" element={<HistoryTest />} />
Expand Down
Loading

0 comments on commit 0dcf00f

Please sign in to comment.