From 7c4347047933ae7658f56ab2f38fe6eb263fe23d Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Fri, 16 Aug 2024 00:50:55 -0400 Subject: [PATCH] fixup! feat: zoeTools.withdrawToSeat --- packages/orchestration/src/utils/zoe-tools.js | 30 +++++++++++-------- .../test/utils/zoe-tools.test.ts | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/orchestration/src/utils/zoe-tools.js b/packages/orchestration/src/utils/zoe-tools.js index bb48c07f2bd3..d08f4ed7dded 100644 --- a/packages/orchestration/src/utils/zoe-tools.js +++ b/packages/orchestration/src/utils/zoe-tools.js @@ -5,7 +5,7 @@ import { } from '@agoric/zoe/src/contractSupport/index.js'; import { E } from '@endo/far'; -const { keys } = Object; +const { assign, keys, values } = Object; /** * @import {InvitationMakers} from '@agoric/smart-wallet/src/types.js'; @@ -89,7 +89,7 @@ export const makeZoeTools = ( console.debug( 'One or more deposits to LCA failed. Returning payment(s)...', ); - const amounts = Object.values(give); + const amounts = values(give); const errors = []; // withdraw the successfully deposited payments const paymentOrWithdrawVs = settleDeposits.map((x, i) => { @@ -103,13 +103,18 @@ export const makeZoeTools = ( // return all payments to the srcSeat const paymentsToReturn = await when(allVows(paymentOrWithdrawVs)); const paymentsKwr = harden( - Object.keys(give).reduce( - (acc, kw, i) => Object.assign(acc, { [kw]: paymentsToReturn[i] }), + keys(give).reduce( + (acc, kw, i) => assign(acc, { [kw]: paymentsToReturn[i] }), {}, ), ); - const dRes = await depositToSeat(zcf, srcSeat, give, paymentsKwr); - console.debug(dRes); + const depositResponse = await depositToSeat( + zcf, + srcSeat, + give, + paymentsKwr, + ); + console.debug(depositResponse); throw Fail`One or more deposits to LCA failed. ${q(errors)}`; } // TODO remove userSeat from baggage @@ -124,15 +129,15 @@ export const makeZoeTools = ( await null; !recipientSeat.hasExited() || Fail`The seat cannot have exited.`; - const paymentVs = Object.values(amounts).map(amt => + const paymentVs = values(amounts).map(amt => srcLocalAccount.withdraw(amt), ); - const settledPmts = await when(allVowsSettled(paymentVs)); + const settledWtihdrawals = await when(allVowsSettled(paymentVs)); // if any of the withdrawals were rejected, undo the successful ones - if (settledPmts.find(x => x.status === 'rejected')) { + if (settledWtihdrawals.find(x => x.status === 'rejected')) { const returnVs = []; - for (const pmtP of settledPmts) { + for (const pmtP of settledWtihdrawals) { if (pmtP.status === 'fulfilled') { returnVs.push(srcLocalAccount.deposit(pmtP.value)); } @@ -140,9 +145,10 @@ export const makeZoeTools = ( await when(allVows(returnVs)); throw Fail`One or more withdrawals failed. Returned all payments to the source local account.`; } + // successfully withdraw all payments for srcLocalAccount, deposit to recipientSeat const paymentsKwr = harden( - Object.keys(amounts).reduce( - (acc, kw, i) => Object.assign(acc, { [kw]: settledPmts[i].value }), + keys(amounts).reduce( + (acc, kw, i) => assign(acc, { [kw]: settledWtihdrawals[i].value }), {}, ), ); diff --git a/packages/orchestration/test/utils/zoe-tools.test.ts b/packages/orchestration/test/utils/zoe-tools.test.ts index b239c3bae592..8e3a522a52b2 100644 --- a/packages/orchestration/test/utils/zoe-tools.test.ts +++ b/packages/orchestration/test/utils/zoe-tools.test.ts @@ -135,3 +135,5 @@ test('zoeTool.localTransfer and zoeTools.withdrawToSeat', async t => { }); } }); + +test.todo('withdrawToSeat, unknown brand');