|
| 1 | +import React, {useEffect, useState} from 'react'; |
| 2 | +import classes from './Chains.module.css' |
| 3 | + |
| 4 | +import ToggleSwitch from "../../../components/ToggleSwitch/ToggleSwitch"; |
| 5 | +import {useGetAllBalanceByChain, useGetTotalBalanceByChain} from "../../../query"; |
| 6 | + |
| 7 | + |
| 8 | +const ChainBalance = ({chainId}) => { |
| 9 | + |
| 10 | + console.log("chainId in chainbalance", chainId) |
| 11 | + |
| 12 | + const [params, setParams] = useState({ |
| 13 | + "excludeZero": false, |
| 14 | + }); |
| 15 | + |
| 16 | + const {data, isLoading, error, refetch} = useGetAllBalanceByChain(chainId, params); |
| 17 | + const {data:total, isLoading:totalIsLoading, error:totalError} = useGetTotalBalanceByChain(chainId); |
| 18 | + |
| 19 | + |
| 20 | + useEffect(() => { |
| 21 | + refetch() |
| 22 | + }, [params]); |
| 23 | + |
| 24 | + |
| 25 | + console.log("data ChainBalance", data) |
| 26 | + |
| 27 | + const content = ()=> { |
| 28 | + |
| 29 | + if (isLoading) return <div className={`d-flex flex-column justify-content-center align-items-center col-12 mt-4 py-5 ${classes.box}`}> |
| 30 | + Loading... |
| 31 | + </div> |
| 32 | + if (error) return <div className={`d-flex flex-column justify-content-center align-items-center col-12 mt-4 py-5 ${classes.box}`}> |
| 33 | + Error! |
| 34 | + </div> |
| 35 | + if (data?.length === 0) return <div className={`d-flex flex-column justify-content-center align-items-center col-12 mt-4 py-5 ${classes.box}`}> |
| 36 | + No Data! |
| 37 | + </div> |
| 38 | + else return <div className={`d-flex flex-column justify-content-center align-items-center col-12 mt-4 py-3 ${classes.box} ${classes.striped}`}> |
| 39 | + {data?.map((balance, index) => <div className={`d-flex flex-row col-12 py-4 px-4`} key={index}> |
| 40 | + <span className={`col-8`}>{index + 1} <span className={`mx-3`}></span> {balance?.address}</span> |
| 41 | + <span className={`col-4 text-center`} style={{color: '#fff'}}>Balance: <span className={`font-size-md`}>{balance?.balance}</span></span> |
| 42 | + </div>)} |
| 43 | + </div> |
| 44 | + |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + return ( |
| 50 | + |
| 51 | + <> |
| 52 | + |
| 53 | + <div className={`col-12 my-2 d-flex flex-row justify-content-between col-12 mt-4 py-4 px-4 ${classes.box}`}> |
| 54 | + <div className={`d-flex flex-row col-5`}> |
| 55 | + <span className={``}>Exclude Zero Balance</span> |
| 56 | + <span className={`mx-2`}> </span> |
| 57 | + <ToggleSwitch |
| 58 | + |
| 59 | + onchange={ () => { |
| 60 | + |
| 61 | + setParams(prevState => {return { |
| 62 | + ...prevState, |
| 63 | + excludeZero: !prevState.excludeZero |
| 64 | + }}) |
| 65 | + |
| 66 | + |
| 67 | + } } |
| 68 | + |
| 69 | + /*onchange={()=> setQuery({ |
| 70 | + ...query, |
| 71 | + ascendingByTime: (prevState => !prevState)} |
| 72 | + )}*/ |
| 73 | + checked={params?.excludeZero}/> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div className={`d-flex flex-row justify-content-center col-7 text-center`}> |
| 77 | + <span className={``}>{total?.chain?.toUpperCase()}</span> |
| 78 | + <span className={`mx-1`}> </span> |
| 79 | + <span className={``}>Total Balance: </span> |
| 80 | + <span className={`mx-2`}> </span> |
| 81 | + <span className={`font-size-md`} style={{color: 'white'}}>{ totalIsLoading ? "Loading..." : total?.balance}</span> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + |
| 85 | + {content()} |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + </> |
| 91 | + |
| 92 | + ); |
| 93 | +}; |
| 94 | + |
| 95 | +export default ChainBalance; |
0 commit comments