2.6 KiB
2.6 KiB
KYC Wizard EU-Ready Smart Address Implementation
Overview
Enhanced the CompleteKycView.vue Step 2 (Address) with an EU-ready country selector and smart ZIP→City auto-fill using the zippopotam.us public API.
Changes Made
1. Frontend: frontend/src/views/CompleteKycView.vue
Template Changes (Step 2 - Address)
- Country selector added as the first field in Step 2 — a
<select>bound tokycForm.region_codewith options: HU, AT, SK, DE, RO (with flag emojis) - City field now has a relative wrapper with a loading spinner (animated SVG) that appears when
isCityLoading === true - City input gets
opacity-60class during loading for visual feedback
Script Changes
- Import: Added
watchfrom Vue - New ref:
isCityLoading(boolean, defaultfalse) - Form state: Added
region_code: 'HU'tokycFormreactive object - Debounced watch on
address_zip:- Clears previous timeout on each keystroke
- Triggers only when ZIP length >= 3
- 600ms debounce delay
- Calls
https://api.zippopotam.us/{country}/{zip}using the selectedregion_code - On success, auto-fills
kycForm.address_cityfromdata.places[0]['place name'] - Error handling with
console.error(silent fail, user can still type city manually) isCityLoadingreset infinallyblock
- Submit payload: Added
region_code: kycForm.region_codeto the API call
2. Backend Schema: backend/app/schemas/auth.py
- Added
region_code: Optional[str] = "HU"toUserKYCCompletePydantic model
3. Backend Service: backend/app/services/auth_service.py
- In
complete_kyc(): Addedif kyc_in.region_code: user.region_code = kyc_in.region_codeto persist the selected country code to the user record
Data Flow
- User selects country (default: HU) →
kycForm.region_code - User types ZIP code → debounced 600ms →
fetch(zippopotam.us/{country}/{zip}) - If found →
address_cityauto-filled; if not → silent fail, manual entry - On submit →
region_codesent in payload → backend updatesusers.region_code
EU Countries Supported
| Code | Country |
|---|---|
| HU | Magyarország |
| AT | Ausztria |
| SK | Szlovákia |
| DE | Németország |
| RO | Románia |
API Reference
- zippopotam.us: Free, no API key required. Returns JSON with
places[]containingplace name,state, etc. - Endpoint format:
https://api.zippopotam.us/{country_code}/{zip_code}