Skip to content

Commit 42957ab

Browse files
committed
feat(wallet): set up a Zoe fee purse and forward invitationDetails
Closes #3669
1 parent 49ece05 commit 42957ab

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

packages/dapp-svelte-wallet/api/src/lib-wallet.js

+51-10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export function makeWallet({
7373
pursesStateChangeHandler = noActionStateChangeHandler,
7474
inboxStateChangeHandler = noActionStateChangeHandler,
7575
}) {
76+
/** @type {Purse=} */
77+
let zoeFeePurse;
78+
7679
// Create the petname maps so we can dehydrate information sent to
7780
// the frontend.
7881
const { makeMapping, dehydrate, edgeMapping } = makeDehydrator();
@@ -361,7 +364,7 @@ export function makeWallet({
361364
async function updateInboxState(id, offer, doPush = true) {
362365
// Only sent the uncompiled offer to the client.
363366
const { proposalTemplate } = offer;
364-
const { instance, installation } = idToOffer.get(id);
367+
const { instance, installation, invitationDetails } = idToOffer.get(id);
365368
if (!instance || !installation) {
366369
// We haven't yet deciphered the invitation, so don't send
367370
// this offer.
@@ -372,14 +375,18 @@ export function makeWallet({
372375
const alreadyDisplayed =
373376
inboxState.has(id) && inboxState.get(id).proposalForDisplay;
374377

378+
const feePursePetname =
379+
zoeFeePurse && purseMapping.valToPetname.get(zoeFeePurse);
375380
const offerForDisplay = {
376381
...offer,
377382
// We cannot store the actions, installation, and instance in the
378-
// displayed offer objects because they are presences are presences and we
383+
// displayed offer objects because they are presences and we
379384
// don't wish to send presences to the frontend.
380385
actions: undefined,
381386
installation: undefined,
382387
instance: undefined,
388+
feePursePetname,
389+
invitationDetails: display(invitationDetails),
383390
proposalTemplate,
384391
instancePetname: instanceDisplay.petname,
385392
installationPetname: installationDisplay.petname,
@@ -548,7 +555,13 @@ export function makeWallet({
548555
const paymentKeywords = await withdrawAllPayments;
549556
const paymentKeywordRecord = harden(Object.fromEntries(paymentKeywords));
550557

551-
const seat = E(zoe).offer(inviteP, harden(proposal), paymentKeywordRecord);
558+
const seat = E(zoe).offer(
559+
inviteP,
560+
harden(proposal),
561+
paymentKeywordRecord,
562+
undefined,
563+
zoeFeePurse,
564+
);
552565
// By the time Zoe settles the seat promise, the escrow should be complete.
553566
// Reclaim if it is somehow not.
554567
seat.finally(tryReclaimingWithdrawnPayments);
@@ -583,7 +596,11 @@ export function makeWallet({
583596
// === API
584597

585598
const addIssuer = async (petnameForBrand, issuerP, makePurse = false) => {
586-
const { brand, issuer } = await brandTable.initIssuer(issuerP);
599+
const issuer = await issuerP;
600+
const recP = brandTable.hasByIssuer(issuer)
601+
? brandTable.getByIssuer(issuer)
602+
: brandTable.initIssuer(issuer);
603+
const { brand } = await recP;
587604
if (!issuerToBoardId.has(issuer)) {
588605
const issuerBoardId = await E(board).getId(issuer);
589606
issuerToBoardId.init(issuer, issuerBoardId);
@@ -769,7 +786,6 @@ export function makeWallet({
769786
} = proposalTemplate;
770787

771788
const purseKeywordRecord = {};
772-
773789
const compile = amountKeywordRecord => {
774790
return harden(
775791
Object.fromEntries(
@@ -814,16 +830,16 @@ export function makeWallet({
814830
offer,
815831
);
816832

817-
const { installation, instance } = await E(zoe).getInvitationDetails(
818-
invitationP,
819-
);
833+
const invitationDetails = await E(zoe).getInvitationDetails(invitationP);
834+
const { instance, installation } = invitationDetails;
820835

821836
return {
837+
invitationDetails,
838+
instance,
839+
installation,
822840
proposal,
823841
inviteP: invitationP,
824842
purseKeywordRecord,
825-
installation,
826-
instance,
827843
};
828844
};
829845

@@ -1556,6 +1572,9 @@ export function makeWallet({
15561572
},
15571573
getUINotifier,
15581574
getZoe() {
1575+
// Return a Zoe that requires fees from its caller.
1576+
// TODO: We will need to wrap zoe with something that prompts the user to
1577+
// pay fees.
15591578
return zoe;
15601579
},
15611580
getBoard() {
@@ -1575,6 +1594,28 @@ export function makeWallet({
15751594
});
15761595

15771596
const initialize = async () => {
1597+
/**
1598+
* @param {Object} param0
1599+
* @param {string} param0.proposedName
1600+
* @param {string} param0.issuerName
1601+
*/
1602+
const addZoeFeePurse = async ({ proposedName, issuerName }) => {
1603+
const feeIssuer = await E(zoe).getFeeIssuer();
1604+
1605+
// Install the fee purse.
1606+
await addIssuer(issuerName, feeIssuer);
1607+
const purse = await E(zoe).makeFeePurse();
1608+
await internalUnsafeImportPurse(issuerName, proposedName, false, purse);
1609+
1610+
return purse;
1611+
};
1612+
1613+
// Create a default fee purse and use it in this contract.
1614+
zoeFeePurse = await addZoeFeePurse({
1615+
proposedName: 'Zoe fees',
1616+
issuerName: 'RUN',
1617+
});
1618+
15781619
// Allow people to send us payments.
15791620
const selfDepositFacet = Far('contact', {
15801621
receive(payment) {

0 commit comments

Comments
 (0)