Skip to content

Commit 3fb619e

Browse files
authored
Merge pull request #381 from blocknative/develop
Release 0.10.3 - Handle new MetaMask error structure - Add notification for `txError` event code
2 parents 502e93f + 80b836a commit 3fb619e

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ yarn add bnc-assist
4343
#### Script Tag
4444

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

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

5353
<!-- OR... -->
5454

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

5858
### Initialize the Library
@@ -194,6 +194,8 @@ var config = {
194194
txSent: Function, // Transaction has been sent to the network
195195
txPending: Function, // Transaction is pending and has been detected in the mempool
196196
txSendFail: Function, // Transaction failed to be sent to the network
197+
txUnderpriced: Function, // Transaction gas limit was set too low
198+
txError: Function, // An unknown MetaMask / JSON RPC error occurred when trying to send the transaction
197199
txStallPending: Function, // Transaction was sent to the network but has not been detected in the txPool
198200
txStallConfirmed: Function, // Transaction has been detected in the mempool but hasn't been confirmed
199201
txFailed: Function, // Transaction failed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-assist",
3-
"version": "0.10.2",
3+
"version": "0.10.3",
44
"description": "Blocknative Assist js library for Dapp developers",
55
"main": "lib/assist.min.js",
66
"scripts": {

src/js/helpers/utilities.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,16 @@ export function assistLog(log) {
131131
console.log('Assist:', log) // eslint-disable-line no-console
132132
}
133133

134-
export function extractMessageFromError(message) {
135-
if (!message) {
134+
export function extractMessageFromError(error) {
135+
if (!error.stack || !error.message) {
136136
return {
137137
eventCode: 'txError',
138138
errorMsg: undefined
139139
}
140140
}
141141

142+
const message = error.stack || error.message
143+
142144
if (message.includes('User denied transaction signature')) {
143145
return {
144146
eventCode: 'txSendFail',
@@ -177,6 +179,7 @@ export function eventCodeToType(eventCode) {
177179
case 'txAwaitingApproval':
178180
case 'txConfirmReminder':
179181
case 'txUnderpriced':
182+
case 'txError':
180183
case 'error':
181184
return 'failed'
182185
case 'txConfirmed':

src/js/logic/send-transaction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ async function onTxReceipt(id, categoryCode, receipt) {
386386
}
387387

388388
function onTxError(id, error, categoryCode) {
389-
const { errorMsg, eventCode } = extractMessageFromError(error.message)
389+
const { errorMsg, eventCode } = extractMessageFromError(error)
390390

391391
let txObj = getTxObjFromQueue(id)
392392

src/js/views/content.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,7 @@ export const transactionMsgs = {
381381
txCancel: ({ transaction }) =>
382382
`Your transaction ID: ${transaction.nonce} is being canceled`,
383383
txUnderpriced: () =>
384-
'The gas price for your transaction is too low, try again with a higher gas price'
384+
'The gas price for your transaction is too low, try again with a higher gas price',
385+
txError: () =>
386+
'An unknown error has occurred with your transaction, please try again'
385387
}

src/js/views/event-to-ui.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ const eventToUI = {
7979
txFailed: notificationsUI,
8080
txSpeedUp: notificationsUI,
8181
txCancel: notificationsUI,
82-
txUnderpriced: notificationsUI
82+
txUnderpriced: notificationsUI,
83+
txError: notificationsUI
8384
},
8485
activeContract: {
8586
txAwaitingApproval: notificationsUI,
@@ -95,7 +96,8 @@ const eventToUI = {
9596
txFailed: notificationsUI,
9697
txSpeedUp: notificationsUI,
9798
txCancel: notificationsUI,
98-
txUnderpriced: notificationsUI
99+
txUnderpriced: notificationsUI,
100+
txError: notificationsUI
99101
},
100102
userInitiatedNotify: {
101103
success: notificationsUI,

0 commit comments

Comments
 (0)