Skip to content

Commit

Permalink
feature: solidity survey notification
Browse files Browse the repository at this point in the history
  • Loading branch information
antico5 committed Dec 14, 2022
1 parent 80743ad commit 1dc5c5b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 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 @@ -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 {
Expand Down
46 changes: 46 additions & 0 deletions client/src/popups/showSoliditySurveyPopup.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const alreadyAnswered =
context.globalState.get<boolean>("answered2022Survey") ?? false;
const lastShown = context.globalState.get<number>("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");
}

0 comments on commit 1dc5c5b

Please sign in to comment.