Skip to content

Commit

Permalink
bug fix: pfp not working on mobile (#2443)
Browse files Browse the repository at this point in the history
* base

* better
  • Loading branch information
Rohan-cp authored Apr 26, 2024
1 parent 19ff3a6 commit b3705d8
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions apps/mobile/src/components/ProfilePicture/ProfilePicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { useFragment } from 'react-relay';
import { graphql } from 'relay-runtime';

import { ProfilePictureFragment$key } from '~/generated/ProfilePictureFragment.graphql';
import { ProfilePictureValidFragment$key } from '~/generated/ProfilePictureValidFragment.graphql';
import { ReportingErrorBoundary } from '~/shared/errors/ReportingErrorBoundary';
import { useGetSinglePreviewImage } from '~/shared/relay/useGetPreviewImages';

import { RawProfilePicture, RawProfilePictureProps } from './RawProfilePicture';

Expand All @@ -21,6 +23,7 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
profileImage {
... on TokenProfileImage {
token {
...ProfilePictureValidFragment
definition {
media {
... on Media {
Expand Down Expand Up @@ -48,7 +51,7 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
);

const { token, profileImage: ensImage } = user?.profileImage ?? {};
const imageUrl = token?.definition?.media?.previewURLs?.small ?? ensImage?.previewURLs?.small;
const ensImageUrl = ensImage?.previewURLs?.small;

const letter = user?.username?.[0]?.toUpperCase();

Expand All @@ -64,15 +67,29 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
/>
);

if (imageUrl) {
if (ensImageUrl) {
return (
<ReportingErrorBoundary fallback={fallbackProfilePicture}>
<RawProfilePicture
eventElementId="ProfilePicture"
eventName="ProfilePicture pressed"
// TODO analytics prop drill
eventContext={null}
imageUrl={imageUrl}
imageUrl={ensImageUrl}
style={style}
{...rest}
/>
</ReportingErrorBoundary>
);
} else if (token) {
return (
<ReportingErrorBoundary fallback={fallbackProfilePicture}>
<ValidProfilePicture
eventElementId="ProfilePicture"
eventName="ProfilePicture pressed"
// TODO analytics prop drill
eventContext={null}
tokenRef={token}
style={style}
{...rest}
/>
Expand All @@ -82,3 +99,23 @@ export function ProfilePicture({ userRef, style, ...rest }: ProfilePictureProps)
return fallbackProfilePicture;
}
}

type ValidProfilePictureProps = {
style?: ViewProps['style'];
tokenRef: ProfilePictureValidFragment$key;
} & Omit<RawProfilePictureProps, 'imageUrl'>;

function ValidProfilePicture({ tokenRef, style, ...rest }: ValidProfilePictureProps) {
const token = useFragment(
graphql`
fragment ProfilePictureValidFragment on Token {
...useGetPreviewImagesSingleFragment
}
`,
tokenRef
);

const imageUrl = useGetSinglePreviewImage({ tokenRef: token, size: 'small' }) ?? '';

return <RawProfilePicture imageUrl={imageUrl} style={style} {...rest} />;
}

0 comments on commit b3705d8

Please sign in to comment.