reset-dialog-puts-the-wipe-where-cancel-belongs.md (4828B)
1 <!-- 2 This file is part of GNU Taler 3 (C) 2026 Taler Systems S.A. 4 5 GNU Taler is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 --> 16 17 # The two dialogs that can destroy a wallet put their button where Cancel belongs 18 19 Found while writing the scenario that confirms a wallet reset — the only thing 20 that calls `clearDb`, and therefore the only scenario that had ever seen this 21 dialog's buttons. 22 23 **Severity: moderate.** Nothing is wrong with the reset itself; the danger is 24 where its button is drawn. A user who dismisses dialogs by tapping the 25 left-hand button — the position Android has used for "Cancel" since 26 Holo — destroys their wallet, and the dialog's own text says what that costs: 27 "you will lose all coins and purchases". 28 29 ## What happens 30 31 **Settings → Reset Wallet (dangerous!)** opens 32 33 ``` 34 Do you really want to reset the wallet and lose all coins and purchases? 35 36 [ Reset ] [ Cancel ] 37 ``` 38 39 Measured on a 1080-wide screen, the buttons' centres are 40 41 ``` 42 the reset dialog's buttons, left to right: [('Reset', 642), ('Cancel', 836)] 43 ``` 44 45 so **Reset is the left-hand button and Cancel the right-hand one** — the 46 opposite of every other confirmation in the app and of the platform 47 convention, where the rightmost text button is the affirmative one and the 48 dismissive action sits to its left. 49 50 Tapping Reset does reset: the balance goes to nothing and `clearDb` runs. 51 52 ## Why 53 54 The two buttons are assigned the wrong way round: 55 56 ```kotlin 57 // wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:358 58 MaterialAlertDialogBuilder(context) 59 .setMessage(R.string.settings_dialog_reset_message) 60 .setNegativeButton(R.string.reset) { _, _ -> // destroys the wallet 61 settingsManager.clearDb { model.dangerouslyReset() } 62 … 63 } 64 .setPositiveButton(R.string.cancel) { _, _ -> // does nothing 65 … 66 } 67 .show() 68 ``` 69 70 `MaterialAlertDialogBuilder` draws the **positive** button rightmost, so 71 putting `cancel` there and `reset` in the negative slot swaps them on screen. 72 73 It is not the only one. The app uses `MaterialAlertDialogBuilder` in exactly 74 two places that matter, and **both** are inverted the same way — the other is 75 the database import, which is also destructive: 76 77 ```kotlin 78 // wallet/src/main/java/net/taler/wallet/settings/SettingsScreen.kt:295 79 .setMessage(R.string.settings_dialog_import_message) // "This operation 80 .setNegativeButton(R.string.import_db) { _, _ -> … } // will overwrite 81 .setPositiveButton(R.string.cancel) { _, _ -> … } // your existing 82 // database" 83 ``` 84 85 Every *other* confirmation in the app is a Compose `AlertDialog` with 86 `confirmButton`/`dismissButton` — the bank-account forget dialog, the 87 transaction delete dialog, the contacts send dialog — and those are right by 88 construction, because Compose places `confirmButton` on the right. The two 89 builder-based dialogs are the only ones where the slot has to be chosen by 90 hand, and both chose wrong. 91 92 ## Reproduce by hand 93 94 1. Install a debug build and withdraw something, so there is money to lose. 95 2. **Settings → Reset Wallet (dangerous!)**. 96 3. Look at the buttons: **Reset** is on the left, **Cancel** on the right. 97 4. Tap the left-hand button the way one dismisses a dialog. The wallet is 98 emptied — balance gone, transactions gone. 99 100 Expected: the destructive action on the right, where this app and the platform 101 put affirmative actions, so that the reflexive left-hand tap is the safe one. 102 103 ## Reproduce with the simulator 104 105 ```bash 106 ssh root@tripwire.taler.net 107 cd /opt/taler-sim/driver 108 SIM_WORKER=0 python3 -u suite.py settings_reset_confirmed 109 ``` 110 111 The scenario reports the two buttons with their x coordinates, confirms 112 `clearDb` reached wallet-core, and checks that no coins survive. 113 114 ## Suggested fix 115 116 Swap them, in both dialogs: 117 118 ```kotlin 119 .setPositiveButton(R.string.reset) { _, _ -> settingsManager.clearDb { … } } 120 .setNegativeButton(R.string.cancel) { _, _ -> … } 121 ``` 122 123 A dialog that can destroy someone's money is also worth a second gate — the 124 database exports warn first ("this file holds your money… Export anyway?"), 125 and the reset is strictly more destructive than an export.