Skip to content

Commit

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

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

export const TipModalContext = createContext<TipModalContextType | null>(null);
Expand All @@ -19,19 +18,13 @@ 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 @@ -46,8 +39,8 @@ export const TipModalProvider: React.FC<React.PropsWithChildren> = ({children})
}, []);

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

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

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

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

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

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

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

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

const account = useAccount();
const walletModal = useWalletModal();
Expand Down Expand Up @@ -69,7 +68,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 ?? publicKeyToTip}`), // Recipient nostr pubkey
uint256.bnToUint256(`0x${event?.pubkey}`), // Recipient nostr pubkey
DEFAULT_TIMELOCK, // timelock
]);

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

{profile?.nip05 && (
Expand All @@ -142,10 +140,6 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(
)}
</View>
</View>

<View style={styles.likes}>
<Text fontSize={11}>16 likes</Text>
</View>
</View>

<Text
Expand Down Expand Up @@ -205,8 +199,7 @@ export const TipModal = forwardRef<Modalize, TipModalProps>(
{(profile?.nip05 && `@${profile.nip05}`) ??
profile?.displayName ??
profile?.name ??
event?.pubkey ??
publicKeyToTip}
event?.pubkey}
</Text>
</View>
</View>
Expand Down
4 changes: 2 additions & 2 deletions JoyboyCommunity/src/screens/Profile/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +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 {show: showTipModal} = useTipModal();

const isSelf = publicKey === userPublicKey;
const isConnected = contacts.data?.includes(userPublicKey);
Expand Down Expand Up @@ -121,7 +121,7 @@ export const ProfileInfo: React.FC<ProfileInfoProps> = ({publicKey: userPublicKe
label={profile?.username ? `Tip @${profile.username}` : 'Tip'}
icon="CoinIcon"
onPress={() => {
showTipProfile(userPublicKey);
showTipModal({pubkey: userPublicKey} as any);
setMenuOpen(false);
}}
/>
Expand Down

0 comments on commit 8769376

Please sign in to comment.