Skip to content

Commit

Permalink
version 0.8.9 (#285)
Browse files Browse the repository at this point in the history
* Access web3 object on window if available to ensure reload on network change (#283)

* Propagate errors to promievent (#281)

* Add check to make sure contract parameter is on txObj (#284)

* Add check to make sure contract parameter is on txObj

* Update checks

* Update to actually fix bug!

* Relax internal gas estimation error handling (#279)

* update to version 0.8.9
  • Loading branch information
cmeisl authored Jun 14, 2019
1 parent 38dac6f commit 063f3a3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
6 changes: 3 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.8.8.
The current version is 0.8.9.
There are minified and non-minified versions.
Put this script at the top of your `<head>`

```html
<script src="https://assist.blocknative.com/0-8-8/assist.js"></script>
<script src="https://assist.blocknative.com/0-8-9/assist.js"></script>

<!-- OR... -->

<script src="https://assist.blocknative.com/0-8-8/assist.min.js"></script>
<script src="https://assist.blocknative.com/0-8-9/assist.min.js"></script>
```

### Initialize the Library
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.8.8",
"version": "0.8.9",
"description": "Blocknative Assist js library for Dapp developers",
"main": "lib/assist.min.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions src/js/helpers/transaction-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ export function getTxObjFromQueue(id) {
export function isDuplicateTransaction({ value, to }, contract) {
const { transactionQueue } = state
let duplicate = transactionQueue.find(txObj => {
if (contract && typeof txObj.contract === 'undefined') return false

const sameMethod = contract
? contract.methodName === txObj.contract.methodName
: true

const sameParams = contract
? argsEqual(contract.parameters, txObj.contract.parameters)
: true
Expand Down
8 changes: 7 additions & 1 deletion src/js/helpers/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,13 @@ export function stepToImageKey(step) {

export function handleError(handlers = {}) {
return errorObj => {
const { callback, reject, resolve } = handlers
const { callback, reject, resolve, promiEvent } = handlers

if (promiEvent) {
promiEvent.emit('error', errorObj)
resolve()
return
}

if (callback) {
callback(errorObj)
Expand Down
14 changes: 10 additions & 4 deletions src/js/helpers/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,26 @@ export function getTransactionParams(
}
})

const gasPromise = new Promise(async (resolve, reject) => {
const gasPromise = new Promise(async resolve => {
let gas
try {
// Get a gas estimate based on if the tx is a contract method call
// or regular transaction
const gas = contractMethod
gas = contractMethod
? await web3Functions.contractGas(version)(
contractMethod,
contractEventObj.parameters,
txObject
)
: await web3Functions.transactionGas(version)(txObject)
resolve(web3Functions.bigNumber(version)(gas))
} catch (e) {
reject(e)
// Sometimes MM can't estimate the gas, and will throw.
// In this case, use either the gas specified by the dapp
// dev, or if that doesn't exist 0 as we are unable to predict
// how much gas the transaction will consume.
gas = txObject.gas ? txObject.gas : 0
} finally {
resolve(web3Functions.bigNumber(version)(gas))
}
})

Expand Down
3 changes: 3 additions & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ function init(config) {
configureWeb3(web3)
}

// This is needed to ensure MetaMask will reload on every network change
window.web3 && window.web3.eth

// Get browser info
getUserAgent()

Expand Down
4 changes: 2 additions & 2 deletions src/js/logic/send-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function sendTransaction(
const [sufficientBalance, ready] = await Promise.all([
hasSufficientBalance(transactionParams),
prepareForTransaction('activePreflight').catch(
handleError({ resolve, reject, callback })
handleError({ resolve, reject, callback, promiEvent })
)
])

Expand Down Expand Up @@ -88,7 +88,7 @@ function sendTransaction(
)
errorObj.eventCode = 'nsfFail'

handleError({ resolve, reject, callback })(errorObj)
handleError({ resolve, reject, callback, promiEvent })(errorObj)
return
}

Expand Down

0 comments on commit 063f3a3

Please sign in to comment.