From a57fcb144d8de40fe50b825d34a27e415ef3fec3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 14 Oct 2022 22:10:03 +0200 Subject: wallet-core: pull out ToS into separate object store --- .../taler-wallet-core/src/operations/exchanges.ts | 45 +++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts') diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index d3905b74b..6569cb394 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -174,24 +174,40 @@ export async function getExchangeDetails( getExchangeDetails.makeContext = (db: DbAccess) => db.mktx((x) => [x.exchanges, x.exchangeDetails]); +/** + * Update the database based on the download of the terms of service. + */ export async function updateExchangeTermsOfService( ws: InternalWalletState, exchangeBaseUrl: string, tos: ExchangeTosDownloadResult, ): Promise { await ws.db - .mktx((x) => [x.exchanges, x.exchangeDetails]) + .mktx((x) => [x.exchanges, x.exchangeTos, x.exchangeDetails]) .runReadWrite(async (tx) => { const d = await getExchangeDetails(tx, exchangeBaseUrl); + let tosRecord = await tx.exchangeTos.get([exchangeBaseUrl, tos.tosEtag]); + if (!tosRecord) { + tosRecord = { + etag: tos.tosEtag, + exchangeBaseUrl, + termsOfServiceContentType: tos.tosContentType, + termsOfServiceText: tos.tosText, + }; + await tx.exchangeTos.put(tosRecord); + } if (d) { - d.termsOfServiceText = tos.tosText; - d.termsOfServiceContentType = tos.tosContentType; - d.termsOfServiceLastEtag = tos.tosEtag; + d.tosCurrentEtag = tos.tosEtag; await tx.exchangeDetails.put(d); } }); } +/** + * Mark a ToS version as accepted by the user. + * + * @param etag version of the ToS to accept, or current ToS version of not given + */ export async function acceptExchangeTermsOfService( ws: InternalWalletState, exchangeBaseUrl: string, @@ -202,7 +218,10 @@ export async function acceptExchangeTermsOfService( .runReadWrite(async (tx) => { const d = await getExchangeDetails(tx, exchangeBaseUrl); if (d) { - d.termsOfServiceAcceptedEtag = etag; + d.tosAccepted = { + etag: etag || d.tosCurrentEtag, + timestamp: TalerProtocolTimestamp.now(), + }; await tx.exchangeDetails.put(d); } }); @@ -611,7 +630,8 @@ export async function updateExchangeFromUrlHandler( ["text/plain"], ); const tosHasBeenAccepted = - exchangeDetails?.termsOfServiceAcceptedEtag === tosDownload.tosEtag; + exchangeDetails?.tosAccepted && + exchangeDetails.tosAccepted.etag === tosDownload.tosEtag; let recoupGroupId: string | undefined; @@ -647,13 +667,13 @@ export async function updateExchangeFromUrlHandler( globalFees, exchangeBaseUrl: r.baseUrl, wireInfo, - termsOfServiceText: tosDownload.tosText, - termsOfServiceAcceptedEtag: tosHasBeenAccepted - ? tosDownload.tosEtag + tosCurrentEtag: tosDownload.tosContentType, + tosAccepted: tosHasBeenAccepted + ? { + etag: tosDownload.tosEtag, + timestamp: TalerProtocolTimestamp.now(), + } : undefined, - termsOfServiceContentType: tosDownload.tosContentType, - termsOfServiceLastEtag: tosDownload.tosEtag, - termsOfServiceAcceptedTimestamp: TalerProtocolTimestamp.now(), }; // FIXME: only update if pointer got updated r.lastUpdate = TalerProtocolTimestamp.now(); @@ -665,7 +685,6 @@ export async function updateExchangeFromUrlHandler( masterPublicKey: details.masterPublicKey, // FIXME: only change if pointer really changed updateClock: TalerProtocolTimestamp.now(), - protocolVersionRange: keysInfo.protocolVersion, }; await tx.exchanges.put(r); await tx.exchangeDetails.put(details); -- cgit v1.2.3