Skip to content

Commit

Permalink
chore(token-definitions): move definitions to root state
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed May 7, 2024
1 parent 9b60ede commit bf6bcd7
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 18 deletions.
3 changes: 3 additions & 0 deletions packages/suite/src/reducers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import type { PreloadStoreAction } from 'src/support/suite/preloadStore';

import { desktopReducer } from './desktop';
import { extraDependencies } from '../support/extraDependencies';
import { prepareTokenDefinitionsReducer } from '@suite-common/token-definitions';

const firmwareReducer = prepareFirmwareReducer(extraDependencies);
const tokenDefinitionsReducer = prepareTokenDefinitionsReducer(extraDependencies);

const rootReducer = combineReducers({
...suiteReducers,
Expand All @@ -37,6 +39,7 @@ const rootReducer = combineReducers({
firmware: firmwareReducer,
backup: backupReducers,
desktop: desktopReducer,
tokenDefinitions: tokenDefinitionsReducer,
});

export type AppState = ReturnType<typeof rootReducer>;
Expand Down
3 changes: 0 additions & 3 deletions packages/suite/src/reducers/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import formDraftReducer from './formDraftReducer';
import cardanoStakingReducer from './cardanoStakingReducer';
import pollingReducer from './pollingReducer';
import { coinjoinReducer } from './coinjoinReducer';
import { prepareTokenDefinitionsReducer } from '@suite-common/token-definitions';

export const transactionsReducer = prepareTransactionsReducer(extraDependencies);
export const accountsReducer = prepareAccountsReducer(extraDependencies);
export const blockchainReducer = prepareBlockchainReducer(extraDependencies);
export const fiatRatesReducer = prepareFiatRatesReducer(extraDependencies);
export const discoveryReducer = prepareDiscoveryReducer(extraDependencies);
export const tokenDefinitionsReducer = prepareTokenDefinitionsReducer(extraDependencies);
export const stakeReducer = prepareStakeReducer(extraDependencies);
export const sendFormReducer = prepareSendFormReducer(extraDependencies);

Expand All @@ -52,7 +50,6 @@ const WalletReducers = combineReducers({
cardanoStaking: cardanoStakingReducer,
pollings: pollingReducer,
coinjoin: coinjoinReducer,
tokenDefinitions: tokenDefinitionsReducer,
stake: stakeReducer,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/suite/src/utils/suite/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { fromWei, toHex, toWei } from 'web3-utils';
import { getEthereumEstimateFeeParams, sanitizeHex } from '@suite-common/wallet-utils';
import TrezorConnect, { EthereumTransaction } from '@trezor/connect';
import BigNumber from 'bignumber.js';
import { ValidatorsQueue } from '@suite-common/wallet-core/src/stake/stakeTypes';
import { ValidatorsQueue } from '@suite-common/wallet-core';

// Gas reserve ensuring txs are processed
const GAS_RESERVE = 220000;
Expand Down
12 changes: 5 additions & 7 deletions suite-common/token-definitions/src/tokenDefinitionsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import { isTokenDefinitionKnown } from './utils';
export const selectNetworkTokenDefinitions = (
state: TokenDefinitionsRootState,
networkSymbol: NetworkSymbol,
) => state.wallet.tokenDefinitions?.[networkSymbol];
) => state.tokenDefinitions?.[networkSymbol];

export const selectCoinDefinitions = (
state: TokenDefinitionsRootState,
networkSymbol: NetworkSymbol,
) => state.wallet.tokenDefinitions?.[networkSymbol]?.coin;
) => state.tokenDefinitions?.[networkSymbol]?.coin;

export const selectNftDefinitions = (
state: TokenDefinitionsRootState,
networkSymbol: NetworkSymbol,
) => state.wallet.tokenDefinitions?.[networkSymbol]?.nft;
) => state.tokenDefinitions?.[networkSymbol]?.nft;

export const selectCoinDefinition = (
state: TokenDefinitionsRootState,
networkSymbol: NetworkSymbol,
contractAddress: string,
) =>
isTokenDefinitionKnown(
state.wallet.tokenDefinitions?.[networkSymbol]?.coin?.data,
state.tokenDefinitions?.[networkSymbol]?.coin?.data,
networkSymbol,
contractAddress,
);
Expand All @@ -43,9 +43,7 @@ export const selectFilterKnownTokens = (
state: TokenDefinitionsRootState,
networkSymbol: NetworkSymbol,
tokens: TokenInfo[],
) => {
return tokens.filter(token => selectCoinDefinition(state, networkSymbol, token.contract));
};
) => tokens.filter(token => selectCoinDefinition(state, networkSymbol, token.contract));

