Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1 min timeout for fetching new token info #16226

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 14 additions & 33 deletions packages/suite/src/actions/wallet/tokenActions.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
import { TokenInfo } from '@trezor/connect';
import * as accountUtils from '@suite-common/wallet-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import { accountsActions, updateFiatRatesThunk } from '@suite-common/wallet-core';
import { Timestamp, TokenAddress } from '@suite-common/wallet-types';
import { FiatCurrencyCode } from '@suite-common/suite-config';
import { accountsActions } from '@suite-common/wallet-core';

import { Dispatch } from 'src/types/suite';
import { Account } from 'src/types/wallet';

export const addToken =
(account: Account, tokenInfo: TokenInfo[], localCurrency: FiatCurrencyCode) =>
(dispatch: Dispatch) => {
dispatch(
accountsActions.updateAccount({
...account,
tokens: (account.tokens || []).concat(accountUtils.enhanceTokens(tokenInfo)),
}),
);
export const addToken = (account: Account, tokenInfo: TokenInfo[]) => (dispatch: Dispatch) => {
dispatch(
accountsActions.updateAccount({
...account,
tokens: (account.tokens || []).concat(accountUtils.enhanceTokens(tokenInfo)),
}),
);

dispatch(
updateFiatRatesThunk({
tickers: [
{
symbol: account.symbol,
tokenAddress: tokenInfo[0].contract as TokenAddress,
},
],
localCurrency,
rateType: 'current',
fetchAttemptTimestamp: Date.now() as Timestamp,
forceFetchToken: true,
}),
);

dispatch(
notificationsActions.addToast({
type: 'add-token-success',
}),
);
};
dispatch(
notificationsActions.addToast({
type: 'add-token-success',
}),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Translation } from 'src/components/suite/Translation';
import { useDispatch, useSelector, useTranslation } from 'src/hooks/suite';
import { Account } from 'src/types/wallet';
import { selectSelectedAccount } from 'src/reducers/wallet/selectedAccountReducer';
import { selectLocalCurrency } from 'src/reducers/wallet/settingsReducer';

interface AddTokenModalProps {
onCancel: () => void;
Expand All @@ -23,7 +22,6 @@ export const AddTokenModal = ({ onCancel }: AddTokenModalProps) => {
const [isFetching, setIsFetching] = useState(false);
const [error, setError] = useState<string | null>(null);
const account = useSelector(selectSelectedAccount);
const localCurrency = useSelector(selectLocalCurrency);
const dispatch = useDispatch();
const { translationString } = useTranslation();

Expand Down Expand Up @@ -99,7 +97,7 @@ export const AddTokenModal = ({ onCancel }: AddTokenModalProps) => {

const handleAddTokenButtonClick = () => {
if (tokenInfo) {
dispatch(addToken(account, tokenInfo, localCurrency));
dispatch(addToken(account, tokenInfo));
onCancel();

analytics.report({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { fetchAllTransactionsForAccountThunk } from '../transactions/transaction

export const prepareFiatRatesMiddleware = createMiddlewareWithExtraDeps(
(action, { dispatch, extra, next, getState }) => {
next(action); //next must be at the beginning, othervise tickers are not going to be updated and fiat rates wont fetch (the user will have to wait for 1m timeout)
const {
actions: { setWalletSettingsLocalCurrency },
selectors: { selectLocalCurrency },
Expand Down Expand Up @@ -126,6 +127,6 @@ export const prepareFiatRatesMiddleware = createMiddlewareWithExtraDeps(
);
}

return next(action);
return action;
},
);
Loading