You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
290 lines
8.1 KiB
290 lines
8.1 KiB
7 years ago
|
const { Component } = require('react')
|
||
7 years ago
|
const { withRouter } = require('react-router-dom')
|
||
|
const { compose } = require('recompose')
|
||
7 years ago
|
const PropTypes = require('prop-types')
|
||
9 years ago
|
const h = require('react-hyperscript')
|
||
7 years ago
|
const { connect } = require('react-redux')
|
||
7 years ago
|
const actions = require('../../../actions')
|
||
|
const infuraCurrencies = require('../../../infura-conversion.json')
|
||
7 years ago
|
const validUrl = require('valid-url')
|
||
7 years ago
|
const { exportAsFile } = require('../../../util')
|
||
|
const SimpleDropdown = require('../../dropdowns/simple-dropdown')
|
||
7 years ago
|
const ToggleButton = require('react-toggle-button')
|
||
7 years ago
|
const { REVEAL_SEED_ROUTE } = require('../../../routes')
|
||
7 years ago
|
const { OLD_UI_NETWORK_TYPE } = require('../../app/scripts/config').enums
|
||
9 years ago
|
|
||
7 years ago
|
const getInfuraCurrencyOptions = () => {
|
||
|
const sortedCurrencies = infuraCurrencies.objects.sort((a, b) => {
|
||
|
return a.quote.name.toLocaleLowerCase().localeCompare(b.quote.name.toLocaleLowerCase())
|
||
|
})
|
||
9 years ago
|
|
||
7 years ago
|
return sortedCurrencies.map(({ quote: { code, name } }) => {
|
||
|
return {
|
||
|
displayValue: `${code.toUpperCase()} - ${name}`,
|
||
|
key: code,
|
||
|
value: code,
|
||
|
}
|
||
|
})
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
class Settings extends Component {
|
||
7 years ago
|
constructor (props) {
|
||
|
super(props)
|
||
|
|
||
7 years ago
|
this.state = {
|
||
|
newRpc: '',
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
7 years ago
|
renderBlockieOptIn () {
|
||
7 years ago
|
const { metamask: { useBlockie }, setUseBlockie } = this.props
|
||
7 years ago
|
|
||
|
return h('div.settings__content-row', [
|
||
|
h('div.settings__content-item', [
|
||
7 years ago
|
h('span', 'Use Blockies Identicon'),
|
||
7 years ago
|
]),
|
||
|
h('div.settings__content-item', [
|
||
|
h('div.settings__content-item-col', [
|
||
7 years ago
|
h(ToggleButton, {
|
||
|
value: useBlockie,
|
||
|
onToggle: (value) => setUseBlockie(!value),
|
||
|
activeLabel: '',
|
||
|
inactiveLabel: '',
|
||
7 years ago
|
}),
|
||
|
]),
|
||
|
]),
|
||
|
])
|
||
|
}
|
||
|
|
||
7 years ago
|
renderCurrentConversion () {
|
||
|
const { metamask: { currentCurrency, conversionDate }, setCurrentCurrency } = this.props
|
||
9 years ago
|
|
||
7 years ago
|
return h('div.settings__content-row', [
|
||
|
h('div.settings__content-item', [
|
||
|
h('span', 'Current Conversion'),
|
||
|
h('span.settings__content-description', `Updated ${Date(conversionDate)}`),
|
||
9 years ago
|
]),
|
||
7 years ago
|
h('div.settings__content-item', [
|
||
|
h('div.settings__content-item-col', [
|
||
|
h(SimpleDropdown, {
|
||
|
placeholder: 'Select Currency',
|
||
|
options: getInfuraCurrencyOptions(),
|
||
|
selectedOption: currentCurrency,
|
||
|
onSelect: newCurrency => setCurrentCurrency(newCurrency),
|
||
|
}),
|
||
|
]),
|
||
|
]),
|
||
|
])
|
||
|
}
|
||
9 years ago
|
|
||
7 years ago
|
renderCurrentProvider () {
|
||
|
const { metamask: { provider = {} } } = this.props
|
||
|
let title, value, color
|
||
|
|
||
|
switch (provider.type) {
|
||
9 years ago
|
|
||
7 years ago
|
case 'mainnet':
|
||
|
title = 'Current Network'
|
||
|
value = 'Main Ethereum Network'
|
||
|
color = '#038789'
|
||
|
break
|
||
|
|
||
|
case 'ropsten':
|
||
|
title = 'Current Network'
|
||
|
value = 'Ropsten Test Network'
|
||
|
color = '#e91550'
|
||
|
break
|
||
|
|
||
|
case 'kovan':
|
||
|
title = 'Current Network'
|
||
|
value = 'Kovan Test Network'
|
||
|
color = '#690496'
|
||
|
break
|
||
|
|
||
|
case 'rinkeby':
|
||
|
title = 'Current Network'
|
||
|
value = 'Rinkeby Test Network'
|
||
|
color = '#ebb33f'
|
||
|
break
|
||
|
|
||
|
default:
|
||
|
title = 'Current RPC'
|
||
|
value = provider.rpcTarget
|
||
|
}
|
||
|
|
||
|
return h('div.settings__content-row', [
|
||
|
h('div.settings__content-item', title),
|
||
|
h('div.settings__content-item', [
|
||
|
h('div.settings__content-item-col', [
|
||
|
h('div.settings__provider-wrapper', [
|
||
|
h('div.settings__provider-icon', { style: { background: color } }),
|
||
|
h('div', value),
|
||
|
]),
|
||
|
]),
|
||
|
]),
|
||
9 years ago
|
])
|
||
7 years ago
|
}
|
||
9 years ago
|
|
||
7 years ago
|
renderNewRpcUrl () {
|
||
|
return (
|
||
|
h('div.settings__content-row', [
|
||
|
h('div.settings__content-item', [
|
||
|
h('span', 'New RPC URL'),
|
||
|
]),
|
||
|
h('div.settings__content-item', [
|
||
|
h('div.settings__content-item-col', [
|
||
|
h('input.settings__input', {
|
||
|
placeholder: 'New RPC URL',
|
||
|
onChange: event => this.setState({ newRpc: event.target.value }),
|
||
|
onKeyPress: event => {
|
||
|
if (event.key === 'Enter') {
|
||
|
this.validateRpc(this.state.newRpc)
|
||
|
}
|
||
|
},
|
||
|
}),
|
||
|
h('div.settings__rpc-save-button', {
|
||
|
onClick: event => {
|
||
|
event.preventDefault()
|
||
|
this.validateRpc(this.state.newRpc)
|
||
|
},
|
||
|
}, 'Save'),
|
||
|
]),
|
||
|
]),
|
||
|
])
|
||
|
)
|
||
|
}
|
||
|
|
||
|
validateRpc (newRpc) {
|
||
|
const { setRpcTarget, displayWarning } = this.props
|
||
9 years ago
|
|
||
7 years ago
|
if (validUrl.isWebUri(newRpc)) {
|
||
|
setRpcTarget(newRpc)
|
||
|
} else {
|
||
|
const appendedRpc = `http://${newRpc}`
|
||
|
|
||
|
if (validUrl.isWebUri(appendedRpc)) {
|
||
|
displayWarning('URIs require the appropriate HTTP/HTTPS prefix.')
|
||
|
} else {
|
||
|
displayWarning('Invalid RPC URI')
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
renderStateLogs () {
|
||
|
return (
|
||
|
h('div.settings__content-row', [
|
||
|
h('div.settings__content-item', [
|
||
|
h('div', 'State Logs'),
|
||
|
h(
|
||
|
'div.settings__content-description',
|
||
|
'State logs contain your public account addresses and sent transactions.'
|
||
|
),
|
||
|
]),
|
||
|
h('div.settings__content-item', [
|
||
|
h('div.settings__content-item-col', [
|
||
|
h('button.settings__clear-button', {
|
||
|
onClick (event) {
|
||
|
exportAsFile('MetaMask State Logs', window.logState())
|
||
|
},
|
||
|
}, 'Download State Logs'),
|
||
|
]),
|
||
|
]),
|
||
|
])
|
||
|
)
|
||
|
}
|
||
|
|
||
|
renderSeedWords () {
|
||
7 years ago
|
const { history } = this.props
|
||
7 years ago
|
|
||
|
return (
|
||
|
h('div.settings__content-row', [
|
||
|
h('div.settings__content-item', 'Reveal Seed Words'),
|
||
|
h('div.settings__content-item', [
|
||
|
h('div.settings__content-item-col', [
|
||
|
h('button.settings__clear-button.settings__clear-button--red', {
|
||
7 years ago
|
onClick: () => history.push(REVEAL_SEED_ROUTE),
|
||
7 years ago
|
}, 'Reveal Seed Words'),
|
||
|
]),
|
||
|
]),
|
||
|
])
|
||
|
)
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
renderOldUI () {
|
||
|
const { setFeatureFlagToBeta } = this.props
|
||
|
|
||
|
return (
|
||
|
h('div.settings__content-row', [
|
||
|
h('div.settings__content-item', 'Use old UI'),
|
||
|
h('div.settings__content-item', [
|
||
|
h('div.settings__content-item-col', [
|
||
7 years ago
|
h('button.settings__clear-button.settings__clear-button--orange', {
|
||
7 years ago
|
onClick (event) {
|
||
|
event.preventDefault()
|
||
|
setFeatureFlagToBeta()
|
||
|
},
|
||
|
}, 'Use old UI'),
|
||
|
]),
|
||
|
]),
|
||
|
])
|
||
|
)
|
||
|
}
|
||
|
|
||
7 years ago
|
render () {
|
||
7 years ago
|
const { warning, isMascara } = this.props
|
||
7 years ago
|
|
||
|
return (
|
||
|
h('div.settings__content', [
|
||
|
warning && h('div.settings__error', warning),
|
||
|
this.renderCurrentConversion(),
|
||
7 years ago
|
// this.renderCurrentProvider(),
|
||
7 years ago
|
this.renderNewRpcUrl(),
|
||
|
this.renderStateLogs(),
|
||
|
this.renderSeedWords(),
|
||
7 years ago
|
!isMascara && this.renderOldUI(),
|
||
7 years ago
|
this.renderBlockieOptIn(),
|
||
7 years ago
|
])
|
||
|
)
|
||
|
}
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
Settings.propTypes = {
|
||
|
metamask: PropTypes.object,
|
||
7 years ago
|
setUseBlockie: PropTypes.func,
|
||
7 years ago
|
setCurrentCurrency: PropTypes.func,
|
||
|
setRpcTarget: PropTypes.func,
|
||
|
displayWarning: PropTypes.func,
|
||
|
revealSeedConfirmation: PropTypes.func,
|
||
7 years ago
|
setFeatureFlagToBeta: PropTypes.func,
|
||
7 years ago
|
warning: PropTypes.string,
|
||
7 years ago
|
history: PropTypes.object,
|
||
7 years ago
|
isMascara: PropTypes.bool,
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
const mapStateToProps = state => {
|
||
|
return {
|
||
|
metamask: state.metamask,
|
||
|
warning: state.appState.warning,
|
||
7 years ago
|
isMascara: state.metamask.isMascara,
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
const mapDispatchToProps = dispatch => {
|
||
|
return {
|
||
|
setCurrentCurrency: currency => dispatch(actions.setCurrentCurrency(currency)),
|
||
|
setRpcTarget: newRpc => dispatch(actions.setRpcTarget(newRpc)),
|
||
|
displayWarning: warning => dispatch(actions.displayWarning(warning)),
|
||
|
revealSeedConfirmation: () => dispatch(actions.revealSeedConfirmation()),
|
||
7 years ago
|
setUseBlockie: value => dispatch(actions.setUseBlockie(value)),
|
||
7 years ago
|
setFeatureFlagToBeta: () => {
|
||
|
return dispatch(actions.setFeatureFlag('betaUI', false, 'OLD_UI_NOTIFICATION_MODAL'))
|
||
|
.then(() => dispatch(actions.setNetworkEndpoints(OLD_UI_NETWORK_TYPE)))
|
||
|
},
|
||
7 years ago
|
}
|
||
9 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
module.exports = compose(
|
||
|
withRouter,
|
||
|
connect(mapStateToProps, mapDispatchToProps)
|
||
|
)(Settings)
|