From 48304699a1292bcb2c3cc5556bba2cdfbfae359b Mon Sep 17 00:00:00 2001 From: mwbailey Date: Wed, 18 Jul 2018 15:05:41 -0700 Subject: [PATCH] Discard signed message after leaving tab (#2056) --- .../components/SignMessage/index.tsx | 7 ++++++- common/features/message/actions.ts | 7 +++++++ common/features/message/reducer.ts | 8 ++++++++ common/features/message/types.ts | 10 ++++++++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/common/containers/Tabs/SignAndVerifyMessage/components/SignMessage/index.tsx b/common/containers/Tabs/SignAndVerifyMessage/components/SignMessage/index.tsx index b2d41fa4c1b..a1f963645cb 100644 --- a/common/containers/Tabs/SignAndVerifyMessage/components/SignMessage/index.tsx +++ b/common/containers/Tabs/SignAndVerifyMessage/components/SignMessage/index.tsx @@ -18,6 +18,7 @@ interface Props { signMessageRequested: messageActions.TSignMessageRequested; signedMessage: ISignedMessage | null; resetWallet: walletActions.TResetWallet; + resetMessage: messageActions.TResetMessage; } interface State { @@ -35,6 +36,7 @@ export class SignMessage extends Component { public componentWillUnmount() { this.props.resetWallet(); + this.props.resetMessage(); } public render() { @@ -97,6 +99,8 @@ export class SignMessage extends Component { private changeWallet = () => { this.props.resetWallet(); + this.props.resetMessage(); + this.setState(initialState); }; } @@ -107,5 +111,6 @@ const mapStateToProps = (state: AppState) => ({ export default connect(mapStateToProps, { signMessageRequested: messageActions.signMessageRequested, - resetWallet: walletActions.resetWallet + resetWallet: walletActions.resetWallet, + resetMessage: messageActions.resetMessage })(SignMessage); diff --git a/common/features/message/actions.ts b/common/features/message/actions.ts index e9621d29954..7f06fc2c20c 100644 --- a/common/features/message/actions.ts +++ b/common/features/message/actions.ts @@ -25,3 +25,10 @@ export function signMessageFailed(): types.SignMessageFailedAction { type: types.MessageActions.SIGN_FAILED }; } + +export type TResetMessage = typeof resetMessage; +export function resetMessage(): types.ResetMessageAction { + return { + type: types.MessageActions.RESET + }; +} diff --git a/common/features/message/reducer.ts b/common/features/message/reducer.ts index 1e95f155ef6..97ffa316da7 100644 --- a/common/features/message/reducer.ts +++ b/common/features/message/reducer.ts @@ -21,6 +21,12 @@ function signMessageFailed(state: types.MessageState): types.MessageState { }; } +function resetMessage(): types.MessageState { + return { + ...INITIAL_STATE + }; +} + export function messageReducer( state: types.MessageState = INITIAL_STATE, action: types.MessageAction @@ -30,6 +36,8 @@ export function messageReducer( return signLocalMessageSucceeded(state, action); case types.MessageActions.SIGN_FAILED: return signMessageFailed(state); + case types.MessageActions.RESET: + return resetMessage(); default: return state; } diff --git a/common/features/message/types.ts b/common/features/message/types.ts index ad4810f569d..197fc5ed0dc 100644 --- a/common/features/message/types.ts +++ b/common/features/message/types.ts @@ -3,7 +3,8 @@ import { ISignedMessage } from 'libs/signing'; export enum MessageActions { SIGN_REQUESTED = 'MESSAGE_SIGN_REQUESTED', SIGN_LOCAL_SUCCEEDED = 'MESSAGE_SIGN_LOCAL_SUCCEEDED', - SIGN_FAILED = 'MESSAGE_SIGN_FAILED' + SIGN_FAILED = 'MESSAGE_SIGN_FAILED', + RESET = 'MESSAGE_RESET' } export interface MessageState { @@ -24,7 +25,12 @@ export interface SignMessageFailedAction { type: MessageActions.SIGN_FAILED; } +export interface ResetMessageAction { + type: MessageActions.RESET; +} + export type MessageAction = | SignMessageRequestedAction | SignLocalMessageSucceededAction - | SignMessageFailedAction; + | SignMessageFailedAction + | ResetMessageAction;