Skip to content

Commit 91705d5

Browse files
committed
🐛 fix(functions.rs): fix bug in cancelOffer function where offer status was not being updated correctly
✨ feat(functions.rs): add cancellation functionality to cancelOffer function 🐛 fix(types.rs): add CANCELLED status to OfferStatus enum
1 parent 840e1f0 commit 91705d5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pallets/afloat/src/functions.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,19 @@ impl<T: Config> Pallet<T> {
864864
ensure!(<AfloatOffers<T>>::contains_key(order_id), Error::<T>::OfferNotFound);
865865
//get offer details
866866
let offer = <AfloatOffers<T>>::get(order_id).unwrap();
867-
Ok(())
867+
match offer.status {
868+
OfferStatus::CREATED => {
869+
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult {
870+
let offer = offer.as_mut().ok_or(Error::<T>::OfferNotFound)?;
871+
offer.cancellation_date = Some(T::TimeProvider::now().as_secs());
872+
offer.status = OfferStatus::CANCELLED;
873+
Ok(())
874+
})?;
875+
Ok(())
876+
}
877+
_ => {
878+
Err(Error::<T>::OfferTaken.into())
879+
}
880+
}
868881
}
869882
}

pallets/afloat/src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub enum SignUpArgs {
5656
}
5757

5858
// ! Offer structures
59-
59+
// ! The statuses with "TF" refer to the transfer form that is generated after a match is formed - so all of the TF_* statuses come after matched
6060
#[derive(
6161
Encode, Decode, Clone, Eq, PartialEq, RuntimeDebugNoBound, MaxEncodedLen, TypeInfo, Copy,
6262
)]
@@ -70,6 +70,7 @@ pub enum OfferStatus {
7070
TF_APPROVED,
7171
APPROVED,
7272
FILLED,
73+
CANCELLED,
7374
}
7475

7576
impl Default for OfferStatus {

0 commit comments

Comments
 (0)