feat: 董事会

This commit is contained in:
gary 2022-04-24 00:33:58 +08:00
parent 1bff22307b
commit e3b2433d23
20 changed files with 865 additions and 1299 deletions

View File

@ -8,6 +8,8 @@ import { usePollCoreFarmData, useFetchProfile, usePollBlockNumber } from 'state/
import { DatePickerPortal } from 'components/DatePicker' import { DatePickerPortal } from 'components/DatePicker'
import { initAxios } from 'utils/request' import { initAxios } from 'utils/request'
import useToast from 'hooks/useToast' import useToast from 'hooks/useToast'
import { fetchUserInfo } from 'state/actions'
import { useAccount } from 'state/userInfo/hooks'
import GlobalStyle from './style/Global' import GlobalStyle from './style/Global'
import Menu from './components/Menu' import Menu from './components/Menu'
import SuspenseWithChunkError from './components/SuspenseWithChunkError' import SuspenseWithChunkError from './components/SuspenseWithChunkError'
@ -64,10 +66,14 @@ const App: React.FC = () => {
usePollCoreFarmData() usePollCoreFarmData()
const dispatch = useDispatch() const dispatch = useDispatch()
const toast = useToast() const toast = useToast()
const account = useAccount()
useEffect(() => { useEffect(() => {
initAxios(dispatch, toast) initAxios(dispatch, toast)
}) }, [])
useEffect(() => {
account && dispatch(fetchUserInfo())
}, [account])
return ( return (
<Router history={history}> <Router history={history}>

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState, useMemo } from 'react'
import { Menu as UikitMenu, ConnectorNames } from '@pancakeswap/uikit' import { Menu as UikitMenu, ConnectorNames } from '@pancakeswap/uikit'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { languageList } from 'config/localization/languages' import { languageList } from 'config/localization/languages'
@ -7,7 +7,7 @@ import useTheme from 'hooks/useTheme'
import useAuth from 'hooks/useAuth' import useAuth from 'hooks/useAuth'
import { useDispatch } from 'react-redux' import { useDispatch } from 'react-redux'
import { usePriceCakeBusd, useProfile } from 'state/hooks' import { usePriceCakeBusd, useProfile } from 'state/hooks'
import { useUnactiveAccount, useSignLogin, useAccount } from 'state/userInfo/hooks' import { useUnactiveAccount, useSignLogin, useAccount, useUserInfo } from 'state/userInfo/hooks'
import useWeb3Provider from 'hooks/useActiveWeb3React' import useWeb3Provider from 'hooks/useActiveWeb3React'
import { clearUserInfo } from 'state/actions' import { clearUserInfo } from 'state/actions'
import config from './config' import config from './config'
@ -22,7 +22,11 @@ const Menu = (props) => {
const unActiveAccount = useUnactiveAccount() const unActiveAccount = useUnactiveAccount()
const dispatch = useDispatch() const dispatch = useDispatch()
const { profile } = useProfile() const { profile } = useProfile()
const userInfo = useUserInfo()
const { currentLanguage, setLanguage, t } = useTranslation() const { currentLanguage, setLanguage, t } = useTranslation()
const inviteUrl = useMemo(() => {
return userInfo?.inviteCode ? `${window.location.origin}?inviteCode=${userInfo.inviteCode}` : window.location.origin
}, [userInfo])
const sign = useSignLogin() const sign = useSignLogin()
const handleLogin = async (connectorID: ConnectorNames) => { const handleLogin = async (connectorID: ConnectorNames) => {
await login(connectorID) await login(connectorID)
@ -43,6 +47,7 @@ const Menu = (props) => {
<UikitMenu <UikitMenu
account={account} account={account}
login={handleLogin} login={handleLogin}
inviteUrl={inviteUrl}
logout={handleLogout} logout={handleLogout}
isDark={isDark} isDark={isDark}
toggleTheme={toggleTheme} toggleTheme={toggleTheme}

View File

@ -1,21 +1,9 @@
[ [
{ {
"inputs": [ "inputs": [
{ { "internalType": "contract IERC20", "name": "_HCC", "type": "address" },
"internalType": "contract IERC20", { "internalType": "address", "name": "_HCCBODReawardPool", "type": "address" },
"name": "_HCC", { "internalType": "uint256", "name": "_minStakeAmount", "type": "uint256" }
"type": "address"
},
{
"internalType": "address",
"name": "_HCCBODReawardPool",
"type": "address"
},
{
"internalType": "uint256",
"name": "_minStakeAmount",
"type": "uint256"
}
], ],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "constructor" "type": "constructor"
@ -23,18 +11,8 @@
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [
{ { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
"indexed": true, { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
], ],
"name": "Deposit", "name": "Deposit",
"type": "event" "type": "event"
@ -42,18 +20,8 @@
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [
{ { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
"indexed": true, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
], ],
"name": "EmergencyWithdraw", "name": "EmergencyWithdraw",
"type": "event" "type": "event"
@ -61,76 +29,44 @@
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [
{ { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
"indexed": true, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
"internalType": "address", ],
"name": "previousOwner", "name": "Harvest",
"type": "address" "type": "event"
}, },
{ {
"indexed": true, "anonymous": false,
"internalType": "address", "inputs": [
"name": "newOwner", { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" },
"type": "address" { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
}
], ],
"name": "OwnershipTransferred", "name": "OwnershipTransferred",
"type": "event" "type": "event"
}, },
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [{ "indexed": false, "internalType": "address", "name": "newHCCBODReawardPool", "type": "address" }],
{
"indexed": false,
"internalType": "address",
"name": "newHCCBODReawardPool",
"type": "address"
}
],
"name": "SetHCCBODReawardPoolEvent", "name": "SetHCCBODReawardPoolEvent",
"type": "event" "type": "event"
}, },
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [{ "indexed": false, "internalType": "uint256", "name": "newLockTime", "type": "uint256" }],
{
"indexed": false,
"internalType": "uint256",
"name": "newLockTime",
"type": "uint256"
}
],
"name": "SetLockTimeEvent", "name": "SetLockTimeEvent",
"type": "event" "type": "event"
}, },
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [{ "indexed": false, "internalType": "uint256", "name": "newMinStakeAmount", "type": "uint256" }],
{
"indexed": false,
"internalType": "uint256",
"name": "newMinStakeAmount",
"type": "uint256"
}
],
"name": "SetMinStakeAmontEvent", "name": "SetMinStakeAmontEvent",
"type": "event" "type": "event"
}, },
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [
{ { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
"indexed": true, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
], ],
"name": "Withdraw", "name": "Withdraw",
"type": "event" "type": "event"
@ -138,26 +74,14 @@
{ {
"inputs": [], "inputs": [],
"name": "HCC", "name": "HCC",
"outputs": [ "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }],
{
"internalType": "contract IERC20",
"name": "",
"type": "address"
}
],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ {
"inputs": [], "inputs": [],
"name": "HCCBODReawardPool", "name": "HCCBODReawardPool",
"outputs": [ "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
@ -165,223 +89,97 @@
"inputs": [], "inputs": [],
"name": "_poolInfo", "name": "_poolInfo",
"outputs": [ "outputs": [
{ { "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
"internalType": "uint256", { "internalType": "uint256", "name": "totalAmount", "type": "uint256" }
"name": "accHCCPerShare",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "totalAmount",
"type": "uint256"
}
], ],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ {
"inputs": [ "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }],
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"internalType": "address",
"name": "_userAddress",
"type": "address"
}
],
"name": "deposit", "name": "deposit",
"outputs": [], "outputs": [],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{ { "inputs": [], "name": "emergencyWithdrawHCC", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
"inputs": [], { "inputs": [], "name": "harvest", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
"name": "emergencyWithdrawHCC",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ {
"inputs": [], "inputs": [],
"name": "lockTime", "name": "lockTime",
"outputs": [ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ {
"inputs": [], "inputs": [],
"name": "minStakeAmount", "name": "minStakeAmount",
"outputs": [ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ {
"inputs": [], "inputs": [],
"name": "owner", "name": "owner",
"outputs": [ "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ {
"inputs": [], "inputs": [],
"name": "paused", "name": "paused",
"outputs": [ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ {
"inputs": [ "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }],
{
"internalType": "address",
"name": "_user",
"type": "address"
}
],
"name": "pendingHCC", "name": "pendingHCC",
"outputs": [ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{ {
"inputs": [], "inputs": [{ "internalType": "address", "name": "_HCCBODReawardPool", "type": "address" }],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_HCCBODReawardPool",
"type": "address"
}
],
"name": "setHCCBODReawardPool", "name": "setHCCBODReawardPool",
"outputs": [], "outputs": [],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{ {
"inputs": [ "inputs": [{ "internalType": "uint256", "name": "_lockTime", "type": "uint256" }],
{
"internalType": "uint256",
"name": "_lockTime",
"type": "uint256"
}
],
"name": "setLockTime", "name": "setLockTime",
"outputs": [], "outputs": [],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{ {
"inputs": [ "inputs": [{ "internalType": "uint256", "name": "_minStakeAmount", "type": "uint256" }],
{
"internalType": "uint256",
"name": "_minStakeAmount",
"type": "uint256"
}
],
"name": "setMinStakeAmount", "name": "setMinStakeAmount",
"outputs": [], "outputs": [],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{ "inputs": [], "name": "setPause", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{ {
"inputs": [], "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "setPause",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership", "name": "transferOwnership",
"outputs": [], "outputs": [],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{ "inputs": [], "name": "updatePool", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{ {
"inputs": [], "inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "updatePool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "userInfo", "name": "userInfo",
"outputs": [ "outputs": [
{ { "internalType": "uint256", "name": "amount", "type": "uint256" },
"internalType": "uint256", { "internalType": "uint256", "name": "rewardDebt", "type": "uint256" },
"name": "amount", { "internalType": "uint256", "name": "unLockTime", "type": "uint256" }
"type": "uint256"
},
{
"internalType": "uint256",
"name": "rewardDebt",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "unLockTime",
"type": "uint256"
}
], ],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{ { "inputs": [], "name": "withdrawHCC", "outputs": [], "stateMutability": "nonpayable", "type": "function" }
"inputs": [],
"name": "withdrawHCC",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
] ]

File diff suppressed because it is too large Load Diff

170
src/config/abi/holder.json Normal file
View File

@ -0,0 +1,170 @@
[
{
"inputs": [
{ "internalType": "contract IERC20", "name": "_HCC", "type": "address" },
{ "internalType": "address", "name": "_HCCStakeReawardPool", "type": "address" },
{ "internalType": "uint256", "name": "_minStakeAmount", "type": "uint256" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "user", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "user", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "EmergencyWithdraw",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "user", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "Harvest",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "address", "name": "newHCCStakeReawardPool", "type": "address" }],
"name": "SetHCCStakeReawardPoolEvent",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "uint256", "name": "newLockTime", "type": "uint256" }],
"name": "SetLockTimeEvent",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "uint256", "name": "newMinStakeAmount", "type": "uint256" }],
"name": "SetMinStakeAmontEvent",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "user", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "Withdraw",
"type": "event"
},
{
"inputs": [],
"name": "HCC",
"outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "HCCStakeReawardPool",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "_poolInfo",
"outputs": [
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }],
"name": "deposit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "emergencyWithdrawHCC", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{ "inputs": [], "name": "harvest", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [],
"name": "minStakeAmount",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "paused",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_user", "type": "address" }],
"name": "pendingHCC",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{ "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [{ "internalType": "address", "name": "_HCCStakeReawardPool", "type": "address" }],
"name": "setHCCStakeReawardPool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "_minStakeAmount", "type": "uint256" }],
"name": "setMinStakeAmount",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "setPause", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "updatePool", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "userInfo",
"outputs": [
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
{ "internalType": "uint256", "name": "rewardDebt", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{ "inputs": [], "name": "withdrawHCC", "outputs": [], "stateMutability": "nonpayable", "type": "function" }
]

View File

@ -1,5 +1,6 @@
import addresses from 'config/constants/contracts' import addresses from 'config/constants/contracts'
import boardChef from 'config/abi/board.json' import boardAbi from 'config/abi/board.json'
import holderAbi from 'config/abi/holder.json'
import tokens from './tokens' import tokens from './tokens'
import { BoardConfig } from './types' import { BoardConfig } from './types'
@ -12,7 +13,17 @@ const bordsList: BoardConfig[] = [
tokenAddresses: tokens.hcc.address, tokenAddresses: tokens.hcc.address,
tokenDecimals: 18, tokenDecimals: 18,
contractAddress: addresses.boardChef, contractAddress: addresses.boardChef,
abi: boardChef, abi: boardAbi,
},
{
pid: 2,
name: 'Holder',
img: 'nodes',
tokenSymbol: tokens.hcc.symbol,
tokenAddresses: tokens.hcc.address,
tokenDecimals: 18,
contractAddress: addresses.holderChef,
abi: holderAbi,
}, },
] ]

View File

@ -8,9 +8,13 @@ export default {
56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95', 56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95',
}, },
boardChef: { boardChef: {
97: '0x0dF74009bF2b85b2B19FC7aF67DD5AAF2cde4Ce0', 97: '0x88fd1e29160f6d498038254f1bd0f7729f812fa1',
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会合约 56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会合约
}, },
holderChef: {
97: '0x0373aa1d09d58bb789db694d6b944b052ff26d91',
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 持币人
},
referralChef: { referralChef: {
97: '0xE79D28722220fcC13833476E327DEA3a663f64DB', 97: '0xE79D28722220fcC13833476E327DEA3a663f64DB',
56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长 56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长

View File

@ -10,7 +10,7 @@ export {
updateUserPendingReward, updateUserPendingReward,
updateUserStakedBalance, updateUserStakedBalance,
} from './pools' } from './pools'
export { setUserInfo, clearUserInfo } from './userInfo' export { setUserInfo, clearUserInfo, fetchUserInfo } from './userInfo'
export { fetchReferralInfoAsync } from './referral' export { fetchReferralInfoAsync } from './referral'
export { fetchBoardsPublicDataAsync, fetchBoardUserDataAsync } from './boards' export { fetchBoardsPublicDataAsync, fetchBoardUserDataAsync } from './boards'
export { profileFetchStart, profileFetchSucceeded, profileFetchFailed } from './profile' export { profileFetchStart, profileFetchSucceeded, profileFetchFailed } from './profile'

View File

@ -1,6 +1,5 @@
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import erc20 from 'config/abi/erc20.json' import erc20 from 'config/abi/erc20.json'
import boardchefABI from 'config/abi/board.json'
import multicall from 'utils/multicall' import multicall from 'utils/multicall'
import { getAddress, getBoardAddress } from 'utils/addressHelpers' import { getAddress, getBoardAddress } from 'utils/addressHelpers'
import boardsConfig from 'config/constants/boards' import boardsConfig from 'config/constants/boards'
@ -26,8 +25,11 @@ const fetchBoards = async () => {
// eslint-disable-next-line prefer-const // eslint-disable-next-line prefer-const
let [tokenBalance, tokenDecimals] = await multicall(erc20, calls) let [tokenBalance, tokenDecimals] = await multicall(erc20, calls)
tokenBalance = new BigNumber(tokenBalance).div(new BigNumber(10).pow(tokenDecimals)) tokenBalance = new BigNumber(tokenBalance).div(new BigNumber(10).pow(tokenDecimals))
// eslint-disable-next-line prefer-const let minStakeAmount = 0
let [minStakeAmount, lockTime] = await multicall(boardConfig.abi, [ let lockTime = 0
if (boardConfig.pid === 1) {
// prettier-ignore
[minStakeAmount, lockTime] = await multicall(boardConfig.abi, [
// 最低质押额度 // 最低质押额度
{ {
address: BoardChefAddress, address: BoardChefAddress,
@ -39,9 +41,20 @@ const fetchBoards = async () => {
name: 'lockTime', name: 'lockTime',
}, },
]) ])
lockTime = new BigNumber(lockTime).toJSON() } else {
console.log(lockTime) // prettier-ignore
minStakeAmount = new BigNumber(minStakeAmount).div(new BigNumber(10).pow(tokenDecimals)).toJSON() [minStakeAmount] = await multicall(boardConfig.abi, [
// 最低质押额度
{
address: BoardChefAddress,
name: 'minStakeAmount',
},
])
lockTime = 0
}
lockTime = new BigNumber(lockTime).toNumber()
minStakeAmount = new BigNumber(minStakeAmount).div(new BigNumber(10).pow(tokenDecimals)).toNumber()
return { return {
...boardConfig, ...boardConfig,
tokenBalance: tokenBalance.toJSON(), tokenBalance: tokenBalance.toJSON(),

View File

@ -52,10 +52,11 @@ export const fetchBoardUserInfo = async (account: string) => {
params: [account], params: [account],
}, },
] ]
const [userInfo, estimatedProfit] = await multicall(boardABI, calls) const [userInfo, estimatedProfit] = await multicall(board.abi, calls)
console.log(estimatedProfit)
return { return {
stakedBalance: new BigNumber(userInfo.amount._hex).toJSON(), stakedBalance: new BigNumber(userInfo.amount._hex).toJSON(),
unLockTime: new BigNumber(userInfo.unLockTime._hex).toNumber(), unLockTime: userInfo.unLockTime ? new BigNumber(userInfo.unLockTime._hex).toNumber() : 0,
estimatedProfit: new BigNumber(estimatedProfit).toJSON(), estimatedProfit: new BigNumber(estimatedProfit).toJSON(),
} }
}), }),

View File

@ -477,19 +477,9 @@ export type UserTicketsResponse = [ethers.BigNumber[], number[], boolean[]]
export interface UserInfo { export interface UserInfo {
id?: number id?: number
avatar?: string inviteCode?: string
name?: string name?: string
address?: string address?: string
description?: string
invite_num?: string
invite_link?: string
email?: string
twitter?: string
facebook?: string
invite_code?: string
scoring_account?: number
invite_reward?: number
inviter_address?: string
} }
export interface UserInfoState { export interface UserInfoState {
userInfo: UserInfo userInfo: UserInfo
@ -509,12 +499,12 @@ export interface ReferralState {
data: Referral data: Referral
} }
export interface Boards extends BoardConfig { export interface Boards extends BoardConfig {
tokenAmount?: BigNumber tokenAmount?: number
minStakeAmount?: number minStakeAmount?: number
userData?: { userData?: {
allowance: BigNumber allowance: number
tokenBalance: BigNumber tokenBalance: number
stakedBalance: BigNumber stakedBalance: number
unlockTime: number unlockTime: number
estimatedProfit: number estimatedProfit: number
} }

View File

@ -30,10 +30,6 @@ export const useUserInfo = () => {
return useSelector((state: State) => state.userInfo.userInfo) return useSelector((state: State) => state.userInfo.userInfo)
} }
export const useUserPortrait = () => {
const userInfo = useSelector((state: State) => state.userInfo.userInfo)
return userInfo?.avatar || '/images/common/portrait.png'
}
// 签名登录 // 签名登录
export const useSignLogin = () => { export const useSignLogin = () => {
const unActiveAccount = useUnactiveAccount() const unActiveAccount = useUnactiveAccount()

View File

@ -7,15 +7,13 @@ const options = {
export const stakeBoard = async (masterChefContract, pid, amount) => { export const stakeBoard = async (masterChefContract, pid, amount) => {
const value = new BigNumber(amount).times(DEFAULT_TOKEN_DECIMAL).toString() const value = new BigNumber(amount).times(DEFAULT_TOKEN_DECIMAL).toString()
const tx = await masterChefContract.deposit(value, options)
const tx = await masterChefContract.deposit(pid, value, options)
const receipt = await tx.wait() const receipt = await tx.wait()
return receipt.status return receipt.status
} }
export const unstakeBoard = async (masterChefContract, pid, amount) => { export const unstakeBoard = async (masterChefContract) => {
const value = new BigNumber(amount).times(DEFAULT_TOKEN_DECIMAL).toString() const tx = await masterChefContract.withdrawHCC(options)
const tx = await masterChefContract.withdrawHCC(pid, value, options)
const receipt = await tx.wait() const receipt = await tx.wait()
return receipt.status return receipt.status
} }

View File

@ -10,14 +10,14 @@ export const getDecimalAmount = (amount: BigNumber, decimals = 18) => {
return new BigNumber(amount).times(BIG_TEN.pow(decimals)) return new BigNumber(amount).times(BIG_TEN.pow(decimals))
} }
export const getBalanceAmount = (amount: BigNumber, decimals = 18) => { export const getBalanceAmount = (amount: BigNumber | number, decimals = 18) => {
return new BigNumber(amount).dividedBy(BIG_TEN.pow(decimals)) return new BigNumber(amount).dividedBy(BIG_TEN.pow(decimals))
} }
/** /**
* This function is not really necessary but is used throughout the site. * This function is not really necessary but is used throughout the site.
*/ */
export const getBalanceNumber = (balance: BigNumber, decimals = 18, decimalPlaces?: number) => { export const getBalanceNumber = (balance: BigNumber | number, decimals = 18, decimalPlaces?: number) => {
const displayBalance = getBalanceAmount(balance, decimals) const displayBalance = getBalanceAmount(balance, decimals)
return decimalPlaces ? displayBalance.decimalPlaces(decimalPlaces).toNumber() : displayBalance.toNumber() return decimalPlaces ? displayBalance.decimalPlaces(decimalPlaces).toNumber() : displayBalance.toNumber()
} }

View File

@ -14,7 +14,7 @@ export const initAxios = (dispatch: Dispatch<any>, toast) => {
hasInit = true hasInit = true
request.interceptors.request.use( request.interceptors.request.use(
(memo: any) => { (memo: any) => {
memo.headers.token = localStorage.getItem(CACHE_TOKEN) memo.headers.Authorization = `Bearer ${localStorage.getItem(CACHE_TOKEN)} `
return memo return memo
}, },
(error) => { (error) => {

View File

@ -47,6 +47,14 @@ const CardActions: React.FC<NodeCardActionsProps> = ({ board, account }) => {
const renderApprovalOrStakeButton = () => { const renderApprovalOrStakeButton = () => {
return isApproved ? ( return isApproved ? (
<> <>
<Flex>
<Text bold textTransform="uppercase" color="secondary" fontSize="12px" pr="3px">
{board.tokenSymbol}
</Text>
<Text bold textTransform="uppercase" color="textSubtle" fontSize="12px">
{t('Staked')}
</Text>
</Flex>
<StakeAction stakedBalance={stakedBalance} tokenBalance={tokenBalance} pid={pid} /> <StakeAction stakedBalance={stakedBalance} tokenBalance={tokenBalance} pid={pid} />
<Flex flexDirection="column" alignItems="flex-start" mt="10"> <Flex flexDirection="column" alignItems="flex-start" mt="10">
<Flex> <Flex>
@ -66,19 +74,7 @@ const CardActions: React.FC<NodeCardActionsProps> = ({ board, account }) => {
) )
} }
return ( return <Action>{!account ? <UnlockButton mt="8px" width="100%" /> : renderApprovalOrStakeButton()}</Action>
<Action>
<Flex>
<Text bold textTransform="uppercase" color="secondary" fontSize="12px" pr="3px">
{board.tokenSymbol}
</Text>
<Text bold textTransform="uppercase" color="textSubtle" fontSize="12px">
{t('Staked')}
</Text>
</Flex>
{!account ? <UnlockButton mt="8px" width="100%" /> : renderApprovalOrStakeButton()}
</Action>
)
} }
export default CardActions export default CardActions

View File

@ -53,21 +53,24 @@ const StakeAction: React.FC<NodeCardActionsProps> = ({ stakedBalance, tokenBalan
const unlockTime = userData.unlockTime * 1000 const unlockTime = userData.unlockTime * 1000
if (unlockTime > new Date().getTime()) { if (unlockTime > new Date().getTime()) {
toastWarning(t('Unlock time %unlockTime%', { unlockTime: dayjs(unlockTime).format('YYYY-MM-DD HH:mm') })) toastWarning(t('Unlock time %unlockTime%', { unlockTime: dayjs(unlockTime).format('YYYY-MM-DD HH:mm') }))
// return return
} }
// onUnstake() onUnstake()
} }
const renderStakingButtons = () => { const renderStakingButtons = () => {
return rawStakedBalance === 0 ? ( return rawStakedBalance === 0 ? (
<Button onClick={onPresentDeposit}>{t(`Stake Token`)}</Button> <Button onClick={onPresentDeposit}>{t(`Stake Token`)}</Button>
) : ( ) : (
<IconButtonWrapper> <IconButtonWrapper>
<IconButton variant="tertiary" onClick={handleUnstake} mr="6px"> {userData.stakedBalance > 0 ? (
<IconButton variant="tertiary" onClick={handleUnstake}>
<MinusIcon color="primary" /> <MinusIcon color="primary" />
</IconButton> </IconButton>
<IconButton variant="tertiary" onClick={onPresentDeposit}> ) : (
<IconButton variant="tertiary" onClick={onPresentDeposit} ml="6px">
<AddIcon color="primary" /> <AddIcon color="primary" />
</IconButton> </IconButton>
)}
</IconButtonWrapper> </IconButtonWrapper>
) )
} }

View File

@ -5,12 +5,9 @@ import { useBoardchef } from 'hooks/useContract'
const useUnstakeBoard = (pid: number) => { const useUnstakeBoard = (pid: number) => {
const boardChefContract = useBoardchef(pid) const boardChefContract = useBoardchef(pid)
const handleUnstake = useCallback( const handleUnstake = useCallback(async () => {
async (amount: string) => { await unstakeBoard(boardChefContract)
await unstakeBoard(boardChefContract, pid, amount) }, [boardChefContract, pid])
},
[boardChefContract, pid],
)
return { onUnstake: handleUnstake } return { onUnstake: handleUnstake }
} }

View File

@ -27,7 +27,7 @@ const Header = styled.div`
const SecondText = styled(Text)` const SecondText = styled(Text)`
white-space: break-spaces; white-space: break-spaces;
` `
const Farms: React.FC = () => { const Boards: React.FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const boardsList = useBoards() const boardsList = useBoards()
const [query, setQuery] = useState('') const [query, setQuery] = useState('')
@ -42,16 +42,11 @@ const Farms: React.FC = () => {
} }
}, [account, dispatch, fastRefresh]) }, [account, dispatch, fastRefresh])
const farmsList = useMemo(() => {
return boardsList.map((board) => {
return board
})
}, [boardsList])
const renderContent = (): JSX.Element => { const renderContent = (): JSX.Element => {
return ( return (
<div> <div>
<FlexLayout> <FlexLayout>
{farmsList.map((board) => ( {boardsList.map((board) => (
<BoardCard key={board.pid} board={board} account={account} removed /> <BoardCard key={board.pid} board={board} account={account} removed />
))} ))}
</FlexLayout> </FlexLayout>
@ -76,4 +71,4 @@ const Farms: React.FC = () => {
) )
} }
export default Farms export default Boards

View File

@ -1,11 +1,19 @@
import React from 'react' import React, { useEffect } from 'react'
import { useTranslation } from 'contexts/Localization' import { useTranslation } from 'contexts/Localization'
import { CACHE_INVITE_CODE } from 'config/constants/cacheKey'
import useParsedQueryString from 'hooks/useParsedQueryString'
import FristCom from './components/FristCom' import FristCom from './components/FristCom'
import IntroduceCom from './components/IntroduceCom' import IntroduceCom from './components/IntroduceCom'
import CourseCom from './components/CourseCom' import CourseCom from './components/CourseCom'
const Home: React.FC = () => { const Home: React.FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const { inviteCode } = useParsedQueryString()
useEffect(() => {
if (inviteCode) {
sessionStorage.setItem(CACHE_INVITE_CODE, inviteCode as string)
}
}, [])
return ( return (
<> <>