Skip to content

feat(flashcard): set or change the Cashu card PIN with one tap - #746

Merged
islandbitcoin merged 4 commits into
mainfrom
jabariennis/eng-616-change-pin
Sep 30, 2026
Merged

islandbitcoin merged 4 commits into
mainfrom
jabariennis/eng-616-change-pin

Conversation

@islandbitcoin

@islandbitcoin islandbitcoin commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Second of the ENG-616 (Flashcard v2) PRs. Stacked on #745: the diff here is only the PIN work, and GitHub retargets it to main when #745 merges. Still moves no money, but it is the first change that writes to the card, so it introduces the door every later write goes through.

Rebased onto #745 after its review rounds (force-pushed 2026-09-27). #745's review deleted the card-event ledger, keyed the PIN copy on the firmware version (ENG-615), added an "unknown" PIN state, and made card records signed-in only. This PR now follows all four. The changes against the original PR are listed at the end, followed by this PR's own review fixes.

What it does

A card ships with no PIN, and until one is set anyone holding it can spend from it or load it. The card screen already says so; this gives that notice an action:

  • Set PIN on a card with none, Change PIN on a card with one. Nothing on a blocked card (no unblock path exists: ENG-617), and nothing on a card whose PIN state the app cannot read.
  • Current PIN (change only) → new PIN → confirm → one tap. After a wrong entry the screen says how many tries are left and what happens when they run out, which depends on the firmware (below).
  • The PINs live in the screen's local state and nowhere else. Nothing is stored, and the spec asserts that no message carries the digits.
  • Set PIN and Change PIN sit with Remove card behind sign-in, as in the original PR. The card screen spec asserts neither shows when signed out.

What a blocked PIN means, per firmware

