Repository navigation
Add fiat wallet - #256
Draft
talvasconcelos wants to merge 13 commits into
Draft
Add fiat wallet #256talvasconcelos wants to merge 13 commits into
talvasconcelos wants to merge 13 commits into
Conversation
Model, services and migrations for booking cash settlement and fiat provider payments to the merchant's own fiat wallet: - `fiat_wallet_id` on `CreateTposData`/`Tpos` (never on `TposClean`) - `services_fiat.py`: canonical resolver (oldest non-deleted wallet in that currency) and idempotent find-or-create, so a user never gets a second fiat wallet per currency - `m027` adds the column; `m028` backfills cash/provider TPoS, reusing an existing wallet, disabling cash when no wallet can be assigned - `tests/test_fiat_wallet.py` covers backfill and resolution Not wired to payments yet: views_api/views_payments/tasks/UI follow.
Bumps the extension to 1.2.0 and gates installs on the LNbits release that ships fiat wallets and the fiat wallet currency argument.
- services_fiat: `resolve_tpos_fiat_wallet` implements R1-R12 — cash settlement is not gated, but setting/changing a `fiat_provider` requires the admin to have enabled card payments for the merchant (hard 400, checked before any wallet lookup); `get_valid_tpos_fiat_wallet` guards deleted/foreign/stale assignments for the payment path - views_api: refuse a fiat wallet as the TPoS wallet, drop the cash superuser gates, resolve the wallet on create and update - new endpoints: `GET /api/v1/wallets` (split wallets, no keys) and `POST /api/v1/fiat/wallets` (idempotent, 200 existing / 201 created) - tests: 7 API tests for the rules above; test helpers moved to the core >= 1.6 internal invoice queue and gained a shared `enable_stripe` fixture
- index.js: walletStatus from GET /tpos/api/v1/wallets, createFiatWallet() through the idempotent POST, explicit fiat_wallet_id on save, cash/provider form state cleared for sats, provider gate (R7c) in createOrUpdateDisabled - admin-form-dialog.js: main/tip wallet selects list lightning wallets only, fiat wallet row with create button, cash checkbox for every merchant, card-payments-disabled banner - e2e: admin dialog creates the fiat wallet and saves cash settlement, the public page shows the cash button; e2e server pins a small currency list
- README: new 'Cash Settlement & Fiat Wallet' section, feature bullet, quick link, LNbits 1.6.2 note, accounting-only/withdrawable-0 clarification - description.md: one bullet for the fiat wallet
- GET /tpos/api/v1/wallets now needs the admin key: it returns the account's whole wallet list (ids, names, balances), which an invoice key must not enumerate (core hides even its own wallet id from an inkey). The admin UI already sends the adminkey. - tests: cash validate credits the fiat wallet and keeps withdrawable_balance at 0 (headline acceptance), public page/manifest projection never carries fiat_wallet_id, a tampered foreign fiat_wallet_id is ignored (409), cash + unsupported currency is a 400, both wallet endpoints reject an invoice key.
Live browser review on /tpos/ (4 comments): - the fiat wallet row only shows once cash settlement is ticked or a fiat provider is picked (comment 3) - Create/Update stays disabled while a fiat-settling TPoS has no assigned wallet in its currency; an unchanged legacy provider row (R7b) keeps saving (comments 1 and 4) - a note under the cash checkbox names the required wallet/currency and turns orange until it exists (comment 2) - the wallet is auto-selected when one exists, re-picked on currency/provider change, and a stale/deleted id no longer counts as assigned - e2e covers the new gating (row hidden, button disabled, enabled after creating the wallet); README wording updated
Owner decision: the wallet belongs to the account/currency, not to TPoS, and every fiat-settling extension reuses it, so it is created as 'EUR' (renameable in LNbits) instead of 'TPoS EUR'. - services_fiat.create_user_fiat_wallet default name = currency (m028 backfill inherits it) - admin dialog wallet option shows the wallet name only (the sats balance there was misleading, review finding) - test asserts the default name; README + internal spec (D8, QA script) updated
The wallet is named after its currency (2e2a739) and clients rename it in LNbits, so the optional name on POST /tpos/api/v1/fiat/wallets (and the service parameter behind it) was dead weight.
Accounts own fiat wallets now and wallets are sorted by name, so 'EUR' sorts before the lightning wallet: superuserWallet() must not assume wallets[0] is a lightning one, or every later test creates a TPoS with a fiat key (400).
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.
Allow non super users to have cash settlement and fiat provider payments by making use of the receive only fiat wallet!