Commit 1344e57c authored by Jack Short's avatar Jack Short Committed by GitHub

feat: share link on transaction page (#5440)

* feat: share link on transaction page

* responding to comment
parent 0b18bf08
...@@ -2,6 +2,7 @@ import { formatEther } from '@ethersproject/units' ...@@ -2,6 +2,7 @@ import { formatEther } from '@ethersproject/units'
import { Trace, useTrace } from '@uniswap/analytics' import { Trace, useTrace } from '@uniswap/analytics'
import { EventName, ModalName } from '@uniswap/analytics-events' import { EventName, ModalName } from '@uniswap/analytics-events'
import clsx from 'clsx' import clsx from 'clsx'
import { OpacityHoverState } from 'components/Common'
import { Box } from 'nft/components/Box' import { Box } from 'nft/components/Box'
import { Portal } from 'nft/components/common/Portal' import { Portal } from 'nft/components/common/Portal'
import { Row } from 'nft/components/Flex' import { Row } from 'nft/components/Flex'
...@@ -15,15 +16,36 @@ import { ...@@ -15,15 +16,36 @@ import {
formatEthPrice, formatEthPrice,
formatUsdPrice, formatUsdPrice,
formatUSDPriceWithCommas, formatUSDPriceWithCommas,
generateTweetForPurchase,
getSuccessfulImageSize, getSuccessfulImageSize,
parseTransactionResponse, parseTransactionResponse,
} from 'nft/utils' } from 'nft/utils'
import { formatAssetEventProperties } from 'nft/utils/formatEventProperties' import { formatAssetEventProperties } from 'nft/utils/formatEventProperties'
import { useEffect, useMemo, useRef, useState } from 'react' import { useEffect, useMemo, useRef, useState } from 'react'
import { Upload } from 'react-feather'
import styled from 'styled-components/macro'
import { ExplorerDataType, getExplorerLink } from 'utils/getExplorerLink' import { ExplorerDataType, getExplorerLink } from 'utils/getExplorerLink'
import * as styles from './TransactionCompleteModal.css' import * as styles from './TransactionCompleteModal.css'
const TWITTER_WIDTH = 560
const TWITTER_HEIGHT = 480
const UploadLink = styled.a`
position: absolute;
right: 32px;
top: 32px;
color: ${({ theme }) => theme.textSecondary};
cursor: pointer;
${OpacityHoverState}
@media only screen and (max-width: ${({ theme }) => `${theme.breakpoint.sm}px`}) {
right: 12px;
top: 28px;
}
`
const TxCompleteModal = () => { const TxCompleteModal = () => {
const [ethPrice, setEthPrice] = useState(3000) const [ethPrice, setEthPrice] = useState(3000)
const [showUnavailable, setShowUnavailable] = useState(false) const [showUnavailable, setShowUnavailable] = useState(false)
...@@ -69,6 +91,16 @@ const TxCompleteModal = () => { ...@@ -69,6 +91,16 @@ const TxCompleteModal = () => {
useSendTransaction.subscribe((state) => (transactionStateRef.current = state.state)) useSendTransaction.subscribe((state) => (transactionStateRef.current = state.state))
}, []) }, [])
const shareTweet = () => {
window.open(
generateTweetForPurchase(nftsPurchased, txHashUrl),
'newwindow',
`left=${(window.screen.width - TWITTER_WIDTH) / 2}, top=${
(window.screen.height - TWITTER_HEIGHT) / 2
}, width=${TWITTER_WIDTH}, height=${TWITTER_HEIGHT}`
)
}
return ( return (
<> <>
{shouldShowModal && ( {shouldShowModal && (
...@@ -94,6 +126,9 @@ const TxCompleteModal = () => { ...@@ -94,6 +126,9 @@ const TxCompleteModal = () => {
<h1 className={styles.title}>Complete!</h1> <h1 className={styles.title}>Complete!</h1>
<p className={styles.subHeading}>Uniswap has granted your wish!</p> <p className={styles.subHeading}>Uniswap has granted your wish!</p>
</Box> </Box>
<UploadLink onClick={shareTweet} target="_blank">
<Upload size={24} strokeWidth={2} />
</UploadLink>
<Box <Box
className={styles.successAssetsContainer} className={styles.successAssetsContainer}
style={{ style={{
......
import { DetailsOrigin, GenieAsset, WalletAsset } from 'nft/types' import { DetailsOrigin, GenieAsset, UpdatedGenieAsset, WalletAsset } from 'nft/types'
export function getRarityStatus( export function getRarityStatus(
rarityStatusCache: Map<string, boolean>, rarityStatusCache: Map<string, boolean>,
...@@ -36,3 +36,11 @@ export const generateTweetForAsset = (asset: GenieAsset): string => { ...@@ -36,3 +36,11 @@ export const generateTweetForAsset = (asset: GenieAsset): string => {
asset.tokenId asset.tokenId
}%20via%20@uniswap` }%20via%20@uniswap`
} }
export const generateTweetForPurchase = (assets: UpdatedGenieAsset[], txHashUrl: string): string => {
const multipleCollections = assets.length > 0 && assets.some((asset) => asset.address !== assets[0].address)
const tweetText = `I just purchased ${
multipleCollections ? `${assets.length} NFTs` : `${assets.length} ${assets[0].collectionName ?? 'NFT'}`
} with Uniswap 🦄\n\nhttps://app.uniswap.org/#/nfts/collection/0x60bb1e2aa1c9acafb4d34f71585d7e959f387769\n${txHashUrl}`
return `https://twitter.com/intent/tweet?text=${encodeURIComponent(tweetText)}`
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment