Skip to content

Commit

Permalink
Merge pull request #1065 from multiversx/mm-fix-data-testids
Browse files Browse the repository at this point in the history
Fixed data-testids
  • Loading branch information
Miro authored Mar 8, 2024
2 parents 28813d4 + 9059a82 commit b6a6b76
Show file tree
Hide file tree
Showing 6 changed files with 3,221 additions and 2,798 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp",
"version": "2.28.8-alpha.2",
"version": "2.28.8-alpha.3",
"description": "A library to hold the main logic for a dapp on the MultiversX blockchain",
"author": "MultiversX",
"license": "GPL-3.0-or-later",
Expand Down
51 changes: 43 additions & 8 deletions src/UI/Balance/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,68 @@ export const BalanceComponent = ({
? `$${mainBalance}`
: mainBalance;

const getBalancePayload = () => {
const balancePayload: Record<string, string> = {};

if (addEqualSign && displayAsUsd) {
Object.assign(balancePayload, { approximation: '≈' });
}

if (processedMainBalance) {
Object.assign(balancePayload, { processedMainBalance });
}

if (decimalBalance) {
Object.assign(balancePayload, { decimalBalance: `.${decimalBalance}` });
}

if (!displayAsUsd && showTokenLabel) {
Object.assign(balancePayload, { tokenLabel: ` ${tokenLabel}` });
}

return balancePayload;
};

const balancePayload = getBalancePayload();
const dataBalanceValue = Object.values(balancePayload).reduce(
(totalBalanceValue, currentBalanceValue) =>
totalBalanceValue.concat(currentBalanceValue),
''
);

return (
<div
className={classNames(styles?.balance, className)}
data-testid={dataTestId}
data-value={dataBalanceValue}
>
{egldIcon && !displayAsUsd && (
<MultiversXSymbol className={styles?.balanceSymbol} />
)}

{addEqualSign && displayAsUsd && (
<span className={styles?.balanceApproximation}></span>
{balancePayload.approximation && (
<span className={styles?.balanceApproximation}>
{balancePayload.approximation}
</span>
)}

<span className={styles?.balanceMain}>{processedMainBalance}</span>
{balancePayload.processedMainBalance && (
<span className={styles?.balanceMain}>{processedMainBalance}</span>
)}

{decimalBalance && (
<span className={styles?.balanceDecimals}>.{decimalBalance}</span>
{balancePayload.decimalBalance && (
<span className={styles?.balanceDecimals}>
{balancePayload.decimalBalance}
</span>
)}

{!displayAsUsd && showTokenLabel && (
{balancePayload.tokenLabel && (
<sup
className={classNames(styles?.balanceSuffix, {
[styles?.balanceSuffixSup]: showTokenLabelSup
})}
>
{' '}
{tokenLabel}
{balancePayload.tokenLabel}
</sup>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ const ConfirmAmountComponent = ({
tokenId: tokenIdForTokenDetails
});

const { type, esdtPrice, isLoading: isTokenDetailsLoading } = tokenDetails;
const { price: egldPrice } = useGetEgldPrice();
const {
type,
esdtPrice,
isLoading: isTokenDetailsLoading,
identifier
} = tokenDetails;

const isEgld = !tokenId;
const tokenPrice = isEgld ? egldPrice : esdtPrice;
Expand All @@ -51,7 +56,11 @@ const ConfirmAmountComponent = ({
{isTokenDetailsLoading ? (
<LoadingDots />
) : (
<ConfirmAmountLabel amount={amount} type={type} />
<ConfirmAmountLabel
amount={amount}
type={type}
identifier={identifier}
/>
)}
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import BigNumber from 'bignumber.js';

import { DataTestIdsEnum } from 'constants/index';
import { withStyles } from 'hocs/withStyles';
import { NftEnumType } from 'types/tokens.types';

Expand All @@ -9,17 +10,20 @@ import { WithStylesImportType } from '../../../../../../../../hocs/useStyles';
interface ConfirmAmountLabelPropsType extends WithStylesImportType {
type?: NftEnumType;
amount: string;
identifier?: string;
}

const ConfirmAmountLabelComponent = ({
amount,
styles,
type
type,
identifier
}: ConfirmAmountLabelPropsType) => {
const amountBigNumber = new BigNumber(amount);
const isAmountZero = amountBigNumber.isZero();
const sftLabel = amountBigNumber.isEqualTo(1) ? 'SFT' : 'SFTs';
const amountToLocaleString = amountBigNumber.toNumber().toLocaleString('en');
const dataValue = `${amountToLocaleString} ${identifier}`;

if (isAmountZero) {
return <div className={styles?.confirmAmountLabel}>You are using</div>;
Expand All @@ -35,7 +39,11 @@ const ConfirmAmountLabelComponent = ({
return (
<div className={styles?.confirmAmountLabel}>
<span className={styles?.confirmAmountLabelText}>You are sending</span>
<span className={styles?.confirmAmountLabelValue}>
<span
className={styles?.confirmAmountLabelValue}
data-testid={DataTestIdsEnum.confirmAmount}
data-value={dataValue}
>
{amountToLocaleString} {sftLabel}
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ConfirmAmountNftSftComponent = ({
tokenDetails
}: ConfirmAmountNftSftPropsType) => {
const { network } = useGetNetworkConfig();
const { identifier, tokenAvatar, ticker, name } = tokenDetails;
const { identifier, tokenAvatar, name } = tokenDetails;

const isSft = NftEnumType.SemiFungibleESDT === type;
const mirroredSftAvatarsCount = 4;
Expand Down Expand Up @@ -95,7 +95,7 @@ const ConfirmAmountNftSftComponent = ({
className={styles?.confirmAmountNftSftTicker}
data-testid={DataTestIdsEnum.nftIdentifier}
>
{ticker}
{identifier}
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit b6a6b76

Please sign in to comment.