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

Refactor event types and allowance types #244

Merged
merged 6 commits into from
Nov 28, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ localazy.content.keys.json
cypress/videos
cypress/screenshots
cypress/downloads
cypress/temp

.vscode/settings.json
.vscode/launch.json
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Props {

export const dynamic = 'error';

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
15 changes: 11 additions & 4 deletions app/[locale]/address/[addressOrName]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AllowanceDashboard from 'components/allowances/dashboard/AllowanceDashboard';
import { isNullish } from 'lib/utils';
import { getChainName } from 'lib/utils/chains';
import { shortenAddress } from 'lib/utils/formatting';
import { getAddressAndDomainName } from 'lib/utils/whois';
Expand All @@ -10,19 +11,25 @@ interface Props {
locale: string;
addressOrName: string;
};
searchParams: {
chainId?: string;
};
}

export const generateMetadata = async ({ params: { locale, addressOrName }, searchParams }): Promise<Metadata> => {
export const generateMetadata = async ({
params: { locale, addressOrName },
searchParams,
}: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

const { address, domainName } = await getAddressAndDomainName(addressOrName);
const addressDisplay = domainName ?? shortenAddress(address);

const chainName = getChainName(Number(searchParams.chainId || 1));

const title = !!searchParams.chainId
? t('address.meta.title_chain', { addressDisplay, chainName })
: t('address.meta.title', { addressDisplay });
const title = isNullish(searchParams.chainId)
? t('address.meta.title', { addressDisplay })
: t('address.meta.title_chain', { addressDisplay, chainName });

return {
title,
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/blog/[...slug]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const BlogLayout = async ({ params, children }: Props) => {
unstable_setRequestLocale(params.locale);

const t = await getTranslations({ locale: params.locale });
const { meta } = readAndParseContentFile(params.slug, params.locale, 'blog');
const { meta } = readAndParseContentFile(params.slug, params.locale, 'blog')!;
const posts = await getSidebar(params.locale, 'blog');
const translationUrl = await getTranslationUrl(params.slug, params.locale, 'blog');

Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/blog/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const generateStaticParams = () => {
};

export const generateMetadata = async ({ params: { locale, slug } }: Props): Promise<Metadata> => {
const { meta } = readAndParseContentFile(slug, locale, 'blog');
const { meta } = readAndParseContentFile(slug, locale, 'blog')!;

return {
title: meta.title,
Expand All @@ -34,7 +34,7 @@ export const generateMetadata = async ({ params: { locale, slug } }: Props): Pro
const BlogPostPage: NextPage<Props> = ({ params }) => {
unstable_setRequestLocale(params.locale);

const { content } = readAndParseContentFile(params.slug, params.locale, 'blog');
const { content } = readAndParseContentFile(params.slug, params.locale, 'blog')!;

return <MarkdownProse content={content} />;
};
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props {

export const dynamic = 'error';

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/disclaimer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const metadata = {

const DisclaimerPage: NextPage<Props> = ({ params }) => {
unstable_setRequestLocale(params.locale);
const { content } = readAndParseContentFile('disclaimer', params.locale, 'docs');
const { content } = readAndParseContentFile('disclaimer', params.locale, 'docs')!;

return (
<ContentPageLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/exploits/[slug]/ExploitChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ExploitCheckerWrapper = ({ exploit }: Props) => {

return (
<Suspense>
<AddressPageContextProvider address={address} initialChainId={chainIds[0]}>
<AddressPageContextProvider address={address!} initialChainId={chainIds[0]}>
<AddressForm onSubmit={setAddress} chainIds={chainIds} />
<ExploitChecker exploit={exploit} />
</AddressPageContextProvider>
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/exploits/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const generateStaticParams = async () => {
return locales.flatMap((locale) => exploits.map((exploit) => ({ locale, slug: exploit.slug })));
};

export const generateMetadata = async ({ params: { locale, slug } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale, slug } }: Props): Promise<Metadata> => {
const { exploit } = await getStaticProps({ locale, slug });
const t = await getTranslations();

Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/exploits/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {

export const dynamic = 'error';

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });
const exploits = await getAllExploits();
const { totalAmount, earliestYear } = getGlobalExploitStats(exploits);
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/extension/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {

export const dynamic = 'error';

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const generateStaticParams = () => {
return locales.map((locale) => ({ locale }));
};

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
6 changes: 3 additions & 3 deletions app/[locale]/learn/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const generateStaticParams = () => {
return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug })));
};

export const generateMetadata = async ({ params: { locale, slug } }): Promise<Metadata> => {
const { meta } = readAndParseContentFile(slug, locale, 'learn');
export const generateMetadata = async ({ params: { locale, slug } }: Props): Promise<Metadata> => {
const { meta } = readAndParseContentFile(slug, locale, 'learn')!;

return {
title: meta.title,
Expand All @@ -35,7 +35,7 @@ export const generateMetadata = async ({ params: { locale, slug } }): Promise<Me
const LearnDocumentPage: NextPage<Props> = async ({ params }) => {
unstable_setRequestLocale(params.locale);

const { content, meta } = readAndParseContentFile(params.slug, params.locale, 'learn');
const { content, meta } = readAndParseContentFile(params.slug, params.locale, 'learn')!;
const sidebar = await getSidebar(params.locale, 'learn');
const translationUrl = await getTranslationUrl(params.slug, params.locale, 'learn');

Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/learn/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const generateStaticParams = () => {
return locales.flatMap((locale) => categorySlugs.map((category) => ({ locale, category })));
};

export const generateMetadata = async ({ params: { locale, category } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale, category } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/learn/faq/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {

export const dynamic = 'error';

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand All @@ -28,7 +28,7 @@ export const generateMetadata = async ({ params: { locale } }): Promise<Metadata
};
};

const FaqPage: NextPage = async ({ params }: Props) => {
const FaqPage: NextPage<Props> = async ({ params }: Props) => {
unstable_setRequestLocale(params.locale);

const sidebar = await getSidebar(params.locale, 'learn');
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/learn/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Props {

export const dynamic = 'error';

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {

// This is a wrapper around ChainSelectHref because we cannot pass the getUrl function as a prop from a server component
const AddNetworkChainSelect = ({ chainId }: Props) => {
const getUrl = useCallback((chainId) => `/learn/wallets/add-network/${getChainSlug(chainId)}`, []);
const getUrl = useCallback((chainId: number) => `/learn/wallets/add-network/${getChainSlug(chainId)}`, []);
return <ChainSelectHref instanceId="add-network-chain-select" selected={chainId} getUrl={getUrl} showNames />;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const AddNetworkForm = ({ chainId }: Props) => {
<FormElement label="Network name" content={chainName} />
<FormElement label="New RPC URL" content={getChainFreeRpcUrl(chainId)} />
<FormElement label="Chain ID" content={String(chainId)} />
<FormElement label="Currency symbol" content={getChainNativeToken(chainId)} />
<FormElement label="Currency symbol" content={getChainNativeToken(chainId)!} />
<FormElement label="Block explorer URL (Optional)" content={getChainExplorerUrl(chainId)} />
</div>
<p>{t('learn.add_network.step_2.paragraph_2')}</p>
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/learn/wallets/add-network/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const generateStaticParams = () => {
return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug })));
};

export const generateMetadata = async ({ params: { locale, slug } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale, slug } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });
const chainId = getChainIdFromSlug(slug);
const chainName = getChainName(chainId);
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/merchandise/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {

export const dynamic = 'error';

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/og.jpg/blog/[...slug]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const generateStaticParams = () => {
};

export async function GET(req: Request, { params }: Props) {
const { meta } = readAndParseContentFile(params.slug, params.locale, 'blog');
const { meta } = readAndParseContentFile(params.slug, params.locale, 'blog')!;

const title = meta.overlay ? meta.sidebarTitle : undefined;
const background = loadDataUrl(`public/assets/images/blog/${params.slug.join('/')}/cover.jpg`, 'image/jpeg');
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/og.jpg/learn/[...slug]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const generateStaticParams = () => {
};

export async function GET(req: Request, { params }: Props) {
const { meta } = readAndParseContentFile(params.slug, params.locale, 'learn');
const { meta } = readAndParseContentFile(params.slug, params.locale, 'learn')!;

const title = meta.overlay ? meta.sidebarTitle : undefined;
const background = loadDataUrl(`public/assets/images/learn/${params.slug.join('/')}/cover.jpg`, 'image/jpeg');
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const jsonLd = {
url: 'https://revoke.cash',
};

export const generateMetadata = async ({ params: { locale } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });

return {
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/privacy-policy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const metadata = {

const PrivacyPolicyPage: NextPage<Props> = ({ params }) => {
unstable_setRequestLocale(params.locale);
const { content } = readAndParseContentFile('privacy-policy', params.locale, 'docs');
const { content } = readAndParseContentFile('privacy-policy', params.locale, 'docs')!;

return (
<ContentPageLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/terms/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const metadata = {

const TermsAndConditionsPage: NextPage<Props> = ({ params }) => {
unstable_setRequestLocale(params.locale);
const { content } = readAndParseContentFile('terms', params.locale, 'docs');
const { content } = readAndParseContentFile('terms', params.locale, 'docs')!;

return (
<ContentPageLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {

// This is a wrapper around ChainSelectHref because we cannot pass the getUrl function as a prop from a server component
const TokenApprovalCheckerChainSelect = ({ chainId }: Props) => {
const getUrl = useCallback((chainId) => `/token-approval-checker/${getChainSlug(chainId)}`, []);
const getUrl = useCallback((chainId: number) => `/token-approval-checker/${getChainSlug(chainId)}`, []);
return <ChainSelectHref instanceId="tac-chain-select" selected={chainId} getUrl={getUrl} showNames />;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useState } from 'react';

interface Props {
chainId: number;
placeholder?: string;
placeholder: string;
}

const TokenApprovalCheckerSearchBox: NextPage<Props> = ({ chainId, placeholder }) => {
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/token-approval-checker/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const generateStaticParams = () => {
return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug })));
};

export const generateMetadata = async ({ params: { locale, slug } }): Promise<Metadata> => {
export const generateMetadata = async ({ params: { locale, slug } }: Props): Promise<Metadata> => {
const t = await getTranslations({ locale });
const chainId = getChainIdFromSlug(slug);
const chainName = getChainName(chainId);
Expand Down
2 changes: 1 addition & 1 deletion app/api/[chainId]/merchandise/generate-code/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ export async function POST(req: NextRequest, { params }: Props) {

// generate a random 9 digit code xxx-xxx-xxx
const generateRandomMerchCode = () => {
return Math.random().toString().replace('.', '').slice(6, 15).match(/.{3}/g).join('-');
return Math.random().toString().replace('.', '').slice(6, 15).match(/.{3}/g)!.join('-');
};
6 changes: 5 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Metadata } from 'next';
import { getTranslations } from 'next-intl/server';

interface Props {
children: React.ReactNode;
}

export const generateMetadata = async (): Promise<Metadata> => {
const t = await getTranslations({ locale: 'en' });

Expand All @@ -16,7 +20,7 @@ export const generateMetadata = async (): Promise<Metadata> => {
};
};

const RootLayout = ({ children }) => {
const RootLayout = ({ children }: Props) => {
return <>{children}</>;
};

Expand Down
9 changes: 5 additions & 4 deletions components/address/AddressHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useQuery } from '@tanstack/react-query';
import ChainSelect from 'components/common/select/ChainSelect';
import { useAddressPageContext } from 'lib/hooks/page-context/AddressPageContext';
import { getNativeTokenPrice } from 'lib/price/utils';
import { isNullish } from 'lib/utils';
import { usePublicClient } from 'wagmi';
import AddressDisplay from './AddressDisplay';
import AddressSocialShareButtons from './AddressSocialShareButtons';
Expand All @@ -13,18 +14,18 @@ import AddressNavigation from './navigation/AddressNavigation';

const AddressHeader = () => {
const { address, domainName, selectedChainId, selectChain } = useAddressPageContext();
const publicClient = usePublicClient({ chainId: selectedChainId });
const publicClient = usePublicClient({ chainId: selectedChainId })!;

const { data: balance, isLoading: balanceIsLoading } = useQuery({
queryKey: ['balance', address, publicClient.chain?.id],
queryFn: () => publicClient.getBalance({ address }),
enabled: !!address && !!publicClient.chain,
queryFn: () => publicClient.getBalance({ address: address! }),
enabled: !isNullish(address) && !isNullish(publicClient.chain),
});

const { data: nativeAssetPrice, isLoading: nativeAssetPriceIsLoading } = useQuery({
queryKey: ['nativeAssetPrice', publicClient.chain.id],
queryFn: () => getNativeTokenPrice(publicClient.chain.id, publicClient),
enabled: !!publicClient,
enabled: !isNullish(publicClient),
});

return (
Expand Down
7 changes: 4 additions & 3 deletions components/address/BalanceDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Loader from 'components/common/Loader';
import { useAddressPageContext } from 'lib/hooks/page-context/AddressPageContext';
import { Nullable } from 'lib/interfaces';
import { isNullish } from 'lib/utils';
import { getChainNativeToken } from 'lib/utils/chains';
import { formatFiatBalance, formatFixedPointBigInt } from 'lib/utils/formatting';
import { twMerge } from 'tailwind-merge';

interface Props {
isLoading: boolean;
balance: bigint;
price?: number;
balance?: bigint;
price?: Nullable<number>;
className?: string;
}

Expand All @@ -25,7 +26,7 @@ const BalanceDisplay = ({ isLoading, balance, price, className }: Props) => {
return (
<Loader isLoading={isLoading || isNullish(balance)} loadingChildren={placeholder} className="rounded-md">
<div className={classes}>
<span>{formatFixedPointBigInt(balance, 18)}</span>
<span>{balance ? formatFixedPointBigInt(balance, 18) : null}</span>
<span className="font-bold">{nativeToken}</span>
{fiatBalanceText ? <span>({fiatBalanceText})</span> : null}
</div>
Expand Down
Loading