From f1842796879d5eb8927e166db89a166bbf845ca8 Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Sat, 11 Nov 2023 16:39:17 +0000 Subject: [PATCH] fix crash on account with no perfs --- src/components/common/AccountCards.tsx | 56 +++++++++++++------------- src/utils/lichess.tsx | 2 +- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/components/common/AccountCards.tsx b/src/components/common/AccountCards.tsx index 2e177909..b2a4f78c 100644 --- a/src/components/common/AccountCards.tsx +++ b/src/components/common/AccountCards.tsx @@ -20,23 +20,25 @@ function AccountCards({ const account = session.lichess.account; const lichessSession = session.lichess; const totalGames = - (account.perfs.ultraBullet?.games ?? 0) + - (account.perfs.bullet?.games ?? 0) + - (account.perfs.blitz?.games ?? 0) + - (account.perfs.rapid?.games ?? 0) + - (account.perfs.classical?.games ?? 0); + (account.perfs?.ultraBullet?.games ?? 0) + + (account.perfs?.bullet?.games ?? 0) + + (account.perfs?.blitz?.games ?? 0) + + (account.perfs?.rapid?.games ?? 0) + + (account.perfs?.classical?.games ?? 0); const stats = []; const speeds = ["bullet", "blitz", "rapid", "classical"] as const; - for (const speed of speeds) { - const perf = account.perfs[speed]; - if (perf) { - stats.push({ - value: perf.rating, - label: speed, - diff: perf.prog, - }); + if (account.perfs) { + for (const speed of speeds) { + const perf = account.perfs[speed]; + if (perf) { + stats.push({ + value: perf.rating, + label: speed, + diff: perf.prog, + }); + } } } @@ -69,13 +71,13 @@ function AccountCards({ sessions.map((s) => s.lichess?.account.id === account.id ? { - ...s, - lichess: { - account: account, - accessToken: lichessSession.accessToken, - }, - updatedAt: Date.now(), - } + ...s, + lichess: { + account: account, + accessToken: lichessSession.accessToken, + }, + updatedAt: Date.now(), + } : s ) ); @@ -120,13 +122,13 @@ function AccountCards({ sessions.map((s) => s.chessCom?.username === session.chessCom?.username ? { - ...s, - chessCom: { - username: session.chessCom!.username, - stats, - }, - updatedAt: Date.now(), - } + ...s, + chessCom: { + username: session.chessCom!.username, + stats, + }, + updatedAt: Date.now(), + } : s ) ); diff --git a/src/utils/lichess.tsx b/src/utils/lichess.tsx index 9bf2ff4b..0200a60a 100644 --- a/src/utils/lichess.tsx +++ b/src/utils/lichess.tsx @@ -29,7 +29,7 @@ type LichessPerf = { export type LichessAccount = { id: string; username: string; - perfs: { + perfs?: { chess960?: LichessPerf; atomic?: LichessPerf; racingKings?: LichessPerf;