diff --git a/packages/suite/src/actions/suite/storageActions.ts b/packages/suite/src/actions/suite/storageActions.ts index 84e6b2f0f7f..cfb85247cbb 100644 --- a/packages/suite/src/actions/suite/storageActions.ts +++ b/packages/suite/src/actions/suite/storageActions.ts @@ -4,6 +4,7 @@ import { MetadataState } from '@suite-common/metadata-types'; import { isDeviceAcquired } from '@suite-common/suite-utils'; import { notificationsActions } from '@suite-common/toast-notifications'; import { DefinitionType, TokenManagementAction } from '@suite-common/token-definitions'; +import type { TradingTransaction } from '@suite-common/trading'; import type { NetworkSymbol } from '@suite-common/wallet-config'; import { FormDraftPrefixKeyValues } from '@suite-common/wallet-constants'; import { deviceActions, selectDevices } from '@suite-common/wallet-core'; @@ -18,7 +19,6 @@ import type { PreloadStoreAction } from 'src/support/suite/preloadStore'; import type { AppState, Dispatch, GetState, TrezorDevice } from 'src/types/suite'; import type { Account } from 'src/types/wallet'; import { GraphData } from 'src/types/wallet/graph'; -import type { Trade } from 'src/types/wallet/tradingCommonTypes'; import { serializeCoinjoinAccount, serializeDevice, @@ -209,7 +209,7 @@ export const saveAccounts = async (accounts: Account[]) => { return db.addItems('accounts', accounts, true); }; -export const saveTradingTrade = async (trade: Trade) => { +export const saveTradingTrade = async (trade: TradingTransaction) => { if (!(await db.isAccessible())) return; return db.addItem('tradingTrades', trade, undefined, true); diff --git a/packages/suite/src/actions/wallet/tradingBuyActions.ts b/packages/suite/src/actions/wallet/tradingBuyActions.ts index 1cb7d4312f5..a794342ed45 100644 --- a/packages/suite/src/actions/wallet/tradingBuyActions.ts +++ b/packages/suite/src/actions/wallet/tradingBuyActions.ts @@ -7,13 +7,12 @@ import { FiatCurrencyCode, } from 'invity-api'; -import { invityAPI, regional } from '@suite-common/trading'; +import { type TradingFiatCurrenciesProps, invityAPI, regional } from '@suite-common/trading'; +import { Account } from '@suite-common/wallet-types'; import * as modalActions from 'src/actions/suite/modalActions'; import { verifyAddress as verifyBuyAddress } from 'src/actions/wallet/trading/tradingCommonActions'; import { Dispatch } from 'src/types/suite'; -import { TradingFiatCurrenciesProps } from 'src/types/trading/trading'; -import { Account } from 'src/types/wallet'; import { TRADING_BUY, TRADING_COMMON } from './constants'; diff --git a/packages/suite/src/actions/wallet/tradingInfoActions.ts b/packages/suite/src/actions/wallet/tradingInfoActions.ts index 2488f0d8e1f..75001e152cb 100644 --- a/packages/suite/src/actions/wallet/tradingInfoActions.ts +++ b/packages/suite/src/actions/wallet/tradingInfoActions.ts @@ -1,7 +1,8 @@ import { InfoResponse } from 'invity-api'; +import type { TradingPaymentMethodListProps } from '@suite-common/trading'; + import { TRADING_INFO } from 'src/actions/wallet/constants'; -import { TradingPaymentMethodListProps } from 'src/types/trading/trading'; export type TradingInfoAction = | { diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingBuyFormDefaultValues.tsx b/packages/suite/src/hooks/wallet/trading/form/useTradingBuyFormDefaultValues.tsx index 284b59fa5b3..fadcb68856c 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingBuyFormDefaultValues.tsx +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingBuyFormDefaultValues.tsx @@ -2,7 +2,7 @@ import { useMemo } from 'react'; import { CryptoId, FiatCurrencyCode } from 'invity-api'; -import { getDefaultCountry } from '@suite-common/trading'; +import { type TradingPaymentMethodListProps, getDefaultCountry } from '@suite-common/trading'; import { networks } from '@suite-common/wallet-config'; import { BuyInfo } from 'src/actions/wallet/tradingBuyActions'; @@ -12,7 +12,6 @@ import { } from 'src/constants/wallet/trading/form'; import { useSelector } from 'src/hooks/suite'; import { useTradingInfo } from 'src/hooks/wallet/trading/useTradingInfo'; -import { TradingPaymentMethodListProps } from 'src/types/trading/trading'; import { TradingBuyFormDefaultValuesProps } from 'src/types/trading/tradingForm'; import { Account } from 'src/types/wallet'; import { buildFiatOption } from 'src/utils/wallet/trading/tradingUtils'; diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts b/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts index f26126c8114..8c880f96893 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts @@ -13,6 +13,7 @@ import { isChanged } from '@suite-common/suite-utils'; import { notificationsActions } from '@suite-common/toast-notifications'; import { type TradingExchangeType, + type TradingTransactionExchange, addIdsToQuotes, getUnusedAddressFromAccount, invityAPI, @@ -51,7 +52,6 @@ import { TradingExchangeFormProps, TradingExchangeStepType, } from 'src/types/trading/tradingForm'; -import { TradeExchange } from 'src/types/wallet/tradingCommonTypes'; import type { CryptoAmountLimitProps } from 'src/utils/suite/validation'; import { createQuoteLink, @@ -123,9 +123,11 @@ export const useTradingExchangeForm = ({ const network = networks[account.symbol]; const trades = useSelector(state => state.wallet.trading.trades); const trade = trades.find( - trade => - trade.tradeType === 'exchange' && transactionId && trade.data.orderId === transactionId, - ) as TradeExchange | undefined; + (trade): trade is TradingTransactionExchange => + trade.tradeType === 'exchange' && + !!transactionId && + trade.data.orderId === transactionId, + ); const { defaultCurrency, defaultValues } = useTradingExchangeFormDefaultValues(account); const exchangeDraftKey = 'trading-exchange'; diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingPaymentMethod.tsx b/packages/suite/src/hooks/wallet/trading/form/useTradingPaymentMethod.tsx index ad08bbf447c..1abed09cc1c 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingPaymentMethod.tsx +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingPaymentMethod.tsx @@ -1,13 +1,13 @@ import { useCallback } from 'react'; -import type { TradingTradeMapProps } from '@suite-common/trading'; - -import { useSelector } from 'src/hooks/suite'; -import { +import type { TradingPaymentMethodListProps, TradingPaymentMethodProps, - TradingTradeBuySellType, -} from 'src/types/trading/trading'; + TradingTradeMapProps, +} from '@suite-common/trading'; + +import { useSelector } from 'src/hooks/suite'; +import { TradingTradeBuySellType } from 'src/types/trading/trading'; import { TradingPaymentMethodHookProps } from 'src/types/trading/tradingForm'; const useTradingPaymentMethod = < diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts b/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts index 73bd306dc78..d3e625b6fbf 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts @@ -8,6 +8,7 @@ import { isChanged } from '@suite-common/suite-utils'; import { notificationsActions } from '@suite-common/toast-notifications'; import { type TradingSellType, + TradingTransactionSell, addIdsToQuotes, filterQuotesAccordingTags, getUnusedAddressFromAccount, @@ -54,7 +55,6 @@ import { TradingSellFormProps, TradingSellStepType, } from 'src/types/trading/tradingForm'; -import { TradeSell } from 'src/types/wallet/tradingCommonTypes'; import type { AmountLimitProps } from 'src/utils/suite/validation'; import { createQuoteLink, getAmountLimits } from 'src/utils/wallet/trading/sellUtils'; import { getTradingNetworkDecimals } from 'src/utils/wallet/trading/tradingUtils'; @@ -106,8 +106,9 @@ export const useTradingSellForm = ({ const localCurrencyOption = { value: localCurrency, label: localCurrency.toUpperCase() }; const trades = useSelector(state => state.wallet.trading.trades); const trade = trades.find( - trade => trade.tradeType === 'sell' && trade.key === transactionId, - ) as TradeSell | undefined; + (trade): trade is TradingTransactionSell => + trade.tradeType === 'sell' && trade.key === transactionId, + ); const [amountLimits, setAmountLimits] = useState(undefined); const [sellStep, setSellStep] = useState('BANK_ACCOUNT'); diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingSellFormDefaultValues.ts b/packages/suite/src/hooks/wallet/trading/form/useTradingSellFormDefaultValues.ts index 73c1ece1c95..88182786bed 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingSellFormDefaultValues.ts +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingSellFormDefaultValues.ts @@ -1,6 +1,10 @@ import { useMemo } from 'react'; -import { cryptoIdToSymbol, getDefaultCountry } from '@suite-common/trading'; +import { + type TradingPaymentMethodListProps, + cryptoIdToSymbol, + getDefaultCountry, +} from '@suite-common/trading'; import { DEFAULT_PAYMENT, DEFAULT_VALUES } from '@suite-common/wallet-constants'; import { FormState, Output } from '@suite-common/wallet-types'; @@ -11,7 +15,6 @@ import { } from 'src/constants/wallet/trading/form'; import { useSelector } from 'src/hooks/suite'; import { useTradingBuildAccountGroups } from 'src/hooks/wallet/trading/form/common/useTradingBuildAccountGroups'; -import { TradingPaymentMethodListProps } from 'src/types/trading/trading'; import { TradingSellFormDefaultValuesProps } from 'src/types/trading/tradingForm'; import { Account } from 'src/types/wallet'; import { diff --git a/packages/suite/src/hooks/wallet/trading/useTradingDetail.ts b/packages/suite/src/hooks/wallet/trading/useTradingDetail.ts index 26fa2ad4231..a45cdd66467 100644 --- a/packages/suite/src/hooks/wallet/trading/useTradingDetail.ts +++ b/packages/suite/src/hooks/wallet/trading/useTradingDetail.ts @@ -1,6 +1,6 @@ import { createContext, useContext } from 'react'; -import type { TradingType } from '@suite-common/trading'; +import type { TradingTransaction, TradingTransactionBuy, TradingType } from '@suite-common/trading'; import { useSelector } from 'src/hooks/suite'; import { useServerEnvironment } from 'src/hooks/wallet/trading/useServerEnviroment'; @@ -19,9 +19,9 @@ import { TradingUseDetailOutputProps, TradingUseDetailProps, } from 'src/types/trading/tradingDetail'; -import { Trade, TradeBuy } from 'src/types/wallet/tradingCommonTypes'; -const isBuyTrade = (trade: Trade): trade is TradeBuy => trade.tradeType === 'buy'; +const isBuyTrade = (trade: TradingTransaction): trade is TradingTransactionBuy => + trade.tradeType === 'buy'; const getTypedTrade = ({ trades, diff --git a/packages/suite/src/hooks/wallet/trading/useTradingWatchTrade.ts b/packages/suite/src/hooks/wallet/trading/useTradingWatchTrade.ts index 8e3489cdf48..9870d870b6c 100644 --- a/packages/suite/src/hooks/wallet/trading/useTradingWatchTrade.ts +++ b/packages/suite/src/hooks/wallet/trading/useTradingWatchTrade.ts @@ -11,22 +11,26 @@ import { WatchSellTradeResponse, } from 'invity-api'; -import { type TradingTradeStatusType, type TradingType, invityAPI } from '@suite-common/trading'; +import { + type TradingTradeStatusType, + type TradingTransaction, + 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 { TradingUseWatchTradeProps, TradingWatchTradeProps } from 'src/types/trading/trading'; -import { Trade, TradeType } from 'src/types/wallet/tradingCommonTypes'; -export const tradeFinalStatuses: Record = { +export const tradeFinalStatuses: Record = { buy: ['SUCCESS', 'ERROR', 'BLOCKED'] satisfies BuyTradeFinalStatus[], sell: ['SUCCESS', 'ERROR', 'BLOCKED', 'CANCELLED', 'REFUNDED'] satisfies SellTradeFinalStatus[], exchange: ['SUCCESS', 'ERROR', 'KYC'] satisfies ExchangeTradeFinalStatus[], }; -const shouldRefreshTrade = (trade: Trade | undefined) => +const shouldRefreshTrade = (trade: TradingTransaction | undefined) => trade && trade.data.status && !tradeFinalStatuses[trade.tradeType].includes(trade.data.status); const tradingWatchTrade = async ({ diff --git a/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts b/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts index 3a1c715b0ac..6f01e226a39 100644 --- a/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts +++ b/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts @@ -6,6 +6,8 @@ import { SellFiatTradeQuoteRequest, } from 'invity-api'; +import type { TradingTransactionBuy, TradingTransactionExchange } from '@suite-common/trading'; + import { STORAGE } from 'src/actions/suite/constants'; import { TRADING_BUY, @@ -23,7 +25,6 @@ import { } from 'src/reducers/wallet/__fixtures__/tradingReducerFixtures'; import { accounts } from 'src/reducers/wallet/__fixtures__/transactionConstants'; import { initialState, tradingReducer } from 'src/reducers/wallet/tradingReducer'; -import { TradeBuy, TradeExchange } from 'src/types/wallet/tradingCommonTypes'; describe('settings reducer', () => { it('test initial state', () => { @@ -288,7 +289,7 @@ describe('settings reducer', () => { }); it('SAVE_TRADE', () => { - const tradeBuy: TradeBuy = { + const tradeBuy: TradingTransactionBuy = { date: 'ddd', key: 'buy-key', tradeType: 'buy', @@ -313,7 +314,7 @@ describe('settings reducer', () => { accountType: 'normal', }, }; - const tradeExchange: TradeExchange = { + const tradeExchange: TradingTransactionExchange = { date: 'ddd', key: 'exchange-key', tradeType: 'exchange', diff --git a/packages/suite/src/reducers/wallet/tradingReducer.ts b/packages/suite/src/reducers/wallet/tradingReducer.ts index ab38f9f75ce..2a9f943d102 100644 --- a/packages/suite/src/reducers/wallet/tradingReducer.ts +++ b/packages/suite/src/reducers/wallet/tradingReducer.ts @@ -11,7 +11,11 @@ import type { SellFiatTradeQuoteRequest, } from 'invity-api'; -import type { TradingType } from '@suite-common/trading'; +import type { + TradingPaymentMethodListProps, + TradingTransaction, + TradingType, +} from '@suite-common/trading'; import type { AccountKey, PrecomposedTransactionFinal } from '@suite-common/wallet-types'; import type { FeeLevel } from '@trezor/connect'; @@ -26,10 +30,8 @@ import { import type { BuyInfo } from 'src/actions/wallet/tradingBuyActions'; import type { ExchangeInfo } from 'src/actions/wallet/tradingExchangeActions'; import type { SellInfo } from 'src/actions/wallet/tradingSellActions'; -import type { AppState, Action as SuiteAction } from 'src/types/suite'; -import { TradingPaymentMethodListProps } from 'src/types/trading/trading'; -import type { WalletAction } from 'src/types/wallet'; -import type { Trade } from 'src/types/wallet/tradingCommonTypes'; +import { AppState } from 'src/reducers/store'; +import { Action } from 'src/types/suite'; export interface ComposedTransactionInfo { composed?: Pick< @@ -86,7 +88,7 @@ export interface State { exchange: Exchange; sell: Sell; composedTransactionInfo: ComposedTransactionInfo; - trades: Trade[]; + trades: TradingTransaction[]; modalCryptoId: CryptoId | undefined; modalAccountKey: AccountKey | undefined; isLoading: boolean; @@ -139,10 +141,7 @@ export const initialState: State = { prefilledFromCryptoId: undefined, }; -export const tradingReducer = ( - state: State = initialState, - action: WalletAction | SuiteAction, -): State => +export const tradingReducer = (state: State = initialState, action: Action): State => produce(state, draft => { switch (action.type) { case STORAGE.LOAD: diff --git a/packages/suite/src/storage/definitions.ts b/packages/suite/src/storage/definitions.ts index 7ce6ae0719b..59ec074904f 100644 --- a/packages/suite/src/storage/definitions.ts +++ b/packages/suite/src/storage/definitions.ts @@ -6,6 +6,7 @@ import { AnalyticsState } from '@suite-common/analytics'; import type { MessageState } from '@suite-common/message-system'; import type { DeviceWithEmptyPath, MessageSystem } from '@suite-common/suite-types'; import { SimpleTokenStructure } from '@suite-common/token-definitions'; +import type { TradingTransaction } from '@suite-common/trading'; import { NetworkSymbol } from '@suite-common/wallet-config'; import type { BackendSettings, @@ -18,8 +19,7 @@ import type { StorageUpdateMessage } from '@trezor/suite-storage'; import type { SuiteState } from 'src/reducers/suite/suiteReducer'; import type { MetadataState } from 'src/types/suite/metadata'; import type { Account, Discovery, WalletAccountTransaction } from 'src/types/wallet'; -import type { CoinjoinAccount, CoinjoinDebugSettings } from 'src/types/wallet/coinjoin'; -import type { Trade } from 'src/types/wallet/tradingCommonTypes'; +import { CoinjoinAccount, CoinjoinDebugSettings } from 'src/types/wallet/coinjoin'; import { GraphData } from '../types/wallet/graph'; @@ -105,7 +105,7 @@ export interface SuiteDBSchema extends DBSchema { }; tradingTrades: { key: string; - value: Trade; + value: TradingTransaction; }; metadata: { key: 'state'; diff --git a/packages/suite/src/storage/migrations/trading/migrationCoinmarketToTrading.ts b/packages/suite/src/storage/migrations/trading/migrationCoinmarketToTrading.ts index c176d57da35..877ab6b4cdf 100644 --- a/packages/suite/src/storage/migrations/trading/migrationCoinmarketToTrading.ts +++ b/packages/suite/src/storage/migrations/trading/migrationCoinmarketToTrading.ts @@ -1,7 +1,6 @@ +import type { TradingTransaction } from '@suite-common/trading'; import type { OnUpgradeFunc } from '@trezor/suite-storage'; -import { Trade } from 'src/types/wallet/tradingCommonTypes'; - import type { SuiteDBSchema } from '../../definitions'; export const migrationCoinmarketToTrading: OnUpgradeFunc = async ( @@ -23,7 +22,7 @@ export const migrationCoinmarketToTrading: OnUpgradeFunc = async const newTradesStore = db.createObjectStore(newStoreName, { keyPath: trades.keyPath }); while (tradesCursor) { - const trade = tradesCursor.value as Trade; + const trade = tradesCursor.value as TradingTransaction; await tradesCursor.delete(); await newTradesStore.add(trade); diff --git a/packages/suite/src/types/trading/trading.ts b/packages/suite/src/types/trading/trading.ts index cf4a3f4f419..922165141ef 100644 --- a/packages/suite/src/types/trading/trading.ts +++ b/packages/suite/src/types/trading/trading.ts @@ -1,5 +1,4 @@ import { - BuyCryptoPaymentMethod, BuyProviderInfo, BuyTrade, CryptoId, @@ -16,6 +15,10 @@ import type { TradingExchangeType, TradingPaymentMethodType, TradingSellType, + TradingTransaction, + TradingTransactionBuy, + TradingTransactionExchange, + TradingTransactionSell, TradingType, } from '@suite-common/trading'; import { AccountType, NetworkSymbolExtended } from '@suite-common/wallet-config'; @@ -32,14 +35,6 @@ import type { SellInfo } from 'src/actions/wallet/tradingSellActions'; import { GetDefaultAccountLabelParams } from 'src/hooks/suite/useDefaultAccountLabel'; import { State } from 'src/reducers/wallet/tradingReducer'; import { ExtendedMessageDescriptor, TrezorDevice } from 'src/types/suite'; -import type { - Option, - Trade, - TradeBuy, - TradeExchange, - TradeSell, - TradeType, -} from 'src/types/wallet/tradingCommonTypes'; type TradingPageType = 'form' | 'offers' | 'confirm'; @@ -70,9 +65,9 @@ export type TradingTradeSellExchangeType = Exclude; export type TradingTradeBuyExchangeType = Exclude; export type TradingTradeMapProps = { - buy: TradeBuy; - sell: TradeSell; - exchange: TradeExchange; + buy: TradingTransactionBuy; + sell: TradingTransactionSell; + exchange: TradingTransactionExchange; }; export type TradingTradeDetailBuySellType = BuyTrade | SellFiatTrade; @@ -84,14 +79,14 @@ export type TradingTradeInfoMapProps = { }; export interface TradingGetTypedTradeProps { - trades: Trade[]; + trades: TradingTransaction[]; tradeType: TradingType; transactionId: string | undefined; } export interface TradingGetDetailDataProps { trading: State; - tradeType: TradeType; + tradeType: TradingType; } export interface TradingGetTypedInfoTradeProps { @@ -112,13 +107,6 @@ export interface TradingWatchTradeProps { removeDraft: (key: string) => void; } -export type TradingPaymentMethodProps = BuyCryptoPaymentMethod | ''; - -export interface TradingPaymentMethodListProps extends Option { - value: TradingPaymentMethodProps; - label: string; -} - export interface TradingCryptoListProps { value: CryptoId; label: string; // token shortcut @@ -191,8 +179,6 @@ export interface TradingAccountsOptionsGroupProps { options: TradingAccountOptionsGroupOptionProps[]; } -export type TradingFiatCurrenciesProps = Map; - export interface TradingGetAmountLabelsProps { type: TradingType; amountInCrypto: boolean; diff --git a/packages/suite/src/types/trading/tradingDetail.ts b/packages/suite/src/types/trading/tradingDetail.ts index 73bd5c1778c..c855eb3076e 100644 --- a/packages/suite/src/types/trading/tradingDetail.ts +++ b/packages/suite/src/types/trading/tradingDetail.ts @@ -4,7 +4,6 @@ import type { SelectedAccountLoaded } from '@suite-common/wallet-types'; import type { TradingTradeCommonProps } from 'src/reducers/wallet/tradingReducer'; import { TradingTradeInfoMapProps, TradingTradeMapProps } from 'src/types/trading/trading'; import type { Account } from 'src/types/wallet'; -import type { TradeType } from 'src/types/wallet/tradingCommonTypes'; export interface TradingDetailContextValues extends TradingTradeCommonProps { account: Account; @@ -20,7 +19,7 @@ export interface TradingGetDetailDataOutputProps { export interface TradingUseDetailProps { selectedAccount: SelectedAccountLoaded; - tradeType: TradeType; + tradeType: TradingType; } export interface TradingUseDetailOutputProps { diff --git a/packages/suite/src/types/trading/tradingForm.ts b/packages/suite/src/types/trading/tradingForm.ts index 9daeddbe516..218075d0d7c 100644 --- a/packages/suite/src/types/trading/tradingForm.ts +++ b/packages/suite/src/types/trading/tradingForm.ts @@ -14,10 +14,15 @@ import type { import type { TradingBuyType, TradingExchangeType, + TradingPaymentMethodListProps, + TradingPaymentMethodProps, TradingPaymentMethodType, TradingSellType, TradingTradeMapProps, TradingTradeType, + TradingTransactionBuy, + TradingTransactionExchange, + TradingTransactionSell, TradingType, } from '@suite-common/trading'; import { Network } from '@suite-common/wallet-config'; @@ -58,13 +63,11 @@ import { TradingCryptoSelectItemProps, TradingGetCryptoQuoteAmountProps, TradingGetProvidersInfoProps, - TradingPaymentMethodListProps, - TradingPaymentMethodProps, TradingTradeSellExchangeType, } from 'src/types/trading/trading'; import type { Account } from 'src/types/wallet'; import { SendContextValues } from 'src/types/wallet/sendForm'; -import { Option, TradeBuy, TradeExchange, TradeSell } from 'src/types/wallet/tradingCommonTypes'; +import { Option } from 'src/types/wallet/tradingCommonTypes'; import { AmountLimitProps, CryptoAmountLimitProps } from 'src/utils/suite/validation'; export interface TradingBuyFormProps { @@ -181,7 +184,7 @@ export interface TradingBuyFormContextProps quotesRequest: AppState['wallet']['trading']['buy']['quotesRequest']; quotes: AppState['wallet']['trading']['buy']['quotes']; selectedQuote: BuyTrade | undefined; - trade?: TradeBuy; + trade?: TradingTransactionBuy; addressVerified: string | undefined; // form - additional helpers for form form: { @@ -208,7 +211,7 @@ export interface TradingSellFormContextProps feeInfo: FeeInfo; quotes: AppState['wallet']['trading']['sell']['quotes']; selectedQuote?: SellFiatTrade; - trade?: TradeSell; + trade?: TradingTransactionSell; suiteReceiveAccounts?: AppState['wallet']['accounts']; sellStep: TradingSellStepType; // form - additional helpers for form @@ -240,7 +243,7 @@ export interface TradingExchangeFormContextProps }; selectedQuote?: ExchangeTrade; - trade?: TradeExchange; + trade?: TradingTransactionExchange; suiteReceiveAccounts?: AccountsState; exchangeStep: TradingExchangeStepType; feeInfo: FeeInfo; diff --git a/packages/suite/src/types/wallet/tradingCommonTypes.ts b/packages/suite/src/types/wallet/tradingCommonTypes.ts index a75a6dd83d2..ea426926ed8 100644 --- a/packages/suite/src/types/wallet/tradingCommonTypes.ts +++ b/packages/suite/src/types/wallet/tradingCommonTypes.ts @@ -1,25 +1,7 @@ -import type { BuyTrade, ExchangeTrade, FiatCurrencyCode, SellFiatTrade } from 'invity-api'; +import type { FiatCurrencyCode } from 'invity-api'; import type { FlagProps } from '@trezor/components'; -import type { Account } from 'src/types/wallet'; - -type CommonTrade = { - date: string; - key?: string; - account: { - descriptor: Account['descriptor']; - symbol: Account['symbol']; - accountType: Account['accountType']; - accountIndex: Account['index']; - }; -}; -export type TradeType = 'buy' | 'sell' | 'exchange'; -export type TradeBuy = CommonTrade & { tradeType: 'buy'; data: BuyTrade }; -export type TradeSell = CommonTrade & { tradeType: 'sell'; data: SellFiatTrade }; -export type TradeExchange = CommonTrade & { tradeType: 'exchange'; data: ExchangeTrade }; -export type Trade = TradeBuy | TradeSell | TradeExchange; - export type Option = { value: string; label: string }; export type CountryOption = { value: FlagProps['country']; label: string }; export type DefaultCountryOption = { value: string; label: string }; diff --git a/packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputPaymentMethod.tsx b/packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputPaymentMethod.tsx index 9f0d5d59065..8d6c79a21b5 100644 --- a/packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputPaymentMethod.tsx +++ b/packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputPaymentMethod.tsx @@ -1,11 +1,12 @@ import { Control, Controller } from 'react-hook-form'; +import type { TradingPaymentMethodListProps } from '@suite-common/trading'; import { Select } from '@trezor/components'; import { Translation } from 'src/components/suite'; import { FORM_PAYMENT_METHOD_SELECT } from 'src/constants/wallet/trading/form'; import { useTradingFormContext } from 'src/hooks/wallet/trading/form/useTradingCommonForm'; -import { TradingPaymentMethodListProps, TradingTradeBuySellType } from 'src/types/trading/trading'; +import { TradingTradeBuySellType } from 'src/types/trading/trading'; import { TradingBuySellFormProps, TradingFormInputDefaultProps, diff --git a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts.tsx b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts.tsx index 27735eb87bb..fa31743a9e0 100644 --- a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts.tsx +++ b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts.tsx @@ -1,9 +1,9 @@ +import type { TradingTransaction } from '@suite-common/trading'; import { Icon, Row, iconSizes } from '@trezor/components'; import { spacings } from '@trezor/theme'; import { FormattedCryptoAmount, HiddenPlaceholder } from 'src/components/suite'; import { useTradingInfo } from 'src/hooks/wallet/trading/useTradingInfo'; -import { Trade } from 'src/types/wallet/tradingCommonTypes'; import { TradingTestWrapper } from 'src/views/wallet/trading'; const Arrow = () => ( @@ -13,7 +13,7 @@ const Arrow = () => ( ); interface TradingTransactionAmountsProps { - trade: Trade; + trade: TradingTransaction; } export const TradingTransactionAmounts = ({ trade }: TradingTransactionAmountsProps) => { diff --git a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionInfo.tsx b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionInfo.tsx index d8c7f9b0fd4..1667947dc69 100644 --- a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionInfo.tsx +++ b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionInfo.tsx @@ -1,18 +1,18 @@ +import type { TradingTransaction, TradingType } from '@suite-common/trading'; import { InfoSegments } from '@trezor/components'; import { spacings } from '@trezor/theme'; import { FormattedDate } from 'src/components/suite'; import { useTranslation } from 'src/hooks/suite'; import { ExtendedMessageDescriptor } from 'src/types/suite'; -import { Trade, TradeType } from 'src/types/wallet/tradingCommonTypes'; import { TradingTransactionStatus } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionStatus'; interface TradingTransactionInfoProps { - trade: Trade; + trade: TradingTransaction; } const translationKeys: Record< - TradeType, + TradingType, Extract > = { buy: 'TR_BUY', diff --git a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionStatus.tsx b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionStatus.tsx index 682ddfa7a8e..f9cb7306a73 100644 --- a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionStatus.tsx +++ b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionStatus.tsx @@ -1,10 +1,10 @@ import { BuyTradeStatus, ExchangeTradeStatus, SellTradeStatus } from 'invity-api'; import { DefaultTheme, useTheme } from 'styled-components'; +import type { TradingTransaction } from '@suite-common/trading'; import { Icon, Row, Text } from '@trezor/components'; import { Translation } from 'src/components/suite'; -import { Trade } from 'src/types/wallet/tradingCommonTypes'; import { getStatusMessage as getBuyStatusMessage } from 'src/utils/wallet/trading/buyUtils'; import { getStatusMessage as getExchangeStatusMessage } from 'src/utils/wallet/trading/exchangeUtils'; import { getStatusMessage as getSellStatusMessage } from 'src/utils/wallet/trading/sellUtils'; @@ -106,7 +106,7 @@ type StatusData = | ReturnType | ReturnType; -const getData = (trade: Trade, theme: DefaultTheme): StatusData | null => { +const getData = (trade: TradingTransaction, theme: DefaultTheme): StatusData | null => { if (!trade.data.status) return null; switch (trade.tradeType) { @@ -120,7 +120,7 @@ const getData = (trade: Trade, theme: DefaultTheme): StatusData | null => { }; interface TradingTransactionStatusProps { - trade: Trade; + trade: TradingTransaction; } export const TradingTransactionStatus = ({ trade }: TradingTransactionStatusProps) => { diff --git a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionExchange.tsx b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionExchange.tsx index 1f8bd9328b8..de7e3c5ff6a 100644 --- a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionExchange.tsx +++ b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionExchange.tsx @@ -1,5 +1,6 @@ import { ExchangeProviderInfo } from 'invity-api'; +import type { TradingTransactionExchange as TradingTxExchange } from '@suite-common/trading'; import { Button } from '@trezor/components'; import { goto } from 'src/actions/suite/routerActions'; @@ -8,7 +9,6 @@ import { Translation } from 'src/components/suite'; import { useDispatch } from 'src/hooks/suite'; import { useTradingWatchTrade } from 'src/hooks/wallet/trading/useTradingWatchTrade'; import { Account } from 'src/types/wallet'; -import { TradeExchange } from 'src/types/wallet/tradingCommonTypes'; import { TradingTransactionAmounts } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts'; import { TradingTransactionContainer } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionContainer'; import { TradingTransactionId } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionId'; @@ -16,7 +16,7 @@ import { TradingTransactionInfo } from 'src/views/wallet/trading/common/TradingT import { TradingTransactionProvider } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionProvider'; interface TradingTransactionExchangeProps { - trade: TradeExchange; + trade: TradingTxExchange; account: Account; providers?: { [name: string]: ExchangeProviderInfo; diff --git a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsBuy.tsx b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsBuy.tsx index 1f77c559183..54af902c28c 100644 --- a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsBuy.tsx +++ b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsBuy.tsx @@ -1,5 +1,6 @@ import { BuyProviderInfo } from 'invity-api'; +import type { TradingTransactionBuy as TradingTxBuy } from '@suite-common/trading'; import { Button } from '@trezor/components'; import { saveTransactionDetailId } from 'src/actions/wallet/tradingBuyActions'; @@ -8,7 +9,6 @@ import { useDispatch } from 'src/hooks/suite'; import { useTradingWatchTrade } from 'src/hooks/wallet/trading/useTradingWatchTrade'; import { useTradingNavigation } from 'src/hooks/wallet/useTradingNavigation'; import { Account } from 'src/types/wallet'; -import { TradeBuy } from 'src/types/wallet/tradingCommonTypes'; import { TradingTransactionAmounts } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts'; import { TradingTransactionContainer } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionContainer'; import { TradingTransactionId } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionId'; @@ -16,7 +16,7 @@ import { TradingTransactionInfo } from 'src/views/wallet/trading/common/TradingT import { TradingTransactionProvider } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionProvider'; interface TradingTransactionBuyProps { - trade: TradeBuy; + trade: TradingTxBuy; account: Account; providers?: { [name: string]: BuyProviderInfo; diff --git a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsSell.tsx b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsSell.tsx index 7f4c78c631b..38dd9e8450e 100644 --- a/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsSell.tsx +++ b/packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransactionsSell.tsx @@ -1,5 +1,6 @@ import { SellProviderInfo } from 'invity-api'; +import type { TradingTransactionSell as TradingTxSell } from '@suite-common/trading'; import { Button } from '@trezor/components'; import { goto } from 'src/actions/suite/routerActions'; @@ -13,7 +14,6 @@ import { Translation } from 'src/components/suite'; import { useDispatch, useSelector } from 'src/hooks/suite'; import { useTradingWatchTrade } from 'src/hooks/wallet/trading/useTradingWatchTrade'; import { Account } from 'src/types/wallet'; -import { TradeSell } from 'src/types/wallet/tradingCommonTypes'; import { TradingTransactionId } from 'src/views/wallet/trading/common'; import { TradingTransactionAmounts } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts'; import { TradingTransactionContainer } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionContainer'; @@ -21,7 +21,7 @@ import { TradingTransactionInfo } from 'src/views/wallet/trading/common/TradingT import { TradingTransactionProvider } from 'src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionProvider'; interface TradingTransactionSellProps { - trade: TradeSell; + trade: TradingTxSell; account: Account; providers?: { [name: string]: SellProviderInfo; diff --git a/suite-common/trading/src/types.ts b/suite-common/trading/src/types.ts index 8c369595bb0..bd1f905655e 100644 --- a/suite-common/trading/src/types.ts +++ b/suite-common/trading/src/types.ts @@ -5,6 +5,7 @@ import type { CryptoId, ExchangeTrade, ExchangeTradeStatus, + FiatCurrencyCode, SellCryptoPaymentMethod, SellFiatTrade, SellTradeStatus, @@ -13,6 +14,8 @@ import type { WatchSellTradeResponse, } from 'invity-api'; +import type { Account } from '@suite-common/wallet-types'; + export type InvityServerEnvironment = 'production' | 'staging' | 'dev' | 'localhost'; export type InvityServers = Record; @@ -52,3 +55,34 @@ export type TradingParsedCryptoIdProps = { networkId: CryptoId; contractAddress: string | undefined; }; + +export type TradingFiatCurrenciesProps = Map; +export type TradingPaymentMethodProps = BuyCryptoPaymentMethod | ''; +export type TradingPaymentMethodListProps = { + value: TradingPaymentMethodProps; + label: string; +}; + +type TradingCommonTransaction = { + date: string; + key?: string; + account: { + descriptor: Account['descriptor']; + symbol: Account['symbol']; + accountType: Account['accountType']; + accountIndex: Account['index']; + }; +}; +export type TradingTransactionBuy = TradingCommonTransaction & { tradeType: 'buy'; data: BuyTrade }; +export type TradingTransactionSell = TradingCommonTransaction & { + tradeType: 'sell'; + data: SellFiatTrade; +}; +export type TradingTransactionExchange = TradingCommonTransaction & { + tradeType: 'exchange'; + data: ExchangeTrade; +}; +export type TradingTransaction = + | TradingTransactionBuy + | TradingTransactionSell + | TradingTransactionExchange;