|
|
@ -21,27 +21,39 @@ export class Web3ProviderModule extends Plugin { |
|
|
|
Should be taken carefully and probably not be release as it is now. |
|
|
|
Should be taken carefully and probably not be release as it is now. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
sendAsync (payload) { |
|
|
|
sendAsync (payload) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
console.log(payload) |
|
|
|
const provider = this.blockchain.web3().currentProvider |
|
|
|
return this.askUserPermission('sendAsync', `Calling ${payload.method} with parameters ${JSON.stringify(payload.params)}`).then( |
|
|
|
// see https://github.com/ethereum/web3.js/pull/1018/files#diff-d25786686c1053b786cc2626dc6e048675050593c0ebaafbf0814e1996f22022R129
|
|
|
|
async (result) => { |
|
|
|
provider[provider.sendAsync ? 'sendAsync' : 'send'](payload, async (error, message) => { |
|
|
|
if(result){ |
|
|
|
if (error) return reject(error) |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
if (payload.method === 'eth_sendTransaction') { |
|
|
|
const provider = this.blockchain.web3().currentProvider |
|
|
|
if (payload.params.length && !payload.params[0].to && message.result) { |
|
|
|
// see https://github.com/ethereum/web3.js/pull/1018/files#diff-d25786686c1053b786cc2626dc6e048675050593c0ebaafbf0814e1996f22022R129
|
|
|
|
setTimeout(async () => { |
|
|
|
provider[provider.sendAsync ? 'sendAsync' : 'send'](payload, async (error, message) => { |
|
|
|
const receipt = await this.tryTillReceiptAvailable(message.result) |
|
|
|
if (error) return reject(error) |
|
|
|
if (!receipt.contractAddress) { |
|
|
|
if (payload.method === 'eth_sendTransaction') { |
|
|
|
console.log('receipt available but contract address not present', receipt) |
|
|
|
if (payload.params.length && !payload.params[0].to && message.result) { |
|
|
|
return |
|
|
|
setTimeout(async () => { |
|
|
|
|
|
|
|
const receipt = await this.tryTillReceiptAvailable(message.result) |
|
|
|
|
|
|
|
if (!receipt.contractAddress) { |
|
|
|
|
|
|
|
console.log('receipt available but contract address not present', receipt) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress) |
|
|
|
|
|
|
|
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name) |
|
|
|
|
|
|
|
}, 50) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress) |
|
|
|
resolve(message) |
|
|
|
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name) |
|
|
|
}) |
|
|
|
}, 50) |
|
|
|
}) |
|
|
|
} |
|
|
|
}else{ |
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
|
|
reject(new Error('User denied permission')) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
resolve(message) |
|
|
|
} |
|
|
|
}) |
|
|
|
) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async tryTillReceiptAvailable (txhash) { |
|
|
|
async tryTillReceiptAvailable (txhash) { |
|
|
|