diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/android/index.ts | 10 | ||||
-rw-r--r-- | src/headless/taler-wallet-cli.ts | 35 | ||||
-rw-r--r-- | src/types/walletTypes.ts | 18 | ||||
-rw-r--r-- | src/wallet.ts | 15 |
4 files changed, 78 insertions, 0 deletions
diff --git a/src/android/index.ts b/src/android/index.ts index 3ed88e4ba..fcdbdaa6e 100644 --- a/src/android/index.ts +++ b/src/android/index.ts @@ -210,6 +210,16 @@ class AndroidWalletMessageHandler { const wallet = await this.wp.promise; return await wallet.getHistory(); } + case "getExchangeTos": { + const wallet = await this.wp.promise; + const exchangeBaseUrl = args.exchangeBaseUrl; + return wallet.getExchangeTos(exchangeBaseUrl); + } + case "setExchangeTosAccepted": { + const wallet = await this.wp.promise; + await wallet.acceptExchangeTermsOfService(args.exchangeBaseUrl, args.acceptedEtag); + return {}; + } case "retryPendingNow": { const wallet = await this.wp.promise; await wallet.runPending(true); diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index 278489d26..838e56f64 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -373,6 +373,41 @@ exchangesCli }); }); +exchangesCli + .subcommand("exchangesAcceptTosCmd", "accept-tos", { + help: "Accept terms of service.", + }) + .requiredArgument("url", clk.STRING, { + help: "Base URL of the exchange.", + }) + .requiredArgument("etag", clk.STRING, { + help: "ToS version tag to accept", + }) + .action(async (args) => { + await withWallet(args, async (wallet) => { + await wallet.acceptExchangeTermsOfService( + args.exchangesAcceptTosCmd.url, + args.exchangesAcceptTosCmd.etag + ); + }); + }); + + exchangesCli + .subcommand("exchangesTosCmd", "tos", { + help: "Show terms of service.", + }) + .requiredArgument("url", clk.STRING, { + help: "Base URL of the exchange.", + }) + .action(async (args) => { + await withWallet(args, async (wallet) => { + const tosResult = await wallet.getExchangeTos( + args.exchangesTosCmd.url, + ); + console.log(JSON.stringify(tosResult, undefined, 2)); + }); + }); + const advancedCli = walletCli.subcommand("advancedArgs", "advanced", { help: "Subcommands for advanced operations (only use if you know what you're doing!).", diff --git a/src/types/walletTypes.ts b/src/types/walletTypes.ts index d61d04692..4b6d867a2 100644 --- a/src/types/walletTypes.ts +++ b/src/types/walletTypes.ts @@ -513,3 +513,21 @@ export interface ManualWithdrawalDetails { */ paytoUris: string[]; } + +export interface GetExchangeTosResult { + /** + * Markdown version of the current ToS. + */ + tos: string; + + /** + * Version tag of the current ToS. + */ + currentEtag: string; + + /** + * Version tag of the last ToS that the user has accepted, + * if any. + */ + acceptedEtag: string | undefined; +} diff --git a/src/wallet.ts b/src/wallet.ts index 2b804ded7..e04c849d5 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -72,6 +72,7 @@ import { ExchangeListItem, ExchangesListRespose, ManualWithdrawalDetails, + GetExchangeTosResult, } from "./types/walletTypes"; import { Logger } from "./util/logging"; @@ -500,6 +501,20 @@ export class Wallet { } } + async getExchangeTos(exchangeBaseUrl: string): Promise<GetExchangeTosResult> { + const exchange = await this.updateExchangeFromUrl(exchangeBaseUrl); + const tos = exchange.termsOfServiceText; + const currentEtag = exchange.termsOfServiceLastEtag; + if (!tos || !currentEtag) { + throw Error("exchange is in invalid state"); + } + return { + acceptedEtag: exchange.termsOfServiceAcceptedEtag, + currentEtag, + tos, + } + } + /** * Get detailed balance information, sliced by exchange and by currency. */ |