mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1430 from MetaMask/i1407-FixNonEditingTxForm
Add test around conf-tx view's gas editing.
This commit is contained in:
commit
9560de80a0
@ -56,6 +56,7 @@
|
|||||||
"debounce": "^1.0.0",
|
"debounce": "^1.0.0",
|
||||||
"deep-extend": "^0.4.1",
|
"deep-extend": "^0.4.1",
|
||||||
"denodeify": "^1.2.1",
|
"denodeify": "^1.2.1",
|
||||||
|
"detect-node": "^2.0.3",
|
||||||
"disc": "^1.3.2",
|
"disc": "^1.3.2",
|
||||||
"dnode": "^1.2.2",
|
"dnode": "^1.2.2",
|
||||||
"end-of-stream": "^1.1.0",
|
"end-of-stream": "^1.1.0",
|
||||||
@ -135,9 +136,11 @@
|
|||||||
"browserify": "^13.0.0",
|
"browserify": "^13.0.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"clone": "^1.0.2",
|
"clone": "^1.0.2",
|
||||||
|
"create-react-factory": "^0.2.1",
|
||||||
"deep-freeze-strict": "^1.1.1",
|
"deep-freeze-strict": "^1.1.1",
|
||||||
"del": "^2.2.0",
|
"del": "^2.2.0",
|
||||||
"envify": "^4.0.0",
|
"envify": "^4.0.0",
|
||||||
|
"enzyme": "^2.8.2",
|
||||||
"eslint-plugin-chai": "0.0.1",
|
"eslint-plugin-chai": "0.0.1",
|
||||||
"eslint-plugin-mocha": "^4.9.0",
|
"eslint-plugin-mocha": "^4.9.0",
|
||||||
"fs-promise": "^1.0.0",
|
"fs-promise": "^1.0.0",
|
||||||
@ -164,6 +167,10 @@
|
|||||||
"prompt": "^1.0.0",
|
"prompt": "^1.0.0",
|
||||||
"qs": "^6.2.0",
|
"qs": "^6.2.0",
|
||||||
"qunit": "^0.9.1",
|
"qunit": "^0.9.1",
|
||||||
|
"react-addons-test-utils": "^15.5.1",
|
||||||
|
"react-dom": "^15.5.4",
|
||||||
|
"react-test-renderer": "^15.5.4",
|
||||||
|
"react-testutils-additions": "^15.2.0",
|
||||||
"sinon": "^1.17.3",
|
"sinon": "^1.17.3",
|
||||||
"tape": "^4.5.1",
|
"tape": "^4.5.1",
|
||||||
"testem": "^1.10.3",
|
"testem": "^1.10.3",
|
||||||
|
18
test/lib/mock-store.js
Normal file
18
test/lib/mock-store.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const createStore = require('redux').createStore
|
||||||
|
const applyMiddleware = require('redux').applyMiddleware
|
||||||
|
const thunkMiddleware = require('redux-thunk')
|
||||||
|
const createLogger = require('redux-logger')
|
||||||
|
const rootReducer = function() {}
|
||||||
|
|
||||||
|
module.exports = configureStore
|
||||||
|
|
||||||
|
const loggerMiddleware = createLogger()
|
||||||
|
|
||||||
|
const createStoreWithMiddleware = applyMiddleware(
|
||||||
|
thunkMiddleware,
|
||||||
|
loggerMiddleware
|
||||||
|
)(createStore)
|
||||||
|
|
||||||
|
function configureStore (initialState) {
|
||||||
|
return createStoreWithMiddleware(rootReducer, initialState)
|
||||||
|
}
|
89
test/unit/components/pending-tx-test.js
Normal file
89
test/unit/components/pending-tx-test.js
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
const assert = require('assert')
|
||||||
|
const additions = require('react-testutils-additions')
|
||||||
|
const h = require('react-hyperscript')
|
||||||
|
const PendingTx = require('../../../ui/app/components/pending-tx')
|
||||||
|
const createReactFactory = require('create-react-factory').createReactFactory
|
||||||
|
const React = require('react')
|
||||||
|
const shallow = require('react-test-renderer/shallow')
|
||||||
|
const Factory = createReactFactory(PendingTx)
|
||||||
|
const ReactTestUtils = require('react-addons-test-utils')
|
||||||
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
|
||||||
|
describe.only('PendingTx', function () {
|
||||||
|
let pendingTxComponent
|
||||||
|
|
||||||
|
const identities = {
|
||||||
|
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826': {
|
||||||
|
name: 'Main Account 1',
|
||||||
|
balance: '0x00000000000000056bc75e2d63100000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const gasPrice = '0x4A817C800' // 20 Gwei
|
||||||
|
const txData = {
|
||||||
|
'id':5021615666270214,
|
||||||
|
'time':1494458763011,
|
||||||
|
'status':'unapproved',
|
||||||
|
'metamaskNetworkId':'1494442339676',
|
||||||
|
'txParams':{
|
||||||
|
'from':'0xfdea65c8e26263f6d9a1b5de9555d2931a33b826',
|
||||||
|
'to':'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||||||
|
'value':'0xde0b6b3a7640000',
|
||||||
|
gasPrice,
|
||||||
|
'gas':'0x7b0c'},
|
||||||
|
'gasLimitSpecified':false,
|
||||||
|
'estimatedGas':'0x5208',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
it('should use updated values when edited.', function (done) {
|
||||||
|
|
||||||
|
const renderer = ReactTestUtils.createRenderer();
|
||||||
|
const newGasPrice = '0x77359400'
|
||||||
|
|
||||||
|
const props = {
|
||||||
|
identities,
|
||||||
|
accounts: identities,
|
||||||
|
txData,
|
||||||
|
sendTransaction: (txMeta, event) => {
|
||||||
|
|
||||||
|
// Assert changes:
|
||||||
|
const result = ethUtil.addHexPrefix(txMeta.txParams.gasPrice)
|
||||||
|
assert.notEqual(result, gasPrice, 'gas price should change')
|
||||||
|
assert.equal(result, newGasPrice, 'gas price assigned.')
|
||||||
|
done()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const pendingTxComponent = h(PendingTx, props)
|
||||||
|
const component = additions.renderIntoDocument(pendingTxComponent);
|
||||||
|
renderer.render(pendingTxComponent)
|
||||||
|
const result = renderer.getRenderOutput()
|
||||||
|
const form = result.props.children
|
||||||
|
const children = form.props.children[form.props.children.length - 1]
|
||||||
|
assert.equal(result.type, 'div', 'should create a div')
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
const input = additions.find(component, '.cell.row input[type="number"]')[1]
|
||||||
|
ReactTestUtils.Simulate.change(input, {
|
||||||
|
target: {
|
||||||
|
value: 2,
|
||||||
|
checkValidity() { return true },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let form = additions.find(component, 'form')[0]
|
||||||
|
form.checkValidity = () => true
|
||||||
|
form.getFormEl = () => { return { checkValidity() { return true } } }
|
||||||
|
ReactTestUtils.Simulate.submit(form, { preventDefault() {}, target: { checkValidity() {return true} } })
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log("WHAAAA")
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
@ -29,6 +29,7 @@ function mapStateToProps (state) {
|
|||||||
unapprovedMsgs: valuesFor(state.metamask.unapprovedMsgs),
|
unapprovedMsgs: valuesFor(state.metamask.unapprovedMsgs),
|
||||||
shapeShiftTxList: state.metamask.shapeShiftTxList,
|
shapeShiftTxList: state.metamask.shapeShiftTxList,
|
||||||
transactions: state.metamask.selectedAddressTxList || [],
|
transactions: state.metamask.selectedAddressTxList || [],
|
||||||
|
conversionRate: state.metamask.conversionRate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ AccountDetailScreen.prototype.render = function () {
|
|||||||
var checksumAddress = selected && ethUtil.toChecksumAddress(selected)
|
var checksumAddress = selected && ethUtil.toChecksumAddress(selected)
|
||||||
var identity = props.identities[selected]
|
var identity = props.identities[selected]
|
||||||
var account = props.accounts[selected]
|
var account = props.accounts[selected]
|
||||||
const { network } = props
|
const { network, conversionRate } = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
@ -182,6 +183,7 @@ AccountDetailScreen.prototype.render = function () {
|
|||||||
|
|
||||||
h(EthBalance, {
|
h(EthBalance, {
|
||||||
value: account && account.balance,
|
value: account && account.balance,
|
||||||
|
conversionRate,
|
||||||
style: {
|
style: {
|
||||||
lineHeight: '7px',
|
lineHeight: '7px',
|
||||||
marginTop: '10px',
|
marginTop: '10px',
|
||||||
@ -243,11 +245,13 @@ AccountDetailScreen.prototype.subview = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AccountDetailScreen.prototype.transactionList = function () {
|
AccountDetailScreen.prototype.transactionList = function () {
|
||||||
const {transactions, unapprovedMsgs, address, network, shapeShiftTxList } = this.props
|
const {transactions, unapprovedMsgs, address,
|
||||||
|
network, shapeShiftTxList, conversionRate } = this.props
|
||||||
return h(TransactionList, {
|
return h(TransactionList, {
|
||||||
transactions: transactions.sort((a, b) => b.time - a.time),
|
transactions: transactions.sort((a, b) => b.time - a.time),
|
||||||
network,
|
network,
|
||||||
unapprovedMsgs,
|
unapprovedMsgs,
|
||||||
|
conversionRate,
|
||||||
address,
|
address,
|
||||||
shapeShiftTxList,
|
shapeShiftTxList,
|
||||||
viewPendingTx: (txId) => {
|
viewPendingTx: (txId) => {
|
||||||
|
@ -15,7 +15,7 @@ function AccountListItem () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AccountListItem.prototype.render = function () {
|
AccountListItem.prototype.render = function () {
|
||||||
const { identity, selectedAddress, accounts, onShowDetail } = this.props
|
const { identity, selectedAddress, accounts, onShowDetail, conversionRate } = this.props
|
||||||
|
|
||||||
const checksumAddress = identity && identity.address && ethUtil.toChecksumAddress(identity.address)
|
const checksumAddress = identity && identity.address && ethUtil.toChecksumAddress(identity.address)
|
||||||
const isSelected = selectedAddress === identity.address
|
const isSelected = selectedAddress === identity.address
|
||||||
@ -52,6 +52,7 @@ AccountListItem.prototype.render = function () {
|
|||||||
}, checksumAddress),
|
}, checksumAddress),
|
||||||
h(EthBalance, {
|
h(EthBalance, {
|
||||||
value: account && account.balance,
|
value: account && account.balance,
|
||||||
|
conversionRate,
|
||||||
style: {
|
style: {
|
||||||
lineHeight: '7px',
|
lineHeight: '7px',
|
||||||
marginTop: '10px',
|
marginTop: '10px',
|
||||||
|
@ -23,6 +23,7 @@ function mapStateToProps (state) {
|
|||||||
scrollToBottom: state.appState.scrollToBottom,
|
scrollToBottom: state.appState.scrollToBottom,
|
||||||
pending,
|
pending,
|
||||||
keyrings: state.metamask.keyrings,
|
keyrings: state.metamask.keyrings,
|
||||||
|
conversionRate: state.metamask.conversionRate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ function AccountsScreen () {
|
|||||||
|
|
||||||
AccountsScreen.prototype.render = function () {
|
AccountsScreen.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const { keyrings } = props
|
const { keyrings, conversionRate } = props
|
||||||
const identityList = valuesFor(props.identities)
|
const identityList = valuesFor(props.identities)
|
||||||
const unapprovedTxList = valuesFor(props.unapprovedTxs)
|
const unapprovedTxList = valuesFor(props.unapprovedTxs)
|
||||||
|
|
||||||
@ -81,6 +82,7 @@ AccountsScreen.prototype.render = function () {
|
|||||||
key: `acct-panel-${identity.address}`,
|
key: `acct-panel-${identity.address}`,
|
||||||
identity,
|
identity,
|
||||||
selectedAddress: this.props.selectedAddress,
|
selectedAddress: this.props.selectedAddress,
|
||||||
|
conversionRate,
|
||||||
accounts: this.props.accounts,
|
accounts: this.props.accounts,
|
||||||
onShowDetail: this.onShowDetail.bind(this),
|
onShowDetail: this.onShowDetail.bind(this),
|
||||||
pending,
|
pending,
|
||||||
|
@ -168,6 +168,7 @@ EnsInput.prototype.ensIconContents = function (recipient) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNetworkEnsSupport(network) {
|
function getNetworkEnsSupport (network) {
|
||||||
return Boolean(networkMap[network])
|
return Boolean(networkMap[network])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,20 +16,19 @@ function EthBalanceComponent () {
|
|||||||
EthBalanceComponent.prototype.render = function () {
|
EthBalanceComponent.prototype.render = function () {
|
||||||
var props = this.props
|
var props = this.props
|
||||||
let { value } = props
|
let { value } = props
|
||||||
var style = props.style
|
const { style, width } = props
|
||||||
var needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true
|
var needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true
|
||||||
value = value ? formatBalance(value, 6, needsParse) : '...'
|
value = value ? formatBalance(value, 6, needsParse) : '...'
|
||||||
var width = props.width
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
h('.ether-balance.ether-balance-amount', {
|
h('.ether-balance.ether-balance-amount', {
|
||||||
style: style,
|
style,
|
||||||
}, [
|
}, [
|
||||||
h('div', {
|
h('div', {
|
||||||
style: {
|
style: {
|
||||||
display: 'inline',
|
display: 'inline',
|
||||||
width: width,
|
width,
|
||||||
},
|
},
|
||||||
}, this.renderBalance(value)),
|
}, this.renderBalance(value)),
|
||||||
])
|
])
|
||||||
@ -38,16 +37,17 @@ EthBalanceComponent.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
EthBalanceComponent.prototype.renderBalance = function (value) {
|
EthBalanceComponent.prototype.renderBalance = function (value) {
|
||||||
var props = this.props
|
var props = this.props
|
||||||
|
const { conversionRate, shorten, incoming } = props
|
||||||
if (value === 'None') return value
|
if (value === 'None') return value
|
||||||
if (value === '...') return value
|
if (value === '...') return value
|
||||||
var balanceObj = generateBalanceObject(value, props.shorten ? 1 : 3)
|
var balanceObj = generateBalanceObject(value, shorten ? 1 : 3)
|
||||||
var balance
|
var balance
|
||||||
var splitBalance = value.split(' ')
|
var splitBalance = value.split(' ')
|
||||||
var ethNumber = splitBalance[0]
|
var ethNumber = splitBalance[0]
|
||||||
var ethSuffix = splitBalance[1]
|
var ethSuffix = splitBalance[1]
|
||||||
const showFiat = 'showFiat' in props ? props.showFiat : true
|
const showFiat = 'showFiat' in props ? props.showFiat : true
|
||||||
|
|
||||||
if (props.shorten) {
|
if (shorten) {
|
||||||
balance = balanceObj.shortBalance
|
balance = balanceObj.shortBalance
|
||||||
} else {
|
} else {
|
||||||
balance = balanceObj.balance
|
balance = balanceObj.balance
|
||||||
@ -73,7 +73,7 @@ EthBalanceComponent.prototype.renderBalance = function (value) {
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
},
|
},
|
||||||
}, this.props.incoming ? `+${balance}` : balance),
|
}, incoming ? `+${balance}` : balance),
|
||||||
h('div', {
|
h('div', {
|
||||||
style: {
|
style: {
|
||||||
color: ' #AEAEAE',
|
color: ' #AEAEAE',
|
||||||
@ -83,7 +83,7 @@ EthBalanceComponent.prototype.renderBalance = function (value) {
|
|||||||
}, label),
|
}, label),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
showFiat ? h(FiatValue, { value: props.value }) : null,
|
showFiat ? h(FiatValue, { value, conversionRate }) : null,
|
||||||
]))
|
]))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,9 @@
|
|||||||
const Component = require('react').Component
|
const Component = require('react').Component
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const connect = require('react-redux').connect
|
|
||||||
const formatBalance = require('../util').formatBalance
|
const formatBalance = require('../util').formatBalance
|
||||||
|
|
||||||
module.exports = connect(mapStateToProps)(FiatValue)
|
module.exports = FiatValue
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
|
||||||
return {
|
|
||||||
conversionRate: state.metamask.conversionRate,
|
|
||||||
currentCurrency: state.metamask.currentCurrency,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inherits(FiatValue, Component)
|
inherits(FiatValue, Component)
|
||||||
function FiatValue () {
|
function FiatValue () {
|
||||||
@ -20,14 +12,16 @@ function FiatValue () {
|
|||||||
|
|
||||||
FiatValue.prototype.render = function () {
|
FiatValue.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
|
const { conversionRate } = props
|
||||||
|
|
||||||
const value = formatBalance(props.value, 6)
|
const value = formatBalance(props.value, 6)
|
||||||
|
|
||||||
if (value === 'None') return value
|
if (value === 'None') return value
|
||||||
var fiatDisplayNumber, fiatTooltipNumber
|
var fiatDisplayNumber, fiatTooltipNumber
|
||||||
var splitBalance = value.split(' ')
|
var splitBalance = value.split(' ')
|
||||||
|
|
||||||
if (props.conversionRate !== 0) {
|
if (conversionRate !== 0) {
|
||||||
fiatTooltipNumber = Number(splitBalance[0]) * props.conversionRate
|
fiatTooltipNumber = Number(splitBalance[0]) * conversionRate
|
||||||
fiatDisplayNumber = fiatTooltipNumber.toFixed(2)
|
fiatDisplayNumber = fiatTooltipNumber.toFixed(2)
|
||||||
} else {
|
} else {
|
||||||
fiatDisplayNumber = 'N/A'
|
fiatDisplayNumber = 'N/A'
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const Component = require('react').Component
|
const Component = require('react').Component
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
|
const isNode = require('detect-node')
|
||||||
const findDOMNode = require('react-dom').findDOMNode
|
const findDOMNode = require('react-dom').findDOMNode
|
||||||
const jazzicon = require('jazzicon')
|
const jazzicon = require('jazzicon')
|
||||||
const iconFactoryGen = require('../../lib/icon-factory')
|
const iconFactoryGen = require('../../lib/icon-factory')
|
||||||
@ -40,8 +41,10 @@ IdenticonComponent.prototype.componentDidMount = function () {
|
|||||||
|
|
||||||
var container = findDOMNode(this)
|
var container = findDOMNode(this)
|
||||||
var diameter = props.diameter || this.defaultDiameter
|
var diameter = props.diameter || this.defaultDiameter
|
||||||
var img = iconFactory.iconForAddress(address, diameter, false)
|
if (!isNode) {
|
||||||
container.appendChild(img)
|
var img = iconFactory.iconForAddress(address, diameter, false)
|
||||||
|
container.appendChild(img)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IdenticonComponent.prototype.componentDidUpdate = function () {
|
IdenticonComponent.prototype.componentDidUpdate = function () {
|
||||||
@ -58,6 +61,8 @@ IdenticonComponent.prototype.componentDidUpdate = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var diameter = props.diameter || this.defaultDiameter
|
var diameter = props.diameter || this.defaultDiameter
|
||||||
var img = iconFactory.iconForAddress(address, diameter, false)
|
if (!isNode) {
|
||||||
container.appendChild(img)
|
var img = iconFactory.iconForAddress(address, diameter, false)
|
||||||
|
container.appendChild(img)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
const Component = require('react').Component
|
const Component = require('react').Component
|
||||||
const connect = require('react-redux').connect
|
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const actions = require('../actions')
|
const actions = require('../actions')
|
||||||
@ -20,12 +19,7 @@ const GWEI_FACTOR = new BN(1e9)
|
|||||||
const MIN_GAS_PRICE_BN = MIN_GAS_PRICE_GWEI_BN.mul(GWEI_FACTOR)
|
const MIN_GAS_PRICE_BN = MIN_GAS_PRICE_GWEI_BN.mul(GWEI_FACTOR)
|
||||||
const MIN_GAS_LIMIT_BN = new BN(21000)
|
const MIN_GAS_LIMIT_BN = new BN(21000)
|
||||||
|
|
||||||
module.exports = connect(mapStateToProps)(PendingTx)
|
module.exports = PendingTx
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
inherits(PendingTx, Component)
|
inherits(PendingTx, Component)
|
||||||
function PendingTx () {
|
function PendingTx () {
|
||||||
Component.call(this)
|
Component.call(this)
|
||||||
@ -37,7 +31,7 @@ function PendingTx () {
|
|||||||
|
|
||||||
PendingTx.prototype.render = function () {
|
PendingTx.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
|
const conversionRate = props.conversionRate
|
||||||
const txMeta = this.gatherTxMeta()
|
const txMeta = this.gatherTxMeta()
|
||||||
const txParams = txMeta.txParams || {}
|
const txParams = txMeta.txParams || {}
|
||||||
|
|
||||||
@ -61,7 +55,6 @@ PendingTx.prototype.render = function () {
|
|||||||
const maxCost = txFeeBn.add(valueBn)
|
const maxCost = txFeeBn.add(valueBn)
|
||||||
|
|
||||||
const dataLength = txParams.data ? (txParams.data.length - 2) / 2 : 0
|
const dataLength = txParams.data ? (txParams.data.length - 2) / 2 : 0
|
||||||
const imageify = props.imageifyIdenticons === undefined ? true : props.imageifyIdenticons
|
|
||||||
|
|
||||||
const balanceBn = hexToBn(balance)
|
const balanceBn = hexToBn(balance)
|
||||||
const insufficientBalance = balanceBn.lt(maxCost)
|
const insufficientBalance = balanceBn.lt(maxCost)
|
||||||
@ -75,18 +68,8 @@ PendingTx.prototype.render = function () {
|
|||||||
}, [
|
}, [
|
||||||
|
|
||||||
h('form#pending-tx-form', {
|
h('form#pending-tx-form', {
|
||||||
onSubmit: (event) => {
|
onSubmit: this.onSubmit.bind(this),
|
||||||
const txMeta = this.gatherTxMeta()
|
|
||||||
event.preventDefault()
|
|
||||||
const form = document.querySelector('form#pending-tx-form')
|
|
||||||
const valid = form.checkValidity()
|
|
||||||
this.setState({ valid })
|
|
||||||
if (valid && this.verifyGasParams()) {
|
|
||||||
props.sendTransaction(txMeta, event)
|
|
||||||
} else {
|
|
||||||
this.props.dispatch(actions.displayWarning('Invalid Gas Parameters'))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
// tx info
|
// tx info
|
||||||
@ -100,7 +83,6 @@ PendingTx.prototype.render = function () {
|
|||||||
|
|
||||||
h(MiniAccountPanel, {
|
h(MiniAccountPanel, {
|
||||||
imageSeed: address,
|
imageSeed: address,
|
||||||
imageifyIdenticons: imageify,
|
|
||||||
picOrder: 'right',
|
picOrder: 'right',
|
||||||
}, [
|
}, [
|
||||||
h('span.font-small', {
|
h('span.font-small', {
|
||||||
@ -121,6 +103,7 @@ PendingTx.prototype.render = function () {
|
|||||||
}, [
|
}, [
|
||||||
h(EthBalance, {
|
h(EthBalance, {
|
||||||
value: balance,
|
value: balance,
|
||||||
|
conversionRate,
|
||||||
inline: true,
|
inline: true,
|
||||||
labelColor: '#F7861C',
|
labelColor: '#F7861C',
|
||||||
}),
|
}),
|
||||||
@ -176,12 +159,8 @@ PendingTx.prototype.render = function () {
|
|||||||
position: 'relative',
|
position: 'relative',
|
||||||
top: '5px',
|
top: '5px',
|
||||||
},
|
},
|
||||||
onChange: (newHex) => {
|
onChange: this.gasLimitChanged.bind(this),
|
||||||
log.info(`Gas limit changed to ${newHex}`)
|
|
||||||
const txMeta = this.gatherTxMeta()
|
|
||||||
txMeta.txParams.gas = newHex
|
|
||||||
this.setState({ txData: txMeta })
|
|
||||||
},
|
|
||||||
ref: (hexInput) => { this.inputs.push(hexInput) },
|
ref: (hexInput) => { this.inputs.push(hexInput) },
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
@ -201,13 +180,7 @@ PendingTx.prototype.render = function () {
|
|||||||
position: 'relative',
|
position: 'relative',
|
||||||
top: '5px',
|
top: '5px',
|
||||||
},
|
},
|
||||||
onChange: (newHex) => {
|
onChange: this.gasPriceChanged.bind(this),
|
||||||
log.info(`Gas price changed to: ${newHex}`)
|
|
||||||
const inWei = hexToBn(newHex).mul(GWEI_FACTOR)
|
|
||||||
const txMeta = this.gatherTxMeta()
|
|
||||||
txMeta.txParams.gasPrice = inWei.toString(16)
|
|
||||||
this.setState({ txData: txMeta })
|
|
||||||
},
|
|
||||||
ref: (hexInput) => { this.inputs.push(hexInput) },
|
ref: (hexInput) => { this.inputs.push(hexInput) },
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
@ -331,13 +304,11 @@ PendingTx.prototype.miniAccountPanelForRecipient = function () {
|
|||||||
const txData = props.txData
|
const txData = props.txData
|
||||||
const txParams = txData.txParams || {}
|
const txParams = txData.txParams || {}
|
||||||
const isContractDeploy = !('to' in txParams)
|
const isContractDeploy = !('to' in txParams)
|
||||||
const imageify = props.imageifyIdenticons === undefined ? true : props.imageifyIdenticons
|
|
||||||
|
|
||||||
// If it's not a contract deploy, send to the account
|
// If it's not a contract deploy, send to the account
|
||||||
if (!isContractDeploy) {
|
if (!isContractDeploy) {
|
||||||
return h(MiniAccountPanel, {
|
return h(MiniAccountPanel, {
|
||||||
imageSeed: txParams.to,
|
imageSeed: txParams.to,
|
||||||
imageifyIdenticons: imageify,
|
|
||||||
picOrder: 'left',
|
picOrder: 'left',
|
||||||
}, [
|
}, [
|
||||||
h('span.font-small', {
|
h('span.font-small', {
|
||||||
@ -353,7 +324,6 @@ PendingTx.prototype.miniAccountPanelForRecipient = function () {
|
|||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
return h(MiniAccountPanel, {
|
return h(MiniAccountPanel, {
|
||||||
imageifyIdenticons: imageify,
|
|
||||||
picOrder: 'left',
|
picOrder: 'left',
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
@ -367,6 +337,21 @@ PendingTx.prototype.miniAccountPanelForRecipient = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PendingTx.prototype.gasPriceChanged = function (newHex) {
|
||||||
|
log.info(`Gas price changed to: ${newHex}`)
|
||||||
|
const inWei = hexToBn(newHex).mul(GWEI_FACTOR)
|
||||||
|
const txMeta = this.gatherTxMeta()
|
||||||
|
txMeta.txParams.gasPrice = inWei.toString(16)
|
||||||
|
this.setState({ txData: txMeta })
|
||||||
|
}
|
||||||
|
|
||||||
|
PendingTx.prototype.gasLimitChanged = function (newHex) {
|
||||||
|
log.info(`Gas limit changed to ${newHex}`)
|
||||||
|
const txMeta = this.gatherTxMeta()
|
||||||
|
txMeta.txParams.gas = newHex
|
||||||
|
this.setState({ txData: txMeta })
|
||||||
|
}
|
||||||
|
|
||||||
PendingTx.prototype.resetGasFields = function () {
|
PendingTx.prototype.resetGasFields = function () {
|
||||||
log.debug(`pending-tx resetGasFields`)
|
log.debug(`pending-tx resetGasFields`)
|
||||||
|
|
||||||
@ -382,6 +367,33 @@ PendingTx.prototype.resetGasFields = function () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PendingTx.prototype.onSubmit = function (event) {
|
||||||
|
event.preventDefault()
|
||||||
|
const txMeta = this.gatherTxMeta()
|
||||||
|
const valid = this.checkValidity()
|
||||||
|
this.setState({ valid })
|
||||||
|
if (valid && this.verifyGasParams()) {
|
||||||
|
this.props.sendTransaction(txMeta, event)
|
||||||
|
} else {
|
||||||
|
this.props.dispatch(actions.displayWarning('Invalid Gas Parameters'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PendingTx.prototype.checkValidity = function () {
|
||||||
|
const form = this.getFormEl()
|
||||||
|
const valid = form.checkValidity()
|
||||||
|
return valid
|
||||||
|
}
|
||||||
|
|
||||||
|
PendingTx.prototype.getFormEl = function () {
|
||||||
|
const form = document.querySelector('form#pending-tx-form')
|
||||||
|
// Stub out form for unit tests:
|
||||||
|
if (!form) {
|
||||||
|
return { checkValidity () { return true } }
|
||||||
|
}
|
||||||
|
return form
|
||||||
|
}
|
||||||
|
|
||||||
// After a customizable state value has been updated,
|
// After a customizable state value has been updated,
|
||||||
PendingTx.prototype.gatherTxMeta = function () {
|
PendingTx.prototype.gatherTxMeta = function () {
|
||||||
log.debug(`pending-tx gatherTxMeta`)
|
log.debug(`pending-tx gatherTxMeta`)
|
||||||
|
@ -15,7 +15,9 @@ const Tooltip = require('./tooltip')
|
|||||||
module.exports = connect(mapStateToProps)(ShiftListItem)
|
module.exports = connect(mapStateToProps)(ShiftListItem)
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
return {}
|
return {
|
||||||
|
conversionRate: state.metamask.conversionRate,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(ShiftListItem, Component)
|
inherits(ShiftListItem, Component)
|
||||||
@ -64,6 +66,7 @@ function formatDate (date) {
|
|||||||
|
|
||||||
ShiftListItem.prototype.renderUtilComponents = function () {
|
ShiftListItem.prototype.renderUtilComponents = function () {
|
||||||
var props = this.props
|
var props = this.props
|
||||||
|
const { conversionRate } = props
|
||||||
|
|
||||||
switch (props.response.status) {
|
switch (props.response.status) {
|
||||||
case 'no_deposits':
|
case 'no_deposits':
|
||||||
@ -96,6 +99,7 @@ ShiftListItem.prototype.renderUtilComponents = function () {
|
|||||||
}),
|
}),
|
||||||
h(EtherBalance, {
|
h(EtherBalance, {
|
||||||
value: `${props.response.outgoingCoin}`,
|
value: `${props.response.outgoingCoin}`,
|
||||||
|
conversionRate,
|
||||||
width: '55px',
|
width: '55px',
|
||||||
shorten: true,
|
shorten: true,
|
||||||
needsParse: false,
|
needsParse: false,
|
||||||
|
@ -19,7 +19,7 @@ function TransactionListItem () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransactionListItem.prototype.render = function () {
|
TransactionListItem.prototype.render = function () {
|
||||||
const { transaction, network } = this.props
|
const { transaction, network, conversionRate } = this.props
|
||||||
if (transaction.key === 'shapeshift') {
|
if (transaction.key === 'shapeshift') {
|
||||||
if (network === '1') return h(ShiftListItem, transaction)
|
if (network === '1') return h(ShiftListItem, transaction)
|
||||||
}
|
}
|
||||||
@ -80,6 +80,7 @@ TransactionListItem.prototype.render = function () {
|
|||||||
|
|
||||||
isTx ? h(EtherBalance, {
|
isTx ? h(EtherBalance, {
|
||||||
value: txParams.value,
|
value: txParams.value,
|
||||||
|
conversionRate,
|
||||||
width: '55px',
|
width: '55px',
|
||||||
shorten: true,
|
shorten: true,
|
||||||
showFiat: false,
|
showFiat: false,
|
||||||
|
@ -13,7 +13,7 @@ function TransactionList () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransactionList.prototype.render = function () {
|
TransactionList.prototype.render = function () {
|
||||||
const { transactions, network, unapprovedMsgs } = this.props
|
const { transactions, network, unapprovedMsgs, conversionRate } = this.props
|
||||||
|
|
||||||
var shapeShiftTxList
|
var shapeShiftTxList
|
||||||
if (network === '1') {
|
if (network === '1') {
|
||||||
@ -69,6 +69,7 @@ TransactionList.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
return h(TransactionListItem, {
|
return h(TransactionListItem, {
|
||||||
transaction, i, network, key,
|
transaction, i, network, key,
|
||||||
|
conversionRate,
|
||||||
showTx: (txId) => {
|
showTx: (txId) => {
|
||||||
this.props.viewPendingTx(txId)
|
this.props.viewPendingTx(txId)
|
||||||
},
|
},
|
||||||
|
@ -27,6 +27,7 @@ function mapStateToProps (state) {
|
|||||||
warning: state.appState.warning,
|
warning: state.appState.warning,
|
||||||
network: state.metamask.network,
|
network: state.metamask.network,
|
||||||
provider: state.metamask.provider,
|
provider: state.metamask.provider,
|
||||||
|
conversionRate: state.metamask.conversionRate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ function ConfirmTxScreen () {
|
|||||||
ConfirmTxScreen.prototype.render = function () {
|
ConfirmTxScreen.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const { network, provider, unapprovedTxs,
|
const { network, provider, unapprovedTxs,
|
||||||
unapprovedMsgs, unapprovedPersonalMsgs } = props
|
unapprovedMsgs, unapprovedPersonalMsgs, conversionRate } = props
|
||||||
|
|
||||||
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
|
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
|
||||||
|
|
||||||
@ -102,6 +103,7 @@ ConfirmTxScreen.prototype.render = function () {
|
|||||||
selectedAddress: props.selectedAddress,
|
selectedAddress: props.selectedAddress,
|
||||||
accounts: props.accounts,
|
accounts: props.accounts,
|
||||||
identities: props.identities,
|
identities: props.identities,
|
||||||
|
conversionRate,
|
||||||
// Actions
|
// Actions
|
||||||
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress),
|
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress),
|
||||||
sendTransaction: this.sendTransaction.bind(this, txData),
|
sendTransaction: this.sendTransaction.bind(this, txData),
|
||||||
|
@ -21,6 +21,7 @@ function mapStateToProps (state) {
|
|||||||
warning: state.appState.warning,
|
warning: state.appState.warning,
|
||||||
network: state.metamask.network,
|
network: state.metamask.network,
|
||||||
addressBook: state.metamask.addressBook,
|
addressBook: state.metamask.addressBook,
|
||||||
|
conversionRate: state.metamask.conversionRate,
|
||||||
}
|
}
|
||||||
|
|
||||||
result.error = result.warning && result.warning.split('.')[0]
|
result.error = result.warning && result.warning.split('.')[0]
|
||||||
@ -40,13 +41,16 @@ function SendTransactionScreen () {
|
|||||||
SendTransactionScreen.prototype.render = function () {
|
SendTransactionScreen.prototype.render = function () {
|
||||||
this.persistentFormParentId = 'send-tx-form'
|
this.persistentFormParentId = 'send-tx-form'
|
||||||
|
|
||||||
var state = this.props
|
const props = this.props
|
||||||
var address = state.address
|
const {
|
||||||
var account = state.account
|
address,
|
||||||
var identity = state.identity
|
account,
|
||||||
var network = state.network
|
identity,
|
||||||
var identities = state.identities
|
network,
|
||||||
var addressBook = state.addressBook
|
identities,
|
||||||
|
addressBook,
|
||||||
|
conversionRate,
|
||||||
|
} = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
@ -125,6 +129,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
|
|
||||||
h(EthBalance, {
|
h(EthBalance, {
|
||||||
value: account && account.balance,
|
value: account && account.balance,
|
||||||
|
conversionRate,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
]),
|
]),
|
||||||
@ -147,7 +152,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
]),
|
]),
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
state.error && h('span.error.flex-center', state.error),
|
props.error && h('span.error.flex-center', props.error),
|
||||||
|
|
||||||
// 'to' field
|
// 'to' field
|
||||||
h('section.flex-row.flex-center', [
|
h('section.flex-row.flex-center', [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user