Skip to content

Commit

Permalink
Adds the ability to sign transactions offline using ledger nano
Browse files Browse the repository at this point in the history
  • Loading branch information
comountainclimber committed Jun 19, 2019
1 parent 6b3157e commit b471b2e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import React, { Fragment } from 'react'
import moment from 'moment'
import { tx, rpc } from '@cityofzion/neon-js'
import { tx, rpc, api } from '@cityofzion/neon-js'
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs'
import classNames from 'classnames'
import { isEmpty } from 'lodash-es'
Expand Down Expand Up @@ -33,10 +33,14 @@ type Props = {
hideModal: () => void,
showErrorNotification: ({ message: string }) => void,
showSuccessNotification: ({ message: string }) => void,
showInfoNotification: ({ message: string }) => void,
wif: string,
tx: Tx,
net: string,
theme: string,
isHardwareLogin: Boolean,
signingFunction?: () => void,
publicKey?: string,
}

type State = {
Expand Down Expand Up @@ -64,12 +68,37 @@ export default class GeneratedTransactionModal extends React.Component<
signTransaction = () => {
try {
const { Transaction } = tx
const { wif } = this.props
const {
wif,
isHardwareLogin,
signingFunction,
showInfoNotification,
publicKey,
} = this.props
const Tx = new Transaction(JSON.parse(this.state.transaction))
const signedTx = Tx.sign(wif)
this.setState({
signedTx,
})
if (isHardwareLogin) {
showInfoNotification({
message: 'Please sign the transaction on your hardware device',
autoDismiss: 0,
})
const config = {
tx: Tx,
signingFunction,
publicKey,
}
const signingPromise = api.signTx(config)
signingPromise.then(config => {
const signedTx = config.tx
this.setState({
signedTx,
})
})
} else {
const signedTx = Tx.sign(wif)
this.setState({
signedTx,
})
}
} catch (error) {
this.props.showErrorNotification({
message: `An error occurred signing the transaction: ${error.message}`,
Expand Down
2 changes: 2 additions & 0 deletions app/components/Modals/ImportTransactionModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ImportTransactionModal from './ImportTransactionModal'
import {
showErrorNotification,
showSuccessNotification,
showInfoNotification,
} from '../../../modules/notifications'
import withAuthData from '../../../hocs/withAuthData'
import withNetworkData from '../../../hocs/withNetworkData'
Expand All @@ -15,6 +16,7 @@ import withThemeData from '../../../hocs/withThemeData'
const actionCreators = {
showErrorNotification,
showSuccessNotification,
showInfoNotification,
}

const mapDispatchToProps = dispatch =>
Expand Down
1 change: 1 addition & 0 deletions app/hocs/withAuthData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Mapping = {
wif?: string,
signingFunction?: string,
isWatchOnly?: boolean,
isHardwareLogin: boolean,
}

export default function withAuthData(): Mapping {
Expand Down
2 changes: 1 addition & 1 deletion app/modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const sendTransaction = ({
}),
)

if (isHardwareSend) {
if (isHardwareSend && !isWatchOnly) {
dispatch(
showInfoNotification({
message: 'Please sign the transaction on your hardware device',
Expand Down

0 comments on commit b471b2e

Please sign in to comment.