部分董事会(待修改)
This commit is contained in:
parent
8e13aa91ac
commit
eaccb3fea2
|
|
@ -1,8 +1,9 @@
|
|||
import BigNumber from 'bignumber.js'
|
||||
import erc20ABI from 'config/abi/erc20.json'
|
||||
import boardABI from 'config/abi/board.json'
|
||||
import multicall from 'utils/multicall'
|
||||
import boardsConfig from 'config/constants/boards'
|
||||
import { getAddress } from 'utils/addressHelpers'
|
||||
import { getAddress, getBoardAddress } from 'utils/addressHelpers'
|
||||
|
||||
export const fetchBoardUserAllowances = async (account: string) => {
|
||||
const calls = boardsConfig.map((board) => {
|
||||
|
|
@ -38,15 +39,15 @@ export const fetchBoardUserTokenBalances = async (account: string) => {
|
|||
export const fetchBoardUserInfo = async (account: string) => {
|
||||
const data = await Promise.all(
|
||||
boardsConfig.map(async (board) => {
|
||||
const boardChefAddress = getAddress(board.contractAddress)
|
||||
const boardChefAdress = getAddress(board.contractAddress)
|
||||
const calls = [
|
||||
{
|
||||
address: boardChefAddress,
|
||||
address: boardChefAdress,
|
||||
name: 'userInfo',
|
||||
params: [account],
|
||||
},
|
||||
{
|
||||
address: boardChefAddress,
|
||||
address: boardChefAdress,
|
||||
name: 'pendingHCC',
|
||||
params: [account],
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ import React, { useEffect, useCallback, useMemo, useState, useRef } from 'react'
|
|||
import { Route, useRouteMatch, useLocation } from 'react-router-dom'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import boardsConfig from 'config/constants/boards'
|
||||
import tokens from 'config/constants/tokens'
|
||||
import { getAddress, getBoardAddress } from 'utils/addressHelpers'
|
||||
import { getDecimalAmountNumber } from 'utils/formatBalance'
|
||||
import boardABI from 'config/abi/board.json'
|
||||
import erc20ABI from 'config/abi/erc20.json'
|
||||
import multicall from 'utils/multicall'
|
||||
import { useWeb3React } from '@web3-react/core'
|
||||
import Balance from 'components/Balance'
|
||||
|
|
@ -46,8 +49,11 @@ const Boards: React.FC = () => {
|
|||
const { fastRefresh } = useRefresh()
|
||||
// 资金池总额
|
||||
const [totalAmount, setTotalAmount] = useState(0)
|
||||
// 分红总额
|
||||
const [shareOutBonus, setShareOutBonus] = useState(0)
|
||||
// 获取资金池总额
|
||||
const getCapital = async () => {
|
||||
console.log(boardsConfig)
|
||||
const calls = boardsConfig.map((board) => {
|
||||
const contractAddress = getAddress(board.contractAddress)
|
||||
return {
|
||||
|
|
@ -55,17 +61,37 @@ const Boards: React.FC = () => {
|
|||
name: '_poolInfo',
|
||||
}
|
||||
})
|
||||
let total = 0
|
||||
const boardsPoolInfo = await multicall(boardABI, calls)
|
||||
console.log('boardsPoolInfo:', boardsPoolInfo)
|
||||
boardsPoolInfo.forEach((item) => {
|
||||
setTotalAmount(totalAmount + Number(new BigNumber(item.totalAmount._hex).toJSON()))
|
||||
total += new BigNumber(item.totalAmount._hex).toNumber()
|
||||
})
|
||||
setTotalAmount(total)
|
||||
}
|
||||
// 获取分红总额
|
||||
const fetchBoardShares = async () => {
|
||||
const calls = boardsConfig.map((board) => {
|
||||
const contractAddress = getAddress(board.tokenAddresses)
|
||||
return {
|
||||
address: contractAddress,
|
||||
name: 'balanceOf',
|
||||
params: ['0x2937a050705009270c9b5bc096d57d519ab7c39b'],
|
||||
}
|
||||
})
|
||||
let total = 0
|
||||
const sharesRed = await multicall(erc20ABI, calls)
|
||||
sharesRed.forEach((item) => {
|
||||
total += new BigNumber(item.balance._hex).div(new BigNumber(10).pow(18)).toNumber()
|
||||
})
|
||||
setShareOutBonus(total)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchBoardsPublicDataAsync())
|
||||
if (account) {
|
||||
dispatch(fetchBoardUserDataAsync(account))
|
||||
getCapital()
|
||||
fetchBoardShares()
|
||||
}
|
||||
}, [account, dispatch, fastRefresh])
|
||||
|
||||
|
|
@ -89,7 +115,7 @@ const Boards: React.FC = () => {
|
|||
</Heading>
|
||||
<Balance lineHeight="1" fontSize="32px" decimals={0} value={Number(totalAmount)} />
|
||||
<FlexLayoutMain>
|
||||
<HeaderItem title={t('The total amount of dividends')} price={1.0} />
|
||||
<HeaderItem title={t('The total amount of dividends')} price={shareOutBonus} />
|
||||
{/* <HeaderItem title={t('Pending dividend')} price={1.0} /> */}
|
||||
<HeaderItem title={t('Number of boards')} price={1.0} />
|
||||
<HeaderItem title={t('Number of holders')} price={1.0} />
|
||||
|
|
|
|||
Loading…
Reference in New Issue