Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
do not panic but send money/nft to owner instead (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjartek authored Apr 27, 2021
1 parent a99dda5 commit bd77c8a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions contracts/Auction.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ pub contract Auction {
collectionRef.deposit(token: <-NFT!)
return
}
panic("Could not send NFT to non existing capability")
if let ownerCollection=self.ownerCollectionCap.borrow() {
let NFT <- self.NFT <- nil
ownerCollection.deposit(token: <-NFT!)
return
}
}

// sendBidTokens sends the bid tokens to the Vault Receiver belonging to the provided Capability
Expand All @@ -172,7 +176,14 @@ pub contract Auction {
}
return
}
panic("Could not send tokens to non existant receiver")

if let ownerRef= self.ownerVaultCap.borrow() {
let bidVaultRef = &self.bidVault as &FungibleToken.Vault
if(bidVaultRef.balance > 0.0) {
ownerRef.deposit(from: <-bidVaultRef.withdraw(amount: bidVaultRef.balance))
}
return
}
}

pub fun releasePreviousBid() {
Expand All @@ -185,7 +196,6 @@ pub contract Auction {
//This method should probably use preconditions more
pub fun settleAuction(cutPercentage: UFix64, cutVault:Capability<&{FungibleToken.Receiver}> ) {


pre {
!self.auctionCompleted : "The auction is already settled"
self.NFT != nil: "NFT in auction does not exist"
Expand Down Expand Up @@ -286,11 +296,7 @@ pub contract Auction {

if self.bidder() != bidderAddress {
if self.bidVault.balance != 0.0 {
if let vaultCap = self.recipientVaultCap {
self.sendBidTokens(self.recipientVaultCap!)
} else {
panic("unable to get recipient Vault capability")
}
self.sendBidTokens(self.recipientVaultCap!)
}
}

Expand Down

0 comments on commit bd77c8a

Please sign in to comment.