-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
3,395 additions
and
2,803 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/examples/sdk-frontend-react/src/app/ChatTest/RejectRequestTest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.