feat(send): warn on tab close/refresh with unsaved transfer input (closes #456) - #558
Open
Vyacheslav-Tomashevskiy wants to merge 1 commit into
Conversation
…oses Northgate-Systems#456) Add a beforeunload guard so closing the tab, refreshing, or typing a new URL while the send form has real input doesn't silently drop a half-filled transfer. - src/hooks/useUnsavedChangesWarning.ts: new hook, takes an isDirty boolean and wires/unwires a beforeunload listener that calls preventDefault() + sets returnValue (browsers show their own wording regardless of the string, per spec). - src/app/(app)/send/page.tsx: isDirty = recipient typed something or the amount was changed from the page's own default (100.00) -- changing just the asset dropdowns alone doesn't count as 'input' worth warning about. Scope note: this only covers beforeunload (tab close/refresh/typed URL), not in-app Link navigation -- the App Router doesn't expose a route-change guard for that, and adding one is a much bigger change than this issue's estimated 1-3h. Verified npm run lint clean on the changed files, npm run build compiles (TypeScript step still fails only on the pre-existing, unrelated isValidStellarPublicKey import gap in validations.ts, same as flagged in Northgate-Systems#529 and prior PRs -- not touched here).
|
@Vyacheslav-Tomashevskiy is attempting to deploy a commit to the codex723's projects Team on Vercel. A member of the Team first needs to authorize it. |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #456.
What
Adds a "did you mean to leave?" browser confirm when someone tries to close the tab, refresh, or type a new URL while they have real input in the send form. Without this, a half-filled transfer just vanishes silently.
Where
src/hooks/useUnsavedChangesWarning.ts— new hook. Takes anisDirtyboolean and wires/unwires abeforeunloadlistener that callspreventDefault()and setsevent.returnValue(browsers ignore any custom message and render their own wording per the spec — setting the value is just what triggers the native prompt).src/app/(app)/send/page.tsx—isDirtyis true once the recipient field has something typed in it, or the amount has been changed away from the page's own default (100.00). Just switching the asset dropdowns doesn't count as "input" worth warning about on its own.Scope note
This only covers
beforeunload— tab close, refresh, typed-URL navigation. It does not intercept in-appLinknavigation (e.g. clicking something in the header/sidebar while the form is dirty), since the App Router doesn't expose a route-change guard for that today, and building one is a considerably bigger change than this issue's estimated 1-3h. Flagging this per the issue's own note about leaving a comment if the approach needs to narrow rather than silently changing scope.Verification
npm run lint— clean on the changed files.npm run build— Turbopack compile succeeds; thetscstep still fails, but only on the pre-existing, unrelatedisValidStellarPublicKeyimport gap insrc/lib/validations.ts(already flagged in fix(validations): restore broken isValidStellarPublicKey import; feat: add /api/stellar/fee-estimate #529 and prior PRs) — nothing in this PR touches that file.