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 1 commit
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
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';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@erights erights Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samsiegart @michaelfig
Where does this status string come from? Where are its possible values defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we have any good documentation on that. The implementation is in https://github.com/Agoric/agoric-sdk/blob/master/packages/wallet/api/src/lib-wallet.js (search for "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 @@ -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