summaryrefslogtreecommitdiff
path: root/src/webex
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-11-20 19:48:43 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-11-20 19:48:43 +0100
commit553da649902f71d5ca34c9a6289ab6b1ef0ba7cb (patch)
tree857c4eb2c39e4a92e71c8a623d3188e6dbbbd1e9 /src/webex
parentfaedf697626dd37f3ac74ad4cac1ec378598bbf3 (diff)
downloadwallet-core-553da649902f71d5ca34c9a6289ab6b1ef0ba7cb.tar.gz
wallet-core-553da649902f71d5ca34c9a6289ab6b1ef0ba7cb.tar.bz2
wallet-core-553da649902f71d5ca34c9a6289ab6b1ef0ba7cb.zip
WIP: simplify DB queries and error handling
Diffstat (limited to 'src/webex')
-rw-r--r--src/webex/messages.ts16
-rw-r--r--src/webex/pages/error.html18
-rw-r--r--src/webex/pages/error.tsx129
-rw-r--r--src/webex/pages/logs.html27
-rw-r--r--src/webex/pages/logs.tsx86
-rw-r--r--src/webex/renderHtml.tsx6
-rw-r--r--src/webex/wxApi.ts32
-rw-r--r--src/webex/wxBackend.ts42
8 files changed, 3 insertions, 353 deletions
diff --git a/src/webex/messages.ts b/src/webex/messages.ts
index 78a1a1fd0..3f6e5cc4a 100644
--- a/src/webex/messages.ts
+++ b/src/webex/messages.ts
@@ -73,14 +73,6 @@ export interface MessageMap {
request: { baseUrl: string };
response: dbTypes.ExchangeRecord;
};
- "currency-info": {
- request: { name: string };
- response: dbTypes.CurrencyRecord;
- };
- "hash-contract": {
- request: { contract: object };
- response: string;
- };
"reserve-creation-info": {
request: { baseUrl: string; amount: AmountJson };
response: walletTypes.ReserveCreationInfo;
@@ -145,14 +137,6 @@ export interface MessageMap {
request: {};
response: void;
};
- "log-and-display-error": {
- request: any;
- response: void;
- };
- "get-report": {
- request: { reportUid: string };
- response: void;
- };
"get-purchase-details": {
request: { contractTermsHash: string };
response: walletTypes.PurchaseDetails;
diff --git a/src/webex/pages/error.html b/src/webex/pages/error.html
deleted file mode 100644
index 51a8fd73a..000000000
--- a/src/webex/pages/error.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<!DOCTYPE html>
-<html>
-
-<head>
- <meta charset="UTF-8">
- <title>Taler Wallet: Error Occured</title>
-
- <link rel="stylesheet" type="text/css" href="../style/wallet.css">
-
- <link rel="icon" href="/img/icon.png">
-
- <script src="/dist/page-common-bundle.js"></script>
- <script src="/dist/error-bundle.js"></script>
-
- <body>
- <div id="container"></div>
- </body>
-</html>
diff --git a/src/webex/pages/error.tsx b/src/webex/pages/error.tsx
deleted file mode 100644
index dee8ce44e..000000000
--- a/src/webex/pages/error.tsx
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- This file is part of TALER
- (C) 2015-2016 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/>
- */
-
-
-/**
- * Page shown to the user to confirm creation
- * of a reserve, usually requested by the bank.
- *
- * @author Florian Dold
- */
-
-
-import * as React from "react";
-import * as ReactDOM from "react-dom";
-import URI = require("urijs");
-
-import * as wxApi from "../wxApi";
-
-import { Collapsible } from "../renderHtml";
-
-interface ErrorProps {
- report: any;
-}
-
-class ErrorView extends React.Component<ErrorProps, { }> {
- render(): JSX.Element {
- const report = this.props.report;
- if (!report) {
- return (
- <div id="main">
- <h1>Error Report Not Found</h1>
- <p>This page is supposed to display an error reported by the GNU Taler wallet,
- but the corresponding error report can't be found.</p>
- <p>Maybe the error occured before the browser was restarted or the wallet was reloaded.</p>
- </div>
- );
- }
- try {
- switch (report.name) {
- case "pay-post-failed": {
- const summary = report.contractTerms.summary || report.contractTerms.order_id;
- return (
- <div id="main">
- <h1>Failed to send payment</h1>
- <p>
- Failed to send payment for <strong>{summary}</strong>{" "}
- to merchant <strong>{report.contractTerms.merchant.name}</strong>.
- </p>
- <p>
- You can <a href={report.contractTerms.fulfillment_url}>retry</a> the payment.{" "}
- If this problem persists, please contact the mechant with the error details below.
- </p>
- <Collapsible initiallyCollapsed={true} title="Error Details">
- <pre>
- {JSON.stringify(report, null, " ")}
- </pre>
- </Collapsible>
- </div>
- );
- }
- default:
- return (
- <div id="main">
- <h1>Unknown Error</h1>
- The GNU Taler wallet reported an unknown error. Here are the details:
- <pre>
- {JSON.stringify(report, null, " ")}
- </pre>
- </div>
- );
- }
- } catch (e) {
- return (
- <div id="main">
- <h1>Error</h1>
- The GNU Taler wallet reported an error. Here are the details:
- <pre>
- {JSON.stringify(report, null, " ")}
- </pre>
- A detailed error report could not be generated:
- <pre>
- {e.toString()}
- </pre>
- </div>
- );
- }
- }
-}
-
-async function main() {
- const url = new URI(document.location.href);
- const query: any = URI.parseQuery(url.query());
-
- const container = document.getElementById("container");
- if (!container) {
- console.error("fatal: can't mount component, countainer missing");
- return;
- }
-
- // report that we'll render, either looked up from the
- // logging module or synthesized here for fixed/fatal errors
- let report;
-
- const reportUid: string = query.reportUid;
- if (!reportUid) {
- report = {
- name: "missing-error",
- };
- } else {
- report = await wxApi.getReport(reportUid);
- }
-
- ReactDOM.render(<ErrorView report={report} />, container);
-}
-
-document.addEventListener("DOMContentLoaded", () => main());
diff --git a/src/webex/pages/logs.html b/src/webex/pages/logs.html
deleted file mode 100644
index 9545269e3..000000000
--- a/src/webex/pages/logs.html
+++ /dev/null
@@ -1,27 +0,0 @@
-<!DOCTYPE html>
-<html>
-
-<head>
- <meta charset="UTF-8">
- <title>Taler Wallet: Logs</title>
-
- <link rel="stylesheet" type="text/css" href="../style/wallet.css">
-
- <link rel="icon" href="/img/icon.png">
-
- <script src="/dist/page-common-bundle.js"></script>
- <script src="/dist/logs-bundle.js"></script>
-
- <style>
- .tree-item {
- margin: 2em;
- border-radius: 5px;
- border: 1px solid gray;
- padding: 1em;
- }
- </style>
-
- <body>
- <div id="container"></div>
- </body>
-</html>
diff --git a/src/webex/pages/logs.tsx b/src/webex/pages/logs.tsx
deleted file mode 100644
index c4fe670a2..000000000
--- a/src/webex/pages/logs.tsx
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- This file is part of TALER
- (C) 2016 Inria
-
- 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/>
- */
-
-/**
- * Show wallet logs.
- *
- * @author Florian Dold
- */
-
-import {
- LogEntry,
- getLogs,
-} from "../../logging";
-
-import * as React from "react";
-import * as ReactDOM from "react-dom";
-
-interface LogViewProps {
- log: LogEntry;
-}
-
-class LogView extends React.Component<LogViewProps, {}> {
- render(): JSX.Element {
- const e = this.props.log;
- return (
- <div className="tree-item">
- <ul>
- <li>level: {e.level}</li>
- <li>msg: {e.msg}</li>
- <li>id: {e.id || "unknown"}</li>
- <li>file: {e.source || "(unknown)"}</li>
- <li>line: {e.line || "(unknown)"}</li>
- <li>col: {e.col || "(unknown)"}</li>
- {(e.detail ? <li> detail: <pre>{e.detail}</pre></li> : [])}
- </ul>
- </div>
- );
- }
-}
-
-interface LogsState {
- logs: LogEntry[]|undefined;
-}
-
-class Logs extends React.Component<{}, LogsState> {
- constructor(props: {}) {
- super({});
- this.update();
- this.state = {} as any;
- }
-
- async update() {
- const logs = await getLogs();
- this.setState({logs});
- }
-
- render(): JSX.Element {
- const logs = this.state.logs;
- if (!logs) {
- return <span>...</span>;
- }
- return (
- <div className="tree-item">
- Logs:
- {logs.map((e) => <LogView log={e} />)}
- </div>
- );
- }
-}
-
-document.addEventListener("DOMContentLoaded", () => {
- ReactDOM.render(<Logs />, document.getElementById("container")!);
-});
diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx
index e2f821058..f2cccfba6 100644
--- a/src/webex/renderHtml.tsx
+++ b/src/webex/renderHtml.tsx
@@ -137,12 +137,12 @@ function AuditorDetailsView(props: {
</p>
);
}
- if (rci.exchangeInfo.auditors.length === 0) {
+ if ((rci.exchangeInfo.details?.auditors ?? []).length === 0) {
return <p>The exchange is not audited by any auditors.</p>;
}
return (
<div>
- {rci.exchangeInfo.auditors.map(a => (
+ {(rci.exchangeInfo.details?.auditors ?? []).map(a => (
<div>
<h3>Auditor {a.auditor_url}</h3>
<p>
@@ -231,7 +231,7 @@ function FeeDetailsView(props: {
<div>
<h3>Overview</h3>
<p>
- Public key: <ExpanderText text={rci.exchangeInfo.masterPublicKey} />
+ Public key: <ExpanderText text={rci.exchangeInfo.details?.masterPublicKey ?? "??"} />
</p>
<p>
{i18n.str`Withdrawal fees:`} {withdrawFee}
diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts
index 39c31ca51..a50672131 100644
--- a/src/webex/wxApi.ts
+++ b/src/webex/wxApi.ts
@@ -123,13 +123,6 @@ export function getCurrencies(): Promise<CurrencyRecord[]> {
}
-/**
- * Get information about a specific currency.
- */
-export function getCurrency(name: string): Promise<CurrencyRecord|null> {
- return callBackend("currency-info", {name});
-}
-
/**
* Get information about a specific exchange.
@@ -225,12 +218,6 @@ export function submitPay(contractTermsHash: string, sessionId: string | undefin
return callBackend("submit-pay", { contractTermsHash, sessionId });
}
-/**
- * Hash a contract. Throws if its not a valid contract.
- */
-export function hashContract(contract: object): Promise<string> {
- return callBackend("hash-contract", { contract });
-}
/**
* Mark a reserve as confirmed.
@@ -285,25 +272,6 @@ export function returnCoins(args: { amount: AmountJson, exchange: string, sender
/**
- * Record an error report and display it in a tabl.
- *
- * If sameTab is set, the error report will be opened in the current tab,
- * otherwise in a new tab.
- */
-export function logAndDisplayError(args: any): Promise<void> {
- return callBackend("log-and-display-error", args);
-}
-
-/**
- * Get an error report from the logging database for the
- * given report UID.
- */
-export function getReport(reportUid: string): Promise<any> {
- return callBackend("get-report", { reportUid });
-}
-
-
-/**
* Look up a purchase in the wallet database from
* the contract terms hash.
*/
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts
index 16cd2a78c..f4decbc60 100644
--- a/src/webex/wxBackend.ts
+++ b/src/webex/wxBackend.ts
@@ -24,7 +24,6 @@
* Imports.
*/
import { BrowserHttpLib } from "../http";
-import * as logging from "../logging";
import { AmountJson } from "../amounts";
import {
ConfirmReserveRequest,
@@ -138,22 +137,6 @@ async function handleMessage(
}
return needsWallet().updateExchangeFromUrl(detail.baseUrl);
}
- case "currency-info": {
- if (!detail.name) {
- return Promise.resolve({ error: "name missing" });
- }
- return needsWallet().getCurrencyRecord(detail.name);
- }
- case "hash-contract": {
- if (!detail.contract) {
- return Promise.resolve({ error: "contract missing" });
- }
- return needsWallet()
- .hashContract(detail.contract)
- .then(hash => {
- return hash;
- });
- }
case "reserve-creation-info": {
if (!detail.baseUrl || typeof detail.baseUrl !== "string") {
return Promise.resolve({ error: "bad url" });
@@ -243,20 +226,6 @@ async function handleMessage(
};
return resp;
}
- case "log-and-display-error":
- logging.storeReport(detail).then(reportUid => {
- const url = chrome.extension.getURL(
- `/src/webex/pages/error.html?reportUid=${reportUid}`,
- );
- if (detail.sameTab && sender && sender.tab && sender.tab.id) {
- chrome.tabs.update(detail.tabId, { url });
- } else {
- chrome.tabs.create({ url });
- }
- });
- return;
- case "get-report":
- return logging.getReport(detail.reportUid);
case "get-purchase-details": {
const contractTermsHash = detail.contractTermsHash;
if (!contractTermsHash) {
@@ -574,17 +543,6 @@ export async function wxMain() {
chrome.runtime.reload();
});
- window.onerror = (m, source, lineno, colno, error) => {
- logging.record(
- "error",
- "".concat(m as any, error as any),
- undefined,
- source || "(unknown)",
- lineno || 0,
- colno || 0,
- );
- };
-
chrome.tabs.query({}, tabs => {
console.log("got tabs", tabs);
for (const tab of tabs) {