import { useEffect, useMemo, useState } from 'react' import useMangoStore from '../../stores/useMangoStore' import Chart from '../Chart' import Loading from '../Loading' import Select from '../Select' import { Table, Td, Th, TrBody, TrHead } from '../TableElements' import { isEmpty } from 'lodash' const AccountFunding = () => { const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current) const [fundingStats, setFundingStats] = useState([]) const [hourlyFunding, setHourlyFunding] = useState(null) const [selectedAsset, setSelectedAsset] = useState('BTC') const [loading, setLoading] = useState(false) const mangoAccountPk = useMemo(() => { return mangoAccount.publicKey.toString() }, [mangoAccount]) useEffect(() => { const fetchFundingStats = async () => { const response = await fetch( `https://mango-transaction-log.herokuapp.com/v3/stats/total-funding?mango-account=${mangoAccountPk}` ) const parsedResponse = await response.json() setFundingStats(Object.entries(parsedResponse)) } const fetchHourlyFundingStats = async () => { setLoading(true) const response = await fetch( `https://mango-transaction-log.herokuapp.com/v3/stats/hourly-funding?mango-account=${mangoAccountPk}` ) const parsedResponse = await response.json() const assets = Object.keys(parsedResponse) const stats = {} for (const asset of assets) { const x = Object.entries(parsedResponse[asset]) stats[asset] = x.map(([key, value]) => { // @ts-ignore return { ...value, time: key } }) } setLoading(false) setHourlyFunding(stats) } fetchFundingStats() fetchHourlyFundingStats() }, [mangoAccountPk]) return ( <>
Total Funding Earned/Paid
{mangoAccount ? (
{fundingStats.length === 0 ? ( ) : ( fundingStats.map(([symbol, stats], index) => { return ( ) }) )}
Token Total Funding
No funding earned/paid
{symbol}-PERP
= 0 ? 'text-th-green' : 'text-th-red' }`} > ${stats.total_funding.toFixed(6)}
<> {!isEmpty(hourlyFunding) && !loading ? ( <>
{Object.keys(hourlyFunding).map((token: string) => (
setSelectedAsset(token)} key={token} > {token}
))}
{hourlyFunding[selectedAsset].length ? (
x.toFixed(6)} type="area" />
) : null} ) : loading ? (
) : null}
) : (
Connect wallet
)} ) } export default AccountFunding