fix(store): country dropdown + require state on checkout#137
Merged
Conversation
Two real causes of a 400 "Invalid input" at checkout: - Country was a free-text 2-char input; browser autofill fills "United States", which fails the ISO-2 rule. Replaced with a country <select> (ISO-2 values); added a countries list + normalizeCountry() name→code helper. - KeepKey rejects an empty state/province on EVERY country (verified US, BR, GB in sandbox), not just US. Client now requires state for all countries, so it's caught before the API call. Also map KeepKey's opaque `invalid_address`/"Invalid input" to an actionable message pointing at the address fields. i18n EN + PT-BR; tests for the country helpers. Verified in sandbox: valid US/BR/GB (with state) → 201; empty state blocked client-side; full country name no longer possible via the dropdown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
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.
Summary
Fixes the
400 "Invalid input"users hit at checkout. Two root causes:"United States", failing the ISO-2 rule. Now a country<select>(ISO-2 values), with anormalizeCountry()name→code helper as a safety net.stateon every country (verified US, BR, GB in sandbox — even the UK), not just US. The form now requires State/Province for all countries, so it's caught client-side before the API call.Also maps KeepKey's opaque
invalid_address/"Invalid input"to an actionable message.Changes
src/lib/store/countries.ts(+ test) — country list +normalizeCountry.src/components/store/CheckoutFlow.tsx— country dropdown; state always required; friendlier server-error surfacing.Test plan
pnpm test— 126 passingpnpm lint+tsccleanGenerated with Claude Code