Skip to content

Commit

Permalink
refactor(run-protocol): use common transition/update in makeTransferI…
Browse files Browse the repository at this point in the history
…nvitation()
  • Loading branch information
turadg committed Feb 23, 2022
1 parent 5262953 commit fcdd7a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions packages/run-protocol/src/vaultFactory/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const makeInnerVault = (
assertPhase(VaultPhase.ACTIVE);
};

/** @type {IterationObserver<unknown> | null} */
let outerUpdater;

// vaultSeat will hold the collateral until the loan is retired. The
Expand Down Expand Up @@ -303,6 +304,7 @@ export const makeInnerVault = (
break;
case VaultPhase.CLOSED:
case VaultPhase.LIQUIDATED:
case VaultPhase.TRANSFER:
outerUpdater.finish(uiState);
outerUpdater = null;
break;
Expand Down Expand Up @@ -684,7 +686,7 @@ export const makeInnerVault = (
};

const makeTransferInvitationHook = seat => {
assertVaultIsOpen();
assertPhase(VaultPhase.TRANSFER);
seat.exit();
// eslint-disable-next-line no-use-before-define
return setupOuter(innerVault);
Expand All @@ -701,10 +703,8 @@ export const makeInnerVault = (
makeAdjustBalancesInvitation,
makeCloseInvitation,
makeTransferInvitation: () => {
if (outerUpdater) {
outerUpdater.finish(snapshotState(VaultPhase.TRANSFER));
outerUpdater = null;
}
assignPhase(VaultPhase.TRANSFER);
updateUiState();
return zcf.makeInvitation(makeTransferInvitationHook, 'TransferVault');
},

Expand Down
4 changes: 2 additions & 2 deletions packages/run-protocol/test/vaultFactory/test-vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,8 @@ test('transfer vault', async t => {
const transferStatus = await E(transferNotifier).getUpdateSince();
t.deepEqual(
transferStatus.value.vaultState,
VaultPhase.ACTIVE,
'new notifier is active',
VaultPhase.TRANSFER,
'vault now transferrable',
);

// Interleave with `adjustVault`
Expand Down

0 comments on commit fcdd7a0

Please sign in to comment.