Skip to content

Commit

Permalink
chore: change sell items to add make invitation method to public facet (
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills authored Apr 2, 2021
1 parent a4a4c01 commit 3d75806
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions packages/zoe/src/contracts/sellItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ const start = zcf => {
return defaultAcceptanceMsg;
};

/** @type {SellItemsPublicFacet} */
const publicFacet = Far('SellItemsPublicFacet', {
getAvailableItems: () => {
assert(sellerSeat && !sellerSeat.hasExited(), X`no items are for sale`);
return sellerSeat.getAmountAllocated('Items');
},
getItemsIssuer: () => issuers.Items,
});
const getAvailableItems = () => {
assert(sellerSeat && !sellerSeat.hasExited(), X`no items are for sale`);
return sellerSeat.getAmountAllocated('Items');
};

const buy = buyerSeat => {
assertProposalShape(buyerSeat, {
Expand Down Expand Up @@ -101,22 +97,31 @@ const start = zcf => {
// The buyer's offer has been processed.
buyerSeat.exit();

if (amountMath.isEmpty(publicFacet.getAvailableItems())) {
if (amountMath.isEmpty(getAvailableItems())) {
zcf.shutdown('All items sold.');
}
return defaultAcceptanceMsg;
};

const makeBuyerInvitation = () => {
const itemsAmount = sellerSeat.getAmountAllocated('Items');
assert(
sellerSeat && !amountMath.isEmpty(itemsAmount),
X`no items are for sale`,
);
return zcf.makeInvitation(buy, 'buyer');
};

/** @type {SellItemsPublicFacet} */
const publicFacet = Far('SellItemsPublicFacet', {
getAvailableItems,
getItemsIssuer: () => issuers.Items,
makeBuyerInvitation,
});

/** @type {SellItemsCreatorFacet} */
const creatorFacet = Far('SellItemsCreatorFacet', {
makeBuyerInvitation: () => {
const itemsAmount = sellerSeat.getAmountAllocated('Items');
assert(
sellerSeat && !amountMath.isEmpty(itemsAmount),
X`no items are for sale`,
);
return zcf.makeInvitation(buy, 'buyer');
},
makeBuyerInvitation,
getAvailableItems: publicFacet.getAvailableItems,
getItemsIssuer: publicFacet.getItemsIssuer,
});
Expand Down

0 comments on commit 3d75806

Please sign in to comment.