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

feat: allow addToken for Coinbase Wallet #627

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { getCurrencyLogoUrls } from 'app/components/CurrencyLogo/CurrencyLogo'
import { useActiveWeb3React } from 'app/services/web3'
import { useCallback, useState } from 'react'

export default function useAddTokenToMetaMask(currencyToAdd: Currency | undefined): {
export default function useAddToken(currencyToAdd: Currency | undefined): {
addToken: () => void
success: boolean | undefined
} {
const { chainId, library } = useActiveWeb3React()
const { library } = useActiveWeb3React()

const token: Token | undefined = currencyToAdd?.wrapped

const [success, setSuccess] = useState<boolean | undefined>()

const addToken = useCallback(() => {
if (library && library.provider.isMetaMask && library.provider.request && token) {
if (library && library.provider.request && token) {
library.provider
.request({
method: 'wallet_watchAsset',
Expand Down
22 changes: 17 additions & 5 deletions src/modals/TransactionConfirmationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import ExternalLink from 'app/components/ExternalLink'
import HeadlessUiModal from 'app/components/Modal/HeadlessUIModal'
import Typography from 'app/components/Typography'
import { getExplorerLink } from 'app/functions'
import useAddTokenToMetaMask from 'app/hooks/useAddTokenToMetaMask'
import useAddTokenToWallet from 'app/hooks/useAddToken'
import useIsCoinbaseWallet from 'app/hooks/useIsCoinbaseWallet'
import { useActiveWeb3React } from 'app/services/web3'
import Lottie from 'lottie-react'
import React, { FC } from 'react'
import React, { FC, useMemo } from 'react'

interface ConfirmationPendingContentProps {
onDismiss: () => void
Expand Down Expand Up @@ -52,7 +53,18 @@ export const TransactionSubmittedContent: FC<TransactionSubmittedContentProps> =
}) => {
const { i18n } = useLingui()
const { library } = useActiveWeb3React()
const { addToken, success } = useAddTokenToMetaMask(currencyToAdd)
const { addToken, success } = useAddTokenToWallet(currencyToAdd)

const isMetaMask = library?.provider?.isMetaMask
const isCbWallet = useIsCoinbaseWallet()

const shouldRenderAddTokenButton = currencyToAdd && (isMetaMask || isCbWallet);

const walletName = useMemo(() => {
if (isMetaMask) return 'MetaMask'
if (isCbWallet) return 'Coinbase Wallet'
}, [isCbWallet, isMetaMask])

return (
<div className="flex flex-col gap-4">
<HeadlessUiModal.Header header={i18n._(t`Transaction submitted`)} onClose={onDismiss} />
Expand All @@ -72,10 +84,10 @@ export const TransactionSubmittedContent: FC<TransactionSubmittedContentProps> =
)}
</HeadlessUiModal.BorderedContent>

{currencyToAdd && library?.provider?.isMetaMask && (
{shouldRenderAddTokenButton && (
<Button color="blue" onClick={!success ? addToken : onDismiss}>
<Typography variant="sm" weight={700}>
{!success ? i18n._(t`Add ${currencyToAdd.symbol} to MetaMask`) : i18n._(t`Dismiss`)}
{!success ? i18n._(t`Add ${currencyToAdd.symbol} to ${walletName}`) : i18n._(t`Dismiss`)}
</Typography>
</Button>
)}
Expand Down