Skip to content

Commit e97007c

Browse files
committed
Addressing api and validation comments
1 parent c0a5441 commit e97007c

File tree

4 files changed

+34
-44
lines changed

4 files changed

+34
-44
lines changed

apps/dashboard/src/@/api/universal-bridge/addRoute.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

apps/dashboard/src/@/api/universal-bridge/tokens.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use server";
22
import { DASHBOARD_THIRDWEB_SECRET_KEY } from "@/constants/server-envs";
3+
import { getAuthToken } from "app/(app)/api/lib/getAuthToken";
34
import { UB_BASE_URL } from "./constants";
45

56
export type TokenMetadata = {
@@ -37,3 +38,31 @@ export async function getUniversalBridgeTokens(props: {
3738
const json = await res.json();
3839
return json.data as Array<TokenMetadata>;
3940
}
41+
42+
export async function addUniversalBridgeTokenRoute(props: {
43+
chainId?: number;
44+
tokenAddress?: string;
45+
}) {
46+
const authToken = await getAuthToken();
47+
const url = new URL(`${UB_BASE_URL}/v1/tokens`);
48+
49+
const res = await fetch(url.toString(), {
50+
method: "POST",
51+
headers: {
52+
"Content-Type": "application/json",
53+
Authorization: `Bearer ${authToken}`,
54+
} as Record<string, string>,
55+
body: JSON.stringify({
56+
chainId: props.chainId,
57+
tokenAddress: props.tokenAddress,
58+
}),
59+
});
60+
61+
if (!res.ok) {
62+
const text = await res.text();
63+
throw new Error(text);
64+
}
65+
66+
const json = await res.json();
67+
return json.data as Array<TokenMetadata>;
68+
}

apps/dashboard/src/components/pay/RouteDiscovery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import { addUniversalBridgeTokenRoute } from "@/api/universal-bridge/addRoute"; // Adjust the import path
2+
import { addUniversalBridgeTokenRoute } from "@/api/universal-bridge/tokens"; // Adjust the import path
33
import { RouteDiscoveryCard } from "@/components/blocks/RouteDiscoveryCard";
44
import {
55
Form,

apps/dashboard/src/components/settings/ApiKeys/validations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isAddress } from "thirdweb";
12
import { RE_DOMAIN } from "utils/regex";
23
import { validStrList } from "utils/validations";
34
import { z } from "zod";
@@ -129,7 +130,9 @@ export const routeDiscoveryValidationSchema = z.object({
129130
.string({
130131
required_error: "Token address is required",
131132
})
132-
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid contract address format"),
133+
.refine((value) => isAddress(value), {
134+
message: "Invalid Ethereum address format",
135+
}),
133136
});
134137
export type RouteDiscoveryValidationSchema = z.infer<
135138
typeof routeDiscoveryValidationSchema

0 commit comments

Comments
 (0)