import { useQuery } from '@apollo/react-hooks' import { Paper } from '@material-ui/core' import { makeStyles } from '@material-ui/core/styles' import BigNumber from 'bignumber.js' import classnames from 'classnames' import gql from 'graphql-tag' import * as R from 'ramda' import React, { useContext } from 'react' import AppContext from 'src/AppContext' import TitleSection from 'src/components/layout/TitleSection' import { H3, Info2, Label2, Label3, P } from 'src/components/typography' import { ReactComponent as BitcoinLogo } from 'src/styling/logos/icon-bitcoin-colour.svg' import { ReactComponent as BitcoinCashLogo } from 'src/styling/logos/icon-bitcoincash-colour.svg' import { ReactComponent as DashLogo } from 'src/styling/logos/icon-dash-colour.svg' import { ReactComponent as EthereumLogo } from 'src/styling/logos/icon-ethereum-colour.svg' import { ReactComponent as LitecoinLogo } from 'src/styling/logos/icon-litecoin-colour.svg' import { ReactComponent as ZCashLogo } from 'src/styling/logos/icon-zcash-colour.svg' import { numberToFiatAmount, numberToCryptoAmount } from 'src/utils/number' import styles from './ATMWallet.styles' const useStyles = makeStyles(styles) const GET_OPERATOR_BY_USERNAME = gql` query operatorByUsername($username: String) { operatorByUsername(username: $username) { id entityId name fiatBalances cryptoBalances machines joined assets preferredFiatCurrency contactInfo { name email } fundings { id origin destination fiatAmount fiatBalanceAfter fiatCurrency created status description } } } ` const CHIPS_PER_ROW = 6 const Assets = ({ balance, wallets, currency }) => { const classes = useStyles({ numberOfChips: CHIPS_PER_ROW }) const walletFiatSum = R.sum(R.map(it => it.fiatValue, wallets)) const totalValue = BigNumber(balance) .plus(walletFiatSum) .toNumber() return (

Available balance

{numberToFiatAmount(balance)} {R.toUpper(currency)}
+

Total balance in wallets

{numberToFiatAmount(walletFiatSum)} {R.toUpper(currency)}
=

Total assets

{numberToFiatAmount(totalValue)} {R.toUpper(currency)}
) } const WalletInfoChip = ({ wallet, currency }) => { const classes = useStyles({ numberOfChips: CHIPS_PER_ROW }) const getLogo = cryptoCode => { switch (cryptoCode) { case 'BTC': return case 'ETH': return case 'LTC': return case 'ZEC': return ( ) case 'BCH': return ( ) case 'DASH': return default: return } } return (
{getLogo(wallet.cryptoCode)} {wallet.isHedged ? 'Hedged' : 'Not hedged'}
{wallet.name} value {numberToCryptoAmount(wallet.amount)} {wallet.cryptoCode} Hedged value {numberToFiatAmount(wallet.hedgedFiatValue)} {currency}
) } const ATMWallet = () => { const classes = useStyles({ numberOfChips: CHIPS_PER_ROW }) const { userData } = useContext(AppContext) const { data, loading } = useQuery(GET_OPERATOR_BY_USERNAME, { context: { clientName: 'pazuz' }, variables: { username: userData?.username } }) const operatorData = R.path(['operatorByUsername'], data) const wallets = [ { cryptoCode: 'BTC', name: 'Bitcoin', amount: operatorData?.cryptoBalances.xbt ?? 0, fiatValue: operatorData?.assets.values.cryptoBalancesInFiat.xbt ?? 0, hedgedFiatValue: operatorData?.assets.values.hedgedContracts.xbt ?? 0, isHedged: BigNumber(operatorData?.assets.values.hedgedCrypto.xbt ?? 0).gt( 0 ) }, { cryptoCode: 'ETH', name: 'Ethereum', amount: operatorData?.cryptoBalances.eth ?? 0, fiatValue: operatorData?.assets.values.cryptoBalancesInFiat.eth ?? 0, hedgedFiatValue: operatorData?.assets.values.hedgedContracts.eth ?? 0, isHedged: BigNumber(operatorData?.assets.values.hedgedCrypto.eth ?? 0).gt( 0 ) }, { cryptoCode: 'LTC', name: 'Litecoin', amount: operatorData?.cryptoBalances.ltc ?? 0, fiatValue: operatorData?.assets.values.cryptoBalancesInFiat.ltc ?? 0, hedgedFiatValue: operatorData?.assets.values.hedgedContracts.ltc ?? 0, isHedged: BigNumber(operatorData?.assets.values.hedgedCrypto.ltc ?? 0).gt( 0 ) }, { cryptoCode: 'ZEC', name: 'Z-Cash', amount: operatorData?.cryptoBalances.zec ?? 0, fiatValue: operatorData?.assets.values.cryptoBalancesInFiat.zec ?? 0, hedgedFiatValue: operatorData?.assets.values.hedgedContracts.zec ?? 0, isHedged: BigNumber(operatorData?.assets.values.hedgedCrypto.zec ?? 0).gt( 0 ) }, { cryptoCode: 'BCH', name: 'Bitcoin Cash', amount: operatorData?.cryptoBalances.bch ?? 0, fiatValue: operatorData?.assets.values.cryptoBalancesInFiat.bch ?? 0, hedgedFiatValue: operatorData?.assets.values.hedgedContracts.bch ?? 0, isHedged: BigNumber(operatorData?.assets.values.hedgedCrypto.bch ?? 0).gt( 0 ) }, { cryptoCode: 'DASH', name: 'Dash', amount: operatorData?.cryptoBalances.dash ?? 0, fiatValue: operatorData?.assets.values.cryptoBalancesInFiat.dash ?? 0, hedgedFiatValue: operatorData?.assets.values.hedgedContracts.dash ?? 0, isHedged: BigNumber( operatorData?.assets.values.hedgedCrypto.dash ?? 0 ).gt(0) } ] return ( !loading && ( <>

ATM Wallets

{R.map( it => ( ), wallets )}
) ) } export default ATMWallet