better types
This commit is contained in:
parent
aec2c1301e
commit
c8c03e381e
@ -26,6 +26,8 @@ import * as dbTypes from "../dbTypes";
|
|||||||
import * as talerTypes from "../talerTypes";
|
import * as talerTypes from "../talerTypes";
|
||||||
import * as walletTypes from "../walletTypes";
|
import * as walletTypes from "../walletTypes";
|
||||||
|
|
||||||
|
import { UpgradeResponse } from "./wxApi";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message type information.
|
* Message type information.
|
||||||
*/
|
*/
|
||||||
@ -73,7 +75,7 @@ export interface MessageMap {
|
|||||||
};
|
};
|
||||||
"query-payment": {
|
"query-payment": {
|
||||||
request: { };
|
request: { };
|
||||||
response: void;
|
response: dbTypes.PurchaseRecord;
|
||||||
};
|
};
|
||||||
"exchange-info": {
|
"exchange-info": {
|
||||||
request: { baseUrl: string };
|
request: { baseUrl: string };
|
||||||
@ -129,7 +131,7 @@ export interface MessageMap {
|
|||||||
};
|
};
|
||||||
"withdraw-payback-reserve": {
|
"withdraw-payback-reserve": {
|
||||||
request: { reservePub: string };
|
request: { reservePub: string };
|
||||||
response: void;
|
response: dbTypes.ReserveRecord[];
|
||||||
};
|
};
|
||||||
"get-precoins": {
|
"get-precoins": {
|
||||||
request: { exchangeBaseUrl: string };
|
request: { exchangeBaseUrl: string };
|
||||||
@ -145,11 +147,11 @@ export interface MessageMap {
|
|||||||
};
|
};
|
||||||
"check-upgrade": {
|
"check-upgrade": {
|
||||||
request: { };
|
request: { };
|
||||||
response: void;
|
response: UpgradeResponse;
|
||||||
};
|
};
|
||||||
"get-sender-wire-infos": {
|
"get-sender-wire-infos": {
|
||||||
request: { };
|
request: { };
|
||||||
response: void;
|
response: walletTypes.SenderWireInfos;
|
||||||
};
|
};
|
||||||
"return-coins": {
|
"return-coins": {
|
||||||
request: { };
|
request: { };
|
||||||
@ -164,20 +166,20 @@ export interface MessageMap {
|
|||||||
response: void;
|
response: void;
|
||||||
};
|
};
|
||||||
"get-purchase": {
|
"get-purchase": {
|
||||||
request: any;
|
request: { contractTermsHash: string };
|
||||||
response: void;
|
response: dbTypes.PurchaseRecord;
|
||||||
};
|
};
|
||||||
"get-full-refund-fees": {
|
"get-full-refund-fees": {
|
||||||
request: { refundPermissions: talerTypes.RefundPermission[] };
|
request: { refundPermissions: talerTypes.RefundPermission[] };
|
||||||
response: void;
|
response: AmountJson;
|
||||||
};
|
};
|
||||||
"accept-tip": {
|
"accept-tip": {
|
||||||
request: { tipToken: talerTypes.TipToken };
|
request: { tipToken: talerTypes.TipToken };
|
||||||
response: void;
|
response: walletTypes.TipStatus;
|
||||||
};
|
};
|
||||||
"get-tip-status": {
|
"get-tip-status": {
|
||||||
request: { tipToken: talerTypes.TipToken };
|
request: { tipToken: talerTypes.TipToken };
|
||||||
response: void;
|
response: walletTypes.TipStatus;
|
||||||
};
|
};
|
||||||
"clear-notification": {
|
"clear-notification": {
|
||||||
request: { };
|
request: { };
|
||||||
@ -188,12 +190,12 @@ export interface MessageMap {
|
|||||||
response: void;
|
response: void;
|
||||||
};
|
};
|
||||||
"download-proposal": {
|
"download-proposal": {
|
||||||
request: any;
|
request: { url: string };
|
||||||
response: void;
|
response: number;
|
||||||
};
|
};
|
||||||
"submit-pay": {
|
"submit-pay": {
|
||||||
request: { contractTermsHash: string, sessionId: string | undefined };
|
request: { contractTermsHash: string, sessionId: string | undefined };
|
||||||
response: void;
|
response: walletTypes.ConfirmPayResult;
|
||||||
};
|
};
|
||||||
"accept-refund": {
|
"accept-refund": {
|
||||||
request: { refundUrl: string }
|
request: { refundUrl: string }
|
||||||
|
@ -49,7 +49,7 @@ interface DetailState {
|
|||||||
interface DetailProps {
|
interface DetailProps {
|
||||||
contractTerms: ContractTerms;
|
contractTerms: ContractTerms;
|
||||||
collapsed: boolean;
|
collapsed: boolean;
|
||||||
exchanges: null|ExchangeRecord[];
|
exchanges: ExchangeRecord[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,11 +110,11 @@ interface ContractPromptProps {
|
|||||||
|
|
||||||
interface ContractPromptState {
|
interface ContractPromptState {
|
||||||
proposalId: number | undefined;
|
proposalId: number | undefined;
|
||||||
proposal: ProposalDownloadRecord | null;
|
proposal: ProposalDownloadRecord | undefined;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
payDisabled: boolean;
|
payDisabled: boolean;
|
||||||
alreadyPaid: boolean;
|
alreadyPaid: boolean;
|
||||||
exchanges: null|ExchangeRecord[];
|
exchanges: ExchangeRecord[] | undefined;
|
||||||
/**
|
/**
|
||||||
* Don't request updates to proposal state while
|
* Don't request updates to proposal state while
|
||||||
* this is set to true, to avoid UI flickering
|
* this is set to true, to avoid UI flickering
|
||||||
@ -123,6 +123,7 @@ interface ContractPromptState {
|
|||||||
holdCheck: boolean;
|
holdCheck: boolean;
|
||||||
payStatus?: CheckPayResult;
|
payStatus?: CheckPayResult;
|
||||||
replaying: boolean;
|
replaying: boolean;
|
||||||
|
payInProgress: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContractPrompt extends React.Component<ContractPromptProps, ContractPromptState> {
|
class ContractPrompt extends React.Component<ContractPromptProps, ContractPromptState> {
|
||||||
@ -131,10 +132,11 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
|
|||||||
this.state = {
|
this.state = {
|
||||||
alreadyPaid: false,
|
alreadyPaid: false,
|
||||||
error: null,
|
error: null,
|
||||||
exchanges: null,
|
exchanges: undefined,
|
||||||
holdCheck: false,
|
holdCheck: false,
|
||||||
payDisabled: true,
|
payDisabled: true,
|
||||||
proposal: null,
|
payInProgress: false,
|
||||||
|
proposal: undefined,
|
||||||
proposalId: props.proposalId,
|
proposalId: props.proposalId,
|
||||||
replaying: false,
|
replaying: false,
|
||||||
};
|
};
|
||||||
@ -231,7 +233,13 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("confirmPay with", proposalId, "and", this.props.sessionId);
|
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);
|
console.log("payResult", payResult);
|
||||||
document.location.href = payResult.nextUrl;
|
document.location.href = payResult.nextUrl;
|
||||||
this.setState({ holdCheck: true });
|
this.setState({ holdCheck: true });
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
DenominationRecord,
|
DenominationRecord,
|
||||||
ExchangeRecord,
|
ExchangeRecord,
|
||||||
PreCoinRecord,
|
PreCoinRecord,
|
||||||
|
ProposalDownloadRecord,
|
||||||
PurchaseRecord,
|
PurchaseRecord,
|
||||||
ReserveRecord,
|
ReserveRecord,
|
||||||
} from "../dbTypes";
|
} from "../dbTypes";
|
||||||
@ -71,8 +72,11 @@ export interface UpgradeResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function callBackend<T extends MessageType>(type: T, detail: MessageMap[T]["request"]): Promise<any> {
|
async function callBackend<T extends MessageType>(
|
||||||
return new Promise<any>((resolve, reject) => {
|
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 (resp && resp.error) {
|
if (resp && resp.error) {
|
||||||
reject(resp);
|
reject(resp);
|
||||||
@ -201,7 +205,7 @@ export function payback(coinPub: string): Promise<void> {
|
|||||||
/**
|
/**
|
||||||
* Get a proposal stored in the wallet by its proposal id.
|
* 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 });
|
return callBackend("get-proposal", { proposalId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
|
|||||||
console.log("processing refund");
|
console.log("processing refund");
|
||||||
const uri = new URI(chrome.extension.getURL("/src/webex/pages/refund.html"));
|
const uri = new URI(chrome.extension.getURL("/src/webex/pages/refund.html"));
|
||||||
uri.query({ refundUrl: fields.refund_url });
|
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
|
// We need to do some asynchronous operation, we can't directly redirect
|
||||||
|
Loading…
Reference in New Issue
Block a user