Skip to content

Commit

Permalink
fix(extension): limit stored tx history size
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Czeglik <[email protected]>
Co-authored-by: Martynas Kazlauskas <[email protected]>
  • Loading branch information
3 people committed Feb 6, 2025
1 parent 91c5918 commit f9d74c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { migrateCollectionStore, migrateWalletStores, shouldAttemptWalletStoresM
import { isLacePopupOpen$, createUserSessionTracker, isLaceTabActive$ } from './session';
import { TrackerSubject } from '@cardano-sdk/util-rxjs';
import { ExperimentName, FeatureFlags } from '../types/feature-flags';
import { TX_HISTORY_LIMIT_SIZE } from '@utils/constants';

export const dAppConnectorActivity$ = new Subject<void>();
const pollController$ = new TrackerSubject(
Expand Down Expand Up @@ -335,6 +336,13 @@ const storesFactory: StoresFactory = {
// and we are sure that it's working well
}
}

const transactions = await firstValueFrom(extensionStores.transactions.getAll().pipe(defaultIfEmpty([])));

if (transactions.length > TX_HISTORY_LIMIT_SIZE) {
await firstValueFrom(extensionStores.transactions.setAll(transactions.slice(-TX_HISTORY_LIMIT_SIZE)));
}

return extensionStores;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { rewardHistoryTransformer } from '@src/views/browser-view/features/activ
import { isKeyHashAddress } from '@cardano-sdk/wallet';
import { ObservableWalletState } from '@hooks/useWalletState';
import { IBlockchainProvider } from './blockchain-provider-slice';
import { TX_HISTORY_LIMIT_SIZE } from '@utils/constants';

export interface FetchWalletActivitiesProps {
fiatCurrency: CurrencyInfo;
Expand Down Expand Up @@ -140,8 +141,7 @@ const mapWalletActivities = memoize(
Pick<IBlockchainProvider, 'inputResolver'> &
Pick<WalletInfoSlice, 'isSharedWallet'>
) => {
const TX_LIMIT_SIZE = 10;
const txHistorySlice = transactions.history.slice(-TX_LIMIT_SIZE);
const txHistorySlice = transactions.history.slice(-TX_HISTORY_LIMIT_SIZE);
const epochRewardsMapper = (earnedEpoch: Wallet.Cardano.EpochNo, rewards: Reward[]): ExtendedActivityProps => {
const REWARD_SPENDABLE_DELAY_EPOCHS = 2;
const spendableEpoch = (earnedEpoch + REWARD_SPENDABLE_DELAY_EPOCHS) as Wallet.Cardano.EpochNo;
Expand Down
2 changes: 2 additions & 0 deletions apps/browser-extension-wallet/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const CARDANO_COIN_SYMBOL: { [key in Wallet.Cardano.NetworkId]: ADASymbol
[Wallet.Cardano.NetworkId.Testnet]: 'tADA'
};

export const TX_HISTORY_LIMIT_SIZE = 10;

export const cardanoCoin: Wallet.CoinId = {
id: '1',
name: 'Cardano',
Expand Down

0 comments on commit f9d74c7

Please sign in to comment.