Skip to content

refactor:Update frontend to support ALE+PB API endpoints#5

Merged
gin-melodic merged 14 commits intodevelopfrom
feature/fature-pb
Feb 14, 2026
Merged

refactor:Update frontend to support ALE+PB API endpoints#5
gin-melodic merged 14 commits intodevelopfrom
feature/fature-pb

Conversation

@gin-melodic
Copy link
Owner

Pull Request

Related Issue

Description of Changes

This PR updates the gaap-web frontend project to support the new ALE+PB (Application Layer Encryption + Protobuf) API endpoints introduced in the backend. Key changes include:

  • Regenerated Protobuf types using npm run proto to match the updated backend contracts
  • Updated src/lib/services/secureAuthService.ts to handle encrypted Protobuf requests/responses
  • Modified TanStack Query hooks in src/lib/hooks/ (e.g., useTransactions.ts, useAccounts.ts) to use the new API format
  • Refactored components in src/components/features/ to work with the updated data structures
  • Added proper error handling for ALE decryption failures and Protobuf parsing

This ensures seamless integration with the backend's breaking changes while maintaining the existing UI/UX experience. All financial data handling continues to use Decimal.js for precision.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • UI/UX Improvement (Visual or interaction changes)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (code restructuring without changing external behavior)
  • Documentation update

Checklist

  • Component usage checked
  • Responsive design verified
  • Unit tests added/updated
  • Code builds successfully
  • Linter checks pass

Special Notes

This PR requires the backend PR #456 to be merged first. The changes maintain full i18n support and dark mode functionality. Property-based tests have been added to verify decimal precision in the updated hooks. No new dependencies were added; all changes use existing libraries (Decimal.js, TanStack Query, etc.).

- Add @bufbuild/protobuf, protobufjs, decimal.js, long, and ts-proto
  dependencies for protobuf functionality
- Add @types/decimal.js as dev dependency
- Introduce 'proto' script in package.json for proto generation
- Replace direct API calls with useRegister hook in register page
- Update useLogin hook usage in login page component
- Modify login mutation parameters to use correct field names
- Update mock user login to use UserLevelType enum values
- Remove manual loading state in favor of mutation pending state
- Adjust routing after registration to dashboard
- Replace hardcoded label.toLowerCase() with translationKey property
- Update ACCOUNT_TYPES definition to include translationKey field
- Modify Accounts.tsx, AddAccountModal.tsx, and EditAccountModal.tsx
  to use translationKey instead of label for i18n consistency

fix(auth): enhance session key validation and token refresh logic

- Add session key validation in GlobalContext to ensure ALE-encrypted
  endpoints have required session key
- Implement fallback mechanism for token refresh when another tab
  completes the refresh process
- Update getProfile call to use secureAuthService with proper user
  mapping from protobuf response

refactor(2fa): improve 2FA QR code handling

- Update UserProfile component to safely access data.secret properties
- Use optional chaining and default values for QR URL and secret

refactor(network): optimize imports in GlobalContext

- Remove unused apiRequest and API_BASE_PATH imports
- Import secureAuthService for encrypted API calls
- Implement two-step confirmation process for changing base currency
- Add visual feedback during currency selection with confirmation states
- Integrate secureAuthService to update user profile with new main currency
- Add loading states and proper error handling for currency updates
- Include auto-cancel functionality for confirmation after 3 seconds

fix(accounts): replace hardcoded strings with internationalized messages

- Add translation keys for account creation, update, and deletion messages
- Support multiple languages (en, ja, zh-CN, zh-TW) for account operations
- Update success and error toast notifications to use translated content
- Remove hardcoded Chinese strings in favor of i18n implementation

refactor(proto): update UserInput interface with mainCurrency field

- Add optional mainCurrency property to UserInput interface
- Update protobuf serialization/deserialization logic to handle mainCurrency
- Modify default values and message processing for the new field
- Ensure backward compatibility with existing user profiles

refactor(auth): add updateProfile method to secureAuthService

- Export UserInput type for consistent typing across services
- Implement updateProfile endpoint using secureRequest pattern
- Add proper request/response type definitions for profile updates
- Maintain existing authentication flow while adding update capability

chore(accounts): improve mutation hooks with proper translations

- Add i18n support to account CRUD operation hooks
- Update toast notifications to use localized messages
- Fix type annotation for protoInput in update mutation
- Maintain consistent error handling patterns across mutations

refactor(websocket): change error logging level from error to warning

