diff options
Diffstat (limited to 'packages/taler-wallet-webextension')
5 files changed, 112 insertions, 147 deletions
diff --git a/packages/taler-wallet-webextension/src/pages/refund.tsx b/packages/taler-wallet-webextension/src/pages/refund.tsx index b34b98f63..1ace50226 100644 --- a/packages/taler-wallet-webextension/src/pages/refund.tsx +++ b/packages/taler-wallet-webextension/src/pages/refund.tsx @@ -37,8 +37,8 @@ function RefundStatusView(props: { talerRefundUri: string }): JSX.Element { try { const result = await wxApi.applyRefund(props.talerRefundUri); setApplied(true); - const r = await wxApi.getPurchaseDetails(result.proposalId); - setPurchaseDetails(r); + // const r = await wxApi.getPurchaseDetails(result.proposalId); + // setPurchaseDetails(r); } catch (e) { console.error(e); setErrMsg(e.message); diff --git a/packages/taler-wallet-webextension/src/pages/tip.tsx b/packages/taler-wallet-webextension/src/pages/tip.tsx index 1f164ad1b..1290037e7 100644 --- a/packages/taler-wallet-webextension/src/pages/tip.tsx +++ b/packages/taler-wallet-webextension/src/pages/tip.tsx @@ -22,79 +22,7 @@ */ import * as React from "react"; -import { acceptTip, getTipStatus } from "../wxApi"; -import { renderAmount, ProgressButton } from "../renderHtml"; -import { useState, useEffect } from "react"; -import { TipStatus } from "taler-wallet-core"; - -function TipDisplay(props: { talerTipUri: string }): JSX.Element { - const [tipStatus, setTipStatus] = useState<TipStatus | undefined>(undefined); - const [discarded, setDiscarded] = useState(false); - const [loading, setLoading] = useState(false); - const [finished, setFinished] = useState(false); - - useEffect(() => { - const doFetch = async (): Promise<void> => { - const ts = await getTipStatus(props.talerTipUri); - setTipStatus(ts); - }; - doFetch(); - }, [props.talerTipUri]); - - if (discarded) { - return <span>You've discarded the tip.</span>; - } - - if (finished) { - return <span>Tip has been accepted!</span>; - } - - if (!tipStatus) { - return <span>Loading ...</span>; - } - - const discard = (): void => { - setDiscarded(true); - }; - - const accept = async (): Promise<void> => { - setLoading(true); - await acceptTip(tipStatus.tipId); - setFinished(true); - }; - - return ( - <div> - <h2>Tip Received!</h2> - <p> - You received a tip of <strong>{renderAmount(tipStatus.amount)}</strong>{" "} - from <span> </span> - <strong>{tipStatus.merchantOrigin}</strong>. - </p> - <p> - The tip is handled by the exchange{" "} - <strong>{tipStatus.exchangeUrl}</strong>. This exchange will charge fees - of <strong>{renderAmount(tipStatus.totalFees)}</strong> for this - operation. - </p> - <form className="pure-form"> - <ProgressButton loading={loading} onClick={() => accept()}> - Accept Tip - </ProgressButton>{" "} - <button className="pure-button" type="button" onClick={() => discard()}> - Discard tip - </button> - </form> - </div> - ); -} export function createTipPage(): JSX.Element { - const url = new URL(document.location.href); - const talerTipUri = url.searchParams.get("talerTipUri"); - if (typeof talerTipUri !== "string") { - throw Error("talerTipUri must be a string"); - } - - return <TipDisplay talerTipUri={talerTipUri} />; + return <span>not implemented</span>; } diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index 455d0b8ae..947b63cea 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -131,61 +131,12 @@ export function getTransactions(): Promise<TransactionsResponse> { } /** - * Return coins to a bank account. - */ -export function returnCoins(args: { - amount: AmountJson; - exchange: string; - senderWire: string; -}): Promise<void> { - return callBackend("return-coins", args); -} - -/** - * Look up a purchase in the wallet database from - * the contract terms hash. - */ -export function getPurchaseDetails( - proposalId: string, -): Promise<PurchaseDetails> { - return callBackend("get-purchase-details", { proposalId }); -} - -/** - * Get the status of processing a tip. - */ -export function getTipStatus(talerTipUri: string): Promise<TipStatus> { - return callBackend("get-tip-status", { talerTipUri }); -} - -/** - * Mark a tip as accepted by the user. - */ -export function acceptTip(talerTipUri: string): Promise<void> { - return callBackend("accept-tip", { talerTipUri }); -} - -/** * Download a refund and accept it. */ export function applyRefund( - refundUrl: string, + talerRefundUri: string, ): Promise<{ contractTermsHash: string; proposalId: string }> { - return callBackend("accept-refund", { refundUrl }); -} - -/** - * Abort a failed payment and try to get a refund. - */ -export function abortFailedPayment(contractTermsHash: string): Promise<void> { - return callBackend("abort-failed-payment", { contractTermsHash }); -} - -/** - * Abort a failed payment and try to get a refund. - */ -export function benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> { - return callBackend("benchmark-crypto", { repetitions }); + return callBackend("applyRefund", { talerRefundUri }); } /** @@ -212,7 +163,7 @@ export function acceptWithdrawal( * Get diagnostics information */ export function getDiagnostics(): Promise<WalletDiagnostics> { - return callBackend("get-diagnostics", {}); + return callBackend("wxGetDiagnostics", {}); } /** @@ -221,14 +172,14 @@ export function getDiagnostics(): Promise<WalletDiagnostics> { export function setExtendedPermissions( value: boolean, ): Promise<ExtendedPermissionsResponse> { - return callBackend("set-extended-permissions", { value }); + return callBackend("wxSetExtendedPermissions", { value }); } /** * Get diagnostics information */ export function getExtendedPermissions(): Promise<ExtendedPermissionsResponse> { - return callBackend("get-extended-permissions", {}); + return callBackend("wxGetExtendedPermissions", {}); } /** diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts index 60d0b6d49..a77b173fe 100644 --- a/packages/taler-wallet-webextension/src/wxBackend.ts +++ b/packages/taler-wallet-webextension/src/wxBackend.ts @@ -37,12 +37,13 @@ import { TalerUriType, makeErrorDetails, TalerErrorCode, + CoreApiResponse, + WalletDiagnostics, + CoreApiResponseSuccess, } from "taler-wallet-core"; import { BrowserHttpLib } from "./browserHttpLib"; import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory"; -const NeedsWallet = Symbol("NeedsWallet"); - /** * Currently active wallet instance. Might be unloaded and * re-instantiated when the database is reset. @@ -60,24 +61,109 @@ const walletInit: OpenedPromise<void> = openPromise<void>(); const notificationPorts: chrome.runtime.Port[] = []; +async function getDiagnostics(): Promise<WalletDiagnostics> { + const manifestData = chrome.runtime.getManifest(); + const errors: string[] = []; + let firefoxIdbProblem = false; + let dbOutdated = false; + try { + await walletInit.promise; + } catch (e) { + errors.push("Error during wallet initialization: " + e); + if ( + currentDatabase === undefined && + outdatedDbVersion === undefined && + isFirefox() + ) { + firefoxIdbProblem = true; + } + } + if (!currentWallet) { + errors.push("Could not create wallet backend."); + } + if (!currentDatabase) { + errors.push("Could not open database"); + } + if (outdatedDbVersion !== undefined) { + errors.push(`Outdated DB version: ${outdatedDbVersion}`); + dbOutdated = true; + } + const diagnostics: WalletDiagnostics = { + walletManifestDisplayVersion: manifestData.version_name || "(undefined)", + walletManifestVersion: manifestData.version, + errors, + firefoxIdbProblem, + dbOutdated, + }; + return diagnostics; +} + async function dispatch( req: any, sender: any, sendResponse: any, ): Promise<void> { - const w = currentWallet; - if (!w) { - sendResponse( - makeErrorDetails( - TalerErrorCode.WALLET_CORE_NOT_AVAILABLE, - "wallet core not available", - {}, - ), - ); - return; + let r: CoreApiResponse; + + const wrapResponse = (result: unknown): CoreApiResponseSuccess => { + return { + type: "response", + id: req.id, + operation: req.operation, + result, + }; + }; + + switch (req.operation) { + case "wxGetDiagnostics": { + r = wrapResponse(await getDiagnostics()); + break; + } + case "wxGetExtendedPermissions": { + const res = await new Promise((resolve, reject) => { + getPermissionsApi().contains(extendedPermissions, (result: boolean) => { + resolve(result); + }); + }); + r = wrapResponse({ newValue: res }); + break; + } + case "wxSetExtendedPermissions": { + const newVal = req.payload.value; + console.log("new extended permissions value", newVal); + if (newVal) { + setupHeaderListener(); + r = wrapResponse({ newValue: true }); + } else { + await new Promise((resolve, reject) => { + getPermissionsApi().remove(extendedPermissions, (rem) => { + console.log("permissions removed:", rem); + resolve(); + }); + }); + r = wrapResponse({ newVal: false }); + } + break; + } + default: + const w = currentWallet; + if (!w) { + r = { + type: "error", + id: req.id, + operation: req.operation, + error: makeErrorDetails( + TalerErrorCode.WALLET_CORE_NOT_AVAILABLE, + "wallet core not available", + {}, + ), + }; + break; + } + r = await w.handleCoreApiRequest(req.operation, req.id, req.payload); + break; } - const r = await w.handleCoreApiRequest(req.operation, req.id, req.payload); try { sendResponse(r); } catch (e) { @@ -188,7 +274,7 @@ try { chrome.runtime.onInstalled.addListener((details) => { console.log("onInstalled with reason", details.reason); if (details.reason === "install") { - const url = chrome.extension.getURL("/welcome.html"); + const url = chrome.extension.getURL("/static/welcome.html"); chrome.tabs.create({ active: true, url: url }); } }); diff --git a/packages/taler-wallet-webextension/static/welcome.html b/packages/taler-wallet-webextension/static/welcome.html index 07ecac707..e0b429f4b 100644 --- a/packages/taler-wallet-webextension/static/welcome.html +++ b/packages/taler-wallet-webextension/static/welcome.html @@ -4,10 +4,10 @@ <meta charset="UTF-8" /> <title>Taler Wallet Installed</title> - <link rel="icon" href="/img/icon.png" /> - <link rel="stylesheet" type="text/css" href="/style/pure.css" /> - <link rel="stylesheet" type="text/css" href="/style/wallet.css" /> - <script src="/pageEntryPoint.js"></script> + <link rel="icon" href="/static/img/icon.png" /> + <link rel="stylesheet" type="text/css" href="/static/style/pure.css" /> + <link rel="stylesheet" type="text/css" href="/static/style/wallet.css" /> + <script src="/dist/pageEntryPoint.js"></script> </head> <body> |