This commit is contained in:
Sebastian 2022-09-16 16:04:41 -03:00
parent 59d235e8d2
commit e143108254
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
22 changed files with 309 additions and 267 deletions

View File

@ -30,10 +30,7 @@ export interface Props {
onSuccess: (tx: string) => Promise<void>; onSuccess: (tx: string) => Promise<void>;
} }
export type State = export type State = State.Loading | State.LoadingUriError | State.Ready;
| State.Loading
| State.LoadingUriError
| State.Ready;
export namespace State { export namespace State {
export interface Loading { export interface Loading {

View File

@ -24,7 +24,6 @@ export function useComponentState(
{ talerDepositUri, amountStr, cancel, onSuccess }: Props, { talerDepositUri, amountStr, cancel, onSuccess }: Props,
api: typeof wxApi, api: typeof wxApi,
): State { ): State {
const info = useAsyncAsHook(async () => { const info = useAsyncAsHook(async () => {
if (!talerDepositUri) throw Error("ERROR_NO-URI-FOR-DEPOSIT"); if (!talerDepositUri) throw Error("ERROR_NO-URI-FOR-DEPOSIT");
if (!amountStr) throw Error("ERROR_NO-AMOUNT-FOR-DEPOSIT"); if (!amountStr) throw Error("ERROR_NO-AMOUNT-FOR-DEPOSIT");

View File

@ -35,7 +35,9 @@ describe("Deposit CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareRefund: async () => ({}), prepareRefund: async () => ({}),
@ -76,14 +78,16 @@ describe("Deposit CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareDeposit: async () => prepareDeposit: async () =>
({ ({
effectiveDepositAmount: Amounts.parseOrThrow("EUR:1"), effectiveDepositAmount: Amounts.parseOrThrow("EUR:1"),
totalDepositCost: Amounts.parseOrThrow("EUR:1.2"), totalDepositCost: Amounts.parseOrThrow("EUR:1.2"),
} as PrepareDepositResponse as any), } as PrepareDepositResponse as any),
createDepositGroup: async () => ({}), createDepositGroup: async () => ({}),
} as any, } as any,
), ),

View File

@ -29,10 +29,7 @@ export interface Props {
onSuccess: (tx: string) => Promise<void>; onSuccess: (tx: string) => Promise<void>;
} }
export type State = export type State = State.Loading | State.LoadingUriError | State.Ready;
| State.Loading
| State.LoadingUriError
| State.Ready;
export namespace State { export namespace State {
export interface Loading { export interface Loading {

View File

@ -87,7 +87,7 @@ export function useComponentState(
invalid: !subject || Amounts.isZero(amount), invalid: !subject || Amounts.isZero(amount),
exchangeUrl: selected.exchangeBaseUrl, exchangeUrl: selected.exchangeBaseUrl,
create: { create: {
onClick: accept onClick: accept,
}, },
cancel: { cancel: {
onClick: onClose, onClick: onClose,

View File

@ -45,7 +45,6 @@ export function LoadingUriView({ error }: State.LoadingUriError): VNode {
); );
} }
export function ReadyView({ export function ReadyView({
invalid, invalid,
exchangeUrl, exchangeUrl,

View File

@ -85,7 +85,6 @@ export namespace State {
payStatus: PreparePayResultAlreadyConfirmed; payStatus: PreparePayResultAlreadyConfirmed;
balance: AmountJson; balance: AmountJson;
} }
} }
const viewMapping: StateViewMap<State> = { const viewMapping: StateViewMap<State> = {

View File

@ -333,5 +333,3 @@ export const AlreadyConfirmedByOther = createExample(BaseView, {
paid: false, paid: false,
}, },
}); });

View File

@ -75,7 +75,9 @@ describe("Payment CTA states", () => {
talerPayUri: undefined, talerPayUri: undefined,
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: nullFunction, onUpdateNotification: nullFunction,
@ -111,19 +113,21 @@ describe("Payment CTA states", () => {
talerPayUri: "taller://pay", talerPayUri: "taller://pay",
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: nullFunction, onUpdateNotification: nullFunction,
preparePay: async () => preparePay: async () =>
({ ({
amountRaw: "USD:10", amountRaw: "USD:10",
status: PreparePayResultType.InsufficientBalance, status: PreparePayResultType.InsufficientBalance,
} as Partial<PreparePayResult>), } as Partial<PreparePayResult>),
getBalance: async () => getBalance: async () =>
({ ({
balances: [], balances: [],
} as Partial<BalancesResponse>), } as Partial<BalancesResponse>),
} as Partial<typeof wxApi> as any, } as Partial<typeof wxApi> as any,
), ),
); );
@ -154,23 +158,25 @@ describe("Payment CTA states", () => {
talerPayUri: "taller://pay", talerPayUri: "taller://pay",
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: nullFunction, onUpdateNotification: nullFunction,
preparePay: async () => preparePay: async () =>
({ ({
amountRaw: "USD:10", amountRaw: "USD:10",
status: PreparePayResultType.InsufficientBalance, status: PreparePayResultType.InsufficientBalance,
} as Partial<PreparePayResult>), } as Partial<PreparePayResult>),
getBalance: async () => getBalance: async () =>
({ ({
balances: [ balances: [
{ {
available: "USD:5", available: "USD:5",
}, },
], ],
} as Partial<BalancesResponse>), } as Partial<BalancesResponse>),
} as Partial<typeof wxApi> as any, } as Partial<typeof wxApi> as any,
), ),
); );
@ -201,24 +207,26 @@ describe("Payment CTA states", () => {
talerPayUri: "taller://pay", talerPayUri: "taller://pay",
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: nullFunction, onUpdateNotification: nullFunction,
preparePay: async () => preparePay: async () =>
({ ({
amountRaw: "USD:10", amountRaw: "USD:10",
amountEffective: "USD:10", amountEffective: "USD:10",
status: PreparePayResultType.PaymentPossible, status: PreparePayResultType.PaymentPossible,
} as Partial<PreparePayResult>), } as Partial<PreparePayResult>),
getBalance: async () => getBalance: async () =>
({ ({
balances: [ balances: [
{ {
available: "USD:15", available: "USD:15",
}, },
], ],
} as Partial<BalancesResponse>), } as Partial<BalancesResponse>),
} as Partial<typeof wxApi> as any, } as Partial<typeof wxApi> as any,
), ),
); );
@ -251,24 +259,26 @@ describe("Payment CTA states", () => {
talerPayUri: "taller://pay", talerPayUri: "taller://pay",
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: nullFunction, onUpdateNotification: nullFunction,
preparePay: async () => preparePay: async () =>
({ ({
amountRaw: "USD:9", amountRaw: "USD:9",
amountEffective: "USD:10", amountEffective: "USD:10",
status: PreparePayResultType.PaymentPossible, status: PreparePayResultType.PaymentPossible,
} as Partial<PreparePayResult>), } as Partial<PreparePayResult>),
getBalance: async () => getBalance: async () =>
({ ({
balances: [ balances: [
{ {
available: "USD:15", available: "USD:15",
}, },
], ],
} as Partial<BalancesResponse>), } as Partial<BalancesResponse>),
} as Partial<typeof wxApi> as any, } as Partial<typeof wxApi> as any,
), ),
); );
@ -301,29 +311,31 @@ describe("Payment CTA states", () => {
talerPayUri: "taller://pay", talerPayUri: "taller://pay",
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: nullFunction, onUpdateNotification: nullFunction,
preparePay: async () => preparePay: async () =>
({ ({
amountRaw: "USD:9", amountRaw: "USD:9",
amountEffective: "USD:10", amountEffective: "USD:10",
status: PreparePayResultType.PaymentPossible, status: PreparePayResultType.PaymentPossible,
} as Partial<PreparePayResult>), } as Partial<PreparePayResult>),
getBalance: async () => getBalance: async () =>
({ ({
balances: [ balances: [
{ {
available: "USD:15", available: "USD:15",
}, },
], ],
} as Partial<BalancesResponse>), } as Partial<BalancesResponse>),
confirmPay: async () => confirmPay: async () =>
({ ({
type: ConfirmPayResultType.Done, type: ConfirmPayResultType.Done,
contractTerms: {}, contractTerms: {},
} as Partial<ConfirmPayResult>), } as Partial<ConfirmPayResult>),
} as Partial<typeof wxApi> as any, } as Partial<typeof wxApi> as any,
), ),
); );
@ -370,29 +382,31 @@ describe("Payment CTA states", () => {
talerPayUri: "taller://pay", talerPayUri: "taller://pay",
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: nullFunction, onUpdateNotification: nullFunction,
preparePay: async () => preparePay: async () =>
({ ({
amountRaw: "USD:9", amountRaw: "USD:9",
amountEffective: "USD:10", amountEffective: "USD:10",
status: PreparePayResultType.PaymentPossible, status: PreparePayResultType.PaymentPossible,
} as Partial<PreparePayResult>), } as Partial<PreparePayResult>),
getBalance: async () => getBalance: async () =>
({ ({
balances: [ balances: [
{ {
available: "USD:15", available: "USD:15",
}, },
], ],
} as Partial<BalancesResponse>), } as Partial<BalancesResponse>),
confirmPay: async () => confirmPay: async () =>
({ ({
type: ConfirmPayResultType.Pending, type: ConfirmPayResultType.Pending,
lastError: { code: 1 }, lastError: { code: 1 },
} as Partial<ConfirmPayResult>), } as Partial<ConfirmPayResult>),
} as Partial<typeof wxApi> as any, } as Partial<typeof wxApi> as any,
), ),
); );
@ -454,24 +468,26 @@ describe("Payment CTA states", () => {
talerPayUri: "taller://pay", talerPayUri: "taller://pay",
cancel: nullFunction, cancel: nullFunction,
goToWalletManualWithdraw: nullFunction, goToWalletManualWithdraw: nullFunction,
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
onUpdateNotification: subscriptions.saveSubscription, onUpdateNotification: subscriptions.saveSubscription,
preparePay: async () => preparePay: async () =>
({ ({
amountRaw: "USD:9", amountRaw: "USD:9",
amountEffective: "USD:10", amountEffective: "USD:10",
status: PreparePayResultType.PaymentPossible, status: PreparePayResultType.PaymentPossible,
} as Partial<PreparePayResult>), } as Partial<PreparePayResult>),
getBalance: async () => getBalance: async () =>
({ ({
balances: [ balances: [
{ {
available: Amounts.stringify(availableBalance), available: Amounts.stringify(availableBalance),
}, },
], ],
} as Partial<BalancesResponse>), } as Partial<BalancesResponse>),
} as Partial<typeof wxApi> as any, } as Partial<typeof wxApi> as any,
), ),
); );

