Skip to content

Commit

Permalink
Locked gno claim 2 fixes (#453)
Browse files Browse the repository at this point in the history
* use new rinkeby contracts

* fix merkle drop contract address on GC

* more specific names

* localize vesting start date

* improve copy

* fix contract address link
  • Loading branch information
jfschwarz authored Apr 26, 2022
1 parent a4efa10 commit d1d77b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/custom/pages/Profile/LockedGnoVesting/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const COW = COW_TOKENS[SupportedChainId.MAINNET]
export const MERKLE_DROP_CONTRACT_ADDRESSES: Record<number, string> = {
[SupportedChainId.MAINNET]: '0x64646f112FfD6F1B7533359CFaAF7998F23C8c40',
[SupportedChainId.RINKEBY]: '0x5444c4AFb2ec7f7367C10F7732b8558650c5899F',
[SupportedChainId.XDAI]: '0x3d610e917130f9D036e85A030596807f57e11093',
[SupportedChainId.XDAI]: '0x48D8566887F8c7d99757CE29c2cD39962bfd9547',
}

const useMerkleDropContract = () => useContract<MerkleDrop>(MERKLE_DROP_CONTRACT_ADDRESSES, MERKLE_DROP_ABI, true)
Expand Down Expand Up @@ -56,7 +56,7 @@ export const useAllocation = (): CurrencyAmount<Token> => {
const START_TIME = 1644584715000
const DURATION = 126144000000

export const useBalances = () => {
export const useCowFromLockedGnoBalances = () => {
const { account } = useActiveWeb3React()
const allocated = useAllocation()
const vested = allocated.multiply(Math.min(Date.now() - START_TIME, DURATION)).divide(DURATION)
Expand All @@ -80,7 +80,7 @@ interface ClaimCallbackParams {
closeModal: () => void
isFirstClaim: boolean
}
export function useClaimCallback({
export function useClaimCowFromLockedGnoCallback({
openModal,
closeModal,
isFirstClaim,
Expand Down
33 changes: 19 additions & 14 deletions src/custom/pages/Profile/LockedGnoVesting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { OperationType } from 'components/TransactionConfirmationModal'
import { useErrorModal } from 'hooks/useErrorMessageAndModal'
import CopyHelper from 'components/Copy'
import { getBlockExplorerUrl } from 'utils'
import { formatDateWithTimezone } from 'utils/time'
import { SupportedChainId as ChainId } from 'constants/chains'
import { useActiveWeb3React } from 'hooks/web3'
import { MERKLE_DROP_CONTRACT_ADDRESSES } from 'pages/Profile/LockedGnoVesting/hooks'
import { useBalances, useClaimCallback } from './hooks'
import { MERKLE_DROP_CONTRACT_ADDRESSES, TOKEN_DISTRO_CONTRACT_ADDRESSES } from 'pages/Profile/LockedGnoVesting/hooks'
import { useCowFromLockedGnoBalances, useClaimCowFromLockedGnoCallback } from './hooks'

enum ClaimStatus {
INITIAL,
Expand All @@ -33,7 +34,7 @@ interface Props {
const LockedGnoVesting: React.FC<Props> = ({ openModal, closeModal }: Props) => {
const { chainId = ChainId.MAINNET } = useActiveWeb3React()
const [status, setStatus] = useState<ClaimStatus>(ClaimStatus.INITIAL)
const { allocated, vested, claimed, loading: loadingBalances } = useBalances()
const { allocated, vested, claimed, loading: loadingBalances } = useCowFromLockedGnoBalances()
const unvested = allocated.subtract(vested)
const allocatedFormatted = formatSmartLocaleAware(allocated, AMOUNT_PRECISION) || '0'
const vestedFormatted = formatSmartLocaleAware(vested, AMOUNT_PRECISION) || '0'
Expand All @@ -45,12 +46,18 @@ const LockedGnoVesting: React.FC<Props> = ({ openModal, closeModal }: Props) =>

const { handleSetError, handleCloseError, ErrorModal } = useErrorModal()

const claimCallback = useClaimCallback({
const isFirstClaim = claimed.equalTo(0)

const claimCallback = useClaimCowFromLockedGnoCallback({
openModal,
closeModal,
isFirstClaim: claimed.equalTo(0),
isFirstClaim,
})

const contractAddress = isFirstClaim
? MERKLE_DROP_CONTRACT_ADDRESSES[chainId]
: TOKEN_DISTRO_CONTRACT_ADDRESSES[chainId]

const handleClaim = useCallback(async () => {
handleCloseError()
if (!claimCallback) {
Expand Down Expand Up @@ -114,16 +121,16 @@ const LockedGnoVesting: React.FC<Props> = ({ openModal, closeModal }: Props) =>
<ConvertWrapper>
<BalanceDisplay titleSize={18} altColor={true}>
<i>
Vested{' '}
Claimable{' '}
<MouseoverTooltipContent
wrap
content={
<div>
<p>
<strong>COW vesting from the GNO lock</strong> is vested linearly over four years, starting on Fri
Feb 11 2022 at 13:05:15 GMT.
<strong>COW vesting from the GNO lock</strong> is vested linearly over four years, starting on{' '}
{formatDateWithTimezone(new Date('02-11-2022 13:05:15 GMT'))}.
</p>
<p>Each time you claim, you will receive the entire vested amount.</p>
<p>Each time you claim, you will receive the entire claimable amount.</p>
</div>
}
>
Expand All @@ -150,11 +157,9 @@ const LockedGnoVesting: React.FC<Props> = ({ openModal, closeModal }: Props) =>
</ConvertWrapper>

<CardActions>
<ExtLink href={getBlockExplorerUrl(chainId, MERKLE_DROP_CONTRACT_ADDRESSES[chainId], 'token')}>
View contract ↗
</ExtLink>
<CopyHelper toCopy={MERKLE_DROP_CONTRACT_ADDRESSES[chainId]}>
<div title="Click to copy token contract address">Copy contract</div>
<ExtLink href={getBlockExplorerUrl(chainId, contractAddress, 'address')}>View contract ↗</ExtLink>
<CopyHelper toCopy={contractAddress}>
<div title="Click to copy contract address">Copy contract</div>
</CopyHelper>
</CardActions>
</Card>
Expand Down

0 comments on commit d1d77b7

Please sign in to comment.