refactor(kyc): consume API validation pattern instead of hardcoded swissPaymentText mirror#739
Draft
TaprootFreak wants to merge 1 commit into
Draft
refactor(kyc): consume API validation pattern instead of hardcoded swissPaymentText mirror#739TaprootFreak wants to merge 1 commit into
TaprootFreak wants to merge 1 commit into
Conversation
…issPaymentText mirror The app kept a byte-for-byte copy of the API's swissPaymentText regex in lib/packages/utils/swiss_payment_text.dart to validate name/address fields inline. That mirror silently drifts whenever the backend's Config.formats.swissPaymentText changes, and it encodes an allowed-character rule the API owns. Replace it with a DfxConfigService that fetches the authoritative pattern from GET /v1/config, compiles it at runtime and validates synchronously. The pattern is warmed at startup and cached (30 min TTL); it is dropped on network switch alongside the other reference-data caches. If the pattern hasn't loaded yet the validator returns true and defers to the server's authoritative @IsSwissPaymentText() check, so the app is never more restrictive than the API and needs no hardcoded fallback. This also fixes the foreign-postal-code class of bugs: NL "1011 AB", UK "EC1A 1BB", CA "K1A 0B1", IE "D02 AF30" now validate correctly because the rule comes from the API rather than a client guess. Deletes the local mirror and its test in the same PR. Server-side change: DFXswiss/api#3911.
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.
What
Deletes the hardcoded
swissPaymentTextregex mirror (lib/packages/utils/swiss_payment_text.dart) and validates name/address fields against the pattern the API serves atGET /v1/configinstead.DfxConfigService— fetches{ formats: { swissPaymentText: { pattern, flags } } }, compiles it to a DartRegExp, caches it (30 min TTL), and exposes a synchronousisSwissPaymentText(value)for form validators.finishSetup(fire-and-forget; failure just defers to the server). Dropped on network switch alongside the other reference-data caches.getIt<DfxConfigService>().isSwissPaymentText(...).Why
Per
CONTRIBUTING.md→ "API as Decision Authority", which characters are valid is a backend-owned rule the app should render, not re-implement. The mirror silently drifted wheneverConfig.formats.swissPaymentTextchanged, and it encoded an allowed-character decision client-side.It also fixes the foreign-postal-code class of bugs: NL
1011 AB, UKEC1A 1BB, CAK1A 0B1, IED02 AF30now validate correctly because the rule comes from the API, not a client guess.Backward compatibility
If the pattern hasn't loaded yet (pre-rollout backend, offline, or first instant after launch) the validator returns
trueand defers to the server's authoritative@IsSwissPaymentText()— the app is never more restrictive than the API and never needs a hardcoded fallback. Mirrors the "legacy backend tolerance" rule.Pair-PR / merge order
Server-side counterpart: DFXswiss/api#3911 (DFXswiss/api#3911), which adds
GET /v1/config.Tests
test/packages/service/dfx/dfx_config_service_test.dart:loadfetches/v1/configand caches;invalidateCacheforces a refetch; non-200 throws.true(defers to server).Verified locally on m5me (Flutter 3.41.6):
dart format,flutter analyze(whole project, clean), and the service test all green. Additionally ran a live end-to-end check against a real DFX API booted on m5me serving this branch of #3911 — the app DTO parsed the actual/v1/configresponse and validated the full matrix identically to the deleted mirror.