Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transfercheck): fix currency formatting #517

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/app-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@conform-to/react": "^1.1.5",
"@conform-to/zod": "^1.1.5",
"@dagrejs/dagre": "^1.1.3",
"@dinero.js/currencies": "2.0.0-alpha.14",
"@hookform/devtools": "^4.3.1",
"@hookform/resolvers": "^3.9.0",
"@lottiefiles/react-lottie-player": "^3.5.4",
Expand Down Expand Up @@ -75,6 +76,7 @@
"cronstrue": "^2.50.0",
"crypto-js": "^4.2.0",
"date-fns": "^3.6.0",
"dinero.js": "2.0.0-alpha.14",
"firebase": "^10.12.4",
"i18next": "^23.12.2",
"i18next-browser-languagedetector": "^8.0.0",
Expand Down
14 changes: 8 additions & 6 deletions packages/app-builder/src/components/Transfers/TransferData.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
formatCurrency,
formatDateTime,
formatNumber,
useFormatLanguage,
} from '@app-builder/utils/format';
import { useGetCopyToClipboard } from '@app-builder/utils/use-get-copy-to-clipboard';
import { type Currency } from 'dinero.js';
import { Trans, useTranslation } from 'react-i18next';

import { Callout } from '../Callout';
Expand All @@ -14,7 +15,7 @@ interface TransferDataProps {
beneficiaryIban: string;
beneficiaryName: string;
createdAt: string;
currency: string;
currency: Currency<number>;
label: string;
senderAccountId: string;
senderAccountType: string;
Expand Down Expand Up @@ -60,17 +61,18 @@ export function TransferData(props: TransferDataProps) {
{t('transfercheck:transfer_detail.transfer_data.label')}
</span>
<span className="text-grey-100 text-s">{props.label}</span>

<span className="text-grey-50 text-s first-letter:capitalize">
{t('transfercheck:transfer_detail.transfer_data.currency')}
</span>
<span className="text-grey-100 text-s">{props.currency}</span>

<span className="text-grey-100 text-s">{props.currency.code}</span>
<span className="text-grey-50 text-s first-letter:capitalize">
{t('transfercheck:transfer_detail.transfer_data.value')}
</span>
<span className="text-grey-100 text-s">
{formatNumber(props.value, { language })}
{formatCurrency(props.value, {
language,
currency: props.currency,
})}
</span>
</div>

Expand Down
13 changes: 9 additions & 4 deletions packages/app-builder/src/components/Transfers/TransfersList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Transfer } from '@app-builder/models/transfer';
import { formatNumber, useFormatLanguage } from '@app-builder/utils/format';
import { formatCurrency, useFormatLanguage } from '@app-builder/utils/format';
import { getRoute } from '@app-builder/utils/routes';
import { fromUUID } from '@app-builder/utils/short-uuid';
import { Link } from '@remix-run/react';
Expand Down Expand Up @@ -33,11 +33,16 @@ export function TransfersList({ className, transfers }: TransfersListProps) {
id: 'value',
header: 'Value',
size: 100,
cell: ({ getValue }) => (
<span>{formatNumber(getValue(), { language })}</span>
cell: ({ getValue, row }) => (
<span>
{formatCurrency(getValue(), {
language,
currency: row.original.data.currency,
})}
</span>
),
}),
columnHelper.accessor((row) => row.data.currency, {
columnHelper.accessor((row) => row.data.currency.code, {
id: 'currency',
header: 'Currency',
size: 50,
Expand Down
6 changes: 4 additions & 2 deletions packages/app-builder/src/models/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { adaptCurrency } from '@app-builder/utils/currencies';
import { type Currency } from 'dinero.js';
import {
type TransferDataDto,
type TransferDto,
Expand All @@ -15,7 +17,7 @@ export interface TransferData {
beneficiaryIban: string;
beneficiaryName: string;
createdAt: string;
currency: string;
currency: Currency<number>;
label: string;
senderAccountId: string;
senderAccountType: 'physical_person' | 'moral_person';
Expand All @@ -38,7 +40,7 @@ export function adaptTransferData(
beneficiaryIban: transferDataDto.beneficiary_iban,
beneficiaryName: transferDataDto.beneficiary_name,
createdAt: transferDataDto.created_at,
currency: transferDataDto.currency,
currency: adaptCurrency(transferDataDto.currency),
label: transferDataDto.label,
senderAccountId: transferDataDto.sender_account_id,
senderAccountType: transferDataDto.sender_account_type,
Expand Down
Loading