diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-07-28 14:22:35 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-07-28 14:22:35 +0530 |
commit | 4365cd6401713b2e207d8c032c0558487e860154 (patch) | |
tree | f66b4bc5aa9dd7e92b72546e0b2fe79c18ed6573 /src/webex | |
parent | 472307a607b046e32f50b05a8be44c47c4b153d4 (diff) |
towards the new withdrawal API (temporarily breaks WebExtension wallet)
Diffstat (limited to 'src/webex')
-rw-r--r-- | src/webex/messages.ts | 159 | ||||
-rw-r--r-- | src/webex/pages/withdraw.tsx | 42 | ||||
-rw-r--r-- | src/webex/wxApi.ts | 28 | ||||
-rw-r--r-- | src/webex/wxBackend.ts | 32 |
4 files changed, 36 insertions, 225 deletions
diff --git a/src/webex/messages.ts b/src/webex/messages.ts deleted file mode 100644 index 5f63697c1..000000000 --- a/src/webex/messages.ts +++ /dev/null @@ -1,159 +0,0 @@ -/* - This file is part of TALER - (C) 2017 Inria and GNUnet e.V. - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -/** - * Type definitions for messages between content scripts/pages and backend. - */ - -// Messages are already documented in wxApi. -/* tslint:disable:completed-docs */ - -import * as dbTypes from "../types/dbTypes"; -import * as walletTypes from "../types/walletTypes"; - -import { UpgradeResponse } from "./wxApi"; - -/** - * Message type information. - */ -export interface MessageMap { - balances: { - request: {}; - response: walletTypes.WalletBalance; - }; - "dump-db": { - request: {}; - response: any; - }; - "import-db": { - request: { - dump: object; - }; - response: void; - }; - ping: { - request: {}; - response: void; - }; - "reset-db": { - request: {}; - response: void; - }; - "confirm-pay": { - request: { proposalId: string; sessionId?: string }; - response: walletTypes.ConfirmPayResult; - }; - "exchange-info": { - request: { baseUrl: string }; - response: dbTypes.ExchangeRecord; - }; - "get-coins": { - request: { exchangeBaseUrl: string }; - response: any; - }; - "refresh-coin": { - request: { coinPub: string }; - response: any; - }; - "get-currencies": { - request: {}; - response: dbTypes.CurrencyRecord[]; - }; - "update-currency": { - request: { currencyRecord: dbTypes.CurrencyRecord }; - response: void; - }; - "get-exchanges": { - request: {}; - response: dbTypes.ExchangeRecord[]; - }; - "get-reserves": { - request: { exchangeBaseUrl: string }; - response: dbTypes.ReserveRecord[]; - }; - "get-denoms": { - request: { exchangeBaseUrl: string }; - response: dbTypes.DenominationRecord[]; - }; - "check-upgrade": { - request: {}; - response: UpgradeResponse; - }; - "get-sender-wire-infos": { - request: {}; - response: walletTypes.SenderWireInfos; - }; - "return-coins": { - request: {}; - response: void; - }; - "get-purchase-details": { - request: { proposalId: string }; - response: walletTypes.PurchaseDetails; - }; - "accept-tip": { - request: { talerTipUri: string }; - response: void; - }; - "get-tip-status": { - request: { talerTipUri: string }; - response: walletTypes.TipStatus; - }; - "accept-refund": { - request: { refundUrl: string }; - response: { contractTermsHash: string; proposalId: string }; - }; - "abort-failed-payment": { - request: { contractTermsHash: string }; - response: void; - }; - "benchmark-crypto": { - request: { repetitions: number }; - response: walletTypes.BenchmarkResult; - }; - "get-withdraw-details": { - request: { - talerWithdrawUri: string; - maybeSelectedExchange: string | undefined; - }; - response: walletTypes.WithdrawalDetailsResponse; - }; - "accept-withdrawal": { - request: { talerWithdrawUri: string; selectedExchange: string }; - response: walletTypes.AcceptWithdrawalResponse; - }; - "prepare-pay": { - request: { talerPayUri: string }; - response: walletTypes.PreparePayResult; - }; - "get-diagnostics": { - request: {}; - response: walletTypes.WalletDiagnostics; - }; - "set-extended-permissions": { - request: { value: boolean }; - response: walletTypes.ExtendedPermissionsResponse; - }; - "get-extended-permissions": { - request: {}; - response: walletTypes.ExtendedPermissionsResponse; - }; -} - -/** - * String literal types for messages. - */ -export type MessageType = keyof MessageMap; diff --git a/src/webex/pages/withdraw.tsx b/src/webex/pages/withdraw.tsx index 0216cdb4f..4a92704b3 100644 --- a/src/webex/pages/withdraw.tsx +++ b/src/webex/pages/withdraw.tsx @@ -23,20 +23,17 @@ import * as i18n from "../i18n"; -import { WithdrawalDetailsResponse } from "../../types/walletTypes"; - import { WithdrawDetailView, renderAmount } from "../renderHtml"; import React, { useState, useEffect } from "react"; import { - getWithdrawDetails, acceptWithdrawal, onUpdateNotification, } from "../wxApi"; function WithdrawalDialog(props: { talerWithdrawUri: string }): JSX.Element { const [details, setDetails] = useState< - WithdrawalDetailsResponse | undefined + any | undefined >(); const [selectedExchange, setSelectedExchange] = useState< string | undefined @@ -57,24 +54,25 @@ function WithdrawalDialog(props: { talerWithdrawUri: string }): JSX.Element { useEffect(() => { const fetchData = async (): Promise<void> => { - console.log("getting from", talerWithdrawUri); - let d: WithdrawalDetailsResponse | undefined = undefined; - try { - d = await getWithdrawDetails(talerWithdrawUri, selectedExchange); - } catch (e) { - console.error( - `error getting withdraw details for uri ${talerWithdrawUri}, exchange ${selectedExchange}`, - e, - ); - setErrMsg(e.message); - return; - } - console.log("got withdrawDetails", d); - if (!selectedExchange && d.bankWithdrawDetails.suggestedExchange) { - console.log("setting selected exchange"); - setSelectedExchange(d.bankWithdrawDetails.suggestedExchange); - } - setDetails(d); + // FIXME: re-implement with new API + // console.log("getting from", talerWithdrawUri); + // let d: WithdrawalDetailsResponse | undefined = undefined; + // try { + // d = await getWithdrawDetails(talerWithdrawUri, selectedExchange); + // } catch (e) { + // console.error( + // `error getting withdraw details for uri ${talerWithdrawUri}, exchange ${selectedExchange}`, + // e, + // ); + // setErrMsg(e.message); + // return; + // } + // console.log("got withdrawDetails", d); + // if (!selectedExchange && d.bankWithdrawDetails.suggestedExchange) { + // console.log("setting selected exchange"); + // setSelectedExchange(d.bankWithdrawDetails.suggestedExchange); + // } + // setDetails(d); }; fetchData(); }, [selectedExchange, errMsg, selecting, talerWithdrawUri, updateCounter]); diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index de37b3639..99a581007 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -37,14 +37,11 @@ import { WalletBalance, PurchaseDetails, WalletDiagnostics, - WithdrawalDetailsResponse, PreparePayResult, AcceptWithdrawalResponse, ExtendedPermissionsResponse, } from "../types/walletTypes"; -import { MessageMap, MessageType } from "./messages"; - /** * Response with information about available version upgrades. */ @@ -77,11 +74,11 @@ export class WalletApiError extends Error { } } -async function callBackend<T extends MessageType>( - type: T, - detail: MessageMap[T]["request"], -): Promise<MessageMap[T]["response"]> { - return new Promise<MessageMap[T]["response"]>((resolve, reject) => { +async function callBackend( + type: string, + detail: any, +): Promise<any> { + return new Promise<any>((resolve, reject) => { chrome.runtime.sendMessage({ type, detail }, (resp) => { if (chrome.runtime.lastError) { console.log("Error calling backend"); @@ -206,7 +203,7 @@ export function getSenderWireInfos(): Promise<SenderWireInfos> { export function returnCoins(args: { amount: AmountJson; exchange: string; - senderWire: object; + senderWire: string; }): Promise<void> { return callBackend("return-coins", args); } @@ -259,19 +256,6 @@ export function benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> { } /** - * Get details about a withdraw operation. - */ -export function getWithdrawDetails( - talerWithdrawUri: string, - maybeSelectedExchange: string | undefined, -): Promise<WithdrawalDetailsResponse> { - return callBackend("get-withdraw-details", { - talerWithdrawUri, - maybeSelectedExchange, - }); -} - -/** * Get details about a pay operation. */ export function preparePay(talerPayUri: string): Promise<PreparePayResult> { diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 793f4b5d3..39fcf899e 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -35,7 +35,6 @@ import { OpenedPromise, openPromise } from "../util/promiseUtils"; import { classifyTalerUri, TalerUriType } from "../util/taleruri"; import { Wallet } from "../wallet"; import { isFirefox, getPermissionsApi } from "./compat"; -import { MessageType } from "./messages"; import * as wxApi from "./wxApi"; import MessageSender = chrome.runtime.MessageSender; import { Database } from "../util/query"; @@ -62,19 +61,9 @@ const notificationPorts: chrome.runtime.Port[] = []; async function handleMessage( sender: MessageSender, - type: MessageType, + type: string, detail: any, ): Promise<any> { - function assertNotFound(t: never): never { - console.error(`Request type ${t as string} unknown`); - console.error(`Request detail was ${detail}`); - return { - error: { - message: `request type ${t as string} unknown`, - requestType: type, - }, - } as never; - } function needsWallet(): Wallet { if (!currentWallet) { throw NeedsWallet; @@ -204,12 +193,6 @@ async function handleMessage( } return needsWallet().benchmarkCrypto(detail.repetitions); } - case "get-withdraw-details": { - return needsWallet().getWithdrawDetailsForUri( - detail.talerWithdrawUri, - detail.maybeSelectedExchange, - ); - } case "accept-withdrawal": { return needsWallet().acceptWithdrawal( detail.talerWithdrawUri, @@ -280,9 +263,14 @@ async function handleMessage( return { newValue: res }; } default: - // Exhaustiveness check. - // See https://www.typescriptlang.org/docs/handbook/advanced-types.html - return assertNotFound(type); + console.error(`Request type ${type} unknown`); + console.error(`Request detail was ${detail}`); + return { + error: { + message: `request type ${type} unknown`, + requestType: type, + }, + }; } } @@ -354,7 +342,7 @@ function makeSyncWalletRedirect( tabId: number, oldUrl: string, params?: { [name: string]: string | undefined }, -): object { +): Record<string, unknown> { const innerUrl = new URL(chrome.extension.getURL("/" + url)); if (params) { for (const key in params) { |