1 import type { ReactNode } from 'react';
2 import { useEffect } from 'react';
4 import { c } from 'ttag';
6 import { Button } from '@proton/atoms';
7 import Alert from '@proton/components/components/alert/Alert';
8 import Bordered from '@proton/components/components/container/Bordered';
9 import Loader from '@proton/components/components/loader/Loader';
10 import Price from '@proton/components/components/price/Price';
11 import type { BitcoinHook } from '@proton/components/payments/react-extensions/useBitcoin';
12 import { MAX_BITCOIN_AMOUNT, MIN_BITCOIN_AMOUNT } from '@proton/payments';
14 import BitcoinDetails from './BitcoinDetails';
15 import type { OwnProps as BitcoinQRCodeProps } from './BitcoinQRCode';
16 import BitcoinQRCode from './BitcoinQRCode';
18 export type Props = BitcoinHook;
23 processingBitcoinToken,
24 bitcoinPaymentValidated,
33 }, [amount, currency, billingAddress?.CountryCode, billingAddress?.State]);
35 if (amount < MIN_BITCOIN_AMOUNT) {
36 const i18n = (amount: ReactNode) => c('Info').jt`Amount below minimum (${amount}).`;
38 <Alert className="mb-4" type="warning">
40 <Price key="price" currency={currency}>
47 if (amount > MAX_BITCOIN_AMOUNT) {
48 const i18n = (amount: ReactNode) => c('Info').jt`Amount above maximum (${amount}).`;
50 <Alert className="mb-4" type="warning">
52 <Price key="price" currency={currency}>
64 if (error || !model.amountBitcoin || !model.address) {
67 <Alert className="mb-4" type="error">{c('Error').t`Error connecting to the Bitcoin API.`}</Alert>
68 <Button onClick={request} data-testid="bitcoin-try-again">{c('Action').t`Try again`}</Button>
73 const qrCodeStatus: BitcoinQRCodeProps['status'] = (() => {
74 if (processingBitcoinToken) {
77 if (bitcoinPaymentValidated) {
83 const btcAmountBold = (
84 <span className="text-bold" key="btc-info-amount">
85 {model.amountBitcoin} BTC
90 <Bordered className="p-6 rounded" data-testid="bitcoin-payment-data">
93 {c('Info').jt`To complete your payment, please send ${btcAmountBold} to the address below.`}
95 <div className="my-6 flex justify-center">
97 className="flex items-center flex-column"
98 amount={model.amountBitcoin}
99 address={model.address}
100 status={qrCodeStatus}
104 <BitcoinDetails amount={model.amountBitcoin} address={model.address} />
109 export default Bitcoin;