From 14a2d5328692584c87eda7801d2e798fa6061021 Mon Sep 17 00:00:00 2001 From: Ludovic Levalleux Date: Wed, 29 Nov 2023 09:32:30 +0000 Subject: [PATCH] fix: ensure a failure to fetch the LENS profile does not crash the dApp (#944) --- .../modal/components/Profile/CreateProfileModal.tsx | 2 ++ src/components/modal/components/Profile/EditProfileModal.tsx | 2 ++ src/lib/utils/hooks/lens/fetchLens.ts | 4 ++-- src/lib/utils/hooks/lens/profile/useGetLensProfiles.ts | 5 +++-- src/pages/profile/seller/Seller.tsx | 4 +++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/modal/components/Profile/CreateProfileModal.tsx b/src/components/modal/components/Profile/CreateProfileModal.tsx index fca49e238..67709e23a 100644 --- a/src/components/modal/components/Profile/CreateProfileModal.tsx +++ b/src/components/modal/components/Profile/CreateProfileModal.tsx @@ -96,6 +96,8 @@ export default function CreateProfileModal({ ); const { refetch } = useCurrentSellers(); const setSwitchAndProfileType = useCallback((switchToLens: boolean) => { + // allow the seller to unlink the lens profile, but does not allow to switch it back + switchToLens = false; setSwitchChecked(switchToLens); setProfileType(switchToLens ? ProfileType.LENS : ProfileType.REGULAR); }, []); diff --git a/src/components/modal/components/Profile/EditProfileModal.tsx b/src/components/modal/components/Profile/EditProfileModal.tsx index 5573a798b..7befe7020 100644 --- a/src/components/modal/components/Profile/EditProfileModal.tsx +++ b/src/components/modal/components/Profile/EditProfileModal.tsx @@ -52,6 +52,8 @@ export default function EditProfileModal({ profileType === ProfileType.LENS ); const setSwitchAndProfileType = useCallback((switchToLens: boolean) => { + // allow the seller to unlink the lens profile, but does not allow to switch it back + switchToLens = false; setSwitchChecked(switchToLens); setProfileType(switchToLens ? ProfileType.LENS : ProfileType.REGULAR); }, []); diff --git a/src/lib/utils/hooks/lens/fetchLens.ts b/src/lib/utils/hooks/lens/fetchLens.ts index 47a822202..ed362b9d0 100644 --- a/src/lib/utils/hooks/lens/fetchLens.ts +++ b/src/lib/utils/hooks/lens/fetchLens.ts @@ -6,7 +6,7 @@ export async function fetchLens>( document: RequestDocument, variables?: V, headers?: Record -): Promise { +): Promise { try { const data = await request(lensApiLink, document, variables, { ...headers, @@ -17,6 +17,6 @@ export async function fetchLens>( } catch (error) { console.error(error); Sentry.captureException(error); - throw error; } + return null; } diff --git a/src/lib/utils/hooks/lens/profile/useGetLensProfiles.ts b/src/lib/utils/hooks/lens/profile/useGetLensProfiles.ts index 0fab5cd05..1cb396a08 100644 --- a/src/lib/utils/hooks/lens/profile/useGetLensProfiles.ts +++ b/src/lib/utils/hooks/lens/profile/useGetLensProfiles.ts @@ -37,6 +37,7 @@ async function getLensProfiles( lensApiLink: string ) { return ( - await fetchLens(lensApiLink, ProfilesDocument, { request }) - ).profiles; + (await fetchLens(lensApiLink, ProfilesDocument, { request })) + ?.profiles || { items: [], pageInfo: { totalCount: 0 } } + ); } diff --git a/src/pages/profile/seller/Seller.tsx b/src/pages/profile/seller/Seller.tsx index 830f5f2a3..deae9e212 100644 --- a/src/pages/profile/seller/Seller.tsx +++ b/src/pages/profile/seller/Seller.tsx @@ -140,7 +140,9 @@ export default function Seller() { : null; const name = - (useLens ? sellerLens?.name : metadata?.name) ?? metadata?.name ?? ""; + (useLens ? sellerLens?.name : metadata?.name) ?? + metadata?.name ?? + `Seller ID: ${sellerId}`; const description = (useLens ? sellerLens?.bio : metadata?.description) ?? metadata?.description ??