Skip to content

Commit

Permalink
fix: ensure a failure to fetch the LENS profile does not crash the dA…
Browse files Browse the repository at this point in the history
…pp (#944)
  • Loading branch information
levalleux-ludo authored Nov 29, 2023
1 parent a269f2e commit 14a2d53
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}, []);
Expand Down
2 changes: 2 additions & 0 deletions src/components/modal/components/Profile/EditProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}, []);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/hooks/lens/fetchLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function fetchLens<T, V = Record<string, unknown>>(
document: RequestDocument,
variables?: V,
headers?: Record<string, unknown>
): Promise<T> {
): Promise<T | null> {
try {
const data = await request<T, V>(lensApiLink, document, variables, {
...headers,
Expand All @@ -17,6 +17,6 @@ export async function fetchLens<T, V = Record<string, unknown>>(
} catch (error) {
console.error(error);
Sentry.captureException(error);
throw error;
}
return null;
}
5 changes: 3 additions & 2 deletions src/lib/utils/hooks/lens/profile/useGetLensProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async function getLensProfiles(
lensApiLink: string
) {
return (
await fetchLens<ProfilesQuery>(lensApiLink, ProfilesDocument, { request })
).profiles;
(await fetchLens<ProfilesQuery>(lensApiLink, ProfilesDocument, { request }))
?.profiles || { items: [], pageInfo: { totalCount: 0 } }
);
}
4 changes: 3 additions & 1 deletion src/pages/profile/seller/Seller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ??
Expand Down

0 comments on commit 14a2d53

Please sign in to comment.