aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-23 17:05:58 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-23 17:05:58 +0100
commitc8c03e381e252dc3a73a2c35bb1cd2ee24eeaabb (patch)
tree2900ff7be452c2e8b76e18529d8e7d506474abe0
parentaec2c1301edd6c62b7665d4bfbf2087927f9419b (diff)
better types
-rw-r--r--src/webex/messages.ts26
-rw-r--r--src/webex/pages/confirm-contract.tsx20
-rw-r--r--src/webex/wxApi.ts10
-rw-r--r--src/webex/wxBackend.ts2
4 files changed, 36 insertions, 22 deletions
diff --git a/src/webex/messages.ts b/src/webex/messages.ts
index 2219cdf1d..9a7dc8fd4 100644
--- a/src/webex/messages.ts
+++ b/src/webex/messages.ts
@@ -26,6 +26,8 @@ import * as dbTypes from "../dbTypes";
import * as talerTypes from "../talerTypes";
import * as walletTypes from "../walletTypes";
+import { UpgradeResponse } from "./wxApi";
+
/**
* Message type information.
*/
@@ -73,7 +75,7 @@ export interface MessageMap {
};
"query-payment": {
request: { };
- response: void;
+ response: dbTypes.PurchaseRecord;
};
"exchange-info": {
request: { baseUrl: string };
@@ -129,7 +131,7 @@ export interface MessageMap {
};
"withdraw-payback-reserve": {
request: { reservePub: string };
- response: void;
+ response: dbTypes.ReserveRecord[];
};
"get-precoins": {
request: { exchangeBaseUrl: string };
@@ -145,11 +147,11 @@ export interface MessageMap {
};
"check-upgrade": {
request: { };
- response: void;
+ response: UpgradeResponse;
};
"get-sender-wire-infos": {
request: { };
- response: void;
+ response: walletTypes.SenderWireInfos;
};
"return-coins": {
request: { };
@@ -164,20 +166,20 @@ export interface MessageMap {
response: void;
};
"get-purchase": {
- request: any;
- response: void;
+ request: { contractTermsHash: string };
+ response: dbTypes.PurchaseRecord;
};
"get-full-refund-fees": {
request: { refundPermissions: talerTypes.RefundPermission[] };
- response: void;
+ response: AmountJson;
};
"accept-tip": {
request: { tipToken: talerTypes.TipToken };
- response: void;
+ response: walletTypes.TipStatus;
};
"get-tip-status": {
request: { tipToken: talerTypes.TipToken };
- response: void;
+ response: walletTypes.TipStatus;
};
"clear-notification": {
request: { };
@@ -188,12 +190,12 @@ export interface MessageMap {
response: void;
};
"download-proposal": {
- request: any;
- response: void;
+ request: { url: string };
+ response: number;
};
"submit-pay": {
request: { contractTermsHash: string, sessionId: string | undefined };
- response: void;
+ response: walletTypes.ConfirmPayResult;
};
"accept-refund": {
request: { refundUrl: string }
diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx
index 2ec131052..7fe6b9600 100644
--- a/src/webex/pages/confirm-contract.tsx
+++ b/src/webex/pages/confirm-contract.tsx
@@ -49,7 +49,7 @@ interface DetailState {
interface DetailProps {
contractTerms: ContractTerms;
collapsed: boolean;
- exchanges: null|ExchangeRecord[];
+ exchanges: ExchangeRecord[] | undefined;
}
@@ -110,11 +110,11 @@ interface ContractPromptProps {
interface ContractPromptState {
proposalId: number | undefined;
- proposal: ProposalDownloadRecord | null;
+ proposal: ProposalDownloadRecord | undefined;
error: string | null;
payDisabled: boolean;
alreadyPaid: boolean;
- exchanges: null|ExchangeRecord[];
+ exchanges: ExchangeRecord[] | undefined;
/**
* Don't request updates to proposal state while
* this is set to true, to avoid UI flickering
@@ -123,6 +123,7 @@ interface ContractPromptState {
holdCheck: boolean;
payStatus?: CheckPayResult;
replaying: boolean;
+ payInProgress: boolean;
}
class ContractPrompt extends React.Component<ContractPromptProps, ContractPromptState> {
@@ -131,10 +132,11 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
this.state = {
alreadyPaid: false,
error: null,
- exchanges: null,
+ exchanges: undefined,
holdCheck: false,
payDisabled: true,
- proposal: null,
+ payInProgress: false,
+ proposal: undefined,
proposalId: props.proposalId,
replaying: false,
};
@@ -231,7 +233,13 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
return;
}
console.log("confirmPay with", proposalId, "and", this.props.sessionId);
- const payResult = await wxApi.confirmPay(proposalId, this.props.sessionId);
+ let payResult;
+ try {
+ payResult = await wxApi.confirmPay(proposalId, this.props.sessionId);
+ } catch (e) {
+
+ return;
+ }
console.log("payResult", payResult);
document.location.href = payResult.nextUrl;
this.setState({ holdCheck: true });
diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts
index 8a7bf8250..a1b0380b9 100644
--- a/src/webex/wxApi.ts
+++ b/src/webex/wxApi.ts
@@ -29,6 +29,7 @@ import {
DenominationRecord,
ExchangeRecord,
PreCoinRecord,
+ ProposalDownloadRecord,
PurchaseRecord,
ReserveRecord,
} from "../dbTypes";
@@ -71,8 +72,11 @@ export interface UpgradeResponse {
}
-async function callBackend<T extends MessageType>(type: T, detail: MessageMap[T]["request"]): Promise<any> {
- return new Promise<any>((resolve, reject) => {
+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) => {
if (resp && resp.error) {
reject(resp);
@@ -201,7 +205,7 @@ export function payback(coinPub: string): Promise<void> {
/**
* Get a proposal stored in the wallet by its proposal id.
*/
-export function getProposal(proposalId: number) {
+export function getProposal(proposalId: number): Promise<ProposalDownloadRecord | undefined> {
return callBackend("get-proposal", { proposalId });
}
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts
index 30842398b..98b543d28 100644
--- a/src/webex/wxBackend.ts
+++ b/src/webex/wxBackend.ts
@@ -514,7 +514,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
console.log("processing refund");
const uri = new URI(chrome.extension.getURL("/src/webex/pages/refund.html"));
uri.query({ refundUrl: fields.refund_url });
- return { redirectUrl: uri.href() };
+ return { redirectUrl: uri.href };
}
// We need to do some asynchronous operation, we can't directly redirect