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(extension): limit stored tx history size [LW-12227] #1696

Merged
merged 1 commit into from
Feb 6, 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
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
Loading