Skip to content

Commit

Permalink
show tip in user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Jul 22, 2024
1 parent f6b0651 commit 474ef5a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
12 changes: 10 additions & 2 deletions JoyboyCommunity/src/context/TipModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type TipModalContextType = {

showSuccess: (props: TipSuccessModalProps) => void;
hideSuccess: () => void;
showTipProfile: (userPublicKeyToTip?: string) => void;
};

export const TipModalContext = createContext<TipModalContextType | null>(null);
Expand All @@ -18,13 +19,19 @@ export const TipModalProvider: React.FC<React.PropsWithChildren> = ({children})
const tipModalRef = useRef<TipModal>(null);

const [event, setEvent] = useState<NDKEvent | undefined>();
const [publicKeyToTip, setPublicKeyToTip] = useState<string | undefined>();
const [successModal, setSuccessModal] = useState<TipSuccessModalProps | null>(null);

const show = useCallback((event: NDKEvent) => {
setEvent(event);
tipModalRef.current?.open();
}, []);

const showTipProfile = useCallback((userPublicKey?: string) => {
setPublicKeyToTip(userPublicKey);
tipModalRef.current?.open();
}, []);

const hide = useCallback(() => {
tipModalRef.current?.close();
setEvent(undefined);
Expand All @@ -39,8 +46,8 @@ export const TipModalProvider: React.FC<React.PropsWithChildren> = ({children})
}, []);

const context = useMemo(
() => ({show, hide, showSuccess, hideSuccess}),
[show, hide, showSuccess, hideSuccess],
() => ({show, hide, showSuccess, hideSuccess, showTipProfile}),
[show, hide, showSuccess, hideSuccess, showTipProfile],
);

return (
Expand All @@ -54,6 +61,7 @@ export const TipModalProvider: React.FC<React.PropsWithChildren> = ({children})
showSuccess={showSuccess}
hideSuccess={hideSuccess}
ref={tipModalRef}
publicKeyToTip={publicKeyToTip}
/>

{successModal && <TipSuccessModal {...successModal} />}
Expand Down
15 changes: 9 additions & 6 deletions JoyboyCommunity/src/modules/TipModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type TipModal = Modalize;

export type TipModalProps = {
event?: NDKEvent;
publicKeyToTip?: string;

show: (event: NDKEvent) => void;
hide: () => void;
Expand All @@ -30,13 +31,13 @@ export type TipModalProps = {
};

export const TipModal = forwardRef<Modalize, TipModalProps>(
({event, hide: hideTipModal, showSuccess, hideSuccess}, ref) => {
({event, hide: hideTipModal, showSuccess, hideSuccess, publicKeyToTip}, ref) => {
const styles = useStyles(stylesheet);

const [token, setToken] = useState<TokenSymbol>(TokenSymbol.ETH);
const [amount, setAmount] = useState<string>('');

const {data: profile} = useProfile({publicKey: event?.pubkey});
const {data: profile} = useProfile({publicKey: event?.pubkey ?? publicKeyToTip});

const account = useAccount();
const walletModal = useWalletModal();
Expand Down Expand Up @@ -68,7 +69,7 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(
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
]);

Expand Down Expand Up @@ -97,7 +98,8 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(
(profile?.nip05 && `@${profile.nip05}`) ??
profile?.displayName ??
profile?.name ??
event?.pubkey,
event?.pubkey ??
publicKeyToTip,
hide: hideSuccess,
});
} else {
Expand Down Expand Up @@ -130,7 +132,7 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(
numberOfLines={1}
ellipsizeMode="middle"
>
{profile?.displayName ?? profile?.name ?? event?.pubkey}
{profile?.displayName ?? profile?.name ?? event?.pubkey ?? publicKeyToTip}
</Text>

{profile?.nip05 && (
Expand Down Expand Up @@ -203,7 +205,8 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(
{(profile?.nip05 && `@${profile.nip05}`) ??
profile?.displayName ??
profile?.name ??
event?.pubkey}
event?.pubkey ??
publicKeyToTip}
</Text>
</View>
</View>
Expand Down
6 changes: 6 additions & 0 deletions JoyboyCommunity/src/screens/Profile/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -30,6 +31,7 @@ export const ProfileInfo: React.FC<ProfileInfoProps> = ({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);
Expand Down Expand Up @@ -118,6 +120,10 @@ export const ProfileInfo: React.FC<ProfileInfoProps> = ({publicKey: userPublicKe
<Menu.Item
label={profile?.username ? `Tip @${profile.username}` : 'Tip'}
icon="CoinIcon"
onPress={() => {
showTipProfile(userPublicKey);
setMenuOpen(false);
}}
/>
<Menu.Item
label={profile?.username ? `Share @${profile.username}` : 'Share'}
Expand Down

0 comments on commit 474ef5a

Please sign in to comment.