remove ToS storage
This commit is contained in:
parent
cd9c3a143b
commit
1fcb55c84d
@ -1076,13 +1076,6 @@ export interface KnownBankAccounts {
|
|||||||
accounts: KnownBankAccountsInfo[];
|
accounts: KnownBankAccountsInfo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExchangeTosStatusDetails {
|
|
||||||
acceptedVersion?: string;
|
|
||||||
currentVersion?: string;
|
|
||||||
contentType?: string;
|
|
||||||
content?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wire fee for one wire method
|
* Wire fee for one wire method
|
||||||
*/
|
*/
|
||||||
@ -1253,7 +1246,6 @@ export interface ExchangeFullDetails {
|
|||||||
exchangeBaseUrl: string;
|
exchangeBaseUrl: string;
|
||||||
currency: string;
|
currency: string;
|
||||||
paytoUris: string[];
|
paytoUris: string[];
|
||||||
tos: ExchangeTosStatusDetails;
|
|
||||||
auditors: ExchangeAuditor[];
|
auditors: ExchangeAuditor[];
|
||||||
wireInfo: WireInfo;
|
wireInfo: WireInfo;
|
||||||
denomFees: DenomOperationMap<FeeDescription[]>;
|
denomFees: DenomOperationMap<FeeDescription[]>;
|
||||||
@ -1317,14 +1309,6 @@ const codecForExchangeAuditor = (): Codec<ExchangeAuditor> =>
|
|||||||
.property("denomination_keys", codecForList(codecForAuditorDenomSig()))
|
.property("denomination_keys", codecForList(codecForAuditorDenomSig()))
|
||||||
.build("codecForExchangeAuditor");
|
.build("codecForExchangeAuditor");
|
||||||
|
|
||||||
const codecForExchangeTos = (): Codec<ExchangeTosStatusDetails> =>
|
|
||||||
buildCodecForObject<ExchangeTosStatusDetails>()
|
|
||||||
.property("acceptedVersion", codecOptional(codecForString()))
|
|
||||||
.property("currentVersion", codecOptional(codecForString()))
|
|
||||||
.property("contentType", codecOptional(codecForString()))
|
|
||||||
.property("content", codecOptional(codecForString()))
|
|
||||||
.build("ExchangeTos");
|
|
||||||
|
|
||||||
export const codecForFeeDescriptionPair = (): Codec<FeeDescriptionPair> =>
|
export const codecForFeeDescriptionPair = (): Codec<FeeDescriptionPair> =>
|
||||||
buildCodecForObject<FeeDescriptionPair>()
|
buildCodecForObject<FeeDescriptionPair>()
|
||||||
.property("group", codecForString())
|
.property("group", codecForString())
|
||||||
@ -1357,7 +1341,6 @@ export const codecForExchangeFullDetails = (): Codec<ExchangeFullDetails> =>
|
|||||||
.property("currency", codecForString())
|
.property("currency", codecForString())
|
||||||
.property("exchangeBaseUrl", codecForString())
|
.property("exchangeBaseUrl", codecForString())
|
||||||
.property("paytoUris", codecForList(codecForString()))
|
.property("paytoUris", codecForList(codecForString()))
|
||||||
.property("tos", codecForExchangeTos())
|
|
||||||
.property("auditors", codecForList(codecForExchangeAuditor()))
|
.property("auditors", codecForList(codecForExchangeAuditor()))
|
||||||
.property("wireInfo", codecForWireInfo())
|
.property("wireInfo", codecForWireInfo())
|
||||||
.property("denomFees", codecForFeesByOperations())
|
.property("denomFees", codecForFeesByOperations())
|
||||||
|
@ -2382,13 +2382,6 @@ export const WalletStoresV1 = {
|
|||||||
byReservePub: describeIndex("byReservePub", "reservePub", {}),
|
byReservePub: describeIndex("byReservePub", "reservePub", {}),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
exchangeTos: describeStore(
|
|
||||||
"exchangeTos",
|
|
||||||
describeContents<ExchangeTosRecord>({
|
|
||||||
keyPath: ["exchangeBaseUrl", "etag"],
|
|
||||||
}),
|
|
||||||
{},
|
|
||||||
),
|
|
||||||
config: describeStore(
|
config: describeStore(
|
||||||
"config",
|
"config",
|
||||||
describeContents<ConfigRecord>({ keyPath: "key" }),
|
describeContents<ConfigRecord>({ keyPath: "key" }),
|
||||||
|
@ -157,35 +157,6 @@ export async function getExchangeDetails(
|
|||||||
getExchangeDetails.makeContext = (db: DbAccess<typeof WalletStoresV1>) =>
|
getExchangeDetails.makeContext = (db: DbAccess<typeof WalletStoresV1>) =>
|
||||||
db.mktx((x) => [x.exchanges, x.exchangeDetails]);
|
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<void> {
|
|
||||||
await ws.db
|
|
||||||
.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.tosCurrentEtag = tos.tosEtag;
|
|
||||||
await tx.exchangeDetails.put(d);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a ToS version as accepted by the user.
|
* Mark a ToS version as accepted by the user.
|
||||||
*
|
*
|
||||||
@ -740,7 +711,6 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
const updated = await ws.db
|
const updated = await ws.db
|
||||||
.mktx((x) => [
|
.mktx((x) => [
|
||||||
x.exchanges,
|
x.exchanges,
|
||||||
x.exchangeTos,
|
|
||||||
x.exchangeDetails,
|
x.exchangeDetails,
|
||||||
x.exchangeSignKeys,
|
x.exchangeSignKeys,
|
||||||
x.denominations,
|
x.denominations,
|
||||||
@ -801,21 +771,6 @@ export async function updateExchangeFromUrlHandler(
|
|||||||
const drRowId = await tx.exchangeDetails.put(newDetails);
|
const drRowId = await tx.exchangeDetails.put(newDetails);
|
||||||
checkDbInvariant(typeof drRowId.key === "number");
|
checkDbInvariant(typeof drRowId.key === "number");
|
||||||
|
|
||||||
let tosRecord = await tx.exchangeTos.get([
|
|
||||||
exchangeBaseUrl,
|
|
||||||
tosDownload.tosEtag,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!tosRecord || tosRecord.etag !== existingTosAccepted?.etag) {
|
|
||||||
tosRecord = {
|
|
||||||
etag: tosDownload.tosEtag,
|
|
||||||
exchangeBaseUrl,
|
|
||||||
termsOfServiceContentType: tosDownload.tosContentType,
|
|
||||||
termsOfServiceText: tosDownload.tosText,
|
|
||||||
};
|
|
||||||
await tx.exchangeTos.put(tosRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const sk of keysInfo.signingKeys) {
|
for (const sk of keysInfo.signingKeys) {
|
||||||
// FIXME: validate signing keys before inserting them
|
// FIXME: validate signing keys before inserting them
|
||||||
await tx.exchangeSignKeys.put({
|
await tx.exchangeSignKeys.put({
|
||||||
|
@ -1856,7 +1856,6 @@ export async function getWithdrawalDetailsForUri(
|
|||||||
.mktx((x) => [
|
.mktx((x) => [
|
||||||
x.exchanges,
|
x.exchanges,
|
||||||
x.exchangeDetails,
|
x.exchangeDetails,
|
||||||
x.exchangeTos,
|
|
||||||
x.denominations,
|
x.denominations,
|
||||||
x.operationRetries,
|
x.operationRetries,
|
||||||
])
|
])
|
||||||
|
@ -34,7 +34,6 @@ import {
|
|||||||
Duration,
|
Duration,
|
||||||
ExchangeDetailedResponse,
|
ExchangeDetailedResponse,
|
||||||
ExchangeListItem,
|
ExchangeListItem,
|
||||||
ExchangeTosStatusDetails,
|
|
||||||
ExchangesListResponse,
|
ExchangesListResponse,
|
||||||
FeeDescription,
|
FeeDescription,
|
||||||
GetExchangeTosResult,
|
GetExchangeTosResult,
|
||||||
@ -202,7 +201,6 @@ import {
|
|||||||
provideExchangeRecordInTx,
|
provideExchangeRecordInTx,
|
||||||
updateExchangeFromUrl,
|
updateExchangeFromUrl,
|
||||||
updateExchangeFromUrlHandler,
|
updateExchangeFromUrlHandler,
|
||||||
updateExchangeTermsOfService,
|
|
||||||
} from "./operations/exchanges.js";
|
} from "./operations/exchanges.js";
|
||||||
import { getMerchantInfo } from "./operations/merchants.js";
|
import { getMerchantInfo } from "./operations/merchants.js";
|
||||||
import {
|
import {
|
||||||
@ -557,33 +555,6 @@ async function getExchangeTos(
|
|||||||
): Promise<GetExchangeTosResult> {
|
): Promise<GetExchangeTosResult> {
|
||||||
// FIXME: download ToS in acceptable format if passed!
|
// FIXME: download ToS in acceptable format if passed!
|
||||||
const { exchangeDetails } = await updateExchangeFromUrl(ws, exchangeBaseUrl);
|
const { exchangeDetails } = await updateExchangeFromUrl(ws, exchangeBaseUrl);
|
||||||
const tosDetails = await ws.db
|
|
||||||
.mktx((x) => [x.exchangeTos])
|
|
||||||
.runReadOnly(async (tx) => {
|
|
||||||
return await getExchangeTosStatusDetails(tx, exchangeDetails);
|
|
||||||
});
|
|
||||||
const content = tosDetails.content;
|
|
||||||
const currentEtag = tosDetails.currentVersion;
|
|
||||||
const contentType = tosDetails.contentType;
|
|
||||||
if (
|
|
||||||
content === undefined ||
|
|
||||||
currentEtag === undefined ||
|
|
||||||
contentType === undefined
|
|
||||||
) {
|
|
||||||
throw Error("exchange is in invalid state");
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
acceptedFormat &&
|
|
||||||
acceptedFormat.findIndex((f) => f === contentType) !== -1
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
acceptedEtag: exchangeDetails.tosAccepted?.etag,
|
|
||||||
currentEtag,
|
|
||||||
content,
|
|
||||||
contentType,
|
|
||||||
tosStatus: getExchangeTosStatus(exchangeDetails),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const tosDownload = await downloadTosFromAcceptedFormat(
|
const tosDownload = await downloadTosFromAcceptedFormat(
|
||||||
ws,
|
ws,
|
||||||
@ -592,17 +563,15 @@ async function getExchangeTos(
|
|||||||
acceptedFormat,
|
acceptedFormat,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (tosDownload.tosContentType === contentType) {
|
await ws.db
|
||||||
return {
|
.mktx((x) => [x.exchanges, x.exchangeDetails])
|
||||||
acceptedEtag: exchangeDetails.tosAccepted?.etag,
|
.runReadWrite(async (tx) => {
|
||||||
currentEtag,
|
const d = await getExchangeDetails(tx, exchangeBaseUrl);
|
||||||
content,
|
if (d) {
|
||||||
contentType,
|
d.tosCurrentEtag = tosDownload.tosEtag;
|
||||||
tosStatus: getExchangeTosStatus(exchangeDetails),
|
await tx.exchangeDetails.put(d);
|
||||||
};
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
await updateExchangeTermsOfService(ws, exchangeBaseUrl, tosDownload);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
acceptedEtag: exchangeDetails.tosAccepted?.etag,
|
acceptedEtag: exchangeDetails.tosAccepted?.etag,
|
||||||
@ -683,32 +652,6 @@ async function forgetKnownBankAccounts(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getExchangeTosStatusDetails(
|
|
||||||
tx: GetReadOnlyAccess<{ exchangeTos: typeof WalletStoresV1.exchangeTos }>,
|
|
||||||
exchangeDetails: ExchangeDetailsRecord,
|
|
||||||
): Promise<ExchangeTosStatusDetails> {
|
|
||||||
let exchangeTos = await tx.exchangeTos.get([
|
|
||||||
exchangeDetails.exchangeBaseUrl,
|
|
||||||
exchangeDetails.tosCurrentEtag,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!exchangeTos) {
|
|
||||||
exchangeTos = {
|
|
||||||
etag: "not-available",
|
|
||||||
termsOfServiceContentType: "text/plain",
|
|
||||||
termsOfServiceText: "terms of service unavailable",
|
|
||||||
exchangeBaseUrl: exchangeDetails.exchangeBaseUrl,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
acceptedVersion: exchangeDetails.tosAccepted?.etag,
|
|
||||||
content: exchangeTos.termsOfServiceText,
|
|
||||||
contentType: exchangeTos.termsOfServiceContentType,
|
|
||||||
currentVersion: exchangeTos.etag,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getExchanges(
|
async function getExchanges(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
): Promise<ExchangesListResponse> {
|
): Promise<ExchangesListResponse> {
|
||||||
@ -717,7 +660,6 @@ async function getExchanges(
|
|||||||
.mktx((x) => [
|
.mktx((x) => [
|
||||||
x.exchanges,
|
x.exchanges,
|
||||||
x.exchangeDetails,
|
x.exchangeDetails,
|
||||||
x.exchangeTos,
|
|
||||||
x.denominations,
|
x.denominations,
|
||||||
x.operationRetries,
|
x.operationRetries,
|
||||||
])
|
])
|
||||||
@ -742,12 +684,7 @@ async function getExchangeDetailedInfo(
|
|||||||
): Promise<ExchangeDetailedResponse> {
|
): Promise<ExchangeDetailedResponse> {
|
||||||
//TODO: should we use the forceUpdate parameter?
|
//TODO: should we use the forceUpdate parameter?
|
||||||
const exchange = await ws.db
|
const exchange = await ws.db
|
||||||
.mktx((x) => [
|
.mktx((x) => [x.exchanges, x.exchangeDetails, x.denominations])
|
||||||
x.exchanges,
|
|
||||||
x.exchangeTos,
|
|
||||||
x.exchangeDetails,
|
|
||||||
x.denominations,
|
|
||||||
])
|
|
||||||
.runReadOnly(async (tx) => {
|
.runReadOnly(async (tx) => {
|
||||||
const ex = await tx.exchanges.get(exchangeBaseurl);
|
const ex = await tx.exchanges.get(exchangeBaseurl);
|
||||||
const dp = ex?.detailsPointer;
|
const dp = ex?.detailsPointer;
|
||||||
@ -769,8 +706,6 @@ async function getExchangeDetailedInfo(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tos = await getExchangeTosStatusDetails(tx, exchangeDetails);
|
|
||||||
|
|
||||||
const denominations: DenominationInfo[] = denominationRecords.map((x) =>
|
const denominations: DenominationInfo[] = denominationRecords.map((x) =>
|
||||||
DenominationRecord.toDenomInfo(x),
|
DenominationRecord.toDenomInfo(x),
|
||||||
);
|
);
|
||||||
@ -779,7 +714,6 @@ async function getExchangeDetailedInfo(
|
|||||||
info: {
|
info: {
|
||||||
exchangeBaseUrl: ex.baseUrl,
|
exchangeBaseUrl: ex.baseUrl,
|
||||||
currency,
|
currency,
|
||||||
tos,
|
|
||||||
paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
|
paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
|
||||||
auditors: exchangeDetails.auditors,
|
auditors: exchangeDetails.auditors,
|
||||||
wireInfo: exchangeDetails.wireInfo,
|
wireInfo: exchangeDetails.wireInfo,
|
||||||
|
@ -23,7 +23,6 @@ import {
|
|||||||
ExchangeTosStatus,
|
ExchangeTosStatus,
|
||||||
TalerError,
|
TalerError,
|
||||||
parseWithdrawExchangeUri,
|
parseWithdrawExchangeUri,
|
||||||
stringifyWithdrawUri,
|
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
Loading…
Reference in New Issue
Block a user