Repository navigation
fix(explore-dash): confirm a gift card's Dash price before the payment is signed - #1368
Merged
Merged
Conversation
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.
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: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.confirmAndSendHeadlesstakes an optional asyncvalidatehook 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) andDashSpendPriceUpdatedDialog.swift(the new sheet). The sheet's state moved from the screen intoDashSpendPayViewModel.SendCoinsService.sendCoinsis unchanged;payWithDashUrltakes 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?
DashWalletTestssuite on the iPhone 17 simulator (schemedashwallet-dashpay, Debug, arm64, built against develop's Platform pin) for8a1323b7e: 2922 tests, 0 failed, 1 skipped. The skip is the existingXCTSkipinPhraseRepairCandidateScanTests. The run was made on the tree one comment-only edit before the commit.a6c4a77e5adds the screen-teardown handling and three tests; on it the gift-card and BIP70 test classes were rerun locally (182 tests, 0 failed).DashWalletTests on simulatorcheck passed on2a8f5534b, which only swaps the warning box for the app's standard one. It passed again ond2a413127, which adds the single-start guard and three tests.9cf1cef11ends 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).b250aa1cechanges 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).39f1a0273adds the two-minute limit andd59504adethe 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).ac7858f9capplies the two-minute limit to a CTX payment request that states no expiry, with three more tests (200 tests, 0 failed locally).01bd8cf26holds the "Price updated" dialog to the sheet's height, with two layout tests (202 tests, 0 failed locally).7e472bcdfdoes 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 on7e472bcdfand it passed.7fe21df1bchanges 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).2a8f5534bwith local-only test patches), with a local server standing in for the provider's payment request so its amount could be set: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 nearUInt64.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.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.BIP70PaymentServiceTestsfor 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;payWithDashUrlruns the caller's check before the PIN prompt; overflowing outputs are malformed.scripts/a11y_audit.py --check: no new findings.scripts/ci/check_test_target_membership.pyandscripts/ci/check_no_old_swift_lookup.py: ok.07a2358famerges 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 useString(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
SystemMessageViewon 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.Reviewer suggestions not taken:
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.Follow-ups
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:
not needed: N1(a comparison and two constants local to the gift-card purchase path, reversible by changing a value)For repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit