diff --git a/frontends/web/src/routes/lightning/components/payment-details.tsx b/frontends/web/src/routes/lightning/components/payment-details.tsx new file mode 100644 index 0000000000..486d6f0618 --- /dev/null +++ b/frontends/web/src/routes/lightning/components/payment-details.tsx @@ -0,0 +1,146 @@ +/** + * Copyright 2024 Shift Crypto AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import type { Payment as IPayment, LnPaymentDetails } from '@/api/lightning'; +import { Dialog } from '@/components/dialog/dialog'; +import { FiatConversion } from '@/components/rates/rates'; +import { TxDetail } from '@/components/transactions/components/detail'; +import { TxDateDetail } from '@/components/transactions/components/date'; +import { TxDetailCopyableValues } from '@/components/transactions/components/address-or-txid'; +import { getTxSign } from '@/components/transactions/utils'; +import { toSat } from '@/utils/conversion'; +import styles from '@/components/transactions/components/details.module.css'; + +type TTxDetailsDialog = { + open: boolean; + onClose: () => void; + payment: IPayment; + sign: string; +} + +export const PaymentDetailsDialog = ({ + open, + onClose, + payment, + sign, +}: TTxDetailsDialog) => { + const { t } = useTranslation(); + + return ( + + {payment && ( + <> + + {payment.description} + + + + {toSat(payment.amountMsat)} + {' '} + sat + + + + + + + + {payment.feeMsat} + {' '} + msat + + + {payment.paymentType} + + + {payment.status} + + { payment.paymentType !== 'closedChannel' && ( + + )} + { payment.paymentType !== 'closedChannel' && ( + + )} + + )} + + ); +}; + +type TTransactionDetails = { + id: string | null; + payment?: IPayment; + onClose: () => void; +} + +export const PaymentDetails = ({ + id, + payment, + onClose, +}: TTransactionDetails) => { + const [open, setOpen] = useState(false); + + useEffect(() => { + if (id) { + setOpen(true); + } + }, [id]); + + if (!payment) { + return null; + } + + return ( + { + setOpen(false); + onClose(); + }} + payment={payment} + sign={getTxSign(payment.paymentType === 'sent' ? 'send' : 'receive')} + /> + ); +}; diff --git a/frontends/web/src/routes/lightning/lightning.tsx b/frontends/web/src/routes/lightning/lightning.tsx index 768fdd80ae..7a3ef8b53a 100644 --- a/frontends/web/src/routes/lightning/lightning.tsx +++ b/frontends/web/src/routes/lightning/lightning.tsx @@ -18,7 +18,7 @@ import { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import * as accountApi from '../../api/account'; -import { getListPayments, subscribeListPayments, subscribeNodeState, Payment as TPayment, getLightningBalance } from '../../api/lightning'; +import { getListPayments, subscribeListPayments, subscribeNodeState, Payment as IPayment, getLightningBalance } from '../../api/lightning'; import { Balance } from '../../components/balance/balance'; import { ContentWrapper } from '@/components/contentwrapper/contentwrapper'; import { View, ViewContent, ViewHeader } from '../../components/view/view'; @@ -31,14 +31,17 @@ import { GlobalBanners } from '@/components/banners'; import { Status } from '../../components/status/status'; import { HideAmountsButton } from '../../components/hideamountsbutton/hideamountsbutton'; import { Transaction } from '@/components/transactions/transaction'; +import { PaymentDetails } from './components/payment-details'; +import { toSat } from '@/utils/conversion'; import styles from './lightning.module.css'; export const Lightning = () => { const { t } = useTranslation(); const [balance, setBalance] = useState(); const [syncedAddressesCount] = useState(); - const [payments, setPayments] = useState(); + const [payments, setPayments] = useState(); const [error, setError] = useState(); + const [detailID, setDetailID] = useState(null); const onStateChange = useCallback(async () => { try { @@ -124,7 +127,7 @@ export const Lightning = () => { internalID: payment.id, addresses: [], amountAtTime: { - amount: (payment.amountMsat * 0.001).toString(), + amount: toSat(payment.amountMsat).toString(), conversions: {}, // TODO: add conversions unit: 'sat' as accountApi.CoinUnit, estimated: false @@ -162,7 +165,7 @@ export const Lightning = () => { { - console.log('show details', internalID); + setDetailID(internalID); }} {...payment} /> @@ -173,6 +176,12 @@ export const Lightning = () => { ) )} + + payment.id === detailID)} + onClose={() => setDetailID(null)} + />