Skip to content

Commit a4e12c5

Browse files
authored
Fix: Auth method for checkout page api requests to ub service (#6996)
1 parent 2297915 commit a4e12c5

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ type Webhook = {
1414
version?: number; // TODO (UB) make this mandatory after migration
1515
};
1616

17-
export async function getWebhooks(props: {
18-
clientId: string;
19-
}) {
17+
export async function getWebhooks() {
2018
const authToken = await getAuthToken();
2119
const res = await fetch(`${UB_BASE_URL}/v1/developer/webhooks`, {
2220
method: "GET",
2321
headers: {
2422
"Content-Type": "application/json",
25-
"x-client-id-override": props.clientId,
2623
Authorization: `Bearer ${authToken}`,
2724
},
2825
});
@@ -54,7 +51,6 @@ export async function createWebhook(props: {
5451
}),
5552
headers: {
5653
"Content-Type": "application/json",
57-
"x-client-id-override": props.clientId,
5854
Authorization: `Bearer ${authToken}`,
5955
},
6056
});
@@ -109,7 +105,6 @@ export async function getFees(props: {
109105
headers: {
110106
"Content-Type": "application/json",
111107
"x-team-id": props.teamId,
112-
"x-client-id-override": props.clientId,
113108
Authorization: `Bearer ${authToken}`,
114109
},
115110
});
@@ -134,7 +129,6 @@ export async function updateFee(props: {
134129
method: "PUT",
135130
headers: {
136131
"Content-Type": "application/json",
137-
"x-client-id-override": props.clientId,
138132
"x-team-id": props.teamId,
139133
Authorization: `Bearer ${authToken}`,
140134
},

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use server";
2-
import { getAuthToken } from "app/(app)/api/lib/getAuthToken";
2+
import { DASHBOARD_THIRDWEB_SECRET_KEY } from "@/constants/server-envs";
33
import { UB_BASE_URL } from "./constants";
44

55
export type TokenMetadata = {
@@ -12,10 +12,8 @@ export type TokenMetadata = {
1212
};
1313

1414
export async function getUniversalBridgeTokens(props: {
15-
clientId?: string;
1615
chainId?: number;
1716
}) {
18-
const authToken = await getAuthToken();
1917
const url = new URL(`${UB_BASE_URL}/v1/tokens`);
2018

2119
if (props.chainId) {
@@ -27,8 +25,7 @@ export async function getUniversalBridgeTokens(props: {
2725
method: "GET",
2826
headers: {
2927
"Content-Type": "application/json",
30-
"x-client-id-override": props.clientId,
31-
Authorization: `Bearer ${authToken}`,
28+
"x-secret-key": DASHBOARD_THIRDWEB_SECRET_KEY,
3229
} as Record<string, string>,
3330
});
3431

apps/dashboard/src/@/components/blocks/TokenSelector.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export function TokenSelector(props: {
2626
enabled?: boolean;
2727
}) {
2828
const { tokens, isFetching } = useTokensData({
29-
clientId: props.client.clientId,
3029
chainId: props.chainId,
3130
enabled: props.enabled,
3231
});

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/connect/universal-bridge/webhooks/components/webhooks.client.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ export function PayWebhooksPage(props: PayWebhooksPageProps) {
6464
const webhooksQuery = useQuery({
6565
queryKey: ["webhooks", props.clientId],
6666
queryFn: async () => {
67-
return await getWebhooks({
68-
clientId: props.clientId,
69-
});
67+
return await getWebhooks();
7068
},
7169
});
7270

apps/dashboard/src/app/checkout/components/client/CheckoutLinkForm.client.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function CheckoutLinkForm() {
189189
<CreditCardIcon className="size-5 sm:size-6" />
190190
</div>
191191
<CardTitle className="text-center sm:text-left">
192-
Create a Checkout Link
192+
Create a Payment Link
193193
</CardTitle>
194194
</div>
195195
</CardHeader>
@@ -300,6 +300,7 @@ export function CheckoutLinkForm() {
300300
value={image || imageUri}
301301
className="!rounded-md aspect-square h-24 w-full"
302302
isDisabled={uploadingImage}
303+
isDisabledText="Uploading..."
303304
selectOrUpload="Upload"
304305
helperText="image"
305306
fileUrl={imageUri}

apps/dashboard/src/app/checkout/page.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getAuthToken } from "app/(app)/api/lib/getAuthToken";
2+
import { loginRedirect } from "app/(app)/login/loginRedirect";
13
import type { Metadata } from "next";
24
import { createThirdwebClient, defineChain, getContract } from "thirdweb";
35
import { getCurrencyMetadata } from "thirdweb/extensions/erc20";
@@ -26,11 +28,18 @@ export default async function RoutesPage({
2628

2729
// If no query parameters are provided, show the form
2830
if (
29-
!params.chainId ||
30-
!params.recipientAddress ||
31-
!params.tokenAddress ||
31+
!params.chainId &&
32+
!params.recipientAddress &&
33+
!params.tokenAddress &&
3234
!params.amount
3335
) {
36+
const authToken = await getAuthToken();
37+
38+
if (!authToken) {
39+
const searchParams = new URLSearchParams(params);
40+
return loginRedirect(`/checkout?${searchParams.toString()}`);
41+
}
42+
3443
return <CheckoutLinkForm />;
3544
}
3645

apps/dashboard/src/hooks/tokens/tokens.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ const tokensStore = /* @__PURE__ */ createStore<TokenMetadata[]>([]);
8282
const structuredTokensStore = /* @__PURE__ */ createStructuredTokensStore();
8383

8484
export function useTokensData({
85-
clientId,
8685
chainId,
8786
enabled,
88-
}: { clientId: string; chainId?: number; enabled?: boolean }) {
87+
}: { chainId?: number; enabled?: boolean }) {
8988
const tokensQuery = useQuery({
9089
queryKey: ["universal-bridge-tokens", chainId],
91-
queryFn: () => getUniversalBridgeTokens({ clientId, chainId }),
90+
queryFn: () => getUniversalBridgeTokens({ chainId }),
9291
enabled,
9392
});
9493

0 commit comments

Comments
 (0)