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

Emc/fix/1944-profile-portfolio-issues #1945

Merged
merged 6 commits into from
Dec 1, 2023
Merged
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
3 changes: 2 additions & 1 deletion carbonmark-api/src/models/User.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Static, Type } from "@sinclair/typebox";
import { isNil } from "lodash";
import { ActivityModel } from "./Activity.model";
import { AssetModel } from "./Asset.model";
import { ListingModel } from "./Listing.model";
Expand Down Expand Up @@ -27,7 +28,7 @@ export function isUser(obj: any): obj is User {
typeof obj.handle === "string" &&
typeof obj.username === "string" &&
typeof obj.description === "string" &&
(obj.profileImgUrl === null || typeof obj.profileImgUrl === "string") &&
(isNil(obj.profileImgUrl) || typeof obj.profileImgUrl === "string") &&
typeof obj.updatedAt === "number" &&
typeof obj.createdAt === "number" &&
typeof obj.wallet === "string" &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Balances } from "./Balances";
import * as styles from "./styles";

type Props = {
user: User | null;
user?: User | null;
isPending: boolean;
};

Expand Down
4 changes: 2 additions & 2 deletions carbonmark/components/pages/Portfolio/Retire/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
PcbProject,
} from "lib/types/carbonmark.types";
import { notNil } from "lib/utils/functional.utils";
import { isNil } from "lodash";
import { NextPage } from "next";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
Expand Down Expand Up @@ -46,8 +47,7 @@ export const Retire: NextPage<RetirePageProps> = (props) => {
const isConnectedUser = isConnected && address;

const isCarbonmarkUser = isConnectedUser && !isLoading && !!carbonmarkUser;
const isUnregistered =
isConnectedUser && !isLoading && carbonmarkUser === null;
const isUnregistered = isConnectedUser && isNil(carbonmarkUser);

const router = useRouter();

Expand Down
8 changes: 3 additions & 5 deletions carbonmark/components/pages/Portfolio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Col, TwoColLayout } from "components/TwoColLayout";
import { Spinner } from "components/shared/Spinner";
import { activityIsAdded, getUserUntil } from "lib/api";
import { notNil } from "lib/utils/functional.utils";
import { isNil } from "lodash";
import { NextPage } from "next";
import { useState } from "react";
import { CarbonmarkAssets } from "./CarbonmarkAssets";
Expand Down Expand Up @@ -40,8 +41,7 @@ export const Portfolio: NextPage = () => {

const isConnectedUser = isConnected && address;
const isCarbonmarkUser = isConnectedUser && !isLoading && !!carbonmarkUser;
const isUnregistered =
isConnectedUser && !isLoading && carbonmarkUser === null;
const isUnregistered = isConnectedUser && isNil(carbonmarkUser);

const onUpdateUser = async () => {
if (!carbonmarkUser) return;
Expand Down Expand Up @@ -111,9 +111,7 @@ export const Portfolio: NextPage = () => {
</Col>

<Col>
{carbonmarkUser && (
<PortfolioSidebar user={carbonmarkUser} isPending={isPending} />
)}
<PortfolioSidebar user={carbonmarkUser} isPending={isPending} />
</Col>
</TwoColLayout>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Text } from "components/Text";
import { addProjectsToAssets, AssetWithProject } from "lib/actions";
import { notNil } from "lib/utils/functional.utils";
import { isListableToken } from "lib/utils/listings.utils";
import { isNil } from "lodash";
import { FC, useEffect, useState } from "react";
import { AssetProject } from "./AssetProject";
import * as styles from "./styles";
Expand All @@ -29,7 +30,7 @@ export const RetireFromPortfolio: FC<Props> = (props) => {
!!carbonmarkUser && !isLoadingAssets && !assetsData?.length;
const hasAssets =
!!carbonmarkUser && !isLoadingAssets && !!listableAssets.length;
const isUnregistered = props.address && !isLoading && carbonmarkUser === null;
const isUnregistered = props.address && !isLoading && isNil(carbonmarkUser);

useEffect(() => {
if (!hasAssets) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FC } from "react";
import * as styles from "./styles";

type Props = {
carbonmarkUser: User | null;
carbonmarkUser?: User | null;
userName: string;
userAddress: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { User } from "lib/types/carbonmark.types";
import { FC } from "react";

type Props = {
user: User | null;
user?: User | null;
isPending?: boolean;
title: string;
};
Expand Down
24 changes: 10 additions & 14 deletions carbonmark/components/pages/Users/SellerConnected/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,11 @@ export const SellerConnected: FC<Props> = (props) => {
<LoginButton className="loginButton" />
</div>
<div className={styles.fullWidth}>
{carbonmarkUser && (
<ProfileHeader
carbonmarkUser={carbonmarkUser}
userName={props.userName}
userAddress={props.userAddress}
/>
)}
<ProfileHeader
carbonmarkUser={carbonmarkUser}
userName={props.userName}
userAddress={props.userAddress}
/>
</div>
<div className={styles.listings}>
<div className={styles.listingsHeader}>
Expand Down Expand Up @@ -209,13 +207,11 @@ export const SellerConnected: FC<Props> = (props) => {
</Col>

<Col>
{carbonmarkUser && (
<ProfileSidebar
user={carbonmarkUser}
isPending={isPending}
title={t`Your seller data`}
/>
)}
<ProfileSidebar
user={carbonmarkUser}
isPending={isPending}
title={t`Your seller data`}
/>
</Col>
</TwoColLayout>

Expand Down
35 changes: 10 additions & 25 deletions carbonmark/components/pages/Users/SellerUnconnected/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGetUsersWalletorhandle } from ".generated/carbonmark-api-sdk/hooks";
import { User } from ".generated/carbonmark-api-sdk/types";
import { useWeb3 } from "@klimadao/lib/utils";
import { t, Trans } from "@lingui/macro";
import { ButtonPrimary } from "components/Buttons/ButtonPrimary";
Expand All @@ -7,30 +7,22 @@ import { Text } from "components/Text";
import { Col, TwoColLayout } from "components/TwoColLayout";
import { createProjectPurchaseLink } from "lib/createUrls";
import { getActiveListings, getSortByUpdateListings } from "lib/listingsGetter";
import { notNil } from "lib/utils/functional.utils";
import { FC } from "react";
import { Listing } from "../Listing";
import { ProfileHeader } from "../ProfileHeader";
import { ProfileSidebar } from "../ProfileSidebar";
import * as styles from "./styles";

type Props = {
user: User | null;
userName: string;
userAddress: string;
};

export const SellerUnconnected: FC<Props> = (props) => {
const { address, isConnected, toggleModal, networkLabel } = useWeb3();
const { data: carbonmarkUser } = useGetUsersWalletorhandle(
props.userAddress,
{
network: networkLabel,
expiresAfter: address === props.userAddress ? "0" : undefined,
},
{ shouldFetch: notNil(props.userAddress) }
);
const { address, isConnected, toggleModal } = useWeb3();

const activeListings = getActiveListings(carbonmarkUser?.listings ?? []);
const activeListings = getActiveListings(props.user?.listings ?? []);
const hasListings = !!activeListings.length;

const sortedListings =
Expand All @@ -44,13 +36,11 @@ export const SellerUnconnected: FC<Props> = (props) => {
<LoginButton className="loginButton" />
</div>
<div className={styles.fullWidth}>
{carbonmarkUser && (
<ProfileHeader
carbonmarkUser={carbonmarkUser}
userName={props.userName}
userAddress={props.userAddress}
/>
)}
<ProfileHeader
carbonmarkUser={props.user}
userName={props.userName}
userAddress={props.userAddress}
/>
</div>
<div className={styles.listings}>
<div className={styles.listingsHeader}>
Expand Down Expand Up @@ -97,12 +87,7 @@ export const SellerUnconnected: FC<Props> = (props) => {
)}
</Col>
<Col>
{carbonmarkUser && (
<ProfileSidebar
user={carbonmarkUser}
title={t`Data for this seller`}
/>
)}
<ProfileSidebar user={props.user} title={t`Data for this seller`} />
</Col>
</TwoColLayout>
</div>
Expand Down
7 changes: 3 additions & 4 deletions carbonmark/components/pages/Users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { t } from "@lingui/macro";
import { Layout } from "components/Layout";
import { PageHead } from "components/PageHead";
import { useConnectedUser } from "hooks/useConnectedUser";
import { getUsersWalletorHandleKey } from "lib/api/swr.keys";
import { fetcher } from "lib/fetcher";
import { User } from "lib/types/carbonmark.types";
import { NextPage } from "next";
Expand Down Expand Up @@ -47,6 +46,7 @@ const Page: NextPage<PageProps> = (props) => {

{isUnconnectedUser && (
<SellerUnconnected
user={props.carbonmarkUser}
userAddress={props.userAddress}
userName={userName}
/>
Expand All @@ -62,9 +62,8 @@ export const Users: NextPage<PageProps> = (props) => (
fetcher,
fallback: {
// https://swr.vercel.app/docs/with-nextjs#complex-keys
[unstable_serialize(
getUsersWalletorHandleKey({}, { walletOrHandle: props.userAddress })
)]: props.carbonmarkUser,
[unstable_serialize(`users/${props.userAddress}`)]:
props.carbonmarkUser,
},
}}
>
Expand Down
7 changes: 1 addition & 6 deletions carbonmark/pages/portfolio/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Portfolio } from "components/pages/Portfolio";
import { withConditionalErrorBoundary } from "hocs/ConditionalErrorBoundary";
import { loadTranslation } from "lib/i18n";
import { GetStaticProps } from "next";
import { isNotFoundError } from "next/dist/client/components/not-found";

export const getStaticProps: GetStaticProps = async (ctx) => {
try {
Expand All @@ -27,7 +25,4 @@ export const getStaticProps: GetStaticProps = async (ctx) => {
};

/** We want to allow the page to render on user not found (404s) */
export default withConditionalErrorBoundary(Portfolio, {
fallback: <h1>User cannot be found</h1>,
predicate: isNotFoundError,
});
export default Portfolio;
7 changes: 1 addition & 6 deletions carbonmark/pages/users/[user].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { getUsersWalletorhandle } from ".generated/carbonmark-api-sdk/clients";
import { User } from ".generated/carbonmark-api-sdk/types";
import { PageProps, Users } from "components/pages/Users";
import { isAddress } from "ethers-v6";
import { withConditionalErrorBoundary } from "hocs/ConditionalErrorBoundary";
import { VALID_HANDLE_REGEX } from "lib/constants";
import { loadTranslation } from "lib/i18n";
import { getAddressByDomain } from "lib/shared/getAddressByDomain";
import { getIsDomainInURL } from "lib/shared/getIsDomainInURL";
import { GetStaticProps } from "next";
import { isNotFoundError } from "next/dist/client/components/not-found";
import { ParsedUrlQuery } from "querystring";

interface Params extends ParsedUrlQuery {
Expand Down Expand Up @@ -150,7 +148,4 @@ export const getStaticPaths = async () => {
};
};

export default withConditionalErrorBoundary(Users, {
fallback: <h1>User cannot be found</h1>,
predicate: isNotFoundError,
});
export default Users;
3 changes: 2 additions & 1 deletion site/components/pages/Retirements/SingleRetirement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PageHead } from "components/PageHead";
import { TweetButton } from "components/TweetButton";
import { carbonTokenInfoMap } from "lib/getTokenInfo";
import { normalizeProjectId } from "lib/normalizeProjectId";
import { isNil } from "lodash";
import { NextPage } from "next";
import dynamic from "next/dynamic";
import Image from "next/image";
Expand Down Expand Up @@ -228,7 +229,7 @@ export const SingleRetirementPage: NextPage<SingleRetirementPageProps> = ({
</Text>
<div className={styles.pledge_button}>
<ViewPledgeButton pledge={props.pledge} />
{props.pledge === null && (
{isNil(props.pledge) && (
<Text className={styles.create_pledge} t="caption" align="center">
<Trans id="retirement.single.is_this_your_retirement">
Is this your retirement?
Expand Down