diff --git a/extension/iframe.tsx b/extension/iframe.tsx index 5dc5145a49..0f0804da0f 100644 --- a/extension/iframe.tsx +++ b/extension/iframe.tsx @@ -104,9 +104,7 @@ class Iframe extends React.Component { return; }; - U.Data.destroySubscriptions(() => { - C.WalletCloseSession(S.Auth.token, () => S.Auth.tokenSet('')); - }); + U.Data.destroySubscriptions(() => U.Data.closeSession()); }); }; diff --git a/extension/popup.tsx b/extension/popup.tsx index 95482faf91..e452a457d8 100644 --- a/extension/popup.tsx +++ b/extension/popup.tsx @@ -87,9 +87,7 @@ class Popup extends React.Component { return; }; - U.Data.destroySubscriptions(() => { - C.WalletCloseSession(S.Auth.token, () => S.Auth.tokenSet('')); - }); + U.Data.destroySubscriptions(() => U.Data.closeSession()); }); }; diff --git a/src/ts/app.tsx b/src/ts/app.tsx index 85a6ade480..52379aaf14 100644 --- a/src/ts/app.tsx +++ b/src/ts/app.tsx @@ -392,10 +392,7 @@ class App extends React.Component { }; e.preventDefault(); - C.WalletCloseSession(S.Auth.token, () => { - S.Auth.tokenSet(''); - window.close(); - }); + U.Data.closeSession(() => window.close()); return false; }); } else { diff --git a/src/ts/lib/util/data.ts b/src/ts/lib/util/data.ts index ac83847d7d..0b7fcc0fd1 100644 --- a/src/ts/lib/util/data.ts +++ b/src/ts/lib/util/data.ts @@ -486,8 +486,7 @@ class UtilData { }; createSession (phrase: string, key: string, callBack?: (message: any) => void) { - const { token } = S.Auth; - const cb = () => { + this.closeSession(() => { C.WalletCreateSession(phrase, key, (message: any) => { if (!message.error.code) { S.Auth.tokenSet(message.token); @@ -499,16 +498,26 @@ class UtilData { callBack(message); }; }); + }); + }; + + closeSession (callBack?: () => void) { + const { token } = S.Auth; + + if (!token) { + if (callBack) { + callBack(); + }; + return; }; - if (token) { - C.WalletCloseSession(token, () => { - S.Auth.tokenSet(''); - cb(); - }); - } else { - cb(); - }; + C.WalletCloseSession(token, () => { + S.Auth.tokenSet(''); + + if (callBack) { + callBack(); + }; + }); }; blockSetText (rootId: string, blockId: string, text: string, marks: I.Mark[], update: boolean, callBack?: (message: any) => void) { diff --git a/src/ts/store/auth.ts b/src/ts/store/auth.ts index 16eebd28ab..f11de84009 100644 --- a/src/ts/store/auth.ts +++ b/src/ts/store/auth.ts @@ -179,15 +179,11 @@ class AuthStore { }; logout (mainWindow: boolean, removeData: boolean) { - const cb = () => { - C.WalletCloseSession(this.token, () => this.tokenSet('')); - }; - if (mainWindow) { - C.AccountStop(removeData, () => cb()); + C.AccountStop(removeData, () => U.Data.closeSession()); Renderer.send('logout'); } else { - cb(); + U.Data.closeSession(); }; analytics.profile('', '');