1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/app/config.js

174 lines
4.7 KiB
JavaScript
Raw Normal View History

const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const actions = require('./actions')
2016-11-19 01:49:39 +01:00
const currencies = require('./conversion.json').rows
2016-12-21 01:41:04 +01:00
const validUrl = require('valid-url')
2017-02-21 21:51:56 +01:00
module.exports = connect(mapStateToProps)(ConfigScreen)
2016-06-21 22:18:32 +02:00
function mapStateToProps (state) {
return {
metamask: state.metamask,
2016-12-21 01:45:22 +01:00
warning: state.appState.warning,
}
}
inherits(ConfigScreen, Component)
2016-06-21 22:18:32 +02:00
function ConfigScreen () {
Component.call(this)
}
2016-06-21 22:18:32 +02:00
ConfigScreen.prototype.render = function () {
var state = this.props
var metamaskState = state.metamask
2016-12-21 01:41:04 +01:00
var warning = state.warning
return (
h('.flex-column.flex-grow', [
// subtitle and nav
h('.section-title.flex-row.flex-center', [
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
onClick: (event) => {
state.dispatch(actions.goHome())
2016-06-21 22:18:32 +02:00
},
}),
h('h2.page-subtitle', 'Settings'),
]),
2016-12-21 01:41:04 +01:00
h('.error', {
style: {
display: warning ? 'block' : 'none',
padding: '0 20px',
textAlign: 'center',
},
}, warning),
// conf view
h('.flex-column.flex-justify-center.flex-grow.select-none', [
h('.flex-space-around', {
style: {
padding: '20px',
2016-06-21 22:18:32 +02:00
},
}, [
currentProviderDisplay(metamaskState),
h('div', { style: {display: 'flex'} }, [
h('input#new_rpc', {
placeholder: 'New RPC URL',
style: {
width: 'inherit',
flex: '1 0 auto',
height: '30px',
margin: '8px',
},
2016-06-21 22:18:32 +02:00
onKeyPress (event) {
if (event.key === 'Enter') {
var element = event.target
var newRpc = element.value
2016-12-21 01:41:04 +01:00
rpcValidation(newRpc, state)
}
2016-06-21 22:18:32 +02:00
},
}),
h('button', {
style: {
alignSelf: 'center',
},
2016-06-21 22:18:32 +02:00
onClick (event) {
event.preventDefault()
var element = document.querySelector('input#new_rpc')
var newRpc = element.value
2016-12-21 01:41:04 +01:00
rpcValidation(newRpc, state)
2016-06-21 22:18:32 +02:00
},
}, 'Save'),
]),
h('hr.horizontal-line'),
2016-08-04 23:04:04 +02:00
currentConversionInformation(metamaskState, state),
h('hr.horizontal-line'),
h('div', {
style: {
marginTop: '20px',
2016-06-21 22:18:32 +02:00
},
}, [
h('button', {
style: {
alignSelf: 'center',
},
2016-06-21 22:18:32 +02:00
onClick (event) {
event.preventDefault()
state.dispatch(actions.revealSeedConfirmation())
2016-06-21 22:18:32 +02:00
},
}, 'Reveal Seed Words'),
]),
]),
]),
])
)
}
2016-12-21 01:41:04 +01:00
function rpcValidation (newRpc, state) {
if (validUrl.isWebUri(newRpc)) {
state.dispatch(actions.setRpcTarget(newRpc))
} else {
var appendedRpc = `http://${newRpc}`
if (validUrl.isWebUri(appendedRpc)) {
state.dispatch(actions.displayWarning('URIs require the appropriate HTTP/HTTPS prefix.'))
} else {
state.dispatch(actions.displayWarning('Invalid RPC URI'))
}
}
}
2016-08-04 23:04:04 +02:00
function currentConversionInformation (metamaskState, state) {
var currentFiat = metamaskState.currentFiat
2016-08-16 23:07:42 +02:00
var conversionDate = metamaskState.conversionDate
2016-08-16 19:48:31 +02:00
return h('div', [
h('span', {style: { fontWeight: 'bold', paddingRight: '10px'}}, 'Current Conversion'),
2016-08-16 23:07:42 +02:00
h('span', {style: { fontWeight: 'bold', paddingRight: '10px', fontSize: '13px'}}, `Updated ${Date(conversionDate)}`),
2016-08-04 23:04:04 +02:00
h('select#currentFiat', {
onChange (event) {
event.preventDefault()
2016-08-16 19:48:31 +02:00
var element = document.getElementById('currentFiat')
2016-08-04 23:04:04 +02:00
var newFiat = element.value
state.dispatch(actions.setCurrentFiat(newFiat))
},
defaultValue: currentFiat,
}, currencies.map((currency) => {
2016-08-16 19:48:31 +02:00
return h('option', {key: currency.code, value: currency.code}, `${currency.code} - ${currency.name}`)
})
2016-08-04 23:04:04 +02:00
),
2016-08-16 19:48:31 +02:00
])
2016-08-04 23:04:04 +02:00
}
2016-06-21 22:18:32 +02:00
function currentProviderDisplay (metamaskState) {
var provider = metamaskState.provider
var title, value
switch (provider.type) {
case 'mainnet':
title = 'Current Network'
value = 'Main Ethereum Network'
break
case 'testnet':
title = 'Current Network'
value = 'Ropsten Test Network'
break
default:
title = 'Current RPC'
value = metamaskState.provider.rpcTarget
2016-06-21 22:18:32 +02:00
}
return h('div', [
h('span', {style: { fontWeight: 'bold', paddingRight: '10px'}}, title),
2016-06-21 22:18:32 +02:00
h('span', value),
])
}