Skip to content

Commit

Permalink
Fix donate_to_project
Browse files Browse the repository at this point in the history
Add amount of current payment to previous payment
  • Loading branch information
CostinCarabas committed Jul 31, 2024
1 parent 324f598 commit c01041d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
19 changes: 17 additions & 2 deletions contracts/potlock/src/potlock_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,22 @@ pub trait PotlockInteractions:
self.require_project_is_active(project_id);
let payment = self.call_value().single_esdt();
let caller = self.blockchain().get_caller();
self.require_donation_same_token_id(project_id, &caller, payment.token_identifier.clone());
self.project_donations(project_id).insert(caller, payment);

let mut donation_mapper = self.project_donations(project_id);
if donation_mapper.contains_key(&caller) {
let opt_payment = donation_mapper.remove(&caller);
if opt_payment.is_some() {
let mut previous_payment = opt_payment.unwrap();
require!(
previous_payment.token_identifier == payment.token_identifier.clone(),
"Already made a payment with a different TokenID"
);
previous_payment.amount += payment.amount;
self.project_donations(project_id)
.insert(caller, previous_payment);
}
} else {
self.project_donations(project_id).insert(caller, payment);
}
}
}
18 changes: 0 additions & 18 deletions contracts/potlock/src/potlock_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,6 @@ pub trait PotlockStorage {
);
}

fn require_donation_same_token_id(
&self,
project_id: ProjectId,
user: &ManagedAddress,
token_id: TokenIdentifier,
) {
let donation_mapper = self.project_donations(project_id);
if donation_mapper.contains_key(user) {
let payment = donation_mapper.get(user);
if payment.is_some() {
require!(
payment.unwrap().token_identifier == token_id,
"Already made a payment with a different TokenID"
);
}
}
}

#[view(getFeeTokenIdentifier)]
#[storage_mapper("feeTokenIdentifier")]
fn fee_token_identifier(&self) -> SingleValueMapper<TokenIdentifier>;
Expand Down

0 comments on commit c01041d

Please sign in to comment.