Skip to content

Commit

Permalink
Merge pull request #381 from blocknative/develop
Browse files Browse the repository at this point in the history
Release 0.10.3

- Handle new MetaMask error structure
- Add notification for `txError` event code
  • Loading branch information
lnbc1QWFyb24 committed Sep 11, 2019
2 parents 502e93f + 80b836a commit 3fb619e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ yarn add bnc-assist
#### Script Tag

The library uses [semantic versioning](https://semver.org/spec/v2.0.0.html).
The current version is 0.10.2.
The current version is 0.10.3.
There are minified and non-minified versions.
Put this script at the top of your `<head>`

```html
<script src="https://assist.blocknative.com/0-10-2/assist.js"></script>
<script src="https://assist.blocknative.com/0-10-3/assist.js"></script>

<!-- OR... -->

<script src="https://assist.blocknative.com/0-10-2/assist.min.js"></script>
<script src="https://assist.blocknative.com/0-10-3/assist.min.js"></script>
```

### Initialize the Library
Expand Down Expand Up @@ -194,6 +194,8 @@ var config = {
txSent: Function, // Transaction has been sent to the network
txPending: Function, // Transaction is pending and has been detected in the mempool
txSendFail: Function, // Transaction failed to be sent to the network
txUnderpriced: Function, // Transaction gas limit was set too low
txError: Function, // An unknown MetaMask / JSON RPC error occurred when trying to send the transaction
txStallPending: Function, // Transaction was sent to the network but has not been detected in the txPool
txStallConfirmed: Function, // Transaction has been detected in the mempool but hasn't been confirmed
txFailed: Function, // Transaction failed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-assist",
"version": "0.10.2",
"version": "0.10.3",
"description": "Blocknative Assist js library for Dapp developers",
"main": "lib/assist.min.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/js/helpers/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ export function assistLog(log) {
console.log('Assist:', log) // eslint-disable-line no-console
}

export function extractMessageFromError(message) {
if (!message) {
export function extractMessageFromError(error) {
if (!error.stack || !error.message) {
return {
eventCode: 'txError',
errorMsg: undefined
}
}

const message = error.stack || error.message

if (message.includes('User denied transaction signature')) {
return {
eventCode: 'txSendFail',
Expand Down Expand Up @@ -177,6 +179,7 @@ export function eventCodeToType(eventCode) {
case 'txAwaitingApproval':
case 'txConfirmReminder':
case 'txUnderpriced':
case 'txError':
case 'error':
return 'failed'
case 'txConfirmed':
Expand Down
2 changes: 1 addition & 1 deletion src/js/logic/send-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ async function onTxReceipt(id, categoryCode, receipt) {
}

function onTxError(id, error, categoryCode) {
const { errorMsg, eventCode } = extractMessageFromError(error.message)
const { errorMsg, eventCode } = extractMessageFromError(error)

let txObj = getTxObjFromQueue(id)

Expand Down
4 changes: 3 additions & 1 deletion src/js/views/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,7 @@ export const transactionMsgs = {
txCancel: ({ transaction }) =>
`Your transaction ID: ${transaction.nonce} is being canceled`,
txUnderpriced: () =>
'The gas price for your transaction is too low, try again with a higher gas price'
'The gas price for your transaction is too low, try again with a higher gas price',
txError: () =>
'An unknown error has occurred with your transaction, please try again'
}
6 changes: 4 additions & 2 deletions src/js/views/event-to-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const eventToUI = {
txFailed: notificationsUI,
txSpeedUp: notificationsUI,
txCancel: notificationsUI,
txUnderpriced: notificationsUI
txUnderpriced: notificationsUI,
txError: notificationsUI
},
activeContract: {
txAwaitingApproval: notificationsUI,
Expand All @@ -95,7 +96,8 @@ const eventToUI = {
txFailed: notificationsUI,
txSpeedUp: notificationsUI,
txCancel: notificationsUI,
txUnderpriced: notificationsUI
txUnderpriced: notificationsUI,
txError: notificationsUI
},
userInitiatedNotify: {
success: notificationsUI,
Expand Down

0 comments on commit 3fb619e

Please sign in to comment.