Skip to content

Commit

Permalink
feat(smart-wallet): withdraw payments before getting invitation
Browse files Browse the repository at this point in the history
This performance optimization avoids all the work of getting an
invitation if there aren't sufficient funds for `proposal.give`.

fixes: #7098
  • Loading branch information
dckc committed Aug 1, 2023
1 parent ab4491a commit e9254e9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/smart-wallet/src/offers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { E, passStyleOf } from '@endo/far';
import { deeplyFulfilledObject } from '@agoric/internal';
import { makePaymentsHelper } from './payments.js';

/**
Expand Down Expand Up @@ -80,15 +81,15 @@ export const makeOfferExecutor = ({
// 1. Prepare values and validate synchronously.
const { id, invitationSpec, proposal, offerArgs } = offerSpec;

const paymentKeywordRecord = await (proposal?.give
? deeplyFulfilledObject(paymentsManager.withdrawGive(proposal.give))
: undefined);

const invitation = invitationFromSpec(invitationSpec);
const invitationAmount = await E(invitationIssuer).getAmountOf(
invitation,
);

const paymentKeywordRecord = proposal?.give
? paymentsManager.withdrawGive(proposal.give)
: undefined;

// 2. Begin executing offer
// No explicit signal to user that we reached here but if anything above
// failed they'd get an 'error' status update.
Expand Down

0 comments on commit e9254e9

Please sign in to comment.