From f274dd3250da675a2c40db8061337f5d320718c7 Mon Sep 17 00:00:00 2001 From: Aaron Barnard Date: Wed, 11 Sep 2019 11:04:12 +1000 Subject: [PATCH 1/3] Handle new MetaMask error structure, add notification for unknown MetaMask errors. --- src/js/helpers/utilities.js | 7 +++++-- src/js/logic/send-transaction.js | 2 +- src/js/views/content.js | 4 +++- src/js/views/event-to-ui.js | 6 ++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/js/helpers/utilities.js b/src/js/helpers/utilities.js index 70a1ef69..283d3e53 100644 --- a/src/js/helpers/utilities.js +++ b/src/js/helpers/utilities.js @@ -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', @@ -177,6 +179,7 @@ export function eventCodeToType(eventCode) { case 'txAwaitingApproval': case 'txConfirmReminder': case 'txUnderpriced': + case 'txError': case 'error': return 'failed' case 'txConfirmed': diff --git a/src/js/logic/send-transaction.js b/src/js/logic/send-transaction.js index e1d9a79d..fdf3fdbf 100644 --- a/src/js/logic/send-transaction.js +++ b/src/js/logic/send-transaction.js @@ -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) diff --git a/src/js/views/content.js b/src/js/views/content.js index 03f1ecc8..dba696e4 100644 --- a/src/js/views/content.js +++ b/src/js/views/content.js @@ -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' } diff --git a/src/js/views/event-to-ui.js b/src/js/views/event-to-ui.js index 0e46049f..7a59c3f6 100644 --- a/src/js/views/event-to-ui.js +++ b/src/js/views/event-to-ui.js @@ -79,7 +79,8 @@ const eventToUI = { txFailed: notificationsUI, txSpeedUp: notificationsUI, txCancel: notificationsUI, - txUnderpriced: notificationsUI + txUnderpriced: notificationsUI, + txError: notificationsUI }, activeContract: { txAwaitingApproval: notificationsUI, @@ -95,7 +96,8 @@ const eventToUI = { txFailed: notificationsUI, txSpeedUp: notificationsUI, txCancel: notificationsUI, - txUnderpriced: notificationsUI + txUnderpriced: notificationsUI, + txError: notificationsUI }, userInitiatedNotify: { success: notificationsUI, From d96162f4526d7381fd62994bd478ad8cfa0ea163 Mon Sep 17 00:00:00 2001 From: Aaron Barnard Date: Wed, 11 Sep 2019 11:17:35 +1000 Subject: [PATCH 2/3] Update docs to include txUnderpriced and txError event codes --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6354a7fc..8254e1ec 100644 --- a/README.md +++ b/README.md @@ -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 From 80b836ab3a3a9b9d20b6fb440eb7a3738b3ebb2d Mon Sep 17 00:00:00 2001 From: Aaron Barnard Date: Wed, 11 Sep 2019 12:01:14 +1000 Subject: [PATCH 3/3] Increment version --- README.md | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8254e1ec..9dd3146b 100644 --- a/README.md +++ b/README.md @@ -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 `` ```html - + - + ``` ### Initialize the Library diff --git a/package.json b/package.json index 8f39e750..8782e305 100644 --- a/package.json +++ b/package.json @@ -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": {