-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
376 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { trezor } from "connectors"; | ||
import PinModal from "./PinModal"; | ||
import PassPhraseModal from "./PassPhraseModal"; | ||
import "style/Trezor.less"; | ||
|
||
@autobind | ||
class TrezorModals extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
onCancelModal() { | ||
this.props.cancelCurrentOperation(); | ||
} | ||
|
||
render() { | ||
if (this.props.waitingForPin) { | ||
return <PinModal | ||
{...this.props} | ||
onCancelModal={this.onCancelModal} | ||
/>; | ||
} else if (this.props.waitingForPassPhrase) { | ||
return <PassPhraseModal | ||
{...this.props} | ||
onCancelModal={this.onCancelModal} | ||
/>; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
const TrezorModalsOrNone = ({ isTrezor, ...props }) => | ||
isTrezor ? <TrezorModals {...props} /> : null; | ||
|
||
export default trezor(TrezorModalsOrNone); |
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,38 @@ | ||
import { PassphraseModal } from "../PassphraseModal"; | ||
import { FormattedMessage as T } from "react-intl"; | ||
|
||
@autobind | ||
class TrezorPassphraseModal extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
onSubmit(passPhrase) { | ||
console.log("gonna submit", passPhrase); | ||
this.props.submitPassPhrase(passPhrase); | ||
} | ||
|
||
render() { | ||
const { onCancelModal } = this.props; | ||
const { onSubmit } = this; | ||
|
||
const trezorLabel = this.props.device ? this.props.device.features.label : ""; | ||
|
||
return ( | ||
<PassphraseModal | ||
show={true} | ||
modalTitle={<T id="trezor.passphraseModal.title" m="Confirm Trezor Passphrase" />} | ||
className="trezor-passphrase-modal" | ||
modalDescription={ | ||
<p> | ||
<T id="trezor.passphraseModal.description" m="Type the secret passphrase for the wallet stored in trezor {label}" | ||
values={{ label: <span className="trezor-label">'{trezorLabel}'</span> }} /> | ||
</p> | ||
} | ||
{...{ onCancelModal, onSubmit }} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default TrezorPassphraseModal; |
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,75 @@ | ||
import Modal from "../Modal"; | ||
import { FormattedMessage as T } from "react-intl"; | ||
import { PasswordInput } from "inputs"; | ||
import { ButtonsToolbar } from "../PassphraseModal"; | ||
import { InvisibleButton } from "buttons"; | ||
|
||
const PinButton = ({ index, label, onClick }) => | ||
<div className="pin-pad-button" onClick={() => onClick(index)}>{label}</div>; | ||
|
||
@autobind | ||
class PinModal extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { currentPin: "" }; | ||
} | ||
|
||
onPinButtonClick(index) { | ||
this.setState({ currentPin: this.state.currentPin + index }); | ||
} | ||
|
||
onCancelModal() { | ||
this.setState({ currentPin: "" }); | ||
this.props.onCancelModal(); | ||
} | ||
|
||
onSubmit() { | ||
this.props.submitPin(this.state.currentPin); | ||
} | ||
|
||
onClearPin() { | ||
this.setState({ currentPin: "" }); | ||
} | ||
|
||
render() { | ||
const { onCancelModal, onSubmit, onPinButtonClick, onClearPin } = this; | ||
|
||
const labels = "ABCDEFGHI"; | ||
const currentPin = this.state.currentPin.split("").map(v => labels[parseInt(v)-1]).join(""); | ||
|
||
const Button = ({ index }) => | ||
<PinButton label={labels[index-1]} index={index} onClick={onPinButtonClick} />; | ||
|
||
const trezorLabel = this.props.device ? this.props.device.features.label : ""; | ||
|
||
return ( | ||
<Modal className="passphrase-modal trezor-pin-modal" {...{ onCancelModal }}> | ||
<h1><T id="trezor.pinModal.title" m="Enter Pin" /></h1> | ||
<p><T id="trezor.pinModal.description" m="Click button sequence that corresponds to your pin on trezor {label}" | ||
values={{ label: <span className="trezor-label">'{trezorLabel}'</span> }} /></p> | ||
<div className="pin-pad"> | ||
<Button index={7} /> | ||
<Button index={8} /> | ||
<Button index={9} /> | ||
<Button index={4} /> | ||
<Button index={5} /> | ||
<Button index={6} /> | ||
<Button index={1} /> | ||
<Button index={2} /> | ||
<Button index={3} /> | ||
</div> | ||
<div> | ||
<InvisibleButton onClick={onClearPin} className="pin-pad-clear-btn"> | ||
<T id="trezor.pinModal.clear" m="clear" /> | ||
</InvisibleButton> | ||
</div> | ||
<div className="password-field"> | ||
<PasswordInput value={currentPin} /> | ||
</div> | ||
<ButtonsToolbar {... { onCancelModal, onSubmit }} /> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default PinModal; |
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 @@ | ||
export { default as TrezorModals } from "./Modals"; |
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,20 @@ | ||
import { connect } from "react-redux"; | ||
import { selectorMap } from "../fp"; | ||
import { bindActionCreators } from "redux"; | ||
import * as sel from "../selectors"; | ||
import * as trza from "../actions/TrezorActions"; | ||
|
||
const mapStateToProps = selectorMap({ | ||
isTrezor: sel.isTrezor, | ||
waitingForPin: sel.trezorWaitingForPin, | ||
waitingForPassPhrase: sel.trezorWaitingForPassPhrase, | ||
device: sel.trezorDevice, | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => bindActionCreators({ | ||
cancelCurrentOperation: trza.cancelCurrentOperation, | ||
submitPin: trza.submitPin, | ||
submitPassPhrase: trza.submitPassPhrase, | ||
}, dispatch); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps); |
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
Oops, something went wrong.