1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 12:47:14 +01:00
metamask-extension/ui/app/components/pages/create-account/connect-hardware/connect-screen.js

198 lines
6.2 KiB
JavaScript
Raw Normal View History

2018-07-05 23:45:28 +02:00
const { Component } = require('react')
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
import Button from '../../../button'
2018-07-05 23:45:28 +02:00
2018-07-06 02:59:31 +02:00
class ConnectScreen extends Component {
2018-07-05 23:45:28 +02:00
constructor (props, context) {
super(props)
2018-08-17 01:39:52 +02:00
this.state = {
selectedDevice: null,
}
}
connect = () => {
if (this.state.selectedDevice) {
this.props.connectToHardwareWallet(this.state.selectedDevice)
}
return null
}
renderConnectToTrezorButton () {
return h(
`button.hw-connect__btn${this.state.selectedDevice === 'trezor' ? '.selected' : ''}`,
{ onClick: _ => this.setState({selectedDevice: 'trezor'}) },
h('img.hw-connect__btn__img', {
src: 'images/trezor-logo.svg',
})
)
}
renderConnectToLedgerButton () {
return h(
`button.hw-connect__btn${this.state.selectedDevice === 'ledger' ? '.selected' : ''}`,
{ onClick: _ => this.setState({selectedDevice: 'ledger'}) },
h('img.hw-connect__btn__img', {
src: 'images/ledger-logo.svg',
})
)
}
renderButtons () {
return (
h('div', {}, [
h('div.hw-connect__btn-wrapper', {}, [
this.renderConnectToLedgerButton(),
this.renderConnectToTrezorButton(),
]),
h(Button, {
type: 'confirm',
large: true,
className: 'hw-connect__connect-btn',
onClick: this.connect,
disabled: !this.state.selectedDevice,
}, this.context.t('connect')),
2018-08-17 01:39:52 +02:00
])
)
2018-07-05 23:45:28 +02:00
}
renderUnsupportedBrowser () {
return (
2018-07-19 06:14:13 +02:00
h('div.new-account-connect-form.unsupported-browser', {}, [
2018-07-07 02:04:20 +02:00
h('div.hw-connect', [
h('h3.hw-connect__title', {}, this.context.t('browserNotSupported')),
2018-08-15 01:22:00 +02:00
h('p.hw-connect__msg', {}, this.context.t('chromeRequiredForHardwareWallets')),
2018-07-06 02:59:31 +02:00
]),
h(Button, {
type: 'primary',
large: true,
onClick: () => global.platform.openWindow({
url: 'https://google.com/chrome',
}),
}, this.context.t('downloadGoogleChrome')),
2018-07-06 02:59:31 +02:00
])
2018-07-05 23:45:28 +02:00
)
}
2018-07-19 04:57:47 +02:00
renderHeader () {
return (
h('div.hw-connect__header', {}, [
2018-08-15 01:22:00 +02:00
h('h3.hw-connect__header__title', {}, this.context.t(`hardwareWallets`)),
h('p.hw-connect__header__msg', {}, this.context.t(`hardwareWalletsMsg`)),
2018-07-19 04:57:47 +02:00
])
)
}
2018-08-17 01:39:52 +02:00
getAffiliateLinks () {
const links = {
trezor: `<a class='hw-connect__get-hw__link' href='https://shop.trezor.io/?a=metamask' target='_blank'>Trezor</a>`,
2018-08-17 03:15:50 +02:00
ledger: `<a class='hw-connect__get-hw__link' href='https://www.ledger.com/products/ledger-nano-s?r=17c4991a03fa&tracker=MY_TRACKER' target='_blank'>Ledger</a>`,
2018-08-17 01:39:52 +02:00
}
2018-07-19 04:57:47 +02:00
2018-08-17 01:39:52 +02:00
const text = this.context.t('orderOneHere')
const response = text.replace('Trezor', links.trezor).replace('Ledger', links.ledger)
return h('div.hw-connect__get-hw__msg', { dangerouslySetInnerHTML: {__html: response }})
2018-07-19 04:57:47 +02:00
}
2018-08-17 01:39:52 +02:00
renderTrezorAffiliateLink () {
return h('div.hw-connect__get-hw', {}, [
h('p.hw-connect__get-hw__msg', {}, this.context.t(`dontHaveAHardwareWallet`)),
this.getAffiliateLinks(),
])
}
2018-08-17 01:39:52 +02:00
2018-07-19 05:12:49 +02:00
scrollToTutorial = (e) => {
if (this.referenceNode) this.referenceNode.scrollIntoView({behavior: 'smooth'})
}
2018-07-19 04:57:47 +02:00
renderLearnMore () {
return (
2018-07-19 05:12:49 +02:00
h('p.hw-connect__learn-more', {
onClick: this.scrollToTutorial,
}, [
2018-07-19 04:57:47 +02:00
this.context.t('learnMore'),
h('img.hw-connect__learn-more__arrow', { src: 'images/caret-right.svg'}),
])
)
}
renderTutorialSteps () {
const steps = [
{
asset: 'hardware-wallet-step-1',
dimensions: {width: '225px', height: '75px'},
},
{
asset: 'hardware-wallet-step-2',
dimensions: {width: '300px', height: '100px'},
},
{
asset: 'hardware-wallet-step-3',
dimensions: {width: '120px', height: '90px'},
},
]
2018-07-19 05:57:09 +02:00
return h('.hw-tutorial', {
2018-07-19 05:12:49 +02:00
ref: node => { this.referenceNode = node },
},
2018-07-19 04:57:47 +02:00
steps.map((step, i) => (
2018-07-19 05:12:49 +02:00
h('div.hw-connect', {}, [
2018-07-19 04:57:47 +02:00
h('h3.hw-connect__title', {}, this.context.t(`step${i + 1}HardwareWallet`)),
h('p.hw-connect__msg', {}, this.context.t(`step${i + 1}HardwareWalletMsg`)),
h('img.hw-connect__step-asset', { src: `images/${step.asset}.svg`, ...step.dimensions }),
])
))
)
}
renderFooter () {
return (
h('div.hw-connect__footer', {}, [
h('h3.hw-connect__footer__title', {}, this.context.t(`readyToConnect`)),
2018-08-17 01:39:52 +02:00
this.renderButtons(),
2018-07-19 04:57:47 +02:00
h('p.hw-connect__footer__msg', {}, [
this.context.t(`havingTroubleConnecting`),
h('a.hw-connect__footer__link', {
2018-07-19 06:16:10 +02:00
href: 'https://support.metamask.io/',
2018-07-19 04:57:47 +02:00
target: '_blank',
}, this.context.t('getHelp')),
]),
])
)
}
2018-07-07 02:04:20 +02:00
renderConnectScreen () {
return (
h('div.new-account-connect-form', {}, [
2018-07-19 04:57:47 +02:00
this.renderHeader(),
2018-08-17 01:39:52 +02:00
this.renderButtons(),
2018-08-15 01:22:00 +02:00
this.renderTrezorAffiliateLink(),
2018-07-19 04:57:47 +02:00
this.renderLearnMore(),
this.renderTutorialSteps(),
this.renderFooter(),
2018-07-07 02:04:20 +02:00
])
)
2018-07-19 04:57:47 +02:00
}
2018-07-05 23:45:28 +02:00
render () {
if (this.props.browserSupported) {
2018-07-07 02:04:20 +02:00
return this.renderConnectScreen()
2018-07-05 23:45:28 +02:00
}
2018-07-06 02:59:31 +02:00
return this.renderUnsupportedBrowser()
2018-07-05 23:45:28 +02:00
}
}
ConnectScreen.propTypes = {
connectToHardwareWallet: PropTypes.func.isRequired,
browserSupported: PropTypes.bool.isRequired,
2018-07-05 23:45:28 +02:00
}
ConnectScreen.contextTypes = {
t: PropTypes.func,
}
2018-07-06 02:59:31 +02:00
module.exports = ConnectScreen