diff --git a/new-lamassu-admin/src/pages/ATMWallet/ATMWallet.js b/new-lamassu-admin/src/pages/ATMWallet/ATMWallet.js index 1d32e44c..b242ca75 100644 --- a/new-lamassu-admin/src/pages/ATMWallet/ATMWallet.js +++ b/new-lamassu-admin/src/pages/ATMWallet/ATMWallet.js @@ -1,6 +1,7 @@ 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' @@ -15,7 +16,7 @@ import { ReactComponent as DashLogo } from 'src/styling/logos/icon-dash-colour.s 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 } from 'src/utils/number' +import { numberToFiatAmount, numberToCryptoAmount } from 'src/utils/number' import styles from './ATMWallet.styles' @@ -31,7 +32,7 @@ const GET_OPERATOR_BY_USERNAME = gql` cryptoBalances machines joined - assetValue + assets preferredFiatCurrency contactInfo { name @@ -57,9 +58,10 @@ const CHIPS_PER_ROW = 6 const Assets = ({ balance, wallets, currency }) => { const classes = useStyles({ numberOfChips: CHIPS_PER_ROW }) - const walletFiatSum = () => { - return R.sum(R.map(it => it.fiatValue, wallets)) - } + const walletFiatSum = R.sum(R.map(it => it.fiatValue, wallets)) + const totalValue = BigNumber(balance) + .plus(walletFiatSum) + .toNumber() return (
@@ -79,7 +81,7 @@ const Assets = ({ balance, wallets, currency }) => {

Total balance in wallets

- {numberToFiatAmount(walletFiatSum())} + {numberToFiatAmount(walletFiatSum)} {R.toUpper(currency)} @@ -91,7 +93,7 @@ const Assets = ({ balance, wallets, currency }) => {

Total assets

- {numberToFiatAmount(balance)} + {numberToFiatAmount(totalValue)} {R.toUpper(currency)} @@ -142,11 +144,11 @@ const WalletInfoChip = ({ wallet, currency }) => {
{wallet.name} value - {numberToFiatAmount(wallet.amount.toFixed(1))} {wallet.cryptoCode} + {numberToCryptoAmount(wallet.amount)} {wallet.cryptoCode} Hedged value - {numberToFiatAmount(wallet.fiatValue)} {currency} + {numberToFiatAmount(wallet.hedgedFiatValue)} {currency}
@@ -170,43 +172,61 @@ const ATMWallet = () => { cryptoCode: 'BTC', name: 'Bitcoin', amount: operatorData?.cryptoBalances.xbt ?? 0, - fiatValue: 0, - isHedged: true + 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: 0, - isHedged: true + 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: 0, - isHedged: true + 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: 0, - isHedged: false + 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: 0, - isHedged: true + 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: 0, - isHedged: false + fiatValue: operatorData?.assets.values.cryptoBalancesInFiat.dash ?? 0, + hedgedFiatValue: operatorData?.assets.values.hedgedContracts.dash ?? 0, + isHedged: BigNumber( + operatorData?.assets.values.hedgedCrypto.dash ?? 0 + ).gt(0) } ] @@ -216,10 +236,10 @@ const ATMWallet = () => {

ATM Wallets

diff --git a/new-lamassu-admin/src/pages/Accounting/Accounting.js b/new-lamassu-admin/src/pages/Accounting/Accounting.js index bd141bcb..0d46d450 100644 --- a/new-lamassu-admin/src/pages/Accounting/Accounting.js +++ b/new-lamassu-admin/src/pages/Accounting/Accounting.js @@ -1,5 +1,6 @@ import { useQuery } from '@apollo/react-hooks' import { makeStyles } from '@material-ui/core/styles' +import BigNumber from 'bignumber.js' import gql from 'graphql-tag' import * as R from 'ramda' import React, { useContext } from 'react' @@ -26,7 +27,7 @@ const GET_OPERATOR_BY_USERNAME = gql` cryptoBalances machines joined - assetValue + assets preferredFiatCurrency contactInfo { name @@ -169,23 +170,31 @@ const Accounting = () => { } ] + const hedgingReserve = BigNumber( + R.reduce( + (acc, value) => acc.plus(value), + BigNumber(0), + R.values(operatorData?.assets.values.hedgedContracts) ?? [] + ) ?? 0 + ).toNumber() + + console.log(opData) + return ( !loading && ( <>

Fiat balance history

diff --git a/new-lamassu-admin/src/pages/Assets/Assets.js b/new-lamassu-admin/src/pages/Assets/Assets.js index aa982f6e..6a2f8e8c 100644 --- a/new-lamassu-admin/src/pages/Assets/Assets.js +++ b/new-lamassu-admin/src/pages/Assets/Assets.js @@ -30,7 +30,7 @@ const GET_OPERATOR_BY_USERNAME = gql` cryptoBalances machines joined - assetValue + assets preferredFiatCurrency contactInfo { name @@ -147,8 +147,7 @@ const Assets = () => { { id: 'fiatBalance', display: 'Fiat balance', - amount: - operatorData?.fiatBalances[operatorData?.preferredFiatCurrency] ?? 0, + amount: operatorData?.assets.total ?? 0, currency: R.toUpper(operatorData?.preferredFiatCurrency ?? ''), class: 'Available balance' }, @@ -156,7 +155,7 @@ const Assets = () => { id: 'hedgingReserve', display: 'Hedging reserve', amount: - operatorData?.fiatBalances[operatorData?.preferredFiatCurrency] ?? 0, + -R.sum(R.values(operatorData?.assets.values.hedgedContracts)) ?? 0, currency: R.toUpper(operatorData?.preferredFiatCurrency ?? ''), class: 'Available balance', direction: 'out' @@ -167,7 +166,7 @@ const Assets = () => { { id: 'hedgedWalletAssets', display: 'Hedged wallet assets', - amount: 0, + amount: R.sum(R.values(operatorData?.assets.values.hedgedContracts)) ?? 0, currency: R.toUpper(operatorData?.preferredFiatCurrency ?? ''), class: 'Wallet assets', direction: 'in' @@ -175,7 +174,7 @@ const Assets = () => { { id: 'unhedgedWalletAssets', display: 'Unhedged wallet assets', - amount: 0, + amount: R.sum(R.values(operatorData?.assets.values.unhedgedFiat)) ?? 0, currency: R.toUpper(operatorData?.preferredFiatCurrency ?? ''), class: 'Wallet assets', direction: 'in' @@ -193,21 +192,22 @@ const Assets = () => { { id: 'hedgingReserve', display: 'Hedging reserve', - amount: 0, + amount: + -R.sum(R.values(operatorData?.assets.values.hedgedContracts)) ?? 0, currency: R.toUpper(operatorData?.preferredFiatCurrency ?? ''), direction: 'out' }, { id: 'hedgedWalletAssets', display: 'Market value of hedged wallet assets', - amount: 0, + amount: R.sum(R.values(operatorData?.assets.values.hedgedContracts)) ?? 0, currency: R.toUpper(operatorData?.preferredFiatCurrency ?? ''), direction: 'in' }, { id: 'unhedgedWalletAssets', display: 'Unhedged wallet assets', - amount: 0, + amount: R.sum(R.values(operatorData?.assets.values.unhedgedFiat)) ?? 0, currency: R.toUpper(operatorData?.preferredFiatCurrency ?? ''), direction: 'in' } diff --git a/new-lamassu-admin/src/utils/apollo.js b/new-lamassu-admin/src/utils/apollo.js index 1921cdcf..022cec4a 100644 --- a/new-lamassu-admin/src/utils/apollo.js +++ b/new-lamassu-admin/src/utils/apollo.js @@ -12,8 +12,7 @@ import AppContext from 'src/AppContext' const URI = process.env.NODE_ENV === 'development' ? 'https://localhost:8070' : '' -const ALT_URI = - process.env.NODE_ENV === 'development' ? 'http://localhost:4001' : '' +const ALT_URI = 'http://localhost:4001' const uploadLink = createUploadLink({ credentials: 'include', diff --git a/new-lamassu-admin/src/utils/number.js b/new-lamassu-admin/src/utils/number.js index 2f433fef..a1221231 100644 --- a/new-lamassu-admin/src/utils/number.js +++ b/new-lamassu-admin/src/utils/number.js @@ -10,4 +10,12 @@ const defaultToZero = value => const numberToFiatAmount = value => value.toLocaleString('en-US', { maximumFractionDigits: 2 }) -export { defaultToZero, transformNumber, numberToFiatAmount } +const numberToCryptoAmount = value => + value.toLocaleString('en-US', { maximumFractionDigits: 5 }) + +export { + defaultToZero, + transformNumber, + numberToFiatAmount, + numberToCryptoAmount +}