feat: 获取统计数据
This commit is contained in:
parent
5b915e6413
commit
eacfbf4406
|
|
@ -90,7 +90,8 @@
|
|||
"name": "_poolInfo",
|
||||
"outputs": [
|
||||
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
|
||||
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" }
|
||||
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" },
|
||||
{ "internalType": "uint256", "name": "num", "type": "uint256" }
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
|
|
|
|||
|
|
@ -90,7 +90,8 @@
|
|||
"name": "_poolInfo",
|
||||
"outputs": [
|
||||
{ "internalType": "uint256", "name": "accHCCPerShare", "type": "uint256" },
|
||||
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" }
|
||||
{ "internalType": "uint256", "name": "totalAmount", "type": "uint256" },
|
||||
{ "internalType": "uint256", "name": "num", "type": "uint256" }
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import holderAbi from 'config/abi/holder.json'
|
|||
import tokens from './tokens'
|
||||
import { BoardConfig } from './types'
|
||||
|
||||
const bordsList: BoardConfig[] = [
|
||||
const boardsList: BoardConfig[] = [
|
||||
{
|
||||
pid: 1,
|
||||
name: 'Board',
|
||||
|
|
@ -13,6 +13,7 @@ const bordsList: BoardConfig[] = [
|
|||
tokenAddresses: tokens.hcc.address,
|
||||
tokenDecimals: 18,
|
||||
contractAddress: addresses.boardChef,
|
||||
contractRewardAddress: addresses.boardRewardChef,
|
||||
abi: boardAbi,
|
||||
},
|
||||
{
|
||||
|
|
@ -23,8 +24,9 @@ const bordsList: BoardConfig[] = [
|
|||
tokenAddresses: tokens.hcc.address,
|
||||
tokenDecimals: 18,
|
||||
contractAddress: addresses.holderChef,
|
||||
contractRewardAddress: addresses.holderRewardChef,
|
||||
abi: holderAbi,
|
||||
},
|
||||
]
|
||||
|
||||
export default bordsList
|
||||
export default boardsList
|
||||
|
|
|
|||
|
|
@ -8,13 +8,21 @@ export default {
|
|||
56: '0x6ab8463a4185b80905e05a9ff80a2d6b714b9e95',
|
||||
},
|
||||
boardChef: {
|
||||
97: '0x7e64aac0806597cb2efddf7c001e59d6b4e9cb15',
|
||||
97: '0xcf5411e9bd61bbd68ddf08e8a3f7680af8993cd0',
|
||||
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会合约
|
||||
},
|
||||
boardRewardChef: {
|
||||
97: '0x2937a050705009270c9b5bc096d57d519ab7c39b',
|
||||
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 节点董事会分红合约
|
||||
},
|
||||
holderChef: {
|
||||
97: '0x4cbbb9e9569a208c9975574675ba24eccea342b3',
|
||||
97: '0x20b74dfb41172fdce43758c014959b5e2586d2cf',
|
||||
56: '0xD34871F12ace1BB8034E18009104b9dA60B84250', // NEED CHANGE 持币人
|
||||
},
|
||||
holderRewardChef: {
|
||||
97: '0x46271393dd6f2c8798a44f857888aa6a85af3527',
|
||||
56: '0x46271393dd6f2c8798a44f857888aa6a85af3527', // NEED CHANGE 持币人分红
|
||||
},
|
||||
referralChef: {
|
||||
97: '0x8a5dc1e8262d6a3de664624fdc13a533ba64e60d',
|
||||
56: '0x88F46EF2Ee08494D84942DCA3bd24cDEf7C88Ae2', // NEED CHANGE 邀请或则军团长
|
||||
|
|
|
|||
|
|
@ -186,5 +186,7 @@ export interface BoardConfig {
|
|||
tokenAddresses: Address
|
||||
tokenDecimals: number
|
||||
contractAddress: Address
|
||||
contractRewardAddress: Address
|
||||
abi: any
|
||||
// rewardAbi: any
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ 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 { getBalanceAmount } from 'utils/formatBalance'
|
||||
import boardABI from 'config/abi/board.json'
|
||||
import erc20ABI from 'config/abi/erc20.json'
|
||||
import multicall from 'utils/multicall'
|
||||
|
|
@ -51,47 +51,55 @@ const Boards: React.FC = () => {
|
|||
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 {
|
||||
address: contractAddress,
|
||||
name: '_poolInfo',
|
||||
}
|
||||
})
|
||||
let total = 0
|
||||
const boardsPoolInfo = await multicall(boardABI, calls)
|
||||
boardsPoolInfo.forEach((item) => {
|
||||
total += new BigNumber(item.totalAmount._hex).toNumber()
|
||||
})
|
||||
setTotalAmount(total)
|
||||
}
|
||||
// // 获取资金池总额
|
||||
// const getCapital = async () => {
|
||||
// const calls = boardsConfig.map((board) => {
|
||||
// const contractAddress = getAddress(board.contractAddress)
|
||||
// return {
|
||||
// address: contractAddress,
|
||||
// name: '_poolInfo',
|
||||
// }
|
||||
// })
|
||||
// let total = 0
|
||||
// const boardsPoolInfo = await multicall(boardABI, calls)
|
||||
// boardsPoolInfo.forEach((item) => {
|
||||
// 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)
|
||||
const boardsData = await Promise.all(
|
||||
boardsConfig.map(async (boardConfig) => {
|
||||
const [boardPoolInfo] = await multicall(boardConfig.abi, [
|
||||
{
|
||||
address: getAddress(boardConfig.contractAddress),
|
||||
name: '_poolInfo',
|
||||
},
|
||||
])
|
||||
const [waitWithdrawAmount] = await multicall(erc20ABI, [
|
||||
{
|
||||
address: getAddress(boardConfig.tokenAddresses),
|
||||
name: 'balanceOf',
|
||||
params: [getAddress(boardConfig.contractRewardAddress)],
|
||||
},
|
||||
])
|
||||
return {
|
||||
totalAmount: getBalanceAmount(new BigNumber(boardPoolInfo.totalAmount._hex)).toNumber(),
|
||||
num: new BigNumber(boardPoolInfo?.num?._hex).toNumber(),
|
||||
waitWithdrawAmount: getBalanceAmount(new BigNumber(waitWithdrawAmount.balance._hex)).toNumber(),
|
||||
}
|
||||
}),
|
||||
)
|
||||
console.log(boardsData)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchBoardsPublicDataAsync())
|
||||
fetchBoardShares()
|
||||
if (account) {
|
||||
dispatch(fetchBoardUserDataAsync(account))
|
||||
getCapital()
|
||||
fetchBoardShares()
|
||||
// getCapital()
|
||||
}
|
||||
}, [account, dispatch, fastRefresh])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue