-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: foxwifhat fox benefits section dumb ui (#8605)
- Loading branch information
Showing
11 changed files
with
200 additions
and
0 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Box, Container, Heading, Image, useColorModeValue } from '@chakra-ui/react' | ||
import { foxAssetId } from '@shapeshiftoss/caip' | ||
import { useCallback } from 'react' | ||
import { useTranslate } from 'react-polyglot' | ||
import FoxWifHatIcon from 'assets/foxwifhat-logo.png' | ||
import { Text } from 'components/Text' | ||
import { useFeatureFlag } from 'hooks/useFeatureFlag/useFeatureFlag' | ||
|
||
import { FoxWifHatClaimRow } from './FoxWifHatClaimRow' | ||
|
||
// @TODO: replace with proper foxwifhat asset id | ||
const foxWifHatAssetId = foxAssetId | ||
|
||
export const FoxWifHat = () => { | ||
const translate = useTranslate() | ||
const isFoxWifHatEnabled = useFeatureFlag('FoxPageFoxWifHatSection') | ||
const containerBackground = useColorModeValue('blackAlpha.50', 'whiteAlpha.50') | ||
|
||
const handleClaim = useCallback(() => { | ||
// eslint-disable-next-line no-console | ||
console.log('Claim') | ||
}, []) | ||
|
||
if (!isFoxWifHatEnabled) return null | ||
|
||
return ( | ||
<> | ||
<Box py={10} bg={containerBackground}> | ||
<Container maxW='container.4xl' px={8}> | ||
<Heading as='h2' fontSize='2xl' display='flex' alignItems='center' mb={4}> | ||
<Image src={FoxWifHatIcon} height='32px' width='auto' me={2} /> | ||
{translate('foxPage.foxWifHat.title')} | ||
</Heading> | ||
|
||
<Text color='text.subtle' translation='foxPage.foxWifHat.description' /> | ||
|
||
<Box bg={containerBackground} borderRadius='lg' mt={8} mb={4}> | ||
<FoxWifHatClaimRow | ||
accountId='0xD41Ba840554701F5f6BefaEbaa927f4474078DBA' | ||
amountCryptoBaseUnit='800000000000000000000000' | ||
assetId={foxWifHatAssetId} | ||
discountPercentDecimal={0.72} | ||
isClaimed={true} | ||
onClaim={handleClaim} | ||
/> | ||
<FoxWifHatClaimRow | ||
accountId='0xD41Ba840554701F5f6BefaEbaa927f4474078DBA' | ||
amountCryptoBaseUnit='800000000000000000000000' | ||
assetId={foxWifHatAssetId} | ||
discountPercentDecimal={0.72} | ||
isClaimed={false} | ||
onClaim={handleClaim} | ||
/> | ||
</Box> | ||
|
||
<Text color='text.subtle' translation='foxPage.foxWifHat.discount' fontSize='sm' /> | ||
</Container> | ||
</Box> | ||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import type { StackDirection } from '@chakra-ui/react' | ||
import { Button, Flex, HStack, Stack, Text, useColorModeValue } from '@chakra-ui/react' | ||
import type { AssetId } from '@shapeshiftoss/caip' | ||
import { fromAssetId } from '@shapeshiftoss/caip' | ||
import { useMemo } from 'react' | ||
import { useTranslate } from 'react-polyglot' | ||
import { Amount } from 'components/Amount/Amount' | ||
import { WalletIcon } from 'components/Icons/WalletIcon' | ||
import { useLocaleFormatter } from 'hooks/useLocaleFormatter/useLocaleFormatter' | ||
import { fromBaseUnit } from 'lib/math' | ||
import { middleEllipsis } from 'lib/utils' | ||
import { | ||
selectAccountIdsByChainId, | ||
selectAccountNumberByAccountId, | ||
selectAssetById, | ||
} from 'state/slices/selectors' | ||
import { useAppSelector } from 'state/store' | ||
|
||
type FoxWifHatClaimRowProps = { | ||
accountId: string | ||
amountCryptoBaseUnit: string | ||
assetId: AssetId | ||
discountPercentDecimal: number | ||
isClaimed?: boolean | ||
onClaim?: () => void | ||
} | ||
|
||
const actionsPaddingLeft = { base: 10, md: 0 } | ||
const columnWidth = { base: '100%', md: '50%' } | ||
const columnDirection: StackDirection = { base: 'column', md: 'row' } | ||
const columnAlignItems = { md: 'center' } | ||
const columnJustifyContent = { md: 'space-between' } | ||
const columnSpacing = { base: 4, md: 12, lg: 24, xl: 48 } | ||
|
||
export const FoxWifHatClaimRow = ({ | ||
accountId, | ||
amountCryptoBaseUnit, | ||
assetId, | ||
discountPercentDecimal, | ||
isClaimed, | ||
onClaim, | ||
}: FoxWifHatClaimRowProps) => { | ||
const textColor = useColorModeValue('gray.500', 'gray.400') | ||
const translate = useTranslate() | ||
const foxWifHatAsset = useAppSelector(state => selectAssetById(state, assetId)) | ||
const accountNumber = useAppSelector(state => | ||
selectAccountNumberByAccountId(state, { accountId }), | ||
) | ||
const accountIdsByChainId = useAppSelector(selectAccountIdsByChainId) | ||
const { | ||
number: { toPercent }, | ||
} = useLocaleFormatter() | ||
|
||
const numberAccounts = useMemo(() => { | ||
return accountIdsByChainId[fromAssetId(assetId).chainId]?.length ?? 0 | ||
}, [accountIdsByChainId, assetId]) | ||
|
||
const amountCryptoHuman = useMemo(() => { | ||
if (!foxWifHatAsset) return | ||
|
||
return fromBaseUnit(amountCryptoBaseUnit, foxWifHatAsset.precision) | ||
}, [amountCryptoBaseUnit, foxWifHatAsset]) | ||
|
||
return ( | ||
<Stack | ||
width='full' | ||
px={6} | ||
py={4} | ||
spacing={columnSpacing} | ||
direction={columnDirection} | ||
alignItems={columnAlignItems} | ||
justifyContent={columnJustifyContent} | ||
> | ||
<Flex width={columnWidth} alignItems='center' justifyContent='space-between'> | ||
<HStack spacing={4}> | ||
<WalletIcon color={textColor} boxSize={6} /> | ||
<Flex direction='column' alignItems='flex-start'> | ||
<Text fontWeight='bold' fontSize='sm'> | ||
{middleEllipsis(accountId)} | ||
</Text> | ||
{numberAccounts > 1 ? ( | ||
<Text color={textColor} fontSize='xs'> | ||
{translate('accounts.accountNumber', { accountNumber })} | ||
</Text> | ||
) : null} | ||
</Flex> | ||
</HStack> | ||
|
||
<Amount.Crypto | ||
value={amountCryptoHuman} | ||
symbol={foxWifHatAsset?.symbol ?? ''} | ||
fontWeight='bold' | ||
maximumFractionDigits={2} | ||
/> | ||
</Flex> | ||
|
||
<Flex | ||
width={columnWidth} | ||
alignItems='center' | ||
justifyContent='space-between' | ||
pl={actionsPaddingLeft} | ||
> | ||
<Text color='green.500' fontSize='sm' fontWeight='bold'> | ||
{translate('foxPage.foxWifHat.discountText', { | ||
percent: toPercent(discountPercentDecimal), | ||
})} | ||
</Text> | ||
|
||
<Button | ||
colorScheme={isClaimed ? 'green' : 'gray'} | ||
size='sm' | ||
onClick={onClaim} | ||
isDisabled={isClaimed} | ||
> | ||
{isClaimed | ||
? translate('foxPage.foxWifHat.claimed') | ||
: translate('foxPage.foxWifHat.claim')} | ||
</Button> | ||
</Flex> | ||
</Stack> | ||
) | ||
} |
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