endpoint / CLI for accepting exchange ToS

This commit is contained in:
Florian Dold 2020-07-11 14:02:17 +05:30
parent afda237e5f
commit c6d80b0128
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 78 additions and 0 deletions

View File

@ -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);

View File

@ -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!).",

View File

@ -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;
}

View File

@ -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.
*/