Skip to content

Commit

Permalink
chore: add the solidity survery 2024 popup (#625)
Browse files Browse the repository at this point in the history
* chore: add the solidity survery 2024 popup

* Update showSoliditySurveyPopup.ts

Co-authored-by: John Kane <[email protected]>

---------

Co-authored-by: John Kane <[email protected]>
  • Loading branch information
galargh and kanej committed Jan 14, 2025
1 parent a4e4ec3 commit f480fbd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);

Expand Down
45 changes: 45 additions & 0 deletions client/src/popups/showSoliditySurveyPopup.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const now = new Date().getTime();

if (now > SURVEY_END_DATE) {
return;
}

const completed = context.globalState.get<boolean>(SURVEY_COMPLETED_KEY);

if (completed === true) {
return;
}

const lastSeen = context.globalState.get<number>(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);
}
}

0 comments on commit f480fbd

Please sign in to comment.