aboutsummaryrefslogtreecommitdiff
path: root/src/webex
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-03-12 00:44:28 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-03-12 00:44:28 +0530
commit2c52046f0bf358a5e07c53394b3b72d091356cce (patch)
tree8993c992b9c8240ee865671cdfbab380e61af96c /src/webex
parent6e2881fabf74a3c1da8e94dcbe3e68fce6080d9e (diff)
downloadwallet-core-2c52046f0bf358a5e07c53394b3b72d091356cce.tar.xz
full recoup, untested/unfinished first attempt
Diffstat (limited to 'src/webex')
-rw-r--r--src/webex/messages.ts8
-rw-r--r--src/webex/pages/payback.tsx40
-rw-r--r--src/webex/wxApi.ts113
-rw-r--r--src/webex/wxBackend.ts9
4 files changed, 55 insertions, 115 deletions
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<ReserveRecord[] | null>(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 <span>loading ...</span>;
- }
- if (reserves.length === 0) {
- return <span>No reserves with payback available.</span>;
- }
- return (
- <div>
- {reserves.map(r => (
- <div>
- <h2>Reserve for ${renderAmount(r.amountWithdrawRemaining)}</h2>
- <ul>
- <li>Exchange: ${r.exchangeBaseUrl}</li>
- </ul>
- <button onClick={() => withdrawPaybackReserve(r.reservePub)}>
- Withdraw again
- </button>
- </div>
- ))}
- </div>
- );
+ return <div>not implemented</div>;
}
registerMountPage(() => <Payback />);
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<T extends MessageType>(
type: T,
detail: MessageMap[T]["request"],
): Promise<MessageMap[T]["response"]> {
return new Promise<MessageMap[T]["response"]>((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<T extends MessageType>(
});
}
-
/**
* Query the wallet for the coins that would be used to withdraw
* from a given reserve.
*/
-export function getReserveCreationInfo(baseUrl: string,
- amount: AmountJson): Promise<ExchangeWithdrawDetails> {
+export function getReserveCreationInfo(
+ baseUrl: string,
+ amount: AmountJson,
+): Promise<ExchangeWithdrawDetails> {
return callBackend("reserve-creation-info", { baseUrl, amount });
}
-
/**
* Get all exchanges the wallet knows about.
*/
export function getExchanges(): Promise<ExchangeRecord[]> {
- return callBackend("get-exchanges", { });
+ return callBackend("get-exchanges", {});
}
-
/**
* Get all currencies the exchange knows about.
*/
export function getCurrencies(): Promise<CurrencyRecord[]> {
- return callBackend("get-currencies", { });
+ return callBackend("get-currencies", {});
}
-
-
/**
* Get information about a specific exchange.
*/
export function getExchangeInfo(baseUrl: string): Promise<ExchangeRecord> {
- 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<void> {
return callBackend("update-currency", { currencyRecord });
}
-
/**
* Get all reserves the wallet has at an exchange.
*/
@@ -152,23 +146,6 @@ export function getReserves(exchangeBaseUrl: string): Promise<ReserveRecord[]> {
return callBackend("get-reserves", { exchangeBaseUrl });
}
-
-/**
- * Get all reserves for which a payback is available.
- */
-export function getPaybackReserves(): Promise<ReserveRecord[]> {
- return callBackend("get-payback-reserves", { });
-}
-
-
-/**
- * Withdraw the payback that is available for a reserve.
- */
-export function withdrawPaybackReserve(reservePub: string): Promise<ReserveRecord[]> {
- return callBackend("withdraw-payback-reserve", { reservePub });
-}
-
-
/**
* Get all coins withdrawn from the given exchange.
*/
@@ -176,15 +153,15 @@ export function getCoins(exchangeBaseUrl: string): Promise<CoinRecord[]> {
return callBackend("get-coins", { exchangeBaseUrl });
}
-
/**
* Get all denoms offered by the given exchange.
*/
-export function getDenoms(exchangeBaseUrl: string): Promise<DenominationRecord[]> {
+export function getDenoms(
+ exchangeBaseUrl: string,
+): Promise<DenominationRecord[]> {
return callBackend("get-denoms", { exchangeBaseUrl });
}
-
/**
* Start refreshing a coin.
*/
@@ -192,15 +169,16 @@ export function refresh(coinPub: string): Promise<void> {
return callBackend("refresh-coin", { coinPub });
}
-
/**
* Pay for a proposal.
*/
-export function confirmPay(proposalId: string, sessionId: string | undefined): Promise<ConfirmPayResult> {
+export function confirmPay(
+ proposalId: string,
+ sessionId: string | undefined,
+): Promise<ConfirmPayResult> {
return callBackend("confirm-pay", { proposalId, sessionId });
}
-
/**
* Mark a reserve as confirmed.
*/
@@ -212,13 +190,17 @@ export function confirmReserve(reservePub: string): Promise<void> {
* Check upgrade information
*/
export function checkUpgrade(): Promise<UpgradeResponse> {
- return callBackend("check-upgrade", { });
+ return callBackend("check-upgrade", {});
}
/**
* Create a reserve.
*/
-export function createReserve(args: { amount: AmountJson, exchange: string, senderWire?: string }): Promise<any> {
+export function createReserve(args: {
+ amount: AmountJson;
+ exchange: string;
+ senderWire?: string;
+}): Promise<any> {
return callBackend("create-reserve", args);
}
@@ -226,42 +208,45 @@ export function createReserve(args: { amount: AmountJson, exchange: string, send
* Reset database
*/
export function resetDb(): Promise<void> {
- return callBackend("reset-db", { });
+ return callBackend("reset-db", {});
}
/**
* Get balances for all currencies/exchanges.
*/
export function getBalance(): Promise<WalletBalance> {
- return callBackend("balances", { });
+ return callBackend("balances", {});
}
-
/**
* Get possible sender wire infos for getting money
* wired from an exchange.
*/
export function getSenderWireInfos(): Promise<SenderWireInfos> {
- 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<void> {
+export function returnCoins(args: {
+ amount: AmountJson;
+ exchange: string;
+ senderWire: object;
+}): Promise<void> {
return callBackend("return-coins", args);
}
-
/**
* Look up a purchase in the wallet database from
* the contract terms hash.
*/
-export function getPurchaseDetails(contractTermsHash: string): Promise<PurchaseDetails> {
+export function getPurchaseDetails(
+ contractTermsHash: string,
+): Promise<PurchaseDetails> {
return callBackend("get-purchase-details", { contractTermsHash });
}
-
/**
* Get the status of processing a tip.
*/
@@ -276,7 +261,6 @@ export function acceptTip(talerTipUri: string): Promise<void> {
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<BenchmarkResult> {
/**
* 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"));