fix(fe): resolve full-project audit findings, enforce type safety, and harden a11y & resilience
Summary of Changes
This PR resolves all findings from a comprehensive frontend code audit across finwise-miniapp-fe, adhering to the strict TypeScript guidelines in @AGENTS.md and standardizing security, accessibility, storage resiliency, and cache invalidation.
Key Improvements
1. Security & PII Protection
-
Redacted PII in Client Logs: Removed
console.logstatements inuse-zalo-login.tsthat exposed sensitive user details (zaloId, user name, avatar, and raw SDK responses) in the client console. -
SDK Typing: Replaced
anySDK payload castings with typed objects and unknown error catch blocks.
2. Strict Type Safety (Zero any Policy)
-
Eliminated
anyacross Services and Stores:-
auth.ts: RefactoredApiResponse<T = unknown>, typederrors?: unknown[], hoisted missing imports, and declaredRegisterRequest,UpdatePasswordRequest(supporting botholdPasswordandcurrentPassword), andResetPasswordRequest. -
auth.service.ts: Replaceddata: anysignatures with dedicated request types. -
ai-assistant.service.ts: UpdatedhandleAIError(error: unknown)with safeaxios.isAxiosError(error)narrowing. -
admin-settings.service.ts&use-admin-settings.ts: Replaced arbitraryvalue: anywithvalue: unknown. -
transactions/index.tsx: Replacedconst q: any = {}withTransactionQueryand typed filter state asTransactionType | "". -
api-client.ts: Introduced strongly typedQueuedRequestinterface for refresh queue handling.
-
3. Error Handling & Storage Resiliency
-
Crash-Proof
safeStorageWrapper: Addedsrc/lib/storage.tswith an in-memory fallback mechanism to prevent fatalSecurityErrorexceptions whenlocalStorageis blocked in restricted webviews or incognito browsing. -
Synchronized across Core Modules: Replaced raw
localStoragecalls acrossauth-store.ts,theme-store.ts,i18n/index.ts,login.tsx,api-client.ts, anduse-notification-sse.ts. -
Safe Admin Error Catches: Migrated untyped
catch (err: any)blocks tocatch (err: unknown)utilizinggetErrorMessage(err, fallback)in Admin settings, notifications, and AI management pages.
4. Accessibility (a11y) & UX Enhancements
-
Interactive
CardAccessibility: Interactive cards withonClickautomatically gainrole="button",tabIndex={0}, and Enter/Space keyboard handlers withevent.preventDefault()to avoid unintentional page scrolling. -
WAI-ARIA Tab Semantics: Added
type="button",role="tablist",role="tab", andaria-selectedtoTabs.tsxto prevent unintended form submissions and improve screen-reader support. -
Accessible Form Controls: Upgraded
Select.tsxwith deterministicReact.useId()and ARIA error binding (aria-invalid,aria-describedby). -
Consistent Date Formatting: Replaced unlocalized
.toLocaleString()calls in Admin tables with application-standardformatDatefromuseI18n().
5. Cache Invalidation Completeness
-
Transfer Query Invalidation: Added
reportKeys.allinvalidation to transfer mutations inuse-transfers.tsso cash flow figures and financial reports update immediately upon fund transfers.