From 91203fad98d11f5709316f020f055a8a0eadeaad Mon Sep 17 00:00:00 2001 From: KillariDev Date: Fri, 29 Dec 2023 12:29:17 +0200 Subject: [PATCH 1/7] remove moonpay --- .env | 3 - .env.production | 3 - cypress/e2e/buy-crypto-modal.test.ts | 28 ---- cypress/e2e/wallet-dropdown.test.ts | 6 - src/assets/svg/moonpay.svg | 1 - src/components/About/constants.tsx | 12 +- .../AccountDrawer/AuthenticatedHeader.tsx | 101 +----------- .../Activity/fixtures/activity.ts | 16 -- .../Activity/parseRemote.test.tsx | 5 - .../MiniPortfolio/Activity/parseRemote.tsx | 39 +---- .../AccountDrawer/MiniPortfolio/constants.tsx | 8 - src/components/FiatOnrampModal/constants.ts | 17 -- src/components/FiatOnrampModal/index.tsx | 147 ------------------ src/components/FiatOnrampModal/utils.test.ts | 78 ---------- src/components/FiatOnrampModal/utils.ts | 74 --------- src/components/TopLevelModals/index.tsx | 2 - .../swap/SwapBuyFiatButton.test.tsx | 98 ------------ src/components/swap/SwapBuyFiatButton.tsx | 124 --------------- src/components/swap/SwapHeader.tsx | 2 - src/constants/networks.ts | 21 +-- src/state/application/hooks.ts | 73 +-------- 21 files changed, 18 insertions(+), 840 deletions(-) delete mode 100644 cypress/e2e/buy-crypto-modal.test.ts delete mode 100644 src/assets/svg/moonpay.svg delete mode 100644 src/components/FiatOnrampModal/constants.ts delete mode 100644 src/components/FiatOnrampModal/index.tsx delete mode 100644 src/components/FiatOnrampModal/utils.test.ts delete mode 100644 src/components/FiatOnrampModal/utils.ts delete mode 100644 src/components/swap/SwapBuyFiatButton.test.tsx delete mode 100644 src/components/swap/SwapBuyFiatButton.tsx diff --git a/.env b/.env index 85871d7e3c8..853cbfb86cb 100644 --- a/.env +++ b/.env @@ -6,9 +6,6 @@ REACT_APP_AWS_API_ENDPOINT="https://beta.api.uniswap.org/v1/graphql" REACT_APP_BNB_RPC_URL="https://rough-sleek-hill.bsc.quiknode.pro/413cc98cbc776cda8fdf1d0f47003583ff73d9bf" REACT_APP_INFURA_KEY="4bf032f2d38a4ed6bb975b80d6340847" REACT_APP_QUICKNODE_MAINNET_RPC_URL="https://magical-alien-tab.quiknode.pro/669e87e569a8277d3fbd9e202f9df93189f19f4c" -REACT_APP_MOONPAY_API="https://api.moonpay.com" -REACT_APP_MOONPAY_LINK="https://us-central1-uniswap-mobile.cloudfunctions.net/signMoonpayLinkV2?platform=web&env=staging" -REACT_APP_MOONPAY_PUBLISHABLE_KEY="pk_test_DycfESRid31UaSxhI5yWKe1r5E5kKSz" REACT_APP_SENTRY_DSN="https://a3c62e400b8748b5a8d007150e2f38b7@o1037921.ingest.sentry.io/4504255148851200" REACT_APP_STATSIG_PROXY_URL="https://api.uniswap.org/v1/statsig-proxy" REACT_APP_TEMP_API_URL="https://temp.api.uniswap.org/v1" diff --git a/.env.production b/.env.production index 47965b24172..744500f7d80 100644 --- a/.env.production +++ b/.env.production @@ -6,9 +6,6 @@ REACT_APP_FIREBASE_KEY="AIzaSyBcZWwTcTJHj_R6ipZcrJkXdq05PuX0Rs0" REACT_APP_FORTMATIC_KEY="pk_live_F937DF033A1666BF" REACT_APP_GOOGLE_ANALYTICS_ID="G-KDP9B6W4H8" REACT_APP_INFURA_KEY="099fc58e0de9451d80b18d7c74caa7c1" -REACT_APP_MOONPAY_API="https://api.moonpay.com" -REACT_APP_MOONPAY_LINK="https://us-central1-uniswap-mobile.cloudfunctions.net/signMoonpayLinkV2?platform=web&env=production" -REACT_APP_MOONPAY_PUBLISHABLE_KEY="pk_live_uQG4BJC4w3cxnqpcSqAfohdBFDTsY6E" REACT_APP_SENTRY_ENABLED=true REACT_APP_SENTRY_TRACES_SAMPLE_RATE=0.00003 REACT_APP_STATSIG_PROXY_URL="https://api.uniswap.org/v1/statsig-proxy" diff --git a/cypress/e2e/buy-crypto-modal.test.ts b/cypress/e2e/buy-crypto-modal.test.ts deleted file mode 100644 index 9357cc31fc7..00000000000 --- a/cypress/e2e/buy-crypto-modal.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { getTestSelector } from '../utils' - -describe('Buy Crypto Modal', () => { - it('should open and close', () => { - cy.visit('/') - - // Open the fiat onramp modal - cy.get(getTestSelector('buy-fiat-button')).click() - cy.get(getTestSelector('fiat-onramp-modal')).should('be.visible') - - // Click on a location that should be outside the modal, which should close it - cy.get('body').click(0, 100) - cy.get(getTestSelector('fiat-onramp-modal')).should('not.exist') - }) - - it('should open and close, mobile viewport', () => { - cy.viewport('iphone-6') - cy.visit('/') - - // Open the fiat onramp modal - cy.get(getTestSelector('buy-fiat-button')).click() - cy.get(getTestSelector('fiat-onramp-modal')).should('be.visible') - - // Click on a location that should be outside the modal, which should close it - cy.get('body').click(10, 10) - cy.get(getTestSelector('fiat-onramp-modal')).should('not.exist') - }) -}) diff --git a/cypress/e2e/wallet-dropdown.test.ts b/cypress/e2e/wallet-dropdown.test.ts index 67856c775e1..9d9de2058f2 100644 --- a/cypress/e2e/wallet-dropdown.test.ts +++ b/cypress/e2e/wallet-dropdown.test.ts @@ -132,12 +132,6 @@ describe('Wallet Dropdown', () => { cy.viewport('iphone-6').visit('/') }) - it('should dismiss the wallet bottom sheet when clicking buy crypto', () => { - cy.get(getTestSelector('web3-status-connected')).click() - cy.get(getTestSelector('wallet-buy-crypto')).click() - cy.contains('Buy crypto').should('not.be.visible') - }) - it('should use a bottom sheet and dismiss when on a mobile screen size', () => { cy.get(getTestSelector('web3-status-connected')).click() cy.root().click(15, 40) diff --git a/src/assets/svg/moonpay.svg b/src/assets/svg/moonpay.svg deleted file mode 100644 index 3f0e2c72e0e..00000000000 --- a/src/assets/svg/moonpay.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/components/About/constants.tsx b/src/components/About/constants.tsx index cbe5c95359d..74528b5729e 100644 --- a/src/components/About/constants.tsx +++ b/src/components/About/constants.tsx @@ -1,10 +1,9 @@ -import { DollarSign, Terminal } from 'react-feather' +import { Terminal } from 'react-feather' import styled from 'styled-components' import { lightTheme } from 'theme/colors' import darkArrowImgSrc from './images/aboutArrowDark.png' import lightArrowImgSrc from './images/aboutArrowLight.png' -import darkDollarImgSrc from './images/aboutDollarDark.png' import darkTerminalImgSrc from './images/aboutTerminalDark.png' import nftCardImgSrc from './images/nftCard.png' import swapCardImgSrc from './images/swapCard.png' @@ -36,15 +35,6 @@ const StyledCardLogo = styled.img` ` export const MORE_CARDS = [ - { - to: 'https://support.uniswap.org/hc/en-us/articles/11306574799117-How-to-use-Moon-Pay-on-the-Uniswap-web-app-', - external: true, - title: 'Buy crypto', - description: 'Buy crypto with your credit card or bank account at the best rates.', - lightIcon: , - darkIcon: , - cta: 'Buy now', - }, { to: '/pools', title: 'Earn', diff --git a/src/components/AccountDrawer/AuthenticatedHeader.tsx b/src/components/AccountDrawer/AuthenticatedHeader.tsx index ae8de05792c..9d05d4a5c0d 100644 --- a/src/components/AccountDrawer/AuthenticatedHeader.tsx +++ b/src/components/AccountDrawer/AuthenticatedHeader.tsx @@ -1,32 +1,29 @@ import { Trans } from '@lingui/macro' import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' -import { ButtonEmphasis, ButtonSize, LoadingButtonSpinner, ThemeButton } from 'components/Button' +import { ButtonEmphasis, ButtonSize, ThemeButton } from 'components/Button' import Column from 'components/Column' import { Power } from 'components/Icons/Power' import { Settings } from 'components/Icons/Settings' import { AutoRow } from 'components/Row' import { LoadingBubble } from 'components/Tokens/loading' import { DeltaArrow } from 'components/Tokens/TokenDetails/Delta' -import Tooltip from 'components/Tooltip' import { getConnection } from 'connection' import { useDisableNFTRoutes } from 'hooks/useDisableNFTRoutes' import useENSName from 'hooks/useENSName' -import { useIsNotOriginCountry } from 'hooks/useIsNotOriginCountry' import { useProfilePageState, useSellAsset, useWalletCollections } from 'nft/hooks' import { useIsNftClaimAvailable } from 'nft/hooks/useIsNftClaimAvailable' import { ProfilePageStateType } from 'nft/types' import { useCallback, useState } from 'react' -import { CreditCard, Info } from 'react-feather' import { useNavigate } from 'react-router-dom' import { useAppDispatch } from 'state/hooks' import { updateSelectedWallet } from 'state/user/reducer' import styled from 'styled-components' -import { CopyHelper, ExternalLink, ThemedText } from 'theme/components' +import { CopyHelper, ThemedText } from 'theme/components' import { shortenAddress } from 'utils' import { NumberType, useFormatter } from 'utils/formatNumbers' -import { useCloseModal, useFiatOnrampAvailability, useOpenModal, useToggleModal } from '../../state/application/hooks' +import { useCloseModal, useToggleModal } from '../../state/application/hooks' import { ApplicationModal } from '../../state/application/reducer' import { useUserHasAvailableClaim, useUserUnclaimedAmount } from '../../state/claim/hooks' import StatusIcon from '../Identicon/StatusIcon' @@ -86,20 +83,6 @@ const IconContainer = styled.div` } } ` -const FiatOnrampNotAvailableText = styled(ThemedText.BodySmall)` - align-items: center; - color: ${({ theme }) => theme.neutral2}; - display: flex; - justify-content: center; -` -const FiatOnrampAvailabilityExternalLink = styled(ExternalLink)` - align-items: center; - display: flex; - height: 14px; - justify-content: center; - margin-left: 6px; - width: 14px; -` const StatusWrapper = styled.div` display: inline-block; @@ -119,15 +102,6 @@ const AccountNamesWrapper = styled.div` margin-left: 8px; ` -const StyledInfoIcon = styled(Info)` - height: 12px; - width: 12px; - flex: 1 1 auto; -` -const StyledLoadingButtonSpinner = styled(LoadingButtonSpinner)` - fill: ${({ theme }) => theme.accent1}; -` - const HeaderWrapper = styled.div` margin-bottom: 20px; display: flex; @@ -158,7 +132,6 @@ export default function AuthenticatedHeader({ account, openSettings }: { account const resetSellAssets = useSellAsset((state) => state.reset) const clearCollectionFilters = useWalletCollections((state) => state.clearCollectionFilters) const isClaimAvailable = useIsNftClaimAvailable((state) => state.isClaimAvailable) - const shouldShowBuyFiatButton = useIsNotOriginCountry('GB') const { formatNumber, formatPercent } = useFormatter() const shouldDisableNFTRoutes = useDisableNFTRoutes() @@ -187,34 +160,6 @@ export default function AuthenticatedHeader({ account, openSettings }: { account closeModal() }, [clearCollectionFilters, closeModal, navigate, resetSellAssets, setSellPageState, toggleWalletDrawer]) - const openFiatOnrampModal = useOpenModal(ApplicationModal.FIAT_ONRAMP) - const openFoRModalWithAnalytics = useCallback(() => { - toggleWalletDrawer() - openFiatOnrampModal() - }, [openFiatOnrampModal, toggleWalletDrawer]) - - const [shouldCheck, setShouldCheck] = useState(false) - const { - available: fiatOnrampAvailable, - availabilityChecked: fiatOnrampAvailabilityChecked, - error, - loading: fiatOnrampAvailabilityLoading, - } = useFiatOnrampAvailability(shouldCheck, openFoRModalWithAnalytics) - - const handleBuyCryptoClick = useCallback(() => { - if (!fiatOnrampAvailabilityChecked) { - setShouldCheck(true) - } else if (fiatOnrampAvailable) { - openFoRModalWithAnalytics() - } - }, [fiatOnrampAvailabilityChecked, fiatOnrampAvailable, openFoRModalWithAnalytics]) - const disableBuyCryptoButton = Boolean( - error || (!fiatOnrampAvailable && fiatOnrampAvailabilityChecked) || fiatOnrampAvailabilityLoading - ) - const [showFiatOnrampUnavailableTooltip, setShow] = useState(false) - const openFiatOnrampUnavailableTooltip = useCallback(() => setShow(true), [setShow]) - const closeFiatOnrampUnavailableTooltip = useCallback(() => setShow(false), [setShow]) - const { data: portfolioBalances } = useCachedPortfolioBalancesQuery({ account }) const portfolio = portfolioBalances?.portfolios?.[0] const totalBalance = portfolio?.tokensTotalDenominatedValue?.value @@ -297,46 +242,6 @@ export default function AuthenticatedHeader({ account, openSettings }: { account View and sell NFTs )} - {shouldShowBuyFiatButton && ( - - {error ? ( - {error} - ) : ( - <> - {fiatOnrampAvailabilityLoading ? ( - - ) : ( - - )}{' '} - Buy crypto - - )} - - )} - {Boolean(!fiatOnrampAvailable && fiatOnrampAvailabilityChecked) && ( - - Not available in your region - Moonpay is not available in some regions. Click to learn more.} - > - - - - - - )} {isUnclaimed && ( diff --git a/src/components/AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts b/src/components/AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts index fc69e280573..edcc22e16fb 100644 --- a/src/components/AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts +++ b/src/components/AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts @@ -12,8 +12,6 @@ import { TransactionType, } from 'graphql/data/__generated__/types-and-hooks' -import { MOONPAY_SENDER_ADDRESSES } from '../../constants' - const MockOrderTimestamp = 10000 const MockRecipientAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' const MockSenderAddress = '0x50EC05ADe8280758E2077fcBC08D878D4aef79C3' @@ -469,20 +467,6 @@ export const MockRemoveLiquidity = { }, } as AssetActivityPartsFragment -export const MockMoonpayPurchase = { - ...mockAssetActivityPartsFragment, - details: { - ...commonTransactionDetailsFields, - type: TransactionType.Receive, - assetChanges: [ - { - ...mockTokenTransferInPartsFragment, - sender: MOONPAY_SENDER_ADDRESSES[0], - }, - ], - }, -} as AssetActivityPartsFragment - export const MockNFTReceive = { ...mockAssetActivityPartsFragment, details: { diff --git a/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx b/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx index ae26c660604..76aaa782a42 100644 --- a/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx +++ b/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx @@ -3,7 +3,6 @@ import ms from 'ms' import { MockClosedUniswapXOrder, - MockMoonpayPurchase, MockNFTApproval, MockNFTApprovalForAll, MockNFTPurchase, @@ -73,10 +72,6 @@ describe('parseRemote', () => { const result = parseRemoteActivities(jest.fn().mockReturnValue(100), [MockRemoveLiquidity]) expect(result?.['someHash']).toMatchSnapshot() }) - it('should parse moonpay purchase', () => { - const result = parseRemoteActivities(jest.fn().mockReturnValue('100'), [MockMoonpayPurchase]) - expect(result?.['someHash']).toMatchSnapshot() - }) it('should parse swap order', () => { const result = parseRemoteActivities(jest.fn().mockReturnValue('100'), [MockSwapOrder]) expect(result?.['someHash']).toMatchSnapshot() diff --git a/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx b/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx index a5907ed2f7d..b9ce67ceaf8 100644 --- a/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx +++ b/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx @@ -1,12 +1,10 @@ import { t } from '@lingui/macro' import { ChainId, Currency, NONFUNGIBLE_POSITION_MANAGER_ADDRESSES, UNI_ADDRESSES } from '@uniswap/sdk-core' import UniswapXBolt from 'assets/svg/bolt.svg' -import moonpayLogoSrc from 'assets/svg/moonpay.svg' import { nativeOnChain } from 'constants/tokens' import { ActivityType, AssetActivityPartsFragment, - Currency as GQLCurrency, NftApprovalPartsFragment, NftApproveForAllPartsFragment, NftTransferPartsFragment, @@ -24,7 +22,7 @@ import { isAddress } from 'utils' import { isSameAddress } from 'utils/addresses' import { NumberType, useFormatter } from 'utils/formatNumbers' -import { MOONPAY_SENDER_ADDRESSES, OrderStatusTable, OrderTextTable } from '../constants' +import { OrderStatusTable, OrderTextTable } from '../constants' import { Activity } from './types' type TransactionChanges = { @@ -134,17 +132,6 @@ function getSwapDescriptor({ return `${inputAmount} ${tokenIn.symbol} for ${outputAmount} ${tokenOut.symbol}` } -/** - * - * @param transactedValue Transacted value amount from TokenTransfer API response - * @returns parsed & formatted USD value as a string if currency is of type USD - */ -function getTransactedValue(transactedValue: TokenTransferPartsFragment['transactedValue']): number | undefined { - if (!transactedValue) return undefined - const price = transactedValue?.currency === GQLCurrency.Usd ? transactedValue.value ?? undefined : undefined - return price -} - function parseSwap(changes: TransactionChanges, formatNumberOrString: FormatNumberOrStringFunctionType) { if (changes.NftTransfer.length > 0 && changes.TokenTransfer.length === 1) { const collectionCounts = getCollectionCounts(changes.NftTransfer) @@ -251,25 +238,13 @@ function parseSendReceive( } if (transfer && assetName && amount) { - const isMoonpayPurchase = MOONPAY_SENDER_ADDRESSES.some((address) => isSameAddress(address, transfer?.sender)) - if (transfer.direction === 'IN') { - return isMoonpayPurchase && transfer.__typename === 'TokenTransfer' - ? { - title: t`Purchased`, - descriptor: `${amount} ${assetName} ${t`for`} ${formatNumberOrString({ - input: getTransactedValue(transfer.transactedValue), - type: NumberType.FiatTokenPrice, - })}`, - logos: [moonpayLogoSrc], - currencies, - } - : { - title: t`Received`, - descriptor: `${amount} ${assetName} ${t`from`} `, - otherAccount: isAddress(transfer.sender) || undefined, - currencies, - } + return { + title: t`Received`, + descriptor: `${amount} ${assetName} ${t`from`} `, + otherAccount: isAddress(transfer.sender) || undefined, + currencies, + } } else { return { title: t`Sent`, diff --git a/src/components/AccountDrawer/MiniPortfolio/constants.tsx b/src/components/AccountDrawer/MiniPortfolio/constants.tsx index d9033c60ec5..62fb9f37e13 100644 --- a/src/components/AccountDrawer/MiniPortfolio/constants.tsx +++ b/src/components/AccountDrawer/MiniPortfolio/constants.tsx @@ -221,14 +221,6 @@ export const OrderTextTable: { }, } -// Non-exhaustive list of addresses Moonpay uses when sending purchased tokens -export const MOONPAY_SENDER_ADDRESSES = [ - '0x8216874887415e2650d12d53ff53516f04a74fd7', - '0x151b381058f91cf871e7ea1ee83c45326f61e96d', - '0xb287eac48ab21c5fb1d3723830d60b4c797555b0', - '0xd108fd0e8c8e71552a167e7a44ff1d345d233ba6', -] - // Converts GQL backend orderStatus enum to the enum used by the frontend and UniswapX backend export const OrderStatusTable: { [key in SwapOrderStatus]: UniswapXOrderStatus } = { [SwapOrderStatus.Open]: UniswapXOrderStatus.OPEN, diff --git a/src/components/FiatOnrampModal/constants.ts b/src/components/FiatOnrampModal/constants.ts deleted file mode 100644 index db0ea4b7a59..00000000000 --- a/src/components/FiatOnrampModal/constants.ts +++ /dev/null @@ -1,17 +0,0 @@ -export const MOONPAY_SUPPORTED_CURRENCY_CODES = [ - 'eth', - 'eth_arbitrum', - 'eth_optimism', - 'eth_polygon', - 'weth', - 'wbtc', - 'matic_polygon', - 'polygon', - 'usdc_arbitrum', - 'usdc_optimism', - 'usdc_polygon', - 'usdc', - 'usdt', -] as const - -export type MoonpaySupportedCurrencyCode = (typeof MOONPAY_SUPPORTED_CURRENCY_CODES)[number] diff --git a/src/components/FiatOnrampModal/index.tsx b/src/components/FiatOnrampModal/index.tsx deleted file mode 100644 index 9e77ec955f3..00000000000 --- a/src/components/FiatOnrampModal/index.tsx +++ /dev/null @@ -1,147 +0,0 @@ -import { Trans } from '@lingui/macro' -import { useWeb3React } from '@web3-react/core' -import { useCallback, useEffect, useState } from 'react' -import { useHref } from 'react-router-dom' -import { useCloseModal, useModalIsOpen } from 'state/application/hooks' -import { ApplicationModal } from 'state/application/reducer' -import styled, { useTheme } from 'styled-components' -import { CustomLightSpinner, ThemedText } from 'theme/components' -import { useIsDarkMode } from 'theme/components/ThemeToggle' - -import Circle from '../../assets/images/blue-loader.svg' -import Modal from '../Modal' -import { MOONPAY_SUPPORTED_CURRENCY_CODES } from './constants' -import { getDefaultCurrencyCode, parsePathParts } from './utils' - -const MOONPAY_DARK_BACKGROUND = '#1c1c1e' -const Wrapper = styled.div<{ isDarkMode: boolean }>` - // #1c1c1e is the background color for the darkmode moonpay iframe as of 2/16/2023 - background-color: ${({ isDarkMode, theme }) => (isDarkMode ? MOONPAY_DARK_BACKGROUND : theme.white)}; - border-radius: 20px; - box-shadow: ${({ theme }) => theme.deprecated_deepShadow}; - display: flex; - flex-flow: column nowrap; - margin: 0; - flex: 1 1; - min-width: 375px; - position: relative; - width: 100%; -` - -const ErrorText = styled(ThemedText.BodyPrimary)` - color: ${({ theme }) => theme.critical}; - margin: auto !important; - text-align: center; - width: 90%; -` -const StyledIframe = styled.iframe<{ isDarkMode: boolean }>` - // #1c1c1e is the background color for the darkmode moonpay iframe as of 2/16/2023 - background-color: ${({ isDarkMode, theme }) => (isDarkMode ? MOONPAY_DARK_BACKGROUND : theme.white)}; - border-radius: 12px; - bottom: 0; - left: 0; - height: calc(100% - 16px); - margin: 8px; - padding: 0; - position: absolute; - right: 0; - top: 0; - width: calc(100% - 16px); -` -const StyledSpinner = styled(CustomLightSpinner)` - bottom: 0; - left: 0; - margin: auto; - position: absolute; - right: 0; - top: 0; -` - -export default function FiatOnrampModal() { - const { account } = useWeb3React() - const theme = useTheme() - const isDarkMode = useIsDarkMode() - const closeModal = useCloseModal() - const fiatOnrampModalOpen = useModalIsOpen(ApplicationModal.FIAT_ONRAMP) - - const { network, tokenAddress } = parsePathParts(location.pathname) - - const [signedIframeUrl, setSignedIframeUrl] = useState(null) - const [error, setError] = useState(null) - const [loading, setLoading] = useState(false) - - const swapUrl = useHref('/swap') - - const fetchSignedIframeUrl = useCallback(async () => { - if (!account) { - setError('Please connect an account before making a purchase.') - return - } - setLoading(true) - setError(null) - try { - const signedIframeUrlFetchEndpoint = process.env.REACT_APP_MOONPAY_LINK as string - const res = await fetch(signedIframeUrlFetchEndpoint, { - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - }, - method: 'POST', - body: JSON.stringify({ - theme: isDarkMode ? 'dark' : 'light', - colorCode: theme.accent1, - defaultCurrencyCode: getDefaultCurrencyCode(tokenAddress, network), - redirectUrl: swapUrl, - walletAddresses: JSON.stringify( - MOONPAY_SUPPORTED_CURRENCY_CODES.reduce( - (acc, currencyCode) => ({ - ...acc, - [currencyCode]: account, - }), - {} - ) - ), - }), - }) - const { url } = await res.json() - setSignedIframeUrl(url) - } catch (e) { - console.log('there was an error fetching the link', e) - setError(e.toString()) - } finally { - setLoading(false) - } - }, [account, isDarkMode, network, swapUrl, theme.accent1, tokenAddress]) - - useEffect(() => { - fetchSignedIframeUrl() - }, [fetchSignedIframeUrl]) - - return ( - closeModal()} height={80 /* vh */}> - - {error ? ( - <> - - MoonPay fiat on-ramp iframe - - - Something went wrong! -
- {error} -
- - ) : loading ? ( - - ) : ( - - )} -
-
- ) -} diff --git a/src/components/FiatOnrampModal/utils.test.ts b/src/components/FiatOnrampModal/utils.test.ts deleted file mode 100644 index 4cca77699c3..00000000000 --- a/src/components/FiatOnrampModal/utils.test.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { ChainId, WETH9 } from '@uniswap/sdk-core' -import { - MATIC, - USDC_ARBITRUM, - USDC_MAINNET, - USDC_OPTIMISM, - USDC_POLYGON, - USDT, - WBTC, - WETH_POLYGON, -} from 'constants/tokens' - -import { getDefaultCurrencyCode, parsePathParts } from './utils' - -describe('getDefaultCurrencyCode', () => { - it('NATIVE/arbitrum should return the correct currency code', () => { - expect(getDefaultCurrencyCode('NATIVE', 'arbitrum')).toBe('eth_arbitrum') - }) - it('NATIVE/optimism should return the correct currency code', () => { - expect(getDefaultCurrencyCode('NATIVE', 'optimism')).toBe('eth_optimism') - }) - it('WETH/polygon should return the correct currency code', () => { - expect(getDefaultCurrencyCode(WETH_POLYGON.address, 'polygon')).toBe('eth_polygon') - }) - it('WETH/ethereum should return the correct currency code', () => { - expect(getDefaultCurrencyCode(WETH9[ChainId.MAINNET].address, 'ethereum')).toBe('weth') - }) - it('WBTC/ethereum should return the correct currency code', () => { - expect(getDefaultCurrencyCode(WBTC.address, 'ethereum')).toBe('wbtc') - }) - it('NATIVE/polygon should return the correct currency code', () => { - expect(getDefaultCurrencyCode('NATIVE', 'polygon')).toBe('matic_polygon') - }) - it('MATIC/ethereum should return the correct currency code', () => { - expect(getDefaultCurrencyCode(MATIC.address, 'ethereum')).toBe('polygon') - }) - it('USDC/arbitrum should return the correct currency code', () => { - expect(getDefaultCurrencyCode(USDC_ARBITRUM.address, 'arbitrum')).toBe('usdc_arbitrum') - }) - it('USDC/optimism should return the correct currency code', () => { - expect(getDefaultCurrencyCode(USDC_OPTIMISM.address, 'optimism')).toBe('usdc_optimism') - }) - it('USDC/polygon should return the correct currency code', () => { - expect(getDefaultCurrencyCode(USDC_POLYGON.address, 'polygon')).toBe('usdc_polygon') - }) - it('native/ethereum should return the correct currency code', () => { - expect(getDefaultCurrencyCode('NATIVE', 'ethereum')).toBe('eth') - }) - it('usdc/ethereum should return the correct currency code', () => { - expect(getDefaultCurrencyCode(USDC_MAINNET.address, 'ethereum')).toBe('usdc') - }) - it('usdt/ethereum should return the correct currency code', () => { - expect(getDefaultCurrencyCode(USDT.address, 'ethereum')).toBe('usdt') - }) - it('chain/token mismatch should default to eth', () => { - expect(getDefaultCurrencyCode(USDC_ARBITRUM.address, 'ethereum')).toBe('eth') - expect(getDefaultCurrencyCode(USDC_OPTIMISM.address, 'ethereum')).toBe('eth') - expect(getDefaultCurrencyCode(USDC_POLYGON.address, 'ethereum')).toBe('eth') - expect(getDefaultCurrencyCode(MATIC.address, 'arbitrum')).toBe('eth') - }) -}) - -describe('parseLocation', () => { - it('should parse the URL correctly', () => { - expect(parsePathParts('/tokens/ethereum/0x2260fac5e5542a773aa44fbcfedf7c193bc2c599')).toEqual({ - network: 'ethereum', - tokenAddress: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', - }) - expect(parsePathParts('tokens/ethereum/0x2260fac5e5542a773aa44fbcfedf7c193bc2c599')).toEqual({ - network: 'ethereum', - tokenAddress: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', - }) - expect(parsePathParts('/swap')).toEqual({ - network: undefined, - tokenAddress: undefined, - }) - }) -}) diff --git a/src/components/FiatOnrampModal/utils.ts b/src/components/FiatOnrampModal/utils.ts deleted file mode 100644 index 032d7c11847..00000000000 --- a/src/components/FiatOnrampModal/utils.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { ChainId, WETH9 } from '@uniswap/sdk-core' -import { - BRIDGED_USDC_ARBITRUM, - MATIC, - USDC_ARBITRUM, - USDC_MAINNET, - USDC_OPTIMISM, - USDC_POLYGON, - USDT, - WBTC, - WETH_POLYGON, -} from 'constants/tokens' -import { Chain } from 'graphql/data/__generated__/types-and-hooks' -import { validateUrlChainParam } from 'graphql/data/util' - -import { MoonpaySupportedCurrencyCode } from './constants' - -type MoonpaySupportedChain = Chain.Ethereum | Chain.Polygon | Chain.Arbitrum | Chain.Optimism -const moonPaySupportedChains = [Chain.Ethereum, Chain.Polygon, Chain.Arbitrum, Chain.Optimism] - -const CURRENCY_CODES: { - [K in MoonpaySupportedChain]: { - [key: string]: MoonpaySupportedCurrencyCode - native: MoonpaySupportedCurrencyCode - } -} = { - [Chain.Ethereum]: { - [WETH9[ChainId.MAINNET]?.address.toLowerCase()]: 'weth', - [USDC_MAINNET.address.toLowerCase()]: 'usdc', - [USDT.address.toLowerCase()]: 'usdt', - [WBTC.address.toLowerCase()]: 'wbtc', - [MATIC.address.toLowerCase()]: 'polygon', - native: 'eth', - }, - [Chain.Arbitrum]: { - [USDC_ARBITRUM.address.toLowerCase()]: 'usdc_arbitrum', - [BRIDGED_USDC_ARBITRUM.address.toLowerCase()]: 'usdc_arbitrum', - native: 'eth_arbitrum', - }, - [Chain.Optimism]: { - [USDC_OPTIMISM.address.toLowerCase()]: 'usdc_optimism', - native: 'eth_optimism', - }, - [Chain.Polygon]: { - [USDC_POLYGON.address.toLowerCase()]: 'usdc_polygon', - [WETH_POLYGON.address.toLowerCase()]: 'eth_polygon', - native: 'matic_polygon', - }, -} - -export function getDefaultCurrencyCode( - address: string | undefined, - chainName: string | undefined -): MoonpaySupportedCurrencyCode { - const chain = validateUrlChainParam(chainName) - if (!address || !chain) return 'eth' - if (moonPaySupportedChains.includes(chain)) { - const code = CURRENCY_CODES[chain as MoonpaySupportedChain]?.[address.toLowerCase()] - return code ?? 'eth' - } - return 'eth' -} - -/** - * You should use useParams() from react-router-dom instead of this function if possible. - * This function is only used in the case where we need to parse the path outside the scope of the router. - */ -export function parsePathParts(pathname: string): { network?: string; tokenAddress?: string } { - const pathParts = pathname.split('/') - // Matches the /tokens// path. - const network = pathParts.length > 2 ? pathParts[pathParts.length - 2] : undefined - const tokenAddress = pathParts.length > 2 ? pathParts[pathParts.length - 1] : undefined - return { network, tokenAddress } -} diff --git a/src/components/TopLevelModals/index.tsx b/src/components/TopLevelModals/index.tsx index 056fcff9846..f5e15e43589 100644 --- a/src/components/TopLevelModals/index.tsx +++ b/src/components/TopLevelModals/index.tsx @@ -1,7 +1,6 @@ import { OffchainActivityModal } from 'components/AccountDrawer/MiniPortfolio/Activity/OffchainActivityModal' import AirdropModal from 'components/AirdropModal' import AddressClaimModal from 'components/claim/AddressClaimModal' -import FiatOnrampModal from 'components/FiatOnrampModal' import { UkDisclaimerModal } from 'components/NavBar/UkDisclaimerModal' import DevFlagsBox from 'dev/DevFlagsBox' import Bag from 'nft/components/bag/Bag' @@ -22,7 +21,6 @@ export default function TopLevelModals() { - {shouldShowDevFlags && } diff --git a/src/components/swap/SwapBuyFiatButton.test.tsx b/src/components/swap/SwapBuyFiatButton.test.tsx deleted file mode 100644 index 7f52476cceb..00000000000 --- a/src/components/swap/SwapBuyFiatButton.test.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import userEvent from '@testing-library/user-event' -import { useWeb3React } from '@web3-react/core' -import { useAccountDrawer } from 'components/AccountDrawer' -import store from 'state' -import { setOriginCountry } from 'state/user/reducer' -import { mocked } from 'test-utils/mocked' -import { act, fireEvent, render, screen } from 'test-utils/render' - -import { useFiatOnrampAvailability, useOpenModal } from '../../state/application/hooks' -import SwapBuyFiatButton, { MOONPAY_REGION_AVAILABILITY_ARTICLE } from './SwapBuyFiatButton' - -jest.mock('../../state/application/hooks') -const mockUseFiatOnrampAvailability = useFiatOnrampAvailability as jest.MockedFunction -const mockUseOpenModal = useOpenModal as jest.MockedFunction - -jest.mock('components/AccountDrawer') -const mockuseAccountDrawer = useAccountDrawer as jest.MockedFunction - -const mockUseFiatOnRampsUnavailable = (shouldCheck: boolean) => { - return { - available: false, - availabilityChecked: shouldCheck, - error: null, - loading: false, - } -} - -const mockUseFiatOnRampsAvailable = (shouldCheck: boolean) => { - if (shouldCheck) { - return { - available: true, - availabilityChecked: true, - error: null, - loading: false, - } - } - return { - available: false, - availabilityChecked: false, - error: null, - loading: false, - } -} - -describe('SwapBuyFiatButton.tsx', () => { - let toggleWalletDrawer: jest.Mock - let useOpenModal: jest.Mock - - beforeAll(() => { - store.dispatch(setOriginCountry('US')) - toggleWalletDrawer = jest.fn() - useOpenModal = jest.fn() - }) - - it('matches base snapshot', () => { - mockUseFiatOnrampAvailability.mockImplementation(mockUseFiatOnRampsUnavailable) - mockuseAccountDrawer.mockImplementation(() => [false, toggleWalletDrawer]) - const { asFragment } = render() - expect(asFragment()).toMatchSnapshot() - }) - - it('fiat on ramps available in region, account unconnected', async () => { - mockUseFiatOnrampAvailability.mockImplementation(mockUseFiatOnRampsAvailable) - mockuseAccountDrawer.mockImplementation(() => [false, toggleWalletDrawer]) - mockUseOpenModal.mockImplementation(() => useOpenModal) - render() - await act(() => userEvent.click(screen.getByTestId('buy-fiat-button'))) - expect(toggleWalletDrawer).toHaveBeenCalledTimes(1) - expect(screen.queryByTestId('fiat-on-ramp-unavailable-tooltip')).not.toBeInTheDocument() - }) - - it('fiat on ramps available in region, account connected', async () => { - mocked(useWeb3React).mockReturnValue({ - account: '0x52270d8234b864dcAC9947f510CE9275A8a116Db', - isActive: true, - } as ReturnType) - mockUseFiatOnrampAvailability.mockImplementation(mockUseFiatOnRampsAvailable) - mockuseAccountDrawer.mockImplementation(() => [false, toggleWalletDrawer]) - mockUseOpenModal.mockImplementation(() => useOpenModal) - render() - await act(() => userEvent.click(screen.getByTestId('buy-fiat-button'))) - expect(toggleWalletDrawer).toHaveBeenCalledTimes(0) - expect(useOpenModal).toHaveBeenCalledTimes(1) - expect(screen.queryByTestId('fiat-on-ramp-unavailable-tooltip')).not.toBeInTheDocument() - expect(screen.queryByTestId('buy-fiat-flow-incomplete-indicator')).not.toBeInTheDocument() - }) - - it('fiat on ramps unavailable in region', async () => { - mockUseFiatOnrampAvailability.mockImplementation(mockUseFiatOnRampsUnavailable) - mockuseAccountDrawer.mockImplementation(() => [false, toggleWalletDrawer]) - render() - await act(() => userEvent.click(screen.getByTestId('buy-fiat-button'))) - fireEvent.mouseOver(screen.getByTestId('buy-fiat-button')) - expect(await screen.findByTestId('fiat-on-ramp-unavailable-tooltip')).toBeInTheDocument() - expect(await screen.findByText(/Learn more/i)).toHaveAttribute('href', MOONPAY_REGION_AVAILABILITY_ARTICLE) - expect(await screen.findByTestId('buy-fiat-button')).toBeDisabled() - }) -}) diff --git a/src/components/swap/SwapBuyFiatButton.tsx b/src/components/swap/SwapBuyFiatButton.tsx deleted file mode 100644 index 9e104fc5e1c..00000000000 --- a/src/components/swap/SwapBuyFiatButton.tsx +++ /dev/null @@ -1,124 +0,0 @@ -import { Trans } from '@lingui/macro' -import { useWeb3React } from '@web3-react/core' -import { useAccountDrawer } from 'components/AccountDrawer' -import { ButtonText } from 'components/Button' -import { MouseoverTooltip } from 'components/Tooltip' -import { useIsNotOriginCountry } from 'hooks/useIsNotOriginCountry' -import { useCallback, useEffect, useState } from 'react' -import styled from 'styled-components' -import { ExternalLink } from 'theme/components' -import { textFadeIn } from 'theme/styles' - -import { useFiatOnrampAvailability, useOpenModal } from '../../state/application/hooks' -import { ApplicationModal } from '../../state/application/reducer' - -export const MOONPAY_REGION_AVAILABILITY_ARTICLE = - 'https://support.uniswap.org/hc/en-us/articles/11306664890381-Why-isn-t-MoonPay-available-in-my-region-' - -enum BuyFiatFlowState { - // Default initial state. User is not actively trying to buy fiat. - INACTIVE, - // Buy fiat flow is active and region availability has been checked. - ACTIVE_CHECKING_REGION, - // Buy fiat flow is active, feature is available in user's region & needs wallet connection. - ACTIVE_NEEDS_ACCOUNT, -} - -const StyledTextButton = styled(ButtonText)` - ${textFadeIn} - color: ${({ theme }) => theme.neutral2}; - gap: 4px; - font-weight: 485; - &:focus { - text-decoration: none; - } - &:active { - text-decoration: none; - } -` - -export default function SwapBuyFiatButton() { - const { account } = useWeb3React() - const openFiatOnRampModal = useOpenModal(ApplicationModal.FIAT_ONRAMP) - const shouldShowBuyFiatButton = useIsNotOriginCountry('GB') - const [checkFiatRegionAvailability, setCheckFiatRegionAvailability] = useState(false) - const { - available: fiatOnrampAvailable, - availabilityChecked: fiatOnrampAvailabilityChecked, - loading: fiatOnrampAvailabilityLoading, - } = useFiatOnrampAvailability(checkFiatRegionAvailability) - const [buyFiatFlowState, setBuyFiatFlowState] = useState(BuyFiatFlowState.INACTIVE) - const [walletDrawerOpen, toggleWalletDrawer] = useAccountDrawer() - - // Depending on the current state of the buy fiat flow the user is in (buyFiatFlowState), - // the desired behavior of clicking the 'Buy' button is different. - // 1) Initially upon first click, need to check the availability of the feature in the user's - // region, and continue the flow. - // 2) If the feature is available in the user's region, need to connect a wallet, and continue - // the flow. - // 3) If the feature is available and a wallet account is connected, show fiat on ramp modal. - // 4) If the feature is unavailable, show feature unavailable tooltip. - const handleBuyCrypto = useCallback(() => { - if (!fiatOnrampAvailabilityChecked) { - setCheckFiatRegionAvailability(true) - setBuyFiatFlowState(BuyFiatFlowState.ACTIVE_CHECKING_REGION) - } else if (fiatOnrampAvailable && !account && !walletDrawerOpen) { - toggleWalletDrawer() - setBuyFiatFlowState(BuyFiatFlowState.ACTIVE_NEEDS_ACCOUNT) - } else if (fiatOnrampAvailable && account) { - openFiatOnRampModal() - setBuyFiatFlowState(BuyFiatFlowState.INACTIVE) - } else if (!fiatOnrampAvailable) { - setBuyFiatFlowState(BuyFiatFlowState.INACTIVE) - } - }, [ - fiatOnrampAvailabilityChecked, - fiatOnrampAvailable, - account, - walletDrawerOpen, - toggleWalletDrawer, - openFiatOnRampModal, - ]) - - // Continue buy fiat flow automatically when requisite state changes have occured. - useEffect(() => { - if ( - (buyFiatFlowState === BuyFiatFlowState.ACTIVE_CHECKING_REGION && fiatOnrampAvailabilityChecked) || - (account && buyFiatFlowState === BuyFiatFlowState.ACTIVE_NEEDS_ACCOUNT) - ) { - handleBuyCrypto() - } - }, [account, handleBuyCrypto, buyFiatFlowState, fiatOnrampAvailabilityChecked]) - - const buyCryptoButtonDisabled = - (!fiatOnrampAvailable && fiatOnrampAvailabilityChecked) || - fiatOnrampAvailabilityLoading || - // When wallet drawer is open AND user is in the connect wallet step of the buy fiat flow, disable buy fiat button. - (walletDrawerOpen && buyFiatFlowState === BuyFiatFlowState.ACTIVE_NEEDS_ACCOUNT) - - const fiatOnRampsUnavailableTooltipDisabled = - !fiatOnrampAvailabilityChecked || (fiatOnrampAvailabilityChecked && fiatOnrampAvailable) - - if (!shouldShowBuyFiatButton) { - return null - } - - return ( - - Crypto purchases are not available in your region. - - Learn more - - - } - placement="bottom" - disabled={fiatOnRampsUnavailableTooltipDisabled} - > - - Buy - - - ) -} diff --git a/src/components/swap/SwapHeader.tsx b/src/components/swap/SwapHeader.tsx index 28590edcafb..8f71d1786bc 100644 --- a/src/components/swap/SwapHeader.tsx +++ b/src/components/swap/SwapHeader.tsx @@ -6,7 +6,6 @@ import { ThemedText } from 'theme/components' import { RowBetween, RowFixed } from '../Row' import SettingsTab from '../Settings' -import SwapBuyFiatButton from './SwapBuyFiatButton' const StyledSwapHeader = styled(RowBetween)` margin-bottom: 10px; @@ -33,7 +32,6 @@ export default function SwapHeader({ Swap - diff --git a/src/constants/networks.ts b/src/constants/networks.ts index c8db52f4ce2..1b74095dcf2 100644 --- a/src/constants/networks.ts +++ b/src/constants/networks.ts @@ -112,26 +112,15 @@ export const FALLBACK_URLS = { * These are the URLs used by the interface when there is not another available source of chain data. */ export const RPC_URLS = { - [ChainId.MAINNET]: [ - `https://ethereum.keydonix.com/v1/mainnet`, - ...FALLBACK_URLS[ChainId.MAINNET], - ], + [ChainId.MAINNET]: [`https://ethereum.keydonix.com/v1/mainnet`, ...FALLBACK_URLS[ChainId.MAINNET]], [ChainId.GOERLI]: [`https://ethereum.keydonix.com/v1/goerli`, ...FALLBACK_URLS[ChainId.GOERLI]], [ChainId.SEPOLIA]: [...FALLBACK_URLS[ChainId.SEPOLIA]], [ChainId.OPTIMISM]: [...FALLBACK_URLS[ChainId.OPTIMISM]], - [ChainId.OPTIMISM_GOERLI]: [ - ...FALLBACK_URLS[ChainId.OPTIMISM_GOERLI], - ], - [ChainId.ARBITRUM_ONE]: [ - ...FALLBACK_URLS[ChainId.ARBITRUM_ONE], - ], - [ChainId.ARBITRUM_GOERLI]: [ - ...FALLBACK_URLS[ChainId.ARBITRUM_GOERLI], - ], + [ChainId.OPTIMISM_GOERLI]: [...FALLBACK_URLS[ChainId.OPTIMISM_GOERLI]], + [ChainId.ARBITRUM_ONE]: [...FALLBACK_URLS[ChainId.ARBITRUM_ONE]], + [ChainId.ARBITRUM_GOERLI]: [...FALLBACK_URLS[ChainId.ARBITRUM_GOERLI]], [ChainId.POLYGON]: [...FALLBACK_URLS[ChainId.POLYGON]], - [ChainId.POLYGON_MUMBAI]: [ - ...FALLBACK_URLS[ChainId.POLYGON_MUMBAI], - ], + [ChainId.POLYGON_MUMBAI]: [...FALLBACK_URLS[ChainId.POLYGON_MUMBAI]], [ChainId.CELO]: FALLBACK_URLS[ChainId.CELO], [ChainId.CELO_ALFAJORES]: FALLBACK_URLS[ChainId.CELO_ALFAJORES], [ChainId.BNB]: [...FALLBACK_URLS[ChainId.BNB]], diff --git a/src/state/application/hooks.ts b/src/state/application/hooks.ts index 53fb5be273b..afd0acf2874 100644 --- a/src/state/application/hooks.ts +++ b/src/state/application/hooks.ts @@ -1,84 +1,15 @@ import { DEFAULT_TXN_DISMISS_MS } from 'constants/misc' -import { useCallback, useEffect, useMemo, useState } from 'react' +import { useCallback, useMemo } from 'react' import { useAppDispatch, useAppSelector } from 'state/hooks' import { AppState } from 'state/reducer' -import { - addPopup, - ApplicationModal, - PopupContent, - removePopup, - setFiatOnrampAvailability, - setOpenModal, -} from './reducer' +import { addPopup, ApplicationModal, PopupContent, removePopup, setOpenModal } from './reducer' export function useModalIsOpen(modal: ApplicationModal): boolean { const openModal = useAppSelector((state: AppState) => state.application.openModal) return openModal === modal } -/** @ref https://dashboard.moonpay.com/api_reference/client_side_api#ip_addresses */ -interface MoonpayIPAddressesResponse { - alpha3?: string - isAllowed?: boolean - isBuyAllowed?: boolean - isSellAllowed?: boolean -} - -async function getMoonpayAvailability(): Promise { - const moonpayPublishableKey = process.env.REACT_APP_MOONPAY_PUBLISHABLE_KEY - if (!moonpayPublishableKey) { - throw new Error('Must provide a publishable key for moonpay.') - } - const moonpayApiURI = process.env.REACT_APP_MOONPAY_API - if (!moonpayApiURI) { - throw new Error('Must provide an api endpoint for moonpay.') - } - const res = await fetch(`${moonpayApiURI}/v4/ip_address?apiKey=${moonpayPublishableKey}`) - const data = await (res.json() as Promise) - return data.isBuyAllowed ?? false -} - -export function useFiatOnrampAvailability(shouldCheck: boolean, callback?: () => void) { - const dispatch = useAppDispatch() - const { available, availabilityChecked } = useAppSelector((state: AppState) => state.application.fiatOnramp) - const [error, setError] = useState(null) - const [loading, setLoading] = useState(false) - - useEffect(() => { - async function checkAvailability() { - setError(null) - setLoading(true) - try { - const result = await getMoonpayAvailability() - if (stale) return - dispatch(setFiatOnrampAvailability(result)) - if (result && callback) { - callback() - } - } catch (e) { - console.error('Error checking onramp availability', e.toString()) - if (stale) return - setError('Error, try again later.') - dispatch(setFiatOnrampAvailability(false)) - } finally { - if (!stale) setLoading(false) - } - } - - if (!availabilityChecked && shouldCheck) { - checkAvailability() - } - - let stale = false - return () => { - stale = true - } - }, [availabilityChecked, callback, dispatch, shouldCheck]) - - return { available, availabilityChecked, loading, error } -} - export function useToggleModal(modal: ApplicationModal): () => void { const isOpen = useModalIsOpen(modal) const dispatch = useAppDispatch() From 5b975662e0cf92d8a78dddba5dc487a61e0e1c48 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 2 Jan 2024 10:58:25 +0200 Subject: [PATCH 2/7] remove fiat availability --- src/state/application/reducer.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/state/application/reducer.ts b/src/state/application/reducer.ts index 747153d2fae..5d47b482dcd 100644 --- a/src/state/application/reducer.ts +++ b/src/state/application/reducer.ts @@ -67,9 +67,6 @@ const applicationSlice = createSlice({ name: 'application', initialState, reducers: { - setFiatOnrampAvailability(state, { payload: available }) { - state.fiatOnramp = { available, availabilityChecked: true } - }, updateChainId(state, action) { const { chainId } = action.payload state.chainId = chainId @@ -100,6 +97,5 @@ const applicationSlice = createSlice({ }, }) -export const { updateChainId, setFiatOnrampAvailability, setOpenModal, addPopup, removePopup } = - applicationSlice.actions +export const { updateChainId, setOpenModal, addPopup, removePopup } = applicationSlice.actions export default applicationSlice.reducer From ac29fcdfa13dd76f5303dd67ef95bc2a089abfb7 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 2 Jan 2024 11:02:12 +0200 Subject: [PATCH 3/7] linting --- src/constants/tokens.ts | 7 ------- src/hooks/useIsNotOriginCountry.ts | 7 ------- 2 files changed, 14 deletions(-) delete mode 100644 src/hooks/useIsNotOriginCountry.ts diff --git a/src/constants/tokens.ts b/src/constants/tokens.ts index f09ead0a1ed..494493013fd 100644 --- a/src/constants/tokens.ts +++ b/src/constants/tokens.ts @@ -96,13 +96,6 @@ export const DAI_OPTIMISM = new Token( 'DAI', 'Dai stable coin' ) -export const MATIC = new Token( - ChainId.MAINNET, - '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', - 18, - 'MATIC', - 'Polygon Matic' -) export const DAI_POLYGON = new Token( ChainId.POLYGON, '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', diff --git a/src/hooks/useIsNotOriginCountry.ts b/src/hooks/useIsNotOriginCountry.ts deleted file mode 100644 index fe66625dcd3..00000000000 --- a/src/hooks/useIsNotOriginCountry.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { useAppSelector } from 'state/hooks' -import { AppState } from 'state/reducer' - -export function useIsNotOriginCountry(country: string) { - const originCountry = useAppSelector((state: AppState) => state.user.originCountry) - return Boolean(originCountry) && originCountry !== country -} From d4b1a8152c41bbfdf05a286d90deab9143d156ba Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 2 Jan 2024 11:03:08 +0200 Subject: [PATCH 4/7] no need this test --- .../SwapBuyFiatButton.test.tsx.snap | 150 ------------------ 1 file changed, 150 deletions(-) delete mode 100644 src/components/swap/__snapshots__/SwapBuyFiatButton.test.tsx.snap diff --git a/src/components/swap/__snapshots__/SwapBuyFiatButton.test.tsx.snap b/src/components/swap/__snapshots__/SwapBuyFiatButton.test.tsx.snap deleted file mode 100644 index 7987707bfe4..00000000000 --- a/src/components/swap/__snapshots__/SwapBuyFiatButton.test.tsx.snap +++ /dev/null @@ -1,150 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`SwapBuyFiatButton.tsx matches base snapshot 1`] = ` - - .c1 { - box-sizing: border-box; - margin: 0; - min-width: 0; - -webkit-appearance: none; - -moz-appearance: none; - appearance: none; - display: inline-block; - text-align: center; - line-height: inherit; - -webkit-text-decoration: none; - text-decoration: none; - font-size: inherit; - padding-left: 16px; - padding-right: 16px; - padding-top: 8px; - padding-bottom: 8px; - color: white; - background-color: primary; - border: 0; - border-radius: 4px; -} - -.c2 { - padding: 16px; - width: 100%; - line-height: 24px; - font-weight: 535; - text-align: center; - border-radius: 16px; - outline: none; - border: 1px solid transparent; - color: #222222; - -webkit-text-decoration: none; - text-decoration: none; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; - justify-content: center; - -webkit-flex-wrap: nowrap; - -ms-flex-wrap: nowrap; - flex-wrap: nowrap; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - cursor: pointer; - position: relative; - z-index: 1; - will-change: transform; - -webkit-transition: -webkit-transform 450ms ease; - -webkit-transition: transform 450ms ease; - transition: transform 450ms ease; - -webkit-transform: perspective(1px) translateZ(0); - -ms-transform: perspective(1px) translateZ(0); - transform: perspective(1px) translateZ(0); -} - -.c2:disabled { - opacity: 50%; - cursor: auto; - pointer-events: none; -} - -.c2 > * { - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - -.c2 > a { - -webkit-text-decoration: none; - text-decoration: none; -} - -.c3 { - padding: 0; - width: -webkit-fit-content; - width: -moz-fit-content; - width: fit-content; - background: none; - -webkit-text-decoration: none; - text-decoration: none; -} - -.c3:focus { - -webkit-text-decoration: underline; - text-decoration: underline; -} - -.c3:hover { - opacity: 0.9; -} - -.c3:active { - -webkit-text-decoration: underline; - text-decoration: underline; -} - -.c3:disabled { - opacity: 50%; - cursor: auto; -} - -.c0 { - display: inline-block; - height: inherit; -} - -.c4 { - -webkit-animation: iAjNNh 125ms ease-in; - animation: iAjNNh 125ms ease-in; - color: #7D7D7D; - gap: 4px; - font-weight: 485; -} - -.c4:focus { - -webkit-text-decoration: none; - text-decoration: none; -} - -.c4:active { - -webkit-text-decoration: none; - text-decoration: none; -} - -
-
- -
-
-
-`; From 66b200e721e325b1b6ac16b695093b3ea31fc0a5 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 2 Jan 2024 11:05:36 +0200 Subject: [PATCH 5/7] not used --- src/components/Button/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx index c210b0f671b..763cac844ab 100644 --- a/src/components/Button/index.tsx +++ b/src/components/Button/index.tsx @@ -6,8 +6,6 @@ import styled, { DefaultTheme, useTheme } from 'styled-components' import { RowBetween } from '../Row' -export { default as LoadingButtonSpinner } from './LoadingButtonSpinner' - type ButtonProps = Omit const ButtonOverlay = styled.div` From d27a42a9cf4894f376b996c8e942c232b6eb7d8e Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 2 Jan 2024 11:07:58 +0200 Subject: [PATCH 6/7] not used --- src/components/Button/LoadingButtonSpinner.tsx | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/components/Button/LoadingButtonSpinner.tsx diff --git a/src/components/Button/LoadingButtonSpinner.tsx b/src/components/Button/LoadingButtonSpinner.tsx deleted file mode 100644 index 9cb659d487a..00000000000 --- a/src/components/Button/LoadingButtonSpinner.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { SpinnerSVG } from 'theme/components' - -const ButtonLoadingSpinner = (props: React.ComponentPropsWithoutRef<'svg'>) => ( - - - - -) - -export default ButtonLoadingSpinner From 4c68b3c3c24b9884240f745574e8a8076c3ba749 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Tue, 2 Jan 2024 11:14:20 +0200 Subject: [PATCH 7/7] remove test snap --- .../__snapshots__/parseRemote.test.tsx.snap | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/src/components/AccountDrawer/MiniPortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap b/src/components/AccountDrawer/MiniPortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap index a894b013daf..f5f3b5fd9fe 100644 --- a/src/components/AccountDrawer/MiniPortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap +++ b/src/components/AccountDrawer/MiniPortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap @@ -137,33 +137,6 @@ Object { } `; -exports[`parseRemote parseRemoteActivities should parse moonpay purchase 1`] = ` -Object { - "chainId": 1, - "currencies": Array [ - Token { - "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", - "chainId": 1, - "decimals": 18, - "isNative": false, - "isToken": true, - "name": "Wrapped Ether", - "symbol": "WETH", - }, - ], - "descriptor": "100 WETH for 100", - "from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3", - "hash": "someHash", - "logos": Array [ - "moonpay.svg", - ], - "nonce": 12345, - "status": "CONFIRMED", - "timestamp": 10000, - "title": "Purchased", -} -`; - exports[`parseRemote parseRemoteActivities should parse nft purchase 1`] = ` Object { "chainId": 1,