Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update profileCard.tsx #942

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 49 additions & 28 deletions app/[addressOrDomain]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export default function Page({ params }: AddressOrDomainProps) {
const [identity, setIdentity] = useState<Identity>();
const [notFound, setNotFound] = useState(false);
const [isOwner, setIsOwner] = useState(false);
const [isLoading, setIsLoading] = useState(true);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless space + unprecise naming, what is loading here ? I would go for isProfileCardLoading

const [completedQuests, setCompletedQuests] = useState<CompletedQuests>([]);
const [userRanking, setUserRanking] = useState<RankingData>({
first_elt_position: -1,
Expand All @@ -103,6 +105,8 @@ export default function Page({ params }: AddressOrDomainProps) {
[]
);



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless space again please use prettier vs code extension to format everything

useEffect(() => {
if (!address) setIsOwner(false);
}, [address]);
Expand Down Expand Up @@ -201,6 +205,7 @@ export default function Page({ params }: AddressOrDomainProps) {
setQuestsLoading(false);
}, []);


const calculateAssetPercentages = async (
userTokens: ArgentUserToken[],
tokens: ArgentTokenMap,
Expand Down Expand Up @@ -289,6 +294,10 @@ export default function Page({ params }: AddressOrDomainProps) {
assetValues[symbol] = (assetValues[symbol] || 0) + value;
}
});




Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete useless space

// Convert to percentages and format
const sortedAssets = Object.entries(assetValues)
.sort(([, a], [, b]) => b - a)
Expand Down Expand Up @@ -397,8 +406,10 @@ export default function Page({ params }: AddressOrDomainProps) {
tokens: ArgentTokenMap,
dapps: ArgentDappMap,
) => {

for await (const token of userTokens) {
const tokenInfo = tokens[token.tokenAddress];

if (tokenInfo.dappId && token.tokenBalance != "0") {
let itemValue = 0;
const currentTokenBalance = await calculateTokenPrice(
Expand Down Expand Up @@ -501,9 +512,9 @@ export default function Page({ params }: AddressOrDomainProps) {
};

const fetchPortfolioProtocols = useCallback(async (data: {
dapps: ArgentDappMap,
tokens: ArgentTokenMap,
userTokens: ArgentUserToken[],
dapps: ArgentDappMap,
tokens: ArgentTokenMap,
userTokens: ArgentUserToken[],
userDapps: ArgentUserDapp[]
}) => {
const { dapps, tokens, userTokens, userDapps } = data;
Expand All @@ -530,6 +541,8 @@ export default function Page({ params }: AddressOrDomainProps) {
}
}, [address]);



const fetchPortfolioData = useCallback(async (addr: string, abortController: AbortController) => {
setLoadingProtocols(true);
try {
Expand Down Expand Up @@ -566,7 +579,7 @@ export default function Page({ params }: AddressOrDomainProps) {
} finally {
setLoadingProtocols(false);
}
}, [fetchPortfolioProtocols, fetchPortfolioAssets]);
}, [fetchPortfolioProtocols, fetchPortfolioAssets, showNotification]);

useEffect(() => {
const abortController = new AbortController();
Expand All @@ -576,7 +589,11 @@ export default function Page({ params }: AddressOrDomainProps) {
fetchPageData(identity.owner);
fetchPortfolioData(identity.owner, abortController);

return () => abortController.abort();
return () => {
abortController.abort();
setLoadingProtocols(false);
setIsLoading(false);
};
}, [identity]);

useEffect(() => setNotFound(false), [dynamicRoute]);
Expand All @@ -585,6 +602,10 @@ export default function Page({ params }: AddressOrDomainProps) {
setInitProfile(false);
}, [address, addressOrDomain]);





Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useleszs space again use prettier !

useEffect(() => {
if (
typeof addressOrDomain === "string" &&
Expand Down Expand Up @@ -723,6 +744,7 @@ export default function Page({ params }: AddressOrDomainProps) {
rankingData={userRanking}
leaderboardData={leaderboardData}
isOwner={isOwner}
isLoading={isLoading}
/>
) : (
<ProfileCardSkeleton />
Expand All @@ -731,31 +753,30 @@ export default function Page({ params }: AddressOrDomainProps) {

{/* Portfolio charts */}
<div className={styles.dashboard_portfolio_summary_container}>
{loadingProtocols ? ( // Change for corresponding state
<PortfolioSummarySkeleton />
) : (
<PortfolioSummary
title="Portfolio by assets type"
data={portfolioAssets}
totalBalance={portfolioAssets.reduce(
(sum, item) => sum + Number(item.itemValue),
0
)}
isProtocol={false}
/>
)}
{loadingProtocols ? (

{(!portfolioAssets || !portfolioProtocols || loadingProtocols) ? (
<PortfolioSummarySkeleton />
) : (
<PortfolioSummary
title="Portfolio by protocol usage"
data={portfolioProtocols}
totalBalance={portfolioProtocols.reduce(
(sum, item) => sum + Number(item.itemValue),
0
)}
isProtocol={true}
/>
<>
<PortfolioSummary
title="Portfolio by assets type"
data={portfolioAssets}
totalBalance={portfolioAssets.reduce(
(sum, item) => sum + Number(item.itemValue),
0
)}
isProtocol={false}
/>
<PortfolioSummary
title="Portfolio by protocol usage"
data={portfolioProtocols}
totalBalance={portfolioProtocols.reduce(
(sum, item) => sum + Number(item.itemValue),
0
)}
isProtocol={true}
/>
</>
)}
</div>

Expand Down
109 changes: 65 additions & 44 deletions components/UI/profileCard/profileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Typography from "../typography/typography";
import { calculateTotalBalance } from "../../../services/argentPortfolioService";
import Avatar from "../avatar";
import { useHidePortfolio } from "@hooks/useHidePortfolio";
import Loading from "@components/skeletons/loading";

const MAX_RETRIES = 1000;
const RETRY_DELAY = 2000;
Expand All @@ -36,13 +37,15 @@ type ProfileCardProps = {
identity: Identity;
leaderboardData: LeaderboardToppersData;
isOwner: boolean;
isLoading:boolean;
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add missing isLoading prop to component parameters

The isLoading prop is defined in ProfileCardProps but not included in the component's parameter destructuring. This makes the prop inaccessible within the component.

Apply this fix:

const ProfileCard: FunctionComponent<ProfileCardProps> = ({
  rankingData,
  identity,
  leaderboardData,
  isOwner,
+ isLoading,
}) => {

Also applies to: 44-48

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You add is Loading to the component props but you don't add it where the component is used + you unforce it.

Please test the stuff you send before a PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fricoben, thank you for pointing this out. You're absolutely correct; the isLoading prop was added to the ProfileCard component but wasn't included where the component is used. To fix this, please ensure that isLoading is passed as a prop in all instances where ProfileCard is instantiated.

For example:

<ProfileCard
  rankingData={rankingData}
  identity={identity}
  leaderboardData={leaderboardData}
  isOwner={isOwner}
  isLoading={isLoading}
/>

Additionally, it's important to thoroughly test your changes before submitting a PR to avoid such oversights.

};

const ProfileCard: FunctionComponent<ProfileCardProps> = ({
rankingData,
identity,
leaderboardData,
isOwner,
isLoading,
}) => {
const { hidePortfolio, setHidePortfolio } = useHidePortfolio();
const [userXp, setUserXp] = useState<number>();
Expand Down Expand Up @@ -114,62 +117,79 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
<div className={styles.dashboard_profile_card}>
<div className={styles.left}>
<div className={styles.profile_picture_div}>
{ formattedAddress?.length !== 0 ? ( // show the avatar of the address in the URL
{formattedAddress?.length !== 0 ? (
<Avatar width="120" address={formattedAddress} />
) : (
<ProfilIcon width="120" color={theme.palette.secondary.main} />
)}
</div>

<div className="flex flex-col h-full justify-center">
<Typography
type={TEXT_TYPE.BODY_SMALL}
color="secondary"
className={styles.accountCreationDate}
>
{sinceDate ? `${sinceDate}` : ""}
</Typography>
<Typography
type={TEXT_TYPE.H2}
className={`${styles.profile_name} mt-2`}
>
{identity.domain?.domain || "Unknown Domain"}
</Typography>
<div className={styles.address_div}>
<div className="flex items-center gap-2">
{isLoading ? (
<>
{/* Updated the Specific Profile Card Component with skeleton Loading component */}
<Skeleton variant="text" width="80%" height={20} />
<Skeleton variant="text" width="60%" height={30} className="mt-2" />
<div className={styles.address_div}>
<div className="flex items-center gap-2">
<Skeleton variant="rectangular" width={100} height={30} />
<EyeIcon />
</div>
</div>
</>
) : (
<>
<Typography
type={TEXT_TYPE.BODY_SMALL}
className={`${styles.wallet_amount} font-extrabold`}
color="secondary"
className={styles.accountCreationDate}
>
{totalBalance !== null ? (
hidePortfolio ? "******" : `$${totalBalance.toFixed(2)}`
) : (
<Skeleton variant="text" width={60} height={30} />
)}
{sinceDate ? `${sinceDate}` : ""}
</Typography>
<div onClick={() => setHidePortfolio(!hidePortfolio)} className="cursor-pointer">
{hidePortfolio ? <EyeIconSlashed /> : <EyeIcon />}
</div>
</div>
</div>
<div className="flex sm:hidden justify-center py-4">
<SocialMediaActions identity={identity} />
{tweetShareLink && (
<Link href={tweetShareLink} target="_blank" rel="noreferrer">
<div className={styles.right_share_button}>
<CDNImage
src={shareSrc}
width={20}
height={20}
alt="share-icon"
/>
<Typography type={TEXT_TYPE.BODY_DEFAULT}>Share</Typography>
<Typography
type={TEXT_TYPE.H2}
className={`${styles.profile_name} mt-2`}
>
{identity.domain?.domain || "Unknown Domain"}
</Typography>
<div className={styles.address_div}>
<div className="flex items-center gap-2">
<Typography
type={TEXT_TYPE.BODY_SMALL}
className={`${styles.wallet_amount} font-extrabold`}
>
{totalBalance !== null ? (
hidePortfolio ? "******" : `$${totalBalance.toFixed(2)}`
) : (
<Skeleton variant="text" width={60} height={30} />
)}
</Typography>
<div onClick={() => setHidePortfolio(!hidePortfolio)} className="cursor-pointer">
{hidePortfolio ? <EyeIconSlashed /> : <EyeIcon />}
</div>
</div>
</Link>
)}
</div>
</div>
</>
)}
</div>

<div className="flex sm:hidden justify-center py-4">
<SocialMediaActions identity={identity} />
{tweetShareLink && (
<Link href={tweetShareLink} target="_blank" rel="noreferrer">
<div className={styles.right_share_button}>
<CDNImage
src={shareSrc}
width={20}
height={20}
alt="share-icon"
/>
<Typography type={TEXT_TYPE.BODY_DEFAULT}>Share</Typography>
</div>
</Link>
)}
</div>
</div>

<div className={styles.right}>
<div className="hidden sm:flex">
<div className={styles.right_top}>
Expand All @@ -191,7 +211,7 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
</div>
</div>
</div>

<div className={styles.right_bottom}>
{leaderboardData && leaderboardData.total_users > 0 && (
<div className={styles.right_bottom_content}>
Expand Down Expand Up @@ -232,6 +252,7 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
</div>
</div>
</div>

);
};

Expand Down
Loading