diff --git a/client/src/extension.ts b/client/src/extension.ts index 144d0522..aac5b5f3 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"; @@ -35,6 +36,9 @@ 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); + // eslint-disable-next-line @typescript-eslint/no-floating-promises warnOnOtherSolidityExtensions(extensionState); diff --git a/client/src/popups/showSoliditySurveyPopup.ts b/client/src/popups/showSoliditySurveyPopup.ts new file mode 100644 index 00000000..a93d42be --- /dev/null +++ b/client/src/popups/showSoliditySurveyPopup.ts @@ -0,0 +1,45 @@ +import { window, ExtensionContext, commands, Uri } from "vscode"; + +const SURVEY_URL = "https://hardhat.org/solidity-survey-2024"; +const SURVEY_COMPLETED_KEY = "soliditySurvey2024Completed"; +const SURVEY_LAST_SEEN_KEY = "soliditySurvey2024LastSeen"; +// Show the survey popup if the user hasn't seen it in the last 7 days +const SURVEY_COOLDOWN_PERIOD = 7 * 24 * 60 * 60 * 1000; +const SURVEY_END_DATE = Date.parse("2025-01-31 23:59:00 +0000"); +const SURVEY_TEXT = + "Please take a few minutes to complete the 2024 Solidity Survey"; +const SURVEY_CTA = "Complete"; + +export async function showSoliditySurveyPopup({ + context, +}: { + context: ExtensionContext; +}): Promise { + const now = new Date().getTime(); + + if (now > SURVEY_END_DATE) { + return; + } + + const completed = context.globalState.get(SURVEY_COMPLETED_KEY); + + if (completed === true) { + return; + } + + const lastSeen = context.globalState.get(SURVEY_LAST_SEEN_KEY); + + if (lastSeen !== undefined && now < lastSeen + SURVEY_COOLDOWN_PERIOD) { + return; + } + + const item = await window.showInformationMessage(SURVEY_TEXT, SURVEY_CTA); + + await context.globalState.update(SURVEY_LAST_SEEN_KEY, now); + + if (item === SURVEY_CTA) { + await commands.executeCommand("vscode.open", Uri.parse(SURVEY_URL)); + + await context.globalState.update(SURVEY_COMPLETED_KEY, true); + } +}