From c3f47e8f5866838b8c58ad8762d636a2b3ec2217 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 31 Aug 2019 12:00:04 +0200 Subject: api simplication --- src/dbTypes.ts | 4 -- src/wallet.ts | 20 ---------- src/walletTypes.ts | 20 ---------- src/webex/messages.ts | 16 -------- src/webex/wxApi.ts | 28 -------------- src/webex/wxBackend.ts | 99 -------------------------------------------------- 6 files changed, 187 deletions(-) diff --git a/src/dbTypes.ts b/src/dbTypes.ts index 17e7a89b7..0ca2b6262 100644 --- a/src/dbTypes.ts +++ b/src/dbTypes.ts @@ -817,10 +817,6 @@ export interface PurchaseRecord { */ timestamp_refund: number; - /** - * Last session id that we submitted to /pay (if any). - */ - lastSessionSig: string | undefined; /** * Last session signature that we submitted to /pay (if any). diff --git a/src/wallet.ts b/src/wallet.ts index 00a82f92c..e90a6e3db 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -701,7 +701,6 @@ export class Wallet { contractTermsHash: proposal.contractTermsHash, finished: false, lastSessionId: undefined, - lastSessionSig: undefined, merchantSig: proposal.merchantSig, payReq, refundsDone: {}, @@ -1134,25 +1133,6 @@ export class Wallet { return { status: "payment-possible", coinSelection: res }; } - /** - * Retrieve information required to pay for a contract, where the - * contract is identified via the fulfillment url. - */ - async queryPaymentByFulfillmentUrl( - url: string, - ): Promise { - const t = await this.q().getIndexed( - Stores.purchases.fulfillmentUrlIndex, - url, - ); - - if (!t) { - console.log("query for payment failed"); - return undefined; - } - return t; - } - private async sendReserveInfoToBank(reservePub: string) { const reserve = await this.q().get( Stores.reserves, diff --git a/src/walletTypes.ts b/src/walletTypes.ts index aec029371..060401c2f 100644 --- a/src/walletTypes.ts +++ b/src/walletTypes.ts @@ -261,26 +261,6 @@ export interface HistoryRecord { detail: any; } -/** - * Query payment response when the payment was found. - */ -export interface QueryPaymentNotFound { - found: false; -} - -/** - * Query payment response when the payment wasn't found. - */ -export interface QueryPaymentFound { - found: true; - contractTermsHash: string; - contractTerms: ContractTerms; - lastSessionSig?: string; - lastSessionId?: string; - payReq: PayReq; - proposalId: number; -} - /** * Information about all sender wire details known to the wallet, * as well as exchanges that accept these wire types. diff --git a/src/webex/messages.ts b/src/webex/messages.ts index f1046d5c7..7b3041ac2 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -73,10 +73,6 @@ export interface MessageMap { request: { proposalId: number }; response: walletTypes.CheckPayResult; }; - "query-payment": { - request: {}; - response: dbTypes.PurchaseRecord; - }; "exchange-info": { request: { baseUrl: string }; response: dbTypes.ExchangeRecord; @@ -97,10 +93,6 @@ export interface MessageMap { request: {}; response: walletTypes.HistoryRecord[]; }; - "get-proposal": { - request: { proposalId: number }; - response: dbTypes.ProposalDownloadRecord | undefined; - }; "get-coins": { request: { exchangeBaseUrl: string }; response: any; @@ -169,10 +161,6 @@ export interface MessageMap { request: { contractTermsHash: string }; response: dbTypes.PurchaseRecord; }; - "get-full-refund-fees": { - request: { refundPermissions: talerTypes.MerchantRefundPermission[] }; - response: AmountJson; - }; "accept-tip": { request: { talerTipUri: string }; response: void; @@ -185,10 +173,6 @@ export interface MessageMap { request: {}; response: void; }; - "taler-pay": { - request: any; - response: void; - }; "download-proposal": { request: { url: string }; response: number; diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index fd01aed3f..d2e8c94f1 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -215,13 +215,6 @@ export function payback(coinPub: string): Promise { return callBackend("payback-coin", { coinPub }); } -/** - * Get a proposal stored in the wallet by its proposal id. - */ -export function getProposal(proposalId: number): Promise { - return callBackend("get-proposal", { proposalId }); -} - /** * Check if payment is possible or already done. */ @@ -257,13 +250,6 @@ export function confirmReserve(reservePub: string): Promise { return callBackend("confirm-reserve", { reservePub }); } -/** - * Query for a payment by fulfillment URL. - */ -export function queryPaymentByFulfillmentUrl(url: string): Promise { - return callBackend("query-payment", { url }); -} - /** * Check upgrade information */ @@ -336,14 +322,6 @@ export function getPurchase(contractTermsHash: string): Promise return callBackend("get-purchase", { contractTermsHash }); } -/** - * Get the refund fees for a refund permission, including - * subsequent refresh and unrefreshable coins. - */ -export function getFullRefundFees(args: { refundPermissions: MerchantRefundPermission[] }): Promise { - return callBackend("get-full-refund-fees", { refundPermissions: args.refundPermissions }); -} - /** * Get the status of processing a tip. @@ -367,12 +345,6 @@ export function clearNotification(): Promise { return callBackend("clear-notification", { }); } -/** - * Trigger taler payment processing (for payment, tipping and refunds). - */ -export function talerPay(msg: any): Promise { - return callBackend("taler-pay", msg); -} /** * Download a contract. diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 70a7557e3..570a37586 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -139,21 +139,6 @@ function handleMessage( } return needsWallet().checkPay(detail.proposalId); } - case "query-payment": { - if (sender.tab && sender.tab.id) { - rateLimitCache[sender.tab.id]++; - if (rateLimitCache[sender.tab.id] > 10) { - console.warn("rate limit for query-payment exceeded"); - const msg = { - error: "rate limit exceeded for query-payment", - hint: "Check for redirect loops", - rateLimitExceeded: true, - }; - return Promise.resolve(msg); - } - } - return needsWallet().queryPaymentByFulfillmentUrl(detail.url); - } case "exchange-info": { if (!detail.baseUrl) { return Promise.resolve({ error: "bad url" }); @@ -187,9 +172,6 @@ function handleMessage( // TODO: limit history length return needsWallet().getHistory(); } - case "get-proposal": { - return needsWallet().getProposal(detail.proposalId); - } case "get-exchanges": { return needsWallet().getExchanges(); } @@ -289,8 +271,6 @@ function handleMessage( } return needsWallet().getPurchase(contractTermsHash); } - case "get-full-refund-fees": - return needsWallet().getFullRefundFees(detail.refundPermissions); case "accept-refund": return needsWallet().applyRefund(detail.refundUrl); case "get-tip-status": { @@ -311,25 +291,6 @@ function handleMessage( } return needsWallet().abortFailedPayment(detail.contractTermsHash); } - case "taler-pay": { - const senderUrl = sender.url; - if (!senderUrl) { - console.log("can't trigger payment, no sender URL"); - return; - } - const tab = sender.tab; - if (!tab) { - console.log("can't trigger payment, no sender tab"); - return; - } - const tabId = tab.id; - if (typeof tabId !== "string") { - console.log("can't trigger payment, no sender tab id"); - return; - } - talerPay(detail, senderUrl, tabId); - return; - } case "benchmark-crypto": { if (!detail.repetitions) { throw Error("repetitions not given"); @@ -418,66 +379,6 @@ class ChromeNotifier implements Notifier { } } -async function talerPay( - fields: any, - url: string, - tabId: number, -): Promise { - if (!currentWallet) { - console.log("can't handle payment, no wallet"); - return undefined; - } - - const w = currentWallet; - - const goToPayment = (p: PurchaseRecord): string => { - const nextUrl = new URI(p.contractTerms.fulfillment_url); - nextUrl.addSearch("order_id", p.contractTerms.order_id); - if (p.lastSessionSig) { - nextUrl.addSearch("session_sig", p.lastSessionSig); - } - return nextUrl.href(); - }; - - if (fields.resource_url) { - const p = await w.queryPaymentByFulfillmentUrl(fields.resource_url); - console.log("query for resource url", fields.resource_url, "result", p); - if ( - p && - (fields.session_id === undefined || fields.session_id === p.lastSessionId) - ) { - return goToPayment(p); - } - } - if (fields.contract_url) { - const proposalId = await w.downloadProposal(fields.contract_url); - const uri = new URI( - chrome.extension.getURL("/src/webex/pages/confirm-contract.html"), - ); - if (fields.session_id) { - uri.addSearch("sessionId", fields.session_id); - } - uri.addSearch("proposalId", proposalId); - const redirectUrl = uri.href(); - return redirectUrl; - } - if (fields.offer_url) { - return fields.offer_url; - } - if (fields.refund_url) { - console.log("processing refund"); - const uri = new URI( - chrome.extension.getURL("/src/webex/pages/refund.html"), - ); - return uri.query({ refundUrl: fields.refund_url }).href(); - } - if (fields.tip) { - const uri = new URI(chrome.extension.getURL("/src/webex/pages/tip.html")); - return uri.query({ tip_token: fields.tip }).href(); - } - return undefined; -} - function getTab(tabId: number): Promise { return new Promise((resolve, reject) => { chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab)); -- cgit v1.2.3