Skip to content

Commit

Permalink
Merge pull request #10 from gucoi/fix_some_bug
Browse files Browse the repository at this point in the history
fix some bug
  • Loading branch information
flmel authored Jun 20, 2024
2 parents 2ea87d1 + 3a34992 commit edf7a5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions contract-rs/src/donation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Contract {
let mut donated_so_far: NearToken = self
.donations
.get(&donor)
.cloned()
.unwrap_or(NearToken::from_near(0));

let to_transfer = if donated_so_far.is_zero() {
Expand All @@ -44,7 +45,7 @@ impl Contract {
// Persist in storage the amount donated so far
donated_so_far = donated_so_far.saturating_add(donation_amount);

self.donations.insert(&donor, &donated_so_far);
self.donations.insert(donor.clone(), donated_so_far);

log!(
"Thank you {} for donating {}! You donated a total of {}",
Expand All @@ -64,6 +65,7 @@ impl Contract {
let amount = self
.donations
.get(&account_id)
.cloned()
.unwrap_or(NearToken::from_near(0))
.as_yoctonear();

Expand All @@ -75,7 +77,7 @@ impl Contract {

// Public Method - get total number of donors
pub fn number_of_donors(&self) -> U64 {
U64::from(self.donations.len())
U64::from(self.donations.len() as u64)
}

// Public Method - paginate through all donations on the contract
Expand All @@ -88,7 +90,7 @@ impl Contract {
.skip(start as usize)
.take(limit.unwrap_or(10) as usize)
.map(|(account_id, total_amount)| Donation {
account_id,
account_id: account_id.clone(),
total_amount: U128::from(total_amount.as_yoctonear()),
})
.collect()
Expand Down
4 changes: 2 additions & 2 deletions contract-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Find all our documentation at https://docs.near.org
use near_sdk::collections::UnorderedMap;
use near_sdk::store::UnorderedMap;
use near_sdk::{near, AccountId, NearToken, PanicOnDefault};

mod donation;
Expand Down Expand Up @@ -47,7 +47,7 @@ mod tests {
const ONE_NEAR: NearToken = NearToken::from_near(1);

#[test]
fn initializes() {
fn initalizes() {
let contract = Contract::init(BENEFICIARY.parse().unwrap());
assert_eq!(
contract.beneficiary,
Expand Down

0 comments on commit edf7a5b

Please sign in to comment.