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