make diagnostics, welcome page and permissions work again
This commit is contained in:
parent
8d72b93a17
commit
1548086f50
@ -241,6 +241,7 @@ export async function getTransactions(
|
|||||||
products: pr.contractData.products,
|
products: pr.contractData.products,
|
||||||
summary: pr.contractData.summary,
|
summary: pr.contractData.summary,
|
||||||
summary_i18n: pr.contractData.summaryI18n,
|
summary_i18n: pr.contractData.summaryI18n,
|
||||||
|
contractTermsHash: pr.contractData.contractTermsHash,
|
||||||
};
|
};
|
||||||
const paymentTransactionId = makeEventId(
|
const paymentTransactionId = makeEventId(
|
||||||
TransactionType.Payment,
|
TransactionType.Payment,
|
||||||
|
@ -226,6 +226,11 @@ export interface PaymentShortInfo {
|
|||||||
*/
|
*/
|
||||||
orderId: string;
|
orderId: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash of the contract terms.
|
||||||
|
*/
|
||||||
|
contractTermsHash: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* More information about the merchant
|
* More information about the merchant
|
||||||
*/
|
*/
|
||||||
|
@ -37,8 +37,8 @@ function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
|
|||||||
try {
|
try {
|
||||||
const result = await wxApi.applyRefund(props.talerRefundUri);
|
const result = await wxApi.applyRefund(props.talerRefundUri);
|
||||||
setApplied(true);
|
setApplied(true);
|
||||||
const r = await wxApi.getPurchaseDetails(result.proposalId);
|
// const r = await wxApi.getPurchaseDetails(result.proposalId);
|
||||||
setPurchaseDetails(r);
|
// setPurchaseDetails(r);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setErrMsg(e.message);
|
setErrMsg(e.message);
|
||||||
|
@ -22,79 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as React from "react";
|
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 {
|
export function createTipPage(): JSX.Element {
|
||||||
const url = new URL(document.location.href);
|
return <span>not implemented</span>;
|
||||||
const talerTipUri = url.searchParams.get("talerTipUri");
|
|
||||||
if (typeof talerTipUri !== "string") {
|
|
||||||
throw Error("talerTipUri must be a string");
|
|
||||||
}
|
|
||||||
|
|
||||||
return <TipDisplay talerTipUri={talerTipUri} />;
|
|
||||||
}
|
}
|
||||||
|
@ -130,62 +130,13 @@ export function getTransactions(): Promise<TransactionsResponse> {
|
|||||||
return callBackend("getTransactions", {});
|
return callBackend("getTransactions", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* Download a refund and accept it.
|
||||||
*/
|
*/
|
||||||
export function applyRefund(
|
export function applyRefund(
|
||||||
refundUrl: string,
|
talerRefundUri: string,
|
||||||
): Promise<{ contractTermsHash: string; proposalId: string }> {
|
): Promise<{ contractTermsHash: string; proposalId: string }> {
|
||||||
return callBackend("accept-refund", { refundUrl });
|
return callBackend("applyRefund", { talerRefundUri });
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -212,7 +163,7 @@ export function acceptWithdrawal(
|
|||||||
* Get diagnostics information
|
* Get diagnostics information
|
||||||
*/
|
*/
|
||||||
export function getDiagnostics(): Promise<WalletDiagnostics> {
|
export function getDiagnostics(): Promise<WalletDiagnostics> {
|
||||||
return callBackend("get-diagnostics", {});
|
return callBackend("wxGetDiagnostics", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,14 +172,14 @@ export function getDiagnostics(): Promise<WalletDiagnostics> {
|
|||||||
export function setExtendedPermissions(
|
export function setExtendedPermissions(
|
||||||
value: boolean,
|
value: boolean,
|
||||||
): Promise<ExtendedPermissionsResponse> {
|
): Promise<ExtendedPermissionsResponse> {
|
||||||
return callBackend("set-extended-permissions", { value });
|
return callBackend("wxSetExtendedPermissions", { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get diagnostics information
|
* Get diagnostics information
|
||||||
*/
|
*/
|
||||||
export function getExtendedPermissions(): Promise<ExtendedPermissionsResponse> {
|
export function getExtendedPermissions(): Promise<ExtendedPermissionsResponse> {
|
||||||
return callBackend("get-extended-permissions", {});
|
return callBackend("wxGetExtendedPermissions", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,12 +37,13 @@ import {
|
|||||||
TalerUriType,
|
TalerUriType,
|
||||||
makeErrorDetails,
|
makeErrorDetails,
|
||||||
TalerErrorCode,
|
TalerErrorCode,
|
||||||
|
CoreApiResponse,
|
||||||
|
WalletDiagnostics,
|
||||||
|
CoreApiResponseSuccess,
|
||||||
} from "taler-wallet-core";
|
} from "taler-wallet-core";
|
||||||
import { BrowserHttpLib } from "./browserHttpLib";
|
import { BrowserHttpLib } from "./browserHttpLib";
|
||||||
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
|
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
|
||||||
|
|
||||||
const NeedsWallet = Symbol("NeedsWallet");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently active wallet instance. Might be unloaded and
|
* Currently active wallet instance. Might be unloaded and
|
||||||
* re-instantiated when the database is reset.
|
* re-instantiated when the database is reset.
|
||||||
@ -60,24 +61,109 @@ const walletInit: OpenedPromise<void> = openPromise<void>();
|
|||||||
|
|
||||||
const notificationPorts: chrome.runtime.Port[] = [];
|
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(
|
async function dispatch(
|
||||||
req: any,
|
req: any,
|
||||||
sender: any,
|
sender: any,
|
||||||
sendResponse: any,
|
sendResponse: any,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const w = currentWallet;
|
let r: CoreApiResponse;
|
||||||
if (!w) {
|
|
||||||
sendResponse(
|
const wrapResponse = (result: unknown): CoreApiResponseSuccess => {
|
||||||
makeErrorDetails(
|
return {
|
||||||
TalerErrorCode.WALLET_CORE_NOT_AVAILABLE,
|
type: "response",
|
||||||
"wallet core not available",
|
id: req.id,
|
||||||
{},
|
operation: req.operation,
|
||||||
),
|
result,
|
||||||
);
|
};
|
||||||
return;
|
};
|
||||||
|
|
||||||
|
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 {
|
try {
|
||||||
sendResponse(r);
|
sendResponse(r);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -188,7 +274,7 @@ try {
|
|||||||
chrome.runtime.onInstalled.addListener((details) => {
|
chrome.runtime.onInstalled.addListener((details) => {
|
||||||
console.log("onInstalled with reason", details.reason);
|
console.log("onInstalled with reason", details.reason);
|
||||||
if (details.reason === "install") {
|
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 });
|
chrome.tabs.create({ active: true, url: url });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Taler Wallet Installed</title>
|
<title>Taler Wallet Installed</title>
|
||||||
|
|
||||||
<link rel="icon" href="/img/icon.png" />
|
<link rel="icon" href="/static/img/icon.png" />
|
||||||
<link rel="stylesheet" type="text/css" href="/style/pure.css" />
|
<link rel="stylesheet" type="text/css" href="/static/style/pure.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="/style/wallet.css" />
|
<link rel="stylesheet" type="text/css" href="/static/style/wallet.css" />
|
||||||
<script src="/pageEntryPoint.js"></script>
|
<script src="/dist/pageEntryPoint.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
Loading…
Reference in New Issue
Block a user