Skip to content

fix(explore-dash): confirm a gift card's Dash price before the payment is signed - #1368

Merged
llbartekll merged 21 commits into
developfrom
claude/giftcard-payment-guards-5a38f7
Nov 25, 2026
Merged

llbartekll merged 21 commits into
developfrom
claude/giftcard-payment-guards-5a38f7

Conversation

@llbartekll

@llbartekll llbartekll commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

When buying a gift card, the buyer confirmed a price in USD ("You pay") and was never shown a Dash amount. The provider then names the Dash amount to send. The wallet did not compare that amount with the confirmed price, and for CTX it asked for the PIN before the payment request had been fetched.

What was done?

  • Dash amount on the Confirm sheet. The sheet shows the Dash amount the price comes to at the wallet's rate ("≈ 4.9370"), under the price and in the "You pay" row. The rate is read once, when the sheet opens; the price, discount and Dash amount shown are the ones the purchase uses.

  • The sheet waits for the provider. After Confirm the sheet stays open, the Confirm button shows a spinner and Cancel is disabled until the provider answers.

  • A higher price is put to the buyer again. The Dash amount a provider requests is compared with the confirmed one (GiftCardPaymentGuard.Approval.assess), for CTX and PiggyCards alike:

    • equal, lower, or higher by up to 0.5%: the sheet closes and the PIN is asked;
    • higher by more than 0.5% and less than 5%: a "Price updated" sheet shows what the buyer confirmed, what the provider asks and the difference, with Pay as the main button and Cancel;
    • higher by 5% or more: the same sheet with a "Final price" row and a warning; Cancel purchase is the main button and Pay the second one.

    There is no upper limit: the buyer decides. The amount on the Pay button is the provider's exact amount, not a rounded one. Cancelling, or swiping the sheet away, ends the purchase with nothing sent and no error dialog. So does the purchase screen going away (a sign-out closes it): a price change waiting for an answer is declined, and a provider's answer that arrives afterwards ends the purchase whatever its amount, with no PIN prompt.

  • Two minutes to accept a higher price on an order with no expiry. A PiggyCards order states no expiry, so the "Price updated" sheet could wait for an answer without limit before the order was paid. A higher price now has to be accepted within two minutes of the sheet coming up; Pay tapped later ends the purchase with the existing "This quote expired. Please go back and try again." message and nothing is sent. Declining late is a plain cancellation. A CTX payment request normally carries an expiry, which is checked again after the sheet; one that states none gets the same two minutes.

  • Both buttons stay in view on a short screen. The warning variant of the "Price updated" sheet, and the Confirm sheet when several card values are listed, are taller than an iPhone SE lets a sheet be, and the sheet cut them off at the bottom, where the second button is (Pay, or Cancel). Both dialogs are now held to the height the sheet has, through one shared view (DashSpendSheetBody): the details scroll and the two buttons stay below them. A dialog that fits is unchanged.

  • One purchase per confirmation. The purchase starts only for the confirmation the sheet is showing and only while none is running, so a second tap on Confirm, or a tap while the sheet animates away after Cancel, orders nothing.

  • PIN after the check (CTX). The headless payment flow fetches and verifies the payment request, runs the caller's check, and only then asks for the PIN. The check may wait for the buyer's answer. The prompt is asked for the request's amount, so the biometric spending limit applies as it does to other sends. The clock is read again after the fetch, after the check and after the prompt: a request that expires while it is fetched or while the buyer decides gets no prompt, and one that expires while the prompt is open is not sent. A signed request with no payment URL is refused once it is prepared, before the check and the prompt. BIP70PaymentService.confirmAndSendHeadless takes an optional async validate hook and holds no policy itself.

  • Exact PiggyCards amounts. The amount is accepted only when the whole string is ASCII decimal digits with at most one decimal point, and is converted to duffs exactly, without going through a binary floating-point value. An amount finer than one duff is refused instead of truncated.

  • Address check (PiggyCards). The payment address must be valid on the current network when the order response is parsed.

  • No usable rate, no purchase. If no exchange rate is available, the rate is zero, negative or not a number, or it is older than the app's existing stale-rate limit (30 minutes) or dated after the current time, the purchase stops when Pay is tapped, before the Confirm sheet opens. If the rate goes stale while the sheet is open, Confirm stops it before an order is created. The order is created for the card value the buyer confirmed, and the stored gift card records that value.

  • A request for no Dash is refused as an invalid gift card amount. A payment request whose outputs do not sum within the amount range is reported as malformed.

  • New files: GiftCardPaymentGuard.swift (the confirmed price, the two thresholds, the comparison and the conversions) and DashSpendPriceUpdatedDialog.swift (the new sheet). The sheet's state moved from the screen into DashSpendPayViewModel. SendCoinsService.sendCoins is unchanged; payWithDashUrl takes the caller's check and holds no policy of its own.

  • Twelve new texts, in the String Catalog (DashWallet/Localizable.xcstrings) in English only. The expired-quote message is an existing text. "Gift card amount is out of range" is no longer used and is marked stale there.

