Skip to content

Commit 1ea30e9

Browse files
Updates on components (#356)
* Updates on components * Updated to use getExplorerLink * Updated package * Moved getExplorerLink import to lib
1 parent fa28a5f commit 1ea30e9

File tree

8 files changed

+213
-143
lines changed

8 files changed

+213
-143
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@fortawesome/fontawesome-svg-core": "6.5.1",
1010
"@fortawesome/free-solid-svg-icons": "6.5.1",
1111
"@fortawesome/react-fontawesome": "0.2.0",
12-
"@multiversx/sdk-core": "14.2.3",
12+
"@multiversx/sdk-core": "14.2.6",
1313
"@multiversx/sdk-dapp": "^5.x",
1414
"@multiversx/sdk-dapp-ui": "^0.x",
1515
"@multiversx/sdk-dapp-utils": "2.0.2",
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
import { Label } from 'components';
22
import { contractAddress } from 'config';
3-
import { ACCOUNTS_ENDPOINT, ExplorerLink } from 'lib';
3+
import {
4+
ACCOUNTS_ENDPOINT,
5+
getExplorerLink,
6+
MvxExplorerLink,
7+
useGetNetworkConfig
8+
} from 'lib';
49

510
export const ContractAddress = () => {
11+
const { network } = useGetNetworkConfig();
12+
const explorerAddress = network.explorerAddress;
13+
const explorerLink = getExplorerLink({
14+
to: `/${ACCOUNTS_ENDPOINT}/${contractAddress}`,
15+
explorerAddress
16+
});
617
return (
718
<p>
819
<Label>Contract: </Label>
9-
<ExplorerLink
10-
page={`/${ACCOUNTS_ENDPOINT}/${contractAddress}`}
20+
<MvxExplorerLink
21+
link={explorerLink}
1122
className='border-b border-dotted border-gray-500 hover:border-solid hover:border-gray-800'
1223
>
1324
{contractAddress}
14-
</ExplorerLink>
25+
</MvxExplorerLink>
1526
</p>
1627
);
1728
};

src/components/OutputContainer/components/PingPongOutput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const PingPongOutput = ({
1313
pongAllowed,
1414
transactions
1515
}: PingPongOutputType) => {
16-
if (!transactions) {
16+
if (!transactions || transactions?.length === 0) {
1717
return null;
1818
}
1919

src/components/OutputContainer/components/TransactionOutput.tsx

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,76 @@
11
import { Label } from 'components';
22
import {
33
ACCOUNTS_ENDPOINT,
4-
ExplorerLink,
5-
FormatAmount,
4+
DECIMALS,
5+
DIGITS,
6+
FormatAmountController,
7+
getExplorerLink,
8+
MvxExplorerLink,
9+
MvxFormatAmount,
610
SignedTransactionType,
711
TRANSACTIONS_ENDPOINT,
12+
useGetAccountInfo,
813
useGetNetworkConfig
914
} from 'lib';
10-
import { DataTestIdsEnum } from 'localConstants';
1115

1216
export const TransactionOutput = ({
1317
transaction
1418
}: {
1519
transaction: SignedTransactionType;
1620
}) => {
1721
const { network } = useGetNetworkConfig();
22+
const { account } = useGetAccountInfo();
1823
const decodedData = transaction.data
1924
? Buffer.from(transaction.data, 'base64').toString('ascii')
2025
: 'N/A';
26+
27+
const { isValid, valueDecimal, valueInteger, label } =
28+
FormatAmountController.getData({
29+
digits: DIGITS,
30+
decimals: DECIMALS,
31+
egldLabel: network.egldLabel,
32+
input: account.balance
33+
});
34+
35+
const explorerAddress = network.explorerAddress;
36+
const hashExplorerLink = getExplorerLink({
37+
to: `/${TRANSACTIONS_ENDPOINT}/${transaction.hash}`,
38+
explorerAddress
39+
});
40+
const receiverExplorerLink = getExplorerLink({
41+
to: `/${ACCOUNTS_ENDPOINT}/${transaction.receiver}`,
42+
explorerAddress
43+
});
44+
2145
return (
2246
<div className='flex flex-col'>
2347
<p>
2448
<Label>Hash:</Label>
25-
<ExplorerLink
26-
page={`/${TRANSACTIONS_ENDPOINT}/${transaction.hash}`}
49+
<MvxExplorerLink
50+
link={hashExplorerLink}
2751
className='border-b border-dotted border-gray-500 hover:border-solid hover:border-gray-800'
2852
>
2953
{transaction.hash}
30-
</ExplorerLink>
54+
</MvxExplorerLink>
3155
</p>
3256
<p>
3357
<Label>Receiver:</Label>
34-
<ExplorerLink
35-
page={`/${ACCOUNTS_ENDPOINT}/${transaction.receiver}`}
58+
<MvxExplorerLink
59+
link={receiverExplorerLink}
3660
className='border-b border-dotted border-gray-500 hover:border-solid hover:border-gray-800'
3761
>
3862
{transaction.receiver}
39-
</ExplorerLink>
63+
</MvxExplorerLink>
4064
</p>
4165

4266
<p>
4367
<Label>Amount: </Label>
44-
<FormatAmount
45-
value={transaction.value}
46-
showLabel={transaction.value !== '0'}
47-
egldLabel={network.egldLabel}
48-
data-testid={DataTestIdsEnum.balance}
68+
<MvxFormatAmount
69+
isValid={isValid}
70+
valueInteger={valueInteger}
71+
valueDecimal={valueDecimal}
72+
label={label}
73+
data-testid='balance'
4974
/>
5075
</p>
5176
<p>

src/lib/sdkDapp/sdkDapp.helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { UnlockPanelManager } from '@multiversx/sdk-dapp/out/managers/UnlockPane
66
export { WALLET_PROVIDER_SEND_TRANSACTION_URL } from '@multiversx/sdk-dapp/out/constants/webWalletProvider.constants';
77
export { getAccountProvider } from '@multiversx/sdk-dapp/out/providers/helpers/accountProvider';
88
export { getActiveTransactionsStatus } from '@multiversx/sdk-dapp/out/utils/transactions/getActiveTransactionsStatus';
9+
export { getExplorerLink } from '@multiversx/sdk-dapp/out/utils/transactions/getExplorerLink';
910
export { getInterpretedTransaction } from '@multiversx/sdk-dapp/out/utils/transactions/getInterpretedTransaction';
1011
export { getTransactions } from '@multiversx/sdk-dapp/out/apiCalls/transactions/getTransactions';
1112
export { initApp } from '@multiversx/sdk-dapp/out/methods/initApp/initApp';

src/pages/Dashboard/widgets/Account/Account.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { Label, OutputContainer } from 'components';
2-
import { FormatAmount, useGetAccountInfo, useGetNetworkConfig } from 'lib';
3-
import { DataTestIdsEnum } from 'localConstants';
2+
import {
3+
DECIMALS,
4+
DIGITS,
5+
FormatAmountController,
6+
MvxFormatAmount,
7+
useGetAccountInfo,
8+
useGetNetworkConfig
9+
} from 'lib';
410
import { Username } from './components';
511

612
export const Account = () => {
713
const { network } = useGetNetworkConfig();
814
const { address, account } = useGetAccountInfo();
915

16+
const { isValid, valueDecimal, valueInteger, label } =
17+
FormatAmountController.getData({
18+
digits: DIGITS,
19+
decimals: DECIMALS,
20+
egldLabel: network.egldLabel,
21+
input: account.balance
22+
});
23+
1024
return (
1125
<OutputContainer>
1226
<div className='flex flex-col text-black' data-testid='topInfo'>
@@ -22,10 +36,13 @@ export const Account = () => {
2236

2337
<p>
2438
<Label>Balance: </Label>
25-
<FormatAmount
26-
value={account.balance}
27-
egldLabel={network.egldLabel}
28-
data-testid={DataTestIdsEnum.balance}
39+
40+
<MvxFormatAmount
41+
isValid={isValid}
42+
valueInteger={valueInteger}
43+
valueDecimal={valueDecimal}
44+
label={label}
45+
data-testid='balance'
2946
/>
3047
</p>
3148
</div>

src/pages/Dashboard/widgets/NativeAuth/NativeAuth.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import { useEffect } from 'react';
22
import { Label, MissingNativeAuthError, OutputContainer } from 'components';
3-
import { FormatAmount, useGetLoginInfo, useGetNetworkConfig } from 'lib';
3+
import {
4+
DECIMALS,
5+
DIGITS,
6+
FormatAmountController,
7+
MvxFormatAmount,
8+
useGetLoginInfo,
9+
useGetNetworkConfig
10+
} from 'lib';
411
import { Username } from '../Account/components';
512
import { useGetProfile } from './hooks';
613

714
export const NativeAuth = () => {
815
const { tokenLogin, isLoggedIn } = useGetLoginInfo();
916
const { isLoading, profile, getProfile } = useGetProfile();
1017
const { network } = useGetNetworkConfig();
18+
const { isValid, valueDecimal, valueInteger, label } =
19+
FormatAmountController.getData({
20+
digits: DIGITS,
21+
decimals: DECIMALS,
22+
egldLabel: network.egldLabel,
23+
input: profile?.balance ?? '0'
24+
});
1125

1226
useEffect(() => {
1327
// On page refresh, tokenInfo is null which implies that we do not have access to loginInfo data
@@ -43,10 +57,11 @@ export const NativeAuth = () => {
4357

4458
<div className='flex gap-1'>
4559
<Label>Balance:</Label>
46-
<FormatAmount
47-
value={profile?.balance ?? '0'}
48-
showLabel={profile?.balance !== '0'}
49-
egldLabel={network.egldLabel}
60+
<MvxFormatAmount
61+
isValid={isValid}
62+
valueInteger={valueInteger}
63+
valueDecimal={valueDecimal}
64+
label={label}
5065
data-testid='balance'
5166
/>
5267
</div>

0 commit comments

Comments
 (0)