import React, { useState } from 'react' import classnames from 'classnames' import QRCode from 'qrcode.react' import BigNumber from 'bignumber.js' import useAxios from '@use-hooks/axios' import { makeStyles } from '@material-ui/core/styles' import { H3, Info1, Info2, Info3, Mono, Label1, Label3, TL2 } from '../components/typography' import Title from '../components/Title' import Sidebar from '../components/Sidebar' import { primaryColor } from '../styling/variables' import styles from './Funding.styles' const useStyles = makeStyles(styles) const formatAddress = (address = '') => { return address.replace(/(.{4})/g, '$1 ') } const sumReducer = (acc, value) => acc.plus(value) const formatNumber = it => { return new BigNumber(it).toFormat(2) } const getConfirmedTotal = list => { return formatNumber( list.map(it => new BigNumber(it.fiatConfirmedBalance)).reduce(sumReducer, new BigNumber(0)) ) } const getPendingTotal = list => { return formatNumber( list.map(it => new BigNumber(it.fiatPending)).reduce(sumReducer, new BigNumber(0)) ) } const Funding = () => { const [data, setData] = useState(null) const [selected, setSelected] = useState(null) const classes = useStyles() const isSelected = it => { return selected && selected.cryptoCode === it.cryptoCode } useAxios({ url: 'http://localhost:8070/api/funding', method: 'GET', trigger: [], customHandler: (err, res) => { if (err) return if (res) { setData(res.data) setSelected(res.data && res.data[0]) } } }) const itemRender = (it) => { return (