From 47d5f1942b4b6a7e66dfe84a3ee640d28dea4427 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Wed, 10 Oct 2018 10:26:13 -0300 Subject: [PATCH] Clear device session on close wallet --- app/actions/TrezorActions.js | 20 ++++++++++++++++++++ app/actions/WalletLoaderActions.js | 2 ++ 2 files changed, 22 insertions(+) diff --git a/app/actions/TrezorActions.js b/app/actions/TrezorActions.js index b575f2fa1e..06dc08166d 100644 --- a/app/actions/TrezorActions.js +++ b/app/actions/TrezorActions.js @@ -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 }); } }; diff --git a/app/actions/WalletLoaderActions.js b/app/actions/WalletLoaderActions.js index 97e9ad32da..ceb2ef79b1 100644 --- a/app/actions/WalletLoaderActions.js +++ b/app/actions/WalletLoaderActions.js @@ -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; @@ -181,6 +182,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 });