Here I simply want to call a walletconnect function when I click on the button. but it is not calling any function. please correct me if I'm wrong somewhere.
App.tsx
import * as React from 'react';
import WalletConnect from "@walletconnect/client";
import QRCodeModal from "@walletconnect/qrcode-modal";
class App extends React.Component<any, any> {
constructor(props:any) {
super(props)
this.state = {
address: ''
}
const connector = new WalletConnect({
bridge: "https://bridge.walletconnect.org", // Required
qrcodeModal: QRCodeModal,
});
}
walletConnectFunc = async () => {
const connector = new WalletConnect({
bridge: "https://bridge.walletconnect.org", // Required
qrcodeModal: QRCodeModal,
});
if (connector.connected) {
alert("already connected")
return
}
connector.createSession();
connector.on("connect", async (error, payload) => {
console.log("connect")
if (error) {
throw error;
}
// Get provided accounts and chainId
const { accounts, chainId } = payload.params[0];
console.log("connect account", accounts)
console.log("chainid account", chainId)
const obj = {
"address": accounts[0],
}
this.setState({ address: obj.address })
console.log(this.state.address)
alert(this.state.address)
})
}
render() {
return (
<div className="App">
<div>
<button className="btn btn-primary my-4" type="button" onClick={() => this.walletConnectFunc()}>WalletConnect</button>
</div>
</div>
);
}
}
export default App;
If more code is required then tell me in a comment section. I will update my question with that information.

onClick{(() => this.something()}can be changed toonClick={this.something}to avoid creating an extra function in the render.asyncwhen you're notawaiting anything in it?onnector.on—asyncis for when you have things you want toawaitrather than using Promise.thensyntax, you don't need to throwasyncs on functions otherwise.