Skip to content

Commit

Permalink
version 0.8.10 (#301)
Browse files Browse the repository at this point in the history
* Add listener to close modal with escape key

* Revert "Add listener to close modal with escape key"

This reverts commit af66cd4.

* Add listener for escape key to close modal (#287)

* Fix/missing return (#294)

* Add missing return after mobileBlocked event and remove redundant resolve

* Make returns consistent, add check for null result so that calback isn't called twice

* Add missing messages parameter (#290)

* Add custom timeout for txStall event (#288)

* Add custom tiemout for txStall event

* updated text for txStall

* Automatic contract type detection on a contract-by-contract basis (#291)

* Automatic detection of truffle contracts

* Remove redundant object property

* update to version 0.8.10

* Update initialization test (#297)

* Make sure keypress listener is removed when modal is closed via click (#299)

* Make sure keypress listener is removed when modal is closed via click

* Change reassignment to null instead of undefined

* Enhancement/remove metamask language images (#300)

* Add provider checks and remove Metmask language and images when not the provider, update styles to work with no image

* update snapshots with new styles and dom structure

* text tweaks

* update snapshot

* capitalization

* Attach listener to iframe window instead

* add check for focus method

* Update test suite
  • Loading branch information
cmeisl authored Jun 19, 2019
1 parent 063f3a3 commit 9d0784a
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 371 deletions.
12 changes: 7 additions & 5 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.9.
The current version is 0.8.10.
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-9/assist.js"></script>
<script src="https://assist.blocknative.com/0-8-10/assist.js"></script>

<!-- OR... -->

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

### Initialize the Library
Expand Down Expand Up @@ -170,7 +170,7 @@ 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
txStall: Function, // Transaction was sent but not received in the mempool after 30 secs
txStall: Function, // Transaction was sent but not confirmed in the blockchain after 30 secs
txFailed: Function, // Transaction failed
nsfFail: Function, // User doesn't have enough funds to complete transaction
txRepeat: Function, // Warning to user that they might be repeating a transaction
Expand All @@ -194,7 +194,9 @@ var config = {
notificationsPosition: Object || String, // Defines where in the viewport notifications will be positioned. See below: 'Notification Positioning'
css: String // Custom css string to overide Assist default styles
},
truffleContract: Boolean, // Set to true if contract object has been instantiated with truffle-contract [false]
timeouts: {
txStall: Number // The number of milliseconds after a transaction has been sent before showing a stall notification if not confirmed in the blockchain
}
}
```

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.9",
"version": "0.8.10",
"description": "Blocknative Assist js library for Dapp developers",
"main": "lib/assist.min.js",
"scripts": {
Expand Down
7 changes: 1 addition & 6 deletions src/__e2e-tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import truffleContract from 'truffle-contract'
import convertLibJson, { abi } from '~/__tests__/res/ConvertLib.json'
import da from '~/js'
import * as websockets from '~/js/helpers/websockets'
import { state, initialState, updateState } from '~/js/helpers/state'
import { initialState, updateState } from '~/js/helpers/state'

import {
convertLibAddress,
Expand Down Expand Up @@ -117,13 +117,9 @@ multidepRequire.forEachVersion('web3', (version, Web3) => {
let decoratedContract
let contract
beforeAll(async () => {
state.config.truffleContract = true
contract = await getTruffleContract(web3)
decoratedContract = assistInstance.Contract(contract)
})
afterAll(() => {
state.config.truffleContract = false
})

test('they can estimate gas of a method call from the decorated contract', async () => {
const expected = await contract.convert.estimateGas(1, 2)
Expand All @@ -134,7 +130,6 @@ multidepRequire.forEachVersion('web3', (version, Web3) => {
describe('the user makes a contract method call', () => {
let res
beforeAll(async () => {
state.config.truffleContract = true
res = await decoratedContract.convert(2, 5)
})
test('results in the expected response', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/__integration-tests__/initialization/initialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ describe('init is called', () => {
notificationsPosition: { mobile: 'top', desktop: 'bottomLeft' },
css: '123'
},
truffleContract: true
timeouts: {
txStall: 1
}
}
test(`should not throw`, () => {
expect(() => {
Expand Down Expand Up @@ -326,6 +328,12 @@ describe('init is called', () => {
})
})

beforeEach(() => {
jest.spyOn(console, 'error')
// eslint-disable-next-line
console.error.mockImplementation(() => {})
})

beforeAll(() => {
jest.spyOn(websockets, 'openWebsocketConnection').mockImplementation(() => {})
})
Expand Down
448 changes: 234 additions & 214 deletions src/__integration-tests__/ui-rendering/__snapshots__/index.test.js.snap

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/__integration-tests__/ui-rendering/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ describe('dom-rendering', () => {
})
})

beforeEach(() => {
jest.spyOn(console, 'error')
// eslint-disable-next-line
console.error.mockImplementation(() => {})
})

// Reset the environment to a specified state and localstorage,
// then create a new iframe
// (not using beforeEach for this as it was behaiving strangely)
Expand Down
6 changes: 1 addition & 5 deletions src/__tests__/js/contract/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Server } from 'mock-socket'
import abi from '~/__tests__/res/dstoken.json'
import da from '~/js'
import * as web3Helpers from '~/js/helpers/web3'
import { state, initialState, updateState } from '~/js/helpers/state'
import { initialState, updateState } from '~/js/helpers/state'
import convertLibJson from '~/__tests__/res/ConvertLib.json'
import { convertLibAddress, port } from '../../../../internals/ganacheConfig'

Expand Down Expand Up @@ -55,12 +55,8 @@ multidepRequire.forEachVersion('web3', (version, Web3) => {
contracts.forEach(([name, getContract]) => {
describe(`with a ${name} contract`, () => {
beforeEach(async () => {
if (name === 'truffle') state.config.truffleContract = true
contract = await getContract(web3)
})
afterEach(() => {
if (name === 'truffle') state.config.truffleContract = false
})
test(`it doesn't fail and returns the expected decorated contract`, () => {
const decoratedContract = assistInstance.Contract(contract)

Expand Down
9 changes: 3 additions & 6 deletions src/__tests__/js/web3.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import truffleContract from 'truffle-contract'
import da from '~/js'
import abi from '~/__tests__/res/dstoken.json'
import { state, initialState, updateState } from '~/js/helpers/state'
import { initialState, updateState } from '~/js/helpers/state'
import * as websockets from '~/js/helpers/websockets'
import { web3Functions } from '~/js/helpers/web3'
import convertLibJson from '~/__tests__/res/ConvertLib'
Expand Down Expand Up @@ -98,7 +98,6 @@ describe(`web3.js tests`, () => {
describe('from a truffle contract', () => {
let contractInstance
beforeEach(async () => {
state.config.truffleContract = true
contract = truffleContract(convertLibJson)
contract.setProvider(
new Web3v0p20.providers.HttpProvider(
Expand All @@ -107,17 +106,15 @@ describe(`web3.js tests`, () => {
)
contractInstance = await contract.at(convertLibAddress)
})
afterEach(() => {
state.config.truffleContract = false
})
// doesn't seem to work
// see https://github.com/blocknative/assist/issues/171
test('should return the expected gas cost', async () => {
const expected = 21988 // gas the convert call should cost
const contractMethod = contractInstance.convert
const parameters = [5, 10]
const contractGas = await web3Functions.contractGas(
simpleVersion
simpleVersion,
true
)(contractMethod, parameters)
expect(contractGas).toEqual(expected)
})
Expand Down
7 changes: 3 additions & 4 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ body {
}

.bn-onboard-basic .bn-onboard-sidebar {
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
padding: 15px 20px;
width: 34%;
background: #eeeeee;
Expand Down Expand Up @@ -365,10 +368,6 @@ img.bn-onboard-img {
font-size: 0.79em;
}

.bn-onboard-basic .bn-onboarding-branding {
position: absolute;
bottom: 15px;
}
.bn-onboard-basic .bn-onboarding-branding img {
margin-top: 5px;
}
Expand Down
3 changes: 3 additions & 0 deletions src/js/helpers/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export function validateConfig(config) {
),
css: ow.optional.string
}),
timeouts: ow.optional.object.exactShape({
txStall: ow.number
}),
truffleContract: ow.optional.boolean
})
)
Expand Down
11 changes: 6 additions & 5 deletions src/js/helpers/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ export const web3Functions = {
return () => Promise.reject(errorObj)
}
},
contractGas: version => {
contractGas: (version, truffleContract) => {
switch (version) {
case '0.2':
return (contractMethod, parameters, txObject) =>
state.config.truffleContract
truffleContract
? contractMethod.estimateGas(...parameters)
: promisify(contractMethod.estimateGas)(...parameters, txObject)
case '1.0':
return (contractMethod, parameters, txObject) =>
state.config.truffleContract
truffleContract
? contractMethod.estimateGas(...parameters)
: contractMethod(...parameters).estimateGas(txObject)
default:
Expand Down Expand Up @@ -167,7 +167,8 @@ export function getNetworkId() {
export function getTransactionParams(
txObject = {},
contractMethod,
contractEventObj
contractEventObj,
truffleContract
) {
return new Promise(async resolve => {
const version = state.web3Version && state.web3Version.slice(0, 3)
Expand Down Expand Up @@ -199,7 +200,7 @@ export function getTransactionParams(
// Get a gas estimate based on if the tx is a contract method call
// or regular transaction
gas = contractMethod
? await web3Functions.contractGas(version)(
? await web3Functions.contractGas(version, truffleContract)(
contractMethod,
contractEventObj.parameters,
txObject
Expand Down
37 changes: 19 additions & 18 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,9 @@ function init(config) {
// CONTRACT FUNCTION //

function Contract(contractObj) {
const {
validApiKey,
supportedNetwork,
web3Instance,
config: { truffleContract }
} = state
const { validApiKey, supportedNetwork, web3Instance } = state

const truffleContract = contractObj.constructor.name === 'TruffleContract'

if (!validApiKey) {
const errorObj = new Error('Your API key is not valid')
Expand Down Expand Up @@ -293,14 +290,14 @@ function init(config) {

newContractObj[name] = (...args) =>
constant
? legacyCall(method, name, args, argsLength)
: legacySend(method, name, args, argsLength)
? legacyCall(method, name, args, argsLength, truffleContract)
: legacySend(method, name, args, argsLength, truffleContract)

newContractObj[name].call = (...args) =>
legacyCall(method, name, args, argsLength)
legacyCall(method, name, args, argsLength, truffleContract)

newContractObj[name].sendTransaction = (...args) =>
legacySend(method, name, args, argsLength)
legacySend(method, name, args, argsLength, truffleContract)

// Add any additional properties onto the method function
Object.entries(contractObj[name]).forEach(([k, v]) => {
Expand All @@ -320,14 +317,14 @@ function init(config) {

newContractObj[name][key] = (...args) =>
constant
? legacyCall(method, name, args, argsLength)
: legacySend(method, name, args, argsLength)
? legacyCall(method, name, args, argsLength, truffleContract)
: legacySend(method, name, args, argsLength, truffleContract)

newContractObj[name][key].call = (...args) =>
legacyCall(method, name, args, argsLength)
legacyCall(method, name, args, argsLength, truffleContract)

newContractObj[name][key].sendTransaction = (...args) =>
legacySend(method, name, args, argsLength)
legacySend(method, name, args, argsLength, truffleContract)

// Add any additional properties onto the method function
Object.entries(method).forEach(([k, v]) => {
Expand Down Expand Up @@ -368,7 +365,7 @@ function init(config) {
methodsObj[name] = (...args) =>
constant
? modernCall(method, name, args)
: modernSend(method, name, args)
: modernSend(method, name, args, truffleContract)

// Add any additional properties onto the method function
Object.entries(method).forEach(([k, v]) => {
Expand All @@ -393,7 +390,7 @@ function init(config) {
methodsObj[overloadedMethodKey] = (...args) =>
constant
? modernCall(overloadedMethod, name, args)
: modernSend(overloadedMethod, name, args)
: modernSend(overloadedMethod, name, args, truffleContract)

// Add any additional properties onto the method function
Object.entries(overloadedMethod).forEach(([k, v]) => {
Expand Down Expand Up @@ -445,9 +442,10 @@ function init(config) {
txObject,
sendMethod,
callback,
inlineCustomMsgs,
inlineCustomMsgs.messages,
undefined,
undefined,
false,
promiEvent
)
return promiEvent
Expand All @@ -457,7 +455,10 @@ function init(config) {
txObject,
sendMethod,
callback,
inlineCustomMsgs.messages
inlineCustomMsgs.messages,
undefined,
undefined,
false
)
}
}
Expand Down
Loading

0 comments on commit 9d0784a

Please sign in to comment.