From 2c52046f0bf358a5e07c53394b3b72d091356cce Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 12 Mar 2020 00:44:28 +0530 Subject: full recoup, untested/unfinished first attempt --- src/webex/messages.ts | 8 ---- src/webex/pages/payback.tsx | 40 +--------------- src/webex/wxApi.ts | 113 +++++++++++++++++++++----------------------- src/webex/wxBackend.ts | 9 ---- 4 files changed, 55 insertions(+), 115 deletions(-) (limited to 'src/webex') diff --git a/src/webex/messages.ts b/src/webex/messages.ts index 132c8c58d..7672fcb4b 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -106,14 +106,6 @@ export interface MessageMap { request: { exchangeBaseUrl: string }; response: dbTypes.ReserveRecord[]; }; - "get-payback-reserves": { - request: {}; - response: dbTypes.ReserveRecord[]; - }; - "withdraw-payback-reserve": { - request: { reservePub: string }; - response: dbTypes.ReserveRecord[]; - }; "get-denoms": { request: { exchangeBaseUrl: string }; response: dbTypes.DenominationRecord[]; diff --git a/src/webex/pages/payback.tsx b/src/webex/pages/payback.tsx index 2601887b0..96d43ff49 100644 --- a/src/webex/pages/payback.tsx +++ b/src/webex/pages/payback.tsx @@ -25,49 +25,11 @@ */ import { ReserveRecord } from "../../types/dbTypes"; import { renderAmount, registerMountPage } from "../renderHtml"; -import { getPaybackReserves, withdrawPaybackReserve } from "../wxApi"; import * as React from "react"; import { useState } from "react"; function Payback() { - const [reserves, setReserves] = useState(null); - - useState(() => { - const update = async () => { - const r = await getPaybackReserves(); - setReserves(r); - }; - - const port = chrome.runtime.connect(); - port.onMessage.addListener((msg: any) => { - if (msg.notify) { - console.log("got notified"); - update(); - } - }); - }); - - if (!reserves) { - return loading ...; - } - if (reserves.length === 0) { - return No reserves with payback available.; - } - return ( -
- {reserves.map(r => ( -
-

Reserve for ${renderAmount(r.amountWithdrawRemaining)}

-
    -
  • Exchange: ${r.exchangeBaseUrl}
  • -
- -
- ))} -
- ); + return
not implemented
; } registerMountPage(() => ); diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index 7464b1f74..5edd1907b 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -18,7 +18,6 @@ * Interface to the wallet through WebExtension messaging. */ - /** * Imports. */ @@ -28,7 +27,6 @@ import { CurrencyRecord, DenominationRecord, ExchangeRecord, - PlanchetRecord, ReserveRecord, } from "../types/dbTypes"; import { @@ -44,7 +42,6 @@ import { import { MessageMap, MessageType } from "./messages"; - /** * Response with information about available version upgrades. */ @@ -66,7 +63,6 @@ export interface UpgradeResponse { oldDbVersion: string; } - /** * Error thrown when the function from the backend (via RPC) threw an error. */ @@ -78,19 +74,22 @@ export class WalletApiError extends Error { } } - async function callBackend( type: T, detail: MessageMap[T]["request"], ): Promise { return new Promise((resolve, reject) => { - chrome.runtime.sendMessage({ type, detail }, (resp) => { + chrome.runtime.sendMessage({ type, detail }, resp => { if (chrome.runtime.lastError) { console.log("Error calling backend"); - reject(new Error(`Error contacting backend: chrome.runtime.lastError.message`)); + reject( + new Error( + `Error contacting backend: chrome.runtime.lastError.message`, + ), + ); } if (typeof resp === "object" && resp && resp.error) { - console.warn("response error:", resp) + console.warn("response error:", resp); const e = new WalletApiError(resp.error.message, resp.error); reject(e); } else { @@ -100,42 +99,38 @@ async function callBackend( }); } - /** * Query the wallet for the coins that would be used to withdraw * from a given reserve. */ -export function getReserveCreationInfo(baseUrl: string, - amount: AmountJson): Promise { +export function getReserveCreationInfo( + baseUrl: string, + amount: AmountJson, +): Promise { return callBackend("reserve-creation-info", { baseUrl, amount }); } - /** * Get all exchanges the wallet knows about. */ export function getExchanges(): Promise { - return callBackend("get-exchanges", { }); + return callBackend("get-exchanges", {}); } - /** * Get all currencies the exchange knows about. */ export function getCurrencies(): Promise { - return callBackend("get-currencies", { }); + return callBackend("get-currencies", {}); } - - /** * Get information about a specific exchange. */ export function getExchangeInfo(baseUrl: string): Promise { - return callBackend("exchange-info", {baseUrl}); + return callBackend("exchange-info", { baseUrl }); } - /** * Replace an existing currency record with the one given. The currency to * replace is specified inside the currency record. @@ -144,7 +139,6 @@ export function updateCurrency(currencyRecord: CurrencyRecord): Promise { return callBackend("update-currency", { currencyRecord }); } - /** * Get all reserves the wallet has at an exchange. */ @@ -152,23 +146,6 @@ export function getReserves(exchangeBaseUrl: string): Promise { return callBackend("get-reserves", { exchangeBaseUrl }); } - -/** - * Get all reserves for which a payback is available. - */ -export function getPaybackReserves(): Promise { - return callBackend("get-payback-reserves", { }); -} - - -/** - * Withdraw the payback that is available for a reserve. - */ -export function withdrawPaybackReserve(reservePub: string): Promise { - return callBackend("withdraw-payback-reserve", { reservePub }); -} - - /** * Get all coins withdrawn from the given exchange. */ @@ -176,15 +153,15 @@ export function getCoins(exchangeBaseUrl: string): Promise { return callBackend("get-coins", { exchangeBaseUrl }); } - /** * Get all denoms offered by the given exchange. */ -export function getDenoms(exchangeBaseUrl: string): Promise { +export function getDenoms( + exchangeBaseUrl: string, +): Promise { return callBackend("get-denoms", { exchangeBaseUrl }); } - /** * Start refreshing a coin. */ @@ -192,15 +169,16 @@ export function refresh(coinPub: string): Promise { return callBackend("refresh-coin", { coinPub }); } - /** * Pay for a proposal. */ -export function confirmPay(proposalId: string, sessionId: string | undefined): Promise { +export function confirmPay( + proposalId: string, + sessionId: string | undefined, +): Promise { return callBackend("confirm-pay", { proposalId, sessionId }); } - /** * Mark a reserve as confirmed. */ @@ -212,13 +190,17 @@ export function confirmReserve(reservePub: string): Promise { * Check upgrade information */ export function checkUpgrade(): Promise { - return callBackend("check-upgrade", { }); + return callBackend("check-upgrade", {}); } /** * Create a reserve. */ -export function createReserve(args: { amount: AmountJson, exchange: string, senderWire?: string }): Promise { +export function createReserve(args: { + amount: AmountJson; + exchange: string; + senderWire?: string; +}): Promise { return callBackend("create-reserve", args); } @@ -226,42 +208,45 @@ export function createReserve(args: { amount: AmountJson, exchange: string, send * Reset database */ export function resetDb(): Promise { - return callBackend("reset-db", { }); + return callBackend("reset-db", {}); } /** * Get balances for all currencies/exchanges. */ export function getBalance(): Promise { - return callBackend("balances", { }); + return callBackend("balances", {}); } - /** * Get possible sender wire infos for getting money * wired from an exchange. */ export function getSenderWireInfos(): Promise { - return callBackend("get-sender-wire-infos", { }); + return callBackend("get-sender-wire-infos", {}); } /** * Return coins to a bank account. */ -export function returnCoins(args: { amount: AmountJson, exchange: string, senderWire: object }): Promise { +export function returnCoins(args: { + amount: AmountJson; + exchange: string; + senderWire: object; +}): Promise { return callBackend("return-coins", args); } - /** * Look up a purchase in the wallet database from * the contract terms hash. */ -export function getPurchaseDetails(contractTermsHash: string): Promise { +export function getPurchaseDetails( + contractTermsHash: string, +): Promise { return callBackend("get-purchase-details", { contractTermsHash }); } - /** * Get the status of processing a tip. */ @@ -276,7 +261,6 @@ export function acceptTip(talerTipUri: string): Promise { return callBackend("accept-tip", { talerTipUri }); } - /** * Download a refund and accept it. */ @@ -291,7 +275,6 @@ export function abortFailedPayment(contractTermsHash: string) { return callBackend("abort-failed-payment", { contractTermsHash }); } - /** * Abort a failed payment and try to get a refund. */ @@ -302,8 +285,14 @@ export function benchmarkCrypto(repetitions: number): Promise { /** * Get details about a withdraw operation. */ -export function getWithdrawDetails(talerWithdrawUri: string, maybeSelectedExchange: string | undefined) { - return callBackend("get-withdraw-details", { talerWithdrawUri, maybeSelectedExchange }); +export function getWithdrawDetails( + talerWithdrawUri: string, + maybeSelectedExchange: string | undefined, +) { + return callBackend("get-withdraw-details", { + talerWithdrawUri, + maybeSelectedExchange, + }); } /** @@ -316,8 +305,14 @@ export function preparePay(talerPayUri: string) { /** * Get details about a withdraw operation. */ -export function acceptWithdrawal(talerWithdrawUri: string, selectedExchange: string) { - return callBackend("accept-withdrawal", { talerWithdrawUri, selectedExchange }); +export function acceptWithdrawal( + talerWithdrawUri: string, + selectedExchange: string, +) { + return callBackend("accept-withdrawal", { + talerWithdrawUri, + selectedExchange, + }); } /** diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index faf917f86..248e6dfba 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -148,15 +148,6 @@ async function handleMessage( } return needsWallet().getReserves(detail.exchangeBaseUrl); } - case "get-payback-reserves": { - return needsWallet().getPaybackReserves(); - } - case "withdraw-payback-reserve": { - if (typeof detail.reservePub !== "string") { - return Promise.reject(Error("reservePub missing")); - } - throw Error("not implemented"); - } case "get-coins": { if (typeof detail.exchangeBaseUrl !== "string") { return Promise.reject(Error("exchangBaseUrl missing")); -- cgit v1.2.3