1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Remove unused components (#7191)

* Remove unused sendWarnings

The send warnings state and associated component is no longer used
anywhere.

* Remove unused subtitleParams

The `subtitleParams` SendHeader prop was being ignored. It has been
removed, along with associated selectors and tests.
This commit is contained in:
Mark Stacey 2019-09-18 18:41:36 -03:00 committed by GitHub
parent 5b309afc2c
commit 624139a00f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1 additions and 189 deletions

View File

@ -6,7 +6,6 @@ import SendReducer, {
updateSendErrors,
showGasButtonGroup,
hideGasButtonGroup,
updateSendWarnings,
} from './send.duck.js'
describe('Send Duck', () => {
@ -20,14 +19,12 @@ describe('Send Duck', () => {
toDropdownOpen: false,
errors: {},
gasButtonGroupShown: true,
warnings: {},
}
const OPEN_FROM_DROPDOWN = 'metamask/send/OPEN_FROM_DROPDOWN'
const CLOSE_FROM_DROPDOWN = 'metamask/send/CLOSE_FROM_DROPDOWN'
const OPEN_TO_DROPDOWN = 'metamask/send/OPEN_TO_DROPDOWN'
const CLOSE_TO_DROPDOWN = 'metamask/send/CLOSE_TO_DROPDOWN'
const UPDATE_SEND_ERRORS = 'metamask/send/UPDATE_SEND_ERRORS'
const UPDATE_SEND_WARNINGS = 'metamask/send/UPDATE_SEND_WARNINGS'
const RESET_SEND_STATE = 'metamask/send/RESET_SEND_STATE'
const SHOW_GAS_BUTTON_GROUP = 'metamask/send/SHOW_GAS_BUTTON_GROUP'
const HIDE_GAS_BUTTON_GROUP = 'metamask/send/HIDE_GAS_BUTTON_GROUP'
@ -176,11 +173,4 @@ describe('Send Duck', () => {
)
})
describe('updateSendWarnings', () => {
assert.deepEqual(
updateSendWarnings('mockWarningObject'),
{ type: UPDATE_SEND_WARNINGS, value: 'mockWarningObject' }
)
})
})

View File

@ -6,7 +6,6 @@ const CLOSE_FROM_DROPDOWN = 'metamask/send/CLOSE_FROM_DROPDOWN'
const OPEN_TO_DROPDOWN = 'metamask/send/OPEN_TO_DROPDOWN'
const CLOSE_TO_DROPDOWN = 'metamask/send/CLOSE_TO_DROPDOWN'
const UPDATE_SEND_ERRORS = 'metamask/send/UPDATE_SEND_ERRORS'
const UPDATE_SEND_WARNINGS = 'metamask/send/UPDATE_SEND_WARNINGS'
const RESET_SEND_STATE = 'metamask/send/RESET_SEND_STATE'
const SHOW_GAS_BUTTON_GROUP = 'metamask/send/SHOW_GAS_BUTTON_GROUP'
const HIDE_GAS_BUTTON_GROUP = 'metamask/send/HIDE_GAS_BUTTON_GROUP'
@ -17,7 +16,6 @@ const initState = {
toDropdownOpen: false,
gasButtonGroupShown: true,
errors: {},
warnings: {},
}
// Reducer
@ -48,13 +46,6 @@ export default function reducer ({ send: sendState = initState }, action = {}) {
...action.value,
},
})
case UPDATE_SEND_WARNINGS:
return extend(newState, {
warnings: {
...newState.warnings,
...action.value,
},
})
case SHOW_GAS_BUTTON_GROUP:
return extend(newState, {
gasButtonGroupShown: true,
@ -94,13 +85,6 @@ export function updateSendErrors (errorObject) {
}
}
export function updateSendWarnings (warningObject) {
return {
type: UPDATE_SEND_WARNINGS,
value: warningObject,
}
}
export function resetSendState () {
return { type: RESET_SEND_STATE }
}

View File

@ -2,7 +2,6 @@ const selectors = {
getToDropdownOpen,
getTokens,
sendToIsInError,
sendToIsInWarning,
}
module.exports = selectors
@ -15,10 +14,6 @@ function sendToIsInError (state) {
return Boolean(state.send.errors.to)
}
function sendToIsInWarning (state) {
return Boolean(state.send.warnings.to)
}
function getTokens (state) {
return state.metamask.tokens
}

View File

@ -1 +0,0 @@
export { default } from './send-row-warning-message.container'

View File

@ -1,27 +0,0 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
export default class SendRowWarningMessage extends Component {
static propTypes = {
warnings: PropTypes.object,
warningType: PropTypes.string,
};
static contextTypes = {
t: PropTypes.func,
};
render () {
const { warnings, warningType } = this.props
const warningMessage = warningType in warnings && warnings[warningType]
return (
warningMessage
? <div className="send-v2__warning">{this.context.t(warningMessage)}</div>
: null
)
}
}

View File

@ -1,12 +0,0 @@
import { connect } from 'react-redux'
import { getSendWarnings } from '../../../send.selectors'
import SendRowWarningMessage from './send-row-warning-message.component'
export default connect(mapStateToProps)(SendRowWarningMessage)
function mapStateToProps (state, ownProps) {
return {
warnings: getSendWarnings(state),
warningType: ownProps.warningType,
}
}

View File

@ -1,28 +0,0 @@
import React from 'react'
import assert from 'assert'
import { shallow } from 'enzyme'
import SendRowWarningMessage from '../send-row-warning-message.component.js'
describe('SendRowWarningMessage Component', function () {
let wrapper
beforeEach(() => {
wrapper = shallow(<SendRowWarningMessage
warnings={{ warning1: 'abc', warning2: 'def' }}
warningType={'warning3'}
/>, { context: { t: str => str + '_t' } })
})
describe('render', () => {
it('should render null if the passed warnings do not contain a warning of warningType', () => {
assert.equal(wrapper.find('.send-v2__warning').length, 0)
assert.equal(wrapper.html(), null)
})
it('should render a warning message if the passed warnings contain a warning of warningType', () => {
wrapper.setProps({ warnings: { warning1: 'abc', warning2: 'def', warning3: 'xyz' } })
assert.equal(wrapper.find('.send-v2__warning').length, 1)
assert.equal(wrapper.find('.send-v2__warning').text(), 'xyz_t')
})
})
})

View File

@ -1,28 +0,0 @@
import assert from 'assert'
import proxyquire from 'proxyquire'
let mapStateToProps
proxyquire('../send-row-warning-message.container.js', {
'react-redux': {
connect: (ms) => {
mapStateToProps = ms
return () => ({})
},
},
'../../../send.selectors': { getSendWarnings: (s) => `mockWarnings:${s}` },
})
describe('send-row-warning-message container', () => {
describe('mapStateToProps()', () => {
it('should map the correct properties to props', () => {
assert.deepEqual(mapStateToProps('mockState', { warningType: 'someType' }), {
warnings: 'mockWarnings:mockState',
warningType: 'someType' })
})
})
})

View File

@ -1,7 +1,6 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import SendRowErrorMessage from './send-row-error-message'
import SendRowWarningMessage from './send-row-warning-message'
export default class SendRowWrapper extends Component {
@ -10,8 +9,6 @@ export default class SendRowWrapper extends Component {
errorType: PropTypes.string,
label: PropTypes.string,
showError: PropTypes.bool,
showWarning: PropTypes.bool,
warningType: PropTypes.string,
};
static contextTypes = {
@ -24,8 +21,6 @@ export default class SendRowWrapper extends Component {
errorType = '',
label,
showError = false,
showWarning = false,
warningType = '',
} = this.props
const formField = Array.isArray(children) ? children[1] || children[0] : children
const customLabelContent = children.length > 1 ? children[0] : null
@ -42,7 +37,6 @@ export default class SendRowWrapper extends Component {
</div>
<div>
{showError && <SendRowErrorMessage errorType={errorType} />}
{!showError && showWarning && <SendRowWarningMessage warningType={warningType} />}
</div>
</div>
</div>
@ -55,8 +49,6 @@ export default class SendRowWrapper extends Component {
errorType = '',
label,
showError = false,
showWarning = false,
warningType = '',
} = this.props
const formField = Array.isArray(children) ? children[1] || children[0] : children
@ -67,7 +59,6 @@ export default class SendRowWrapper extends Component {
<div className="send-v2__form-label">
{label}
{showError && <SendRowErrorMessage errorType={errorType} />}
{!showError && showWarning && <SendRowWarningMessage warningType={warningType} />}
{customLabelContent}
</div>
<div className="send-v2__form-field">

View File

@ -9,7 +9,6 @@ export default class SendHeader extends Component {
clearSend: PropTypes.func,
history: PropTypes.object,
titleKey: PropTypes.string,
subtitleParams: PropTypes.array,
};
static contextTypes = {

View File

@ -1,14 +1,13 @@
import { connect } from 'react-redux'
import { clearSend } from '../../../store/actions'
import SendHeader from './send-header.component'
import { getSubtitleParams, getTitleKey } from './send-header.selectors'
import { getTitleKey } from './send-header.selectors'
export default connect(mapStateToProps, mapDispatchToProps)(SendHeader)
function mapStateToProps (state) {
return {
titleKey: getTitleKey(state),
subtitleParams: getSubtitleParams(state),
}
}

View File

@ -6,7 +6,6 @@ const {
const selectors = {
getTitleKey,
getSubtitleParams,
}
module.exports = selectors
@ -27,16 +26,3 @@ function getTitleKey (state) {
return 'sendETH'
}
}
function getSubtitleParams (state) {
const isEditing = Boolean(getSendEditingTransactionId(state))
const token = getSelectedToken(state)
if (isEditing) {
return [ 'editingTransaction' ]
} else if (token) {
return [ 'onlySendTokensToAccountAddress', [ token.symbol ] ]
} else {
return [ 'onlySendToEtherAddress' ]
}
}

View File

@ -24,7 +24,6 @@ describe('SendHeader Component', function () {
clearSend={propsMethodSpies.clearSend}
history={historySpies}
titleKey={'mockTitleKey'}
subtitleParams={[ 'mockSubtitleKey', 'mockVal']}
/>, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } })
})

View File

@ -20,7 +20,6 @@ proxyquire('../send-header.container.js', {
'../../../store/actions': actionSpies,
'./send-header.selectors': {
getTitleKey: (s) => `mockTitleKey:${s}`,
getSubtitleParams: (s) => `mockSubtitleParams:${s}`,
},
})
@ -31,7 +30,6 @@ describe('send-header container', () => {
it('should map the correct properties to props', () => {
assert.deepEqual(mapStateToProps('mockState'), {
titleKey: 'mockTitleKey:mockState',
subtitleParams: 'mockSubtitleParams:mockState',
})
})

View File

@ -3,7 +3,6 @@ import proxyquire from 'proxyquire'
const {
getTitleKey,
getSubtitleParams,
} = proxyquire('../send-header.selectors', {
'../send.selectors': {
getSelectedToken: (mockState) => mockState.t,
@ -32,21 +31,4 @@ describe('send-header selectors', () => {
})
})
describe('getSubtitleParams()', () => {
it('should return the correct params when getSendEditingTransactionId is truthy', () => {
assert.deepEqual(getSubtitleParams({ e: 1, t: true, to: '0x123' }), [ 'editingTransaction' ])
})
it('should return the correct params when getSendEditingTransactionId is falsy and getSelectedToken is truthy', () => {
assert.deepEqual(
getSubtitleParams({ e: null, t: { symbol: 'ABC' }, to: '0x123' }),
[ 'onlySendTokensToAccountAddress', [ 'ABC' ] ]
)
})
it('should return the correct params when getSendEditingTransactionId is falsy and getSelectedToken is falsy', () => {
assert.deepEqual(getSubtitleParams({ e: null, to: '0x123' }), [ 'onlySendToEtherAddress' ])
})
})
})

View File

@ -53,7 +53,6 @@ const selectors = {
getSendTo,
getSendToAccounts,
getSendToNickname,
getSendWarnings,
getTokenBalance,
getTokenExchangeRate,
getUnapprovedTxs,
@ -244,11 +243,6 @@ function getSendToAccounts (state) {
const addressBookAccounts = getAddressBook(state)
return [...fromAccounts, ...addressBookAccounts]
}
function getSendWarnings (state) {
return state.send.warnings
}
function getTokenBalance (state) {
return state.metamask.send.tokenBalance
}

View File

@ -190,7 +190,6 @@ var actions = {
UPDATE_SEND_AMOUNT: 'UPDATE_SEND_AMOUNT',
UPDATE_SEND_MEMO: 'UPDATE_SEND_MEMO',
UPDATE_SEND_ERRORS: 'UPDATE_SEND_ERRORS',
UPDATE_SEND_WARNINGS: 'UPDATE_SEND_WARNINGS',
UPDATE_MAX_MODE: 'UPDATE_MAX_MODE',
UPDATE_SEND: 'UPDATE_SEND',
CLEAR_SEND: 'CLEAR_SEND',
@ -215,7 +214,6 @@ var actions = {
setMaxModeTo,
updateSend,
updateSendErrors,
updateSendWarnings,
clearSend,
setSelectedAddress,
gasLoadingStarted,
@ -1037,13 +1035,6 @@ function updateSendErrors (errorObject) {
}
}
function updateSendWarnings (warningObject) {
return {
type: actions.UPDATE_SEND_WARNINGS,
value: warningObject,
}
}
function setSendTokenBalance (tokenBalance) {
return {
type: actions.UPDATE_SEND_TOKEN_BALANCE,