ido
This commit is contained in:
parent
c82edf99b7
commit
43aec46f87
|
|
@ -54,7 +54,7 @@ const Referral = lazy(() => import('./views/Referral'))
|
|||
const Board = lazy(() => import('./views/Board'))
|
||||
const Nft = lazy(() => import('./views/Nft'))
|
||||
const Announcement = lazy(() => import('./views/Announcement'))
|
||||
const Exchange = lazy(() => import('./views/Exchange'))
|
||||
const Ido = lazy(() => import('./views/Ido'))
|
||||
|
||||
// This config is required for number formatting
|
||||
BigNumber.config({
|
||||
|
|
@ -100,8 +100,8 @@ const App: React.FC = () => {
|
|||
<Route path="/pools">
|
||||
<Pools />
|
||||
</Route>
|
||||
<Route path="/exchange">
|
||||
<Exchange />
|
||||
<Route path="/ido">
|
||||
<Ido />
|
||||
</Route>
|
||||
<Route path="/referral">
|
||||
<Referral />
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const config: (t: ContextApi['t']) => MenuEntry[] = (t) => [
|
|||
{
|
||||
label: t('IDO Exchange'),
|
||||
icon: 'FarmIcon',
|
||||
href: '/exchange',
|
||||
href: '/Ido',
|
||||
},
|
||||
{
|
||||
label: t('Exchange'),
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ export default {
|
|||
56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长收益
|
||||
},
|
||||
idoPurchase: {
|
||||
97: '0x3d437b81f8080c11d0e7c6b8a6c8185d8b92afee',
|
||||
56: '0x3d437b81f8080c11d0e7c6b8a6c8185d8b92afee', // NEED CHANGE IDO兑换
|
||||
97: '0x2bAA17bDeC5cDF2943309B245EF5310FF9c46B01',
|
||||
56: '0x2bAA17bDeC5cDF2943309B245EF5310FF9c46B01', // NEED CHANGE IDO兑换
|
||||
},
|
||||
lotteryV2: {
|
||||
97: '0x5790c3534F30437641541a0FA04C992799602998',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
import request from 'utils/request'
|
||||
|
||||
export const getPurchaseActivity = () => {
|
||||
return request.request({
|
||||
url: '/high_city/app/api/purchasr/activity/current',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
export default getPurchaseActivity
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
import { createSlice } from '@reduxjs/toolkit'
|
||||
import { getReferralRewardInfo, getReferralConfigInfo } from 'services/referral'
|
||||
import { ReferralInfo, ReferralConfigType, ReferralConfigInfo } from 'types/referral'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import erc20ABI from 'config/abi/erc20.json'
|
||||
import multicall from 'utils/multicall'
|
||||
import tokens from 'config/constants/tokens'
|
||||
import { getAddress, getIdoPurchaseAddress } from 'utils/addressHelpers'
|
||||
import { ReferralState } from '../types'
|
||||
|
||||
const initialState: ReferralState = {
|
||||
commanderConfigInfo: {},
|
||||
normalConfigInfo: {},
|
||||
isCommander: false,
|
||||
rewardInfo: {},
|
||||
}
|
||||
const payWayList = {
|
||||
usdt: tokens.usdt,
|
||||
}
|
||||
export const referralSlice = createSlice({
|
||||
name: 'Ido',
|
||||
initialState,
|
||||
reducers: {
|
||||
setReferralInfo: (state, action) => {
|
||||
console.log(action)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Actions
|
||||
export const { setReferralInfo } = referralSlice.actions
|
||||
// Thunks
|
||||
// export const fetchReferralInfoAsync = (account) => async (dispatch) => {
|
||||
// if (!account) {
|
||||
// dispatch(setReferralInfo({}))
|
||||
// return
|
||||
// }
|
||||
// const data: ReferralInfo = await getReferralRewardInfo()
|
||||
// const configInfo: ReferralConfigInfo[] = await getReferralConfigInfo()
|
||||
// dispatch(
|
||||
// setReferralInfo({
|
||||
// commanderConfigInfo: configInfo?.find((item) => item.type === ReferralConfigType.COMMANDER) || {},
|
||||
// normalConfigInfo: configInfo?.find((item) => item.type === ReferralConfigType.NORMAL) || {},
|
||||
// isCommander: data.isCommander,
|
||||
// rewardInfo: data.reward || {},
|
||||
// }),
|
||||
// )
|
||||
// }
|
||||
|
||||
export const fetchIdoUserAllowances = async (account: string) => {
|
||||
const calls = Object.values(payWayList).map((payWayItem) => {
|
||||
const tokenAddresses = getAddress(payWayItem.address)
|
||||
const idoPurchaseAddress = getIdoPurchaseAddress()
|
||||
return { address: tokenAddresses, name: 'allowance', params: [account, idoPurchaseAddress] }
|
||||
})
|
||||
|
||||
const rawLpAllowances = await multicall(erc20ABI, calls)
|
||||
const parsedLpAllowances = rawLpAllowances.map((balance) => {
|
||||
return new BigNumber(balance).toNumber()
|
||||
})
|
||||
return {
|
||||
usdt: parsedLpAllowances[0],
|
||||
}
|
||||
}
|
||||
|
||||
export default referralSlice.reducer
|
||||
|
|
@ -60,7 +60,7 @@ import chainlinkOracleAbi from 'config/abi/chainlinkOracle.json'
|
|||
import MultiCallAbi from 'config/abi/Multicall.json'
|
||||
import bunnySpecialCakeVaultAbi from 'config/abi/bunnySpecialCakeVault.json'
|
||||
import bunnySpecialPredictionAbi from 'config/abi/bunnySpecialPrediction.json'
|
||||
import idoPurchase from 'config/abi/purchase.json'
|
||||
import idoPurchase from 'config/abi/idoPurchase.json'
|
||||
import { ChainLinkOracleContract, PredictionsContract } from './types'
|
||||
|
||||
const getContract = (abi: any, address: string, signer?: ethers.Signer | ethers.providers.Provider) => {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ const StakeAction: React.FC<NodeCardActionsProps> = ({ stakedBalance, tokenBalan
|
|||
const { t } = useTranslation()
|
||||
const { toastWarning } = useToast()
|
||||
const { onStake } = useStakeBoard(pid)
|
||||
console.log(onStake)
|
||||
const { onUnstake } = useUnstakeBoard(pid)
|
||||
const { onUnstake: onUnstakeForce } = useUnstakeForceBoard(pid)
|
||||
const { tokenDecimals = 18, minStakeAmount, userData } = useBoardsFromPid(pid)
|
||||
|
|
|
|||
|
|
@ -1,81 +0,0 @@
|
|||
import React, { useMemo, useState, useEffect } from 'react'
|
||||
import styled, { keyframes } from 'styled-components'
|
||||
import { useTranslation } from 'contexts/Localization'
|
||||
import { Flex, Text, Button } from '@pancakeswap/uikit'
|
||||
import { useIdoPurchase } from 'hooks/useContract'
|
||||
|
||||
import { useAccount } from 'state/userInfo/hooks'
|
||||
import UnlockButton from 'components/UnlockButton'
|
||||
import ExchangeInput from './ExchangeInput'
|
||||
|
||||
const FCard = styled.div`
|
||||
width: 650px;
|
||||
background: ${(props) => props.theme.card.background};
|
||||
border-radius: 32px;
|
||||
box-shadow: 0px 2px 30px 0px rgba(0, 0, 0, 0.1);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
padding: 50px 70px;
|
||||
`
|
||||
const HeaderText = styled(Text)`
|
||||
font-size: 48px;
|
||||
color: #280d5f;
|
||||
`
|
||||
const TimeText = styled(Text)`
|
||||
color: #7a6eaa;
|
||||
font-size: 22px;
|
||||
`
|
||||
|
||||
const RateText = styled(Text)`
|
||||
font-size: 30px;
|
||||
color: #280d5f;
|
||||
`
|
||||
const RateNumber = styled(Text)`
|
||||
font-size: 30px;
|
||||
color: #1fc7d4;
|
||||
`
|
||||
const FooterButton = styled.div`
|
||||
margin-top: 50px;
|
||||
width: 100%;
|
||||
`
|
||||
const UnlockButtonDiv = styled(UnlockButton)`
|
||||
width: 100%;
|
||||
`
|
||||
|
||||
const ExchangeCard: React.FC = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const account = useAccount()
|
||||
|
||||
const useBuyTransaction = () => {
|
||||
return useIdoPurchase()
|
||||
}
|
||||
console.log(useBuyTransaction())
|
||||
// useEffect(() => {}, [])
|
||||
|
||||
return (
|
||||
<FCard>
|
||||
<HeaderText>{t('IDO exchange in the first phase')}</HeaderText>
|
||||
<TimeText>{t('Opening time of next exchange period:')}2022.5.16 00:00</TimeText>
|
||||
<ExchangeInput name="USDT" />
|
||||
<Flex alignItems="center" justifyContent="center" marginTop={20}>
|
||||
<RateText>{t('Exchange rate')}:</RateText>
|
||||
<RateNumber>1USDT=100HCC</RateNumber>
|
||||
</Flex>
|
||||
<Flex alignItems="center" justifyContent="center">
|
||||
<Text color="textSubtle">{t('gross')}:100000HCC</Text>
|
||||
<Text color="textSubtle" marginLeft={20}>
|
||||
{t('remaining quantity')}:100000HCC
|
||||
</Text>
|
||||
</Flex>
|
||||
<ExchangeInput name="HCC" />
|
||||
<FooterButton>
|
||||
{account ? <Button width="100%">{t('Immediately change')}</Button> : <UnlockButtonDiv />}
|
||||
</FooterButton>
|
||||
</FCard>
|
||||
)
|
||||
}
|
||||
|
||||
export default ExchangeCard
|
||||
|
|
@ -22,15 +22,16 @@ const CoinText = styled(Text)`
|
|||
interface InputProps {
|
||||
name: string
|
||||
value?: number | string
|
||||
onChange: (e: React.FormEvent<HTMLInputElement>) => void
|
||||
}
|
||||
|
||||
const ExchangeInput: React.FC<InputProps> = ({ name, value }) => {
|
||||
const ExchangeInput: React.FC<InputProps> = ({ name, value, onChange }) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<PriceContent>
|
||||
<CoinText>{name}</CoinText>
|
||||
<Input value={value} placeholder={t('Please enter the amount')} />
|
||||
<Input value={value} placeholder={t('Please enter the amount')} onChange={onChange} type="number" />
|
||||
</PriceContent>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
import React, { useMemo, useState, useEffect, useCallback } from 'react'
|
||||
import styled, { keyframes } from 'styled-components'
|
||||
import { useTranslation } from 'contexts/Localization'
|
||||
import { Flex, Text, Button, Input } from '@pancakeswap/uikit'
|
||||
import { getAddress, getIdoPurchaseAddress } from 'utils/addressHelpers'
|
||||
import { getPurchaseActivity } from 'services/idoPurchase'
|
||||
// import { useIdoPurchase } from 'hooks/useContract'
|
||||
import { fetchIdoUserAllowances } from 'state/ido'
|
||||
import multicall from 'utils/multicall'
|
||||
import { useERC20, useIdoPurchase } from 'hooks/useContract'
|
||||
import idoPurchaseABI from 'config/abi/idoPurchase.json'
|
||||
|
||||
import tokens from 'config/constants/tokens'
|
||||
import { useAccount } from 'state/userInfo/hooks'
|
||||
import UnlockButton from 'components/UnlockButton'
|
||||
import ExchangeInput from './IdoInput'
|
||||
import { useApproveIdo, useBuyTransaction } from '../hooks'
|
||||
|
||||
const FCard = styled.div`
|
||||
width: 650px;
|
||||
background: ${(props) => props.theme.card.background};
|
||||
border-radius: 32px;
|
||||
box-shadow: 0px 2px 30px 0px rgba(0, 0, 0, 0.1);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
padding: 50px 70px;
|
||||
`
|
||||
const HeaderText = styled(Text)`
|
||||
font-size: 48px;
|
||||
color: #280d5f;
|
||||
`
|
||||
const TimeText = styled(Text)`
|
||||
color: #7a6eaa;
|
||||
font-size: 22px;
|
||||
`
|
||||
|
||||
const RateText = styled(Text)`
|
||||
font-size: 30px;
|
||||
color: #280d5f;
|
||||
`
|
||||
const RateNumber = styled(Text)`
|
||||
font-size: 30px;
|
||||
color: #1fc7d4;
|
||||
`
|
||||
const FooterButton = styled.div`
|
||||
margin-top: 50px;
|
||||
width: 100%;
|
||||
`
|
||||
const UnlockButtonDiv = styled(UnlockButton)`
|
||||
width: 100%;
|
||||
`
|
||||
|
||||
const ExchangeCard: React.FC = () => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const account = useAccount()
|
||||
|
||||
const [allowanceList, setAllowanceList] = useState({ usdt: 0 })
|
||||
const getAllowances = async () => {
|
||||
const allowances = await fetchIdoUserAllowances(account)
|
||||
setAllowanceList({
|
||||
usdt: allowances.usdt,
|
||||
})
|
||||
}
|
||||
|
||||
const getPurchasrInfo = async () => {
|
||||
const data = await getPurchaseActivity()
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (account) {
|
||||
getAllowances()
|
||||
getPurchasrInfo()
|
||||
}
|
||||
}, [account])
|
||||
|
||||
const usdtContract = useERC20(getAddress(tokens.usdt.address))
|
||||
const { onApprove: onUsdtApprove } = useApproveIdo(usdtContract)
|
||||
|
||||
const [loading, setLoading] = useState(false)
|
||||
const handleApprove = async (approve) => {
|
||||
try {
|
||||
setLoading(true)
|
||||
await approve()
|
||||
setLoading(false)
|
||||
getAllowances()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
const [usdtPrice, setUsdtPrice] = useState('')
|
||||
const [hccPrice, setHccPrice] = useState('')
|
||||
|
||||
const handleUsdtChange = (e: React.FormEvent<HTMLInputElement>) => {
|
||||
const price = Number(e.currentTarget.value) * Number(hccPrice)
|
||||
console.log(price)
|
||||
setUsdtPrice(e.currentTarget.value)
|
||||
setHccPrice(price.toString())
|
||||
}
|
||||
const handleHccChange = (e: React.FormEvent<HTMLInputElement>) => {
|
||||
setHccPrice(e.currentTarget.value)
|
||||
}
|
||||
const buyTransaction = useBuyTransaction()
|
||||
// 立即兑换
|
||||
const immediatelyChange = async () => {
|
||||
console.log('立即兑换')
|
||||
// "inputs": [
|
||||
// { "internalType": "uint256", "name": "round", "type": "uint256" },
|
||||
// { "internalType": "uint256", "name": "amount", "type": "uint256" }
|
||||
// ],
|
||||
// "name": "purchase",
|
||||
const params = [
|
||||
'0x8ec8610ef88cdd222d45a22dd98c55a98b979664',
|
||||
'50000000000000000000',
|
||||
'0',
|
||||
'1652787744',
|
||||
'1525022104880209921',
|
||||
'0x18e77720bdfb43fc6b0a9a9050b7001fcd8f859041bdb0986d053366238e41582ceacaaca5e8c9ac815f6cc054c7135638b38acf5cd0aeb8fe6112effe7901d81b',
|
||||
]
|
||||
const res = await buyTransaction()
|
||||
console.log(res)
|
||||
// setTxId(res.hash)
|
||||
const params1 = [1, 2]
|
||||
// const tx = await useIdoPurchase.purchase(...params)
|
||||
// console.log(idoPurchaseABI)
|
||||
// const Info = await multicall(idoPurchaseABI, [
|
||||
// {
|
||||
// address: getIdoPurchaseAddress(),
|
||||
// name: 'purchase',
|
||||
// params: params1,
|
||||
// },
|
||||
// ])
|
||||
// console.log(Info)
|
||||
}
|
||||
|
||||
return (
|
||||
<FCard>
|
||||
<HeaderText>{t('IDO exchange in the first phase')}</HeaderText>
|
||||
<TimeText>{t('Opening time of next exchange period:')}2022.5.16 00:00</TimeText>
|
||||
<ExchangeInput name="USDT" value={usdtPrice} onChange={handleUsdtChange} />
|
||||
<Flex alignItems="center" justifyContent="center" marginTop={20}>
|
||||
<RateText>{t('Exchange rate')}:</RateText>
|
||||
<RateNumber>1USDT=100HCC</RateNumber>
|
||||
</Flex>
|
||||
<Flex alignItems="center" justifyContent="center">
|
||||
<Text color="textSubtle">{t('gross')}:100000HCC</Text>
|
||||
<Text color="textSubtle" marginLeft={20}>
|
||||
{t('remaining quantity')}:100000HCC
|
||||
</Text>
|
||||
</Flex>
|
||||
<ExchangeInput name="HCC" value={hccPrice} onChange={handleHccChange} />
|
||||
<FooterButton>
|
||||
{account ? (
|
||||
allowanceList.usdt ? (
|
||||
<Button width="100%" onClick={immediatelyChange}>
|
||||
{t('Immediately change')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
mt="8px"
|
||||
width="100%"
|
||||
disabled={loading}
|
||||
onClick={() => {
|
||||
handleApprove(onUsdtApprove)
|
||||
}}
|
||||
>
|
||||
{t('Approve %coin% Contract', { coin: 'USDT' })}
|
||||
</Button>
|
||||
)
|
||||
) : (
|
||||
<UnlockButtonDiv />
|
||||
)}
|
||||
</FooterButton>
|
||||
</FCard>
|
||||
)
|
||||
}
|
||||
|
||||
export default ExchangeCard
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
import { useState, useCallback } from 'react'
|
||||
import { useIdoPurchase, useReferralchef } from 'hooks/useContract'
|
||||
import useTokenBalance from 'hooks/useTokenBalance'
|
||||
import erc20ABI from 'config/abi/erc20.json'
|
||||
import { getAddress, getIdoPurchaseAddress } from 'utils/addressHelpers'
|
||||
import { getPurchaseActivity } from 'services/idoPurchase'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import multicall from 'utils/multicall'
|
||||
import tokensList from 'config/constants/tokens'
|
||||
import useToast from 'hooks/useToast'
|
||||
import { useTranslation } from 'contexts/Localization'
|
||||
import { ethers, Contract } from 'ethers'
|
||||
import { getBalanceNumber, getDecimalAmountNumber } from 'utils/formatBalance'
|
||||
|
||||
import { getWithdrawRewardParams, getBuyReferralParams } from 'services/referral'
|
||||
|
||||
export const useApproveIdo = (tokenContract: Contract) => {
|
||||
const handleApprove = useCallback(async () => {
|
||||
try {
|
||||
const tx = await tokenContract.approve(getIdoPurchaseAddress(), ethers.constants.MaxUint256)
|
||||
const receipt = await tx.wait()
|
||||
return receipt.status
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}, [tokenContract])
|
||||
|
||||
return { onApprove: handleApprove }
|
||||
}
|
||||
|
||||
export const useBuyTransaction = () => {
|
||||
const idoPurchase = useIdoPurchase()
|
||||
const transaction = async () => {
|
||||
const data = await getPurchaseActivity()
|
||||
const { id } = data
|
||||
const params = [id, 1110000000000]
|
||||
const res = await idoPurchase.purchase(...params)
|
||||
return res
|
||||
}
|
||||
return transaction
|
||||
}
|
||||
|
||||
export default useApproveIdo
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import React, { useState, useEffect } from 'react'
|
||||
import styled from 'styled-components'
|
||||
import ExchangeCard from './components/ExchangeCard'
|
||||
import ExchangeCard from './components/IdoPurchaseCard'
|
||||
|
||||
const PageContent = styled.div`
|
||||
min-height: calc(100vh - 64px);
|
||||
|
|
@ -33,6 +33,7 @@ export const useBuyTransaction = () => {
|
|||
const data = await getBuyReferralParams()
|
||||
const { to, hccPrice, otherPaymentPrice, timestamp, code, sign } = data
|
||||
const params = [to, hccPrice, otherPaymentPrice, timestamp, code, sign]
|
||||
console.log(referralContract)
|
||||
const res = await referralContract.mint(...params)
|
||||
return res
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue