Skip to content

Commit

Permalink
Merge branch 'dev' into feat-1500-project-update-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
blushi authored Aug 30, 2023
2 parents 05fcaa8 + a741f90 commit 10b663a
Show file tree
Hide file tree
Showing 31 changed files with 222 additions and 121 deletions.
2 changes: 1 addition & 1 deletion web-components/src/components/cards/OnBoardingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const OnBoardingCard: React.FC<React.PropsWithChildren<Props>> = ({
}) => {
return (
<Card
borderColor="info.light"
borderColor="grey.100"
className={className}
sx={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getBatchQuery } from 'lib/queries/react-query/ecocredit/getBatchQuery/g
import { getClassQuery } from 'lib/queries/react-query/ecocredit/getClassQuery/getClassQuery';
import { getProjectQuery } from 'lib/queries/react-query/ecocredit/getProjectQuery/getProjectQuery';
import { getMetadataQuery } from 'lib/queries/react-query/registry-server/getMetadataQuery/getMetadataQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { useWallet } from 'lib/wallet/wallet';

interface Response {
Expand Down Expand Up @@ -66,7 +66,7 @@ export const useFetchEcocredit = ({ batchDenom }: Props): Response => {

// AllCreditClasses
const { data: creditClassesData } = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

// Credit Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { messageActionEquals } from 'lib/ecocredit/constants';
import { normalizeBridgedEcocredits } from 'lib/normalizers/bridge/normalizeBridgedEcocredits';
import { getBridgeTxStatusQuery } from 'lib/queries/react-query/bridge/getBridgeTxStatusQuery/getBridgeTxStatusQuery';
import { getGetTxsEventQuery } from 'lib/queries/react-query/cosmos/bank/getTxsEventQuery/getTxsEventQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';

import { useBatchesWithMetadata } from 'hooks/batches/useBatchesWithMetadata';

Expand Down Expand Up @@ -57,7 +57,7 @@ export const useFetchBridgedEcocredits = ({ address }: Props): Output => {

// AllCreditClasses
const { data: creditClassData } = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

// TxsEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { chainId } from '../../../lib/ledger';
import { RegistryIconLink, RegistryNavLink } from '../../atoms';
import { WalletButton } from '../WalletButton/WalletButton';
import {
getBorderBottom,
getHeaderColors,
getIsTransparent,
getMenuItems,
Expand All @@ -50,6 +51,8 @@ const RegistryLayoutHeader: React.FC = () => {
const navigate = useNavigate();
const headerColors = useMemo(() => getHeaderColors(theme), [theme]);
const isTransparent = useMemo(() => getIsTransparent(pathname), [pathname]);
const borderBottom = useMemo(() => getBorderBottom(pathname), [pathname]);

const menuItems = useMemo(() => getMenuItems(pathname), [pathname]);
const userMenuItems = useMemo(
() => getUserMenuItems({ linkComponent: RegistryNavLink, pathname, theme }),
Expand Down Expand Up @@ -89,7 +92,7 @@ const RegistryLayoutHeader: React.FC = () => {
color={color}
transparent={isTransparent}
absolute={isTransparent}
borderBottom={false} // TODO: there's some bug where this won't change on routes - hardcoded for now
borderBottom={borderBottom}
fullWidth={fullWidthRegExp.test(pathname)}
pathname={pathname}
extras={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ export const getHeaderColors = (theme: Theme): HeaderColors => ({
'/project-developers': theme.palette.primary.main,
'/methodology-review-process': theme.palette.primary.main,
});

export const getBorderBottom = (pathname: string): boolean =>
['/project-pages', '/projects'].some(route => pathname.startsWith(route));
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getAllowedDenomQuery } from 'lib/queries/react-query/ecocredit/marketpl
import { getSellOrdersExtendedQuery } from 'lib/queries/react-query/ecocredit/marketplace/getSellOrdersExtendedQuery/getSellOrdersExtendedQuery';
import { getProjectByHandleQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectByHandleQuery/getProjectByHandleQuery';
import { getProjectByOnChainIdQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectByOnChainIdQuery/getProjectByOnChainIdQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllProjectPageQuery } from 'lib/queries/react-query/sanity/getAllProjectPageQuery/getAllProjectPageQuery';
import { getFromCacheOrFetch } from 'lib/queries/react-query/utils/getFromCacheOrFetch';

Expand All @@ -32,7 +32,9 @@ export const projectDetailsLoader =

// Queries
const allProjectPageQuery = getAllProjectPageQuery({ sanityClient });
const allCreditClassesQuery = getAllCreditClassesQuery({ sanityClient });
const allCreditClassesQuery = getAllSanityCreditClassesQuery({
sanityClient,
});
const projectQuery = getProjectQuery({
request: { projectId },
client: ecocreditClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { getGeocodingQuery } from 'lib/queries/react-query/mapbox/getGeocodingQu
import { getMetadataQuery } from 'lib/queries/react-query/registry-server/getMetadataQuery/getMetadataQuery';
import { getProjectByHandleQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectByHandleQuery/getProjectByHandleQuery';
import { getProjectByOnChainIdQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectByOnChainIdQuery/getProjectByOnChainIdQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllProjectPageQuery } from 'lib/queries/react-query/sanity/getAllProjectPageQuery/getAllProjectPageQuery';
import { getProjectByIdQuery } from 'lib/queries/react-query/sanity/getProjectByIdQuery/getProjectByIdQuery';
import { getSoldOutProjectsQuery } from 'lib/queries/react-query/sanity/getSoldOutProjectsQuery/getSoldOutProjectsQuery';
Expand Down Expand Up @@ -95,7 +95,7 @@ function ProjectDetails(): JSX.Element {
});

const { data: sanityCreditClassData } = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

const [isBuyFlowStarted, setIsBuyFlowStarted] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CREATE_PROJECT_URL_REGEX = /\/project-pages\/([a-z0-9-]+)\/(.*)/g;
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';

import { OffChainProject } from 'hooks/projects/useProjectWithMetadata';

import { EditFormTemplate } from './EditFormTemplate';
import { OnboardingFormTemplate } from './OnboardingFormTemplate';
import { ProjectFormAccessTemplate } from './ProjectFormAccessTemplate';
import { CREATE_PROJECT_URL_REGEX } from './ProjectFormTemplate.constants';

type Props = {
isEdit?: boolean;
Expand All @@ -23,6 +25,22 @@ const ProjectFormTemplate: React.FC<React.PropsWithChildren<Props>> = ({
children,
}) => {
const adminAddr = project?.walletByAdminWalletId?.addr;
const location = useLocation();
const { pathname } = location;
const navigate = useNavigate();
const { onChainId } = project ?? {};

useEffect(() => {
if (pathname.match(CREATE_PROJECT_URL_REGEX) && !!onChainId) {
const newUrl = pathname.replace(
CREATE_PROJECT_URL_REGEX,
`/project-pages/${onChainId}/edit/$2`,
);

navigate(newUrl);
}
}, [project, pathname, onChainId, navigate]);

return (
<ProjectFormAccessTemplate
loading={loading}
Expand Down
4 changes: 2 additions & 2 deletions web-marketplace/src/hooks/batches/usePaginatedBatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { UseStateSetter } from 'types/react/use-state';
import { useLedger } from 'ledger';
import { getAddDataToBatchesQuery } from 'lib/queries/react-query/ecocredit/getAddDataToBatchesQuery/getAddDataToBatchesQuery';
import { getBatchesQuery } from 'lib/queries/react-query/ecocredit/getBatchesQuery/getBatchesQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';

import { client as sanityClient } from '../../lib/clients/sanity';

Expand All @@ -35,7 +35,7 @@ export const usePaginatedBatches = (): {
const { rowsPerPage } = paginationParams;

const sanityCreditClassDataResult = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

/* Fetch current page batches */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UseStateSetter } from 'types/react/use-state';
import { useLedger } from 'ledger';
import { getAddDataToBatchesQuery } from 'lib/queries/react-query/ecocredit/getAddDataToBatchesQuery/getAddDataToBatchesQuery';
import { getBatchesByProjectQuery } from 'lib/queries/react-query/ecocredit/getBatchesByProjectQuery/getBatchesByProjectQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';

import { client as sanityClient } from '../../lib/clients/sanity';

Expand All @@ -34,7 +34,7 @@ export const usePaginatedBatchesByProject = ({
const { rowsPerPage, page } = paginationParams;

const sanityCreditClassDataResult = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

/* Fetch current page batches */
Expand Down
4 changes: 2 additions & 2 deletions web-marketplace/src/hooks/projects/useProjectsWithOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getProjectsQuery } from 'lib/queries/react-query/ecocredit/getProjectsQ
import { getSellOrdersExtendedQuery } from 'lib/queries/react-query/ecocredit/marketplace/getSellOrdersExtendedQuery/getSellOrdersExtendedQuery';
import { getMetadataQuery } from 'lib/queries/react-query/registry-server/getMetadataQuery/getMetadataQuery';
import { getProjectByOnChainIdQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectByOnChainIdQuery/getProjectByOnChainIdQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { useWallet } from 'lib/wallet/wallet';

import { ProjectsSellOrders } from 'pages/Projects/hooks/useProjectsSellOrders.types';
Expand Down Expand Up @@ -99,7 +99,7 @@ export function useProjectsWithOrders({

// AllCreditClasses
const { data: creditClassData } = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

/* Normalization/Filtering/Sorting */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { getClassImageWithGreenDefault } from 'utils/image/classImage';

import { AllCreditClassesQuery } from 'generated/graphql';
import { IndexerClassesByIssuerQuery, Maybe } from 'generated/indexer-graphql';
import { AllCreditClassQuery } from 'generated/sanity-graphql';
import { CreditClassMetadataLD } from 'lib/db/types/json-ld';

import { CreditClassItem } from './normalizeCreditClassItems.types';

type Params = {
classesByIssuer?: Maybe<IndexerClassesByIssuerQuery>;
classesMetadata?: (CreditClassMetadataLD | undefined)[];
sanityCreditClasses?: AllCreditClassQuery;
offChainCreditClasses?: AllCreditClassesQuery;
};

export const normalizeCreditClassItems = ({
classesByIssuer,
classesMetadata,
sanityCreditClasses,
offChainCreditClasses,
}: Params): CreditClassItem[] => {
return (
classesByIssuer?.allClassIssuers?.nodes.map((creditClass, index) => {
const metadata = classesMetadata?.[index];
const creditClassOnChainId = creditClass?.classId;
const sanityCreditClass = sanityCreditClasses?.allCreditClass.find(
sanityCreditClass => sanityCreditClass.path === sanityCreditClass,
);
const offChainCreditClass =
offChainCreditClasses?.allCreditClasses?.nodes.find(
creditClass => creditClass?.onChainId === creditClassOnChainId,
);

const name = metadata?.['schema:name'];
const title = name
? `${name} (${creditClassOnChainId})`
: creditClassOnChainId;

return {
id: offChainCreditClass?.id ?? '',
imageSrc: getClassImageWithGreenDefault({
metadata,
sanityClass: sanityCreditClass,
}),
onChainId: creditClassOnChainId ?? '',
title: title ?? '',
description: metadata?.['schema:description'],
};
}) ?? []
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface CreditClassItem {
id: string;
onChainId: string;
imageSrc: string;
title: string;
description?: string;
disabled?: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ALL_CREDIT_CLASSES_KEY = 'AllCreditClassesQuery';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
AllCreditClassesDocument,
AllCreditClassesQuery,
} from 'generated/graphql';

import { ALL_CREDIT_CLASSES_KEY } from './getAllCreditClassesQuery.constants';
import {
ReactQueryGetAllCreditClassesParams,
ReactQueryGetAllCreditClassesResponse,
} from './getAllCreditClassesQuery.types';

export const getAllCreditClassesQuery = ({
client,
...params
}: ReactQueryGetAllCreditClassesParams): ReactQueryGetAllCreditClassesResponse => ({
queryKey: [ALL_CREDIT_CLASSES_KEY],
queryFn: async () => {
const { data } = await client.query<AllCreditClassesQuery>({
query: AllCreditClassesDocument,
});

return data;
},
...params,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApolloClient, NormalizedCacheObject } from '@apollo/client';
import { QueryObserverOptions } from '@tanstack/react-query';

import { AllCreditClassesQuery } from 'generated/graphql';

import { ReactQueryBuilderResponse } from '../../../types/react-query.types';

export type ReactQueryGetAllCreditClassesResponse =
QueryObserverOptions<AllCreditClassesQuery>;

export type ReactQueryGetAllCreditClassesParams = {
client: ApolloClient<NormalizedCacheObject>;
} & ReactQueryBuilderResponse<ReactQueryGetAllCreditClassesResponse>;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ReactQueryGetAllCreditClassesResponse,
} from './getAllCreditClassesQuery.types';

export const getAllCreditClassesQuery = ({
export const getAllSanityCreditClassesQuery = ({
sanityClient,
...params
}: ReactQueryGetAllCreditClassesParams): ReactQueryGetAllCreditClassesResponse => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UseStateSetter } from 'types/react/use-state';
import { useLedger } from 'ledger';
import { client as sanityClient } from 'lib/clients/sanity';
import { getBasketBalancesQuery } from 'lib/queries/react-query/ecocredit/basket/getBasketBalances/getBasketBalancesQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';

import { useBatchesWithMetadata } from 'hooks/batches/useBatchesWithMetadata';

Expand Down Expand Up @@ -80,7 +80,7 @@ export const useFetchBasketEcocredits = ({

// AllCreditClasses
const { data: creditClassData } = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

// Normalization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ProjectCardProps } from 'web-components/lib/components/cards/ProjectCar
import { client as sanityClient } from 'lib/clients/sanity';
import { normalizeProjectsWithCreditClass } from 'lib/normalizers/projects/normalizeProjectsWithCreditClass';
import { getProjectByOnChainIdQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectByOnChainIdQuery/getProjectByOnChainIdQuery';
import { getAllCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';

import { useProjectsWithMetadata } from 'hooks/projects/useProjectsWithMetadata';

Expand All @@ -24,7 +24,7 @@ export const useFetchProjectsByIds = ({ projectIds }: Props): Response => {
const graphqlClient = useApolloClient();

const { data: creditClassData } = useQuery(
getAllCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
getAllSanityCreditClassesQuery({ sanityClient, enabled: !!sanityClient }),
);

const { projects, isProjectsLoading, projectsMetadata, classesMetadata } =
Expand Down
Loading

0 comments on commit 10b663a

Please sign in to comment.