Skip to content

Commit

Permalink
fix(wallet): handle cancelled offer state (#4292)
Browse files Browse the repository at this point in the history
* fix(wallet): handle cancelled offer state

* chore(wallet): simplify conditional
  • Loading branch information
samsiegart authored Jan 21, 2022
1 parent fa8dc13 commit 9dd2dc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/wallet/ui/src/components/Offer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const statusText = {
complete: 'Accepted',
pending: 'Pending',
proposed: 'Proposed',
cancel: 'Cancelled',
};

const statusColors = {
Expand All @@ -29,6 +30,7 @@ const statusColors = {
pending: 'warning',
proposed: 'default',
complete: 'success',
cancel: 'default',
};

const cmp = (a, b) => {
Expand Down Expand Up @@ -69,7 +71,7 @@ const OfferWithoutContext = ({
setPendingOffers({ offerId: id, isPending: true });
}

// Eagerly show pending and declined offers states.
// Eagerly show pending and declined offers' states.
if (status === 'proposed' && pendingOffers.has(id)) {
status = 'pending';
}
Expand Down Expand Up @@ -192,17 +194,16 @@ const OfferWithoutContext = ({
</div>
);

const isOfferCompleted = [
'accept',
'decline',
'complete',
'rejected',
'cancel',
].includes(status);

return (
<Request
header="Offer"
completed={
status === 'accept' ||
status === 'decline' ||
status === 'complete' ||
status === 'rejected'
}
close={close}
>
<Request header="Offer" completed={isOfferCompleted} close={close}>
<Chip
variant="outlined"
color={statusColors[status]}
Expand Down
5 changes: 5 additions & 0 deletions packages/wallet/ui/src/components/tests/Offer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ test('renders the request as completed when appropriate', () => {
rejectedOffer.status = 'rejected';
component = mount(<Offer offer={rejectedOffer} />);
expect(component.find(Request).props().completed).toEqual(true);

const cancelledOffer = { ...offer };
cancelledOffer.status = 'cancel';
component = mount(<Offer offer={cancelledOffer} />);
expect(component.find(Request).props().completed).toEqual(true);
});

test('closes the offer', () => {
Expand Down

0 comments on commit 9dd2dc4

Please sign in to comment.