Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download wallets modal #2202

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/components/DownloadWalletModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Trans } from '@lingui/macro'
import { rgba } from 'polished'
import { X } from 'react-feather'
import { Image, Text } from 'rebass'
import styled from 'styled-components'

import Column from 'components/Column'
import Modal from 'components/Modal'
import Row, { RowBetween } from 'components/Row'
import { connections } from 'constants/wallets'
import useTheme from 'hooks/useTheme'
import { ApplicationModal } from 'state/application/actions'
import { useCloseModal, useModalOpen } from 'state/application/hooks'
import { useDarkModeManager } from 'state/user/hooks'
import { ButtonText } from 'theme'

const DownloadWalletRow = styled.a`
display: flex;
gap: 8px;
border-radius: 999px;
padding: 12px 16px;
color: ${({ theme }) => theme.subText};
font-size: 16px;
font-weight: 500;
background: ${({ theme }) => theme.buttonBlack};
line-height: 24px;
text-decoration: none;

flex-basis: calc((100% - 20px) / 2); // 20px gap
min-width: 170px;
box-sizing: border-box;
${({ theme }) => theme.mediaWidth.upToExtraSmall`
flex-basis: 100%;
`}

:hover {
background: ${({ theme }) => rgba(theme.buttonBlack, 0.6)};
}
`

export default function DownloadWalletModal() {
const theme = useTheme()
const [isDarkMode] = useDarkModeManager()
const isOpen = useModalOpen(ApplicationModal.DOWNLOAD_WALLET)
const closeModal = useCloseModal(ApplicationModal.DOWNLOAD_WALLET)
return (
<Modal isOpen={isOpen} onDismiss={closeModal} maxWidth="600px">
<Column width="100%" padding="30px 24px" overflowY="scroll">
<RowBetween>
<Text fontSize="20px" fontWeight="500">
<Trans>Download a Wallet</Trans>
</Text>

<ButtonText onClick={closeModal} style={{ lineHeight: 0 }}>
<X size={24} color={theme.text} />
</ButtonText>
</RowBetween>

<Row gap="20px" marginTop="24px" flexWrap="wrap">
{Object.values(connections)
.filter(e => e.installLink)
.map(item => (
<DownloadWalletRow
key={item.installLink}
href={item.installLink}
target="_blank"
rel="noopener noreferrer"
>
<Image width="24px" maxHeight="24px" src={isDarkMode ? item.icon : item.iconLight} />
{item.name}
</DownloadWalletRow>
))}
</Row>
</Column>
</Modal>
)
}
15 changes: 11 additions & 4 deletions src/components/Tutorial/TutorialSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SwapSettingBtn from 'assets/images/tutorial_swap/swap_setting_btn.png'
import WelcomeImage from 'assets/images/tutorial_swap/welcome.png'
import { ButtonOutlined, ButtonPrimary } from 'components/Button'
import { ToggleItemType } from 'components/Collapse'
import { SUPPORTED_WALLETS } from 'constants/wallets'
import { connections } from 'constants/wallets'
import { useActiveWeb3React } from 'hooks'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import { useTutorialSwapGuide } from 'state/tutorial/hooks'
Expand Down Expand Up @@ -81,6 +81,9 @@ const NetworkItemWrapper = styled.div`
padding: 10px 15px;
gap: 10px;
cursor: pointer;
flex-basis: calc((100% - 10px) / 2); // 10px gap
min-width: 160px;
box-sizing: border-box;
`

