Skip to content

Commit

Permalink
feat: Update header safe token widget for SAP
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Nov 26, 2024
1 parent dec9e37 commit 92085f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
49 changes: 37 additions & 12 deletions src/components/common/SafeTokenWidget/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import UnreadBadge from '@/components/common/UnreadBadge'
import { IS_PRODUCTION, SAFE_TOKEN_ADDRESSES, SAFE_LOCKING_ADDRESS } from '@/config/constants'
import { AppRoutes } from '@/config/routes'
import useChainId from '@/hooks/useChainId'
import type { Vesting } from '@/hooks/useSafeTokenAllocation'
import useSafeTokenAllocation, { useSafeVotingPower } from '@/hooks/useSafeTokenAllocation'
import { OVERVIEW_EVENTS } from '@/services/analytics'
import { formatVisualAmount } from '@/utils/formatters'
Expand All @@ -20,11 +22,19 @@ import { formatAmount } from '@/utils/formatNumber'

const TOKEN_DECIMALS = 18

export const useSafeTokenAddress = () => {
const chainId = useChainId()
return getSafeTokenAddress(chainId)
const canRedeemSAPUnboostedAllocation = (allocation?: Vesting[]): boolean => {
const sapUnboostedAllocation = allocation?.find(({ tag }) => tag === 'sap_unboosted')

if (!sapUnboostedAllocation) {
return false
}

return !sapUnboostedAllocation.isRedeemed && !sapUnboostedAllocation.isExpired
}

// TODO: Replace with actual date once contracts are deployed
const SAP_REDEEM_DEADLINE = '31.12.2025'

export const getSafeTokenAddress = (chainId: string): string | undefined => {
return SAFE_TOKEN_ADDRESSES[chainId]
}
Expand Down Expand Up @@ -61,10 +71,19 @@ const SafeTokenWidget = () => {
}

const flooredSafeBalance = formatVisualAmount(allocation || BigInt(0), TOKEN_DECIMALS, 0)
const canRedeemSAPUnboosted = canRedeemSAPUnboostedAllocation(allocationData)

return (
<Box className={css.container}>
<Tooltip title="Go to Safe{DAO} Governance">
<Tooltip
title={
url
? canRedeemSAPUnboosted
? `Redeem your allocation before ${SAP_REDEEM_DEADLINE} to be eligible!`
: 'Go to Safe{DAO} Governance'
: ''
}
>
<span>
<Track {...OVERVIEW_EVENTS.SAFE_TOKEN_WIDGET}>
<Link href={url} passHref legacyBehavior>
Expand All @@ -73,17 +92,23 @@ const SafeTokenWidget = () => {
<Typography
component="div"
variant="body2"
lineHeight={1}
// Badge does not accept className so must be here
className={css.allocationBadge}
sx={{
lineHeight: '20px',
}}
>
{allocationDataLoading || allocationLoading ? (
<Skeleton width="16px" animation="wave" />
) : (
flooredSafeBalance
)}
<UnreadBadge
invisible={!canRedeemSAPUnboosted}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right',
}}
>
{allocationDataLoading || allocationLoading ? (
<Skeleton width="16px" animation="wave" />
) : (
flooredSafeBalance
)}
</UnreadBadge>
</Typography>

<Divider orientation="vertical" />
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSafeTokenAllocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const VESTING_URL =
: 'https://safe-claiming-app-data.staging.5afe.dev/allocations/'

export type VestingData = {
tag: 'user' | 'ecosystem' | 'investor' | 'user_v2' // SEP #5
tag: 'user' | 'ecosystem' | 'investor' | 'user_v2' | 'sap_boosted' | 'sap_unboosted' // SEP #5
account: string
chainId: number
contract: string
Expand Down

0 comments on commit 92085f3

Please sign in to comment.