diff --git a/.changeset/stale-suits-share.md b/.changeset/stale-suits-share.md new file mode 100644 index 0000000..df6cdb2 --- /dev/null +++ b/.changeset/stale-suits-share.md @@ -0,0 +1,5 @@ +--- +'minotaur-wallet': minor +--- + +Add Transaction Display page diff --git a/apps/wallet/src/components/tx/TxDisplay.tsx b/apps/wallet/src/components/tx/TxDisplay.tsx index c3ceef1..2f4bed1 100644 --- a/apps/wallet/src/components/tx/TxDisplay.tsx +++ b/apps/wallet/src/components/tx/TxDisplay.tsx @@ -1,13 +1,12 @@ import { openTxInBrowser } from '@/action/tx'; import ErgAmount from '@/components/amounts-display/ErgAmount'; -import IssuedBurntTokenAmount from '@/components/token-amount/IssuedBurntTokenAmount'; import useIssuedAndBurntTokens from '@/hooks/useIssuedAndBurntTokens'; import useTxValues from '@/hooks/useTxValues'; import TxAssetDetail from '@/pages/wallet-page/transaction/TxAssetDetail'; import { StateWallet } from '@/store/reducer/wallet'; import { getValueColor } from '@/utils/functions'; import { OpenInNew } from '@mui/icons-material'; -import { IconButton, Stack, Typography } from '@mui/material'; +import { IconButton, Typography } from '@mui/material'; import React from 'react'; import * as wasm from 'ergo-lib-wasm-browser'; @@ -20,7 +19,7 @@ interface TxDisplayPropsType { const TxDisplay = ({ tx, boxes, wallet, date }: TxDisplayPropsType) => { const txId = tx.id().to_str(); - const issuedAndBurnt = useIssuedAndBurntTokens(tx, boxes); + const { mapped } = useIssuedAndBurntTokens(tx, boxes); const { txValues } = useTxValues(tx, boxes, wallet); const openTx = () => openTxInBrowser(wallet.networkType, txId ?? ''); return ( @@ -58,49 +57,22 @@ const TxDisplay = ({ tx, boxes, wallet, date }: TxDisplayPropsType) => { {Object.entries(txValues.tokens).map((item) => ( - - ))} - {issuedAndBurnt.burnt.length > 0 ? ( - - Burnt tokens - - - {issuedAndBurnt.burnt.map((item) => ( - - ))} - + + - ) : null} - {issuedAndBurnt.issued.length > 0 ? ( - - - Issued tokens - - - {issuedAndBurnt.issued.map((item) => ( - - ))} - - - ) : null} + ))} ); }; diff --git a/apps/wallet/src/hooks/useIssuedAndBurntTokens.ts b/apps/wallet/src/hooks/useIssuedAndBurntTokens.ts index a314480..fece8e2 100644 --- a/apps/wallet/src/hooks/useIssuedAndBurntTokens.ts +++ b/apps/wallet/src/hooks/useIssuedAndBurntTokens.ts @@ -19,6 +19,9 @@ const useIssuedAndBurntTokens = ( tx: wasm.UnsignedTransaction | wasm.Transaction | undefined, boxes: Array, ) => { + const [mapped, setMapped] = useState>( + new Map(), + ); const [issued, setIssued] = useState>([]); const [burnt, setBurnt] = useState>([]); const [storedTxId, setStoredTxId] = useState(''); @@ -41,20 +44,25 @@ const useIssuedAndBurntTokens = ( } const issuedTokens: Array = []; const burntTokens: Array = []; + const mappedTokens: Map = new Map(); for (const [tokenId, amount] of tokens.entries()) { if (amount > 0n) { issuedTokens.push({ tokenId, amount }); } else if (amount < 0n) { burntTokens.push({ tokenId, amount: -amount }); } + if (amount !== 0n) { + mappedTokens.set(tokenId, amount); + } } setIssued(issuedTokens); setBurnt(burntTokens); + setMapped(mappedTokens); setStoredTxId(tx.id().to_str()); setLoading(false); } }, [tx, boxes, storedTxId, loading]); - return { issued, burnt }; + return { issued, burnt, mapped }; }; export default useIssuedAndBurntTokens; diff --git a/apps/wallet/src/pages/wallet-page/asset/AssetItemDetail.tsx b/apps/wallet/src/pages/wallet-page/asset/AssetItemDetail.tsx index d088600..546508a 100644 --- a/apps/wallet/src/pages/wallet-page/asset/AssetItemDetail.tsx +++ b/apps/wallet/src/pages/wallet-page/asset/AssetItemDetail.tsx @@ -9,7 +9,7 @@ interface AssetItemDetailPropsType { id: string; description?: string; logo?: React.ElementType; - balance: React.ReactNode | string; + balance?: React.ReactNode | string; emissionAmount: React.ReactNode | string; txId: string; handleClose: () => unknown; @@ -37,7 +37,9 @@ const AssetItemDetail = (props: AssetItemDetailPropsType) => { - + {props.balance ? ( + + ) : null} { - const issuedAndBurnt = useIssuedAndBurntTokens(props.tx, props.boxes); + const { issued, burnt } = useIssuedAndBurntTokens(props.tx, props.boxes); const { txValues, valuesDirection } = useTxValues( props.tx, props.boxes, @@ -75,13 +75,13 @@ const TxSignValues = (props: WalletSignNormalPropsType) => { These amount will be spent when transaction proceed. { const details = useAssetDetail(props.id, props.networkType); + const [showDetail, setShowDetail] = useState(false); if (props.amount === 0n) return null; const color = getValueColor(props.amount); + const getLabel = () => + props.amount > 0 + ? props.issueAndBurn + ? 'Issued' + : 'Received' + : props.issueAndBurn + ? 'Burnt' + : 'Sent'; return ( @@ -25,18 +37,38 @@ const TxAssetDetail = (props: TxAssetDetailPropsType) => { )} - + setShowDetail(true)}> {details.name} {props.amount > 0 ? '+' : ''} - 0 ? 'Received' : 'Sent'} - /> + + setShowDetail(false)} + > + 0n ? ( + + ) : ( + '?' + ) + } + txId={details.txId} + handleClose={() => setShowDetail(false)} + /> + ); };