Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated RPC URL #60

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_ALCHEMY_API_URL=https://mainnet.infura.io/v3/
NEXT_PUBLIC_ALCHEMY_API_URL=https://mainnet.infura.io/v3/267d7afc40074cb393caa41e83578f9d
10 changes: 3 additions & 7 deletions src/hooks/distribution/useDistributionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ type DistributionInfo = {
dateEnded: BigNumber
lastClaim: BigNumber
amountOwedTotal: BigNumber
claimable: BigNumber
curve: BigNumber
}

const useDistribtuionInfo = (): DistributionInfo => {
const useDistributionInfo = (): DistributionInfo => {
const { library, account, chainId } = useWeb3React()
const distribution = useContract<BaoDistribution>('BaoDistribution')

Expand All @@ -26,9 +25,8 @@ const useDistribtuionInfo = (): DistributionInfo => {
['@/hooks/vebao/useAccountDistribution', providerKey(library, account, chainId)],
async () => {
const { dateStarted, dateEnded, lastClaim, amountOwedTotal } = await distribution.distributions(account)
const claimable = await distribution.claimable(account, 0)
const block = await library.getBlock()
const timeStarted = dateStarted.mul(1000).toNumber()
const block = await library.getBlock()
const timeNow = block.timestamp * 1000
const daysDiff = Math.floor((timeNow - timeStarted) / 86400000)
const curve = await distribution.distCurve(amountOwedTotal, exponentiate(BigNumber.from(daysDiff)))
Expand All @@ -38,7 +36,6 @@ const useDistribtuionInfo = (): DistributionInfo => {
dateEnded,
lastClaim,
amountOwedTotal,
claimable,
curve,
}
},
Expand All @@ -49,7 +46,6 @@ const useDistribtuionInfo = (): DistributionInfo => {
dateEnded: BigNumber.from(0),
lastClaim: BigNumber.from(0),
amountOwedTotal: BigNumber.from(0),
claimable: BigNumber.from(0),
curve: BigNumber.from(0),
},
},
Expand All @@ -64,4 +60,4 @@ const useDistribtuionInfo = (): DistributionInfo => {
return distributionInfo
}

export default useDistribtuionInfo
export default useDistributionInfo
8 changes: 5 additions & 3 deletions src/pages/distribution/components/Claim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useTransactionHandler from '@/hooks/base/useTransactionHandler'
import { BaoDistribution } from '@/typechain/BaoDistribution'
//import { useWeb3React } from '@web3-react/core'
import useDistributionInfo from '@/hooks/distribution/useDistributionInfo'
import useClaimable from '@/hooks/distribution/useClaimable'
import { getDisplayBalance } from '@/utils/numberFormat'
import { BigNumber } from 'ethers'
import { formatUnits } from 'ethers/lib/utils'
Expand All @@ -18,6 +19,7 @@ const Migration: React.FC = () => {
const { handleTx } = useTransactionHandler()
const distribution = useContract<BaoDistribution>('BaoDistribution')
const distributionInfo = useDistributionInfo()
const claimable = useClaimable()

let lastClaim = 'Never'
if (distributionInfo && !distributionInfo.dateStarted.eq(distributionInfo.lastClaim)) {
Expand Down Expand Up @@ -78,7 +80,7 @@ const Migration: React.FC = () => {
<div className='flex h-8 flex-row items-center justify-center gap-2 rounded px-2 py-4'>
<Image src='/images/tokens/BAO.png' height={24} width={24} alt='BAO' />
<Typography variant='base' className='font-semibold'>
{getDisplayBalance(distributionInfo.claimable || BigNumber.from(0))}
{getDisplayBalance(BigNumber.isBigNumber(claimable) ? claimable : BigNumber.from(0))}
</Typography>
</div>
</div>
Expand All @@ -98,11 +100,11 @@ const Migration: React.FC = () => {
<div className='w-2/5 flex-1'>
<Button
className='my-4'
disabled={!distributionInfo.claimable?.gt(0)}
disabled={!(BigNumber.isBigNumber(claimable) && claimable.gt(0))}
fullWidth
onClick={async () => {
const claim = distribution.claim()
handleTx(claim, `Distribution: Claim ${formatUnits(distributionInfo.claimable as BigNumber)} BAO`)
handleTx(claim, `Distribution: Claim ${formatUnits(claimable as BigNumber)} BAO`)
}}
>
Claim Now
Expand Down
25 changes: 9 additions & 16 deletions src/pages/distribution/components/Locked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const Migration: React.FC = () => {

const distribution = useContract<BaoDistribution>('BaoDistribution')

const { account, chainId, library } = useWeb3React()
const { account } = useWeb3React()
const { data: merkleLeaf } = useQuery(
['/api/vebao/distribution/proof', account, chainId],
['https://bao-distribution-api.herokuapp.com/', account],
async () => {
const leafResponse = await fetch(`/api/vebao/distribution/proof/${account}/`)
const leafResponse = await fetch(`https://bao-distribution-api.herokuapp.com/${account}`)
if (leafResponse.status !== 200) {
const { error } = await leafResponse.json()
throw new Error(`${error.code} - ${error.message}`)
Expand All @@ -67,17 +67,14 @@ const Migration: React.FC = () => {
},
)

const distributionInfo = useDistributionInfo()
const dist = useDistributionInfo()

const canStartDistribution = !!merkleLeaf

console.log('Date Started', distributionInfo ? distributionInfo.dateStarted : 0)
console.log('Can Start Distribution', canStartDistribution)
const canStartDistribution = !!distribution && !!dist && !!merkleLeaf

return (
<div className='flex flex-col items-center'>
<div className='pt-4 md:w-4/5'>
{distributionInfo && distributionInfo.dateStarted.gt(0) ? (
{dist && dist.dateStarted.gt(0) ? (
<>
<div className='pb-5'>
<Typography variant='lg' className='text-lg font-bold leading-6'>
Expand Down Expand Up @@ -168,18 +165,14 @@ const Migration: React.FC = () => {
<Typography className='px-2 font-semibold text-text-100'>Total Locked BAO</Typography>
<div className='flex h-8 w-auto flex-row items-center justify-center gap-2 rounded border border-primary-400 bg-primary-100 px-2 py-4'>
<Image src='/images/tokens/BAO.png' height={24} width={24} alt='BAO' />
<Typography className='font-bold'>
{getDisplayBalance((distributionInfo && distributionInfo.amountOwedTotal) || BigNumber.from(0))}
</Typography>
<Typography className='font-bold'>{getDisplayBalance(dist ? dist.amountOwedTotal : BigNumber.from(0))}</Typography>
</div>
</div>
<div className='flex flex-row items-center'>
<Typography className='px-2 font-semibold text-text-100'>BAO Unlocked</Typography>
<div className='flex h-8 w-auto flex-row items-center justify-center gap-2 rounded border border-primary-400 bg-primary-100 px-2 py-4'>
<Image src='/images/tokens/BAO.png' height={24} width={24} alt='BAO' />
<Typography className='font-bold'>
{getDisplayBalance((distributionInfo && distributionInfo.curve) || BigNumber.from(0))}
</Typography>
<Typography className='font-bold'>{getDisplayBalance(dist ? dist.curve : BigNumber.from(0))}</Typography>
</div>
</div>
</div>
Expand Down Expand Up @@ -236,7 +229,7 @@ const Migration: React.FC = () => {
</Button>
) : (
<Button
disabled={!canStartDistribution || (distributionInfo && distributionInfo.dateStarted.gt(0))}
disabled={!canStartDistribution || (dist && dist.dateStarted.gt(0))}
className='bg-primary-500'
onClick={async () => {
const startDistribution = distribution.startDistribution(merkleLeaf.proof, merkleLeaf.amount)
Expand Down