Browse Source

Merge #573

573: Should not be able to trigger close in `PendingOpen` r=scratchscratchscratchy a=scratchscratchscratchy

fixes https://github.com/itchysats/itchysats/issues/517

Triggering a settlement proposal prior to being `Open` does not make sense.

Co-authored-by: scratchy <scratchy@itchysats.network>
debug-collab-settlement
bors[bot] 3 years ago
committed by GitHub
parent
commit
dcac61f71f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      daemon/src/model/cfd.rs
  2. 8
      daemon/src/taker_cfd.rs
  3. 4
      taker-frontend/src/components/History.tsx

4
daemon/src/model/cfd.rs

@ -1221,6 +1221,10 @@ impl Cfd {
)
}
pub fn is_collaborative_settle_possible(&self) -> bool {
matches!(self.state.clone(), CfdState::Open { .. })
}
pub fn role(&self) -> Role {
self.order.origin.into()
}

8
daemon/src/taker_cfd.rs

@ -188,6 +188,14 @@ where
let mut conn = self.db.acquire().await?;
let cfd = load_cfd_by_order_id(order_id, &mut conn).await?;
if !cfd.is_collaborative_settle_possible() {
anyhow::bail!(
"Settlement proposal not possible because for cfd {} is in state {} which cannot be collaboratively settled",
order_id,
cfd.state
)
}
let proposal = cfd.calculate_settlement(current_price, self.n_payouts)?;
if self

4
taker-frontend/src/components/History.tsx

@ -98,9 +98,7 @@ const CfdDetails = ({ cfd }: CfdDetailsProps) => {
});
const disableCloseButton = cfd.state.getGroup() === StateGroupKey.CLOSED
|| [StateKey.OPEN_COMMITTED, StateKey.OUTGOING_SETTLEMENT_PROPOSAL, StateKey.PENDING_CLOSE].includes(
cfd.state.key,
);
|| !(cfd.state.key === StateKey.OPEN);
return (
<HStack bg={useColorModeValue("gray.100", "gray.700")} rounded={5}>

Loading…
Cancel
Save