export const selectValidTokensByDeviceStateAndNetworkSymbol = (
state: TokenDefinitionsRootState,
Expand Down
2 changes: 1 addition & 1 deletion suite-common/token-definitions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type TokenDefinitionsState = {
[key in NetworkSymbol]?: TokenDefinitions;
};

export type TokenDefinitionsRootState = { wallet: { tokenDefinitions: TokenDefinitionsState } };
export type TokenDefinitionsRootState = { tokenDefinitions: TokenDefinitionsState };

type TokenDefinition = {
error: boolean;
Expand Down
2 changes: 1 addition & 1 deletion suite-common/wallet-core/src/fiat-rates/fiatRatesThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { Account, TickerId, RateType, Timestamp } from '@suite-common/wallet-typ
import { isTestnet } from '@suite-common/wallet-utils';
import { AccountTransaction } from '@trezor/connect';
import { getNetworkFeatures } from '@suite-common/wallet-config';
import { selectIsSpecificCoinDefinitionKnown } from '@suite-common/token-definitions/src/tokenDefinitionsSelectors';

import { FIAT_RATES_MODULE_PREFIX, REFETCH_INTERVAL } from './fiatRatesConstants';
import { selectTickersToBeUpdated, selectTransactionsWithMissingRates } from './fiatRatesSelectors';
import { transactionsActions } from '../transactions/transactionsActions';
import { selectIsSpecificCoinDefinitionKnown } from '@suite-common/token-definitions/src/tokenDefinitionsSelectors';
import { selectIsElectrumBackendSelected } from '../blockchain/blockchainSelectors';

type UpdateTxsFiatRatesThunkPayload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
} from '@suite-common/wallet-utils';
import { isClaimTx, isStakeTx, isStakeTypeTx, isUnstakeTx } from '@suite-common/suite-utils';
import { createReducerWithExtraDeps } from '@suite-common/redux-utils';
import { selectNetworkTokenDefinitions } from '@suite-common/token-definitions/src/tokenDefinitionsSelectors';
import { TokenDefinitionsRootState } from '@suite-common/token-definitions';

import { accountsActions } from '../accounts/accountsActions';
import { transactionsActions } from './transactionsActions';
import {
selectBlockchainHeightBySymbol,
BlockchainRootState,
} from '../blockchain/blockchainReducer';
import { selectNetworkTokenDefinitions } from '@suite-common/token-definitions/src/tokenDefinitionsSelectors';
import { TokenDefinitionsRootState } from '@suite-common/token-definitions';

export interface TransactionsState {
isLoading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import TrezorConnect from '@trezor/connect';
import { blockbookUtils } from '@trezor/blockchain-link-utils';
import { Transaction } from '@trezor/blockchain-link-types/src/blockbook';
import { createThunk } from '@suite-common/redux-utils';
import { selectNetworkTokenDefinitions } from '@suite-common/token-definitions/src/tokenDefinitionsSelectors';

import { accountsActions } from '../accounts/accountsActions';
import { selectTransactions } from './transactionsReducer';
import { TRANSACTIONS_MODULE_PREFIX, transactionsActions } from './transactionsActions';
import { selectAccountByKey, selectAccounts } from '../accounts/accountsReducer';
import { selectBlockchainHeightBySymbol } from '../blockchain/blockchainReducer';
import { selectNetworkTokenDefinitions } from '@suite-common/token-definitions/src/tokenDefinitionsSelectors';

/**
* Replace existing transaction in the reducer (RBF)
Expand Down
2 changes: 1 addition & 1 deletion suite-common/wallet-utils/src/exportTransactionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { trezorLogo } from '@suite-common/suite-constants';
import { TransactionTarget } from '@trezor/connect';
import { Network } from '@suite-common/wallet-config';
import { ExportFileType, WalletAccountTransaction } from '@suite-common/wallet-types';
import { TokenDefinitions } from '@suite-common/token-definitions';

import { formatNetworkAmount, formatAmount } from './accountUtils';
import { getNftTokenId, isNftTokenTransfer } from './transactionUtils';
import { localizeNumber } from './localizeNumberUtils';
import { getIsPhishingTransaction } from './antiFraud';
import { TokenDefinitions } from '@suite-common/token-definitions';

type AccountTransactionForExports = Omit<WalletAccountTransaction, 'targets'> & {
targets: (TransactionTarget & { metadataLabel?: string })[];
Expand Down
3 changes: 3 additions & 0 deletions suite-native/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
{
"path": "../../suite-common/suite-constants"
},
{
"path": "../../suite-common/token-definitions"
},
{
"path": "../../suite-common/wallet-core"
},
Expand Down
2 changes: 1 addition & 1 deletion suite-native/state/src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const prepareRootReducers = async () => {
fiat: fiatRatesReducer,
transactions: transactionsReducer,
discovery: discoveryReducer,
tokenDefinitions: tokenDefinitionsReducer,
fees: feesReducer,
});

Expand Down Expand Up @@ -130,5 +129,6 @@ export const prepareRootReducers = async () => {
notifications: notificationsReducer,
discoveryConfig: discoveryConfigPersistedReducer,
messageSystem: messageSystemPersistedReducer,
tokenDefinitions: tokenDefinitionsReducer,
});
};
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8937,6 +8937,7 @@ __metadata:
"@suite-common/message-system": "workspace:*"
"@suite-common/redux-utils": "workspace:*"
"@suite-common/suite-constants": "workspace:*"
"@suite-common/token-definitions": "workspace:*"
"@suite-common/wallet-core": "workspace:*"
"@suite-native/accounts": "workspace:*"
"@suite-native/alerts": "workspace:*"
Expand Down

0 comments on commit bf6bcd7

Please sign in to comment.