Skip to content
Open
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
6 changes: 3 additions & 3 deletions apps/scan/src/app/(app)/_hooks/send/use-evm-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { usdc } from '@/lib/tokens/usdc';

import { useEvmTokenBalance } from '../balance/token/use-evm-token-balance';

import { ethereumAddressSchema } from '@/lib/schemas';
import { evmAddressSchema } from '@/lib/schemas';

import { useWalletChain } from '@/app/(app)/_contexts/wallet-chain/hook';
import { useEvmX402Fetch } from '../x402/evm';
Expand Down Expand Up @@ -100,7 +100,7 @@ export const useEvmSend = (props?: Props) => {
toast.error('Amount is required');
return;
}
const parseResult = ethereumAddressSchema.safeParse(toAddress);
const parseResult = evmAddressSchema.safeParse(toAddress);
if (!parseResult.success) {
toast.error('Invalid address');
return;
Expand Down Expand Up @@ -133,7 +133,7 @@ export const useEvmSend = (props?: Props) => {
balance < amount ||
isBalanceLoading ||
isSent ||
!ethereumAddressSchema.safeParse(toAddress).success,
!evmAddressSchema.safeParse(toAddress).success,
isPending: isSending,
statusText,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { api } from '@/trpc/client';

import { useWalletChain } from '@/app/(app)/_contexts/wallet-chain/hook';

import { ethereumAddressSchema, solanaAddressSchema } from '@/lib/schemas';
import { evmAddressSchema, solanaAddressSchema } from '@/lib/schemas';
import { usdc } from '@/lib/tokens/usdc';
import { formatAddress } from '@/lib/utils';

Expand Down Expand Up @@ -59,7 +59,7 @@ export const Send: React.FC = () => {
} = api.user.serverWallet.sendUsdc.useMutation();

const schema =
chain === ChainType.SOLANA ? solanaAddressSchema : ethereumAddressSchema;
chain === ChainType.SOLANA ? solanaAddressSchema : evmAddressSchema;

const handleSubmit = useCallback(() => {
const parseResult = schema.safeParse(address);
Expand Down
4 changes: 2 additions & 2 deletions apps/scan/src/app/mcp/deposit/[address]/[method]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { notFound } from 'next/navigation';
import { METHODS } from './_components/methods';
import { Body } from '@/app/_components/layout/page-utils';

import { ethereumAddressSchema } from '@/lib/schemas';
import { evmAddressSchema } from '@/lib/schemas';

import { OnrampMethods, OnrampProviders } from '@/services/onramp/types';

const paramsSchema = z.object({
address: ethereumAddressSchema,
address: evmAddressSchema,
method: z.union([z.literal(OnrampMethods.WALLET), z.enum(OnrampProviders)]),
});

Expand Down
4 changes: 2 additions & 2 deletions apps/scan/src/app/mcp/deposit/[address]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ethereumAddressSchema } from '@/lib/schemas';
import { evmAddressSchema } from '@/lib/schemas';

export default async function DepositLayout({
children,
params,
}: LayoutProps<'/mcp/deposit/[address]'>) {
const { address } = await params;

const parsedAddress = ethereumAddressSchema.safeParse(address);
const parsedAddress = evmAddressSchema.safeParse(address);

if (!parsedAddress.success) {
throw new Error('Invalid address');
Expand Down
15 changes: 5 additions & 10 deletions apps/scan/src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import z from 'zod';

import { Chain, SUPPORTED_CHAINS } from '@/types/chain';

import { getAddress, isAddress, type Address } from 'viem';
import { getAddress, isAddress } from 'viem';
import type { MixedAddress, SolanaAddress } from '@/types/address';

export const ethereumAddressSchema = z
export const evmAddressSchema = z
.string()
.regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address')
.transform(address => address.toLowerCase() as Address);
.refine(isAddress, 'Invalid EVM address')
.transform(a => getAddress(a));

export const sortingSchema = (sortIds: string[] | readonly string[]) =>
z.object({
Expand All @@ -23,7 +23,7 @@ export const solanaAddressSchema = z

// Create a mixed address schema
export const mixedAddressSchema = z
.union([ethereumAddressSchema, solanaAddressSchema])
.union([evmAddressSchema, solanaAddressSchema])
.transform(address => address as MixedAddress);

export const chainSchema = z.enum(Chain);
Expand All @@ -46,8 +46,3 @@ export const sendUsdcQueryParamsSchema = z.object({
address: mixedAddressSchema,
chain: supportedChainSchema,
});

export const evmAddressSchema = z
.string()
.refine(isAddress, 'Invalid EVM address')
.transform(a => getAddress(a));
4 changes: 2 additions & 2 deletions apps/scan/src/services/cdp/onramp/create-onramp-session.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';

import { cdpFetch } from '../lib/fetch';
import { ethereumAddressSchema, solanaAddressSchema } from '@/lib/schemas';
import { evmAddressSchema, solanaAddressSchema } from '@/lib/schemas';
import { Chain, SUPPORTED_CHAINS } from '@/types/chain';

export const createOnrampUrlParamsSchema = z.object({
Expand Down Expand Up @@ -33,7 +33,7 @@ export const createOnrampUrl = async (
const address =
defaultNetwork === Chain.SOLANA
? solanaAddressSchema.parse(addressInput)
: ethereumAddressSchema.parse(addressInput);
: evmAddressSchema.parse(addressInput);

const { token } = await cdpFetch(
{
Expand Down
4 changes: 2 additions & 2 deletions apps/scan/src/trpc/routers/onramp/coinbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getOnrampTransactions,
} from '@/services/onramp/coinbase/onramp-session';

import { ethereumAddressSchema } from '@/lib/schemas';
import { evmAddressSchema } from '@/lib/schemas';

export const coinbaseOnrampRouter = createTRPCRouter({
session: {
Expand All @@ -21,7 +21,7 @@ export const coinbaseOnrampRouter = createTRPCRouter({
create: publicProcedure
.input(
createOnrampUrlParamsSchema.extend({
address: ethereumAddressSchema,
address: evmAddressSchema,
})
)
.mutation(async ({ input }) => {
Expand Down