Skip to content

Commit

Permalink
refactor: resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNilesh committed Aug 18, 2023
2 parents 5a577c6 + 93e3106 commit c4a2013
Show file tree
Hide file tree
Showing 27 changed files with 3,668 additions and 2,720 deletions.
15 changes: 9 additions & 6 deletions packages/examples/sdk-backend-node/src/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const runChatUseCases = async (): Promise<void> => {
await PushAPI_chat_video_call_notification(TargetChatId);

console.log('PushAPI.chat.createGroup');
const chatId = await PushAPI_chat_createGroup();
const { chatId, name } = await PushAPI_chat_createGroup();

console.log('PushAPI.chat.conversationHash');
await PushAPI_chat_conversationHash();
Expand All @@ -112,7 +112,7 @@ export const runChatUseCases = async (): Promise<void> => {
await PushAPI_chat_updateGroup(chatId);

console.log('PushAPI.chat.getGroupByName');
await PushAPI_chat_getGroupByName();
await PushAPI_chat_getGroupByName(name);

console.log('PushAPI.chat.getGroup');
await PushAPI_chat_getGroup(chatId);
Expand Down Expand Up @@ -400,7 +400,7 @@ async function PushAPI_chat_approve(silent = !showAPIResponse) {
// Push Chat - PushAPI.chat.createGroup
async function PushAPI_chat_createGroup(
silent = !showAPIResponse
): Promise<string> {
): Promise<{ chatId: string; name: string }> {
// Fetch user
const user = await PushAPI.user.get({
account: `eip155:${signerAddress}`,
Expand Down Expand Up @@ -433,7 +433,7 @@ async function PushAPI_chat_createGroup(
if (!silent) {
console.log(response);
}
return response.chatId;
return { chatId: response.chatId, name: response.groupName };
}

// Push Chat - PushAPI.chat.updateGroup
Expand Down Expand Up @@ -483,9 +483,12 @@ async function PushAPI_chat_updateGroup(
}

// Push Chat - PushAPI.chat.getGroupByName
async function PushAPI_chat_getGroupByName(silent = !showAPIResponse) {
async function PushAPI_chat_getGroupByName(
name: string,
silent = !showAPIResponse
) {
const response = await PushAPI.chat.getGroupByName({
groupName: 'Push Group Chat 3',
groupName: name,
env: env as ENV,
});

Expand Down
9 changes: 6 additions & 3 deletions packages/examples/sdk-backend-node/src/chat/nftChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const runNFTChatUseCases = async (): Promise<void> => {
await PushAPI_nft_chat_updateGroup(chatId);

console.log('PushAPI.chat.getGroupByName');
await PushAPI_nft_chat_getGroupByName();
await PushAPI_nft_chat_getGroupByName(updatedNftGroupName);

console.log('PushAPI.chat.getGroup');
await PushAPI_nft_chat_getGroup(chatId);
Expand Down Expand Up @@ -509,9 +509,12 @@ async function PushAPI_nft_chat_updateGroup(
}

// Push Chat - PushAPI.chat.getGroupByName
async function PushAPI_nft_chat_getGroupByName(silent = !showAPIResponse) {
async function PushAPI_nft_chat_getGroupByName(
name: string,
silent = !showAPIResponse
) {
const response = await PushAPI.chat.getGroupByName({
groupName: 'Push Group Chat 3',
groupName: name,
env: env as ENV,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ const ChatTest = () => {
<Link to="/getGroup" className="nav-button">
CHAT.GETGROUP
</Link>
<Link to="/getGroupAccess" className="nav-button">
CHAT.GETGROUPACCESS
</Link>
<Link to="/addMembersToGroup" className="nav-button">
CHAT.ADDMEMBERSTOGROUP
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Web3Context, EnvContext } from '../context';
import * as PushAPI from '@pushprotocol/restapi';
import { walletToPCAIP10 } from '../helpers';
import ChatTest from './ChatTest';
import { Rules } from '@pushprotocol/restapi';

const CreateGroupTest = () => {
const { account: acc, library } = useContext<any>(Web3Context);
Expand All @@ -26,6 +27,8 @@ const CreateGroupTest = () => {
const [contractAddressERC20, setContractAddressERC20] = useState<string>();
const [numberOfERC20, setNumberOfERC20] = useState<string>();
const [meta, setMeta] = useState<string>();
const [rules, setRules] = useState<string>();

const [account, setAccount] = useState<string>(acc);

const [sendResponse, setSendResponse] = useState<any>('');
Expand Down Expand Up @@ -74,6 +77,10 @@ const CreateGroupTest = () => {
setMeta((e.target as HTMLInputElement).value);
};

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

const updateAccount = (e: React.SyntheticEvent<HTMLElement>) => {
setAccount((e.target as HTMLInputElement).value);
};
Expand All @@ -99,6 +106,7 @@ const CreateGroupTest = () => {
signer: librarySigner,
env,
meta: meta,
rules: rules ? JSON.parse(rules) as Rules : undefined
});

setSendResponse(response);
Expand Down Expand Up @@ -238,6 +246,17 @@ const CreateGroupTest = () => {
/>
</SectionItem>


<SectionItem style={{ marginTop: 20 }}>
<label>rules</label>
<input
type="text"
onChange={updateRules}
value={rules}
style={{ width: 400, height: 30 }}
/>
</SectionItem>

<SectionItem style={{ marginTop: 20 }}>
<SectionButton onClick={testCreateGroup}>
create group
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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';

const GetGroupAccessTest = () => {
const { env } = useContext<any>(EnvContext);
const [isLoading, setLoading] = useState(false);
const [chatId, setChatId] = useState<string>('');
const [did, setDid] = useState<string>('');
const [sendResponse, setSendResponse] = useState<any>('');

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

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

const testGetGroupAccess = async () => {
try {
setLoading(true);

const response = await PushAPI.chat.getGroupAccess({
chatId: chatId,
did: did,
env,
});
setSendResponse(response);
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};

return (
<div>
<h2>Get Group Access Test Page</h2>

<Loader show={isLoading} />

<Section>
<SectionItem>
<SectionButton onClick={testGetGroupAccess}>get group access</SectionButton>
</SectionItem>
<SectionItem>
<label>chatId</label>
<input
type="text"
onChange={updateChatId}
value={chatId}
style={{ width: 400, height: 30 }}
/>
</SectionItem>
<SectionItem>
<label>did</label>
<input
type="text"
onChange={updateDid}
value={did}
style={{ width: 400, height: 30 }}
/>
</SectionItem>
<SectionItem>
<div>
{sendResponse ? (
<CodeFormatter>
{JSON.stringify(sendResponse, null, 4)}
</CodeFormatter>
) : null}
</div>
</SectionItem>
</Section>
</div>
);
};

export default GetGroupAccessTest;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Web3Context, EnvContext } from '../context';
import * as PushAPI from '@pushprotocol/restapi';
import { walletToPCAIP10 } from '../helpers';
import ChatTest from './ChatTest';
import { Rules } from '@pushprotocol/restapi';

const UpdateGroupTest = () => {
const { account: acc, library } = useContext<any>(Web3Context);
Expand All @@ -23,6 +24,7 @@ const UpdateGroupTest = () => {
const [admins, setAdmins] = useState<string>('');
const [account, setAccount] = useState<string>(acc);
const [sendResponse, setSendResponse] = useState<any>('');
const [rules, setRules] = useState<string>();

const updateChatId = (e: React.SyntheticEvent<HTMLElement>) => {
setChatId((e.target as HTMLInputElement).value);
Expand All @@ -47,6 +49,10 @@ const UpdateGroupTest = () => {
setAdmins((e.target as HTMLInputElement).value);
};

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

const updateAccount = (e: React.SyntheticEvent<HTMLElement>) => {
setAccount((e.target as HTMLInputElement).value);
};
Expand All @@ -64,6 +70,7 @@ const UpdateGroupTest = () => {
account: isCAIP ? walletToPCAIP10(account) : account,
signer: librarySigner,
env,
rules: rules ? JSON.parse(rules) as Rules : undefined
});

setSendResponse(response);
Expand Down Expand Up @@ -143,6 +150,17 @@ const UpdateGroupTest = () => {
style={{ width: 400, height: 30 }}
/>
</SectionItem>

<SectionItem style={{ marginTop: 20 }}>
<label>rules</label>
<input
type="text"
onChange={updateRules}
value={rules}
style={{ width: 400, height: 30 }}
/>
</SectionItem>

<SectionItem style={{ marginTop: 20 }}>
<label>Group Creator ( Waller Addr or NFT DID )</label>
<input
Expand Down
Loading

0 comments on commit c4a2013

Please sign in to comment.