Skip to content

Commit 903328f

Browse files
committed
Merge #971: gui: prevent spend with duplicate addresses
8639f9b gui: prevent spend with duplicate addresses (jp1ac4) Pull request description: Currently, if duplicate addresses are entered when creating a new spend, the user can click Next and only the second amount will be used for the draft PSBT. This change prevents the user clicking Next if there are duplicate addresses and stops the `redraft` function running. ACKs for top commit: edouardparis: ACK 8639f9b Tree-SHA512: f2110e49e07ec04deb8997fae987998dcfeacc41bec0c770a16fe555bde0b49b67c4cc14736fb7bbb5e536abb3d2ef1e847bbe5075be751b579728aac2a98a97
2 parents c1e2d26 + 8639f9b commit 903328f

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

gui/src/app/state/spend/step.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,28 @@ impl DefineSpend {
170170
&& self.recipients.iter().all(|r| r.valid())
171171
}
172172

173-
fn check_valid(&mut self) {
174-
self.is_valid =
175-
self.form_values_are_valid() && self.coins.iter().any(|(_, selected)| *selected);
176-
self.is_duplicate = false;
173+
fn exists_duplicate(&self) -> bool {
177174
for (i, recipient) in self.recipients.iter().enumerate() {
178-
if !self.is_duplicate && !recipient.address.value.is_empty() {
179-
self.is_duplicate = self.recipients[..i]
175+
if !recipient.address.value.is_empty()
176+
&& self.recipients[..i]
180177
.iter()
181-
.any(|r| r.address.value == recipient.address.value);
178+
.any(|r| r.address.value == recipient.address.value)
179+
{
180+
return true;
182181
}
183182
}
183+
false
184+
}
185+
186+
fn check_valid(&mut self) {
187+
self.is_valid =
188+
self.form_values_are_valid() && self.coins.iter().any(|(_, selected)| *selected);
189+
self.is_duplicate = self.exists_duplicate();
184190
}
185191
/// redraft calculates the amount left to select and auto selects coins
186192
/// if the user did not select a coin manually
187193
fn redraft(&mut self, daemon: Arc<dyn Daemon + Sync + Send>) {
188-
if !self.form_values_are_valid() || self.recipients.is_empty() {
194+
if !self.form_values_are_valid() || self.exists_duplicate() || self.recipients.is_empty() {
189195
return;
190196
}
191197

gui/src/app/view/spend/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub fn create_spend_tx<'a>(
253253
.width(Length::Fixed(100.0)),
254254
)
255255
.push(
256-
if is_valid
256+
if is_valid && !duplicate
257257
&& (is_self_send
258258
|| (total_amount < *balance_available
259259
&& Some(&Amount::from_sat(0)) == amount_left))

0 commit comments

Comments
 (0)