diff --git a/packages/dapp-svelte-wallet/api/src/lib-wallet.js b/packages/dapp-svelte-wallet/api/src/lib-wallet.js index 6de6ffcfae5..066cb58faf0 100644 --- a/packages/dapp-svelte-wallet/api/src/lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/src/lib-wallet.js @@ -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) { @@ -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 }; }; @@ -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()]); }; @@ -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} */ diff --git a/packages/dapp-svelte-wallet/api/src/types.js b/packages/dapp-svelte-wallet/api/src/types.js index 8e32f05017c..66e92ea674c 100644 --- a/packages/dapp-svelte-wallet/api/src/types.js +++ b/packages/dapp-svelte-wallet/api/src/types.js @@ -132,6 +132,6 @@ * @property {(brand: Brand) => IssuerRecord} getByBrand * @property {(issuer: Issuer) => boolean} hasByIssuer * @property {(issuer: Issuer) => IssuerRecord} getByIssuer - * @property {(issuerP: ERef, addMeta = x => x) => Promise} initIssuer + * @property {(issuerP: ERef, addMeta?: (x: any) => any) => Promise} initIssuer * @property {(issuerRecord: IssuerRecord) => void } initIssuerByRecord */ diff --git a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js index 9ececdc5c67..5490f257d42 100644 --- a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js @@ -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', @@ -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', @@ -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 }, @@ -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 }, @@ -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', @@ -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 },