From 7aa6377fcb5ed2417f4573966b0f47d623ff8c29 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Fri, 3 Mar 2023 13:59:24 +1100 Subject: [PATCH] refactor connect --- extension/src/connect/index.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/extension/src/connect/index.ts b/extension/src/connect/index.ts index 694e69a339..90c936e7cd 100644 --- a/extension/src/connect/index.ts +++ b/extension/src/connect/index.ts @@ -36,7 +36,7 @@ export class Connect extends BaseRepository { void this.getSecret(STUDIO_ACCESS_TOKEN_KEY).then( async studioAccessToken => { this.studioAccessToken = studioAccessToken - await this.setContext() + await this.updateIsStudioConnected() this.deferred.resolve() } ) @@ -46,8 +46,9 @@ export class Connect extends BaseRepository { if (e.key !== STUDIO_ACCESS_TOKEN_KEY) { return } + this.studioAccessToken = await this.getSecret(STUDIO_ACCESS_TOKEN_KEY) - return this.setContext() + return this.updateIsStudioConnected() }) ) @@ -133,17 +134,16 @@ export class Connect extends BaseRepository { return openUrl(`${STUDIO_URL}/user/_/profile?section=accessToken`) } - private setContext() { + private updateIsStudioConnected() { const storedToken = this.getStudioAccessToken() - if (isStudioAccessToken(storedToken)) { - this.studioIsConnected = true - this.sendWebviewMessage() - return setContextValue(ContextKey.STUDIO_CONNECTED, true) - } + const isConnected = isStudioAccessToken(storedToken) + return this.setStudioIsConnected(isConnected) + } - this.studioIsConnected = false + private setStudioIsConnected(isConnected: boolean) { + this.studioIsConnected = isConnected this.sendWebviewMessage() - return setContextValue(ContextKey.STUDIO_CONNECTED, false) + return setContextValue(ContextKey.STUDIO_CONNECTED, isConnected) } private getSecret(key: string) {