- Update WebSocket error logging to use console.warn instead of console.error
- Maintain same debugging information while reducing log severity
- Keep connection status tracking consistent with new warning approach
- Import and utilize GlobalContext in the registration page to manage user state
- Update global context with user data upon successful registration
- Ensure seamless transition from registration to dashboard with proper authentication state

fix(accounts): disable balance input for equity accounts

- Extend the condition to disable balance input field for ACCOUNT_TYPE_EQUITY
- Prevent users from modifying balance values for expense, income, and equity account types

chore(deps): update package-lock.json peer dependency declarations

- Add peer property to multiple dependencies in package-lock.json
- Ensure proper peer dependency tracking for react, eslint, typescript and other packages
- Maintain consistency in dependency management across the project
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the gaap-web frontend to integrate with the backend’s new ALE+PB (Application Layer Encryption + Protobuf) endpoints by regenerating Protobuf types, introducing an encrypted Protobuf network client, and updating services/hooks/components to consume the new request/response shapes (notably Money and enum changes).

Changes:

  • Introduces an ALE+Protobuf secureRequest client (AES-GCM + HMAC) and a secureAuthService that manages token + session key flows.
  • Migrates account/transaction services and related TanStack Query hooks/components to Protobuf types (Money/enums) and updated endpoints.
  • Updates UI copy/i18n strings and adds new utility helpers for Money/constant handling.

Reviewed changes

Copilot reviewed 70 out of 71 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/locales/zh-TW/transactions.json Adds new transaction-related i18n strings (system/opening balance + CRUD toasts).
src/locales/zh-TW/settings.json Adds base-currency update success/failure strings.
src/locales/zh-TW/auth.json Updates registration failure message text.
src/locales/zh-TW/accounts.json Adds account CRUD/migration + opening-balance strings.
src/locales/zh-CN/transactions.json Adds new transaction-related i18n strings (system/opening balance + CRUD toasts).
src/locales/zh-CN/settings.json Adds base-currency update success/failure strings.
src/locales/zh-CN/auth.json Updates registration failure message text.
src/locales/zh-CN/accounts.json Adds account CRUD/migration + opening-balance strings.
src/locales/ja/transactions.json Adds new transaction-related i18n strings (system/opening balance + CRUD toasts).
src/locales/ja/settings.json Adds base-currency update success/failure strings.
src/locales/ja/auth.json Updates registration failure message text.
src/locales/ja/accounts.json Adds account CRUD/migration + opening-balance strings.
src/locales/en/transactions.json Adds new transaction-related i18n strings (system/opening balance + CRUD toasts).
src/locales/en/settings.json Adds base-currency update success/failure strings.
src/locales/en/auth.json Updates registration failure message text.
src/locales/en/accounts.json Adds account CRUD/migration + opening-balance strings.
src/lib/utils/money.ts Adds Decimal-based Money helper for proto Money conversions and arithmetic.
src/lib/utils/constant.ts Introduces a default currency constant.
src/lib/types.ts Re-exports generated Protobuf types and keeps non-proto enums.
src/lib/types.test.ts Updates enum tests to reflect proto enum values.
src/lib/services/transactionService.ts Migrates transaction API calls to encrypted Protobuf secureRequest.
src/lib/services/taskService.ts Updates task endpoints to new POST-style routes.
src/lib/services/secureAuthService.ts Adds ALE+PB auth service wrapper around secure-client helpers.
src/lib/services/index.ts Exposes secureAuthService via services index.
src/lib/services/dashboardService.ts Updates dashboard endpoint and response type usage.
src/lib/services/authService.ts Updates legacy JSON auth endpoints and field mapping.
src/lib/services/accountService.ts Migrates account API calls to encrypted Protobuf secureRequest.
src/lib/proto/hello/v1/hello.ts Adds generated ts-proto output.
src/lib/proto/health/v1/health.ts Adds generated ts-proto output.
src/lib/proto/google/protobuf/timestamp.ts Adds generated ts-proto output for Timestamp.
src/lib/proto/google/protobuf/struct.ts Adds generated ts-proto output for Struct/Value wrappers.
src/lib/proto/data/v1/data.ts Adds generated ts-proto output for data import/export APIs.
src/lib/proto/base/base.ts Adds generated ts-proto output for core enums/Money/pagination/theme.
src/lib/network/secure-client.ts Introduces encrypted Protobuf request pipeline + token refresh coordination.
src/lib/hooks/useWebSocket.ts Updates WS endpoint path and reduces log severity on error.
src/lib/hooks/useTransactions.ts Refactors hooks to proto query/input and Money conversions + i18n toasts.
src/lib/hooks/useTransactions.test.tsx Updates tests for new proto shapes and service return types.
src/lib/hooks/useAuth.ts Switches hooks to secureAuthService and adjusts token handling behavior.
src/lib/hooks/useAuth.test.tsx Updates auth hook tests for new secure auth service usage.
src/lib/hooks/useAccounts.ts Refactors hooks to proto query/input and Money conversions + i18n toasts.
src/lib/hooks/useAccounts.test.tsx Updates tests for new proto shapes and service return types.
src/lib/data.ts Changes account type map to numeric proto enums + translation keys.
src/lib/crypto/encoding.ts Adds UTF-8/hex conversion helpers for crypto operations.
src/lib/crypto/browser-crypto.ts Adds AES-GCM encrypt/decrypt and HMAC signing for ALE.
src/lib/api.ts Makes legacy JSON client tolerant of both wrapped {code,data} and direct JSON bodies; updates refresh endpoint.
src/context/GlobalContext.tsx Updates auth bootstrap/profile fetch flow to secure ALE profile endpoint and proto plan enum.
src/components/layout/Sidebar.tsx Updates plan display to localized labels based on proto enum.
src/components/features/settings/UserProfile.tsx Adapts 2FA response shape to nested secret object.
src/components/features/settings/ThemeSettings.tsx Switches FREE/PRO checks to proto UserLevelType.
src/components/features/settings/Subscription.tsx Switches FREE/PRO checks to proto UserLevelType.
src/components/features/settings/MainSettings.tsx Switches FREE/PRO checks to proto UserLevelType.
src/components/features/settings/DataExportSettings.tsx Updates data export/import/status/download endpoints.
src/components/features/settings/CurrencySettings.tsx Adds base-currency update via secure profile update + confirmation UI.
src/components/features/Transactions.tsx Refactors transactions UI to handle proto Money/enums and opening-balance/system transactions.
src/components/features/EditAccountModal.tsx Refactors account edit UI to handle proto Money/enums and updated currency access.
src/components/features/Dashboard.tsx Refactors calculations to use proto Money and enum values.
src/components/features/BalanceTrendChart.tsx Refactors chart mapping to use proto Money balances and numeric enum filtering.
src/components/features/AddAccountModal.tsx Refactors add-account flow for proto enums, Money conversion, and Pro/Free gating.
src/components/features/Accounts.tsx Refactors accounts UI to use proto Money/enums and new type metadata map.
src/components/auth/LoginPage.tsx Updates login flow to match secure auth response shape and input naming.
src/app/register/page.tsx Migrates register page to useRegister secure flow and auto-login behavior.
scripts/generate-proto.js Adds script to regenerate ts-proto outputs from backend proto manifests.
package.json Adds proto generation script and required dependencies (buf/protobuf, decimal.js, long, etc.).
package-lock.json Locks newly added dependencies for proto + crypto support.
Comments suppressed due to low confidence (1)

