import React, { PropTypes, Component } from 'react';
import LedgerContianer from '@digix/react-ledger-container';
export default class SignLedgerTransaction extends Component {
constructor(props) {
super(props);
this.handleSign = this.handleSign.bind(this);
}
handleSign({ signTransaction }) {
// txData = { to, nonce, gasPrice, value, data, gas } (w/ optional `from` for validating)
const { txData, account, publishTransaction } = this.props;
// kdPath = "44'/60'/0'/0";
const { kdPath } = account;
// signTransaction method will show the signing UI on ledger screen
signTransaction(kdPath, txData).then((signedTx) => {
publishTransaction({ signedTx });
})
}
render() {
const { kdPath, address } = this.props.account;
return (
<LedgerContianer
expect={{ kdPath, address }}
onReady={this.handleSign}
renderReady={({ config }) => <p>Ready to sign! Using ledger version {config.version}.</p>}
/>
);
}
}
SignLedgerTransaction.propTypes = {
publishTransaction: PropTypes.func.isRequired,
account: PropTypes.object.isRequired,
txData: PropTypes.object.isRequired,
};