Earlier heads of this PR refused a request more than 5% above the confirmed price outright. That refusal is replaced by the "Price updated" sheet, following the updated design.

How Has This Been Tested?

  • Full DashWalletTests suite on the iPhone 17 simulator (scheme dashwallet-dashpay, Debug, arm64, built against develop's Platform pin) for 8a1323b7e: 2922 tests, 0 failed, 1 skipped. The skip is the existing XCTSkip in PhraseRepairCandidateScanTests. The run was made on the tree one comment-only edit before the commit. a6c4a77e5 adds the screen-teardown handling and three tests; on it the gift-card and BIP70 test classes were rerun locally (182 tests, 0 failed).
  • CI: the DashWalletTests on simulator check passed on 2a8f5534b, which only swaps the warning box for the app's standard one. It passed again on d2a413127, which adds the single-start guard and three tests. 9cf1cef11 ends a purchase whose screen is gone whatever the quote and passes the amount to the prompt, with three more tests; on it the gift-card and BIP70 test classes were rerun locally (189 tests, 0 failed). b250aa1ce changes tests only: every wait in the purchase sheet tests is bounded, so a regression fails the test instead of hanging the suite (same 189 tests, 0 failed locally). 39f1a0273 adds the two-minute limit and d59504ade the early refusal of a signed request with no payment URL, with eight more tests; on them the gift-card and BIP70 test classes were rerun locally (197 tests, 0 failed). ac7858f9c applies the two-minute limit to a CTX payment request that states no expiry, with three more tests (200 tests, 0 failed locally). 01bd8cf26 holds the "Price updated" dialog to the sheet's height, with two layout tests (202 tests, 0 failed locally). 7e472bcdf does the same for the Confirm dialog and moves the layout into one view, with two more layout tests (204 tests, 0 failed locally). The full suite was not rerun locally for these five commits; CI ran it on 7e472bcdf and it passed. 7fe21df1b changes tests only: the default rate in the purchase sheet tests is stamped with the injected clock, which removes a failure across a second boundary (204 tests, 0 failed locally).
  • Run in the app on a simulator (testnet, a build of 2a8f5534b with local-only test patches), with a local server standing in for the provider's payment request so its amount could be set:
    • amount as confirmed: the Confirm sheet showed the Dash amount, then the spinner with Cancel disabled, closed, and the PIN prompt followed; the payment was built, posted and broadcast on testnet;
    • amount 3% higher: the sheet changed in place to "Price updated" with the three rows; Pay led to the PIN prompt and the payment went out for the higher amount;
    • amount 10% higher: the warning variant; "Cancel purchase" and a swipe down each ended the purchase with no prompt, no error and nothing sent; the second Pay button led to the PIN prompt;
    • a provider error while the sheet waited (CTX staging refused the order) closed the sheet and showed "Purchase Failed".
  • GiftCardPaymentGuardTests (47 tests): the confirmed price for a usable rate and for a missing, zero, negative, not-a-number, stale and future-dated rate; a quote equal to, below, 0.5% above, one duff over 0.5%, just under 5%, at 5% and far above the confirmed amount, a quote for no Dash, small amounts and values near UInt64.max; the figures a price change carries; exact, sub-duff, zero, negative and too-large amounts; amount strings with trailing text, a repeated decimal point, a grouping comma or a digit followed by a combining mark; rate age; how the sheets write Dash amounts and the increase in percent, rounded down; the answer limit for a payment request with and without an expiry.
  • DashSpendPayApprovalTests (27 tests): for every provider the Confirm sheet does not open without a usable rate; it opens with the Dash amount at the wallet's rate; a rate gone stale stops the purchase before the provider is asked; a second start for the same confirmation, a Confirm after Cancel and a confirmation no longer on screen start nothing; a quote as confirmed or 0.3% higher closes the sheet without asking; a higher quote waits for the buyer and goes on when they pay; a quote 5% higher carries the warning; declining, or dismissing the sheet, cancels the purchase; closing the screen declines a waiting price change; a quote that arrives after it, as confirmed or higher, ends the purchase; so does the screen closing while the sheet leaves; a purchase begun after the screen was last reported gone goes on, and a price change that arrives once the screen is back is shown; a quote for no Dash is refused without asking; with a time limit, a higher price accepted at the limit goes on, one accepted a second past it ends the purchase with the expired-quote message (also with the limit a payment request without an expiry is given), one declined past it is a cancellation, and a quote that needs no answer is not timed; without a limit the answer may come at any time.
  • DashSpendPurchaseSheetLayoutTests (4 tests): the warning variant of "Price updated" and the Confirm dialog with several card values take no more height than their limit, and each dialog below the limit keeps its natural height.
  • The "Price updated" dialog was measured at the default text size: the warning variant is 650 pt tall at 375 pt wide (670 at 320, 630 at 393), the plain variant 434 pt; the sheet adds 92 pt, and a 667 pt screen allows a 634 pt sheet. The Confirm dialog is 524 pt, and 610 pt with three card values. The warning variant and the Confirm dialog with three card values were rendered inside the sheet's chrome at 375 x 634 pt: both buttons are fully in view and the part above them scrolls to its end.
  • PiggyCardsPaymentURITests (9 tests): the payment URI's amount, a missing or zero amount, an amount with a combining mark, a sub-duff amount, and an address for another network.
  • Eleven tests in BIP70PaymentServiceTests for the headless flow: the request is fetched before the PIN is asked for; a passing check lets the send go ahead and the prompt is asked for the request's amount; a refused request ends the flow with no PIN prompt and nothing built or posted; an expired request never reaches the check; a request that expires while it is fetched, or while the caller's check waits, gets no PIN prompt; a request that expires while the PIN prompt is open is not sent; a signed request with no payment URL reaches neither the caller's check nor the prompt, and an unsigned one with no payment URL goes on; payWithDashUrl runs the caller's check before the PIN prompt; overflowing outputs are malformed.
  • The Confirm sheet (idle and waiting) and both variants of the "Price updated" sheet (light, and the warning variant in dark) were rendered on the simulator from the real views and compared with the design by eye.
  • scripts/a11y_audit.py --check: no new findings. scripts/ci/check_test_target_membership.py and scripts/ci/check_no_old_swift_lookup.py: ok.
  • 07a2358fa merges develop, which moved the app's texts to one String Catalog (feat(ui): move the main app's texts to one String Catalog #1455). The old string lists stay deleted, the lookups in this PR's files use String(localized:), and the Catalog was written by the Debug build's sync phase. On the merged tree: the build succeeds, the gift-card and BIP70 test classes pass (204 tests, 0 failed), and the String Catalog tools' own tests pass. The full suite was not rerun locally; CI runs it.

Not tested / open

  • The biometric spending limit on a CTX purchase was not run in the app; the amount reaching the prompt is covered by a unit test.
  • The two-minute limit bounds how long a PiggyCards order waits for its payment; it does not confirm that the order is still open. How long PiggyCards keeps an unpaid order open is not known, and two minutes is the PIN prompt's own timeout, not a provider value. The limit was not run in the app (PiggyCards has no testnet path), and that the PiggyCards path and the CTX path for a request without an expiry pass it is read from the code, not tested: the provider repository is not injectable (Gift card purchase: no test covers that each provider path compares the requested Dash amount #1456). Whether CTX ever sends a request without an expiry is not known. Rechecking the order's status before paying is left to Gift card purchase: a purchase that ends after the order was created leaves the order open at the provider #1458.
  • The short-screen layout was rendered in a window of an iPhone SE's size, not seen in a presented sheet or on a short device. Accessibility text sizes were not measured. On a phone about 812 pt tall (iPhone 12/13 mini) the warning variant fits by the numbers with little to spare; not checked on one.
  • The height limit is taken from the display, and the sheet's own cap from the window. In a window shorter than the display (iPad Slide Over or Stage Manager) the buttons can still be cut off, as they could before the limit. (Gift card sheets: compare spacing, colours and texts with the design #1459)
  • No real CTX or PiggyCards purchase was made. On testnet the app talks to CTX staging, which refused to create an order ("no discounts are currently available for this merchant"), so the provider's answer in the app run above came from a local stand-in. A real provider quote has not been seen. PiggyCards has no testnet path.
  • How often the "Price updated" sheet appears is not known. The 0.5% margin that is paid without asking again is a judgment call, not calibrated against live provider quotes.
  • The rate the amount is compared with is the wallet's own rate feed. For CTX that feed and the quote come from the same provider, so the comparison is with that provider's published rate, not with a third party's. The buyer now sees and confirms the Dash amount. For PiggyCards the two come from different companies.
  • PiggyCards purchases depend on the wallet's rate feed too, and that feed is fetched from CTX: while it is unavailable for more than 30 minutes, purchases from both providers stop.
  • The 30-minute rate limit reuses the app's existing stale-rate constant. It has not been observed in a real outage of the rate service; while one lasts longer than 30 minutes, gift card purchases stop.
  • The layout follows a screenshot of the design, built from the app's existing components and colour tokens (the warning is DashUIKit's SystemMessageView on the app's caution yellow). Exact spacing was not read from Figma. Two deliberate differences: the provider's amount is written in full (up to eight decimals) where the design shows four, and both variants of the sheet show the same three rows.
  • The warning text on the design had typing errors; the text here is: "This can mean the market moved fast or the provider's price is wrong. If you're not sure, cancel and try again in a few minutes."

Reviewer suggestions not taken:

  • A test that each provider path compares the provider's amount. The rate reader and the BIP70 service are injectable and tested, and the comparison both paths call (confirmQuote) is tested, but the provider repositories and the send service are still shared instances in the view model; making them injectable is a refactor beyond this change.
  • Comparing the provider's fiat amount and discount with the confirmed price. It adds a second acceptance rule, and what those fields hold for a discounted order has not been confirmed against a live response.
  • A second rate source for CTX. It adds a network dependency to every purchase and needs a rule for when the two rates disagree or one is unavailable. A product decision.
  • Stopping a payment request download at the size limit. The transport is unchanged here and buffers the same way on the interactive BIP70 path; the 50 KB check still runs before the body is parsed.

Follow-ups

  1. Make the provider repositories and the send service injectable and test the purchase flow end to end with controllable provider responses. (Gift card purchase: no test covers that each provider path compares the requested Dash amount #1456)
  2. Unsigned payment requests are accepted as before. Whether gift-card payments should require a signed request is not decided here. (Gift card purchase: decide whether a payment request must be signed #1464)
  3. A PiggyCards amount finer than one duff is now refused; confirm PiggyCards never quotes one. (PiggyCards: a Dash amount finer than one duff is refused after the order has been created #1457)
  4. A declined price leaves the provider's order open; the app has no call to cancel one. (Gift card purchase: a purchase that ends after the order was created leaves the order open at the provider #1458)
  5. Decide whether a CTX quote should also be compared with a rate from a second source. (Gift card purchase: decide whether a CTX quote is also compared with a rate from a second source #1465)
  6. Stop a payment request download once it passes the size limit. (Payment requests: stop the download once it passes the size limit #1466)
  7. Read the exact spacing, colours and texts of the two sheets from Figma. (Gift card sheets: compare spacing, colours and texts with the design #1459)

Also tracked: no real provider purchase (#1460), the 0.5% margin (#1461), a rate outage (#1462), the provider's fiat amount and discount (#1463). Two older problems in the same flow, raised in review: #1467 and #1468.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • ADR (ADR-0001): not needed: N1 (a comparison and two constants local to the gift-card purchase path, reversible by changing a value)
  • Nothing in this PR (files, commit messages, branch name, description, comments, attachments, linked issues) holds customer data, unfixed vulnerability detail, secrets, or step-by-step attack detail against keys, PIN or encryption; such content is left out and handled privately with the maintainers (ADR-0001, rule 2)

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Gift-card purchases now show the confirmed total and approximate Dash amount, with a review step if the provider’s quoted price changes. Buyers can approve or cancel the updated price.
    • The purchase flow displays a waiting state while the provider responds and warns when a price increase is substantial.
  • Bug Fixes
    • Purchases use the price confirmed by the buyer and are checked against a fresh exchange rate before payment.
    • Invalid payment addresses and unapproved price increases prevent payment from proceeding.
    • Payment requests are checked before authorization, rechecked for expiry, and rejected if their total amount overflows.

Loading
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