Skip to content

Commit

Permalink
Discard signed message after leaving tab (#2056)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwbailey authored and dternyak committed Jul 18, 2018
1 parent e242d09 commit 4830469
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props {
signMessageRequested: messageActions.TSignMessageRequested;
signedMessage: ISignedMessage | null;
resetWallet: walletActions.TResetWallet;
resetMessage: messageActions.TResetMessage;
}

interface State {
Expand All @@ -35,6 +36,7 @@ export class SignMessage extends Component<Props, State> {

public componentWillUnmount() {
this.props.resetWallet();
this.props.resetMessage();
}

public render() {
Expand Down Expand Up @@ -97,6 +99,8 @@ export class SignMessage extends Component<Props, State> {

private changeWallet = () => {
this.props.resetWallet();
this.props.resetMessage();
this.setState(initialState);
};
}

Expand All @@ -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);
7 changes: 7 additions & 0 deletions common/features/message/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
8 changes: 8 additions & 0 deletions common/features/message/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
10 changes: 8 additions & 2 deletions common/features/message/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

0 comments on commit 4830469

Please sign in to comment.