mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-24 18:09:10 +00:00
5d3e461301
* Check in. * Add read only wallet and new types for that. Convert some components to require full wallet. * Fix readonly property, fix uncaught throw. * Disable address only on some tabs. * Use FullWalletOnly render callback to handle signing. * Work around uncertain wallet type. * Fix function args. * Undo bug fix that should be done in another branch. * Disable button while address is bad. * Remove log. * Convert anonymous functions to class functions.
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
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 (
|
|
<button
|
|
className="SignMessage-sign btn btn-primary btn-lg"
|
|
onClick={this.handleSignMessage}
|
|
>
|
|
{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}`);
|
|
}
|
|
};
|
|
}
|