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