|
|
|
@ -11,7 +11,7 @@ export const profile = { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class Web3ProviderModule extends Plugin { |
|
|
|
|
constructor (blockchain) { |
|
|
|
|
constructor(blockchain) { |
|
|
|
|
super(profile) |
|
|
|
|
this.blockchain = blockchain |
|
|
|
|
} |
|
|
|
@ -20,11 +20,12 @@ export class Web3ProviderModule extends Plugin { |
|
|
|
|
that is used by plugins to call the current ethereum provider. |
|
|
|
|
Should be taken carefully and probably not be release as it is now. |
|
|
|
|
*/ |
|
|
|
|
sendAsync (payload) { |
|
|
|
|
return this.askUserPermission('sendAsync', `Calling ${payload.method} with parameters ${JSON.stringify(payload.params)}`).then( |
|
|
|
|
async (result) => { |
|
|
|
|
if(result){ |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
sendAsync(payload) { |
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
this.askUserPermission('sendAsync', `Calling ${payload.method} with parameters ${JSON.stringify(payload.params)}`).then( |
|
|
|
|
async (result) => { |
|
|
|
|
if (result) { |
|
|
|
|
const provider = this.blockchain.web3().currentProvider |
|
|
|
|
// see https://github.com/ethereum/web3.js/pull/1018/files#diff-d25786686c1053b786cc2626dc6e048675050593c0ebaafbf0814e1996f22022R129
|
|
|
|
|
provider[provider.sendAsync ? 'sendAsync' : 'send'](payload, async (error, message) => { |
|
|
|
@ -44,18 +45,16 @@ export class Web3ProviderModule extends Plugin { |
|
|
|
|
} |
|
|
|
|
resolve(message) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}else{ |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
} else { |
|
|
|
|
reject(new Error('User denied permission')) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}).catch((e) => { |
|
|
|
|
reject(e) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async tryTillReceiptAvailable (txhash) { |
|
|
|
|
async tryTillReceiptAvailable(txhash) { |
|
|
|
|
try { |
|
|
|
|
const receipt = await this.call('blockchain', 'getTransactionReceipt', txhash) |
|
|
|
|
if (receipt) return receipt |
|
|
|
@ -66,9 +65,9 @@ export class Web3ProviderModule extends Plugin { |
|
|
|
|
return await this.tryTillReceiptAvailable(txhash) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async pause () {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
setTimeout(resolve, 500)
|
|
|
|
|
})
|
|
|
|
|
async pause() { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
setTimeout(resolve, 500) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|