2017-11-29 23:14:57 +00:00
|
|
|
import React from 'react';
|
|
|
|
import translate from 'translations';
|
|
|
|
import { ISignedMessage } from 'libs/signing';
|
|
|
|
import { IFullWallet } from 'libs/wallet';
|
|
|
|
import { TShowNotification } from 'actions/notifications';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
wallet: IFullWallet;
|
|
|
|
message: string;
|
|
|
|
showNotification: TShowNotification;
|
|
|
|
onSignMessage(msg: ISignedMessage): any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class SignMessageButton extends React.Component<Props, {}> {
|
|
|
|
public render() {
|
|
|
|
return (
|
2017-12-18 23:29:26 +00:00
|
|
|
<button className="SignMessage-sign btn btn-primary btn-lg" onClick={this.handleSignMessage}>
|
2017-11-29 23:14:57 +00:00
|
|
|
{translate('NAV_SignMsg')}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleSignMessage = async () => {
|
|
|
|
const { wallet, message, showNotification, onSignMessage } = this.props;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const signedMessage: ISignedMessage = {
|
|
|
|
address: await wallet.getAddressString(),
|
|
|
|
message,
|
|
|
|
signature: await wallet.signMessage(message),
|
|
|
|
version: '2'
|
|
|
|
};
|
|
|
|
|
|
|
|
onSignMessage(signedMessage);
|
|
|
|
showNotification(
|
|
|
|
'success',
|
|
|
|
`Successfully signed message with address ${signedMessage.address}.`
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
showNotification('danger', `Error signing message: ${err.message}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|