Merge #971: gui: prevent spend with duplicate addresses
8639f9b94f1fdceaee94aa927e8f9b7b07cc51f9 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 8639f9b94f1fdceaee94aa927e8f9b7b07cc51f9
Tree-SHA512: f2110e49e07ec04deb8997fae987998dcfeacc41bec0c770a16fe555bde0b49b67c4cc14736fb7bbb5e536abb3d2ef1e847bbe5075be751b579728aac2a98a97
This commit is contained in:
commit
903328ffef
@ -170,22 +170,28 @@ impl DefineSpend {
|
||||
&& self.recipients.iter().all(|r| r.valid())
|
||||
}
|
||||
|
||||
fn exists_duplicate(&self) -> bool {
|
||||
for (i, recipient) in self.recipients.iter().enumerate() {
|
||||
if !recipient.address.value.is_empty()
|
||||
&& self.recipients[..i]
|
||||
.iter()
|
||||
.any(|r| r.address.value == recipient.address.value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn check_valid(&mut self) {
|
||||
self.is_valid =
|
||||
self.form_values_are_valid() && self.coins.iter().any(|(_, selected)| *selected);
|
||||
self.is_duplicate = false;
|
||||
for (i, recipient) in self.recipients.iter().enumerate() {
|
||||
if !self.is_duplicate && !recipient.address.value.is_empty() {
|
||||
self.is_duplicate = self.recipients[..i]
|
||||
.iter()
|
||||
.any(|r| r.address.value == recipient.address.value);
|
||||
}
|
||||
}
|
||||
self.is_duplicate = self.exists_duplicate();
|
||||
}
|
||||
/// redraft calculates the amount left to select and auto selects coins
|
||||
/// if the user did not select a coin manually
|
||||
fn redraft(&mut self, daemon: Arc<dyn Daemon + Sync + Send>) {
|
||||
if !self.form_values_are_valid() || self.recipients.is_empty() {
|
||||
if !self.form_values_are_valid() || self.exists_duplicate() || self.recipients.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -253,7 +253,7 @@ pub fn create_spend_tx<'a>(
|
||||
.width(Length::Fixed(100.0)),
|
||||
)
|
||||
.push(
|
||||
if is_valid
|
||||
if is_valid && !duplicate
|
||||
&& (is_self_send
|
||||
|| (total_amount < *balance_available
|
||||
&& Some(&Amount::from_sat(0)) == amount_left))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user