bnc-assist
Advanced tools
Comparing version 0.9.5 to 0.9.6
{ | ||
"name": "bnc-assist", | ||
"version": "0.9.5", | ||
"version": "0.9.6", | ||
"description": "Blocknative Assist js library for Dapp developers", | ||
@@ -5,0 +5,0 @@ "main": "lib/assist.min.js", |
@@ -46,3 +46,3 @@ # Assist.js | ||
The library uses [semantic versioning](https://semver.org/spec/v2.0.0.html). | ||
The current version is 0.9.5. | ||
The current version is 0.9.6. | ||
There are minified and non-minified versions. | ||
@@ -52,7 +52,7 @@ Put this script at the top of your `<head>` | ||
```html | ||
<script src="https://assist.blocknative.com/0-9-5/assist.js"></script> | ||
<script src="https://assist.blocknative.com/0-9-6/assist.js"></script> | ||
<!-- OR... --> | ||
<script src="https://assist.blocknative.com/0-9-5/assist.min.js"></script> | ||
<script src="https://assist.blocknative.com/0-9-6/assist.min.js"></script> | ||
``` | ||
@@ -59,0 +59,0 @@ |
@@ -99,4 +99,5 @@ import uuid from 'uuid/v4' | ||
typeof last(allArgsCopy) === 'object' && | ||
(last(allArgsCopy).messages || last(allArgsCopy).clickHandlers) && | ||
takeLast(allArgsCopy) | ||
(last(allArgsCopy).messages || last(allArgsCopy).clickHandlers) | ||
? takeLast(allArgsCopy) | ||
: {} | ||
@@ -247,8 +248,10 @@ const callback = | ||
export function handleError(handlers = {}) { | ||
return errorObj => { | ||
return (errorObj, receipt) => { | ||
const { callback, reject, resolve, promiEvent } = handlers | ||
if (promiEvent) { | ||
promiEvent.emit('error', errorObj) | ||
promiEvent.emit('error', errorObj, receipt) | ||
promiEvent.reject(errorObj) | ||
resolve() | ||
return | ||
@@ -255,0 +258,0 @@ } |
@@ -223,4 +223,4 @@ import { state } from '~/js/helpers/state' | ||
return waitForTransactionReceipt(hash).then(() => { | ||
onTxReceipt(transactionId, categoryCode) | ||
return waitForTransactionReceipt(hash).then(receipt => { | ||
onTxReceipt(transactionId, categoryCode, receipt) | ||
}) | ||
@@ -239,4 +239,4 @@ }) | ||
await tx.wait() | ||
onTxReceipt(transactionId, categoryCode) | ||
const receipt = await tx.wait() | ||
onTxReceipt(transactionId, categoryCode, receipt) | ||
}) | ||
@@ -248,30 +248,24 @@ .catch(errorObj => { | ||
} else { | ||
new Promise(confirmed => { | ||
/* In web3 v1 instead of resolving the promise returned by sendTransaction | ||
* we need to setup the promiEvent argument to mirror the behavior of the | ||
* promiEvent returned by web3 when we call .send on the contract method. | ||
*/ | ||
txPromise | ||
.on('transactionHash', hash => { | ||
promiEvent.emit('transactionHash', hash) | ||
onTxHash(transactionId, hash, categoryCode) | ||
callback && callback(null, hash) | ||
}) | ||
.on('receipt', receipt => { | ||
promiEvent.emit('receipt', receipt) | ||
confirmed(receipt) | ||
}) | ||
.once('confirmation', confirmed) | ||
.on('confirmation', (confirmation, receipt) => { | ||
promiEvent.emit('confirmation', confirmation, receipt) | ||
}) | ||
.on('error', errorObj => { | ||
promiEvent.emit('error', errorObj) | ||
onTxError(transactionId, errorObj, categoryCode) | ||
handleError({ resolve, reject, callback })(errorObj) | ||
}) | ||
.then(promiEvent.resolve) | ||
.catch(promiEvent.reject) | ||
}).then(() => onTxReceipt(transactionId, categoryCode)) | ||
txPromise | ||
.on('transactionHash', hash => { | ||
promiEvent.emit('transactionHash', hash) | ||
onTxHash(transactionId, hash, categoryCode) | ||
callback && callback(null, hash) | ||
}) | ||
.on('receipt', receipt => { | ||
promiEvent.emit('receipt', receipt) | ||
promiEvent.resolve(receipt) | ||
resolve() | ||
onTxReceipt(transactionId, categoryCode, receipt) | ||
}) | ||
.on('confirmation', (confirmation, receipt) => { | ||
promiEvent.emit('confirmation', confirmation, receipt) | ||
}) | ||
.on('error', (errorObj, receipt) => { | ||
onTxError(transactionId, errorObj, categoryCode) | ||
handleError({ resolve, reject, callback, promiEvent })( | ||
errorObj, | ||
receipt | ||
) | ||
}) | ||
} | ||
@@ -339,9 +333,9 @@ }) | ||
async function onTxReceipt(id, categoryCode) { | ||
async function onTxReceipt(id, categoryCode, receipt) { | ||
let txObj = getTxObjFromQueue(id) | ||
if (txObj.transaction.status === 'confirmed') { | ||
txObj = updateTransactionInQueue(id, { status: 'completed' }) | ||
txObj = updateTransactionInQueue(id, { status: 'completed', receipt }) | ||
} else { | ||
txObj = updateTransactionInQueue(id, { status: 'confirmed' }) | ||
txObj = updateTransactionInQueue(id, { status: 'confirmed', receipt }) | ||
} | ||
@@ -348,0 +342,0 @@ |
Sorry, the diff of this file is too big to display
2566703
12942