diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-31 12:00:04 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-31 12:00:04 +0200 |
commit | c3f47e8f5866838b8c58ad8762d636a2b3ec2217 (patch) | |
tree | 5eef656a13cff01a8114c5f9aa7181f870e7a37d /src | |
parent | 5a7269b20db0371535669c0faa7f1814d967b5ca (diff) |
api simplication
Diffstat (limited to 'src')
-rw-r--r-- | src/dbTypes.ts | 4 | ||||
-rw-r--r-- | src/wallet.ts | 20 | ||||
-rw-r--r-- | src/walletTypes.ts | 20 | ||||
-rw-r--r-- | src/webex/messages.ts | 16 | ||||
-rw-r--r-- | src/webex/wxApi.ts | 28 | ||||
-rw-r--r-- | src/webex/wxBackend.ts | 99 |
6 files changed, 0 insertions, 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<PurchaseRecord | undefined> { - 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<ReserveRecord>( Stores.reserves, diff --git a/src/walletTypes.ts b/src/walletTypes.ts index aec029371..060401c2f 100644 --- a/src/walletTypes.ts +++ b/src/walletTypes.ts @@ -262,26 +262,6 @@ export interface HistoryRecord { } /** - * 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 @@ -216,13 +216,6 @@ export function payback(coinPub: string): Promise<void> { } /** - * Get a proposal stored in the wallet by its proposal id. - */ -export function getProposal(proposalId: number): Promise<ProposalDownloadRecord | undefined> { - return callBackend("get-proposal", { proposalId }); -} - -/** * Check if payment is possible or already done. */ export function checkPay(proposalId: number): Promise<CheckPayResult> { @@ -258,13 +251,6 @@ export function confirmReserve(reservePub: string): Promise<void> { } /** - * Query for a payment by fulfillment URL. - */ -export function queryPaymentByFulfillmentUrl(url: string): Promise<PurchaseRecord> { - return callBackend("query-payment", { url }); -} - -/** * Check upgrade information */ export function checkUpgrade(): Promise<UpgradeResponse> { @@ -336,14 +322,6 @@ export function getPurchase(contractTermsHash: string): Promise<PurchaseRecord> 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<AmountJson> { - return callBackend("get-full-refund-fees", { refundPermissions: args.refundPermissions }); -} - /** * Get the status of processing a tip. @@ -367,12 +345,6 @@ export function clearNotification(): Promise<void> { return callBackend("clear-notification", { }); } -/** - * Trigger taler payment processing (for payment, tipping and refunds). - */ -export function talerPay(msg: any): Promise<void> { - 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<string | undefined> { - 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<chrome.tabs.Tab> { return new Promise((resolve, reject) => { chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab)); |