From 128126e9539025922f7aedbb8972f79459caaf74 Mon Sep 17 00:00:00 2001 From: Gadflyxx Date: Thu, 3 Sep 2026 14:01:34 +0000 Subject: [PATCH] fix:All issue --- src/app/solve/SolvePageClient.tsx | 14 +++++- src/components/SwapCard.test.tsx | 70 ++++++++++++++++++++++++++++++ src/components/SwapCard.tsx | 19 +++++++- src/hooks/useSolverRegistration.ts | 10 ++++- src/hooks/useSwapSubmission.ts | 12 ++++- src/lib/i18n/messages/en.ts | 2 + src/lib/i18n/messages/es.ts | 1 + src/store/wallet.ts | 2 +- 8 files changed, 124 insertions(+), 6 deletions(-) diff --git a/src/app/solve/SolvePageClient.tsx b/src/app/solve/SolvePageClient.tsx index 8673fb5..cf89633 100644 --- a/src/app/solve/SolvePageClient.tsx +++ b/src/app/solve/SolvePageClient.tsx @@ -684,10 +684,20 @@ export default function SolvePageClient() {

)} + {networkMismatch && ( +

+ ⚠ Wrong network — switch Freighter to{" "} + + {process.env["NEXT_PUBLIC_NETWORK"] ?? "testnet"} + {" "} + before registering. +

+ )} + diff --git a/src/components/SwapCard.test.tsx b/src/components/SwapCard.test.tsx index 35f819c..044388b 100644 --- a/src/components/SwapCard.test.tsx +++ b/src/components/SwapCard.test.tsx @@ -289,4 +289,74 @@ describe("SwapCard", () => { }), ); }); + + // ── Issue #248: networkMismatch submission guard ────────────────────────── + + it("disables the swap button and shows an inline alert when connected to the wrong network", async () => { + useWalletStore.setState({ + isConnected: true, + address: "GABC123", + network: "MAINNET", + networkMismatch: true, + }); + + const user = userEvent.setup(); + renderSwapCard(); + + const input = screen.getByPlaceholderText("0"); + await user.type(input, "500"); + + // Inline alert must be visible. + await waitFor(() => { + expect(screen.getAllByRole("alert").some((el) => + el.textContent?.toLowerCase().includes("wrong network") + )).toBe(true); + }); + + // The swap button must be disabled. + const swapButton = screen.getAllByRole("button").find( + (btn) => btn.textContent?.toLowerCase().includes("wrong network") + ); + expect(swapButton).toBeDefined(); + expect(swapButton).toBeDisabled(); + + // Freighter must never be called. + expect(signTransactionMock).not.toHaveBeenCalled(); + }); + + it("does not show the network-mismatch alert when networkMismatch is false", async () => { + useWalletStore.setState({ + isConnected: true, + address: "GABC123", + network: "TESTNET", + networkMismatch: false, + }); + + renderSwapCard(); + + // No mismatch alert should be present. + const alerts = screen.queryAllByRole("alert"); + const mismatchAlert = alerts.find((el) => + el.textContent?.toLowerCase().includes("wrong network") + ); + expect(mismatchAlert).toBeUndefined(); + }); + + it("does not show the network-mismatch alert when wallet is not connected (networkMismatch defaults to false)", () => { + // networkMismatch defaults to false before any connection — the guard + // must not falsely block a pre-connection state. + useWalletStore.setState({ + isConnected: false, + address: null, + networkMismatch: false, + }); + + renderSwapCard(); + + const alerts = screen.queryAllByRole("alert"); + const mismatchAlert = alerts.find((el) => + el.textContent?.toLowerCase().includes("wrong network") + ); + expect(mismatchAlert).toBeUndefined(); + }); }); diff --git a/src/components/SwapCard.tsx b/src/components/SwapCard.tsx index 6327935..0028a43 100644 --- a/src/components/SwapCard.tsx +++ b/src/components/SwapCard.tsx @@ -6,6 +6,7 @@ import { useQuote } from "@/hooks/useQuote"; import { useSwapSubmission } from "@/hooks/useSwapSubmission"; import { useRecentChains } from "@/hooks/useRecentChains"; import { useToastStore } from "@/store/toast"; +import { useWalletStore } from "@/store/wallet"; import { CHAINS, DST_TOKENS, SRC_TOKENS } from "@/lib/marketData"; import { isValidStellarPublicKey } from "@/lib/stellarAddress"; import { formatTokenAmount } from "@/lib/format"; @@ -214,12 +215,14 @@ export function SwapCard({ initialAmount = "", previewQuote, onPreviewSubmit }: // ── Submission ───────────────────────────────────────────────────────────── const submission = useSwapSubmission(); const isSubmitting = submission.status in SUBMISSION_LABEL_KEY; + const networkMismatch = useWalletStore((s) => s.networkMismatch); const canSwap = Boolean(srcAmount) && parseFloat(srcAmount) > 0 && !quoting && !isSubmitting && - !dstAddressError; + !dstAddressError && + !networkMismatch; function truncateToDecimals(value: string, decimals: number): string { const dotIndex = value.indexOf("."); @@ -673,6 +676,16 @@ export function SwapCard({ initialAmount = "", previewQuote, onPreviewSubmit }:

)} + {networkMismatch && ( +

+ ⚠ Wrong network — switch Freighter to{" "} + + {process.env["NEXT_PUBLIC_NETWORK"] ?? "testnet"} + {" "} + before swapping. +

+ )} +