Skip to content

Commit

Permalink
fix(wallet-backend): get tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Sep 23, 2021
1 parent 25a0a2f commit 1b4a22b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
26 changes: 15 additions & 11 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function makeWallet({
let nowMs;

// Subscribe to the timer service to update our stamp.
assert(localTimerService, 'localTimerService is required');
if (localTimerService) {
observeNotifier(E(localTimerService).makeNotifier(0n, 1000n), {
updateState(bigStamp) {
Expand All @@ -91,17 +90,19 @@ export function makeWallet({
let lastSequence = 0;
const addMeta = record => {
const { meta: oldMeta = {} } = record;
let { sequence, creationStamp } = oldMeta;
if (!sequence) {
const meta = { ...oldMeta };
if (!meta.sequence) {
// Add a sequence number to the record.
lastSequence += 1;
sequence = lastSequence;
meta.sequence = lastSequence;
}
if (!creationStamp) {
// Set the creationStamp to be right now.
creationStamp = nowMs;
if (nowMs !== undefined) {
if (!meta.creationStamp) {
// Set the creationStamp to be right now.
meta.creationStamp = nowMs;
}
meta.updatedStamp = nowMs;
}
const meta = { ...oldMeta, sequence, creationStamp, updatedStamp: nowMs };
return { ...record, meta };
};

Expand Down Expand Up @@ -1194,7 +1195,11 @@ export function makeWallet({
actions,
displayPayment,
});
payments.set(paymentRecord.payment, harden(paymentRecord));
if (payments.has(paymentRecord.payment)) {
payments.set(paymentRecord.payment, harden(paymentRecord));
} else {
payments.init(paymentRecord.payment, harden(paymentRecord));
}
paymentsUpdater.updateState([...payments.values()]);
};

Expand All @@ -1208,14 +1213,13 @@ export function makeWallet({
paymentP,
E(paymentP).getAllegedBrand(),
]);

const depositedPK = makePromiseKit();

/** @type {PaymentRecord} */
let paymentRecord = addMeta({
payment,
brand,
issuer: undefined,
status: undefined,
actions: Far('payment actions', {
async deposit(purseOrPetname = undefined) {
/** @type {Purse} */
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@
* @property {(brand: Brand) => IssuerRecord} getByBrand
* @property {(issuer: Issuer) => boolean} hasByIssuer
* @property {(issuer: Issuer) => IssuerRecord} getByIssuer
* @property {(issuerP: ERef<Issuer>, addMeta = x => x) => Promise<IssuerRecord>} initIssuer
* @property {(issuerP: ERef<Issuer>, addMeta?: (x: any) => any) => Promise<IssuerRecord>} initIssuer
* @property {(issuerRecord: IssuerRecord) => void } initIssuerByRecord
*/
17 changes: 16 additions & 1 deletion packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t
},
},
inviteHandleBoardId: '727995140',
meta: {
sequence: 3,
},
proposalTemplate: {},
requestContext: { dappOrigin: 'unknown' },
instancePetname: 'automaticRefund',
Expand Down Expand Up @@ -625,6 +628,9 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t
},
},
inviteHandleBoardId: '727995140',
meta: {
sequence: 3,
},
proposalTemplate: {},
requestContext: { dappOrigin: 'unknown' },
instancePetname: 'automaticRefund',
Expand Down Expand Up @@ -710,6 +716,9 @@ test('lib-wallet offer methods', async t => {
inviteHandleBoardId: '727995140',
instance,
installation,
meta: {
sequence: 2,
},
proposalTemplate: {
give: { Contribution: { pursePetname: 'Fun budget', value: 1 } },
exit: { onDemand: null },
Expand Down Expand Up @@ -824,6 +833,9 @@ test('lib-wallet offer methods', async t => {
},
},
inviteHandleBoardId: '727995140',
meta: {
sequence: 2,
},
proposalTemplate: {
give: { Contribution: { pursePetname: 'Fun budget', value: 1 } },
exit: { onDemand: null },
Expand Down Expand Up @@ -859,7 +871,7 @@ test('lib-wallet offer methods', async t => {
description: 'getRefund',
handle: {
kind: 'unnamed',
petname: 'unnamed-6',
petname: 'unnamed-7',
},
installation: {
kind: 'unnamed',
Expand All @@ -871,6 +883,9 @@ test('lib-wallet offer methods', async t => {
},
},
inviteHandleBoardId: '371571443',
meta: {
sequence: 5,
},
proposalTemplate: {
give: { Contribution: { pursePetname: 'Fun budget', value: 1 } },
exit: { onDemand: null },
Expand Down

0 comments on commit 1b4a22b

Please sign in to comment.