Skip to content

Commit

Permalink
feat(app): adding ability to reset onboarding skip (passportxyz#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer authored Apr 22, 2024
1 parent ccc89ff commit eaed809
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/.env-example.env
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ NEXT_PUBLIC_MAINTENANCE_MODE_ON=["2023-06-07T21:00:00.000Z", "2023-06-08T22:15:0
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=YOUR_WALLET_CONNECT_PROJECT_ID
NEXT_PUBLIC_WEB3_ONBOARD_EXPLORE_URL=http://localhost:3000/
NEXT_PUBLIC_FF_CERAMIC_CLIENT=off
NEXT_PUBLIC_ONBOARD_RESET_INDEX=1
41 changes: 31 additions & 10 deletions app/__tests__/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
} from "@gitcoin/passport-types";
import { platforms } from "@gitcoin/passport-platforms";
const { Ens, Lens, Github } = platforms;
import { checkShowOnboard } from "../../utils/helpers";

import axios from "axios";
import { _checkShowOnboard } from "../../utils/helpers";

const mockedAllPlatforms = new Map();
mockedAllPlatforms.set("Ens", {
Expand Down Expand Up @@ -68,25 +67,47 @@ describe("checkShowOnboard", () => {
localStorage.clear();
});

it("returns true if onboardTS is not set in localStorage", () => {
expect(checkShowOnboard()).toBe(true);
it("returns true if onboardTS is not set in localStorage", async () => {
expect(_checkShowOnboard("")).toBe(true);
});

it("returns true if onboardTS is set and older than 3 months", () => {
it("returns true if onboardTS is set and older than 3 months", async () => {
const olderTimestamp = Math.floor(Date.now() / 1000) - 3 * 30 * 24 * 60 * 60 - 1;
localStorage.setItem("onboardTS", olderTimestamp.toString());
expect(checkShowOnboard()).toBe(true);
expect(_checkShowOnboard("")).toBe(true);
});

it("returns false if onboardTS is set and within the last 3 months", () => {
it("returns false if onboardTS is set and within the last 3 months", async () => {
const recentTimestamp = Math.floor(Date.now() / 1000) - 2 * 30 * 24 * 60 * 60;
localStorage.setItem("onboardTS", recentTimestamp.toString());
expect(checkShowOnboard()).toBe(false);
expect(_checkShowOnboard("")).toBe(false);
});

it("returns true if onboardTS is set and exactly 3 months old", () => {
it("returns true if onboardTS is set and exactly 3 months old", async () => {
const threeMonthsOldTimestamp = Math.floor(Date.now() / 1000) - 3 * 30 * 24 * 60 * 60;
localStorage.setItem("onboardTS", threeMonthsOldTimestamp.toString());
expect(checkShowOnboard()).toBe(true);
expect(_checkShowOnboard("")).toBe(true);
});

it("returns true if ONBOARD_RESET_INDEX newly set", async () => {
const recentTimestamp = Math.floor(Date.now() / 1000) - 2 * 30 * 24 * 60 * 60;
localStorage.setItem("onboardTS", recentTimestamp.toString());
expect(_checkShowOnboard("1")).toBe(true);
});

it("returns false if ONBOARD_RESET_INDEX set but already processed and re-skipped", async () => {
const recentTimestamp = Math.floor(Date.now() / 1000) - 2 * 30 * 24 * 60 * 60;
localStorage.setItem("onboardTS", recentTimestamp.toString());
expect(_checkShowOnboard("1")).toBe(true);
localStorage.setItem("onboardTS", recentTimestamp.toString());
expect(_checkShowOnboard("1")).toBe(false);
});

it("returns true if ONBOARD_RESET_INDEX set, re-skipped, then changed again", async () => {
const recentTimestamp = Math.floor(Date.now() / 1000) - 2 * 30 * 24 * 60 * 60;
localStorage.setItem("onboardTS", recentTimestamp.toString());
expect(_checkShowOnboard("1")).toBe(true);
localStorage.setItem("onboardTS", recentTimestamp.toString());
expect(_checkShowOnboard("2")).toBe(true);
});
});
19 changes: 18 additions & 1 deletion app/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ export function reduceStampResponse(providerIDs: PROVIDER_ID[], verifiedCredenti
}));
}

export function checkShowOnboard(): boolean {
// This is pulled out to support testing
// Use `checkShowOnboard` instead
export function _checkShowOnboard(currentOnboardResetIndex: string) {
const savedOnboardResetIndex = localStorage.getItem("onboardResetIndex");

localStorage.setItem("onboardResetIndex", currentOnboardResetIndex || "");

if (currentOnboardResetIndex && currentOnboardResetIndex !== savedOnboardResetIndex) {
localStorage.removeItem("onboardTS");
return true;
}

const onboardTs = localStorage.getItem("onboardTS");

if (!onboardTs) return true;
// Get the current Unix timestamp in seconds.
const currentTimestamp = Math.floor(Date.now() / 1000);
Expand All @@ -66,6 +78,11 @@ export function checkShowOnboard(): boolean {
return onBoardOlderThanThreeMonths;
}

export function checkShowOnboard(): boolean {
const currentOnboardResetIndex = process.env.NEXT_PUBLIC_ONBOARD_RESET_INDEX || "";
return _checkShowOnboard(currentOnboardResetIndex);
}

/**
* Fetch data from a GraphQL endpoint
*
Expand Down

0 comments on commit eaed809

Please sign in to comment.