Skip to content

Commit 7318c7c

Browse files
committed
Addressing comments.
1 parent cc5c06e commit 7318c7c

File tree

3 files changed

+68
-129
lines changed

3 files changed

+68
-129
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function RouteDiscoveryCard(
7575
>
7676
{props.saveButton.isPending && <Spinner className="size-3" />}
7777
{props.saveButton.label ||
78-
(props.saveButton.isPending ? "Submitting" : "Submit Token")}
78+
(props.saveButton.isPending ? "Submit" : "Submit Token")}
7979
</Button>
8080
)}
8181
</div>

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

Lines changed: 67 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,12 @@ import {
1717
routeDiscoveryValidationSchema,
1818
} from "components/settings/ApiKeys/validations";
1919
import { useTrack } from "hooks/analytics/useTrack";
20-
import { useState } from "react";
2120
import { useForm } from "react-hook-form";
2221
import { toast } from "sonner";
23-
import { useActiveWalletChain } from "thirdweb/react";
2422

2523
const TRACKING_CATEGORY = "token_discovery";
2624

2725
export const RouteDiscovery: React.FC = () => {
28-
const [isSubmitSuccess, setIsSubmitSuccess] = useState(false);
29-
const [isSubmitFail, setIsSubmitFailed] = useState(false);
30-
const walletChain = useActiveWalletChain();
31-
32-
// State to track the selected chain ID directly from the NetworkSelectorButton
33-
const [selectedChainId, setSelectedChainId] = useState<number | undefined>(
34-
walletChain?.id,
35-
);
36-
3726
const form = useForm<RouteDiscoveryValidationSchema>({
3827
resolver: zodResolver(routeDiscoveryValidationSchema),
3928
defaultValues: {
@@ -43,44 +32,43 @@ export const RouteDiscovery: React.FC = () => {
4332
});
4433

4534
const resetForm = () => {
46-
setIsSubmitSuccess(false);
47-
setIsSubmitFailed(false);
4835
form.reset();
4936
};
5037

5138
const trackEvent = useTrack();
5239

5340
const submitDiscoveryMutation = useMutation({
5441
mutationFn: async (values: {
42+
chainId: number;
5543
tokenAddress: string;
5644
}) => {
57-
try {
58-
// Call the API to add the route
59-
const result = await addUniversalBridgeTokenRoute({
60-
chainId: selectedChainId,
61-
tokenAddress: values.tokenAddress,
62-
});
45+
// Call the API to add the route
46+
const result = await addUniversalBridgeTokenRoute({
47+
chainId: values.chainId,
48+
tokenAddress: values.tokenAddress,
49+
});
6350

64-
return result;
65-
} catch (error) {
66-
console.error("Error adding route:", error);
67-
throw error; // Re-throw to trigger onError handler
68-
}
51+
return result;
6952
},
7053
});
7154

7255
const handleSubmit = form.handleSubmit(
73-
({ tokenAddress }) => {
74-
console.log("selectedChainId", selectedChainId);
56+
({ chainId, tokenAddress }) => {
7557
submitDiscoveryMutation.mutate(
7658
{
59+
chainId,
7760
tokenAddress,
7861
},
7962
{
8063
onSuccess: (data) => {
81-
setIsSubmitSuccess(true);
82-
toast.success("Token submitted for discovery");
83-
console.log("Token route added successfully:", data);
64+
toast.success("Token submitted successfully!", {
65+
description:
66+
"Thank you for your submission. Contact support if your token doesn't appear after some time.",
67+
action: {
68+
label: "Submit Another token",
69+
onClick: () => resetForm(),
70+
},
71+
});
8472
trackEvent({
8573
category: TRACKING_CATEGORY,
8674
action: "token-discovery-submit",
@@ -91,15 +79,18 @@ export const RouteDiscovery: React.FC = () => {
9179
},
9280
});
9381
},
94-
onError: (err) => {
95-
setIsSubmitFailed(true);
96-
toast.error("Token Submission Failed");
82+
onError: () => {
83+
toast.error("Token submission failed!", {
84+
description:
85+
"Please double check the network and token address. If issues persist, please reach out to our support team.",
86+
action: {
87+
label: "Try Again",
88+
onClick: () => resetForm(),
89+
},
90+
});
9791

9892
// Get appropriate error message
99-
let errorMessage = "An unknown error occurred";
100-
if (err) {
101-
errorMessage = err.message;
102-
}
93+
const errorMessage = "An unknown error occurred";
10394

10495
trackEvent({
10596
category: TRACKING_CATEGORY,
@@ -111,52 +102,11 @@ export const RouteDiscovery: React.FC = () => {
111102
},
112103
);
113104
},
114-
(errors) => {
115-
console.log("Form validation errors:", errors);
105+
() => {
116106
toast.error("Please fix the form errors before submitting");
117107
},
118108
);
119109

120-
// Success component shown after successful submission
121-
const SuccessComponent = () => (
122-
<div className="mt-4 rounded-md border border-green-200 bg-green-50 p-4">
123-
<h4 className="font-medium text-green-600 text-lg">
124-
Token submitted successfully!
125-
</h4>
126-
<p className="mb-3 text-green-600">
127-
Thank you for your submission. If you still do not see your token listed
128-
after some time, please reach out to our team for support.
129-
</p>
130-
<button
131-
type="button"
132-
onClick={resetForm}
133-
className="rounded-md border border-green-500 bg-green-100 px-4 py-2 text-green-700 transition-colors hover:bg-green-200"
134-
>
135-
Submit Another Token
136-
</button>
137-
</div>
138-
);
139-
140-
// Failure component shown after submission fails
141-
const FailComponent = () => (
142-
<div className="mt-4 rounded-md border border-red-200 bg-red-50 p-4">
143-
<h4 className="font-medium text-lg text-red-600">
144-
Token submission failed!
145-
</h4>
146-
<p className="mb-2 text-red-600">
147-
Please double check the network and token address. If issues persist,
148-
please reach out to our support team.
149-
</p>
150-
<button
151-
type="button"
152-
onClick={resetForm}
153-
className="rounded-md border border-red-500 bg-red-100 px-4 py-2 text-red-700 transition-colors hover:bg-red-200"
154-
>
155-
Try Again
156-
</button>
157-
</div>
158-
);
159-
160110
return (
161111
<Form {...form}>
162112
<form onSubmit={handleSubmit} autoComplete="off">
@@ -165,14 +115,12 @@ export const RouteDiscovery: React.FC = () => {
165115
errorText={form.getFieldState("tokenAddress").error?.message}
166116
saveButton={
167117
// Only show the submit button in the default state
168-
!isSubmitSuccess && !isSubmitFail
169-
? {
170-
type: "submit",
171-
disabled: !form.formState.isDirty,
172-
isPending: submitDiscoveryMutation.isPending,
173-
variant: "primary",
174-
}
175-
: undefined // Hide the button when in success or error states
118+
{
119+
type: "submit",
120+
disabled: !form.formState.isDirty,
121+
isPending: submitDiscoveryMutation.isPending,
122+
variant: "outline",
123+
}
176124
}
177125
noPermissionText={undefined}
178126
>
@@ -186,47 +134,39 @@ export const RouteDiscovery: React.FC = () => {
186134
this page within 20-40 minutes of submitting this form.
187135
</p>
188136

189-
{isSubmitSuccess ? (
190-
<SuccessComponent />
191-
) : isSubmitFail ? (
192-
<FailComponent />
193-
) : (
194-
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
195-
<FormField
196-
control={form.control}
197-
name="chainId"
198-
render={({ field }) => (
199-
<FormItem>
200-
<FormLabel>Blockchain</FormLabel>
201-
<FormControl>
202-
<NetworkSelectorButton
203-
onSwitchChain={(chain) => {
204-
// When a chain is selected, capture its ID and name
205-
setSelectedChainId(chain.chainId);
206-
// Update the form field value
207-
field.onChange(chain.chainId);
208-
}}
209-
/>
210-
</FormControl>
211-
</FormItem>
212-
)}
213-
/>
214-
<FormField
215-
control={form.control}
216-
name="tokenAddress"
217-
render={({ field }) => (
218-
<FormItem>
219-
<FormLabel>Token Address</FormLabel>
220-
<FormControl>
221-
<div className="flex items-center gap-2">
222-
<Input {...field} placeholder="0x..." />
223-
</div>
224-
</FormControl>
225-
</FormItem>
226-
)}
227-
/>
228-
</div>
229-
)}
137+
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
138+
<FormField
139+
control={form.control}
140+
name="chainId"
141+
render={({ field }) => (
142+
<FormItem>
143+
<FormLabel>Blockchain</FormLabel>
144+
<FormControl>
145+
<NetworkSelectorButton
146+
onSwitchChain={(chain) => {
147+
// Update the form field value
148+
field.onChange(chain.chainId);
149+
}}
150+
/>
151+
</FormControl>
152+
</FormItem>
153+
)}
154+
/>
155+
<FormField
156+
control={form.control}
157+
name="tokenAddress"
158+
render={({ field }) => (
159+
<FormItem>
160+
<FormLabel>Token Address</FormLabel>
161+
<FormControl>
162+
<div className="flex items-center gap-2">
163+
<Input {...field} placeholder="0x..." />
164+
</div>
165+
</FormControl>
166+
</FormItem>
167+
)}
168+
/>
169+
</div>
230170
</div>
231171
</RouteDiscoveryCard>
232172
</form>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export const routeDiscoveryValidationSchema = z.object({
129129
.string({
130130
required_error: "Token address is required",
131131
})
132-
.min(1, "Token address is required")
133132
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid contract address format"),
134133
});
135134
export type RouteDiscoveryValidationSchema = z.infer<

0 commit comments

Comments
 (0)