View File

@ -166,14 +166,14 @@ export function BaseView(state: SupportedStates): VNode {
/> />
)} )}
</section> </section>
<ButtonsSection <ButtonsSection
amount={state.amount} amount={state.amount}
balance={state.balance} balance={state.balance}
payStatus={state.payStatus} payStatus={state.payStatus}
uri={state.uri} uri={state.uri}
payHandler={state.status === "ready" ? state.payHandler : undefined} payHandler={state.status === "ready" ? state.payHandler : undefined}
goToWalletManualWithdraw={state.goToWalletManualWithdraw} goToWalletManualWithdraw={state.goToWalletManualWithdraw}
/> />
<section> <section>
<Link upperCased onClick={state.cancel}> <Link upperCased onClick={state.cancel}>
<i18n.Translate>Cancel</i18n.Translate> <i18n.Translate>Cancel</i18n.Translate>

View File

@ -22,11 +22,7 @@
import { Amounts } from "@gnu-taler/taler-util"; import { Amounts } from "@gnu-taler/taler-util";
import beer from "../../../static-dev/beer.png"; import beer from "../../../static-dev/beer.png";
import { createExample } from "../../test-utils.js"; import { createExample } from "../../test-utils.js";
import { import { IgnoredView, InProgressView, ReadyView } from "./views.js";
IgnoredView,
InProgressView,
ReadyView,
} from "./views.js";
export default { export default {
title: "cta/refund", title: "cta/refund",
}; };