const NetworkWrapper = styled.div`
Expand All @@ -89,7 +92,7 @@ const NetworkWrapper = styled.div`
padding: 15px;
gap: 10px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
`

const ImageMobile = ({
Expand Down Expand Up @@ -162,11 +165,15 @@ function ConnectWallet() {
</Heading>
{isExpanded && (
<NetworkWrapper>
{Object.values(SUPPORTED_WALLETS)
{Object.values(connections)
.filter(e => e.installLink)
.map(item => (
<NetworkItemWrapper key={item.name} onClick={() => window.open(item.installLink)}>
<img src={isDarkMode ? item.icon : item.iconLight} alt={item.name} width="20" height="20" />
<img
src={isDarkMode ? item.icon : item.iconLight}
alt={item.name}
style={{ width: '20px', maxHeight: '20px' }}
/>
<span>{item.name}</span>
</NetworkItemWrapper>
))}
Expand Down
32 changes: 16 additions & 16 deletions src/constants/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,6 @@ export const SUPPORTED_WALLETS = {
readyState: detectCoinbase,
readyStateSolana: () => (isMobile ? WalletReadyState.Unsupported : coinbaseAdapter.readyState),
} as EVMWalletInfo & SolanaWalletInfo,
WALLET_CONNECT: {
connector: walletConnectV2,
hooks: walletConnectV2Hooks,
name: 'WalletConnect',
icon: WALLETCONNECT,
iconLight: WALLETCONNECT,
readyState: () => WalletReadyState.Installed,
} as EVMWalletInfo,
SAFE: {
connector: gnosisSafe,
hooks: gnosisSafeHooks,
Expand All @@ -256,6 +248,22 @@ export const SUPPORTED_WALLETS = {
installLink: 'https://safe.global/wallet',
readyState: detectSafe,
} as EVMWalletInfo,
BLOCTO_INJECTED: {
connector: bloctoInject,
hooks: bloctoInjectHooks,
name: 'Blocto',
icon: BLOCTO,
iconLight: BLOCTO,
readyState: detectBloctoInjected,
} as EVMWalletInfo,
WALLET_CONNECT: {
connector: walletConnectV2,
hooks: walletConnectV2Hooks,
name: 'WalletConnect',
icon: WALLETCONNECT,
iconLight: WALLETCONNECT,
readyState: () => WalletReadyState.Installed,
} as EVMWalletInfo,
BLOCTO: {
connector: blocto,
hooks: bloctoHooks,
Expand All @@ -265,14 +273,6 @@ export const SUPPORTED_WALLETS = {
installLink: 'https://www.blocto.io/download',
readyState: detectBlocto,
} as EVMWalletInfo,
BLOCTO_INJECTED: {
connector: bloctoInject,
hooks: bloctoInjectHooks,
name: 'Blocto',
icon: BLOCTO,
iconLight: BLOCTO,
readyState: detectBloctoInjected,
} as EVMWalletInfo,
SOLFLARE: {
adapter: solflareAdapter,
name: 'Solflare',
Expand Down
64 changes: 8 additions & 56 deletions src/pages/BuyCrypto/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import { Trans } from '@lingui/macro'
import { rgba } from 'polished'
import { stringify } from 'querystring'
import React, { useEffect, useRef, useState } from 'react'
import { ArrowDown, ChevronDown, Repeat, X } from 'react-feather'
import React, { useEffect, useRef } from 'react'
import { ArrowDown, ChevronDown, Repeat } from 'react-feather'
import { Link, useNavigate } from 'react-router-dom'
import { useMedia } from 'react-use'
import { Flex, Image, Text } from 'rebass'
Expand All @@ -27,18 +26,18 @@ import metamask from 'assets/wallets-connect/metamask.svg'
import walletConnect from 'assets/wallets-connect/wallet-connect.svg'
import { ButtonLight, ButtonPrimary } from 'components/Button'
import CopyHelper from 'components/Copy'
import DownloadWalletModal from 'components/DownloadWalletModal'
import Cart from 'components/Icons/Cart'
import Deposit from 'components/Icons/Deposit'
import Modal from 'components/Modal'
import { TRANSAK_API_KEY, TRANSAK_URL } from 'constants/env'
import { APP_PATHS } from 'constants/index'
import { SUPPORTED_WALLETS } from 'constants/wallets'
import { useActiveWeb3React } from 'hooks'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import useParsedQueryString from 'hooks/useParsedQueryString'
import useTheme from 'hooks/useTheme'
import { KSStatistic } from 'pages/About/AboutKyberSwap'
import { useWalletModalToggle } from 'state/application/hooks'
import { ApplicationModal } from 'state/application/actions'
import { useToggleModal, useWalletModalToggle } from 'state/application/hooks'
import { useDarkModeManager } from 'state/user/hooks'
import { ButtonText, ExternalLink } from 'theme'

Expand Down Expand Up @@ -136,23 +135,6 @@ const Address = styled.div`
width: fit-content;
`

const DownloadWalletRow = styled.a`
display: flex;
gap: 8px;
border-radius: 999px;
padding: 12px 16px;
color: ${({ theme }) => theme.subText};
font-size: 16px;
font-weight: 500;
background: ${({ theme }) => theme.buttonBlack};
line-height: 24px;
text-decoration: none;

