From e35f796e80dd71e0af579ae8cf06357004586db5 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Wed, 3 Jul 2024 23:33:45 +0700 Subject: [PATCH] Add link evm address modal --- src/components/modals/LinkEvmAddressModal.tsx | 31 +++++++++++--- src/modules/points/PointsWidget.tsx | 41 ++++++++++++++++++- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/components/modals/LinkEvmAddressModal.tsx b/src/components/modals/LinkEvmAddressModal.tsx index 2f230e190..53682741f 100644 --- a/src/components/modals/LinkEvmAddressModal.tsx +++ b/src/components/modals/LinkEvmAddressModal.tsx @@ -1,17 +1,28 @@ +import useLinkedEvmAddress from '@/hooks/useLinkedEvmAddress' import { useAddExternalProviderToIdentity } from '@/services/datahub/identity/mutation' import { IdentityProvider } from '@subsocial/data-hub-sdk' import { getAddress, isAddress } from 'ethers' -import { useState } from 'react' +import { useEffect, useState } from 'react' import Button from '../Button' import Input from '../inputs/Input' -import Modal, { ModalFunctionalityProps } from './Modal' +import Modal, { ModalFunctionalityProps, ModalProps } from './Modal' -export default function LinkEvmAddressModal(props: ModalFunctionalityProps) { +export default function LinkEvmAddressModal( + props: ModalFunctionalityProps & Pick +) { const [evmAddress, setEvmAddress] = useState('') const [evmAddressError, setEvmAddressError] = useState('') const { mutate, isLoading } = useAddExternalProviderToIdentity({ onSuccess: () => props.closeModal(), }) + + const { evmAddress: myEvmAddress } = useLinkedEvmAddress() + useEffect(() => { + if (props.isOpen && myEvmAddress) { + setEvmAddress(myEvmAddress) + } + }, [myEvmAddress, props.isOpen]) + const onSubmit = (e: any) => { e.preventDefault() const checksumAddress = getAddress(evmAddress) @@ -21,12 +32,20 @@ export default function LinkEvmAddressModal(props: ModalFunctionalityProps) { } return ( - -
+ + { const address = e.target.value setEvmAddress(address) diff --git a/src/modules/points/PointsWidget.tsx b/src/modules/points/PointsWidget.tsx index ee3f3b9b3..697def896 100644 --- a/src/modules/points/PointsWidget.tsx +++ b/src/modules/points/PointsWidget.tsx @@ -9,11 +9,14 @@ import Button from '@/components/Button' import Card from '@/components/Card' import LinkText from '@/components/LinkText' import Name from '@/components/Name' +import LinkEvmAddressModal from '@/components/modals/LinkEvmAddressModal' import RewardPerDayModal from '@/components/modals/RewardPerDayModal' import SubsocialProfileModal from '@/components/subsocial-profile/SubsocialProfileModal' import useIsMounted from '@/hooks/useIsMounted' +import useLinkedEvmAddress from '@/hooks/useLinkedEvmAddress' import { useSendEvent } from '@/stores/analytics' import { useMyMainAddress } from '@/stores/my-account' +import { truncateAddress } from '@/utils/account' import { cx } from '@/utils/class-names' import { allowWindowScroll, preventWindowScroll } from '@/utils/window' import { Transition } from '@headlessui/react' @@ -208,12 +211,17 @@ const UserStatsSection = ({ const sendEvent = useSendEvent() const [openProfileModal, setOpenProfileModal] = useState(false) const [openRewardModal, setOpenRewardModal] = useState(false) + const [openEvmLinkModal, setOpenEvmLinkModal] = useState(false) + const { evmAddress } = useLinkedEvmAddress() return ( <>
{ setDrawerContentState('leaderboard') }} @@ -225,12 +233,13 @@ const UserStatsSection = ({
+ {evmAddress && ( + +
+ + My EVM Address + + + {truncateAddress(evmAddress ?? '')} + +
+ { + sendEvent('edit_evm_address_click') + setOpenEvmLinkModal(true) + }} + > + Edit + +
+ )}
LIKES LEFT TODAY: @@ -300,6 +331,12 @@ const UserStatsSection = ({ closeModal={() => setOpenProfileModal(false)} isOpen={openProfileModal} /> + setOpenEvmLinkModal(false)} + title='Edit your EVM address for rewards' + description='We will send your token rewards to this address if you win in contest.' + /> ) }