Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): handle cancelled offer state #4292

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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