Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename current amounts to recent, etc. Deprecate old. #2109

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/ERTP/src/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ function makeIssuerKit(
paymentLedger.init(payment, amount);
return payment;
},
getCurrentAmount: () => currentBalance,
getCurrentAmount: async () => currentBalance,
getCurrentAmountNotifier: () => balanceNotifier,
getRecentAmount: async () => currentBalance,
getRecentAmountNotifier: () => balanceNotifier,
getAllegedBrand: () => brand,
// eslint-disable-next-line no-use-before-define
getDepositFacet: () => depositFacet,
Expand Down
15 changes: 13 additions & 2 deletions packages/ERTP/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,21 @@
*
* @property {() => Brand} getAllegedBrand Get the alleged Brand for this Purse
*
* @property {() => Amount} getCurrentAmount
* Get the amount contained in this purse.
* @property {() => Promise<Amount>} getCurrentAmount
* at-deprecated Use `getRecentAmount` instead.
* TODO How to I tell jsdoc something in this position is deprecated?
katelynsills marked this conversation as resolved.
Show resolved Hide resolved
*
* @property {() => Notifier<Amount>} getCurrentAmountNotifier
* at-deprecated Use `getRecentAmountNotifier` instead.
* TODO How to I tell jsdoc something in this position is deprecated?
*
* @property {() => Promise<Amount>} getRecentAmount
* Get an amount that was recent contained in this purse. If asked repeatedly
* the answer should be eventually consistent. Under quiescence it should eventually
* converge on the correct amount. Any amount reported should have been a correct
* amount at some point in the past.
*
* @property {() => Notifier<Amount>} getRecentAmountNotifier
* Get a lossy notifier for changes to this purse's balance.
*
* @property {(payment: Payment, optAmount: Amount=) => Amount} deposit
Expand Down
22 changes: 11 additions & 11 deletions packages/ERTP/test/unitTests/test-issuerObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ test('issuer.makeEmptyPurse', async t => {
const purse = issuer.makeEmptyPurse();
const payment = mint.mintPayment(amountMath.make(837));

const notifier = purse.getCurrentAmountNotifier();
const notifier = purse.getRecentAmountNotifier();
let nextUpdate = notifier.getUpdateSince();

const checkNotifier = async () => {
const { value: balance, updateCount } = await nextUpdate;
t.assert(
amountMath.isEqual(purse.getCurrentAmount(), balance),
amountMath.isEqual(await purse.getRecentAmount(), balance),
`the notifier balance is the same as the purse`,
);
nextUpdate = notifier.getUpdateSince(updateCount);
};

t.assert(
amountMath.isEqual(purse.getCurrentAmount(), amountMath.getEmpty()),
amountMath.isEqual(await purse.getRecentAmount(), amountMath.getEmpty()),
`empty purse is empty`,
);
await checkNotifier();
Expand All @@ -102,7 +102,7 @@ test('issuer.makeEmptyPurse', async t => {
`the balance returned is the purse balance`,
);
t.assert(
amountMath.isEqual(purse.getCurrentAmount(), fungible837),
amountMath.isEqual(await purse.getRecentAmount(), fungible837),
`the new purse balance is the payment's old balance`,
);
await checkNotifier();
Expand All @@ -118,7 +118,7 @@ test('issuer.makeEmptyPurse', async t => {
);
});
t.assert(
amountMath.isEqual(purse.getCurrentAmount(), amountMath.getEmpty()),
amountMath.isEqual(await purse.getRecentAmount(), amountMath.getEmpty()),
`the purse is empty again`,
);
await checkNotifier();
Expand All @@ -140,7 +140,7 @@ test('purse.deposit', async t => {
const fungibleSum = amountMath.add(fungible17, fungible25);

const purse = issuer.makeEmptyPurse();
const notifier = purse.getCurrentAmountNotifier();
const notifier = purse.getRecentAmountNotifier();
const payment17 = mint.mintPayment(fungible17);
const payment25 = mint.mintPayment(fungible25);

Expand All @@ -149,7 +149,7 @@ test('purse.deposit', async t => {
const checkNotifier = async () => {
const { value: balance, updateCount } = await nextUpdate;
t.assert(
amountMath.isEqual(purse.getCurrentAmount(), balance),
amountMath.isEqual(await purse.getRecentAmount(), balance),
`the notifier balance is the same as the purse`,
);
nextUpdate = notifier.getUpdateSince(updateCount);
Expand All @@ -165,7 +165,7 @@ test('purse.deposit', async t => {
`the balance changes by the deposited amount: ${delta.value}`,
);
t.assert(
amountMath.isEqual(purse.getCurrentAmount(), expectedNewBalance),
amountMath.isEqual(await purse.getRecentAmount(), expectedNewBalance),
`the new purse balance ${depositResult.value} is the expected amount: ${expectedNewBalance.value}`,
);
await checkNotifier();
Expand Down Expand Up @@ -204,14 +204,14 @@ test('purse.getDepositFacet', async t => {

const purse = issuer.makeEmptyPurse();
const payment = mint.mintPayment(fungible25);
const notifier = purse.getCurrentAmountNotifier();
const notifier = purse.getRecentAmountNotifier();

let nextUpdate = notifier.getUpdateSince();
const checkNotifier = async () => {
const { value: balance, updateCount } = await nextUpdate;
nextUpdate = notifier.getUpdateSince(updateCount);
t.assert(
amountMath.isEqual(purse.getCurrentAmount(), balance),
amountMath.isEqual(await purse.getRecentAmount(), balance),
`the notifier balance is the same as the purse's`,
);
};
Expand All @@ -222,7 +222,7 @@ test('purse.getDepositFacet', async t => {
`the balance returned is the purse balance`,
);
t.assert(
amountMath.isEqual(purse.getCurrentAmount(), fungible25),
amountMath.isEqual(await purse.getRecentAmount(), fungible25),
`the new purse balance is the payment's old balance`,
);
await checkNotifier();
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/test/test-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ test.serial('home.wallet - receive zoe invite', async t => {
await E(depositFacet).receive(invite);

// The invite was successfully received in the user's wallet.
const invitePurseBalance = await E(invitePurse).getCurrentAmount();
const invitePurseBalance = await E(invitePurse).getRecentAmount();
t.is(
invitePurseBalance.value[0].description,
'getRefund',
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default async function deployWallet(
if (!payment && purse) {
// Withdraw the payment from the purse.
payment = E(purse)
.getCurrentAmount()
.getRecentAmount()
.then(amount => E(purse).withdraw(amount));
}

Expand Down
12 changes: 6 additions & 6 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ export function makeWallet({
pursesState.delete(key);
}
}
const currentAmount = await E(purse).getCurrentAmount();
const { value, brand } = currentAmount;
const recentAmount = await E(purse).getRecentAmount();
const { value, brand } = recentAmount;
const brandPetname = brandMapping.valToPetname.get(brand);
const dehydratedCurrentAmount = dehydrate(currentAmount);
const dehydratedRecentAmount = dehydrate(recentAmount);
const brandBoardId = await E(board).getId(brand);

let depositBoardId;
Expand All @@ -200,8 +200,8 @@ export function makeWallet({
pursePetname,
displayInfo: (issuerRecord && issuerRecord.displayInfo),
value,
currentAmountSlots: dehydratedCurrentAmount,
currentAmount: fillInSlots(dehydratedCurrentAmount),
recentAmountSlots: dehydratedRecentAmount,
recentAmount: fillInSlots(dehydratedRecentAmount),
};
pursesState.set(purseKey, jstate);

Expand Down Expand Up @@ -593,7 +593,7 @@ export function makeWallet({

// Just notice the balance updates for the purse.
observeIteration(
makeAsyncIterableFromNotifier(E(purse).getCurrentAmountNotifier()),
makeAsyncIterableFromNotifier(E(purse).getRecentAmountNotifier()),
{
updateState(_balance) {
updatePursesState(
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp-svelte-wallet/api/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
* @property {Petname} pursePetname the petname for this purse
* @property {any} displayInfo the brand's displayInfo
* @property {any} value the purse's current balance
* @property {any} currentAmountSlots
* @property {any} currentAmount
* @property {any} recentAmountSlots TODO do we also need a deprecated currentAmountSlots?
* @property {any} recentAmount TODO do we also need a deprecated currentAmount?
katelynsills marked this conversation as resolved.
Show resolved Hide resolved
*/

/**
Expand Down
Loading