From edd3a39a0ca01a299b6d9ebed8d34c29a9c3bb30 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 11 May 2023 14:16:48 +0200 Subject: taler-util: remove deprecated function --- .../src/paths/instance/templates/qr/QrPage.tsx | 2 - packages/taler-util/src/taleruri.ts | 60 ------------- packages/taler-wallet-cli/src/index.ts | 97 +++++++++++----------- 3 files changed, 49 insertions(+), 110 deletions(-) diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx index ab1bcb849..90084f113 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx @@ -19,11 +19,9 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { buildPayto, classifyTalerUri } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; -import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; import { QR } from "../../../../components/exception/QR.js"; import { FormErrors, diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts index bd63fd103..cb0d74a12 100644 --- a/packages/taler-util/src/taleruri.ts +++ b/packages/taler-util/src/taleruri.ts @@ -168,66 +168,6 @@ export enum TalerUriAction { DevExperiment = "dev-experiment", } -/** - * Classify a taler:// URI. - * @deprecated use parseTalerUri - */ -export function classifyTalerUri(s: string): TalerUriType { - const sl = s.toLowerCase(); - if (sl.startsWith("taler://restore/")) { - return TalerUriType.TalerRecovery; - } - if (sl.startsWith("taler+http://restore/")) { - return TalerUriType.TalerRecovery; - } - if (sl.startsWith("taler://pay/")) { - return TalerUriType.TalerPay; - } - if (sl.startsWith("taler+http://pay/")) { - return TalerUriType.TalerPay; - } - if (sl.startsWith("taler://pay-template/")) { - return TalerUriType.TalerPayTemplate; - } - if (sl.startsWith("taler+http://pay-template/")) { - return TalerUriType.TalerPayTemplate; - } - if (sl.startsWith("taler://tip/")) { - return TalerUriType.TalerTip; - } - if (sl.startsWith("taler+http://tip/")) { - return TalerUriType.TalerTip; - } - if (sl.startsWith("taler://refund/")) { - return TalerUriType.TalerRefund; - } - if (sl.startsWith("taler+http://refund/")) { - return TalerUriType.TalerRefund; - } - if (sl.startsWith("taler://withdraw/")) { - return TalerUriType.TalerWithdraw; - } - if (sl.startsWith("taler+http://withdraw/")) { - return TalerUriType.TalerWithdraw; - } - if (sl.startsWith(`taler://${talerActionPayPush}/`)) { - return TalerUriType.TalerPayPush; - } - if (sl.startsWith(`taler+http://${talerActionPayPush}/`)) { - return TalerUriType.TalerPayPush; - } - if (sl.startsWith(`taler://${talerActionPayPull}/`)) { - return TalerUriType.TalerPayPull; - } - if (sl.startsWith(`taler+http://${talerActionPayPull}/`)) { - return TalerUriType.TalerPayPull; - } - if (sl.startsWith("taler://dev-experiment/")) { - return TalerUriType.TalerDevExperiment; - } - return TalerUriType.Unknown; -} - interface TalerUriProtoInfo { innerProto: "http" | "https"; rest: string; diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index 66d2d92e0..f713635a2 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -21,7 +21,6 @@ import { AbsoluteTime, addPaytoQueryParams, AgeRestriction, - classifyTalerUri, codecForList, codecForString, CoreApiResponse, @@ -32,13 +31,14 @@ import { j2s, Logger, parsePaytoUri, + parseTalerUri, PreparePayResultType, RecoveryMergeStrategy, sampleWalletCoreTransactions, setDangerousTimetravel, setGlobalLogLevelFromString, summarizeTalerErrorDetail, - TalerUriType, + TalerUriAction, WalletNotification, } from "@gnu-taler/taler-util"; import { clk } from "@gnu-taler/taler-util/clk"; @@ -639,70 +639,68 @@ walletCli } else { uri = await readlinePrompt("Taler URI: "); } - const uriType = classifyTalerUri(uri); - switch (uriType) { - case TalerUriType.TalerPay: + const parsedTalerUri = parseTalerUri(uri); + if (!parsedTalerUri) { + throw Error("invalid taler URI"); + } + switch (parsedTalerUri.type) { + case TalerUriAction.Pay: await doPay(wallet.client, uri, { alwaysYes: args.handleUri.autoYes, }); break; - case TalerUriType.TalerTip: - { - const res = await wallet.client.call( - WalletApiOperation.PrepareTip, - { - talerTipUri: uri, - }, - ); - console.log("tip status", res); - await wallet.client.call(WalletApiOperation.AcceptTip, { - walletTipId: res.walletTipId, - }); - } + case TalerUriAction.Tip: { + const res = await wallet.client.call(WalletApiOperation.PrepareTip, { + talerTipUri: uri, + }); + console.log("tip status", res); + await wallet.client.call(WalletApiOperation.AcceptTip, { + walletTipId: res.walletTipId, + }); break; - case TalerUriType.TalerRefund: + } + case TalerUriAction.Refund: await wallet.client.call(WalletApiOperation.StartRefundQueryForUri, { talerRefundUri: uri, }); break; - case TalerUriType.TalerWithdraw: - { - const withdrawInfo = await wallet.client.call( - WalletApiOperation.GetWithdrawalDetailsForUri, - { - talerWithdrawUri: uri, - restrictAge: args.handleUri.restrictAge, - }, - ); - console.log("withdrawInfo", withdrawInfo); - const selectedExchange = - args.handleUri.withdrawalExchange ?? - withdrawInfo.defaultExchangeBaseUrl; - if (!selectedExchange) { - console.error( - "no exchange specified for withdrawal (and no exchange suggested by the bank)", - ); - processExit(1); - return; - } - const res = await wallet.client.call( - WalletApiOperation.AcceptBankIntegratedWithdrawal, - { - exchangeBaseUrl: selectedExchange, - talerWithdrawUri: uri, - }, + case TalerUriAction.Withdraw: { + const withdrawInfo = await wallet.client.call( + WalletApiOperation.GetWithdrawalDetailsForUri, + { + talerWithdrawUri: uri, + restrictAge: args.handleUri.restrictAge, + }, + ); + console.log("withdrawInfo", withdrawInfo); + const selectedExchange = + args.handleUri.withdrawalExchange ?? + withdrawInfo.defaultExchangeBaseUrl; + if (!selectedExchange) { + console.error( + "no exchange specified for withdrawal (and no exchange suggested by the bank)", ); - console.log("accept withdrawal response", res); + processExit(1); + return; } + const res = await wallet.client.call( + WalletApiOperation.AcceptBankIntegratedWithdrawal, + { + exchangeBaseUrl: selectedExchange, + talerWithdrawUri: uri, + }, + ); + console.log("accept withdrawal response", res); break; - case TalerUriType.TalerDevExperiment: { + } + case TalerUriAction.DevExperiment: { await wallet.client.call(WalletApiOperation.ApplyDevExperiment, { devExperimentUri: uri, }); break; } default: - console.log(`URI type (${uriType}) not handled`); + console.log(`URI type (${parsedTalerUri}) not handled`); break; } return; @@ -1683,3 +1681,6 @@ async function read(stream: NodeJS.ReadStream) { export function main() { walletCli.run(); } +function classifyTalerUri(uri: string) { + throw new Error("Function not implemented."); +} -- cgit v1.2.3