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 9b2bbf1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
8 changes: 1 addition & 7 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,14 @@ 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, {
extra: {
state: LocalStorage.getItem(GAME_STATE_KEY),
stats: LocalStorage.getItem(GAME_STATS_KEY),
},
});
Expand Down Expand Up @@ -134,13 +130,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

0 comments on commit 9b2bbf1

Please sign in to comment.