-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed share nft purchase screen (#5101)
- Loading branch information
Showing
9 changed files
with
79 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 62 additions & 45 deletions
107
packages/scoutgame-ui/src/components/common/NFTPurchaseDialog/components/SuccessView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,82 @@ | ||
'use client'; | ||
|
||
import { Box, Button, Stack, Typography } from '@mui/material'; | ||
import { Box, IconButton, Stack, Typography } from '@mui/material'; | ||
import Image from 'next/image'; | ||
import Link from 'next/link'; | ||
|
||
import { useMdScreen } from '../../../../hooks/useMediaScreens'; | ||
|
||
export function SuccessView({ | ||
builder | ||
}: { | ||
builder: { id: string; displayName: string; nftImageUrl?: string | null; path: string }; | ||
builder: { id: string; displayName: string; congratsImageUrl?: string | null; path: string }; | ||
}) { | ||
const isMd = useMdScreen(); | ||
|
||
const handleShare = (platform: 'x' | 'telegram' | 'warpcast') => { | ||
const shareUrl = getShareMessage({ builderName: builder.displayName, builderPath: builder.path, platform }); | ||
window.open(shareUrl, '_blank'); | ||
}; | ||
const size = !isMd ? 30 : 42.5; | ||
|
||
return ( | ||
<Stack gap={2} textAlign='center' data-test='success-view'> | ||
<Typography color='secondary' variant='h5' fontWeight={600}> | ||
Congratulations! | ||
</Typography> | ||
<Typography>You scouted {builder.displayName}</Typography> | ||
<Box | ||
bgcolor='black.dark' | ||
width='100%' | ||
p={2} | ||
display='flex' | ||
alignItems='center' | ||
flexDirection='column' | ||
gap={1} | ||
py={12} | ||
{builder.congratsImageUrl ? ( | ||
<Image src={builder.congratsImageUrl} alt={builder.path} width={400} height={400} /> | ||
) : ( | ||
<Image src='/images/no_nft_person.png' alt='no nft image available' width={200} height={200} /> | ||
)} | ||
<Stack | ||
sx={{ | ||
background: 'url(/images/nft-mint-bg.png)', | ||
backgroundRepeat: 'no-repeat', | ||
backgroundPosition: 'center', | ||
backgroundSize: 'cover' | ||
justifyContent: 'center', | ||
p: { | ||
xs: 1, | ||
md: 2 | ||
}, | ||
alignItems: 'center', | ||
backgroundColor: '#D8E1FF' | ||
}} | ||
> | ||
{builder.nftImageUrl ? ( | ||
<Image | ||
src={builder.nftImageUrl} | ||
alt={builder.path} | ||
width={200} | ||
height={300} | ||
style={{ aspectRatio: '1/1.4', width: '50%', height: '50%' }} | ||
/> | ||
) : ( | ||
<Image src='/images/no_nft_person.png' alt='no nft image available' width={200} height={200} /> | ||
)} | ||
</Box> | ||
<Button | ||
LinkComponent={Link} | ||
fullWidth | ||
href={ | ||
typeof window !== 'undefined' && 'Telegram' in window | ||
? `https://t.me/share/url?url=${window.location.origin}/u/${builder.path}&text=${encodeURI( | ||
`I scouted ${builder.displayName} on Scout Game!` | ||
)}` | ||
: `https://warpcast.com/~/compose?text=${encodeURI( | ||
`I scouted ${builder.displayName} on Scout Game!` | ||
)}&embeds[]=${window.location.origin}/u/${builder.path}` | ||
} | ||
target='_blank' | ||
rel='noopener noreferrer' | ||
> | ||
Share now | ||
</Button> | ||
<Typography variant={isMd ? 'h6' : 'subtitle1'} color='#000' fontWeight='bold'> | ||
Share now | ||
</Typography> | ||
<Stack flexDirection='row' justifyContent='center'> | ||
<IconButton onClick={() => handleShare('x')}> | ||
<Image src='/images/logos/x.png' alt='X' width={size} height={size} /> | ||
</IconButton> | ||
<IconButton onClick={() => handleShare('telegram')}> | ||
<Image src='/images/logos/telegram.png' alt='Telegram' width={size} height={size} /> | ||
</IconButton> | ||
<IconButton onClick={() => handleShare('warpcast')}> | ||
<Image src='/images/logos/warpcast.png' alt='Warpcast' width={size} height={size} /> | ||
</IconButton> | ||
</Stack> | ||
</Stack> | ||
</Stack> | ||
); | ||
} | ||
|
||
function getShareMessage({ | ||
builderName, | ||
builderPath, | ||
platform | ||
}: { | ||
builderName: string; | ||
builderPath: string; | ||
platform: 'x' | 'telegram' | 'warpcast'; | ||
}) { | ||
const embedUrl = `${window.location.origin}/u/${builderPath}`; | ||
const shareMessage = `I scouted ${builderName} on Scout Game!`; | ||
|
||
const urls = { | ||
x: `https://x.com/intent/tweet?text=${encodeURIComponent(shareMessage)}`, | ||
telegram: `https://t.me/share/url?url=${encodeURIComponent(embedUrl)}&text=${encodeURIComponent(shareMessage)}`, | ||
warpcast: `https://warpcast.com/~/compose?text=${encodeURIComponent(shareMessage)}&embeds[]=${encodeURIComponent( | ||
embedUrl | ||
)}` | ||
}; | ||
return urls[platform]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters