Skip to content

Commit

Permalink
Fix modals in crypto addresses menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Sep 4, 2024
1 parent a025eb5 commit cad172a
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 33 deletions.
Binary file added src/assets/graphics/eth-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/graphics/phantom-wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/components/wallets/UseMobileModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import EvmWallets from '@/assets/graphics/eth-logo.png'
import PhantomWallet from '@/assets/graphics/phantom-wallet.png'
import Image from 'next/image'
import Button from '../Button'
import Modal, { ModalFunctionalityProps } from '../modals/Modal'

const UseMobileModal = ({
chain,
...props
}: ModalFunctionalityProps & { chain: 'evm' | 'solana' }) => {
const imagePath = chain === 'evm' ? EvmWallets : PhantomWallet

return (
<Modal
{...props}
title={`Please use your phone with ${
chain === 'evm' ? 'EVM' : 'Phantom'
} wallet`}
description={'For the best experience, use your phone'}
>
<div className='mt-2 flex flex-col items-center gap-6'>
<Image src={imagePath} alt='' className='h-[150px] w-[150px]' />
<Button size='lg' className='w-full' onClick={() => props.closeModal()}>
Got it!
</Button>
</div>
</Modal>
)
}

export default UseMobileModal
73 changes: 47 additions & 26 deletions src/modules/telegram/MenuPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import LayoutWithBottomNavigation from '@/components/layouts/LayoutWithBottomNav
import { getReferralLink } from '@/components/referral/utils'
import SubsocialProfileModal from '@/components/subsocial-profile/SubsocialProfileModal'
import UnlinkWalletModal from '@/components/wallets/UnlinkWalletModal'
import UseMobileModal from '@/components/wallets/UseMobileModal'
import EvmConnectWalletModal from '@/components/wallets/evm/EvmConnectWalletModal'
import useIsModerationAdmin from '@/hooks/useIsModerationAdmin'
import { useLinkedProviders } from '@/hooks/useLinkedEvmAddress'
import useTgNoScroll from '@/hooks/useTgNoScroll'
import PointsWidget from '@/modules/points/PointsWidget'
import { useMyMainAddress } from '@/stores/my-account'
import { truncateAddress } from '@/utils/account'
import { isTouchDevice } from '@/utils/device'
import { copyToClipboard } from '@/utils/strings'
import { IdentityProvider } from '@subsocial/data-hub-sdk'
import Image from 'next/image'
Expand Down Expand Up @@ -181,18 +183,17 @@ function MyAccountPageContent({ setPage }: ContentProps) {
)
}

type AddressesModalKind =
| 'evm'
| 'solana'
| 'unlink-solana'
| 'unlink-evm'
| undefined
type ModalChain = 'evm' | 'solana'

