Skip to content

Commit

Permalink
Merge pull request #6122 from whymarrh/fix-gas-editing
Browse files Browse the repository at this point in the history
Fix advanced inline gas editing
  • Loading branch information
whymarrh authored Feb 8, 2019
2 parents 1a4203a + 0972e23 commit fbc2d58
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 76 deletions.
100 changes: 90 additions & 10 deletions test/e2e/beta/metamask-beta-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,87 @@ describe('MetaMask', function () {
})
})

describe('Send ETH from inside MetaMask', () => {
describe('Send ETH from inside MetaMask using default gas', () => {
it('starts a send transaction', async function () {
const sendButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Send')]`))
await sendButton.click()
await delay(regularDelayMs)

const inputAddress = await findElement(driver, By.css('input[placeholder="Recipient Address"]'))
const inputAmount = await findElement(driver, By.css('.unit-input__input'))
await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970')
await inputAmount.sendKeys('1')

const inputValue = await inputAmount.getAttribute('value')
assert.equal(inputValue, '1')
await delay(regularDelayMs)

// Continue to next screen
const nextScreen = await findElement(driver, By.xpath(`//button[contains(text(), 'Next')]`))
await nextScreen.click()
await delay(regularDelayMs)
})

it('confirms the transaction', async function () {
const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`))
await confirmButton.click()
await delay(largeDelayMs)
})

it('finds the transaction in the transactions list', async function () {
const transactions = await findElements(driver, By.css('.transaction-list-item'))
assert.equal(transactions.length, 1)

if (process.env.SELENIUM_BROWSER !== 'firefox') {
const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary'))
await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/), 10000)
}
})
})

describe('Send ETH from inside MetaMask using fast gas option', () => {
it('starts a send transaction', async function () {
const sendButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Send')]`))
await sendButton.click()
await delay(regularDelayMs)

const inputAddress = await findElement(driver, By.css('input[placeholder="Recipient Address"]'))
const inputAmount = await findElement(driver, By.css('.unit-input__input'))
await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970')
await inputAmount.sendKeys('1')

const inputValue = await inputAmount.getAttribute('value')
assert.equal(inputValue, '1')

// Set the gas price
const fastGas = await findElement(driver, By.xpath(`//button/div/div[contains(text(), "Fast")]`))
await fastGas.click()
await delay(regularDelayMs)

// Continue to next screen
const nextScreen = await findElement(driver, By.xpath(`//button[contains(text(), 'Next')]`))
await nextScreen.click()
await delay(regularDelayMs)
})

it('confirms the transaction', async function () {
const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`))
await confirmButton.click()
await delay(largeDelayMs)
})

it('finds the transaction in the transactions list', async function () {
const transactions = await findElements(driver, By.css('.transaction-list-item'))
assert.equal(transactions.length, 2)

if (process.env.SELENIUM_BROWSER !== 'firefox') {
const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary'))
await driver.wait(until.elementTextMatches(txValues, /-1\s*ETH/), 10000)
}
})
})

describe('Send ETH from inside MetaMask using advanced gas modal', () => {
it('starts a send transaction', async function () {
const sendButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Send')]`))
await sendButton.click()
Expand Down Expand Up @@ -391,7 +471,7 @@ describe('MetaMask', function () {

it('finds the transaction in the transactions list', async function () {
const transactions = await findElements(driver, By.css('.transaction-list-item'))
assert.equal(transactions.length, 1)
assert.equal(transactions.length, 3)

if (process.env.SELENIUM_BROWSER !== 'firefox') {
const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary'))
Expand Down Expand Up @@ -447,7 +527,7 @@ describe('MetaMask', function () {

it('finds the transaction in the transactions list', async function () {
const transactions = await findElements(driver, By.css('.transaction-list-item'))
assert.equal(transactions.length, 2)
assert.equal(transactions.length, 4)

const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary'))
await driver.wait(until.elementTextMatches(txValues, /-3\s*ETH/), 10000)
Expand Down Expand Up @@ -487,7 +567,7 @@ describe('MetaMask', function () {
})

it('navigates the transactions', async () => {
let navigateTxButtons = await findElements(driver, By.css('.confirm-page-container-navigation__arrow'))
let navigateTxButtons = await findElements(driver, By.css('.confirm-page-container-navigation__arrow'), 20000)
assert.equal(navigateTxButtons.length, 4, 'navigation button present')

await navigateTxButtons[2].click()
Expand Down Expand Up @@ -586,7 +666,7 @@ describe('MetaMask', function () {
await delay(largeDelayMs * 2)

const confirmedTxes = await findElements(driver, By.css('.transaction-list__completed-transactions .transaction-list-item'))
assert.equal(confirmedTxes.length, 3, '3 transactions present')
assert.equal(confirmedTxes.length, 5, '5 transactions present')
})
})

Expand Down Expand Up @@ -637,7 +717,7 @@ describe('MetaMask', function () {

await driver.wait(async () => {
const confirmedTxes = await findElements(driver, By.css('.transaction-list__completed-transactions .transaction-list-item'))
return confirmedTxes.length === 4
return confirmedTxes.length === 6
}, 10000)

const txAction = await findElements(driver, By.css('.transaction-list-item__action'))
Expand Down Expand Up @@ -697,7 +777,7 @@ describe('MetaMask', function () {

await driver.wait(async () => {
const confirmedTxes = await findElements(driver, By.css('.transaction-list__completed-transactions .transaction-list-item'))
return confirmedTxes.length === 5
return confirmedTxes.length === 7
}, 10000)

const txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary'))
Expand Down Expand Up @@ -729,7 +809,7 @@ describe('MetaMask', function () {

await driver.wait(async () => {
const confirmedTxes = await findElements(driver, By.css('.transaction-list__completed-transactions .transaction-list-item'))
return confirmedTxes.length === 6
return confirmedTxes.length === 8
}, 10000)

const txValues = await findElement(driver, By.css('.transaction-list-item__amount--primary'))
Expand All @@ -743,9 +823,9 @@ describe('MetaMask', function () {
const balance = await findElement(driver, By.css('.transaction-view-balance__primary-balance'))
await delay(regularDelayMs)
if (process.env.SELENIUM_BROWSER !== 'firefox') {
await driver.wait(until.elementTextMatches(balance, /^89.*\s*ETH.*$/), 10000)
await driver.wait(until.elementTextMatches(balance, /^87.*\s*ETH.*$/), 10000)
const tokenAmount = await balance.getText()
assert.ok(/^89.*\s*ETH.*$/.test(tokenAmount))
assert.ok(/^87.*\s*ETH.*$/.test(tokenAmount))
await delay(regularDelayMs)
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import { connect } from 'react-redux'
import { showModal } from '../../../actions'
import {
decGWEIToHexWEI,
decimalToHex,
hexWEIToDecGWEI,
} from '../../../helpers/conversions.util'
import AdvancedGasInputs from './advanced-gas-inputs.component'

function convertGasPriceForInputs (gasPriceInHexWEI) {
return Number(hexWEIToDecGWEI(gasPriceInHexWEI))
}

function convertGasLimitForInputs (gasLimitInHexWEI) {
return parseInt(gasLimitInHexWEI, 16)
}

const mapDispatchToProps = dispatch => {
return {
showGasPriceInfoModal: modalName => dispatch(showModal({ name: 'GAS_PRICE_INFO_MODAL' })),
showGasLimitInfoModal: modalName => dispatch(showModal({ name: 'GAS_LIMIT_INFO_MODAL' })),
}
}

export default connect(null, mapDispatchToProps)(AdvancedGasInputs)
const mergeProps = (stateProps, dispatchProps, ownProps) => {
const {customGasPrice, customGasLimit, updateCustomGasPrice, updateCustomGasLimit} = ownProps
return {
...stateProps,
...dispatchProps,
...ownProps,
customGasPrice: convertGasPriceForInputs(customGasPrice),
customGasLimit: convertGasLimitForInputs(customGasLimit),
updateCustomGasPrice: (price) => updateCustomGasPrice(decGWEIToHexWEI(price)),
updateCustomGasLimit: (limit) => updateCustomGasLimit(decimalToHex(limit)),
}
}

export default connect(null, mapDispatchToProps, mergeProps)(AdvancedGasInputs)
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export default class ConfirmTransactionBase extends Component {
txData: PropTypes.object,
unapprovedTxCount: PropTypes.number,
currentNetworkUnapprovedTxs: PropTypes.object,
updateGasAndCalculate: PropTypes.func,
customGas: PropTypes.object,
// Component props
action: PropTypes.string,
contentComponent: PropTypes.node,
Expand All @@ -83,10 +85,7 @@ export default class ConfirmTransactionBase extends Component {
valid: PropTypes.bool,
warning: PropTypes.string,
advancedInlineGasShown: PropTypes.bool,
gasPrice: PropTypes.number,
gasLimit: PropTypes.number,
insufficientBalance: PropTypes.bool,
convertThenUpdateGasAndCalculate: PropTypes.func,
}

state = {
Expand Down Expand Up @@ -172,10 +171,9 @@ export default class ConfirmTransactionBase extends Component {
hexTransactionTotal,
hideDetails,
advancedInlineGasShown,
gasPrice,
gasLimit,
customGas,
insufficientBalance,
convertThenUpdateGasAndCalculate,
updateGasAndCalculate,
} = this.props

if (hideDetails) {
Expand All @@ -195,10 +193,10 @@ export default class ConfirmTransactionBase extends Component {
/>
{advancedInlineGasShown
? <AdvancedGasInputs
updateCustomGasPrice={newGasPrice => convertThenUpdateGasAndCalculate({ gasPrice: newGasPrice, gasLimit })}
updateCustomGasLimit={newGasLimit => convertThenUpdateGasAndCalculate({ gasLimit: newGasLimit, gasPrice })}
customGasPrice={gasPrice}
customGasLimit={gasLimit}
updateCustomGasPrice={newGasPrice => updateGasAndCalculate({ ...customGas, gasPrice: newGasPrice })}
updateCustomGasLimit={newGasLimit => updateGasAndCalculate({ ...customGas, gasLimit: newGasLimit })}
customGasPrice={customGas.gasPrice}
customGasLimit={customGas.gasLimit}
insufficientBalance={insufficientBalance}
customPriceIsSafe={true}
isSpeedUp={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import {
GAS_LIMIT_TOO_LOW_ERROR_KEY,
} from '../../../constants/error-keys'
import { getHexGasTotal } from '../../../helpers/confirm-transaction/util'
import {
convertGasPriceForInputs,
convertGasLimitForInputs,
decimalToHex,
decGWEIToHexWEI,
} from '../../../helpers/conversions.util'
import { isBalanceSufficient, calcGasTotal } from '../../send/send.utils'
import { conversionGreaterThan } from '../../../conversion-util'
import { MIN_GAS_LIMIT_DEC } from '../../send/send.constants'
Expand Down Expand Up @@ -132,12 +126,10 @@ const mapStateToProps = (state, props) => {
unapprovedTxCount,
currentNetworkUnapprovedTxs,
customGas: {
gasLimit: customGasLimit || gasPrice,
gasPrice: customGasPrice || gasLimit,
gasLimit: customGasLimit || gasLimit,
gasPrice: customGasPrice || gasPrice,
},
advancedInlineGasShown: getAdvancedInlineGasShown(state),
gasPrice: convertGasPriceForInputs(gasPrice),
gasLimit: convertGasLimitForInputs(gasLimit),
insufficientBalance,
}
}
Expand All @@ -155,12 +147,6 @@ const mapDispatchToProps = dispatch => {
updateGasAndCalculate: ({ gasLimit, gasPrice }) => {
return dispatch(updateGasAndCalculate({ gasLimit, gasPrice }))
},
convertThenUpdateGasAndCalculate: ({ gasLimit, gasPrice }) => {
return dispatch(updateGasAndCalculate({
gasLimit: decimalToHex(gasLimit),
gasPrice: decGWEIToHexWEI(gasPrice),
}))
},
showRejectTransactionsConfirmationModal: ({ onSubmit, unapprovedTxCount }) => {
return dispatch(showModal({ name: 'REJECT_TRANSACTIONS', onSubmit, unapprovedTxCount }))
},
Expand Down Expand Up @@ -235,6 +221,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
validate: validateEditGas,
}),
cancelAllTransactions: () => dispatchCancelAllTransactions(valuesFor(unapprovedTxs)),
updateGasAndCalculate,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ import {
getRenderableEstimateDataForSmallButtonsFromGWEI,
getDefaultActiveButtonIndex,
} from '../../../../selectors/custom-gas'
import {
decGWEIToHexWEI,
decimalToHex,
convertGasPriceForInputs,
convertGasLimitForInputs,
} from '../../../../helpers/conversions.util'
import {
showGasButtonGroup,
} from '../../../../ducks/send.duck'
Expand All @@ -33,17 +27,15 @@ import {
import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js'
import { showModal, setGasPrice, setGasLimit, setGasTotal } from '../../../../actions'
import { getAdvancedInlineGasShown, getCurrentEthBalance } from '../../../../selectors'
import { addHexPrefix } from 'ethereumjs-util'
import SendGasRow from './send-gas-row.component'

export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(SendGasRow)

function mapStateToProps (state) {
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state)
const gasPrice = getGasPrice(state)
const gasLimit = getGasLimit(state)
const activeButtonIndex = getDefaultActiveButtonIndex(gasButtonInfo, gasPrice)
const renderableGasPrice = convertGasPriceForInputs(gasPrice)
const renderableGasLimit = convertGasLimitForInputs(getGasLimit(state))

const gasTotal = getGasTotal(state)
const conversionRate = getConversionRate(state)
Expand All @@ -70,8 +62,8 @@ function mapStateToProps (state) {
},
gasButtonGroupShown: getGasButtonGroupShown(state),
advancedInlineGasShown: getAdvancedInlineGasShown(state),
gasPrice: renderableGasPrice,
gasLimit: renderableGasLimit,
gasPrice,
gasLimit,
insufficientBalance,
}
}
Expand All @@ -80,16 +72,18 @@ function mapDispatchToProps (dispatch) {
return {
showCustomizeGasModal: () => dispatch(showModal({ name: 'CUSTOMIZE_GAS', hideBasic: true })),
setGasPrice: (newPrice, gasLimit) => {
newPrice = decGWEIToHexWEI(newPrice)
dispatch(setGasPrice(newPrice))
dispatch(setCustomGasPrice(addHexPrefix(newPrice)))
dispatch(setGasTotal(calcGasTotal(gasLimit, newPrice)))
dispatch(setCustomGasPrice(newPrice))
if (gasLimit) {
dispatch(setGasTotal(calcGasTotal(gasLimit, newPrice)))
}
},
setGasLimit: (newLimit, gasPrice) => {
newLimit = decimalToHex(newLimit)
dispatch(setGasLimit(newLimit))
dispatch(setCustomGasLimit(addHexPrefix(newLimit.toString(16))))
dispatch(setGasTotal(calcGasTotal(newLimit, gasPrice)))
dispatch(setCustomGasLimit(newLimit))
if (gasPrice) {
dispatch(setGasTotal(calcGasTotal(newLimit, gasPrice)))
}
},
showGasButtonGroup: () => dispatch(showGasButtonGroup()),
resetCustomData: () => dispatch(resetCustomData()),
Expand Down
Loading

0 comments on commit fbc2d58

Please sign in to comment.