Skip to content

Commit

Permalink
Decouple ens-input.component from send context
Browse files Browse the repository at this point in the history
  • Loading branch information
danjm committed Jul 25, 2019
1 parent 157e7d6 commit 1418145
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions test/unit/ui/app/reducers/metamask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ describe('MetaMask Reducers', () => {

it('update ensResolution', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_ENS_RESOLUTION,
type: actions.UPDATE_SEND_ENS_RESOLUTION,
payload: '0x1337',
})

Expand All @@ -543,7 +543,7 @@ describe('MetaMask Reducers', () => {

it('update ensResolutionError', () => {
const state = reduceMetamask({}, {
type: actions.UPDATE_ENS_RESOLUTION_ERROR,
type: actions.UPDATE_SEND_ENS_RESOLUTION_ERROR,
payload: 'ens name not found',
})

Expand Down
4 changes: 2 additions & 2 deletions ui/app/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function reduceMetamask (state, action) {
},
})

case actions.UPDATE_ENS_RESOLUTION:
case actions.UPDATE_SEND_ENS_RESOLUTION:
return extend(metamaskState, {
send: {
...metamaskState.send,
Expand All @@ -301,7 +301,7 @@ function reduceMetamask (state, action) {
},
})

case actions.UPDATE_ENS_RESOLUTION_ERROR:
case actions.UPDATE_SEND_ENS_RESOLUTION_ERROR:
return extend(metamaskState, {
send: {
...metamaskState.send,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class EnsInput extends Component {
scanQrCode: PropTypes.func,
updateEnsResolutionError: PropTypes.func,
addressBook: PropTypes.array,
onPaste: PropTypes.func,
onReset: PropTypes.func,
}

state = {
Expand Down Expand Up @@ -69,9 +71,9 @@ export default class EnsInput extends Component {
}

resetInput = () => {
const { updateSendTo, updateEnsResolution, updateEnsResolutionError } = this.props
const { updateEnsResolution, updateEnsResolutionError, onReset } = this.props
this.onChange({ target: { value: '' } })
updateSendTo('', '')
onReset()
updateEnsResolution('')
updateEnsResolutionError('')
}
Expand All @@ -98,13 +100,12 @@ export default class EnsInput extends Component {
onPaste = event => {
event.clipboardData.items[0].getAsString(text => {
if (isValidAddress(text)) {
this.props.updateSendTo(text)
this.props.onPaste(text)
}
})
}

onChange = e => {
console.log('onchange', e.target.value)
const { network, onChange, updateEnsResolution, updateEnsResolutionError } = this.props
const input = e.target.value
const networkHasEnsSupport = getNetworkEnsSupport(network)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import {
import {
getAddressBook,
} from '../../../../selectors/selectors'
import {
updateSendTo,
updateEnsResolution,
updateEnsResolutionError,
} from '../../../../store/actions'
const connect = require('react-redux').connect


Expand All @@ -21,10 +16,5 @@ export default connect(
selectedAddress: getSendTo(state),
selectedName: getSendToNickname(state),
addressBook: getAddressBook(state),
}),
dispatch => ({
updateSendTo: (to, nickname) => dispatch(updateSendTo(to, nickname)),
updateEnsResolution: (ensResolution) => dispatch(updateEnsResolution(ensResolution)),
updateEnsResolutionError: (message) => dispatch(updateEnsResolutionError(message)),
})
)(EnsInput)
4 changes: 4 additions & 0 deletions ui/app/pages/send/send.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ export default class SendTransactionScreen extends PersistentForm {
this.props.scanQrCode()
}}
onChange={this.onRecipientInputChange}
onPaste={text => this.props.updateSendTo(text)}
onReset={() => this.props.updateSendTo('', '')}
updateEnsResolution={this.props.updateSendEnsResolution}
updateEnsResolutionError={this.props.updateSendEnsResolutionError}
/>
)
}
Expand Down
4 changes: 4 additions & 0 deletions ui/app/pages/send/send.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
setGasTotal,
showQrScanner,
qrCodeDetected,
updateSendEnsResolution,
updateSendEnsResolutionError,
} from '../../store/actions'
import {
resetSendState,
Expand Down Expand Up @@ -119,5 +121,7 @@ function mapDispatchToProps (dispatch) {
qrCodeDetected: (data) => dispatch(qrCodeDetected(data)),
updateSendTo: (to, nickname) => dispatch(updateSendTo(to, nickname)),
fetchBasicGasEstimates: () => dispatch(fetchBasicGasEstimates()),
updateSendEnsResolution: (ensResolution) => dispatch(updateSendEnsResolution(ensResolution)),
updateSendEnsResolutionError: (message) => dispatch(updateSendEnsResolutionError(message)),
}
}
16 changes: 8 additions & 8 deletions ui/app/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ var actions = {
CLOSE_FROM_DROPDOWN: 'CLOSE_FROM_DROPDOWN',
GAS_LOADING_STARTED: 'GAS_LOADING_STARTED',
GAS_LOADING_FINISHED: 'GAS_LOADING_FINISHED',
UPDATE_ENS_RESOLUTION: 'UPDATE_ENS_RESOLUTION',
UPDATE_ENS_RESOLUTION_ERROR: 'UPDATE_ENS_RESOLUTION_ERROR',
updateEnsResolution,
updateEnsResolutionError,
UPDATE_SEND_ENS_RESOLUTION: 'UPDATE_SEND_ENS_RESOLUTION',
UPDATE_SEND_ENS_RESOLUTION_ERROR: 'UPDATE_SEND_ENS_RESOLUTION_ERROR',
updateSendEnsResolution,
updateSendEnsResolutionError,
setGasLimit,
setGasPrice,
updateGasData,
Expand Down Expand Up @@ -1173,16 +1173,16 @@ function clearSend () {
}
}

function updateEnsResolution (ensResolution) {
function updateSendEnsResolution (ensResolution) {
return {
type: actions.UPDATE_ENS_RESOLUTION,
type: actions.UPDATE_SEND_ENS_RESOLUTION,
payload: ensResolution,
}
}

function updateEnsResolutionError (errorMessage) {
function updateSendEnsResolutionError (errorMessage) {
return {
type: actions.UPDATE_ENS_RESOLUTION_ERROR,
type: actions.UPDATE_SEND_ENS_RESOLUTION_ERROR,
payload: errorMessage,
}
}
Expand Down

0 comments on commit 1418145

Please sign in to comment.