SHARE
TWEET

Untitled

a guest Jun 17th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public initWallet = async () => {
  2.     const local = localStorage ? localStorage.getItem("walletconnect") : null;
  3.  
  4.     if (local) {
  5.       let session;
  6.  
  7.       try {
  8.         session = JSON.parse(local);
  9.       } catch (error) {
  10.         throw error;
  11.       }
  12.  
  13.       const walletConnector = new WalletConnect({ session });
  14.  
  15.       const { connected, chainId, accounts, peerMeta } = walletConnector;
  16.  
  17.       const address = accounts[0];
  18.  
  19.       await updateWallet(address, chainId);
  20.  
  21.       await this.setState({
  22.         connected,
  23.         walletConnector,
  24.         address,
  25.         chainId,
  26.         peerMeta
  27.       });
  28.  
  29.       window.walletConnector = walletConnector; // tslint:disable-line
  30.  
  31.       (window as any).connexWC = new ProviderWallet({
  32.         behaviorType: 'walletconnect',
  33.         behaviorOptions: {
  34.           walletconnect: walletConnector,
  35.         }
  36.       });
  37.  
  38.       const wallet = ((window as any).connexWC as ProviderWallet);
  39.       wallet.onSigningRequest.on('SIGN_TX', (params: any[]) => {
  40.             // Either sign with Connex or Thorify
  41.         return;
  42.       });
  43.      
  44.       this.subscribeToEvents();
  45.     }
  46.   };
  47.  
  48.   public initWalletConnect = async () => {
  49.     const { uri } = this.state;
  50.  
  51.     this.setState({ loading: true });
  52.  
  53.     try {
  54.       const walletConnector = new WalletConnect({ uri });
  55.  
  56.       window.walletConnector = walletConnector; // tslint:disable-line
  57.  
  58.       (window as any).connexWC = new ProviderWallet({
  59.         behaviorType: 'walletconnect',
  60.         behaviorOptions: {
  61.           walletconnect: walletConnector,
  62.         }
  63.       });
  64.  
  65.       const wallet = ((window as any).connexWC as ProviderWallet);
  66.  
  67.       const wallet = ((window as any).connexWC as ProviderWallet);
  68.       wallet.onSigningRequest.on('SIGN_TX', (params: any[]) => {
  69.             // Either sign with Connex or Thorify
  70.         return;
  71.       });
  72.      
  73.       if (!walletConnector.connected) {
  74.         await walletConnector.createSession();
  75.       }
  76.  
  77.       await this.setState({
  78.         loading: false,
  79.         walletConnector,
  80.         uri: walletConnector.uri
  81.       });
  82.  
  83.       this.subscribeToEvents();
  84.     } catch (error) {
  85.       this.setState({ loading: false });
  86.  
  87.       throw error;
  88.     }
  89.   };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top