2019-08-29 23:12:55 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
(C) 2015-2016 GNUnet e.V.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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
|
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Page shown to the user to confirm creation
|
|
|
|
* of a reserve, usually requested by the bank.
|
|
|
|
*
|
|
|
|
* @author Florian Dold
|
|
|
|
*/
|
|
|
|
|
2019-12-12 20:53:15 +01:00
|
|
|
import * as i18n from "../i18n";
|
2019-08-29 23:12:55 +02:00
|
|
|
|
2021-03-27 14:35:58 +01:00
|
|
|
import { renderAmount } from "../renderHtml";
|
2019-08-29 23:12:55 +02:00
|
|
|
|
|
|
|
import React, { useState, useEffect } from "react";
|
2020-06-03 13:16:25 +02:00
|
|
|
import {
|
|
|
|
acceptWithdrawal,
|
|
|
|
onUpdateNotification,
|
2020-08-13 20:43:51 +02:00
|
|
|
getWithdrawalDetailsForUri,
|
2020-06-03 13:16:25 +02:00
|
|
|
} from "../wxApi";
|
2021-03-27 14:35:58 +01:00
|
|
|
import { WithdrawUriInfoResponse } from "@gnu-taler/taler-util";
|
2019-08-29 23:12:55 +02:00
|
|
|
|
2020-06-03 13:16:25 +02:00
|
|
|
function WithdrawalDialog(props: { talerWithdrawUri: string }): JSX.Element {
|
2021-01-17 18:33:25 +01:00
|
|
|
const [details, setDetails] = useState<WithdrawUriInfoResponse | undefined>();
|
2019-08-29 23:12:55 +02:00
|
|
|
const [selectedExchange, setSelectedExchange] = useState<
|
|
|
|
string | undefined
|
|
|
|
>();
|
|
|
|
const talerWithdrawUri = props.talerWithdrawUri;
|
|
|
|
const [cancelled, setCancelled] = useState(false);
|
|
|
|
const [selecting, setSelecting] = useState(false);
|
|
|
|
const [errMsg, setErrMsg] = useState<string | undefined>("");
|
2020-05-04 15:22:54 +02:00
|
|
|
const [updateCounter, setUpdateCounter] = useState(1);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return onUpdateNotification(() => {
|
|
|
|
setUpdateCounter(updateCounter + 1);
|
|
|
|
});
|
2020-06-03 13:16:25 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []);
|
2019-08-29 23:12:55 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
2020-04-06 20:02:01 +02:00
|
|
|
const fetchData = async (): Promise<void> => {
|
2021-01-17 18:33:25 +01:00
|
|
|
const res = await getWithdrawalDetailsForUri({
|
|
|
|
talerWithdrawUri: props.talerWithdrawUri,
|
|
|
|
});
|
2020-08-13 20:43:51 +02:00
|
|
|
setDetails(res);
|
2020-08-19 16:09:21 +02:00
|
|
|
if (res.defaultExchangeBaseUrl) {
|
|
|
|
setSelectedExchange(res.defaultExchangeBaseUrl);
|
|
|
|
}
|
2019-08-29 23:12:55 +02:00
|
|
|
};
|
|
|
|
fetchData();
|
2020-05-04 15:22:54 +02:00
|
|
|
}, [selectedExchange, errMsg, selecting, talerWithdrawUri, updateCounter]);
|
2019-08-29 23:12:55 +02:00
|
|
|
|
|
|
|
if (!details) {
|
|
|
|
return <span>Loading...</span>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cancelled) {
|
|
|
|
return <span>Withdraw operation has been cancelled.</span>;
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:02:01 +02:00
|
|
|
const accept = async (): Promise<void> => {
|
2020-04-07 10:07:32 +02:00
|
|
|
if (!selectedExchange) {
|
|
|
|
throw Error("can't accept, no exchange selected");
|
|
|
|
}
|
2019-08-29 23:12:55 +02:00
|
|
|
console.log("accepting exchange", selectedExchange);
|
2020-04-07 10:07:32 +02:00
|
|
|
const res = await acceptWithdrawal(talerWithdrawUri, selectedExchange);
|
2019-08-29 23:12:55 +02:00
|
|
|
console.log("accept withdrawal response", res);
|
|
|
|
if (res.confirmTransferUrl) {
|
|
|
|
document.location.href = res.confirmTransferUrl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2020-05-01 10:46:56 +02:00
|
|
|
<h1>Digital Cash Withdrawal</h1>
|
2019-08-29 23:12:55 +02:00
|
|
|
<i18n.Translate wrap="p">
|
|
|
|
You are about to withdraw{" "}
|
2021-01-17 18:33:25 +01:00
|
|
|
<strong>{renderAmount(details.amount)}</strong> from your bank account
|
|
|
|
into your wallet.
|
2019-08-29 23:12:55 +02:00
|
|
|
</i18n.Translate>
|
2020-06-03 13:16:25 +02:00
|
|
|
{selectedExchange ? (
|
2020-05-01 10:46:56 +02:00
|
|
|
<p>
|
2020-06-03 13:16:25 +02:00
|
|
|
The exchange <strong>{selectedExchange}</strong> will be used as the
|
|
|
|
Taler payment service provider.
|
|
|
|
</p>
|
|
|
|
) : null}
|
2020-05-01 10:46:56 +02:00
|
|
|
|
2019-08-29 23:12:55 +02:00
|
|
|
<div>
|
|
|
|
<button
|
|
|
|
className="pure-button button-success"
|
|
|
|
disabled={!selectedExchange}
|
|
|
|
onClick={() => accept()}
|
|
|
|
>
|
|
|
|
{i18n.str`Accept fees and withdraw`}
|
|
|
|
</button>
|
|
|
|
<p>
|
|
|
|
<span
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
style={{ textDecoration: "underline", cursor: "pointer" }}
|
|
|
|
onClick={() => setSelecting(true)}
|
|
|
|
>
|
|
|
|
{i18n.str`Chose different exchange provider`}
|
|
|
|
</span>
|
|
|
|
<br />
|
|
|
|
<span
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
style={{ textDecoration: "underline", cursor: "pointer" }}
|
|
|
|
onClick={() => setCancelled(true)}
|
|
|
|
>
|
|
|
|
{i18n.str`Cancel withdraw operation`}
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:02:01 +02:00
|
|
|
export function createWithdrawPage(): JSX.Element {
|
2020-04-06 17:35:51 +02:00
|
|
|
const url = new URL(document.location.href);
|
2020-04-07 10:07:32 +02:00
|
|
|
const talerWithdrawUri = url.searchParams.get("talerWithdrawUri");
|
|
|
|
if (!talerWithdrawUri) {
|
|
|
|
throw Error("withdraw URI required");
|
|
|
|
}
|
2020-05-04 15:22:54 +02:00
|
|
|
return <WithdrawalDialog talerWithdrawUri={talerWithdrawUri} />;
|
2020-04-07 10:07:32 +02:00
|
|
|
}
|