Skip to content

Commit d968ded

Browse files
committed
refactoring
1 parent 240386b commit d968ded

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

extension/iframe.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ class Iframe extends React.Component {
104104
return;
105105
};
106106

107-
U.Data.destroySubscriptions(() => {
108-
C.WalletCloseSession(S.Auth.token, () => S.Auth.tokenSet(''));
109-
});
107+
U.Data.destroySubscriptions(() => U.Data.closeSession());
110108
});
111109
};
112110

extension/popup.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ class Popup extends React.Component {
8787
return;
8888
};
8989

90-
U.Data.destroySubscriptions(() => {
91-
C.WalletCloseSession(S.Auth.token, () => S.Auth.tokenSet(''));
92-
});
90+
U.Data.destroySubscriptions(() => U.Data.closeSession());
9391
});
9492
};
9593

src/ts/app.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,7 @@ class App extends React.Component<object, State> {
392392
};
393393

394394
e.preventDefault();
395-
C.WalletCloseSession(S.Auth.token, () => {
396-
S.Auth.tokenSet('');
397-
window.close();
398-
});
395+
U.Data.closeSession(() => window.close());
399396
return false;
400397
});
401398
} else {

src/ts/lib/util/data.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,7 @@ class UtilData {
486486
};
487487

488488
createSession (phrase: string, key: string, callBack?: (message: any) => void) {
489-
const { token } = S.Auth;
490-
const cb = () => {
489+
this.closeSession(() => {
491490
C.WalletCreateSession(phrase, key, (message: any) => {
492491
if (!message.error.code) {
493492
S.Auth.tokenSet(message.token);
@@ -499,16 +498,26 @@ class UtilData {
499498
callBack(message);
500499
};
501500
});
502-
};
501+
});
502+
};
503503

504-
if (token) {
505-
C.WalletCloseSession(token, () => {
506-
S.Auth.tokenSet('');
507-
cb();
508-
});
509-
} else {
510-
cb();
504+
closeSession (callBack?: () => void) {
505+
const { token } = S.Auth;
506+
507+
if (!token) {
508+
if (callBack) {
509+
callBack();
510+
};
511+
return;
511512
};
513+
514+
C.WalletCloseSession(token, () => {
515+
S.Auth.tokenSet('');
516+
517+
if (callBack) {
518+
callBack();
519+
};
520+
});
512521
};
513522

514523
blockSetText (rootId: string, blockId: string, text: string, marks: I.Mark[], update: boolean, callBack?: (message: any) => void) {

src/ts/store/auth.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,11 @@ class AuthStore {
179179
};
180180

181181
logout (mainWindow: boolean, removeData: boolean) {
182-
const cb = () => {
183-
C.WalletCloseSession(this.token, () => this.tokenSet(''));
184-
};
185-
186182
if (mainWindow) {
187-
C.AccountStop(removeData, () => cb());
183+
C.AccountStop(removeData, () => U.Data.closeSession());
188184
Renderer.send('logout');
189185
} else {
190-
cb();
186+
U.Data.closeSession();
191187
};
192188

193189
analytics.profile('', '');

0 commit comments

Comments
 (0)