From 1dc5c5b945afe3661d3ffdea13803a0d3d4761be Mon Sep 17 00:00:00 2001 From: Armando Andini Date: Wed, 14 Dec 2022 14:03:03 -0300 Subject: [PATCH] feature: solidity survey notification --- client/src/extension.ts | 3 ++ client/src/popups/showSoliditySurveyPopup.ts | 46 ++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 client/src/popups/showSoliditySurveyPopup.ts diff --git a/client/src/extension.ts b/client/src/extension.ts index 420958004..527d6d4a4 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -1,5 +1,6 @@ import { ExtensionContext } from "vscode"; import { showAnalyticsAllowPopup } from "./popups/showAnalyticsAllowPopup"; +import { showSoliditySurveyPopup } from "./popups/showSoliditySurveyPopup"; import { warnOnOtherSolidityExtensions } from "./popups/warnOnOtherSolidityExtensions"; import { indexHardhatProjects } from "./setup/indexHardhatProjects"; import { setupCommands } from "./setup/setupCommands"; @@ -37,6 +38,8 @@ export async function activate(context: ExtensionContext) { // eslint-disable-next-line @typescript-eslint/no-floating-promises showAnalyticsAllowPopup(extensionState); // eslint-disable-next-line @typescript-eslint/no-floating-promises + showSoliditySurveyPopup(extensionState); // TODO: Remove this after 2023-01-07 + // eslint-disable-next-line @typescript-eslint/no-floating-promises warnOnOtherSolidityExtensions(extensionState); return { diff --git a/client/src/popups/showSoliditySurveyPopup.ts b/client/src/popups/showSoliditySurveyPopup.ts new file mode 100644 index 000000000..6383400e4 --- /dev/null +++ b/client/src/popups/showSoliditySurveyPopup.ts @@ -0,0 +1,46 @@ +import { window, ExtensionContext, commands, Uri } from "vscode"; + +const SHOW_SURVEY_COOLDOWN = 7 * 24 * 60 * 60 * 1000; + +// TODO: Remove this after 2023-01-07 +export async function showSoliditySurveyPopup({ + context, +}: { + context: ExtensionContext; +}): Promise { + const alreadyAnswered = + context.globalState.get("answered2022Survey") ?? false; + const lastShown = context.globalState.get("survey2022LastShown") ?? 0; + + if (alreadyAnswered || pastLimitDate() || shownRecently(lastShown)) { + return; + } + + const item = await window.showInformationMessage( + "Please respond to the 2022 Solidity Developer Survey", + "Respond" + ); + + // Store that we've shown the popup + await context.globalState.update("survey2022LastShown", new Date().getTime()); + + if (item === "Respond") { + await commands.executeCommand( + "vscode.open", + Uri.parse( + "https://blog.soliditylang.org/2022/12/07/solidity-developer-survey-2022-announcement/" + ) + ); + + // Store that the user answered the survey + await context.globalState.update("answered2022Survey", true); + } +} + +function shownRecently(lastShown: number) { + return new Date().getTime() - lastShown < SHOW_SURVEY_COOLDOWN; +} + +function pastLimitDate(): boolean { + return new Date().getTime() > Date.parse("2023-01-07 22:59:00 +0000"); +}