2022-07-21 15:36:15 +02:00
|
|
|
/*
|
|
|
|
This file is part of GNU Taler
|
|
|
|
(C) 2022 Taler Systems S.A.
|
|
|
|
|
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { AmountJson } from "@gnu-taler/taler-util";
|
2022-07-31 01:55:41 +02:00
|
|
|
import { Loading } from "../../components/Loading.js";
|
2022-07-21 15:36:15 +02:00
|
|
|
import { HookError } from "../../hooks/useAsyncAsHook.js";
|
|
|
|
import { ButtonHandler, SelectFieldHandler } from "../../mui/handlers.js";
|
2022-07-31 01:55:41 +02:00
|
|
|
import { compose, StateViewMap } from "../../utils/index.js";
|
|
|
|
import * as wxApi from "../../wxApi.js";
|
2022-07-21 15:36:15 +02:00
|
|
|
import {
|
|
|
|
Props as TermsOfServiceSectionProps
|
|
|
|
} from "../TermsOfServiceSection.js";
|
|
|
|
import { useComponentState } from "./state.js";
|
2022-07-31 01:55:41 +02:00
|
|
|
import { CompletedView, LoadingExchangeView, LoadingInfoView, LoadingUriView, SuccessView } from "./views.js";
|
2022-07-21 15:36:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
talerWithdrawUri: string | undefined;
|
2022-08-10 16:50:46 +02:00
|
|
|
cancel: () => Promise<void>;
|
2022-07-21 15:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export type State =
|
2022-07-31 01:55:41 +02:00
|
|
|
| State.Loading
|
|
|
|
| State.LoadingUriError
|
|
|
|
| State.LoadingExchangeError
|
2022-07-21 15:36:15 +02:00
|
|
|
| State.LoadingInfoError
|
|
|
|
| State.Success
|
|
|
|
| State.Completed;
|
|
|
|
|
|
|
|
export namespace State {
|
|
|
|
|
2022-07-31 01:55:41 +02:00
|
|
|
export interface Loading {
|
|
|
|
status: "loading";
|
|
|
|
error: undefined;
|
|
|
|
}
|
|
|
|
export interface LoadingUriError {
|
2022-07-21 15:36:15 +02:00
|
|
|
status: "loading-uri";
|
2022-07-31 01:55:41 +02:00
|
|
|
error: HookError;
|
2022-07-21 15:36:15 +02:00
|
|
|
}
|
2022-07-31 01:55:41 +02:00
|
|
|
export interface LoadingExchangeError {
|
2022-07-21 15:36:15 +02:00
|
|
|
status: "loading-exchange";
|
2022-07-31 01:55:41 +02:00
|
|
|
error: HookError;
|
2022-07-21 15:36:15 +02:00
|
|
|
}
|
|
|
|
export interface LoadingInfoError {
|
|
|
|
status: "loading-info";
|
2022-07-31 01:55:41 +02:00
|
|
|
error: HookError;
|
2022-07-21 15:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export type Completed = {
|
|
|
|
status: "completed";
|
2022-07-31 01:55:41 +02:00
|
|
|
error: undefined;
|
2022-07-21 15:36:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export type Success = {
|
|
|
|
status: "success";
|
2022-07-31 01:55:41 +02:00
|
|
|
error: undefined;
|
2022-07-21 15:36:15 +02:00
|
|
|
|
2022-08-10 16:50:46 +02:00
|
|
|
exchangeUrl: string;
|
2022-07-21 15:36:15 +02:00
|
|
|
|
|
|
|
chosenAmount: AmountJson;
|
|
|
|
withdrawalFee: AmountJson;
|
|
|
|
toBeReceived: AmountJson;
|
|
|
|
|
|
|
|
doWithdrawal: ButtonHandler;
|
|
|
|
tosProps?: TermsOfServiceSectionProps;
|
|
|
|
mustAcceptFirst: boolean;
|
|
|
|
|
2022-08-10 16:50:46 +02:00
|
|
|
ageRestriction?: SelectFieldHandler;
|
|
|
|
|
|
|
|
cancel: () => Promise<void>;
|
2022-07-21 15:36:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const viewMapping: StateViewMap<State> = {
|
2022-07-31 01:55:41 +02:00
|
|
|
loading: Loading,
|
2022-07-21 15:36:15 +02:00
|
|
|
"loading-uri": LoadingUriView,
|
|
|
|
"loading-exchange": LoadingExchangeView,
|
|
|
|
"loading-info": LoadingInfoView,
|
|
|
|
completed: CompletedView,
|
|
|
|
success: SuccessView,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const WithdrawPage = compose("Withdraw", (p: Props) => useComponentState(p, wxApi), viewMapping)
|