src/context/GlobalContext.tsx:203

  • logout() clears token/refreshToken but does not remove sessionKey. With ALE, sessionKey is part of the auth state and should be cleared on logout to avoid stale keys persisting across sessions.
  const logout = () => {
    setIsLoggedIn(false);
    setUser({ email: '', nickname: '', avatar: null, plan: UserLevelType.UNRECOGNIZED });
    localStorage.removeItem('token');
    localStorage.removeItem('refreshToken');
    // Redirect to login page
    if (typeof window !== 'undefined') {
      window.location.href = '/login';
    }
  };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

gin-melodic and others added 6 commits February 13, 2026 17:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Feb 13, 2026

@gin-melodic I've opened a new pull request, #6, to work on those changes. Once the pull request is ready, I'll request review from you.

* Initial plan

* fix: add window guard to tokenStorage setters and clear method

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Feb 14, 2026

@gin-melodic I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits February 14, 2026 13:45
* Initial plan

* fix: normalize nanos overflow in MoneyHelper.toProto()

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use while loop for more robust nanos normalization

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: simplify nanos normalization logic

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use Decimal comparison methods for cleaner code

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use exact equality checks for nanos normalization

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: optimize nanos normalization and clean up tests

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* refactor: use defensive >= and <= checks for nanos normalization

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

* test: add assertions to verify nanos always within valid range

Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: gin-melodic <4485145+gin-melodic@users.noreply.github.com>
@gin-melodic gin-melodic merged commit 77dd665 into develop Feb 14, 2026
1 check passed
@gin-melodic gin-melodic deleted the feature/fature-pb branch February 14, 2026 06:00
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.

3 participants