From 710c5a02cbd0301b361edaf394c018cad090690a Mon Sep 17 00:00:00 2001 From: Adam Chambers Date: Sat, 9 Dec 2023 23:49:05 +0000 Subject: [PATCH] fix: handle missing referral data --- .../DesktopAccountSummary.tsx | 4 +- .../desktop/Points/PointsOverview.tsx | 28 ++++++++++-- .../marginfi-v2-ui-state/src/lib/points.ts | 45 ++++++++++++------- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/apps/marginfi-v2-ui/src/components/desktop/DesktopAccountSummary/DesktopAccountSummary.tsx b/apps/marginfi-v2-ui/src/components/desktop/DesktopAccountSummary/DesktopAccountSummary.tsx index 860cf3c3dd..e20813dc70 100644 --- a/apps/marginfi-v2-ui/src/components/desktop/DesktopAccountSummary/DesktopAccountSummary.tsx +++ b/apps/marginfi-v2-ui/src/components/desktop/DesktopAccountSummary/DesktopAccountSummary.tsx @@ -23,7 +23,7 @@ const AccountSummary = () => { return (
-
+
Global stats {
{connected && ( -
+
Your account = ({ userPointsData }) => {
- + Total Points
= ({ userPointsData }) => {
- + Lending Points
= ({ userPointsData }) => { - + Borrowing Points
= ({ userPointsData }) => { - + Referral Points
!uuidPattern.test(code)); - isCustomReferralLink = true; - } else { - userReferralCode = userReferralData?.referralCode || ""; - isCustomReferralLink = false; + try { + userPublicProfileSnap = await getDoc(userPublicProfileDoc); + userReferralData = userPublicProfileSnap.data(); + if (userReferralData && Array.isArray(userReferralData?.referralCode)) { + const uuidPattern = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-\b[0-9a-fA-F]{12}$/; + userReferralCode = userReferralData.referralCode.find((code) => !uuidPattern.test(code)); + isCustomReferralLink = true; + } else { + userReferralCode = userReferralData?.referralCode || ""; + isCustomReferralLink = false; + } + } catch (e) { + console.log("error", e); } const pointsData = userPointsSnap.data(); + if (!pointsData) { + return { + ...DEFAULT_USER_POINTS_DATA, + owner: wallet, + }; + } + + console.log("pointsData", pointsData); + const depositPoints = pointsData.total_deposit_points.toFixed(4); const borrowPoints = pointsData.total_borrow_points.toFixed(4); const referralPoints = (pointsData.total_referral_deposit_points + pointsData.total_referral_borrow_points).toFixed(