Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public initWallet = async () => {
- const local = localStorage ? localStorage.getItem("walletconnect") : null;
- if (local) {
- let session;
- try {
- session = JSON.parse(local);
- } catch (error) {
- throw error;
- }
- const walletConnector = new WalletConnect({ session });
- const { connected, chainId, accounts, peerMeta } = walletConnector;
- const address = accounts[0];
- await updateWallet(address, chainId);
- await this.setState({
- connected,
- walletConnector,
- address,
- chainId,
- peerMeta
- });
- window.walletConnector = walletConnector; // tslint:disable-line
- (window as any).connexWC = new ProviderWallet({
- behaviorType: 'walletconnect',
- behaviorOptions: {
- walletconnect: walletConnector,
- }
- });
- const wallet = ((window as any).connexWC as ProviderWallet);
- wallet.onSigningRequest.on('SIGN_TX', (params: any[]) => {
- // Either sign with Connex or Thorify
- return;
- });
- this.subscribeToEvents();
- }
- };
- public initWalletConnect = async () => {
- const { uri } = this.state;
- this.setState({ loading: true });
- try {
- const walletConnector = new WalletConnect({ uri });
- window.walletConnector = walletConnector; // tslint:disable-line
- (window as any).connexWC = new ProviderWallet({
- behaviorType: 'walletconnect',
- behaviorOptions: {
- walletconnect: walletConnector,
- }
- });
- const wallet = ((window as any).connexWC as ProviderWallet);
- const wallet = ((window as any).connexWC as ProviderWallet);
- wallet.onSigningRequest.on('SIGN_TX', (params: any[]) => {
- // Either sign with Connex or Thorify
- return;
- });
- if (!walletConnector.connected) {
- await walletConnector.createSession();
- }
- await this.setState({
- loading: false,
- walletConnector,
- uri: walletConnector.uri
- });
- this.subscribeToEvents();
- } catch (error) {
- this.setState({ loading: false });
- throw error;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement