fix issues in the webextension refund UI
This commit is contained in:
parent
cda75feb5b
commit
35c83414f9
@ -252,10 +252,7 @@ async function acceptRefundResponse(
|
||||
let queryDone = true;
|
||||
|
||||
if (numNewRefunds === 0) {
|
||||
if (
|
||||
p.autoRefundDeadline &&
|
||||
p.autoRefundDeadline.t_ms > now.t_ms
|
||||
) {
|
||||
if (p.autoRefundDeadline && p.autoRefundDeadline.t_ms > now.t_ms) {
|
||||
queryDone = false;
|
||||
}
|
||||
} else {
|
||||
@ -361,7 +358,7 @@ async function startRefundQuery(
|
||||
export async function applyRefund(
|
||||
ws: InternalWalletState,
|
||||
talerRefundUri: string,
|
||||
): Promise<{ contractTermsHash: string }> {
|
||||
): Promise<{ contractTermsHash: string; proposalId: string }> {
|
||||
const parseResult = parseRefundUri(talerRefundUri);
|
||||
|
||||
console.log("applying refund", parseResult);
|
||||
@ -384,7 +381,10 @@ export async function applyRefund(
|
||||
logger.info("processing purchase for refund");
|
||||
await startRefundQuery(ws, purchase.proposalId);
|
||||
|
||||
return { contractTermsHash: purchase.contractData.contractTermsHash };
|
||||
return {
|
||||
contractTermsHash: purchase.contractData.contractTermsHash,
|
||||
proposalId: purchase.proposalId,
|
||||
};
|
||||
}
|
||||
|
||||
export async function processPurchaseQueryRefund(
|
||||
|
@ -112,7 +112,10 @@ import {
|
||||
import { durationMin, Duration } from "./util/time";
|
||||
import { processRecoupGroup } from "./operations/recoup";
|
||||
import { OperationFailedAndReportedError } from "./operations/errors";
|
||||
import { TransactionsRequest, TransactionsResponse } from "./types/transactions";
|
||||
import {
|
||||
TransactionsRequest,
|
||||
TransactionsResponse,
|
||||
} from "./types/transactions";
|
||||
import { getTransactions } from "./operations/transactions";
|
||||
|
||||
const builtinCurrencies: CurrencyRecord[] = [
|
||||
@ -631,7 +634,7 @@ export class Wallet {
|
||||
*/
|
||||
async applyRefund(
|
||||
talerRefundUri: string,
|
||||
): Promise<{ contractTermsHash: string }> {
|
||||
): Promise<{ contractTermsHash: string; proposalId: string }> {
|
||||
return applyRefund(this.ws, talerRefundUri);
|
||||
}
|
||||
|
||||
@ -719,14 +722,14 @@ export class Wallet {
|
||||
return refuseProposal(this.ws, proposalId);
|
||||
}
|
||||
|
||||
async getPurchaseDetails(hc: string): Promise<PurchaseDetails> {
|
||||
const purchase = await this.db.get(Stores.purchases, hc);
|
||||
async getPurchaseDetails(proposalId: string): Promise<PurchaseDetails> {
|
||||
const purchase = await this.db.get(Stores.purchases, proposalId);
|
||||
if (!purchase) {
|
||||
throw Error("unknown purchase");
|
||||
}
|
||||
const refundsDoneAmounts = Object.values(
|
||||
purchase.refundsDone,
|
||||
).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
|
||||
const refundsDoneAmounts = Object.values(purchase.refundsDone).map((x) =>
|
||||
Amounts.parseOrThrow(x.perm.refund_amount),
|
||||
);
|
||||
const refundsPendingAmounts = Object.values(
|
||||
purchase.refundsPending,
|
||||
).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
|
||||
@ -734,12 +737,12 @@ export class Wallet {
|
||||
...refundsDoneAmounts,
|
||||
...refundsPendingAmounts,
|
||||
]).amount;
|
||||
const refundsDoneFees = Object.values(
|
||||
purchase.refundsDone,
|
||||
).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
|
||||
const refundsPendingFees = Object.values(
|
||||
purchase.refundsPending,
|
||||
).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
|
||||
const refundsDoneFees = Object.values(purchase.refundsDone).map((x) =>
|
||||
Amounts.parseOrThrow(x.perm.refund_amount),
|
||||
);
|
||||
const refundsPendingFees = Object.values(purchase.refundsPending).map((x) =>
|
||||
Amounts.parseOrThrow(x.perm.refund_amount),
|
||||
);
|
||||
const totalRefundFees = Amounts.sum([
|
||||
...refundsDoneFees,
|
||||
...refundsPendingFees,
|
||||
@ -818,7 +821,9 @@ export class Wallet {
|
||||
return coinsJson;
|
||||
}
|
||||
|
||||
async getTransactions(request: TransactionsRequest): Promise<TransactionsResponse> {
|
||||
async getTransactions(
|
||||
request: TransactionsRequest,
|
||||
): Promise<TransactionsResponse> {
|
||||
return getTransactions(this.ws, request);
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ export interface MessageMap {
|
||||
response: void;
|
||||
};
|
||||
"get-purchase-details": {
|
||||
request: { contractTermsHash: string };
|
||||
request: { proposalId: string };
|
||||
response: walletTypes.PurchaseDetails;
|
||||
};
|
||||
"accept-tip": {
|
||||
@ -135,7 +135,7 @@ export interface MessageMap {
|
||||
};
|
||||
"accept-refund": {
|
||||
request: { refundUrl: string };
|
||||
response: string;
|
||||
response: { contractTermsHash: string; proposalId: string };
|
||||
};
|
||||
"abort-failed-payment": {
|
||||
request: { contractTermsHash: string };
|
||||
@ -169,7 +169,7 @@ export interface MessageMap {
|
||||
response: walletTypes.ExtendedPermissionsResponse;
|
||||
};
|
||||
"get-extended-permissions": {
|
||||
request: { };
|
||||
request: {};
|
||||
response: walletTypes.ExtendedPermissionsResponse;
|
||||
};
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import { createPopup } from "./pages/popup";
|
||||
import { createWithdrawPage } from "./pages/withdraw";
|
||||
import { createWelcomePage } from "./pages/welcome";
|
||||
import { createPayPage } from "./pages/pay";
|
||||
import { createRefundPage } from "./pages/refund";
|
||||
|
||||
function main(): void {
|
||||
try {
|
||||
@ -47,6 +48,9 @@ function main(): void {
|
||||
case "pay.html":
|
||||
mainElement = createPayPage();
|
||||
break;
|
||||
case "refund.html":
|
||||
mainElement = createRefundPage();
|
||||
break;
|
||||
default:
|
||||
throw Error(`page '${page}' not implemented`);
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
|
||||
useEffect(() => {
|
||||
const doFetch = async (): Promise<void> => {
|
||||
try {
|
||||
const hc = await wxApi.applyRefund(props.talerRefundUri);
|
||||
const result = await wxApi.applyRefund(props.talerRefundUri);
|
||||
setApplied(true);
|
||||
const r = await wxApi.getPurchaseDetails(hc);
|
||||
const r = await wxApi.getPurchaseDetails(result.proposalId);
|
||||
setPurchaseDetails(r);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
@ -246,9 +246,9 @@ export function returnCoins(args: {
|
||||
* the contract terms hash.
|
||||
*/
|
||||
export function getPurchaseDetails(
|
||||
contractTermsHash: string,
|
||||
proposalId: string,
|
||||
): Promise<PurchaseDetails> {
|
||||
return callBackend("get-purchase-details", { contractTermsHash });
|
||||
return callBackend("get-purchase-details", { proposalId });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,7 +268,9 @@ export function acceptTip(talerTipUri: string): Promise<void> {
|
||||
/**
|
||||
* Download a refund and accept it.
|
||||
*/
|
||||
export function applyRefund(refundUrl: string): Promise<string> {
|
||||
export function applyRefund(
|
||||
refundUrl: string,
|
||||
): Promise<{ contractTermsHash: string; proposalId: string }> {
|
||||
return callBackend("accept-refund", { refundUrl });
|
||||
}
|
||||
|
||||
@ -329,7 +331,9 @@ export function getDiagnostics(): Promise<WalletDiagnostics> {
|
||||
/**
|
||||
* Get diagnostics information
|
||||
*/
|
||||
export function setExtendedPermissions(value: boolean): Promise<ExtendedPermissionsResponse> {
|
||||
export function setExtendedPermissions(
|
||||
value: boolean,
|
||||
): Promise<ExtendedPermissionsResponse> {
|
||||
return callBackend("set-extended-permissions", { value });
|
||||
}
|
||||
|
||||
@ -340,7 +344,6 @@ export function getExtendedPermissions(): Promise<ExtendedPermissionsResponse> {
|
||||
return callBackend("get-extended-permissions", {});
|
||||
}
|
||||
|
||||
|
||||
export function onUpdateNotification(f: () => void): () => void {
|
||||
const port = chrome.runtime.connect({ name: "notifications" });
|
||||
const listener = (): void => {
|
||||
@ -350,4 +353,4 @@ export function onUpdateNotification(f: () => void): () => void {
|
||||
return () => {
|
||||
port.onMessage.removeListener(listener);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -212,11 +212,14 @@ async function handleMessage(
|
||||
return resp;
|
||||
}
|
||||
case "get-purchase-details": {
|
||||
const contractTermsHash = detail.contractTermsHash;
|
||||
if (!contractTermsHash) {
|
||||
throw Error("contractTermsHash missing");
|
||||
const proposalId = detail.proposalId;
|
||||
if (!proposalId) {
|
||||
throw Error("proposalId missing");
|
||||
}
|
||||
return needsWallet().getPurchaseDetails(contractTermsHash);
|
||||
if (typeof proposalId !== "string") {
|
||||
throw Error("proposalId must be a string");
|
||||
}
|
||||
return needsWallet().getPurchaseDetails(proposalId);
|
||||
}
|
||||
case "accept-refund":
|
||||
return needsWallet().applyRefund(detail.refundUrl);
|
||||
|
Loading…
Reference in New Issue
Block a user