-
Notifications
You must be signed in to change notification settings - Fork 138
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
||
const [completedQuests, setCompletedQuests] = useState<CompletedQuests>([]); | ||
const [userRanking, setUserRanking] = useState<RankingData>({ | ||
first_elt_position: -1, | ||
|
@@ -103,6 +105,8 @@ export default function Page({ params }: AddressOrDomainProps) { | |
[] | ||
); | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
|
@@ -201,6 +205,7 @@ export default function Page({ params }: AddressOrDomainProps) { | |
setQuestsLoading(false); | ||
}, []); | ||
|
||
|
||
const calculateAssetPercentages = async ( | ||
userTokens: ArgentUserToken[], | ||
tokens: ArgentTokenMap, | ||
|
@@ -289,6 +294,10 @@ export default function Page({ params }: AddressOrDomainProps) { | |
assetValues[symbol] = (assetValues[symbol] || 0) + value; | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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( | ||
|
@@ -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; | ||
|
@@ -530,6 +541,8 @@ export default function Page({ params }: AddressOrDomainProps) { | |
} | ||
}, [address]); | ||
|
||
|
||
|
||
const fetchPortfolioData = useCallback(async (addr: string, abortController: AbortController) => { | ||
setLoadingProtocols(true); | ||
try { | ||
|
@@ -566,7 +579,7 @@ export default function Page({ params }: AddressOrDomainProps) { | |
} finally { | ||
setLoadingProtocols(false); | ||
} | ||
}, [fetchPortfolioProtocols, fetchPortfolioAssets]); | ||
}, [fetchPortfolioProtocols, fetchPortfolioAssets, showNotification]); | ||
|
||
useEffect(() => { | ||
const abortController = new AbortController(); | ||
|
@@ -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]); | ||
|
@@ -585,6 +602,10 @@ export default function Page({ params }: AddressOrDomainProps) { | |
setInitProfile(false); | ||
}, [address, addressOrDomain]); | ||
|
||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useleszs space again use prettier ! |
||
useEffect(() => { | ||
if ( | ||
typeof addressOrDomain === "string" && | ||
|
@@ -723,6 +744,7 @@ export default function Page({ params }: AddressOrDomainProps) { | |
rankingData={userRanking} | ||
leaderboardData={leaderboardData} | ||
isOwner={isOwner} | ||
isLoading={isLoading} | ||
/> | ||
) : ( | ||
<ProfileCardSkeleton /> | ||
|
@@ -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> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -36,13 +37,15 @@ type ProfileCardProps = { | |
identity: Identity; | ||
leaderboardData: LeaderboardToppersData; | ||
isOwner: boolean; | ||
isLoading:boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing isLoading prop to component parameters The Apply this fix: const ProfileCard: FunctionComponent<ProfileCardProps> = ({
rankingData,
identity,
leaderboardData,
isOwner,
+ isLoading,
}) => { Also applies to: 44-48 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fricoben, thank you for pointing this out. You're absolutely correct; the 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>(); | ||
|
@@ -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}> | ||
|
@@ -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}> | ||
|
@@ -232,6 +252,7 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({ | |
</div> | ||
</div> | ||
</div> | ||
|
||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
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