Created
April 25, 2018 17:37
-
-
Save jdkanani/8d4b18ae68d3774a92d1ee637a26efde to your computer and use it in GitHub Desktop.
Walletconnect providers
This file contains 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
import Web3 from 'web3' | |
function getCallback(payload, cb) { | |
return function(err, result) { | |
const obj = {} | |
const keys = ['id', 'jsonrpc'] | |
keys.forEach(key => { | |
obj[key] = payload[key] | |
}) | |
obj.result = result | |
cb(err, obj) | |
} | |
} | |
export default class WalletConnectProvider extends Web3.providers.HttpProvider { | |
isWalletConnect = true | |
constructor({host, timeout, webconnector}) { | |
super(host, timeout) | |
// set webconnector | |
this._webconnector = webconnector | |
} | |
send(...args) { | |
return super.send(...args) | |
} | |
sendAsync(payload, cb) { | |
if (payload.method === 'eth_sendTransaction' || payload.method === 'eth_signTypedData') { | |
return this._webconnector | |
.createTransaction(payload) | |
.then(({transactionId}) => { | |
this._webconnector.listenTransactionStatus(transactionId, getCallback(payload, cb)) | |
}) | |
.catch(getCallback(payload, cb)) | |
} | |
return super.send(payload, cb) | |
} | |
} |
Author
jdkanani
commented
Apr 30, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment