Skip to content

Commit

Permalink
remove game state from migration
Browse files Browse the repository at this point in the history
  • Loading branch information
pveyes committed Oct 5, 2023
1 parent 0c7d4ae commit f0e46b6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
7 changes: 1 addition & 6 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ export default function Home(props: Props) {
if (isOnLegacyRoute) {
try {
const hash = LocalStorage.getItem(LAST_HASH_KEY) || "";
const state: GameState = JSON.parse(
LocalStorage.getItem(GAME_STATE_KEY) || JSON.stringify(initialState)
);
const stats: GameStats = JSON.parse(
LocalStorage.getItem(GAME_STATS_KEY) || JSON.stringify(initialStats)
);
const migrationLink = generateMigrationLink(hash, state, stats);
const migrationLink = generateMigrationLink(hash, stats);
window.location.replace(migrationLink);
} catch (err) {
Sentry.captureException(err, {
Expand Down Expand Up @@ -134,13 +131,11 @@ export default function Home(props: Props) {
}

LocalStorage.setItem(GAME_STATS_KEY, JSON.stringify(data.stats));
LocalStorage.setItem(GAME_STATE_KEY, JSON.stringify(data.state));
LocalStorage.setItem(LAST_HASH_KEY, data.lastHash);
if (data.lastHash === game.hash) {
setModalState("stats");
}

game.migrate(data.lastHash, data.state);
setStats(data.stats);
trackEvent("migrationSuccess", {});
router.replace("/");
Expand Down
7 changes: 1 addition & 6 deletions utils/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,10 @@ export function checkHardModeAnswer(
return [false, ""];
}

export function generateMigrationLink(
hash: string,
state: Game["state"],
stats: GameStats
): string {
export function generateMigrationLink(hash: string, stats: GameStats): string {
const migrationData: MigrationData = {
stats,
lastHash: hash,
state: state,
time: Date.now(),
};
const encodedMigrationData = encodeURIComponent(
Expand Down
1 change: 0 additions & 1 deletion utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface Game<T = GameState> {
}

export interface MigrationData {
state: GameState;
stats: GameStats;
lastHash: string;
time: number;
Expand Down

1 comment on commit f0e46b6

@vercel
Copy link

@vercel vercel bot commented on f0e46b6 Oct 5, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

katla – ./

katla-git-main-katla.vercel.app
katla.vercel.app
katla-katla.vercel.app
katla.id

Please sign in to comment.