Skip to content

Commit c200a9f

Browse files
author
Senior Engineer
committed
fix(frontend): add deposit form validation with inline errors
Add field-level validation for deposit/withdraw amounts and block form submission until input is valid, including minimum deposit and balance checks with inline messages that clear as users correct values. Made-with: Cursor
1 parent 7eb4c5a commit c200a9f

2 files changed

Lines changed: 414 additions & 152 deletions

File tree

frontend/src/components/VaultDashboard.test.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,39 @@ describe("VaultDashboard", () => {
158158
expect(input).toHaveValue(1250.5);
159159
});
160160

161-
it("prevents transactions above the max allowable amount", async () => {
161+
it("shows inline error and blocks submit for amounts above balance", async () => {
162162
renderDashboard("GABC123");
163163

164164
expect(await screen.findByText(/Approve & Deposit/i)).toBeInTheDocument();
165165

166166
const input = screen.getByPlaceholderText("0.00");
167167
fireEvent.change(input, { target: { value: "2000" } });
168-
fireEvent.click(screen.getByRole("button", { name: "Approve & Deposit" }));
168+
fireEvent.blur(input);
169169

170-
expect(screen.getByText(/Amount exceeds maximum/i)).toBeInTheDocument();
170+
expect(
171+
screen.getByText(/Deposit amount cannot exceed your available USDC balance./i),
172+
).toBeInTheDocument();
173+
expect(screen.getByRole("button", { name: "Approve & Deposit" })).toBeDisabled();
174+
});
175+
176+
it("shows minimum deposit validation and clears error when corrected", async () => {
177+
renderDashboard("GABC123");
178+
179+
expect(await screen.findByText(/Approve & Deposit/i)).toBeInTheDocument();
180+
181+
const input = screen.getByPlaceholderText("0.00");
182+
fireEvent.change(input, { target: { value: "0.5" } });
183+
fireEvent.blur(input);
184+
185+
expect(screen.getByText(/Minimum deposit is 1.00 USDC./i)).toBeInTheDocument();
186+
expect(screen.getByRole("button", { name: "Approve & Deposit" })).toBeDisabled();
187+
188+
fireEvent.change(input, { target: { value: "10" } });
189+
190+
await waitFor(() => {
191+
expect(screen.queryByText(/Minimum deposit is 1.00 USDC./i)).not.toBeInTheDocument();
192+
expect(screen.getByRole("button", { name: "Approve & Deposit" })).toBeEnabled();
193+
});
171194
});
172195

173196
it("shows a normalized API error message when data loading fails", async () => {
@@ -182,6 +205,8 @@ describe("VaultDashboard", () => {
182205
await waitFor(() => {
183206
expect(screen.getByRole("alert")).toHaveTextContent("Data unavailable");
184207
}, { timeout: 3000 });
185-
expect(screen.getByRole("alert")).toHaveTextContent("Failed to load vault data");
208+
expect(screen.getByRole("alert")).toHaveTextContent(
209+
"We could not reach the server. Check your connection and try again.",
210+
);
186211
});
187212
});

0 commit comments

Comments
 (0)