Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add the solidity survery 2024 popup #625

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
galargh marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
Loading