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

feature: solidity survey notification #312

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful.

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");
}