Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Show banner if the user has claimed already (#2393)
Browse files Browse the repository at this point in the history
* Show banner if the user has claimed already

* Update claimed banner message and color

* Change one const name
  • Loading branch information
nenadV91 committed Feb 9, 2022
1 parent d65d7f0 commit 66ed3cb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
31 changes: 31 additions & 0 deletions src/custom/pages/Claim/ClaimBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Trans } from '@lingui/macro'
import { useClaimState } from 'state/claim/hooks'
import { ClaimBanner as ClaimBannerWrapper } from './styled'
import CheckCircle from 'assets/cow-swap/check.svg'
import { ClaimStatus } from 'state/claim/actions'
import SVG from 'react-inlinesvg'
import { ClaimCommonTypes } from 'pages/Claim/types'

type ClaimBannerProps = Pick<ClaimCommonTypes, 'hasClaims'> & {
isClaimed: boolean
}

export default function ClaimBanner({ hasClaims, isClaimed }: ClaimBannerProps) {
const { claimStatus, activeClaimAccount, isInvestFlowActive } = useClaimState()

const shouldShowBanner =
claimStatus === ClaimStatus.DEFAULT && !!activeClaimAccount && !isInvestFlowActive && (hasClaims || isClaimed)

if (!shouldShowBanner) return null

return (
<ClaimBannerWrapper isClaimed={isClaimed}>
<SVG src={CheckCircle} description="eligible" />
<Trans>
{hasClaims
? 'This account is eligible for vCOW token claims!'
: 'This account has already claimed vCOW tokens!'}
</Trans>
</ClaimBannerWrapper>
)
}
22 changes: 0 additions & 22 deletions src/custom/pages/Claim/EligibleBanner.tsx

This file was deleted.

12 changes: 8 additions & 4 deletions src/custom/pages/Claim/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ClaimNav from './ClaimNav'
import ClaimingStatus from './ClaimingStatus'
import ClaimsOnOtherChainsBanner from './ClaimsOnOtherChainsBanner'
import ClaimsTable from './ClaimsTable'
import EligibleBanner from './EligibleBanner'
import ClaimBanner from './ClaimBanner'
import FooterNavButtons from './FooterNavButtons'
import InvestmentFlow from './InvestmentFlow'
import { ClaimSummary } from './ClaimSummary'
Expand Down Expand Up @@ -87,7 +87,11 @@ export default function Claim() {
const { handleCloseError, handleSetError, ErrorModal } = useErrorModal()

// get user claim data
const { claims: userClaimData, isLoading: isClaimDataLoading } = useUserEnhancedClaimData(activeClaimAccount)
const {
isClaimed,
claims: userClaimData,
isLoading: isClaimDataLoading,
} = useUserEnhancedClaimData(activeClaimAccount)

// get total unclaimed amount
const unclaimedAmount = useUserUnclaimedAmount(activeClaimAccount)
Expand Down Expand Up @@ -247,8 +251,8 @@ export default function Claim() {
<Confetti start={claimStatus === ClaimStatus.CONFIRMED} />
{/* Top nav buttons */}
<ClaimNav account={account} handleChangeAccount={handleChangeClick} />
{/* Show general title OR total to claim (user has airdrop or airdrop+investment) --------------------------- */}
<EligibleBanner hasClaims={hasClaims} />
{/* Show banner that tells if user has available claims or has already claimed all */}
<ClaimBanner isClaimed={isClaimed} hasClaims={hasClaims} />
{/* Show total to claim (user has airdrop or airdrop+investment) */}
<ClaimSummary hasClaims={hasClaims} unclaimedAmount={unclaimedAmount} />
{/* Get address/ENS (user not connected yet or opted for checking 'another' account) */}
Expand Down
8 changes: 4 additions & 4 deletions src/custom/pages/Claim/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,16 @@ export const NegativeIcon = styled(Frown)`
stroke: ${({ theme }) => theme.primary1};
`

export const EligibleBanner = styled.div`
export const ClaimBanner = styled.div<{ isClaimed: boolean }>`
width: 100%;
border-radius: var(--border-radius);
padding: 12px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
background: ${({ theme }) => transparentize(0.9, theme.success)};
color: ${({ theme }) => theme.success};
background: ${({ theme, isClaimed }) => transparentize(0.9, !isClaimed ? theme.success : theme.blue2)};
color: ${({ theme, isClaimed }) => (!isClaimed ? theme.success : theme.blue2)};
margin: 0 auto 16px;
font-weight: 600;
Expand All @@ -770,7 +770,7 @@ export const EligibleBanner = styled.div`
height: 21px;
> path {
fill: ${({ theme }) => theme.success};
fill: ${({ theme, isClaimed }) => (!isClaimed ? theme.success : theme.blue2)};
}
${({ theme }) => theme.mediaWidth.upToSmall`
Expand Down
9 changes: 7 additions & 2 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ export function useHasZeroInvested(): boolean {
type UseUserEnhancedClaimDataResult = {
claims: EnhancedUserClaimData[]
isLoading: boolean
isClaimed: boolean
}

/**
Expand All @@ -925,7 +926,7 @@ type UseUserEnhancedClaimDataResult = {
* @param account
*/
export function useUserEnhancedClaimData(account: Account): UseUserEnhancedClaimDataResult {
const { available, isLoading } = useClassifiedUserClaims(account)
const { available, claimed, isLoading } = useClassifiedUserClaims(account)
const { chainId: preCheckChainId } = useActiveWeb3React()
const native = useNativeTokenPrice()
const gno = useGnoPrice()
Expand All @@ -940,7 +941,11 @@ export function useUserEnhancedClaimData(account: Account): UseUserEnhancedClaim
return sorted.map((claim) => _enhanceClaimData(claim, chainId, { native, gno, usdc }))
}, [available, gno, native, preCheckChainId, usdc])

return { claims, isLoading }
const isClaimed = useMemo(() => {
return Boolean(!available.length && claimed.length)
}, [available.length, claimed.length])

return { claims, isClaimed, isLoading }
}

function _sortTypes(a: UserClaimData, b: UserClaimData): number {
Expand Down

0 comments on commit 66ed3cb

Please sign in to comment.