Skip to content

Commit

Permalink
Clear device session on close wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusd committed Oct 23, 2018
1 parent 435ad8b commit ce20082
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/actions/TrezorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,26 @@ export const cancelCurrentOperation = () => async (dispatch, getState) => {
dispatch({ type: TRZ_CANCELOPERATION_SUCCESS });
} catch (error) {
dispatch({ error, type: TRZ_CANCELOPERATION_FAILED });
throw error;
}
};

export const TRZ_CLEARDEVICESESSION_SUCCESS = "TRZ_CLEARDEVICESESSION_SUCCESS";
export const TRZ_CLEARDEVICESESSION_FAILED = "TRZ_CLEARDEVICESESSION_FAILED";

// Closes a device session, locking the device (if it requires a pin).
export const clearDeviceSession = () => async (dispatch, getState) => {
const device = selectors.trezorDevice(getState());
if (!device) return;

await dispatch(cancelCurrentOperation());
try {
await deviceRun(dispatch, getState, device, async session => {
await session.clearSession();
});
dispatch({ type: TRZ_CLEARDEVICESESSION_SUCCESS });
} catch (error) {
dispatch({ error, type: TRZ_CLEARDEVICESESSION_FAILED });
}
};

Expand Down
2 changes: 2 additions & 0 deletions app/actions/WalletLoaderActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import axios from "axios";
import { SpvSyncRequest, SyncNotificationType, RpcSyncRequest } from "../middleware/walletrpc/api_pb";
import { push as pushHistory } from "react-router-redux";
import { stopNotifcations } from "./NotificationActions";
import { clearDeviceSession as trezorClearDeviceSession } from "./TrezorActions";

const MAX_RPC_RETRIES = 5;
const RPC_RETRY_DELAY = 5000;
Expand Down Expand Up @@ -183,6 +184,7 @@ export const closeWalletRequest = () => async(dispatch, getState) => {
await dispatch(stopNotifcations());
await dispatch(syncCancel());
await dispatch(rescanCancel());
await dispatch(trezorClearDeviceSession());
await closeWallet(getState().walletLoader.loader);
await wallet.stopWallet();
dispatch({ type: CLOSEWALLET_SUCCESS });
Expand Down

0 comments on commit ce20082

Please sign in to comment.