Skip to content

Commit 540db0f

Browse files
committed
refactor: migrate from useTradingInfo to useTradingUtils
1 parent e9290ef commit 540db0f

File tree

53 files changed

+253
-553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+253
-553
lines changed

packages/product-components/src/components/AssetLogo/AssetLogo.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,15 @@ export const AssetLogo = ({
271271
onLoad={handleOnLoad}
272272
onError={handleLoadError}
273273
/>
274-
{showNetworkIcon && (
275-
<StyledNetworkIcon
276-
networkSymbol={symbol as NetworkSymbol | LegacyNetworkSymbol}
277-
size={size * 0.375}
278-
/>
279-
)}
280274
</ElevationUp>
281275
)}
276+
277+
{showNetworkIcon && (
278+
<StyledNetworkIcon
279+
networkSymbol={symbol as NetworkSymbol | LegacyNetworkSymbol}
280+
size={size * 0.375}
281+
/>
282+
)}
282283
</Container>
283284
);
284285
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import { spacings } from '@trezor/theme';
77
import { ItemClickableContainer } from '../ItemClickableContainer';
88
import { AccountAmount } from './AccountAmount';
99

10-
export type AssetRowSendFromAccountProps = {
10+
export type AssetRowAccountWithBalanceProps = {
1111
account: Account;
1212
dataTestId?: string;
1313
onClick: (account: Account) => void;
1414
};
1515

16-
export function AssetRowSendFromAccount({
16+
export function AssetRowAccountWithBalance({
1717
dataTestId,
1818
account,
1919
onClick,
20-
}: AssetRowSendFromAccountProps) {
20+
}: AssetRowAccountWithBalanceProps) {
2121
return (
2222
<ItemClickableContainer onClick={() => onClick(account)}>
2323
<Row data-testid={dataTestId} gap={spacings.sm} alignItems="center">
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './constants';
22
export * from './AssetRowReceiveToAccount';
3-
export * from './AssetRowSendFromAccount';
3+
export * from './AssetRowAccountWithBalance';

packages/suite/src/components/suite/layouts/SuiteLayout/PageHeader/GlobalSendReceive/GlobalSendModal/GlobalSendModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { setSendFormPrefill } from 'src/actions/suite/suiteActions';
99
import {
1010
AssetGroupLabel,
1111
AssetGroupSpace,
12-
AssetRowSendFromAccount,
12+
AssetRowAccountWithBalance,
1313
AssetRowToken,
1414
AssetsList,
1515
AssetsListEmpty,
@@ -71,7 +71,7 @@ export function GlobalSendModal({ onCancel, onSubmit }: GlobalSendModalProps) {
7171

7272
case 'account':
7373
return (
74-
<AssetRowSendFromAccount
74+
<AssetRowAccountWithBalance
7575
account={item.account}
7676
onClick={handleAccountClick}
7777
/>

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/ApproveModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
TradingExchangeType,
88
invityAPI,
99
tradingExchangeActions,
10-
useTradingInfo,
10+
useTradingUtils,
1111
} from '@suite-common/trading';
1212
import { getDisplaySymbol } from '@suite-common/wallet-config';
1313
import {
@@ -82,7 +82,7 @@ export const ApproveModal = ({
8282

8383
const isDebug = useSelector(selectIsDebugModeActive);
8484

85-
const { cryptoIdToSymbolAndContractAddress, cryptoIdToCoinSymbol } = useTradingInfo();
85+
const { cryptoIdToSymbolAndContractAddress, cryptoIdToCoinSymbol } = useTradingUtils();
8686

8787
const [approvalType, setApprovalType] = useState<DexApprovalType>('MINIMAL');
8888
const [isConfirmButtonLoading, setIsConfirmButtonLoading] = useState<boolean>(false);

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/RevokeModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TradingExchangeType,
77
invityAPI,
88
tokenSupportsIncreasingAllowance,
9-
useTradingInfo,
9+
useTradingUtils,
1010
} from '@suite-common/trading';
1111
import { getDisplaySymbol } from '@suite-common/wallet-config';
1212
import {
@@ -70,7 +70,7 @@ export const RevokeModal = ({ setIsWaitingForDevice, onCancel }: RevokeModalProp
7070

7171
const isDebug = useSelector(selectIsDebugModeActive);
7272

73-
const { cryptoIdToSymbolAndContractAddress } = useTradingInfo();
73+
const { cryptoIdToSymbolAndContractAddress } = useTradingUtils();
7474

7575
const [isConfirmButtonLoading, setIsConfirmButtonLoading] = useState<boolean>(false);
7676

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/TradingTermsModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState } from 'react';
22

33
import { CryptoId } from 'invity-api';
44

5-
import { TradingType, useTradingInfo } from '@suite-common/trading';
5+
import { TradingType, useTradingUtils } from '@suite-common/trading';
66
import {
77
// Banner,
88
// Checkbox,
@@ -53,7 +53,7 @@ export const TradingTermsModal = ({
5353

5454
const providerName = provider || 'unknown provider';
5555
const { device } = useDevice();
56-
const { cryptoIdToCoinSymbol } = useTradingInfo();
56+
const { cryptoIdToCoinSymbol } = useTradingUtils();
5757
const iconProps = {
5858
size: 24,
5959
paddingType: 'medium',

packages/suite/src/hooks/wallet/trading/form/common/useTradingFiatValues.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useMemo } from 'react';
33
import { CryptoId, FiatCurrencyCode } from 'invity-api';
44

55
import {
6+
TRADING_DEFAULT_CRYPTO_CURRENCY,
67
cryptoIdToNetworkAndContractAddress,
78
isCryptoIdForNativeToken,
89
mapTestnetSymbol,
@@ -53,15 +54,14 @@ export const useTradingFiatValues = ({
5354
const isNativeToken = cryptoId && isCryptoIdForNativeToken(cryptoId);
5455

5556
const { network, contractAddress, symbol } = useMemo(() => {
56-
const defaultCryptoSymbol = 'btc';
5757
const assetInfo = cryptoId && cryptoIdToNetworkAndContractAddress(cryptoId);
5858

5959
return {
6060
network: assetInfo?.network,
6161
contractAddress: isNativeToken
6262
? undefined
6363
: (assetInfo?.contractAddress as TokenAddress | undefined),
64-
symbol: assetInfo?.network?.symbol ?? defaultCryptoSymbol,
64+
symbol: assetInfo?.network?.symbol ?? TRADING_DEFAULT_CRYPTO_CURRENCY,
6565
};
6666
}, [cryptoId, isNativeToken]);
6767

packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,18 @@ export const useTradingExchangeForm = ({
190190
const isReceiveAddressFormValid =
191191
Object.keys(tradingReceiveAddress.form.formState.errors).length === 0;
192192

193-
useTradingFiatValues({
194-
cryptoId: receiveCryptoSelect?.id,
195-
// FIXME: cermak: ????
196-
// amount: receiveCryptoSelect?.balance,
197-
fiatCurrency: output?.currency?.value as FiatCurrencyCode,
198-
});
193+
const fiatTradingValuesParams = selectedQuote
194+
? {
195+
cryptoId: selectedQuote.receive,
196+
amount: selectedQuote.receiveStringAmount,
197+
fiatCurrency: output?.currency?.value as FiatCurrencyCode | undefined,
198+
}
199+
: {
200+
cryptoId: quotesRequest?.receive,
201+
amount: output?.amount,
202+
fiatCurrency: output?.currency?.value as FiatCurrencyCode | undefined,
203+
};
204+
useTradingFiatValues(fiatTradingValuesParams);
199205

200206
const formIsValid = Object.keys(formState.errors).length === 0;
201207
const hasValues = !!output?.amount && !!values.receiveCryptoSelect;
@@ -733,10 +739,10 @@ export const useTradingExchangeForm = ({
733739
await handleChange();
734740
};
735741

736-
const fetchFeesAndCompose = async () => {
742+
const fetchFeesAndCompose = useCallback(async () => {
737743
await dispatch(updateFeeInfoThunk({ networkSymbol: account.symbol })).unwrap();
738744
composeRequest();
739-
};
745+
}, [dispatch, account.symbol, composeRequest]);
740746

741747
useEffect(() => {
742748
const networkType = getNetworkType(account.symbol);
@@ -800,18 +806,15 @@ export const useTradingExchangeForm = ({
800806
if (pageType !== 'form') return;
801807

802808
fetchFeesAndCompose();
803-
// eslint-disable-next-line react-hooks/exhaustive-deps
804-
}, [transactionData, outputAddress, ethereumAdjustGasLimit, pageType]);
809+
}, [transactionData, outputAddress, ethereumAdjustGasLimit, pageType, fetchFeesAndCompose]);
805810

806811
useEffect(() => {
807812
setValue('receiveAddress', receiveAddress);
808-
// eslint-disable-next-line react-hooks/exhaustive-deps
809-
}, [receiveAddress]);
813+
}, [receiveAddress, setValue]);
810814

811815
useEffect(() => {
812816
setValue('extraField', extraField);
813-
// eslint-disable-next-line react-hooks/exhaustive-deps
814-
}, [extraField]);
817+
}, [extraField, setValue]);
815818

816819
useEffect(() => {
817820
dispatch(tradingThunks.loadInitialDataThunk({ activeSection: type }));

packages/suite/src/support/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11149,7 +11149,7 @@ export default defineMessages({
1114911149
defaultMessage: 'To',
1115011150
},
1115111151
TR_ASSET_PICKER_SEARCH_PLACEHOLDER: {
11152-
id: 'TR_SWAP_ASSET_PICKER_SEARCH_PLACEHOLDER',
11152+
id: 'TR_ASSET_PICKER_SEARCH_PLACEHOLDER',
1115311153
defaultMessage: 'Search coin or token',
1115411154
},
1115511155
TR_ASSET_PICKER_YOUR_ASSETS: {

0 commit comments

Comments
 (0)