pretty
This commit is contained in:
parent
59d235e8d2
commit
e143108254
@ -30,10 +30,7 @@ export interface Props {
|
||||
onSuccess: (tx: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export type State =
|
||||
| State.Loading
|
||||
| State.LoadingUriError
|
||||
| State.Ready;
|
||||
export type State = State.Loading | State.LoadingUriError | State.Ready;
|
||||
|
||||
export namespace State {
|
||||
export interface Loading {
|
||||
|
@ -24,7 +24,6 @@ export function useComponentState(
|
||||
{ talerDepositUri, amountStr, cancel, onSuccess }: Props,
|
||||
api: typeof wxApi,
|
||||
): State {
|
||||
|
||||
const info = useAsyncAsHook(async () => {
|
||||
if (!talerDepositUri) throw Error("ERROR_NO-URI-FOR-DEPOSIT");
|
||||
if (!amountStr) throw Error("ERROR_NO-AMOUNT-FOR-DEPOSIT");
|
||||
|
@ -35,7 +35,9 @@ describe("Deposit CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareRefund: async () => ({}),
|
||||
@ -76,14 +78,16 @@ describe("Deposit CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareDeposit: async () =>
|
||||
({
|
||||
effectiveDepositAmount: Amounts.parseOrThrow("EUR:1"),
|
||||
totalDepositCost: Amounts.parseOrThrow("EUR:1.2"),
|
||||
} as PrepareDepositResponse as any),
|
||||
({
|
||||
effectiveDepositAmount: Amounts.parseOrThrow("EUR:1"),
|
||||
totalDepositCost: Amounts.parseOrThrow("EUR:1.2"),
|
||||
} as PrepareDepositResponse as any),
|
||||
createDepositGroup: async () => ({}),
|
||||
} as any,
|
||||
),
|
||||
|
@ -29,10 +29,7 @@ export interface Props {
|
||||
onSuccess: (tx: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export type State =
|
||||
| State.Loading
|
||||
| State.LoadingUriError
|
||||
| State.Ready;
|
||||
export type State = State.Loading | State.LoadingUriError | State.Ready;
|
||||
|
||||
export namespace State {
|
||||
export interface Loading {
|
||||
|
@ -87,7 +87,7 @@ export function useComponentState(
|
||||
invalid: !subject || Amounts.isZero(amount),
|
||||
exchangeUrl: selected.exchangeBaseUrl,
|
||||
create: {
|
||||
onClick: accept
|
||||
onClick: accept,
|
||||
},
|
||||
cancel: {
|
||||
onClick: onClose,
|
||||
|
@ -45,7 +45,6 @@ export function LoadingUriView({ error }: State.LoadingUriError): VNode {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function ReadyView({
|
||||
invalid,
|
||||
exchangeUrl,
|
||||
|
@ -85,7 +85,6 @@ export namespace State {
|
||||
payStatus: PreparePayResultAlreadyConfirmed;
|
||||
balance: AmountJson;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const viewMapping: StateViewMap<State> = {
|
||||
|
@ -333,5 +333,3 @@ export const AlreadyConfirmedByOther = createExample(BaseView, {
|
||||
paid: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
@ -75,7 +75,9 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: undefined,
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: nullFunction,
|
||||
@ -111,19 +113,21 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: "taller://pay",
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: nullFunction,
|
||||
preparePay: async () =>
|
||||
({
|
||||
amountRaw: "USD:10",
|
||||
status: PreparePayResultType.InsufficientBalance,
|
||||
} as Partial<PreparePayResult>),
|
||||
({
|
||||
amountRaw: "USD:10",
|
||||
status: PreparePayResultType.InsufficientBalance,
|
||||
} as Partial<PreparePayResult>),
|
||||
getBalance: async () =>
|
||||
({
|
||||
balances: [],
|
||||
} as Partial<BalancesResponse>),
|
||||
({
|
||||
balances: [],
|
||||
} as Partial<BalancesResponse>),
|
||||
} as Partial<typeof wxApi> as any,
|
||||
),
|
||||
);
|
||||
@ -154,23 +158,25 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: "taller://pay",
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: nullFunction,
|
||||
preparePay: async () =>
|
||||
({
|
||||
amountRaw: "USD:10",
|
||||
status: PreparePayResultType.InsufficientBalance,
|
||||
} as Partial<PreparePayResult>),
|
||||
({
|
||||
amountRaw: "USD:10",
|
||||
status: PreparePayResultType.InsufficientBalance,
|
||||
} as Partial<PreparePayResult>),
|
||||
getBalance: async () =>
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:5",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:5",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
} as Partial<typeof wxApi> as any,
|
||||
),
|
||||
);
|
||||
@ -201,24 +207,26 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: "taller://pay",
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: nullFunction,
|
||||
preparePay: async () =>
|
||||
({
|
||||
amountRaw: "USD:10",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
({
|
||||
amountRaw: "USD:10",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
getBalance: async () =>
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
} as Partial<typeof wxApi> as any,
|
||||
),
|
||||
);
|
||||
@ -251,24 +259,26 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: "taller://pay",
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: nullFunction,
|
||||
preparePay: async () =>
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
getBalance: async () =>
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
} as Partial<typeof wxApi> as any,
|
||||
),
|
||||
);
|
||||
@ -301,29 +311,31 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: "taller://pay",
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: nullFunction,
|
||||
preparePay: async () =>
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
getBalance: async () =>
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
confirmPay: async () =>
|
||||
({
|
||||
type: ConfirmPayResultType.Done,
|
||||
contractTerms: {},
|
||||
} as Partial<ConfirmPayResult>),
|
||||
({
|
||||
type: ConfirmPayResultType.Done,
|
||||
contractTerms: {},
|
||||
} as Partial<ConfirmPayResult>),
|
||||
} as Partial<typeof wxApi> as any,
|
||||
),
|
||||
);
|
||||
@ -370,29 +382,31 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: "taller://pay",
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: nullFunction,
|
||||
preparePay: async () =>
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
getBalance: async () =>
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: "USD:15",
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
confirmPay: async () =>
|
||||
({
|
||||
type: ConfirmPayResultType.Pending,
|
||||
lastError: { code: 1 },
|
||||
} as Partial<ConfirmPayResult>),
|
||||
({
|
||||
type: ConfirmPayResultType.Pending,
|
||||
lastError: { code: 1 },
|
||||
} as Partial<ConfirmPayResult>),
|
||||
} as Partial<typeof wxApi> as any,
|
||||
),
|
||||
);
|
||||
@ -454,24 +468,26 @@ describe("Payment CTA states", () => {
|
||||
talerPayUri: "taller://pay",
|
||||
cancel: nullFunction,
|
||||
goToWalletManualWithdraw: nullFunction,
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
onUpdateNotification: subscriptions.saveSubscription,
|
||||
preparePay: async () =>
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
({
|
||||
amountRaw: "USD:9",
|
||||
amountEffective: "USD:10",
|
||||
status: PreparePayResultType.PaymentPossible,
|
||||
} as Partial<PreparePayResult>),
|
||||
getBalance: async () =>
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: Amounts.stringify(availableBalance),
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
({
|
||||
balances: [
|
||||
{
|
||||
available: Amounts.stringify(availableBalance),
|
||||
},
|
||||
],
|
||||
} as Partial<BalancesResponse>),
|
||||
} as Partial<typeof wxApi> as any,
|
||||
),
|
||||
);
|
||||
|
@ -166,14 +166,14 @@ export function BaseView(state: SupportedStates): VNode {
|
||||
/>
|
||||
)}
|
||||
</section>
|
||||
<ButtonsSection
|
||||
amount={state.amount}
|
||||
balance={state.balance}
|
||||
payStatus={state.payStatus}
|
||||
uri={state.uri}
|
||||
payHandler={state.status === "ready" ? state.payHandler : undefined}
|
||||
goToWalletManualWithdraw={state.goToWalletManualWithdraw}
|
||||
/>
|
||||
<ButtonsSection
|
||||
amount={state.amount}
|
||||
balance={state.balance}
|
||||
payStatus={state.payStatus}
|
||||
uri={state.uri}
|
||||
payHandler={state.status === "ready" ? state.payHandler : undefined}
|
||||
goToWalletManualWithdraw={state.goToWalletManualWithdraw}
|
||||
/>
|
||||
<section>
|
||||
<Link upperCased onClick={state.cancel}>
|
||||
<i18n.Translate>Cancel</i18n.Translate>
|
||||
|
@ -22,11 +22,7 @@
|
||||
import { Amounts } from "@gnu-taler/taler-util";
|
||||
import beer from "../../../static-dev/beer.png";
|
||||
import { createExample } from "../../test-utils.js";
|
||||
import {
|
||||
IgnoredView,
|
||||
InProgressView,
|
||||
ReadyView,
|
||||
} from "./views.js";
|
||||
import { IgnoredView, InProgressView, ReadyView } from "./views.js";
|
||||
export default {
|
||||
title: "cta/refund",
|
||||
};
|
||||
|
@ -40,7 +40,9 @@ describe("Refund CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareRefund: async () => ({}),
|
||||
@ -80,26 +82,28 @@ describe("Refund CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareRefund: async () =>
|
||||
({
|
||||
effectivePaid: "EUR:2",
|
||||
awaiting: "EUR:2",
|
||||
gone: "EUR:0",
|
||||
granted: "EUR:0",
|
||||
pending: false,
|
||||
proposalId: "1",
|
||||
info: {
|
||||
contractTermsHash: "123",
|
||||
merchant: {
|
||||
name: "the merchant name",
|
||||
({
|
||||
effectivePaid: "EUR:2",
|
||||
awaiting: "EUR:2",
|
||||
gone: "EUR:0",
|
||||
granted: "EUR:0",
|
||||
pending: false,
|
||||
proposalId: "1",
|
||||
info: {
|
||||
contractTermsHash: "123",
|
||||
merchant: {
|
||||
name: "the merchant name",
|
||||
},
|
||||
orderId: "orderId1",
|
||||
summary: "the summary",
|
||||
},
|
||||
orderId: "orderId1",
|
||||
summary: "the summary",
|
||||
},
|
||||
} as PrepareRefundResult as any),
|
||||
} as PrepareRefundResult as any),
|
||||
applyRefund: async () => ({}),
|
||||
onUpdateNotification: async () => ({}),
|
||||
} as any,
|
||||
@ -138,26 +142,28 @@ describe("Refund CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareRefund: async () =>
|
||||
({
|
||||
effectivePaid: "EUR:2",
|
||||
awaiting: "EUR:2",
|
||||
gone: "EUR:0",
|
||||
granted: "EUR:0",
|
||||
pending: false,
|
||||
proposalId: "1",
|
||||
info: {
|
||||
contractTermsHash: "123",
|
||||
merchant: {
|
||||
name: "the merchant name",
|
||||
({
|
||||
effectivePaid: "EUR:2",
|
||||
awaiting: "EUR:2",
|
||||
gone: "EUR:0",
|
||||
granted: "EUR:0",
|
||||
pending: false,
|
||||
proposalId: "1",
|
||||
info: {
|
||||
contractTermsHash: "123",
|
||||
merchant: {
|
||||
name: "the merchant name",
|
||||
},
|
||||
orderId: "orderId1",
|
||||
summary: "the summary",
|
||||
},
|
||||
orderId: "orderId1",
|
||||
summary: "the summary",
|
||||
},
|
||||
} as PrepareRefundResult as any),
|
||||
} as PrepareRefundResult as any),
|
||||
applyRefund: async () => ({}),
|
||||
onUpdateNotification: async () => ({}),
|
||||
} as any,
|
||||
@ -223,27 +229,28 @@ describe("Refund CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareRefund: async () =>
|
||||
({
|
||||
awaiting: Amounts.stringify(awaiting),
|
||||
effectivePaid: "EUR:2",
|
||||
gone: "EUR:0",
|
||||
granted: Amounts.stringify(granted),
|
||||
pending,
|
||||
proposalId: "1",
|
||||
info: {
|
||||
contractTermsHash: "123",
|
||||
merchant: {
|
||||
name: "the merchant name",
|
||||
({
|
||||
awaiting: Amounts.stringify(awaiting),
|
||||
effectivePaid: "EUR:2",
|
||||
gone: "EUR:0",
|
||||
granted: Amounts.stringify(granted),
|
||||
pending,
|
||||
proposalId: "1",
|
||||
info: {
|
||||
contractTermsHash: "123",
|
||||
merchant: {
|
||||
name: "the merchant name",
|
||||
},
|
||||
orderId: "orderId1",
|
||||
summary: "the summary",
|
||||
},
|
||||
orderId: "orderId1",
|
||||
summary: "the summary",
|
||||
},
|
||||
} as PrepareRefundResult as any),
|
||||
} as PrepareRefundResult as any),
|
||||
applyRefund: async () => ({}),
|
||||
onUpdateNotification: subscriptions.saveSubscription,
|
||||
} as any,
|
||||
|
@ -52,7 +52,7 @@ export function useComponentState(
|
||||
|
||||
//FIX: this may not be seen since we are moving to the success also
|
||||
tipInfo.retry();
|
||||
onSuccess(res.transactionId)
|
||||
onSuccess(res.transactionId);
|
||||
};
|
||||
|
||||
const baseInfo = {
|
||||
|
@ -34,7 +34,9 @@ describe("Tip CTA states", () => {
|
||||
onCancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareTip: async () => ({}),
|
||||
@ -75,17 +77,19 @@ describe("Tip CTA states", () => {
|
||||
onCancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareTip: async () =>
|
||||
({
|
||||
accepted: tipAccepted,
|
||||
exchangeBaseUrl: "exchange url",
|
||||
merchantBaseUrl: "merchant url",
|
||||
tipAmountEffective: "EUR:1",
|
||||
walletTipId: "tip_id",
|
||||
} as PrepareTipResult as any),
|
||||
({
|
||||
accepted: tipAccepted,
|
||||
exchangeBaseUrl: "exchange url",
|
||||
merchantBaseUrl: "merchant url",
|
||||
tipAmountEffective: "EUR:1",
|
||||
walletTipId: "tip_id",
|
||||
} as PrepareTipResult as any),
|
||||
acceptTip: async () => {
|
||||
tipAccepted = true;
|
||||
},
|
||||
@ -136,16 +140,18 @@ describe("Tip CTA states", () => {
|
||||
onCancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareTip: async () =>
|
||||
({
|
||||
exchangeBaseUrl: "exchange url",
|
||||
merchantBaseUrl: "merchant url",
|
||||
tipAmountEffective: "EUR:1",
|
||||
walletTipId: "tip_id",
|
||||
} as PrepareTipResult as any),
|
||||
({
|
||||
exchangeBaseUrl: "exchange url",
|
||||
merchantBaseUrl: "merchant url",
|
||||
tipAmountEffective: "EUR:1",
|
||||
walletTipId: "tip_id",
|
||||
} as PrepareTipResult as any),
|
||||
acceptTip: async () => ({}),
|
||||
} as any,
|
||||
),
|
||||
@ -191,17 +197,19 @@ describe("Tip CTA states", () => {
|
||||
onCancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null; },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
prepareTip: async () =>
|
||||
({
|
||||
accepted: true,
|
||||
exchangeBaseUrl: "exchange url",
|
||||
merchantBaseUrl: "merchant url",
|
||||
tipAmountEffective: "EUR:1",
|
||||
walletTipId: "tip_id",
|
||||
} as PrepareTipResult as any),
|
||||
({
|
||||
accepted: true,
|
||||
exchangeBaseUrl: "exchange url",
|
||||
merchantBaseUrl: "merchant url",
|
||||
tipAmountEffective: "EUR:1",
|
||||
walletTipId: "tip_id",
|
||||
} as PrepareTipResult as any),
|
||||
acceptTip: async () => ({}),
|
||||
} as any,
|
||||
),
|
||||
|
@ -29,10 +29,7 @@ export interface Props {
|
||||
onSuccess: (tx: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export type State =
|
||||
| State.Loading
|
||||
| State.LoadingUriError
|
||||
| State.Ready;
|
||||
export type State = State.Loading | State.LoadingUriError | State.Ready;
|
||||
|
||||
export namespace State {
|
||||
export interface Loading {
|
||||
|
@ -31,7 +31,6 @@ export function useComponentState(
|
||||
TalerErrorDetail | undefined
|
||||
>(undefined);
|
||||
|
||||
|
||||
async function accept(): Promise<void> {
|
||||
try {
|
||||
const resp = await api.initiatePeerPushPayment({
|
||||
@ -61,7 +60,7 @@ export function useComponentState(
|
||||
onInput: async (e) => setSubject(e),
|
||||
},
|
||||
create: {
|
||||
onClick: accept
|
||||
onClick: accept,
|
||||
},
|
||||
chosenAmount: amount,
|
||||
toBeReceived: amount,
|
||||
|
@ -38,7 +38,6 @@ export function LoadingUriView({ error }: State.LoadingUriError): VNode {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function ReadyView({
|
||||
subject,
|
||||
toBeReceived,
|
||||
|
@ -68,7 +68,7 @@ export function useComponentState(
|
||||
const resp = await api.acceptPeerPushPayment({
|
||||
peerPushPaymentIncomingId,
|
||||
});
|
||||
onSuccess(resp.transactionId)
|
||||
onSuccess(resp.transactionId);
|
||||
} catch (e) {
|
||||
if (e instanceof TalerError) {
|
||||
setOperationError(e.errorDetail);
|
||||
|
@ -40,8 +40,8 @@ export function useComponentStateFromParams(
|
||||
// get the first exchange with the currency as the default one
|
||||
const exchange = exchangeHookDep
|
||||
? exchangeHookDep.exchanges.find(
|
||||
(e) => e.currency === chosenAmount.currency,
|
||||
)
|
||||
(e) => e.currency === chosenAmount.currency,
|
||||
)
|
||||
: undefined;
|
||||
/**
|
||||
* For the exchange selected, bring the status of the terms of service
|
||||
@ -152,8 +152,8 @@ export function useComponentStateFromParams(
|
||||
const { state: termsState } = (!terms
|
||||
? undefined
|
||||
: terms.hasError
|
||||
? undefined
|
||||
: terms.response) || { state: undefined };
|
||||
? undefined
|
||||
: terms.response) || { state: undefined };
|
||||
|
||||
async function onAccept(accepted: boolean): Promise<void> {
|
||||
if (!termsState || !exchange) return;
|
||||
@ -190,10 +190,10 @@ export function useComponentStateFromParams(
|
||||
//TODO: calculate based on exchange info
|
||||
const ageRestriction = ageRestrictionEnabled
|
||||
? {
|
||||
list: ageRestrictionOptions,
|
||||
value: String(ageRestricted),
|
||||
onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
|
||||
}
|
||||
list: ageRestrictionOptions,
|
||||
value: String(ageRestricted),
|
||||
onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
@ -214,12 +214,12 @@ export function useComponentStateFromParams(
|
||||
tosProps: !termsState
|
||||
? undefined
|
||||
: {
|
||||
onAccept,
|
||||
onReview: setReviewing,
|
||||
reviewed: reviewed,
|
||||
reviewing: reviewing,
|
||||
terms: termsState,
|
||||
},
|
||||
onAccept,
|
||||
onReview: setReviewing,
|
||||
reviewed: reviewed,
|
||||
reviewing: reviewing,
|
||||
terms: termsState,
|
||||
},
|
||||
mustAcceptFirst,
|
||||
cancel,
|
||||
};
|
||||
@ -339,9 +339,8 @@ export function useComponentStateFromURI(
|
||||
if (res.confirmTransferUrl) {
|
||||
document.location.href = res.confirmTransferUrl;
|
||||
} else {
|
||||
onSuccess(res.transactionId)
|
||||
onSuccess(res.transactionId);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
if (e instanceof TalerError) {
|
||||
setWithdrawError(e);
|
||||
@ -372,8 +371,8 @@ export function useComponentStateFromURI(
|
||||
const { state: termsState } = (!terms
|
||||
? undefined
|
||||
: terms.hasError
|
||||
? undefined
|
||||
: terms.response) || { state: undefined };
|
||||
? undefined
|
||||
: terms.response) || { state: undefined };
|
||||
|
||||
async function onAccept(accepted: boolean): Promise<void> {
|
||||
if (!termsState || !thisExchange) return;
|
||||
@ -410,10 +409,10 @@ export function useComponentStateFromURI(
|
||||
//TODO: calculate based on exchange info
|
||||
const ageRestriction = ageRestrictionEnabled
|
||||
? {
|
||||
list: ageRestrictionOptions,
|
||||
value: String(ageRestricted),
|
||||
onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
|
||||
}
|
||||
list: ageRestrictionOptions,
|
||||
value: String(ageRestricted),
|
||||
onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
@ -435,12 +434,12 @@ export function useComponentStateFromURI(
|
||||
tosProps: !termsState
|
||||
? undefined
|
||||
: {
|
||||
onAccept,
|
||||
onReview: setReviewing,
|
||||
reviewed: reviewed,
|
||||
reviewing: reviewing,
|
||||
terms: termsState,
|
||||
},
|
||||
onAccept,
|
||||
onReview: setReviewing,
|
||||
reviewed: reviewed,
|
||||
reviewing: reviewing,
|
||||
terms: termsState,
|
||||
},
|
||||
mustAcceptFirst,
|
||||
cancel,
|
||||
};
|
||||
|
@ -68,7 +68,9 @@ describe("Withdraw CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
listExchanges: async () => ({ exchanges }),
|
||||
@ -109,7 +111,9 @@ describe("Withdraw CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
listExchanges: async () => ({ exchanges }),
|
||||
@ -152,7 +156,9 @@ describe("Withdraw CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
listExchanges: async () => ({ exchanges }),
|
||||
@ -163,10 +169,10 @@ describe("Withdraw CTA states", () => {
|
||||
}),
|
||||
getExchangeWithdrawalInfo:
|
||||
async (): Promise<ExchangeWithdrawDetails> =>
|
||||
({
|
||||
withdrawalAmountRaw: "ARS:2",
|
||||
withdrawalAmountEffective: "ARS:2",
|
||||
} as any),
|
||||
({
|
||||
withdrawalAmountRaw: "ARS:2",
|
||||
withdrawalAmountEffective: "ARS:2",
|
||||
} as any),
|
||||
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
|
||||
contentType: "text",
|
||||
content: "just accept",
|
||||
@ -227,7 +233,9 @@ describe("Withdraw CTA states", () => {
|
||||
cancel: async () => {
|
||||
null;
|
||||
},
|
||||
onSuccess: async () => { null },
|
||||
onSuccess: async () => {
|
||||
null;
|
||||
},
|
||||
},
|
||||
{
|
||||
listExchanges: async () => ({ exchanges }),
|
||||
@ -238,10 +246,10 @@ describe("Withdraw CTA states", () => {
|
||||
}),
|
||||
getExchangeWithdrawalInfo:
|
||||
async (): Promise<ExchangeWithdrawDetails> =>
|
||||
({
|
||||
withdrawalAmountRaw: "ARS:2",
|
||||
withdrawalAmountEffective: "ARS:2",
|
||||
} as any),
|
||||
({
|
||||
withdrawalAmountRaw: "ARS:2",
|
||||
withdrawalAmountEffective: "ARS:2",
|
||||
} as any),
|
||||
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
|
||||
contentType: "text",
|
||||
content: "just accept",
|
||||
|
@ -249,49 +249,65 @@ export function Application(): VNode {
|
||||
redirectTo(Pages.ctaWithdrawManual({ amount }))
|
||||
}
|
||||
cancel={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaRefund}
|
||||
component={RefundPage}
|
||||
cancel={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaTips}
|
||||
component={TipPage}
|
||||
onCancel={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaWithdraw}
|
||||
component={WithdrawPageFromURI}
|
||||
cancel={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaWithdrawManual.pattern}
|
||||
component={WithdrawPageFromParams}
|
||||
cancel={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaDeposit}
|
||||
component={DepositPageCTA}
|
||||
cancel={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaInvoiceCreate.pattern}
|
||||
component={InvoiceCreatePage}
|
||||
onClose={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaTransferCreate.pattern}
|
||||
component={TransferCreatePage}
|
||||
onClose={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaInvoicePay}
|
||||
@ -300,13 +316,17 @@ export function Application(): VNode {
|
||||
redirectTo(Pages.ctaWithdrawManual({ amount }))
|
||||
}
|
||||
onClose={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={Pages.ctaTransferPickup}
|
||||
component={TransferPickupPage}
|
||||
onClose={() => redirectTo(Pages.balance)}
|
||||
onSuccess={(tid:string) => redirectTo(Pages.balanceTransaction({ tid }))}
|
||||
onSuccess={(tid: string) =>
|
||||
redirectTo(Pages.balanceTransaction({ tid }))
|
||||
}
|
||||
/>
|
||||
|
||||
{/**
|
||||
|
@ -634,7 +634,7 @@ export function TransactionView({
|
||||
text={transaction.exchangeBaseUrl}
|
||||
kind="neutral"
|
||||
/>
|
||||
{transaction.pending && ( /** pending is not-pay */
|
||||
{transaction.pending /** pending is not-pay */ && (
|
||||
<Part
|
||||
title={<i18n.Translate>URI</i18n.Translate>}
|
||||
text={<ShowQrWithCopy text={transaction.talerUri} />}
|
||||
@ -720,13 +720,13 @@ export function TransactionView({
|
||||
text={transaction.exchangeBaseUrl}
|
||||
kind="neutral"
|
||||
/>
|
||||
{/* {transaction.pending && ( //pending is not-received
|
||||
{/* {transaction.pending && ( //pending is not-received
|
||||
)} */}
|
||||
<Part
|
||||
title={<i18n.Translate>URI</i18n.Translate>}
|
||||
text={<ShowQrWithCopy text={transaction.talerUri} />}
|
||||
kind="neutral"
|
||||
/>
|
||||
<Part
|
||||
title={<i18n.Translate>URI</i18n.Translate>}
|
||||
text={<ShowQrWithCopy text={transaction.talerUri} />}
|
||||
kind="neutral"
|
||||
/>
|
||||
<Part
|
||||
title={<i18n.Translate>Details</i18n.Translate>}
|
||||
text={
|
||||
|
Loading…
Reference in New Issue
Block a user