diff options
Diffstat (limited to 'packages/taler-wallet-webextension')
10 files changed, 91 insertions, 69 deletions
diff --git a/packages/taler-wallet-webextension/src/browserHttpLib.ts b/packages/taler-wallet-webextension/src/browserHttpLib.ts index 42c0c4f00..c568862d9 100644 --- a/packages/taler-wallet-webextension/src/browserHttpLib.ts +++ b/packages/taler-wallet-webextension/src/browserHttpLib.ts @@ -1,5 +1,30 @@ +/* + This file is part of GNU Taler + (C) 2020 Taler Systems S.A. -import { httpLib, OperationFailedError, Logger } from "taler-wallet-core"; + GNU 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. + + GNU 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 + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +/** + * Imports. + */ +import { + OperationFailedError, + Logger, + HttpRequestLibrary, + HttpRequestOptions, + HttpResponse, + Headers, +} from "taler-wallet-core"; import { TalerErrorCode } from "taler-wallet-core/lib/TalerErrorCode"; const logger = new Logger("browserHttpLib"); @@ -8,14 +33,14 @@ const logger = new Logger("browserHttpLib"); * An implementation of the [[HttpRequestLibrary]] using the * browser's XMLHttpRequest. */ -export class BrowserHttpLib implements httpLib.HttpRequestLibrary { +export class BrowserHttpLib implements HttpRequestLibrary { private req( method: string, url: string, requestBody?: any, - options?: httpLib.HttpRequestOptions, - ): Promise<httpLib.HttpResponse> { - return new Promise<httpLib.HttpResponse>((resolve, reject) => { + options?: HttpRequestOptions, + ): Promise<HttpResponse> { + return new Promise<HttpResponse>((resolve, reject) => { const myRequest = new XMLHttpRequest(); myRequest.open(method, url); if (options?.headers) { @@ -87,7 +112,7 @@ export class BrowserHttpLib implements httpLib.HttpRequestLibrary { const arr = headers.trim().split(/[\r\n]+/); // Create a map of header names to values - const headerMap: httpLib.Headers = new httpLib.Headers(); + const headerMap: Headers = new Headers(); arr.forEach(function (line) { const parts = line.split(": "); const headerName = parts.shift(); @@ -98,7 +123,7 @@ export class BrowserHttpLib implements httpLib.HttpRequestLibrary { const value = parts.join(": "); headerMap.set(headerName, value); }); - const resp: httpLib.HttpResponse = { + const resp: HttpResponse = { requestUrl: url, status: myRequest.status, headers: headerMap, @@ -112,19 +137,19 @@ export class BrowserHttpLib implements httpLib.HttpRequestLibrary { }); } - get(url: string, opt?: httpLib.HttpRequestOptions): Promise<httpLib.HttpResponse> { + get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> { return this.req("GET", url, undefined, opt); } postJson( url: string, body: unknown, - opt?: httpLib.HttpRequestOptions, - ): Promise<httpLib.HttpResponse> { + opt?: HttpRequestOptions, + ): Promise<HttpResponse> { return this.req("POST", url, JSON.stringify(body), opt); } stop(): void { // Nothing to do } -}
\ No newline at end of file +} diff --git a/packages/taler-wallet-webextension/src/i18n.tsx b/packages/taler-wallet-webextension/src/i18n.tsx index afbb0e278..bd74316f6 100644 --- a/packages/taler-wallet-webextension/src/i18n.tsx +++ b/packages/taler-wallet-webextension/src/i18n.tsx @@ -23,7 +23,7 @@ */ import React from "react"; -import { i18n as i18nCore } from "taler-wallet-core"; +import * as i18nCore from "taler-wallet-core"; /** * Convert template strings to a msgid */ diff --git a/packages/taler-wallet-webextension/src/pages/pay.tsx b/packages/taler-wallet-webextension/src/pages/pay.tsx index b876a9c58..1e1f91caf 100644 --- a/packages/taler-wallet-webextension/src/pages/pay.tsx +++ b/packages/taler-wallet-webextension/src/pages/pay.tsx @@ -30,10 +30,10 @@ import * as wxApi from "../wxApi"; import React, { useState, useEffect } from "react"; -import { Amounts, AmountJson, walletTypes, talerTypes } from "taler-wallet-core"; +import { Amounts, AmountJson, PreparePayResult, PreparePayResultType, ContractTerms, codecForContractTerms, ConfirmPayResultType } from "taler-wallet-core"; function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { - const [payStatus, setPayStatus] = useState<walletTypes.PreparePayResult | undefined>(); + const [payStatus, setPayStatus] = useState<PreparePayResult | undefined>(); const [payErrMsg, setPayErrMsg] = useState<string | undefined>(""); const [numTries, setNumTries] = useState(0); const [loading, setLoading] = useState(false); @@ -60,7 +60,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { amountEffective = Amounts.parseOrThrow(payStatus.amountEffective); } - if (payStatus.status === walletTypes.PreparePayResultType.AlreadyConfirmed && numTries === 0) { + if (payStatus.status === PreparePayResultType.AlreadyConfirmed && numTries === 0) { return ( <span> You have already paid for this article. Click{" "} @@ -69,10 +69,10 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { ); } - let contractTerms: talerTypes.ContractTerms; + let contractTerms: ContractTerms; try { - contractTerms = talerTypes.codecForContractTerms().decode(payStatus.contractTerms); + contractTerms = codecForContractTerms().decode(payStatus.contractTerms); } catch (e) { // This should never happen, as the wallet is supposed to check the contract terms // before storing them. @@ -109,7 +109,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { try { setLoading(true); const res = await wxApi.confirmPay(proposalId, undefined); - if (res.type !== walletTypes.ConfirmPayResultType.Done) { + if (res.type !== ConfirmPayResultType.Done) { throw Error("payment pending"); } document.location.href = res.nextUrl; diff --git a/packages/taler-wallet-webextension/src/pages/popup.tsx b/packages/taler-wallet-webextension/src/pages/popup.tsx index 72c9f4bcb..61edcfe50 100644 --- a/packages/taler-wallet-webextension/src/pages/popup.tsx +++ b/packages/taler-wallet-webextension/src/pages/popup.tsx @@ -29,9 +29,10 @@ import * as i18n from "../i18n"; import { AmountJson, Amounts, - time, - taleruri, - walletTypes, + BalancesResponse, + Balance, + classifyTalerUri, + TalerUriType, } from "taler-wallet-core"; @@ -174,7 +175,7 @@ function EmptyBalanceView(): JSX.Element { } class WalletBalanceView extends React.Component<any, any> { - private balance?: walletTypes.BalancesResponse; + private balance?: BalancesResponse; private gotError = false; private canceler: (() => void) | undefined = undefined; private unmount = false; @@ -198,7 +199,7 @@ class WalletBalanceView extends React.Component<any, any> { return; } this.updateBalanceRunning = true; - let balance: walletTypes.BalancesResponse; + let balance: BalancesResponse; try { balance = await wxApi.getBalance(); } catch (e) { @@ -221,7 +222,7 @@ class WalletBalanceView extends React.Component<any, any> { this.setState({}); } - formatPending(entry: walletTypes.Balance): JSX.Element { + formatPending(entry: Balance): JSX.Element { let incoming: JSX.Element | undefined; let payment: JSX.Element | undefined; @@ -393,25 +394,25 @@ function makeExtensionUrlWithParams( } function actionForTalerUri(talerUri: string): string | undefined { - const uriType = taleruri.classifyTalerUri(talerUri); + const uriType = classifyTalerUri(talerUri); switch (uriType) { - case taleruri.TalerUriType.TalerWithdraw: + case TalerUriType.TalerWithdraw: return makeExtensionUrlWithParams("withdraw.html", { talerWithdrawUri: talerUri, }); - case taleruri.TalerUriType.TalerPay: + case TalerUriType.TalerPay: return makeExtensionUrlWithParams("pay.html", { talerPayUri: talerUri, }); - case taleruri.TalerUriType.TalerTip: + case TalerUriType.TalerTip: return makeExtensionUrlWithParams("tip.html", { talerTipUri: talerUri, }); - case taleruri.TalerUriType.TalerRefund: + case TalerUriType.TalerRefund: return makeExtensionUrlWithParams("refund.html", { talerRefundUri: talerUri, }); - case taleruri.TalerUriType.TalerNotifyReserve: + case TalerUriType.TalerNotifyReserve: // FIXME: implement break; default: diff --git a/packages/taler-wallet-webextension/src/pages/refund.tsx b/packages/taler-wallet-webextension/src/pages/refund.tsx index 7326dfc88..b34b98f63 100644 --- a/packages/taler-wallet-webextension/src/pages/refund.tsx +++ b/packages/taler-wallet-webextension/src/pages/refund.tsx @@ -21,15 +21,14 @@ */ import React, { useEffect, useState } from "react"; - import * as wxApi from "../wxApi"; import { AmountView } from "../renderHtml"; -import { walletTypes } from "taler-wallet-core"; +import { PurchaseDetails } from "taler-wallet-core"; function RefundStatusView(props: { talerRefundUri: string }): JSX.Element { const [applied, setApplied] = useState(false); const [purchaseDetails, setPurchaseDetails] = useState< - walletTypes.PurchaseDetails | undefined + PurchaseDetails | undefined >(undefined); const [errMsg, setErrMsg] = useState<string | undefined>(undefined); diff --git a/packages/taler-wallet-webextension/src/pages/tip.tsx b/packages/taler-wallet-webextension/src/pages/tip.tsx index 6cf4e1875..1f164ad1b 100644 --- a/packages/taler-wallet-webextension/src/pages/tip.tsx +++ b/packages/taler-wallet-webextension/src/pages/tip.tsx @@ -22,16 +22,13 @@ */ import * as React from "react"; - import { acceptTip, getTipStatus } from "../wxApi"; - import { renderAmount, ProgressButton } from "../renderHtml"; - import { useState, useEffect } from "react"; -import { walletTypes } from "taler-wallet-core"; +import { TipStatus } from "taler-wallet-core"; function TipDisplay(props: { talerTipUri: string }): JSX.Element { - const [tipStatus, setTipStatus] = useState<walletTypes.TipStatus | undefined>(undefined); + const [tipStatus, setTipStatus] = useState<TipStatus | undefined>(undefined); const [discarded, setDiscarded] = useState(false); const [loading, setLoading] = useState(false); const [finished, setFinished] = useState(false); diff --git a/packages/taler-wallet-webextension/src/pages/welcome.tsx b/packages/taler-wallet-webextension/src/pages/welcome.tsx index ff5de572c..00d8ae6c7 100644 --- a/packages/taler-wallet-webextension/src/pages/welcome.tsx +++ b/packages/taler-wallet-webextension/src/pages/welcome.tsx @@ -26,11 +26,11 @@ import { PageLink } from "../renderHtml"; import * as wxApi from "../wxApi"; import { getPermissionsApi } from "../compat"; import { extendedPermissions } from "../permissions"; -import { walletTypes } from "taler-wallet-core"; +import { WalletDiagnostics } from "taler-wallet-core"; function Diagnostics(): JSX.Element | null { const [timedOut, setTimedOut] = useState(false); - const [diagnostics, setDiagnostics] = useState<walletTypes.WalletDiagnostics | undefined>( + const [diagnostics, setDiagnostics] = useState<WalletDiagnostics | undefined>( undefined, ); diff --git a/packages/taler-wallet-webextension/src/renderHtml.tsx b/packages/taler-wallet-webextension/src/renderHtml.tsx index 89f6c12e8..fcf64b6d5 100644 --- a/packages/taler-wallet-webextension/src/renderHtml.tsx +++ b/packages/taler-wallet-webextension/src/renderHtml.tsx @@ -23,7 +23,7 @@ /** * Imports. */ -import { AmountJson, Amounts, time, walletTypes } from "taler-wallet-core"; +import { AmountJson, Amounts, stringifyTimestamp, ExchangeWithdrawDetails } from "taler-wallet-core"; import * as i18n from "./i18n"; import React from "react"; @@ -127,7 +127,7 @@ export class Collapsible extends React.Component< function WireFee(props: { s: string; - rci: walletTypes.ExchangeWithdrawDetails; + rci: ExchangeWithdrawDetails; }): JSX.Element { return ( <> @@ -144,7 +144,7 @@ function WireFee(props: { <tbody> {props.rci.wireFees.feesForType[props.s].map((f) => ( <tr key={f.sig}> - <td>{time.stringifyTimestamp(f.endStamp)}</td> + <td>{stringifyTimestamp(f.endStamp)}</td> <td>{renderAmount(f.wireFee)}</td> <td>{renderAmount(f.closingFee)}</td> </tr> @@ -155,7 +155,7 @@ function WireFee(props: { } function AuditorDetailsView(props: { - rci: walletTypes.ExchangeWithdrawDetails | null; + rci: ExchangeWithdrawDetails | null; }): JSX.Element { const rci = props.rci; console.log("rci", rci); @@ -192,7 +192,7 @@ function AuditorDetailsView(props: { } function FeeDetailsView(props: { - rci: walletTypes.ExchangeWithdrawDetails | null; + rci: ExchangeWithdrawDetails | null; }): JSX.Element { const rci = props.rci; if (!rci) { @@ -222,7 +222,7 @@ function FeeDetailsView(props: { <p> {i18n.str`Rounding loss:`} {overhead} </p> - <p>{i18n.str`Earliest expiration (for deposit): ${time.stringifyTimestamp( + <p>{i18n.str`Earliest expiration (for deposit): ${stringifyTimestamp( rci.earliestDepositExpiration, )}`}</p> <h3>Coin Fees</h3> @@ -268,7 +268,7 @@ function FeeDetailsView(props: { * Shows details about a withdraw request. */ export function WithdrawDetailView(props: { - rci: walletTypes.ExchangeWithdrawDetails | null; + rci: ExchangeWithdrawDetails | null; }): JSX.Element { const rci = props.rci; return ( diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index ee86d90e5..1bcee1285 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -21,7 +21,7 @@ /** * Imports. */ -import { AmountJson, walletTypes } from "taler-wallet-core"; +import { AmountJson, ConfirmPayResult, BalancesResponse, PurchaseDetails, TipStatus, BenchmarkResult, PreparePayResult, AcceptWithdrawalResponse, WalletDiagnostics } from "taler-wallet-core"; export interface ExtendedPermissionsResponse { @@ -101,7 +101,7 @@ export function refresh(coinPub: string): Promise<void> { export function confirmPay( proposalId: string, sessionId: string | undefined, -): Promise<walletTypes.ConfirmPayResult> { +): Promise<ConfirmPayResult> { return callBackend("confirm-pay", { proposalId, sessionId }); } @@ -122,7 +122,7 @@ export function resetDb(): Promise<void> { /** * Get balances for all currencies/exchanges. */ -export function getBalance(): Promise<walletTypes.BalancesResponse> { +export function getBalance(): Promise<BalancesResponse> { return callBackend("balances", {}); } @@ -143,14 +143,14 @@ export function returnCoins(args: { */ export function getPurchaseDetails( proposalId: string, -): Promise<walletTypes.PurchaseDetails> { +): Promise<PurchaseDetails> { return callBackend("get-purchase-details", { proposalId }); } /** * Get the status of processing a tip. */ -export function getTipStatus(talerTipUri: string): Promise<walletTypes.TipStatus> { +export function getTipStatus(talerTipUri: string): Promise<TipStatus> { return callBackend("get-tip-status", { talerTipUri }); } @@ -180,14 +180,14 @@ export function abortFailedPayment(contractTermsHash: string): Promise<void> { /** * Abort a failed payment and try to get a refund. */ -export function benchmarkCrypto(repetitions: number): Promise<walletTypes.BenchmarkResult> { +export function benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> { return callBackend("benchmark-crypto", { repetitions }); } /** * Get details about a pay operation. */ -export function preparePay(talerPayUri: string): Promise<walletTypes.PreparePayResult> { +export function preparePay(talerPayUri: string): Promise<PreparePayResult> { return callBackend("prepare-pay", { talerPayUri }); } @@ -197,7 +197,7 @@ export function preparePay(talerPayUri: string): Promise<walletTypes.PreparePayR export function acceptWithdrawal( talerWithdrawUri: string, selectedExchange: string, -): Promise<walletTypes.AcceptWithdrawalResponse> { +): Promise<AcceptWithdrawalResponse> { return callBackend("accept-withdrawal", { talerWithdrawUri, selectedExchange, @@ -207,7 +207,7 @@ export function acceptWithdrawal( /** * Get diagnostics information */ -export function getDiagnostics(): Promise<walletTypes.WalletDiagnostics> { +export function getDiagnostics(): Promise<WalletDiagnostics> { return callBackend("get-diagnostics", {}); } diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts index 8575c150a..ce024e096 100644 --- a/packages/taler-wallet-webextension/src/wxBackend.ts +++ b/packages/taler-wallet-webextension/src/wxBackend.ts @@ -28,7 +28,7 @@ import * as wxApi from "./wxApi"; import MessageSender = chrome.runtime.MessageSender; import { extendedPermissions } from "./permissions"; -import { Wallet, promiseUtil, db, walletTypes, taleruri, queryLib } from "taler-wallet-core"; +import { Wallet, OpenedPromise, openPromise, deleteTalerDatabase, WALLET_DB_MINOR_VERSION, WalletDiagnostics, openTalerDatabase, Database, classifyTalerUri, TalerUriType } from "taler-wallet-core"; import { BrowserHttpLib } from "./browserHttpLib"; import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory"; @@ -47,7 +47,7 @@ let currentDatabase: IDBDatabase | undefined; */ let outdatedDbVersion: number | undefined; -const walletInit: promiseUtil.OpenedPromise<void> = promiseUtil.openPromise<void>(); +const walletInit: OpenedPromise<void> = openPromise<void>(); const notificationPorts: chrome.runtime.Port[] = []; @@ -78,7 +78,7 @@ async function handleMessage( return Promise.resolve(); } case "reset-db": { - db.deleteTalerDatabase(indexedDB); + deleteTalerDatabase(indexedDB); setBadgeText({ text: "" }); console.log("reset done"); if (!currentWallet) { @@ -148,7 +148,7 @@ async function handleMessage( dbResetRequired = true; } const resp: wxApi.UpgradeResponse = { - currentDbVersion: db.WALLET_DB_MINOR_VERSION.toString(), + currentDbVersion: WALLET_DB_MINOR_VERSION.toString(), dbResetRequired, oldDbVersion: (outdatedDbVersion || "unknown").toString(), }; @@ -217,7 +217,7 @@ async function handleMessage( errors.push(`Outdated DB version: ${outdatedDbVersion}`); dbOutdated = true; } - const diagnostics: walletTypes.WalletDiagnostics = { + const diagnostics: WalletDiagnostics = { walletManifestDisplayVersion: manifestData.version_name || "(undefined)", walletManifestVersion: manifestData.version, @@ -368,7 +368,7 @@ async function reinitWallet(): Promise<void> { currentDatabase = undefined; setBadgeText({ text: "" }); try { - currentDatabase = await db.openTalerDatabase(indexedDB, reinitWallet); + currentDatabase = await openTalerDatabase(indexedDB, reinitWallet); } catch (e) { console.error("could not open database", e); walletInit.reject(e); @@ -377,7 +377,7 @@ async function reinitWallet(): Promise<void> { const http = new BrowserHttpLib(); console.log("setting wallet"); const wallet = new Wallet( - new queryLib.Database(currentDatabase), + new Database(currentDatabase), http, new BrowserCryptoWorkerFactory(), ); @@ -432,9 +432,9 @@ function headerListener( for (const header of details.responseHeaders || []) { if (header.name.toLowerCase() === "taler") { const talerUri = header.value || ""; - const uriType = taleruri.classifyTalerUri(talerUri); + const uriType = classifyTalerUri(talerUri); switch (uriType) { - case taleruri.TalerUriType.TalerWithdraw: + case TalerUriType.TalerWithdraw: return makeSyncWalletRedirect( "withdraw.html", details.tabId, @@ -443,7 +443,7 @@ function headerListener( talerWithdrawUri: talerUri, }, ); - case taleruri.TalerUriType.TalerPay: + case TalerUriType.TalerPay: return makeSyncWalletRedirect( "pay.html", details.tabId, @@ -452,7 +452,7 @@ function headerListener( talerPayUri: talerUri, }, ); - case taleruri.TalerUriType.TalerTip: + case TalerUriType.TalerTip: return makeSyncWalletRedirect( "tip.html", details.tabId, @@ -461,7 +461,7 @@ function headerListener( talerTipUri: talerUri, }, ); - case taleruri.TalerUriType.TalerRefund: + case TalerUriType.TalerRefund: return makeSyncWalletRedirect( "refund.html", details.tabId, @@ -470,7 +470,7 @@ function headerListener( talerRefundUri: talerUri, }, ); - case taleruri.TalerUriType.TalerNotifyReserve: + case TalerUriType.TalerNotifyReserve: Promise.resolve().then(() => { const w = currentWallet; if (!w) { |