:hover {
background: ${({ theme }) => rgba(theme.buttonBlack, 0.6)};
}
`

const Step = ({
currentStep = 1,
direction = 'vertical',
Expand Down Expand Up @@ -190,6 +172,7 @@ function BuyCrypto() {
const { account, chainId, networkInfo } = useActiveWeb3React()

const toggleWalletModal = useWalletModalToggle()
const toggleDownloadWalletModal = useToggleModal(ApplicationModal.DOWNLOAD_WALLET)

const step0Ref = useRef<HTMLDivElement>(null)
const step1Ref = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -248,8 +231,6 @@ function BuyCrypto() {
const [isDarkMode] = useDarkModeManager()
const { mixpanelHandler } = useMixpanel()

const [showDownloadModal, setShowDownloadModal] = useState(false)

const handleStepClick = (value: number) => {
switch (value) {
case 1:
Expand Down Expand Up @@ -288,36 +269,7 @@ function BuyCrypto() {

return (
<>
<Modal isOpen={showDownloadModal} onDismiss={() => setShowDownloadModal(false)} maxWidth="512px">
<Flex width="100%" padding="30px 24px" flexDirection="column">
<Flex justifyContent="space-between" alignItems="center">
<Text fontSize="20px" fontWeight="500">
<Trans>Download a Wallet</Trans>
</Text>

<ButtonText onClick={() => setShowDownloadModal(false)} style={{ lineHeight: 0 }}>
<X size={24} color={theme.text} />
</ButtonText>
</Flex>

<Flex sx={{ gap: '20px' }} marginTop="24px" flexDirection="column" justifyContent="center">
{Object.values(SUPPORTED_WALLETS)
.filter(e => e.installLink)
.map(item => (
<DownloadWalletRow
key={item.installLink}
href={item.installLink}
target="_blank"
rel="noopener noreferrer"
>
<Image width="24px" src={isDarkMode ? item.icon : item.iconLight} />
{item.name}
</DownloadWalletRow>
))}
</Flex>
</Flex>
</Modal>

<DownloadWalletModal />
<IntroWrapper ref={step0Ref}>
<IntroContent>
{!upToMedium && <Step currentStep={1} direction="vertical" onStepClick={handleStepClick} />}
Expand Down Expand Up @@ -437,7 +389,7 @@ function BuyCrypto() {
padding="10px"
onClick={() => {
mixpanelHandler(MIXPANEL_TYPE.TRANSAK_DOWNLOAD_WALLET_CLICKED)
setShowDownloadModal(true)
toggleDownloadWalletModal()
}}
>
<Deposit width={24} height={24} />
Expand Down
1 change: 1 addition & 0 deletions src/state/application/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum ApplicationModal {
VOTE,
PRICE_RANGE,
POOL_DETAIL,
DOWNLOAD_WALLET,

MOBILE_LIVE_CHART,
MOBILE_TRADE_ROUTES,
Expand Down
Loading