Skip to content

Commit

Permalink
chore(trading): move common types to suite-common
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive authored and izmy committed Jan 31, 2025
1 parent fbf5e80 commit 4425d89
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Locator, Page } from '@playwright/test';

import { regional } from '@suite-common/trading';
import { FiatCurrencyCode } from '@suite-common/suite-config';
import { regional } from '@suite-common/trading';
import { NetworkSymbol } from '@suite-common/wallet-config';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CryptoId } from 'invity-api';

import { isDesktop } from '@trezor/env-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import type { TradingType } from '@suite-common/trading';
import {
confirmAddressOnDeviceThunk,
selectSelectedDevice,
Expand All @@ -15,8 +15,8 @@ import {
hasNetworkFeatures,
parseFormDraftKey,
} from '@suite-common/wallet-utils';
import type { TradingType } from '@suite-common/trading';
import { PROTO } from '@trezor/connect';
import { isDesktop } from '@trezor/env-utils';

import * as modalActions from 'src/actions/suite/modalActions';
import { TRADING_BUY, TRADING_COMMON, TRADING_EXCHANGE } from 'src/actions/wallet/constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useForm, useWatch } from 'react-hook-form';
import type { BuyTrade, BuyTradeQuoteRequest, CryptoId } from 'invity-api';
import useDebounce from 'react-use/lib/useDebounce';

import { type TradingBuyType, invityAPI } from '@suite-common/trading';
import { isChanged } from '@suite-common/suite-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import { type TradingBuyType, invityAPI } from '@suite-common/trading';
import { networks } from '@suite-common/wallet-config';
import { formatAmount } from '@suite-common/wallet-utils';
import { isDesktop } from '@trezor/env-utils';
import { analytics, EventType } from '@trezor/suite-analytics';
import { EventType, analytics } from '@trezor/suite-analytics';

import * as routerActions from 'src/actions/suite/routerActions';
import * as tradingCommonActions from 'src/actions/wallet/trading/tradingCommonActions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
} from 'invity-api';
import useDebounce from 'react-use/lib/useDebounce';

import { type TradingExchangeType, invityAPI } from '@suite-common/trading';
import { isChanged } from '@suite-common/suite-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import { type TradingExchangeType, invityAPI } from '@suite-common/trading';
import { networks } from '@suite-common/wallet-config';
import { Account } from '@suite-common/wallet-types';
import { amountToSmallestUnit, formatAmount, toFiatCurrency } from '@suite-common/wallet-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useForm, useWatch } from 'react-hook-form';
import type { BankAccount, CryptoId, SellFiatTrade, SellFiatTradeQuoteRequest } from 'invity-api';
import useDebounce from 'react-use/lib/useDebounce';

import { type TradingSellType, invityAPI } from '@suite-common/trading';
import { isChanged } from '@suite-common/suite-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import { type TradingSellType, invityAPI } from '@suite-common/trading';
import { networks } from '@suite-common/wallet-config';
import { amountToSmallestUnit, formatAmount } from '@suite-common/wallet-utils';
import { EventType, analytics } from '@trezor/suite-analytics';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ import {
WatchSellTradeResponse,
} from 'invity-api';

import { type TradingType, invityAPI } from '@suite-common/trading';
import { type TradingTradeStatusType, type TradingType, invityAPI } from '@suite-common/trading';

import { saveTrade as saveBuyTrade } from 'src/actions/wallet/tradingBuyActions';
import { saveTrade as saveExchangeTrade } from 'src/actions/wallet/tradingExchangeActions';
import { saveTrade as saveSellTrade } from 'src/actions/wallet/tradingSellActions';
import { useFormDraft } from 'src/hooks/wallet/useFormDraft';
import {
TradingTradeStatusType,
TradingUseWatchTradeProps,
TradingWatchTradeProps,
} from 'src/types/trading/trading';
import { TradingUseWatchTradeProps, TradingWatchTradeProps } from 'src/types/trading/trading';
import { Trade, TradeType } from 'src/types/wallet/tradingCommonTypes';

export const tradeFinalStatuses: Record<TradeType, TradingTradeStatusType[]> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/suite/src/reducers/suite/suiteReducer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import produce from 'immer';

import type { InvityServerEnvironment } from '@suite-common/trading';
import { Feature, selectIsFeatureDisabled } from '@suite-common/message-system';
import { isDeviceAcquired } from '@suite-common/suite-utils';
import type { InvityServerEnvironment } from '@suite-common/trading';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { DeviceRootState, discoveryActions, selectSelectedDevice } from '@suite-common/wallet-core';
import { AddressDisplayOptions, WalletType } from '@suite-common/wallet-types';
Expand Down
15 changes: 1 addition & 14 deletions packages/suite/src/types/trading/trading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@ import {
BuyCryptoPaymentMethod,
BuyProviderInfo,
BuyTrade,
BuyTradeStatus,
CryptoId,
ExchangeProviderInfo,
ExchangeTrade,
ExchangeTradeStatus,
FiatCurrencyCode,
SellFiatTrade,
SellProviderInfo,
SellTradeStatus,
} from 'invity-api';
import { AnyAction, Dispatch } from 'redux';

