Last active
June 5, 2019 19:49
-
-
Save molekilla/e4d28ab2eceb8463b16d3a79685b5979 to your computer and use it in GitHub Desktop.
Odenplan with WC mock wallet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment