refactor: extract wallet from marketplaces into standalone component with provider protocol #126
Merged
shubham3121 merged 10 commits intomainfrom Apr 5, 2026
Merged
refactor: extract wallet from marketplaces into standalone component with provider protocol #126shubham3121 merged 10 commits intomainfrom
shubham3121 merged 10 commits intomainfrom
Conversation
…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
e5ac67d to
c00679f
Compare
- 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
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.
This pull request introduces a major refactor of how wallet data is managed for payment and accounting policies, extracting wallet information from the
marketplacesandsettingstables into a new standalonewalletstable. 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:
walletstable to store wallet information, including wallet type, configuration, and linkage to tenants. Migrated relevant wallet data frommarketplacesandsettingsinto this new table, and linked existing payment policies to the appropriate wallet via a newwallet_idforeign key on thepoliciestable. Old wallet fields were removed frommarketplacesandsettings.AttachedPolicyschema to include an optionalwallet_idfield, allowing policies to reference a wallet directly.wallet_address,wallet_private_key) from theMarketplaceentity and eliminated wallet management methods from theMarketplaceHandlerand repository. [1] [2] [3] [4] [5] [6] [7]Endpoint and Handler Refactors:
EndpointHandlerto use aWalletRepositoryfor 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:
These changes modernize the wallet infrastructure, centralize sensitive data, and improve maintainability for future payment integrations.