From 474ef5acad389c015a00c4162e422356c7cba742 Mon Sep 17 00:00:00 2001 From: MSghais Date: Mon, 22 Jul 2024 02:43:22 +0200 Subject: [PATCH] show tip in user profile --- JoyboyCommunity/src/context/TipModal.tsx | 12 ++++++++++-- JoyboyCommunity/src/modules/TipModal/index.tsx | 15 +++++++++------ .../src/screens/Profile/Info/index.tsx | 6 ++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/JoyboyCommunity/src/context/TipModal.tsx b/JoyboyCommunity/src/context/TipModal.tsx index 7d47c973..85421462 100644 --- a/JoyboyCommunity/src/context/TipModal.tsx +++ b/JoyboyCommunity/src/context/TipModal.tsx @@ -10,6 +10,7 @@ export type TipModalContextType = { showSuccess: (props: TipSuccessModalProps) => void; hideSuccess: () => void; + showTipProfile: (userPublicKeyToTip?: string) => void; }; export const TipModalContext = createContext(null); @@ -18,6 +19,7 @@ export const TipModalProvider: React.FC = ({children}) const tipModalRef = useRef(null); const [event, setEvent] = useState(); + const [publicKeyToTip, setPublicKeyToTip] = useState(); const [successModal, setSuccessModal] = useState(null); const show = useCallback((event: NDKEvent) => { @@ -25,6 +27,11 @@ export const TipModalProvider: React.FC = ({children}) tipModalRef.current?.open(); }, []); + const showTipProfile = useCallback((userPublicKey?: string) => { + setPublicKeyToTip(userPublicKey); + tipModalRef.current?.open(); + }, []); + const hide = useCallback(() => { tipModalRef.current?.close(); setEvent(undefined); @@ -39,8 +46,8 @@ export const TipModalProvider: React.FC = ({children}) }, []); const context = useMemo( - () => ({show, hide, showSuccess, hideSuccess}), - [show, hide, showSuccess, hideSuccess], + () => ({show, hide, showSuccess, hideSuccess, showTipProfile}), + [show, hide, showSuccess, hideSuccess, showTipProfile], ); return ( @@ -54,6 +61,7 @@ export const TipModalProvider: React.FC = ({children}) showSuccess={showSuccess} hideSuccess={hideSuccess} ref={tipModalRef} + publicKeyToTip={publicKeyToTip} /> {successModal && } diff --git a/JoyboyCommunity/src/modules/TipModal/index.tsx b/JoyboyCommunity/src/modules/TipModal/index.tsx index 3371e8d8..3a0d55a0 100644 --- a/JoyboyCommunity/src/modules/TipModal/index.tsx +++ b/JoyboyCommunity/src/modules/TipModal/index.tsx @@ -22,6 +22,7 @@ export type TipModal = Modalize; export type TipModalProps = { event?: NDKEvent; + publicKeyToTip?: string; show: (event: NDKEvent) => void; hide: () => void; @@ -30,13 +31,13 @@ export type TipModalProps = { }; export const TipModal = forwardRef( - ({event, hide: hideTipModal, showSuccess, hideSuccess}, ref) => { + ({event, hide: hideTipModal, showSuccess, hideSuccess, publicKeyToTip}, ref) => { const styles = useStyles(stylesheet); const [token, setToken] = useState(TokenSymbol.ETH); const [amount, setAmount] = useState(''); - const {data: profile} = useProfile({publicKey: event?.pubkey}); + const {data: profile} = useProfile({publicKey: event?.pubkey ?? publicKeyToTip}); const account = useAccount(); const walletModal = useWalletModal(); @@ -68,7 +69,7 @@ export const TipModal = forwardRef( const depositCallData = CallData.compile([ amountUint256, // Amount TOKENS[token][CHAIN_ID].address, // Token address - uint256.bnToUint256(`0x${event?.pubkey}`), // Recipient nostr pubkey + uint256.bnToUint256(`0x${event?.pubkey ?? publicKeyToTip}`), // Recipient nostr pubkey DEFAULT_TIMELOCK, // timelock ]); @@ -97,7 +98,8 @@ export const TipModal = forwardRef( (profile?.nip05 && `@${profile.nip05}`) ?? profile?.displayName ?? profile?.name ?? - event?.pubkey, + event?.pubkey ?? + publicKeyToTip, hide: hideSuccess, }); } else { @@ -130,7 +132,7 @@ export const TipModal = forwardRef( numberOfLines={1} ellipsizeMode="middle" > - {profile?.displayName ?? profile?.name ?? event?.pubkey} + {profile?.displayName ?? profile?.name ?? event?.pubkey ?? publicKeyToTip} {profile?.nip05 && ( @@ -203,7 +205,8 @@ export const TipModal = forwardRef( {(profile?.nip05 && `@${profile.nip05}`) ?? profile?.displayName ?? profile?.name ?? - event?.pubkey} + event?.pubkey ?? + publicKeyToTip} diff --git a/JoyboyCommunity/src/screens/Profile/Info/index.tsx b/JoyboyCommunity/src/screens/Profile/Info/index.tsx index d750cb9e..01b623ce 100644 --- a/JoyboyCommunity/src/screens/Profile/Info/index.tsx +++ b/JoyboyCommunity/src/screens/Profile/Info/index.tsx @@ -6,6 +6,7 @@ import {Pressable, View} from 'react-native'; import {UserPlusIcon} from '../../../assets/icons'; import {Button, IconButton, Menu, Text} from '../../../components'; import {useContacts, useEditContacts, useProfile, useStyles, useTheme} from '../../../hooks'; +import {useTipModal} from '../../../hooks/modals'; import {useAuth} from '../../../store/auth'; import {ProfileScreenProps} from '../../../types'; import {ProfileHead} from '../Head'; @@ -30,6 +31,7 @@ export const ProfileInfo: React.FC = ({publicKey: userPublicKe const userContacts = useContacts({authors: [userPublicKey]}); const contacts = useContacts({authors: [publicKey]}); const editContacts = useEditContacts(); + const {showTipProfile} = useTipModal(); const isSelf = publicKey === userPublicKey; const isConnected = contacts.data?.includes(userPublicKey); @@ -118,6 +120,10 @@ export const ProfileInfo: React.FC = ({publicKey: userPublicKe { + showTipProfile(userPublicKey); + setMenuOpen(false); + }} />