11import { Tooltip } from "@namada/components" ;
2+ import clsx from "clsx" ;
23import { useMemo } from "react" ;
34import { BsEye , BsEyeSlash } from "react-icons/bs" ;
5+ import semiTransparentEye from "./assets/semi-transparent-eye.svg" ;
6+ import shieldedEye from "./assets/shielded-eye.svg" ;
7+ import transparentEye from "./assets/transparent-eye.svg" ;
48import { isShieldedAddress } from "./common" ;
59
10+ type TransactionType = "transparent" | "semi-transparent" | "shielded" ;
11+
612export const ShieldedPropertiesTooltip = ( {
713 sourceAddress,
814 destinationAddress,
915} : {
1016 sourceAddress : string | undefined ;
1117 destinationAddress : string | undefined ;
1218} ) : JSX . Element => {
19+ const isSourceShielded = isShieldedAddress ( sourceAddress ?? "" ) ;
20+ const isDestShielded = isShieldedAddress ( destinationAddress ?? "" ) ;
21+
22+ // Determine transaction type
23+ const transactionType : TransactionType = useMemo ( ( ) => {
24+ if ( isSourceShielded && isDestShielded ) {
25+ return "shielded" ;
26+ } else if ( ! isSourceShielded && ! isDestShielded ) {
27+ return "transparent" ;
28+ } else {
29+ return "semi-transparent" ;
30+ }
31+ } , [ isSourceShielded , isDestShielded ] ) ;
32+
1333 const visible = useMemo ( ( ) : JSX . Element => {
1434 return (
1535 < span className = "flex items-center gap-2" >
@@ -28,32 +48,67 @@ export const ShieldedPropertiesTooltip = ({
2848 ) ;
2949 } , [ ] ) ;
3050
31- const shieldedTransfer =
32- isShieldedAddress ( sourceAddress ?? "" ) &&
33- isShieldedAddress ( destinationAddress ?? "" ) ;
34- const shieldingTransfer =
35- isShieldedAddress ( destinationAddress ?? "" ) &&
36- ! isShieldedAddress ( sourceAddress ?? "" ) ;
51+ // Determine visibility for each property based on transaction type
52+ const senderVisible = transactionType !== "shielded" && ! isSourceShielded ;
53+ const recipientVisible = transactionType === "transparent" || ! isDestShielded ;
54+ const assetVisible = transactionType !== "shielded" ;
55+ const amountVisible = transactionType !== "shielded" ;
56+
57+ // Transaction type header
58+ const transactionTypeHeader = useMemo ( ( ) => {
59+ return (
60+ < div className = "flex items-center justify-center gap-2 bg-neutral-800 rounded-sm py-2 px-4" >
61+ < span
62+ className = { clsx (
63+ "text-sm font-medium" ,
64+ transactionType === "shielded" && "text-yellow-400"
65+ ) }
66+ >
67+ { transactionType === "shielded" ?
68+ "Shielded"
69+ : transactionType === "semi-transparent" ?
70+ "Semi-transparent"
71+ : "Transparent" }
72+ </ span >
73+ < img
74+ src = {
75+ transactionType === "shielded" ? shieldedEye
76+ : transactionType === "semi-transparent" ?
77+ semiTransparentEye
78+ : transparentEye
79+ }
80+ alt = {
81+ transactionType === "shielded" ? "Shielded"
82+ : transactionType === "semi-transparent" ?
83+ "Semi-transparent"
84+ : "Transparent"
85+ }
86+ className = "w-4 h-4"
87+ />
88+ </ div >
89+ ) ;
90+ } , [ transactionType ] ) ;
3791
3892 return (
3993 < Tooltip position = "top" className = "z-50 rounded-lg -mt-2" >
40- < div className = "min-w-[15rem] py-2 space-y-3" >
41- < p className = "text-white text-sm font-medium" > Transaction Privacy:</ p >
94+ < div className = "min-w-[18rem] py-3 space-y-3" >
95+ { transactionTypeHeader }
96+
4297 < div className = "flex w-full items-center justify-between" >
4398 < span className = "text-neutral-400 text-sm" > Sender address</ span >
44- { shieldedTransfer ? hidden : visible }
45- </ div >
46- < div className = "flex w-full items-center justify-between" >
47- < span className = "text-neutral-400 text-sm" > Recipient address</ span >
48- { shieldingTransfer || shieldedTransfer ? hidden : visible }
99+ { senderVisible ? visible : hidden }
49100 </ div >
50101 < div className = "flex w-full items-center justify-between" >
51102 < span className = "text-neutral-400 text-sm" > Asset</ span >
52- { shieldedTransfer ? hidden : visible }
103+ { assetVisible ? visible : hidden }
53104 </ div >
54105 < div className = "flex w-full items-center justify-between" >
55106 < span className = "text-neutral-400 text-sm" > Amount</ span >
56- { shieldedTransfer ? hidden : visible }
107+ { amountVisible ? visible : hidden }
108+ </ div >
109+ < div className = "flex w-full items-center justify-between" >
110+ < span className = "text-neutral-400 text-sm" > Destination address</ span >
111+ { recipientVisible ? visible : hidden }
57112 </ div >
58113 </ div >
59114 </ Tooltip >
0 commit comments