View File

@ -40,7 +40,9 @@ describe("Refund CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareRefund: async () => ({}), prepareRefund: async () => ({}),
@ -80,26 +82,28 @@ describe("Refund CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareRefund: async () => prepareRefund: async () =>
({ ({
effectivePaid: "EUR:2", effectivePaid: "EUR:2",
awaiting: "EUR:2", awaiting: "EUR:2",
gone: "EUR:0", gone: "EUR:0",
granted: "EUR:0", granted: "EUR:0",
pending: false, pending: false,
proposalId: "1", proposalId: "1",
info: { info: {
contractTermsHash: "123", contractTermsHash: "123",
merchant: { merchant: {
name: "the merchant name", name: "the merchant name",
},
orderId: "orderId1",
summary: "the summary",
}, },
orderId: "orderId1", } as PrepareRefundResult as any),
summary: "the summary",
},
} as PrepareRefundResult as any),
applyRefund: async () => ({}), applyRefund: async () => ({}),
onUpdateNotification: async () => ({}), onUpdateNotification: async () => ({}),
} as any, } as any,
@ -138,26 +142,28 @@ describe("Refund CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareRefund: async () => prepareRefund: async () =>
({ ({
effectivePaid: "EUR:2", effectivePaid: "EUR:2",
awaiting: "EUR:2", awaiting: "EUR:2",
gone: "EUR:0", gone: "EUR:0",
granted: "EUR:0", granted: "EUR:0",
pending: false, pending: false,
proposalId: "1", proposalId: "1",
info: { info: {
contractTermsHash: "123", contractTermsHash: "123",
merchant: { merchant: {
name: "the merchant name", name: "the merchant name",
},
orderId: "orderId1",
summary: "the summary",
}, },
orderId: "orderId1", } as PrepareRefundResult as any),
summary: "the summary",
},
} as PrepareRefundResult as any),
applyRefund: async () => ({}), applyRefund: async () => ({}),
onUpdateNotification: async () => ({}), onUpdateNotification: async () => ({}),
} as any, } as any,
@ -223,27 +229,28 @@ describe("Refund CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareRefund: async () => prepareRefund: async () =>
({ ({
awaiting: Amounts.stringify(awaiting), awaiting: Amounts.stringify(awaiting),
effectivePaid: "EUR:2", effectivePaid: "EUR:2",
gone: "EUR:0", gone: "EUR:0",
granted: Amounts.stringify(granted), granted: Amounts.stringify(granted),
pending, pending,
proposalId: "1", proposalId: "1",
info: { info: {
contractTermsHash: "123", contractTermsHash: "123",
merchant: { merchant: {
name: "the merchant name", name: "the merchant name",
},
orderId: "orderId1",
summary: "the summary",
}, },
orderId: "orderId1", } as PrepareRefundResult as any),
summary: "the summary",
},
} as PrepareRefundResult as any),
applyRefund: async () => ({}), applyRefund: async () => ({}),
onUpdateNotification: subscriptions.saveSubscription, onUpdateNotification: subscriptions.saveSubscription,
} as any, } as any,

