feat(frontend): honor Swap query params on / and /swap (Uniswap/Pancake/Terra DEX aliases) #711
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#711
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The dApp homepage (
// Swap) ignores common DEX share and aggregator query strings (?outputCurrency=,inputCurrency,from,to, and the usual Uniswap / PancakeSwap / Terra Classic DEX aliases).https://dex.cl8y.com/swap/?…is supposed to work as well (redirect to/is OK if the query string is preserved). Today those links land on the default retail pair and look like the tokens were never requested.This is one product surface: Swap deep-link query params (route alias + parser + apply). Bundle
/swappreservation and token/amount apply together. Do not split “redirect” vs “parse” into two issues.Current codebase
Swap lives at
/;/swapis not a real routefrontend-dapp/src/App.tsxmountsSwapPageonly at/. There is no/swapRoute. Unknown paths hit:React Router
Navigate to="/"dropslocation.searchandlocation.hash. Visitinghttps://dex.cl8y.com/swap/?from=uluna&to=<cw20>therefore:index.html(docker/frontend/nginx.conftry_files … /index.html) — Coolify does not 404 the path./and throws away the query.SwapPagenever sees the intended tokens.Playwright already
page.goto('/swap')(e2e/swap-token-select-viewport.spec.ts,e2e/swap-token-select-cls.spec.ts) and comments that/swapredirects to/. That is why E2E still “works” without query params. Legal clickwrap allowlistshttps://dex.cl8y.com/swap(legalClickwrap.test.ts) as a same-origin path, not as a Swap parser.Shell Swap tab is
{ path: '/', label: 'Swap', end: true }(navItems.ts). Remaining on/after a search-preserving redirect keeps the Swap tab active (#182 /AGENTS_FRONTEND_SHELL_NAV.md).SwapPage never reads
useSearchParamsSwapPage.tsxinitializes:After factory pairs load, an effect overwrites empty / retail-hidden legs with
defaultRetailSwapTokenPair(first two non-gem ids — P562-4). There is no search-param branch, so a deep link cannot win over that default.The gap is already documented as known:
ust1SecondaryMarket.ts: “SwapPage does not yet honor token query params — keep the home Swap route only.”ust1SecondarySwapPath()returns'/'.Token pickers are factory-gated
TokenSearchSelect/tokenSearchQuery.ts(#481): options must stay insidegetAllTokens(pairs)(factory legs + wrap natives fromNATIVE_WRAPPED_PAIRS). Production hides gems (#562 P562, never?showGems=1). Visible native tickers are LUNC / USTC, ids stayuluna/uusd(#630).Create Pair must not grow query prefill (
/create?a=&b=is C542-11 / P402-5). Trade already deep-links via/trade/:pairAddr. This issue is Swap only.Contrast: other pages already parse query safely
?price=parseChartsPriceQueryjavascript:→ ignore; last repeated key wins; never echo raw HTML/ust1acquireparseUst1AcquirePrefilldirection+ humanamount;isPositiveDecimalAmount; max 24 chars; clamp; never auto-submituseSearchParamsis voidedSwap has zero of that for pay/receive.
Why the new implementation is needed
inputCurrency/outputCurrency. Terra Classic DEXes (Terraswap, Astroport, Terraport, Loop-style UIs) usefrom/towithuluna/uusd/terra1…. Token pages, listing forms, and partner CTAs already mint those URLs. CL8Y currently ignores them./swapis the URL people type. Docs, legal allowlist, and E2E treat/swapas the Swap page. The catch-all redirect withoutsearchmakesdex.cl8y.com/swap/?outputCurrency=…indistinguishable from a cold homepage visit./ust1secondary-market Swap CTAs cannot deep-link a UST1 pair until Swap honors tokens. Acquire Guide already prefills/ust1; Swap cannot do the inverse.This is frontend routing + a pure parser. No contract, indexer, or Coolify env change. Nginx SPA fallback already serves
/swap.Constraints / guardrails
getAllTokens(pairs)(or the wrap native/CW20 pair already injected there). Unknown / unlisted CW20s must not be injected into the picker or quoted.terra1…values must passisValidTerraBech32Address. Format-onlyterra1/ truncated / bad checksum → ignore that side (keep default). Never render the raw hostile string into the trigger or a banner.RUBY,EMBER, … /COLUMBUS5_GEM_ADDRESSES). LocalTerra /VITE_SHOW_TEST_TOKENS=truemay apply gems that are actually in the factory set. Never honor?showGems=1(X8).LUNC/lunc/uluna→ iduluna.USTC/UST/uusd→ iduusd. Display still LUNC/USTC. Do not treat a spoofed indexersymbol=UST1as identity when the address is in the gem set.ETH,BNB,WETH,0x…hex,ibc/…,factory/…→ ignore that side. Do not map ETH→LUNC.?outputCurrency=only: set receive, default pay todefaultRetailSwapTokenPair’s first id that is not the receive token (typically native/economic). Same for pay-only.exactAmount/amount/value/amountInonly whenisPositiveDecimalAmountand length ≤ a small cap (reuse the 24-char idea from/ust1). NoexactField=output/ reverse quote in this issue (Swap is You Pay–driven). Never auto-submit. Disconnect stays quote-only (#678 A678).slippage,expertMode,recipient/toAddress,pool_only/hybrid_optimize(hybrid stays always-on #596),chain=(except ignore), affiliate/referrer,javascript:,data:,http(s):,//.allTokensis non-empty. Query must win overdefaultRetailSwapTokenPairwithout a flicker-then-overwrite race, and must not re-apply on every picker change (user can still flip tokens after landing).uluna/uusd/ checksummedterra1). Symbols used for resolve only. Logos still go throughresolveTrustedTokenLogoUrl. NodangerouslySetInnerHTML. Nowindow.locationbuilt from query values except React Router search preservation of the already-parsedURLSearchParamsobject (do not concatenate user strings intoto=)./trade/:pairAddr)./ust1copy.Layoutuseskey={location.pathname}(#138). Search-only changes on/must not require a remount; apply viauseSearchParamson the already-mountedSwapPage.Relevant files
frontend-dapp/src/App.tsx/swap(and/swap/) before*; preservesearch+hashon redirect to/frontend-dapp/src/pages/SwapPage.tsxfrontend-dapp/src/utils/swapQueryParams.ts(new)frontend-dapp/src/utils/pairCatalogRank.tsdefaultRetailSwapTokenPair,isRetailHiddenTestToken, gem listsfrontend-dapp/src/utils/tokenRegistry.tsfrontend-dapp/src/utils/terraAddressValidation.tsfrontend-dapp/src/utils/tokenSearchQuery.tsfrontend-dapp/src/utils/decimalAmountInput.tsfrontend-dapp/src/utils/chartsPairRoute.tsfrontend-dapp/src/utils/ust1AcquirePrefill.tsfrontend-dapp/src/utils/ust1SecondaryMarket.tsust1SecondarySwapPath()can gain?from=&to=after parser existsfrontend-dapp/src/components/common/navItems.ts/frontend-dapp/src/utils/legalClickwrap.ts/swapalready allowlisted; redirect must stay same-origindocker/frontend/nginx.conftry_files(no new rewrite required)docs/frontend.mdskills/AGENTS_FRONTEND_SHELL_NAV.md/— update that/swappreserves searchfrontend-dapp/src/pages/SwapPage.test.tsxinitialEntrieswith queryfrontend-dapp/e2e/swap-token-select-viewport.spec.tsRecommended direction
Route alias. Small wrapper (not a bare
to="/"):path="/swap"→<Navigate to={{ pathname: '/', search: location.search, hash: location.hash }} replace />Same for trailing slash if the router does not collapse it. Keep catch-all
*for everything else. Do not mount a secondSwapPageat/swap(Swap tabend: truewould go inactive).Pure helper
parseSwapQueryParams(search: URLSearchParams): { payId, receiveId, payAmountHuman }with documented alias priority (first family with a non-empty value wins; within a family, last repeated key wins — same as Charts?price=):inputCurrency,from,tokenIn,token_in,sellToken,currencyIn,inToken,pay,offeroutputCurrency,to,tokenOut,token_out,buyToken,currencyOut,outToken,receive,askexactAmount,amount,value,amountInResolve a value in order: exact native denom (
uluna/uusd) → registry / wrap product ticker (case-insensitive, capped length like Charts 80) → checksummedterra1. Elsenull.Apply in SwapPage once
allTokens.length >= 2: resolve both sides against the factory set + retail gem filter; if pay invalid, keep default pay; if receive invalid, keep default receive; if both invalid, current defaults. Then setinputAmountonly when the amount parse succeeds. Flip-direction and pickeronChangestill work afterward.Optional follow-through (same MR):
ust1SecondarySwapPath()→'/?from=<ust1>&to=<quote>'(or/swap/?…which redirects) using published mainnet/env addresses, only when those ids are in the factory set. Update the “no fake query params” unit test.Canonical outbound links (token pages, Guide, listings) may mint
/?from=&to=or/swap/?inputCurrency=&outputCurrency=. Preferfrom/towithuluna/uusd/bech32 in first-party UI so we do not put display tickers in execute ids. Accepting Uniswap names is for inbound compatibility.Acceptance criteria
/?from=uluna&to=<listed cw20>selects Pay LUNC and Receive that token after pairs load (columbus-5 or LocalTerra listed id)./?inputCurrency=uluna&outputCurrency=<listed cw20>and Pancake-style?outputCurrency=only (pay defaults) work the same.https://dex.cl8y.com/swap/?from=…&to=…and/swap/?…(trailing slash OK) redirect or resolve to Swap with the same tokens (search preserved). Swap nav tab stays active.LUNC/USTC/CL8Y/UST1/cLUNC/cUSTCtickers resolve to the correct ids when those assets are in the factory/wrap universe.javascript:alert(1), HTML,0x…,ETH, overlong, empty, and gem (production) values are ignored per side; defaults remain; no raw string in the DOM trigger.?showGems=1is ignored.?a=&b=prefill. Trade URLs unchanged./swapE2E without query still pass (redirect to/OK).docs/frontend.md) list supported keys and fail-closed rules. Shell-nav skill notes/swappreserves search.Test plan (functional paths)
/no querydefaultRetailSwapTokenPair/?from=uluna&to=<listed>/?inputCurrency=uusd&outputCurrency=<listed>/?outputCurrency=<listed>only/swap?from=uluna&to=<listed>and/swap/?from=…from=LUNC&to=UST1(when UST1 listed)uluna+ UST1 CW20; UI shows LUNC / UST1exactAmount=1.5with valid tokens1.5; no wallet popupVITE_NETWORK=localfrom=uluna&to=<cLUNC>ust1SecondarySwapPath()(if updated)page.goto('/swap')existing viewport/CLS E2E#/junkVitest: table-driven
swapQueryParams.test.ts(aliases, hostile, gems, tickers, amount). RTLSwapPagewithMemoryRouter initialEntries={['/?from=uluna&to=…']}and mockedgetAllTokens. Playwright smoke:goto('/swap?from=uluna&to=…')assert pay/receive combobox labels (5 workers,PLAYWRIGHT_SKIP_CHAIN=1OK if factory tokens exist).Test plan (attack, hack, and abuse)
?from=javascript:alert(1)/data:text/html/https://evil///evil?to=<img onerror=…>/to=%3Cscript%3Eterra1/ truncatedfrom=RUBY?showGems=1/?expertMode=1/?slippage=50?recipient=<attacker>/toAddress=senderstays connected wallet?pool_only=1/hybrid_optimize=0exactAmount=1e18/ negative /999…(over cap) / commasterra1CW20to=https://phishas receive or as Navigateto{ pathname: '/', search, hash }from=uluna&from=uusdto=terra1…)redirect_uri/swap?…must not widen originsVerification criteria
make lint-frontendand Vitest for the new helper + SwapPage RTL +ust1SecondaryMarketpath test (if updated)./swap?from=…&to=…(and/equivalent) shows the intended combobox labels;/swapwithout query still matches existing #498/#632 tests.VITE_NETWORK=mainnetunit tests prove gem query does not apply.http://127.0.0.1:5173/swap?from=uluna&to=<local listed cw20>aftermake dev— Pay LUNC, receive that token, type an amount, confirm quote; change token; confirm query does not snap back. Repeat with PancakeoutputCurrencyonly.https://dex.cl8y.com/swap/?inputCurrency=uluna&outputCurrency=<columbus-5 listed>selects the pair; Swap tab active; no extra/swapchrome.make verify-issue-678still passes (acquire banners). Do not regress #481 / #562 / #630 / #182 / #542.Out of scope: reverse (
exactField=output) quotes; Trade query tokens; Create Pair prefill; persisting query intolocalStorage; rewriting the URL on every picker change (nice-to-have later, not required); mapping EVM addresses.marked as related to #678
marked as related to #508
marked as related to #481
marked as related to #562
mentioned in merge request !1199
Implementation is in !1199 (
feat/711-swap-query-params).make verify-issue-711passed twice (parser + RTL + C542-11 + docs/skills). Playwright/swapsmoke and Coolify were not run here (no LocalTerra in this session).Follow-up for marketing-site DEX hrefs (gated on this MR merge): opened on PlasticDigits/CL8Y-web — deep-link
/?from=uluna&to=<CL8Y CW20>on the Trade-on-DEX row; keep product originhttps://dex.cl8y.comquery-free.marked as related to #713
mentioned in issue #713
Follow-up for #711 leftovers (reverse quote, URL rewrite, Swap Share, Create/Trade query prefill) is bundled in #713. Keep that work off !1199.
mentioned in merge request !1200
mentioned in commit
13d586b9f6mentioned in issue #714
marked as related to #714
Merged as !1199 into main (plus follow-up !1200 / #713).
Sanity check before merge:
verify-issue-711).pairsQuery.isSuccessgate + delayed-pairs RTL).make verify-issue-7115/5 after that.Post-merge leftover: #714. Do not reopen this issue unless a merged invariant is wrong.
mentioned in issue #715
marked as related to #715
mentioned in merge request !1201
mentioned in issue #716