-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from Emurgo/feature/fromDaedalusKey
Daedalus Master Key restore
- Loading branch information
Showing
34 changed files
with
529 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// @flow | ||
import React, { Component } from 'react'; | ||
import { observer } from 'mobx-react'; | ||
import classnames from 'classnames'; | ||
import { Input } from 'react-polymorph/lib/components/Input'; | ||
import { InputSkin } from 'react-polymorph/lib/skins/simple/InputSkin'; | ||
import { Button } from 'react-polymorph/lib/components/Button'; | ||
import { ButtonSkin } from 'react-polymorph/lib/skins/simple/ButtonSkin'; | ||
import { defineMessages, intlShape } from 'react-intl'; | ||
import ReactToolboxMobxForm from '../../utils/ReactToolboxMobxForm'; | ||
import BorderedBox from '../widgets/BorderedBox'; | ||
import globalMessages from '../../i18n/global-messages'; | ||
import styles from './TransferMasterKeyPage.scss'; | ||
import config from '../../config'; | ||
|
||
const messages = defineMessages({ | ||
masterKeyInputLabel: { | ||
id: 'transfer.form.masterkey.input.label', | ||
defaultMessage: '!!!Master key', | ||
description: 'Label for the master key input on the transfer master key page.' | ||
}, | ||
masterKeyInputHint: { | ||
id: 'transfer.form.masterkey.input.hint', | ||
defaultMessage: '!!!Enter master key', | ||
description: 'Hint "Enter master key" for the master keyinput on the transfer master key page.' | ||
}, | ||
masterKeyRequirements: { | ||
id: 'transfer.form.masterkey.requirement', | ||
defaultMessage: '!!!Note: master keys are 192 characters and hexadecimal-encoded', | ||
description: 'Description of master key format' | ||
}, | ||
}); | ||
|
||
messages.fieldIsRequired = globalMessages.fieldIsRequired; | ||
messages.invalidMasterKey = globalMessages.invalidMasterKey; | ||
messages.nextButtonLabel = globalMessages.nextButtonLabel; | ||
messages.backButtonLabel = globalMessages.backButtonLabel; | ||
messages.step1 = globalMessages.step1; | ||
messages.instructionTitle = globalMessages.instructionTitle; | ||
|
||
type Props = { | ||
onSubmit: Function, | ||
onBack: Function, | ||
step0: string, | ||
}; | ||
|
||
@observer | ||
export default class TransferMasterKeyPage extends Component<Props> { | ||
|
||
static contextTypes = { | ||
intl: intlShape.isRequired | ||
}; | ||
|
||
form = new ReactToolboxMobxForm({ | ||
fields: { | ||
masterKey: { | ||
label: this.context.intl.formatMessage(messages.masterKeyInputLabel), | ||
placeholder: this.context.intl.formatMessage(messages.masterKeyInputHint), | ||
value: '', | ||
validators: [({ field }) => { | ||
const value = field.value; | ||
if (value === '') { | ||
return [false, this.context.intl.formatMessage(messages.fieldIsRequired)]; | ||
} | ||
if (value.length !== 192) { | ||
return [false, this.context.intl.formatMessage(messages.invalidMasterKey)]; | ||
} | ||
if (!value.match('^[0-9a-fA-F]+$')) { | ||
return [false, this.context.intl.formatMessage(messages.invalidMasterKey)]; | ||
} | ||
return true; | ||
}], | ||
}, | ||
}, | ||
}, { | ||
options: { | ||
validateOnChange: true, | ||
validationDebounceWait: config.forms.FORM_VALIDATION_DEBOUNCE_WAIT, | ||
}, | ||
}); | ||
|
||
submit = () => { | ||
this.form.submit({ | ||
onSuccess: (form) => { | ||
const { masterKey } = form.values(); | ||
const payload = { | ||
masterKey, | ||
}; | ||
this.props.onSubmit(payload); | ||
}, | ||
onError: () => {} | ||
}); | ||
}; | ||
|
||
render() { | ||
const { intl } = this.context; | ||
const { form } = this; | ||
const { onBack, step0 } = this.props; | ||
|
||
const nextButtonClasses = classnames([ | ||
'proceedTransferButtonClasses', | ||
'primary', | ||
styles.button, | ||
]); | ||
const backButtonClasses = classnames([ | ||
'backTransferButtonClasses', | ||
'flat', | ||
styles.button, | ||
]); | ||
|
||
const masterKeyField = form.$('masterKey'); | ||
|
||
return ( | ||
<div className={styles.component}> | ||
<BorderedBox> | ||
|
||
<div className={styles.body}> | ||
|
||
{ /* Instructions for how to transfer */ } | ||
<div> | ||
<div className={styles.title}> | ||
{intl.formatMessage(messages.instructionTitle)} | ||
</div> | ||
|
||
<ul className={styles.instructionsList}> | ||
{ | ||
<div className={styles.text}> | ||
{step0} | ||
{intl.formatMessage(messages.step1)} | ||
<br /><br /> | ||
{intl.formatMessage(messages.masterKeyRequirements)} | ||
</div> | ||
} | ||
</ul> | ||
</div> | ||
|
||
<Input | ||
className="masterKey" | ||
autoComplete="off" | ||
{...masterKeyField.bind()} | ||
error={masterKeyField.error} | ||
skin={InputSkin} | ||
/> | ||
|
||
<div className={styles.buttonsWrapper}> | ||
<Button | ||
className={nextButtonClasses} | ||
label={intl.formatMessage(messages.nextButtonLabel)} | ||
onClick={this.submit} | ||
skin={ButtonSkin} | ||
/> | ||
|
||
<Button | ||
className={backButtonClasses} | ||
label={intl.formatMessage(messages.backButtonLabel)} | ||
onClick={onBack} | ||
skin={ButtonSkin} | ||
/> | ||
</div> | ||
|
||
</div> | ||
|
||
</BorderedBox> | ||
|
||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
@import '../../themes/mixins/loading-spinner'; | ||
|
||
.component { | ||
padding: 20px; | ||
} | ||
|
||
.button { | ||
display: block !important; | ||
margin: 20px auto 0; | ||
} | ||
|
||
.body { | ||
color: var(--theme-bordered-box-text-color); | ||
font-family: var(--font-regular); | ||
font-size: 14px; | ||
line-height: 19px; | ||
|
||
.title { | ||
font-size: 11px; | ||
font-family: var(--font-medium); | ||
font-weight: 600; | ||
line-height: 1.38; | ||
margin-bottom: 4px; | ||
padding-left: 10px; | ||
text-transform: uppercase; | ||
} | ||
|
||
.text { | ||
font-size: 15px; | ||
margin-bottom: 0.3%; | ||
word-break: break-word; | ||
} | ||
|
||
.instructionsList { | ||
list-style-type: disc; | ||
list-style-position: inside; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.buttonsWrapper { | ||
display: flex; | ||
flex-direction: row-reverse; | ||
justify-content: center; | ||
} | ||
|
||
.submitWithPasswordButton { | ||
&.spinning { | ||
@include loading-spinner("../../assets/images/spinner-light.svg"); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.