Skip to content

Commit

Permalink
fix(client): bank change summary value
Browse files Browse the repository at this point in the history
  • Loading branch information
p-98 committed Jul 15, 2024
1 parent 74a9a89 commit 36dd854
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import React, { useMemo } from "react";
import cn from "classnames";
import config from "Config";
import { SimpleListItem } from "Components/material/list";
import { FragmentType, graphql, useFragment } from "Utility/graphql";
import {
FragmentType,
graphql,
makeFragmentData,
useFragment,
} from "Utility/graphql";
import {
currency,
currencyName,
Expand All @@ -14,6 +19,15 @@ import {

import styles from "../bankAccountInfo.module.css";

const bank = makeFragmentData(
{
__typename: "CompanyUser",
type: "COMPANY" as const,
id: config.roles.bankCompanyId,
},
Eq_UserFragment
);

export const Summary_TransactionFragment = graphql(/* GraohQL */ `
fragment Summary_TransactionFragment on Transaction {
... on TransferTransaction {
Expand Down Expand Up @@ -111,6 +125,10 @@ const summaryFactories: {
const fromCurrencyName = currencyName(trx.fromCurrency);
const toCurrencyName = currencyName(trx.toCurrency);
const value = (() => {
if (userEq(user, bank) && trx.fromCurrency === config.mainCurrency)
return +trx.fromValue;
if (userEq(user, bank) && trx.toCurrency === config.mainCurrency)
return -trx.toValue;
if (trx.fromCurrency === config.mainCurrency) return -trx.fromValue;
if (trx.toCurrency === config.mainCurrency) return trx.toValue;
return 0;
Expand Down

0 comments on commit 36dd854

Please sign in to comment.