Skip to content

Commit

Permalink
fix(wallet): handle cancelled offer state
Browse files Browse the repository at this point in the history
  • Loading branch information
samsiegart committed Jan 13, 2022
1 parent f599585 commit d152b49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
22 changes: 11 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 @@ -71,7 +73,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 @@ -194,17 +196,15 @@ const OfferWithoutContext = ({
</div>
);

const isOfferCompleted =
status === 'accept' ||
status === 'decline' ||
status === 'complete' ||
status === 'rejected' ||
status === 'cancel';

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 @@ -291,6 +291,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 d152b49

Please sign in to comment.