function MyCryptoAddressesContent({ setPage }: ContentProps) {
const myAddress = useMyMainAddress()
const [modalKind, setModalKind] = useState<AddressesModalKind>(undefined)
const [modalKind, setModalKind] = useState<ModalChain>()
const solanaWalletUrl = useGetSolanaWalletUrl()
const router = useRouter()
const [isOpenUseMobileModal, setIsOpenUseMobileModal] = useState(false)
const [openEvmConnectWalletModal, setOpenEvmConnectWalletModal] =
useState(false)
const [openUnlinkModal, setOpenUnlinkModal] = useState(false)

const { providers } = useLinkedProviders(myAddress || '')

Expand All @@ -214,16 +215,34 @@ function MyCryptoAddressesContent({ setPage }: ContentProps) {
</span>
) : undefined,
icon: evmProvider?.externalId ? '🖇️' : '🛠️',
onClick: () =>
setModalKind(evmProvider?.externalId ? 'unlink-evm' : 'evm'),
onClick: () => {
setModalKind('evm')
if (!isTouchDevice()) {
setIsOpenUseMobileModal(true)
return
}

evmProvider?.externalId
? setOpenUnlinkModal(true)
: setOpenEvmConnectWalletModal(true)
},
},
{
title: `${solanaProvider?.externalId ? 'Edit' : 'Add'} Solana Address`,
title: `${
solanaProvider?.externalId ? 'Unlink' : 'Add'
} Solana Address`,
icon: solanaProvider?.externalId ? '🖇️' : '🛠️',
onClick: () =>
onClick: () => {
setModalKind('solana')
if (!isTouchDevice()) {
setIsOpenUseMobileModal(true)
return
}

solanaProvider?.externalId
? setModalKind('unlink-solana')
: router.push(solanaWalletUrl),
? setOpenUnlinkModal(true)
: router.push(solanaWalletUrl)
},
desc: solanaProvider?.externalId ? (
<span className='font-medium leading-none text-slate-400'>
{truncateAddress(solanaProvider?.externalId)}
Expand All @@ -247,19 +266,21 @@ function MyCryptoAddressesContent({ setPage }: ContentProps) {
</div>
<Menu menuItems={cryptoAddressesItems} />
</div>
{!evmProvider?.externalId && (
<EvmConnectWalletModal
isOpen={modalKind === 'evm'}
closeModal={() => setModalKind(undefined)}
/>
)}
{modalKind?.includes('unlink') && (
<UnlinkWalletModal
chain={modalKind.includes('solana') ? 'solana' : 'evm'}
isOpen={!!modalKind}
closeModal={() => setModalKind(undefined)}
/>
)}
<EvmConnectWalletModal
isOpen={openEvmConnectWalletModal}
closeModal={() => setOpenEvmConnectWalletModal(false)}
/>
<UnlinkWalletModal
chain={modalKind || 'evm'}
isOpen={openUnlinkModal}
closeModal={() => setOpenUnlinkModal(false)}
/>

<UseMobileModal
isOpen={isOpenUseMobileModal}
closeModal={() => setIsOpenUseMobileModal(false)}
chain={modalKind as ModalChain}
/>
</>
)
}
Expand Down
14 changes: 14 additions & 0 deletions src/pages/solana/connect.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Button from '@/components/Button'
import Container from '@/components/Container'
import { env } from '@/env.mjs'
import useLinkedAddress from '@/hooks/useLinkedEvmAddress'
import { addExternalProviderToIdentity } from '@/server/datahub-queue/identity'
import { createSignedSocialDataEvent } from '@/services/datahub/utils'
import { decryptPayload } from '@/stores/encryption'
import { decodeSecretKey, loginWithSecretKey } from '@/utils/account'
import { getCommonServerSideProps } from '@/utils/page'
import { IdentityProvider } from '@subsocial/data-hub-sdk'
import bs58 from 'bs58'
import { useEffect } from 'react'
import nacl from 'tweetnacl'

export const getServerSideProps = getCommonServerSideProps(
Expand Down Expand Up @@ -81,10 +83,22 @@ export const getServerSideProps = getCommonServerSideProps(
export default function SolanaConnectPage({
solanaAddress,
error,
address,
}: {
solanaAddress: string
error: string
address: string
}) {
const { refetch } = useLinkedAddress(
address,
{ enabled: true },
IdentityProvider.SOLANA
)

useEffect(() => {
refetch()
}, [refetch])

return (
<Container className='flex h-screen w-full flex-col items-center justify-center text-center'>
<h1 className='text-2xl font-bold'>
Expand Down
7 changes: 0 additions & 7 deletions src/pages/solana/sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ export const getServerSideProps = getCommonServerSideProps<{
sharedSecretDapp
)

const params = {
dapp_encryption_public_key: env.NEXT_PUBLIC_DAPP_PUBLIC_KEY,
nonce: bs58.encode(signNonce),
payload: bs58.encode(encrypted),
redirect_link: `${env.NEXT_PUBLIC_BASE_URL}/solana/connect?solana_address=${connectData.public_key}&signer=${signer}&signer_nonce=${signerNonce}&address=${address}&message=${message}&phantom_encryption_public_key=${phantomEncryptionPublicKey}`,
}

return {
props: {
address,
Expand Down

0 comments on commit cad172a

Please sign in to comment.