Skip to content

feat: i18n browser language detection + extract deposit validators with Vitest#36

Open
zqleslie wants to merge 1 commit into
davz7:mainfrom
zqleslie:fix-stellar-wave-29-27
Open

feat: i18n browser language detection + extract deposit validators with Vitest#36
zqleslie wants to merge 1 commit into
davz7:mainfrom
zqleslie:fix-stellar-wave-29-27

Conversation

@zqleslie

Copy link
Copy Markdown

Summary

Addresses issue #27 and issue #29 for Stellar Wave 5.

Issue #29 — Auto-detect browser language and persist preference ✅

  • Language detection on init: reads localStorage.getItem('ms-lang') first
  • Fallback to browser language: if no stored preference, parses navigator.language — if it starts with en, uses en; otherwise defaults to es
  • Persist manual choice: when user toggles language in LandingNavbar.jsx, the new value is written to localStorage.setItem('ms-lang', lang)
  • fallbackLng stays as es
  • No extra dependencies — manual implementation with i18next (lighter than adding i18next-browser-languagedetector)

Issue #27 — Vitest unit tests for deposit validation helpers ✅

  • Extracted validators into netlify/functions/_lib/depositValidation.js:
    • validateAmount — min/max range validation ($40–$100,000 MXN)
    • validateKyc — KYC status check (must be 'approved')
    • validateBankAccount — bank account status check (must be 'active')
    • validateUserId — user ID presence check
  • Vitest test file at netlify/functions/_lib/depositValidation.test.js with full coverage:
    • Amount: below min, above max, string, negative, zero, undefined, null, valid
    • KYC: pending, rejected, missing, approved
    • Bank account: pending, missing, active
    • User ID: missing, valid
  • Updated etherfuse-deposit.js to import from the helper — no behavior change
  • Added vitest to devDependencies and npm run test:functions script

Files changed

  • CreditRoot/src/i18n/index.js — Added browser language detection + localStorage persistence
  • CreditRoot/src/screens/components/LandingNavbar.jsx — Added localStorage write on toggle
  • netlify/functions/_lib/depositValidation.js (new) — Extracted pure validation helpers
  • netlify/functions/_lib/depositValidation.test.js (new) — Vitest unit tests
  • netlify/functions/etherfuse-deposit.js — Refactored to use extracted validators
  • package.json — Added vitest + test script
  • vitest.config.js (new) — Vitest configuration

Part of Stellar Wave 5 — May 26 to Jun 2, 2026

…t tests (Wave 5 davz7#27 davz7#29)

Issue davz7#29:
- Detect navigator.language on first visit (en→'en', else→'es')
- Persist user language choice in localStorage('ms-lang')
- Update LandingNavbar toggle to write to localStorage
- i18n fallbackLng stays 'es'

Issue davz7#27:
- Extract validators into netlify/functions/_lib/depositValidation.js
- Add Vitest test file with full coverage
- Update etherfuse-deposit.js to import from helper
- Add vitest to devDependencies + test:functions script

Fixes: davz7#27, davz7#29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant