Skip to content

Commit

Permalink
fixup! style(run-protocol): rename VaultState to VaultPhase
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 23, 2022
1 parent 5c29760 commit 837381e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/run-protocol/src/vaultFactory/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,20 @@ export const makeInnerVault = (
zcf.makeEmptySeatKit(undefined);

/** @type {VAULT_PHASE} */
let vaultPhase = VaultPhase.ACTIVE;
let phase = VaultPhase.ACTIVE;

const assertVaultIsOpen = () => {
assert(vaultPhase === VaultPhase.ACTIVE, X`vault must still be active`);
assert(phase === VaultPhase.ACTIVE, X`vault must still be active`);
};

/**
* @param {VAULT_PHASE} newPhase
*/
const assignPhase = newPhase => {
const validNewPhases = validTransitions[vaultPhase];
const validNewPhases = validTransitions[phase];
if (!validNewPhases.includes(newPhase))
throw new Error(
`Vault cannot transition from ${vaultPhase} to ${newPhase}`,
);
vaultPhase = newPhase;
throw new Error(`Vault cannot transition from ${phase} to ${newPhase}`);
phase = newPhase;
};

let outerUpdater;
Expand Down Expand Up @@ -316,10 +314,10 @@ export const makeInnerVault = (
// [https://github.com/Agoric/dapp-token-economy/issues/123]
const collateralizationRatio = await getCollateralizationRatio();
/** @type {VaultUIState} */
const uiState = snapshotState(vaultPhase, collateralizationRatio);
const uiState = snapshotState(phase, collateralizationRatio);
trace('updateUiState', uiState);

switch (vaultPhase) {
switch (phase) {
case VaultPhase.ACTIVE:
case VaultPhase.LIQUIDATING:
outerUpdater.updateState(uiState);
Expand All @@ -329,14 +327,14 @@ export const makeInnerVault = (
outerUpdater.finish(uiState);
break;
default:
throw Error(`unreachable vaultState: ${vaultPhase}`);
throw Error(`unreachable vaultState: ${phase}`);
}
};
// XXX Echo notifications from the manager through all vaults
// TODO move manager state to a separate notifer https://github.com/Agoric/agoric-sdk/issues/4540
observeNotifier(managerNotifier, {
updateState: () => {
if (vaultPhase !== VaultPhase.CLOSED) {
if (phase !== VaultPhase.CLOSED) {
updateUiState();
}
},
Expand Down

0 comments on commit 837381e

Please sign in to comment.