View File

@ -52,7 +52,7 @@ export function useComponentState(
//FIX: this may not be seen since we are moving to the success also //FIX: this may not be seen since we are moving to the success also
tipInfo.retry(); tipInfo.retry();
onSuccess(res.transactionId) onSuccess(res.transactionId);
}; };
const baseInfo = { const baseInfo = {

View File

@ -34,7 +34,9 @@ describe("Tip CTA states", () => {
onCancel: async () => { onCancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareTip: async () => ({}), prepareTip: async () => ({}),
@ -75,17 +77,19 @@ describe("Tip CTA states", () => {
onCancel: async () => { onCancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareTip: async () => prepareTip: async () =>
({ ({
accepted: tipAccepted, accepted: tipAccepted,
exchangeBaseUrl: "exchange url", exchangeBaseUrl: "exchange url",
merchantBaseUrl: "merchant url", merchantBaseUrl: "merchant url",
tipAmountEffective: "EUR:1", tipAmountEffective: "EUR:1",
walletTipId: "tip_id", walletTipId: "tip_id",
} as PrepareTipResult as any), } as PrepareTipResult as any),
acceptTip: async () => { acceptTip: async () => {
tipAccepted = true; tipAccepted = true;
}, },
@ -136,16 +140,18 @@ describe("Tip CTA states", () => {
onCancel: async () => { onCancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareTip: async () => prepareTip: async () =>
({ ({
exchangeBaseUrl: "exchange url", exchangeBaseUrl: "exchange url",
merchantBaseUrl: "merchant url", merchantBaseUrl: "merchant url",
tipAmountEffective: "EUR:1", tipAmountEffective: "EUR:1",
walletTipId: "tip_id", walletTipId: "tip_id",
} as PrepareTipResult as any), } as PrepareTipResult as any),
acceptTip: async () => ({}), acceptTip: async () => ({}),
} as any, } as any,
), ),
@ -191,17 +197,19 @@ describe("Tip CTA states", () => {
onCancel: async () => { onCancel: async () => {
null; null;
}, },
onSuccess: async () => { null; }, onSuccess: async () => {
null;
},
}, },
{ {
prepareTip: async () => prepareTip: async () =>
({ ({
accepted: true, accepted: true,
exchangeBaseUrl: "exchange url", exchangeBaseUrl: "exchange url",
merchantBaseUrl: "merchant url", merchantBaseUrl: "merchant url",
tipAmountEffective: "EUR:1", tipAmountEffective: "EUR:1",
walletTipId: "tip_id", walletTipId: "tip_id",
} as PrepareTipResult as any), } as PrepareTipResult as any),
acceptTip: async () => ({}), acceptTip: async () => ({}),
} as any, } as any,
), ),

View File

@ -29,10 +29,7 @@ export interface Props {
onSuccess: (tx: string) => Promise<void>; onSuccess: (tx: string) => Promise<void>;
} }
export type State = export type State = State.Loading | State.LoadingUriError | State.Ready;
| State.Loading
| State.LoadingUriError
| State.Ready;
export namespace State { export namespace State {
export interface Loading { export interface Loading {

View File

@ -31,7 +31,6 @@ export function useComponentState(
TalerErrorDetail | undefined TalerErrorDetail | undefined
>(undefined); >(undefined);
async function accept(): Promise<void> { async function accept(): Promise<void> {
try { try {
const resp = await api.initiatePeerPushPayment({ const resp = await api.initiatePeerPushPayment({
@ -61,7 +60,7 @@ export function useComponentState(
onInput: async (e) => setSubject(e), onInput: async (e) => setSubject(e),
}, },
create: { create: {
onClick: accept onClick: accept,
}, },
chosenAmount: amount, chosenAmount: amount,
toBeReceived: amount, toBeReceived: amount,

View File

@ -38,7 +38,6 @@ export function LoadingUriView({ error }: State.LoadingUriError): VNode {
); );
} }
export function ReadyView({ export function ReadyView({
subject, subject,
toBeReceived, toBeReceived,

View File

@ -68,7 +68,7 @@ export function useComponentState(
const resp = await api.acceptPeerPushPayment({ const resp = await api.acceptPeerPushPayment({
peerPushPaymentIncomingId, peerPushPaymentIncomingId,
}); });
onSuccess(resp.transactionId) onSuccess(resp.transactionId);
} catch (e) { } catch (e) {
if (e instanceof TalerError) { if (e instanceof TalerError) {
setOperationError(e.errorDetail); setOperationError(e.errorDetail);

View File

@ -40,8 +40,8 @@ export function useComponentStateFromParams(
// get the first exchange with the currency as the default one // get the first exchange with the currency as the default one
const exchange = exchangeHookDep const exchange = exchangeHookDep
? exchangeHookDep.exchanges.find( ? exchangeHookDep.exchanges.find(
(e) => e.currency === chosenAmount.currency, (e) => e.currency === chosenAmount.currency,
) )
: undefined; : undefined;
/** /**
* For the exchange selected, bring the status of the terms of service * For the exchange selected, bring the status of the terms of service
@ -152,8 +152,8 @@ export function useComponentStateFromParams(
const { state: termsState } = (!terms const { state: termsState } = (!terms
? undefined ? undefined
: terms.hasError : terms.hasError
? undefined ? undefined
: terms.response) || { state: undefined }; : terms.response) || { state: undefined };
async function onAccept(accepted: boolean): Promise<void> { async function onAccept(accepted: boolean): Promise<void> {
if (!termsState || !exchange) return; if (!termsState || !exchange) return;
@ -190,10 +190,10 @@ export function useComponentStateFromParams(
//TODO: calculate based on exchange info //TODO: calculate based on exchange info
const ageRestriction = ageRestrictionEnabled const ageRestriction = ageRestrictionEnabled
? { ? {
list: ageRestrictionOptions, list: ageRestrictionOptions,
value: String(ageRestricted), value: String(ageRestricted),
onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)), onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
} }
: undefined; : undefined;
return { return {
@ -214,12 +214,12 @@ export function useComponentStateFromParams(
tosProps: !termsState tosProps: !termsState
? undefined ? undefined
: { : {
onAccept, onAccept,
onReview: setReviewing, onReview: setReviewing,
reviewed: reviewed, reviewed: reviewed,
reviewing: reviewing, reviewing: reviewing,
terms: termsState, terms: termsState,
}, },
mustAcceptFirst, mustAcceptFirst,
cancel, cancel,
}; };
@ -339,9 +339,8 @@ export function useComponentStateFromURI(
if (res.confirmTransferUrl) { if (res.confirmTransferUrl) {
document.location.href = res.confirmTransferUrl; document.location.href = res.confirmTransferUrl;
} else { } else {
onSuccess(res.transactionId) onSuccess(res.transactionId);
} }
} catch (e) { } catch (e) {
if (e instanceof TalerError) { if (e instanceof TalerError) {
setWithdrawError(e); setWithdrawError(e);
@ -372,8 +371,8 @@ export function useComponentStateFromURI(
const { state: termsState } = (!terms const { state: termsState } = (!terms
? undefined ? undefined
: terms.hasError : terms.hasError
? undefined ? undefined
: terms.response) || { state: undefined }; : terms.response) || { state: undefined };
async function onAccept(accepted: boolean): Promise<void> { async function onAccept(accepted: boolean): Promise<void> {
if (!termsState || !thisExchange) return; if (!termsState || !thisExchange) return;
@ -410,10 +409,10 @@ export function useComponentStateFromURI(
//TODO: calculate based on exchange info //TODO: calculate based on exchange info
const ageRestriction = ageRestrictionEnabled const ageRestriction = ageRestrictionEnabled
? { ? {
list: ageRestrictionOptions, list: ageRestrictionOptions,
value: String(ageRestricted), value: String(ageRestricted),
onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)), onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
} }
: undefined; : undefined;
return { return {
@ -435,12 +434,12 @@ export function useComponentStateFromURI(
tosProps: !termsState tosProps: !termsState
? undefined ? undefined
: { : {
onAccept, onAccept,
onReview: setReviewing, onReview: setReviewing,
reviewed: reviewed, reviewed: reviewed,
reviewing: reviewing, reviewing: reviewing,
terms: termsState, terms: termsState,
}, },
mustAcceptFirst, mustAcceptFirst,
cancel, cancel,
}; };

View File

@ -68,7 +68,9 @@ describe("Withdraw CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null }, onSuccess: async () => {
null;
},
}, },
{ {
listExchanges: async () => ({ exchanges }), listExchanges: async () => ({ exchanges }),
@ -109,7 +111,9 @@ describe("Withdraw CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null }, onSuccess: async () => {
null;
},
}, },
{ {
listExchanges: async () => ({ exchanges }), listExchanges: async () => ({ exchanges }),
@ -152,7 +156,9 @@ describe("Withdraw CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null }, onSuccess: async () => {
null;
},
}, },
{ {
listExchanges: async () => ({ exchanges }), listExchanges: async () => ({ exchanges }),
@ -163,10 +169,10 @@ describe("Withdraw CTA states", () => {
}), }),
getExchangeWithdrawalInfo: getExchangeWithdrawalInfo:
async (): Promise<ExchangeWithdrawDetails> => async (): Promise<ExchangeWithdrawDetails> =>
({ ({
withdrawalAmountRaw: "ARS:2", withdrawalAmountRaw: "ARS:2",
withdrawalAmountEffective: "ARS:2", withdrawalAmountEffective: "ARS:2",
} as any), } as any),
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({ getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
contentType: "text", contentType: "text",
content: "just accept", content: "just accept",
@ -227,7 +233,9 @@ describe("Withdraw CTA states", () => {
cancel: async () => { cancel: async () => {
null; null;
}, },
onSuccess: async () => { null }, onSuccess: async () => {
null;
},
}, },
{ {
listExchanges: async () => ({ exchanges }), listExchanges: async () => ({ exchanges }),
@ -238,10 +246,10 @@ describe("Withdraw CTA states", () => {
}), }),
getExchangeWithdrawalInfo: getExchangeWithdrawalInfo:
async (): Promise<ExchangeWithdrawDetails> => async (): Promise<ExchangeWithdrawDetails> =>
({ ({
withdrawalAmountRaw: "ARS:2", withdrawalAmountRaw: "ARS:2",
withdrawalAmountEffective: "ARS:2", withdrawalAmountEffective: "ARS:2",
} as any), } as any),
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({ getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
contentType: "text", contentType: "text",
content: "just accept", content: "just accept",

View File

@ -249,49 +249,65 @@ export function Application(): VNode {
redirectTo(Pages.ctaWithdrawManual({ amount })) redirectTo(Pages.ctaWithdrawManual({ amount }))
} }
cancel={() => redirectTo(Pages.balance)} cancel={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaRefund} path={Pages.ctaRefund}
component={RefundPage} component={RefundPage}
cancel={() => redirectTo(Pages.balance)} cancel={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaTips} path={Pages.ctaTips}
component={TipPage} component={TipPage}
onCancel={() => redirectTo(Pages.balance)} onCancel={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaWithdraw} path={Pages.ctaWithdraw}
component={WithdrawPageFromURI} component={WithdrawPageFromURI}
cancel={() => redirectTo(Pages.balance)} cancel={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaWithdrawManual.pattern} path={Pages.ctaWithdrawManual.pattern}
component={WithdrawPageFromParams} component={WithdrawPageFromParams}
cancel={() => redirectTo(Pages.balance)} cancel={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaDeposit} path={Pages.ctaDeposit}
component={DepositPageCTA} component={DepositPageCTA}
cancel={() => redirectTo(Pages.balance)} cancel={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaInvoiceCreate.pattern} path={Pages.ctaInvoiceCreate.pattern}
component={InvoiceCreatePage} component={InvoiceCreatePage}
onClose={() => redirectTo(Pages.balance)} onClose={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaTransferCreate.pattern} path={Pages.ctaTransferCreate.pattern}
component={TransferCreatePage} component={TransferCreatePage}
onClose={() => redirectTo(Pages.balance)} onClose={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaInvoicePay} path={Pages.ctaInvoicePay}
@ -300,13 +316,17 @@ export function Application(): VNode {
redirectTo(Pages.ctaWithdrawManual({ amount })) redirectTo(Pages.ctaWithdrawManual({ amount }))
} }
onClose={() => redirectTo(Pages.balance)} onClose={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
<Route <Route
path={Pages.ctaTransferPickup} path={Pages.ctaTransferPickup}
component={TransferPickupPage} component={TransferPickupPage}
onClose={() => redirectTo(Pages.balance)} onClose={() => redirectTo(Pages.balance)}
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))} onSuccess={(tid: string) =>
redirectTo(Pages.balanceTransaction({ tid }))
}
/> />
{/** {/**

View File

@ -634,7 +634,7 @@ export function TransactionView({
text={transaction.exchangeBaseUrl} text={transaction.exchangeBaseUrl}
kind="neutral" kind="neutral"
/> />
{transaction.pending && ( /** pending is not-pay */ {transaction.pending /** pending is not-pay */ && (
<Part <Part
title={<i18n.Translate>URI</i18n.Translate>} title={<i18n.Translate>URI</i18n.Translate>}
text={<ShowQrWithCopy text={transaction.talerUri} />} text={<ShowQrWithCopy text={transaction.talerUri} />}
@ -720,13 +720,13 @@ export function TransactionView({
text={transaction.exchangeBaseUrl} text={transaction.exchangeBaseUrl}
kind="neutral" kind="neutral"
/> />
{/* {transaction.pending && ( //pending is not-received {/* {transaction.pending && ( //pending is not-received
)} */} )} */}
<Part <Part
title={<i18n.Translate>URI</i18n.Translate>} title={<i18n.Translate>URI</i18n.Translate>}
text={<ShowQrWithCopy text={transaction.talerUri} />} text={<ShowQrWithCopy text={transaction.talerUri} />}
kind="neutral" kind="neutral"
/> />
<Part <Part
title={<i18n.Translate>Details</i18n.Translate>} title={<i18n.Translate>Details</i18n.Translate>}
text={ text={