Skip to content

refactor: extract wallet from marketplaces into standalone component with provider protocol #126

Merged
shubham3121 merged 10 commits intomainfrom
shubham/mpp/wallets
Apr 5, 2026
Merged

refactor: extract wallet from marketplaces into standalone component with provider protocol #126
shubham3121 merged 10 commits intomainfrom
shubham/mpp/wallets

Conversation

@shubham3121
Copy link
Copy Markdown
Member

This pull request introduces a major refactor of how wallet data is managed for payment and accounting policies, extracting wallet information from the marketplaces and settings tables into a new standalone wallets table. It updates data models, repositories, and endpoint logic to support this new structure, and removes legacy wallet-handling code from the marketplace layer. The changes improve separation of concerns and pave the way for supporting multiple wallet types and better security.

Database and Data Model Changes:

  • Added a new wallets table to store wallet information, including wallet type, configuration, and linkage to tenants. Migrated relevant wallet data from marketplaces and settings into this new table, and linked existing payment policies to the appropriate wallet via a new wallet_id foreign key on the policies table. Old wallet fields were removed from marketplaces and settings.
  • Updated the AttachedPolicy schema to include an optional wallet_id field, allowing policies to reference a wallet directly.
  • Removed wallet-related fields (wallet_address, wallet_private_key) from the Marketplace entity and eliminated wallet management methods from the MarketplaceHandler and repository. [1] [2] [3] [4] [5] [6] [7]

Endpoint and Handler Refactors:

  • Refactored the EndpointHandler to use a WalletRepository for loading wallet configuration for payment policies, removing legacy logic that injected wallet credentials from the marketplace or settings. The handler now builds policy context metadata based on the wallet attached to the payment policy. [1] [2] [3] [4] [5] [6]

Infrastructure and Imports:

  • Updated Alembic environment and handler imports to reference the new wallet entities and repositories. [1] [2]

These changes modernize the wallet infrastructure, centralize sensitive data, and improve maintainability for future payment integrations.

…t providers

New standalone wallet component following Clean Architecture:
- Wallet entity with wallet_type + configuration JSON
- WalletProvider Protocol (gateway boundary) with SetupResult
- MppWalletProvider (generates/imports Tempo keypairs)
- XenditWalletProvider (validates gateway credentials)
- WalletType/WalletCategory enums, config registry
- WalletHandler (use case), WalletRepository, schemas, routes
- Category-split file structure: wallets/mpp/ and wallets/gateway/xendit/
- Add wallet_id FK on Policy entity (payment policies reference a wallet)
- PolicyHandler: validate wallet_id required for payment policies,
  enforce same-wallet-per-endpoint rule
- EndpointHandler: load wallet from payment policy's wallet_id at
  query time, replace marketplace+settings lookup
- Remove settings_repository dependency from EndpointHandler
  (mpp_secret_key now lives in wallet credentials)
- Remove mpp_secret_key from Settings entity and repository
- Add wallets relationship to Tenant entity
- Wire WalletRepository, providers, handler, and routes in main.py
- Update alembic/env.py with Wallet entity import
- Remove wallet_address and wallet_private_key from Marketplace entity
- Remove 6 wallet methods from MarketplaceHandler
- Remove 6 wallet routes from marketplace routes
- Remove wallet schemas from marketplace schemas
- Remove wallet params from MarketplaceRepository.update()
- Add migration: create wallets table, add wallet_id FK to policies,
  migrate existing MPP data, drop old columns
- Create wallets.ts API module with MPP + gateway routes
- Update types: WalletResponse with id/wallet_type/display,
  WalletListItem, MppBalanceResponse
- Update user store: auto-discover MPP wallet via walletsApi.list(),
  fetchBalance uses wallet ID
- Update WalletSetupDialog: use walletsApi for create/import/update
- Update TransactionsDialog: use walletsApi.getMppTransactions
- Update SettingsPage, CreateDataEndpointPage: use walletsApi.list()
- Remove wallet methods from marketplacesApi
- Remove dead BalanceResponse and CreateWalletResponse types
@shubham3121 shubham3121 force-pushed the shubham/mpp/wallets branch from e5ac67d to c00679f Compare March 31, 2026 11:43
- EndpointHandler: inject wallets as metadata["wallets"] dict keyed by
  wallet_type, single batch get_by_ids query, no wallet type imports
- MppAccountingPolicy: read from metadata["wallets"]["mpp"] instead
  of flat keys
- PolicyRepository: add has_different_wallet() for same-wallet
  enforcement via single SQL query
- WalletRepository: add get_by_ids() for batch loading
@shubham3121 shubham3121 marked this pull request as draft March 31, 2026 14:07
@shubham3121 shubham3121 marked this pull request as ready for review April 5, 2026 16:34
@shubham3121 shubham3121 merged commit 3cc88c5 into main Apr 5, 2026
2 checks passed
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