On v0.2.0 (every card in the field today), a blocked PIN stops being checked: three wrong entries switch the PIN check off and anyone holding the card can spend from it (ENG-615, fixed in cashu-javacard#25 as applet 0.3). The copy follows #745's blockedPinGatesSpend(version):

v0.2.0 (and any version not confirmed fixed) a version confirmed to freeze once blocked
wrong current PIN (63C2) "Wrong PIN. Tries left before the PIN check switches off: 2." "Wrong PIN. Tries left before the card blocks: 2."
6983, and the re-read after it says blocked (or the card left before the re-read) "The PIN has been entered wrong too many times, and on this card's software that switches the PIN check off: anyone holding the card can spend its balance. Move the value off it." "The PIN has been entered wrong too many times. The card is blocked and must be replaced."
6983, and the re-read still says set "…The card is blocked and must be replaced." (cannot happen: 0.3 sets state 2 on every exhausting check)
63C0 "…The card is blocked and must be replaced." (0.3 never sends it)
set-PIN warning "…three wrong entries in a row switch the PIN check off." "…three wrong entries block the card for good…"

Why the last two rows freeze on v0.2.0: 63C0 only ever comes from v0.2.0's CHANGE_PIN spending the last try, and that path never sets the blocked state ([email protected]:555-559). VERIFY_PIN then answers 6983 at entry (:508) while state 1 keeps every gated command refusing (:587-591), so the card is frozen for everyone, and GET_INFO still says "set". A 6983 with a re-read that still says "set" is that same card. This screen verifies first, so it never produces either itself; another reader can. The blocked copy does not say "that was the last try", because a card blocked before this tap answers the same 6983.

A blocked PIN ends the flow on this screen: the whole message stays in the status area (announced to a screen reader), the pad and Continue give way to Close, and Close goes back to the card, which the re-read after the refusal has already switched to #745's blocked notice. (A toast shows two ellipsized lines, which cut the v0.2.0 message before "anyone holding the card can spend its balance. Move the value off it.")

No version is on the confirmed list yet; "0.3" goes on it once cashu-javacard#25 ships (a #745 follow-up).

Change also verifies the current PIN with VERIFY_PIN before CHANGE_PIN, in the same session. On v0.2.0 that matters: CHANGE_PIN's own failed checks burn tries without ever marking the PIN blocked, which would freeze the card for its owner while GET_INFO still reports "set".

Other outcomes on the PIN screen

What happened What the holder sees Then
6985 on SET_PIN "This card already has a PIN. Change it instead." (the re-read switches the card screen to Change PIN) back to the new PIN
6986 (a card someone ran LOCK_CARD on) "This card is locked against changes, so its PIN can't be set or changed." back to the first step
any other refusal "The card refused the change. Try again." The status word goes to a console.warn with the error name, never to the screen back to the first step
a tag without the applet (a BoltCard, a bank card) "That isn't a Cashu card. Tap the card this screen is showing." PINs kept: only the confirmation is retyped
a different Cashu card "That is a different card. Tap the card this screen is showing." PINs kept
the sheet cancelled before any PIN command went out (Android or iOS) nothing: no error (as flash-pos treats a cancel) PINs kept
tap lost before any PIN command "No Cashu card found. Hold the card steady and try again." PINs kept
tap lost during VERIFY_PIN "No Cashu card found. Hold the card steady and try again." back to the current PIN: a wrong one may have cost a try
tap lost after CHANGE_PIN went out "The tap was cut short while the card was saving the new PIN. It may already use the new PIN: try the new one first." back to the current PIN
tap lost after SET_PIN went out "The tap was cut short while the card was saving the PIN. It may already use this PIN: confirm it and tap the card again to finish." new PIN kept: only the confirmation is retyped
then the same PIN again, answered 6985 "PIN set. The card saved it during the tap that was cut short." back to the card, which offers Change PIN

SET_PIN saves the PIN before it answers ([email protected]:538-539; 0.3: 574-575), so a lost answer may hide a PIN the card already holds. The retry settles it: 9000 sets the PIN, and a 6985 to the only PIN a cut-short tap carried means the earlier write landed. That tap counts as a success, so the card is re-read (or assume applies when it leaves first) and the card screen stops offering Set PIN. A different PIN still gets "already has a PIN", and after two cut-short taps with different PINs a 6985 claims neither. The one case this can't tell apart without spending a VERIFY_PIN try is a card that got a PIN from another reader after the card screen read it and whose answer to the first tap was also lost.

A cancel that cuts off a PIN command counts as a lost answer, not a quiet cancel: a quiet retry after a CHANGE_PIN that landed would verify the old PIN and spend a try. Android never reports a cancel on a connected tag as UserCancel (react-native-nfc-manager 3.17.2 NfcManager.java:113-125; the next transceive fails with "no tech request available"), so the guard covers iOS, where an in-flight command's error carries CoreNFC's code.

One deliberate deviation from the plan

The ticket said "do not expose SET_PIN". I've exposed it for the unset case only. The applet's default is no PIN, and nothing in the provisioning chain sets one today, so a consumer card nobody can PIN is a bearer card by accident. SET_PIN is one-way (a PIN can be changed but never removed) and the screen says exactly that before the first entry. LOCK_CARD stays out.

runCardOperation: the write path

New on FlashcardProvider, alongside readFlashcard. Its shape is ported from flash-pos's executeCharge:

  1. IsoDep-only session (never NDEF), one per call.
  2. Raise Android's 618 ms transceive timeout to 5 s. An on-card operation can outlive the default, and flash-pos watched burns die at 0.6 s on a card that never moved and still burn their slot. iOS has no such knob.
  3. SELECT on the fresh channel (a new IsoDep channel resets the active applet; without this Android answers 6E00).
  4. GET_PUBKEY, compared with expectedPubkey, the card the screen is showing, so a PIN can't land on a different card. expectedPubkey is required.
  5. Run the operation, then re-read GET_INFO + GET_BALANCE so context shows the card as it now is. Signed in, the card's record in the store is updated too; signed out the re-read stays in memory, as a tap's does (feat(flashcard): Cashu card screen — read the card, remember it, show it #745's rule). Only the card on screen is updated.
  6. The re-read is best effort. Once the operation has succeeded, its result is returned even if the card leaves before the re-read: a PIN change that landed must never come back as a failure, or the holder retypes the old PIN and spends tries on it. The caller passes what a success proves (assume: { pinState: "set" } for both PIN commands), and that is applied when the re-read is lost.
  7. A card that refused the operation is re-read too, because a refusal can change the card: the third wrong PIN blocks it. The refusal is then rethrown unchanged, and the caller gets what the re-read said through onReread. A different card, a tag without the applet, or a lost channel gets no re-read.
  8. If the operation moved value, drop the tap's keyset split and the mint's per-unit figures in context, and the mint's unit on the card's record: the screen shows the new total as "unit unknown" until the next read. A mint answer that arrives late for the old split is ignored in context and in the store. (No operation in this PR moves value; load and spend will.)
  9. Release exactly once, on every path; every failure is rethrown after the release. The caller owns the message.

Load and spend will call this same function.

Codec

SET_PIN 0x41, CHANGE_PIN 0x42 (oldLen ‖ old ‖ new, after VERIFY_PIN in the same session), both behind #745's 4–8 ASCII-digit check so nothing malformed reaches the card, and triesLeft for 63CX. The PIN pad is ported from flash-pos so the two apps ask the same way.

Accessibility

The step title, the masked entry and the error use plain testIDs, not testProps (which labels an element with its id, so a screen reader said "pin-error"). The title is a header; the entry reads "Digits entered: 3"; the pad keys are buttons read as their digit, "Clear" or "Delete". The error area is a live region on Android and is announced on iOS; a blocked-PIN outcome is announced before the screen closes.

Tests

  • Codec: both commands byte for byte, validation refusing before any APDU, the card's own refusals (6985 already set, 6982 unverified, 63C1).
  • runCardOperation against the provider harness: session shape and APDU order; on Android, the timeout raised after requestTechnology and before the first APDU; the identity check refusing a different card with the op never called and nothing re-read; a refusal re-read and rethrown as the same error; three wrong PINs against a scripted v0.2.0 card (63C2, 63C1, 6983) leaving the card "blocked" in context and on its record; no re-read after a lost channel or a tag without the applet; a card that leaves after a successful op still resolving with the op's result, released once, with assume applied and the lost re-read logged by error name only; release-once on every path; signed out, nothing reaches the store; per-unit figures and the record's unit kept by an op that moves no value, dropped by one that does, and not restored by a late mint answer.
  • The PIN screen: change and set flows down to the exact APDUs and the assume they pass, too-short entry, mismatch, same-as-current, and no PIN digit in any message. Wrong PIN and every blocked-PIN case (6983 re-read blocked, re-read set, no re-read; 63C0) under both firmware behaviours, including the flow ending on this screen with the full message, no pad, no toast, and the card screen only on Close. One case per other failure (6985, 6986, other refusal, not a Cashu card, different card, cancel, tap lost before SET_PIN, during VERIFY_PIN and after CHANGE_PIN), each with the step it returns to; after a failure before any PIN reached the card, the next tap sends the same PINs. A tap cut short after SET_PIN: the new PIN kept, then the retry against a scripted card (6985 to the same PIN is the PIN set, with assume passed; 9000 is a plain set; a different PIN, two cut-short PINs, or a 6985 with no cut-short tap before it get "already has a PIN"). A cancel that cuts off SET_PIN or CHANGE_PIN handled as a lost answer. Screen-reader labels, and each success (change, set, earlier set) announced.
  • The card screen: Set PIN / Change PIN per PIN state, opening the PIN screen in the right mode; no PIN action on a blocked or unknown card, or when signed out (with or without a PIN).
  • Android timeout helper.
  • Each new test was checked against a mutant of the code it guards (24 mutants in round 1 and 14 in round 2, all caught), including deleting the timeout step and rendering the PIN action outside the sign-in gate.
  • Full suite 147 suites / 1640 tests; tsc clean; changed-lines lint, prettier, translation drift and check:translations clean.

Changes against the original PR (from the rebase)

Review fixes (round 1)

  • A lost re-read after a successful operation no longer turns it into a failure (it made a landed PIN change look failed, and the holder then burned tries on the old PIN); assume covers the lost re-read.
  • A refused operation is re-read, so three wrong PINs leave the card "blocked" in context and in the store, and the card screen stops showing the "set" notice and Change PIN on a blocked card. A blocked-PIN outcome ends the PIN flow.
  • 63C0 now says "blocked and must be replaced" on every firmware (it only ever means v0.2.0's frozen card); 6983 takes its copy from the re-read; neither claims this tap spent the last try.
  • Plain copy for a tag without the applet, for 6986, and for any other refusal (no developer text or status word on screen); a cancel keeps the PINs; a tap lost after CHANGE_PIN says the new PIN may already be in use.
  • Screen-reader labels (above).
  • expectedPubkey is required.
  • A late mint answer no longer writes a unit to the record for a split an operation already dropped, and an operation that moves value clears the record's unit.
  • Tries-left copy no longer needs a plural ("Tries left before the card blocks: 1.").
  • New strings (notCashuCard, cardLocked, cardRefused, pinChangeUncertain, pinEntered, pinPadClear, pinPadDelete) and the reworded ones fanned to all 23 locales.

Review fixes (round 2)

  • A tap cut short after SET_PIN went out no longer says "No Cashu card found" and sends the holder back to pick a PIN. It says the card may already use the PIN, keeps it, and the retry settles it (table above). Before, a holder who picked a different PIN on the retry got "Change it instead" while the card held the first PIN, and three wrong guesses at that PIN switch the PIN check off on v0.2.0.
  • A failure before any PIN reached the card (a different card, a tag without the applet, a tap lost before VERIFY_PIN or SET_PIN) keeps the PINs typed and asks only for the confirmation, as a cancel already did. A wrong current PIN, a refusal, or a lost answer after a PIN command went out still start over.
  • A cancel that cuts off a PIN command is a lost answer (above).
  • The card screen spec asserts the PIN action is hidden when signed out.
  • New strings pinSetUncertain and pinSetEarlier fanned to all 23 locales.

Review fixes (round 3)

  • The last-try outcome no longer goes into a toast, which cut the message at two lines; the flow ends on this screen with Close (above).
  • Success is announced to a screen reader before the screen goes back; a toast alone is never read out.

Full suite 147 suites / 1640 tests; tsc, changed-lines lint, prettier and check:translations clean.

Device check owed

Both phones, a real card, TEST backend. On a fresh card: Set PIN, confirm the card screen flips to the set-PIN notice on return, and that a spend-side command now demands the PIN (cardctl or the POS). On a PIN card: change it, enter the wrong current PIN once and confirm "Tries left before the PIN check switches off: 2." (v0.2.0 card), then the right one. On a spare card, enter the wrong current PIN three times and confirm the whole blocked message shows on the PIN screen with a Close button, and that Close leads to the card screen's blocked notice with no Change PIN. Tap a different card at the apply step and confirm it's refused with only the confirmation to retype; tap a BoltCard and confirm "That isn't a Cashu card". Cancel the sheet at the apply step and confirm only the confirmation needs retyping and the next tap works (no stranded session). Pull the card away just as the change applies and follow the "may already use the new PIN" message. On a fresh card, pull it away just as a new PIN is set and follow the "may already use this PIN" message: the next tap should end on "PIN set" and the card screen should offer Change PIN. Kill the app mid-tap. With TalkBack and VoiceOver on, confirm the pad keys, the entry count, a wrong-PIN error and the success message are read as words.

🤖 Generated with Claude Code

@linear

linear Bot commented Sep 27, 2026

Copy link
Copy Markdown

ENG-616

Dread and others added 4 commits September 30, 2026 16:31
Second of the ENG-616 PRs, stacked on the card screen. Still moves no
money; it is the first change that writes to the card.

A card ships with no PIN, and until one is set anyone holding it can spend
from it or load it. The card screen already says so; this PR gives that
notice an action. "Set PIN" appears on a card with none, "Change PIN" on a
card with one, and neither on a blocked card, which has no way back
(ENG-617), or on a card whose PIN state the app cannot read. SET_PIN is a
one-way door (a PIN can be changed but never removed, and the screen says
that before the first entry), so the plan's "do not expose SET_PIN" is
deliberately overridden for the unset case: a consumer card that nobody
can PIN is a bearer card by accident.

The flow: current PIN (change only), new PIN, confirm, then one tap. All
three stay in the screen's local state and nowhere else: nothing is
stored, and the spec asserts no message carries the digits. Inside the tap
the provider's new `runCardOperation` opens an IsoDep-only session, raises
Android's 618 ms transceive timeout (an on-card operation can outlive it,
and flash-pos watched burns die and still burn), SELECTs the applet on the
fresh channel, checks GET_PUBKEY against the card the screen is showing so
the PIN never lands on a different card, runs VERIFY_PIN + CHANGE_PIN (or
SET_PIN alone), re-reads the card so context shows the new PIN state, and
releases exactly once whatever happened. This is the door every later
card-changing flow (load, spend) goes through. It keeps the card screen's
rules: signed out, the re-read stays in memory and nothing reaches the
store; and an operation that moved value drops the tap's keyset split and
the mint's per-unit figures rather than show them beside a new total, and
a late mint answer cannot bring them back.

Verifying before CHANGE_PIN also matters on v0.2.0 firmware, where
CHANGE_PIN's own failed checks burn tries without ever marking the PIN
blocked, freezing the card for its owner too.

Errors say what the card said and what the card now does. A wrong current
PIN reports the tries left (63CX). What the last try means depends on the
firmware (`blockedPinGatesSpend`): a card confirmed to freeze once blocked
is reported blocked; on v0.2.0, where three wrong entries switch the PIN
check off (ENG-615), the screen says that instead, and so does the set-PIN
warning. A different card is named as such; a cancelled or lost tap says
to try again. The PIN pad is ported from flash-pos so both apps ask the
same way.

Codec: SET_PIN 0x41 and CHANGE_PIN 0x42 (oldLen ‖ old ‖ new), behind the
card screen's 4-8 ASCII-digit check so nothing malformed reaches the card,
and `triesLeft` for 63CX.

Tests: the two commands byte for byte; `runCardOperation` against the
provider harness (session shape, identity check, re-read, release on every
path, signed out, the split kept or dropped); the PIN screen through every
step and every failure under both firmware behaviours; the PIN actions on
the card screen per PIN state; the Android timeout helper. 23 locales
updated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
runCardOperation no longer lets its re-read decide the outcome. Once the
operation has succeeded, a card that leaves before GET_INFO/GET_BALANCE
no longer rejects the call: the result stands, the lost re-read is
logged by error name only, and what the operation proves (the caller's
`assume`, `pinState: "set"` for both PIN commands) is applied instead.
Before, a CHANGE_PIN that had landed came back as "No Cashu card found",
and the holder then retyped the old PIN into 63C2, 63C1, 6983.

A card that refused the operation (a CardError other than a failed
SELECT) is re-read too, before the refusal is rethrown unchanged. The
third wrong PIN now leaves the card "blocked" in context and on its
record, so the card screen shows #745's blocked notice and no Change PIN
button. A different card or a lost channel gets no re-read. The caller
learns what the re-read said through `onReread`. `expectedPubkey` is
required: the identity check always runs.

The PIN screen maps outcomes against the firmware (CashuApplet.java at
v0.2.0 and applet 0.3):
- 63C0 says "blocked and must be replaced" on every firmware. It only
  ever comes from v0.2.0's CHANGE_PIN spending the last try, which never
  sets pinState 2 (:555-559), so the card is frozen, not open.
- 6983 takes its copy from the re-read: pinState 2 follows
  blockedPinGatesSpend, pinState 1 is v0.2.0's frozen card, and no
  re-read falls back to the firmware. The copy no longer claims this tap
  spent the last try, since a card blocked earlier answers the same.
- A blocked PIN ends the flow on a toast, announced, back to the card.
- A tag without the applet, 6986 (LOCK_CARD) and any other refusal get
  plain words; the status word goes to a console.warn, never the screen.
- A cancelled sheet (NfcError.UserCancel) shows no error and keeps the
  current and new PINs, as flash-pos does.
- A tap lost after CHANGE_PIN went out says the new PIN may already be
  in use and to try it first.

Accessibility: plain testIDs replace testProps on the step title, entry
and error (a screen reader said "pin-error"); the title is a header, the
entry reads "Digits entered: N", pad keys are buttons read as the digit,
"Clear" or "Delete"; the status area is a live region on Android and
errors are announced on iOS.

A late mint answer no longer writes a unit to the record for a split an
operation already dropped (the provider keeps a ref of the card and
checks it), and an operation that moves value clears the record's unit.

Tries-left copy no longer needs a plural. Seven new strings and four
reworded ones fanned to all 23 locales.

Tests: the Android timeout wired between requestTechnology and the first
APDU (the shared NFC mock gains setTimeout and NfcError); a refusal
re-read and rethrown as the same error; three wrong PINs against a
scripted v0.2.0 card ending "blocked" in context and store; no re-read
after a wrong card, a lost channel or a failed SELECT; a lost re-read
after a successful op; the record's unit kept or cleared; one screen
case per failure branch, every blocked-PIN case under both firmware
behaviours, and screen-reader labels. Each checked against a mutant of
the code it guards (24 mutants, all caught). Full suite 147 suites /
1630 tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er saw

Review fixes on the Cashu card PIN flow (ENG-616).

- A tap cut short after SET_PIN went out said "No Cashu card found" and
  sent the holder back to pick a PIN, though SET_PIN saves the PIN before
  it answers ([email protected]:538-539; 0.3: 574-575). It now says
  the card may already use the PIN, keeps it, and asks only for the
  confirmation. The retry settles it: 9000 sets it, and a 6985 to the only
  PIN a cut-short tap carried means the earlier write landed, so the tap
  counts as a success (re-read, or `assume` when the card leaves first)
  and the card screen offers Change PIN. A different PIN still gets
  "already has a PIN"; after two cut-short taps with different PINs a
  6985 claims neither.
- A failure before any PIN reached the card (a different card, a tag
  without the applet, a tap lost before VERIFY_PIN or SET_PIN) keeps the
  PINs typed and asks only for the confirmation. A wrong current PIN, a
  refusal, or a lost answer after a PIN command went out still start over.
- A cancel that cuts off a PIN command is a lost answer, not a quiet
  cancel: a quiet retry after a CHANGE_PIN that landed would verify the
  old PIN and spend a try.
- The card screen spec asserts the PIN action is hidden when signed out.
- New strings pinSetUncertain and pinSetEarlier in all 23 locales.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cess

Round-3 review findings on the PIN flow.

The outcome that ends the flow (the last try: a PIN switched off on
v0.2.0 firmware, or a frozen card) went into a toast, and this app's
toasts show two ellipsized lines in a fixed box. The 177-character v0.2.0
message lost its last sentence, "anyone holding the card can spend its
balance. Move the value off it.", which is the part that matters, and the
frozen copy lost "replaced". When the card left before the re-read, the
card screen could not make up for it. The flow now ends on this screen:
the whole message stays in the status area (a live region on Android,
announced on iOS), the pad and Continue give way to Close, and the card
screen shows only when the holder presses it.

Success went only to a toast, which is never announced, so a TalkBack or
VoiceOver user heard nothing, including after the retry that finishes a
cut-short SET_PIN. The screen now announces the same message before it
goes back.

Specs: every last-try case asserts the full message on screen, no pad,
no toast, and goBack only on Close; the change, set and earlier-set
successes assert the announcement. Reverting either fix fails them (9 and
3 cases).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@islandbitcoin
islandbitcoin changed the base branch from jabariennis/eng-616-flashcard-v2-cashu-card-screen-balance-top-up-pin-sweep to main September 30, 2026 20:32
@islandbitcoin
islandbitcoin force-pushed the jabariennis/eng-616-change-pin branch from 4e53f42 to b4abe2a Compare September 30, 2026 20:32
@islandbitcoin
islandbitcoin merged commit 105bb30 into main Sep 30, 2026
10 checks passed
islandbitcoin pushed a commit that referenced this pull request Oct 9, 2026
Mirror the five new FlashcardV2 keys (slotsSpentNote, topUpSlotsReclaim,
topUpReclaimed, topUpSlotsSettling, topUpSettlingNote) and the updated
slotSummary into all 23 locale files, the same way #746/#747/#755 did,
so check:translation-drift passes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6
islandbitcoin added a commit that referenced this pull request Oct 9, 2026
…#759)

* feat(cashu-card): CLEAR_SPENT, slot-shape check and spent-slot reads (ENG-631)

Add the CLEAR_SPENT (0x31) APDU and `isProofShaped`, the card file's slot
checks that tell a CLEAR_SPENT remnant from a proof. A card read now reads
every occupied slot (`readCardSlots`) and carries the spent slots on
`CashuCardInfo.spentSlots`, so the next top-up can ask the mint about them
before its load tap. The Flashcard context re-reads the slots after an op
that moved the balance or the spent count, so a clear shows at once.

`getUnspentByKeyset` still reads unspent slots only; nothing here sends
CLEAR_SPENT.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6

* feat(cashu-card-topup): reclaim mint-settled spent slots on the load tap (ENG-631)

`reclaimVerdicts` asks the mint (NUT-07) about the card's proof-shaped spent
slots before the tap; `reclaimPlan` says what a reclaim will do with them;
`reclaimSpentSlots` re-reads the spent slots in the session and sends
CLEAR_SPENT only when every one is a remnant or mint-SPENT, otherwise sends
nothing and counts what is still settling. `prepareTopUp` counts
`card.reclaimable` as room; `loadTopUp` itself still never clears, and its
inventory no longer takes a torn spent slot's nonce as the record's proof.
`TopUpError` can carry the reclaim's result with a refusal.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6

* feat(flashcard-v2): free settled spent slots on the top-up's load tap (ENG-631)

The load tap now runs VERIFY_PIN, the reclaim, then the load in one session;
the mint is asked about the spent slots before the tap, and a mint that
cannot answer costs no tap. The amount step counts the slots the tap will
free as room (`reclaimable`), the done step says how many were freed, and a
no-room refusal says how many spent slots are still settling. The card
screen shows unspent, spent and free counts with a note on spent slots.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6

* fix(cashu-card-topup): hand the reclaim's card read to the load, and drop the retry note from the done step (ENG-631)

Review fixes on #759.

- `reclaimSpentSlots` hands on what it read (`inventory`: the slot
  statuses and each spent slot's proof) when it sent no CLEAR_SPENT, and
  `loadTopUp` takes that in place of a read of its own. A first load in
  the same tap now sends no GET_SLOT_STATUS; a resumed load reads only
  the unspent slots, taking the spent ones from the reclaim. After a
  clear the read is stale and the load reads the card afresh, which
  after a full clear means the unspent slots alone. On a resumed load
  of a card with k spent and u unspent slots that is u GET_PROOFs
  before the first LOAD_PROOF instead of 1 + k + u.
- The done step's settling note no longer reuses `topUpSlotsSettling`,
  whose "Try again later." belongs to the `slots` refusal: a load that
  went through has nothing to try again. New `topUpSettlingNote`.

Tests: engine tests count the tap's APDUs for a first and a resumed load
with and without a clear, and assert the inventory handed on (or not);
the hook test checks the hand-off; the screen test asserts the new note
and that it carries no retry imperative.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6

* chore(i18n): add FlashcardV2 reclaim copy to every locale

Mirror the five new FlashcardV2 keys (slotsSpentNote, topUpSlotsReclaim,
topUpReclaimed, topUpSlotsSettling, topUpSettlingNote) and the updated
slotSummary into all 23 locale files, the same way #746/#747/#755 did,
so check:translation-drift passes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6

* fix(flashcard-v2): wait for the reclaim plan before showing the amount field, and rethrow the engine's own refusal (ENG-631)

Review fixes on #759:

- The amount field waited for the unfinished-top-ups read but not for the
  reclaim plan. On a card with no empty slot and every slot spent, the room
  was 0 until the mint answered, so the field refused every amount ("try a
  smaller amount") and then changed its mind a round-trip later. The screen
  now tracks the plan settling (`reclaimRead`), set at once when there is
  nothing to ask about and in a `finally` otherwise, and the field waits on
  both reads.

- `useCardTopUp.load` built a fresh TopUpError to attach the reclaim, so a
  refused load's stack pointed at the catch block rather than the engine's
  own check. `TopUpError.reclaim` is now writable and the original error is
  rethrown with it set.

Tests: two screen tests hold the plan (resolve / reject) and assert no field
mounts until it settles; a hook test asserts the rejected error is the very
one the engine threw.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6

* fix(flashcard-v2): show a spinner while the amount field waits on the reclaim plan (ENG-631)

Review fix on #759:

- The amount field waits for the reclaim plan, and that plan is a mint
  round-trip over the phone's network with no timeout. On a card with
  spent slots the amount step showed the unit caption, "Paid from" and a
  disabled Continue around a blank gap for as long as the mint took to
  answer, or RN fetch took to fail. An ActivityIndicator now sits in the
  field's slot (`topup-amount-loading`) until both the unfinished-top-ups
  read and the plan have settled, matching the screen's own loading step.

- The held-plan, held-read and refused-mint screen tests assert the
  indicator is present before settle/refuse and gone after.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WxkKbrg2Xohf3mQj7BLrs6

---------

Co-authored-by: Dread <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
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