Add Emit Function (#113)

Co-authored-by: Ben Kremer <ben@walletconnect.com>
Co-authored-by: Vanessa Mercado <finessevanes@Vanessas-MacBook-Pro.local>
This commit is contained in:
vanes 2023-02-15 01:54:07 -08:00 committed by GitHub
parent 4f8d26dda4
commit 8927cddaf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -55,12 +55,13 @@ const SActiveSession = styled(SActiveAccount as any)`
interface HeaderProps {
ping: () => Promise<void>;
emit: () => Promise<void>;
disconnect: () => Promise<void>;
session: SessionTypes.Struct | undefined;
}
const Header = (props: HeaderProps) => {
const { ping, disconnect, session } = props;
const { ping, disconnect, session, emit } = props;
return (
<SHeader {...props}>
{session ? (
@ -82,6 +83,9 @@ const Header = (props: HeaderProps) => {
<Button outline color="black" onClick={ping}>
{"Ping"}
</Button>
<Button outline color="black" onClick={emit}>
{"Emit"}
</Button>
<Button outline color="red" onClick={disconnect}>
{"Disconnect"}
</Button>

View File

@ -108,6 +108,18 @@ const Home: NextPage = () => {
await ping();
};
async function emit() {
if (typeof client === "undefined") {
throw new Error("WalletConnect is not initialized");
}
await client.emit({
topic: session?.topic || '',
event: { name: 'chainChanged', data: {} },
chainId: 'eip155:5'
})
}
const getEthereumActions = (): AccountAction[] => {
const onSendTransaction = async (chainId: string, address: string) => {
openRequestModal();
@ -408,7 +420,7 @@ const Home: NextPage = () => {
return (
<SLayout>
<Column maxWidth={1000} spanHeight>
<Header ping={onPing} disconnect={disconnect} session={session} />
<Header ping={onPing} disconnect={disconnect} session={session} emit={emit}/>
<SContent>{isInitializing ? "Loading..." : renderContent()}</SContent>
</Column>
<Modal show={!!modal} closeModal={closeModal}>