Skip to content

Commit

Permalink
feat: vesting phase 2
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Mar 20, 2024
1 parent 4da591b commit 66d6f65
Show file tree
Hide file tree
Showing 5 changed files with 4,614 additions and 59 deletions.
38 changes: 20 additions & 18 deletions src/pages/ElasticSnapshot/components/Vesting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { shortenAddress } from 'utils'
import { formatDisplayNumber } from 'utils/numbers'

import abi from '../data/abis/vestingAbi.json'
import vestingOptionA from '../data/vesting/optionA.json'
import vestingOptionB from '../data/vesting/optionB.json'
import VestingClaimModal, { vestingContractAddress } from './VestingClaimModal'
import VestingClaimModal from './VestingClaimModal'

const Details = styled.div`
margin-top: 24px;
Expand Down Expand Up @@ -87,15 +85,24 @@ const Legend = styled.div`

const format = (value: number) => formatDisplayNumber(value, { style: 'currency', significantDigits: 6 })

export default function Vesting({ userSelectedOption }: { userSelectedOption: 'A' | 'B' }) {
export interface VestingInterface {
claimData: { receiver: string; vestingAmount: number; index: number }
proof: string[]
}

export default function Vesting({
userSelectedOption,
userVestingData,
contractAddress,
tcLink,
}: {
userSelectedOption: 'A' | 'B'
userVestingData: VestingInterface
contractAddress: string
tcLink: string
}) {
const theme = useTheme()
const { account } = useActiveWeb3React()
const userVestingData = useMemo(
() =>
vestingOptionA.find(item => item.claimData.receiver.toLowerCase() === account?.toLowerCase()) ||
vestingOptionB.find(item => item.claimData.receiver.toLowerCase() === account?.toLowerCase()),
[account],
)

const proof = useMemo(() => userVestingData?.proof, [userVestingData])

Expand All @@ -105,7 +112,7 @@ export default function Vesting({ userSelectedOption }: { userSelectedOption: 'A
const [endTime, setEndTime] = useState(0)
const [vestedAmount, setVestedAmount] = useState(0)

const vestingContract = useReadingContract(vestingContractAddress[userSelectedOption], abi, ChainId.MATIC)
const vestingContract = useReadingContract(contractAddress, abi, ChainId.MATIC)

const [, setRender] = useState(0)
const getVestedData = useCallback(() => {
Expand Down Expand Up @@ -164,15 +171,10 @@ export default function Vesting({ userSelectedOption }: { userSelectedOption: 'A
proof={proof}
tokenAmount={claimableAmount}
vestingAmount={userVestingData.claimData.vestingAmount}
option={userSelectedOption}
contractAddress={contractAddress}
tcLink={tcLink}
/>
)}
<Text fontSize={14} color={theme.subText} lineHeight="20px">
<Trans>
You can find the vesting details of each category of assets that were affected by the exploit below.
</Trans>
</Text>

<Details>
<Box
sx={{ borderBottom: `1px solid ${theme.border}`, padding: '1rem 1.5rem', background: theme.background }}
Expand Down
42 changes: 22 additions & 20 deletions src/pages/ElasticSnapshot/components/VestingClaimModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,23 @@ import { friendlyError } from 'utils/errorMessage'
import VestingAbi from '../data/abis/vestingAbi.json'

const ContractInterface = new Interface(VestingAbi)
export const vestingContractAddress = {
A: '0x04F57dE350E76ec952b6B4d1283Ba800ab3c95e3',
B: '0xF3E4C1f21a1218Ae8e48569c94275ABd605563fD',
}

export default function VestingClaimModal({
onDismiss,
leafIndex,
proof,
tokenAmount,
vestingAmount,
option,
contractAddress,
tcLink,
}: {
leafIndex: number
onDismiss: () => void
proof: string[]
tokenAmount: number
vestingAmount: number
option: 'A' | 'B'
contractAddress: string
tcLink: string
}) {
const upToSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToSmall}px)`)
const theme = useTheme()
Expand Down Expand Up @@ -108,12 +106,11 @@ export default function VestingClaimModal({
name: 'Kyberswap Linear Vesting Grant',
version: '1',
chainId: ChainId.MATIC,
verifyingContract: vestingContractAddress[option],
verifyingContract: contractAddress,
},
message: {
leafIndex,
termsAndConditions:
'By confirming this transaction, I agree to the Terms and Conditions of KyberSwap Treasury Grant Program which can be found at this link https://bafkreidnmptjtdvhzcuy4jiib34j5aapsuklhrryqptvfprnld7o6st42y.ipfs.w3s.link',
termsAndConditions: `By confirming this transaction, I agree to the Terms and Conditions of KyberSwap Treasury Grant Program which can be found at this link ${tcLink}`,
},
}),
])
Expand All @@ -131,7 +128,7 @@ export default function VestingClaimModal({
library
?.getSigner()
.sendTransaction({
to: vestingContractAddress[option],
to: contractAddress,
data: encodedData,
})
.then(tx => {
Expand Down Expand Up @@ -161,7 +158,18 @@ export default function VestingClaimModal({
type: NotificationType.ERROR,
})
})
}, [option, account, library, notify, addTransactionWithType, onDismiss, leafIndex, proof, vestingAmount])
}, [
account,
library,
notify,
addTransactionWithType,
onDismiss,
leafIndex,
proof,
vestingAmount,
contractAddress,
tcLink,
])

useEffect(() => {
if (autoSign && chainId === ChainId.MATIC) {
Expand Down Expand Up @@ -222,11 +230,8 @@ export default function VestingClaimModal({

<Text color={theme.subText} fontSize={14} marginTop="24px">
Make sure you have read and understand the{' '}
<ExternalLink href="https://bafkreidnmptjtdvhzcuy4jiib34j5aapsuklhrryqptvfprnld7o6st42y.ipfs.w3s.link/">
KyberSwap’s Terms and Conditions
</ExternalLink>{' '}
before proceeding. You will need to Sign a message to confirm that you have read and accepted before claiming
your assets.
<ExternalLink href={tcLink}>KyberSwap’s Terms and Conditions</ExternalLink> before proceeding. You will need
to Sign a message to confirm that you have read and accepted before claiming your assets.
</Text>

<TermAndCondition
Expand All @@ -240,10 +245,7 @@ export default function VestingClaimModal({
style={{ marginRight: '12px', height: '14px', width: '14px', minWidth: '14px', cursor: 'pointer' }}
/>
<Text>
Accept{' '}
<ExternalLink href="https://bafkreidnmptjtdvhzcuy4jiib34j5aapsuklhrryqptvfprnld7o6st42y.ipfs.w3s.link/">
KyberSwap’s Terms and Conditions
</ExternalLink>
Accept <ExternalLink href={tcLink}>KyberSwap’s Terms and Conditions</ExternalLink>
</Text>
</TermAndCondition>
<Flex marginTop="24px" sx={{ gap: '1rem' }}>
Expand Down
Loading

0 comments on commit 66d6f65

Please sign in to comment.