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:
parent
4f8d26dda4
commit
8927cddaf9
@ -55,12 +55,13 @@ const SActiveSession = styled(SActiveAccount as any)`
|
|||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
ping: () => Promise<void>;
|
ping: () => Promise<void>;
|
||||||
|
emit: () => Promise<void>;
|
||||||
disconnect: () => Promise<void>;
|
disconnect: () => Promise<void>;
|
||||||
session: SessionTypes.Struct | undefined;
|
session: SessionTypes.Struct | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Header = (props: HeaderProps) => {
|
const Header = (props: HeaderProps) => {
|
||||||
const { ping, disconnect, session } = props;
|
const { ping, disconnect, session, emit } = props;
|
||||||
return (
|
return (
|
||||||
<SHeader {...props}>
|
<SHeader {...props}>
|
||||||
{session ? (
|
{session ? (
|
||||||
@ -82,6 +83,9 @@ const Header = (props: HeaderProps) => {
|
|||||||
<Button outline color="black" onClick={ping}>
|
<Button outline color="black" onClick={ping}>
|
||||||
{"Ping"}
|
{"Ping"}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button outline color="black" onClick={emit}>
|
||||||
|
{"Emit"}
|
||||||
|
</Button>
|
||||||
<Button outline color="red" onClick={disconnect}>
|
<Button outline color="red" onClick={disconnect}>
|
||||||
{"Disconnect"}
|
{"Disconnect"}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -108,6 +108,18 @@ const Home: NextPage = () => {
|
|||||||
await ping();
|
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 getEthereumActions = (): AccountAction[] => {
|
||||||
const onSendTransaction = async (chainId: string, address: string) => {
|
const onSendTransaction = async (chainId: string, address: string) => {
|
||||||
openRequestModal();
|
openRequestModal();
|
||||||
@ -408,7 +420,7 @@ const Home: NextPage = () => {
|
|||||||
return (
|
return (
|
||||||
<SLayout>
|
<SLayout>
|
||||||
<Column maxWidth={1000} spanHeight>
|
<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>
|
<SContent>{isInitializing ? "Loading..." : renderContent()}</SContent>
|
||||||
</Column>
|
</Column>
|
||||||
<Modal show={!!modal} closeModal={closeModal}>
|
<Modal show={!!modal} closeModal={closeModal}>
|
||||||
|
Loading…
Reference in New Issue
Block a user