import { TokenDefinitionsState } from '@suite-common/token-definitions';
import type {
TradingBuyType,
TradingExchangeType,
TradingPaymentMethodType,
TradingSellType,
TradingType,
} from '@suite-common/trading';
import { TokenDefinitionsState } from '@suite-common/token-definitions';
import { AccountType, NetworkSymbolExtended } from '@suite-common/wallet-config';
import { AccountsState } from '@suite-common/wallet-core';
import { Account, SelectedAccountLoaded } from '@suite-common/wallet-types';
Expand Down Expand Up @@ -100,8 +97,6 @@ export interface TradingGetTypedTradeProps {
transactionId: string | undefined;
}

export type TradingTradeStatusType = BuyTradeStatus | SellTradeStatus | ExchangeTradeStatus;

export interface TradingGetDetailDataProps {
trading: State;
tradeType: TradeType;
Expand Down Expand Up @@ -138,14 +133,6 @@ export interface TradingCryptoListProps {
cryptoName?: string | undefined; // full name
}

export type TradingUtilsProvidersProps = {
[name: string]: {
logo: string;
companyName: string;
brandName?: string;
};
};

export interface TradingInfoProps {
cryptoIdToPlatformName: (cryptoId: CryptoId) => string | undefined;
cryptoIdToCoinName: (cryptoId: CryptoId) => string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/suite/src/utils/wallet/trading/tradingUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BuyTrade, CryptoId, ExchangeTrade, SellFiatTrade } from 'invity-api';
import { v4 as uuidv4 } from 'uuid';

import { type TradingTradeType, type TradingType, regional } from '@suite-common/trading';
import { DefinitionType, isTokenDefinitionKnown } from '@suite-common/token-definitions';
import { type TradingTradeType, type TradingType, regional } from '@suite-common/trading';
import {
Network,
NetworkSymbol,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { TradingTradeType } from '@suite-common/trading';
import type { TradingTradeType, TradingUtilsProvidersProps } from '@suite-common/trading';
import { Card, Paragraph, Row, Spinner } from '@trezor/components';
import { spacings } from '@trezor/theme';

import { Translation } from 'src/components/suite';
import { TradingUtilsProvidersProps } from 'src/types/trading/trading';
import { TradingUtilsProvider } from 'src/views/wallet/trading/common/TradingUtils/TradingUtilsProvider';

interface TradingFormOfferItemProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TradingTradeType } from '@suite-common/trading';
import type { TradingTradeType, TradingUtilsProvidersProps } from '@suite-common/trading';
import { Card, Column, Paragraph, Row, Spinner } from '@trezor/components';
import { spacings } from '@trezor/theme';

Expand All @@ -10,7 +10,6 @@ import {
FORM_RATE_FLOATING,
FORM_RATE_TYPE,
} from 'src/constants/wallet/trading/form';
import { TradingUtilsProvidersProps } from 'src/types/trading/trading';
import { TradingExchangeFormContextProps } from 'src/types/trading/tradingForm';
import { TradingFormOffersSwitcherItem } from 'src/views/wallet/trading/common/TradingForm/TradingFormOffersSwitcherItem';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ExchangeTrade } from 'invity-api';
import styled from 'styled-components';

import { TradingUtilsProvidersProps } from '@suite-common/trading';
import { Badge, Radio, Row, Text, Tooltip, useElevation } from '@trezor/components';
import { Elevation, borders, mapElevationToBackground, spacings, spacingsPx } from '@trezor/theme';

import { Translation } from 'src/components/suite';
import { FORM_EXCHANGE_CEX, FORM_EXCHANGE_DEX } from 'src/constants/wallet/trading/form';
import { TradingUtilsProvidersProps } from 'src/types/trading/trading';
import { ExchangeType } from 'src/types/trading/tradingForm';
import { TradingUtilsProvider } from 'src/views/wallet/trading/common/TradingUtils/TradingUtilsProvider';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PropsWithChildren, useMemo } from 'react';

import type { TradingType } from '@suite-common/trading';
import { Route } from '@suite-common/suite-types';
import type { TradingType } from '@suite-common/trading';
import { Box, Button, IconButton, Row } from '@trezor/components';
import { spacings } from '@trezor/theme';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import styled from 'styled-components';

import { invityAPI } from '@suite-common/trading';
import { TradingUtilsProvidersProps, invityAPI } from '@suite-common/trading';
import { Row } from '@trezor/components';
import { spacings } from '@trezor/theme';

import { Translation } from 'src/components/suite';
import { TradingUtilsProvidersProps } from 'src/types/trading/trading';

const Icon = styled.img`
flex: none;
Expand Down
11 changes: 11 additions & 0 deletions suite-common/trading/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type {
BuyCryptoPaymentMethod,
BuyTrade,
BuyTradeStatus,
ExchangeTrade,
ExchangeTradeStatus,
SellCryptoPaymentMethod,
SellFiatTrade,
SellTradeStatus,
WatchBuyTradeResponse,
WatchExchangeTradeResponse,
WatchSellTradeResponse,
Expand All @@ -27,3 +30,11 @@ export type TradingWatchTradeResponsePropsMap = {
};

export type TradingPaymentMethodType = BuyCryptoPaymentMethod | SellCryptoPaymentMethod;
export type TradingTradeStatusType = BuyTradeStatus | SellTradeStatus | ExchangeTradeStatus;
export type TradingUtilsProvidersProps = {
[name: string]: {
logo: string;
companyName: string;
brandName?: string;
};
};

0 comments on commit 4425d89

Please sign in to comment.