Skip to content

Commit e273aa9

Browse files
fix: [LW-10267] staking persistence local storage (#1064)
* fix(extension): add a fallback for stakingBrowserPreferencesPersistence localstorage object * fix: lw-10267 add migration to fix broken staking center * refactor(staking,extension): expose DEFAULT_STAKING_BROWSER_PREFERENCES and apply changes to popup --------- Co-authored-by: przemyslaw.wlodek <przem.wlodek.github@gmail.com>
1 parent f37d85e commit e273aa9

File tree

10 files changed

+53
-17
lines changed

10 files changed

+53
-17
lines changed

apps/browser-extension-wallet/src/features/delegation/components/MultiDelegationStakingPopup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OutsideHandlesProvider, StakingPopup } from '@lace/staking';
1+
import { DEFAULT_STAKING_BROWSER_PREFERENCES, OutsideHandlesProvider, StakingPopup } from '@lace/staking';
22
import React, { useCallback, useEffect } from 'react';
33
import {
44
useAnalyticsContext,
@@ -89,7 +89,7 @@ export const MultiDelegationStakingPopup = (): JSX.Element => {
8989
] = useLocalStorage(MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY, true);
9090

9191
const [stakingBrowserPreferencesPersistence, { updateLocalStorage: setStakingBrowserPreferencesPersistence }] =
92-
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY);
92+
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY, DEFAULT_STAKING_BROWSER_PREFERENCES);
9393

9494
const walletAddress = walletInfo.addresses?.[0].address?.toString();
9595
const analytics = useAnalyticsContext();

apps/browser-extension-wallet/src/lib/scripts/migrations/migrations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type Migration = {
4343
downgrade?: (password?: string) => MigrationPersistance | Promise<MigrationPersistance>;
4444
};
4545

46-
const migrations: Migration[] = [versions.v_1_0_0];
46+
const migrations: Migration[] = [versions.v_1_10_2];
4747

4848
/**
4949
* Applies all migrations in order between the two version provided
@@ -137,7 +137,6 @@ export const migrationsRequirePassword = async (
137137
*/
138138
export const checkMigrations = async (previousVersion: string, migrationsArray = migrations): Promise<void> => {
139139
const currentVersion = runtime.getManifest().version;
140-
141140
// Return if a downgrade is occurring
142141
if (isVersionOlderThanOrEqual(currentVersion, previousVersion)) {
143142
// TODO: allow migrations if downgrading versions too [LW-5595]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './v1_0_0';
2+
export * from './v1_10_2';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable camelcase, @typescript-eslint/no-empty-function, no-console */
2+
import { getItemFromLocalStorage, removeItemFromLocalStorage } from '../util';
3+
import { Migration } from '../migrations';
4+
5+
const MIGRATION_VERSION = '1.10.2';
6+
7+
export const v_1_10_2: Migration = {
8+
version: MIGRATION_VERSION,
9+
upgrade: async () => ({
10+
prepare: () => {
11+
try {
12+
/**
13+
* Between the v1.9.0 and v1.10.0 releases, the 'stakingBrowserPreferences'
14+
* localStorage was updated, and contained a change in spelling, removing this
15+
* object allows it to be saved again and any issues related to spelling
16+
* are mitigated
17+
* */
18+
removeItemFromLocalStorage('stakingBrowserPreferences');
19+
} catch (error) {
20+
console.log(`error executing migration ${MIGRATION_VERSION}: ${error}`);
21+
throw error;
22+
}
23+
},
24+
assert: () => {
25+
const stakingBrowserPreferences = getItemFromLocalStorage('stakingBrowserPreferences');
26+
return !!stakingBrowserPreferences;
27+
},
28+
persist: () => {},
29+
rollback: () => {}
30+
})
31+
};

apps/browser-extension-wallet/src/views/browser-view/features/staking/components/StakingContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { compactNumberWithUnit } from '@utils/format-number';
1010
import { isMultidelegationSupportedByDevice } from '@views/browser/features/staking';
1111
import { useWalletStore } from '@stores';
1212
import { useAnalyticsContext, useCurrencyStore, useExternalLinkOpener } from '@providers';
13-
import { OutsideHandlesProvider } from '@lace/staking';
13+
import { DEFAULT_STAKING_BROWSER_PREFERENCES, OutsideHandlesProvider } from '@lace/staking';
1414
import { useBalances, useFetchCoinPrice, useLocalStorage } from '@hooks';
1515
import {
1616
MULTIDELEGATION_FIRST_VISIT_LS_KEY,
@@ -27,7 +27,7 @@ export const StakingContainer = (): React.ReactElement => {
2727

2828
const analytics = useAnalyticsContext();
2929
const [stakingBrowserPreferencesPersistence, { updateLocalStorage: setStakingBrowserPreferencesPersistence }] =
30-
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY);
30+
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY, DEFAULT_STAKING_BROWSER_PREFERENCES);
3131
const [multidelegationFirstVisit, { updateLocalStorage: setMultidelegationFirstVisit }] = useLocalStorage(
3232
MULTIDELEGATION_FIRST_VISIT_LS_KEY,
3333
true

packages/staking/src/features/BrowsePools/constants.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowsePoolsView, StakePoolSortOptions } from './types';
1+
import { BrowsePoolsView, StakePoolSortOptions, StakingBrowserPreferences } from './types';
22
import { getDefaultSortOrderByField } from './utils';
33

44
export const SEARCH_DEBOUNCE_IN_MS = 300;
@@ -9,3 +9,8 @@ export const DEFAULT_SORT_OPTIONS: StakePoolSortOptions = {
99
};
1010

1111
export const DEFAULT_BROWSE_POOLS_VIEW: BrowsePoolsView = BrowsePoolsView.grid;
12+
13+
export const DEFAULT_STAKING_BROWSER_PREFERENCES: StakingBrowserPreferences = {
14+
poolsView: DEFAULT_BROWSE_POOLS_VIEW,
15+
selectedPoolIds: [],
16+
};

packages/staking/src/features/BrowsePools/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ export { BrowsePools } from './BrowsePools';
22
export { BrowsePoolsPreferencesCard } from './BrowsePoolsPreferencesCard';
33
export { getPoolInfos } from './queries';
44
export { useBrowsePoolsPersistence } from './hooks';
5-
export { DEFAULT_SORT_OPTIONS } from './constants';
5+
export { DEFAULT_SORT_OPTIONS, DEFAULT_STAKING_BROWSER_PREFERENCES } from './constants';
66

77
// TODO: remove once multi delegation feature is GA'd
88
export { getSaturationLevel, isOversaturated, getDefaultSortOrderByField } from './utils';
9-
export type { StakePoolSortOptions, TranslationsFor, SortField, SortOrder } from './types';
9+
export type { StakingBrowserPreferences, StakePoolSortOptions, TranslationsFor, SortField, SortOrder } from './types';
1010
export { BrowsePoolsView } from './types';
1111
export { StakePoolCardProgressBar } from './StakePoolCard';
1212
export { StakePoolsListRowSkeleton, config as stakePoolTableConfig } from './StakePoolsList';

packages/staking/src/features/BrowsePools/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ export type StakePoolSortOptions = {
2222
};
2323

2424
export type TranslationsFor<T extends string> = Record<T, string>;
25+
26+
export type StakingBrowserPreferences = {
27+
poolsView: BrowsePoolsView;
28+
selectedPoolIds: string[];
29+
};

packages/staking/src/features/outside-handles-provider/types.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TxBuilder } from '@cardano-sdk/tx-construction';
22
import { Wallet } from '@lace/cardano';
33
import { AssetActivityListProps } from '@lace/core';
4-
import { BrowsePoolsView, StakePoolSortOptions } from 'features/BrowsePools/types';
4+
import { StakePoolSortOptions, StakingBrowserPreferences } from 'features/BrowsePools';
55
import type { IAnalyticsTracker } from '@lace/common';
66

77
type WalletBalance = {
@@ -40,11 +40,6 @@ export enum StateStatus {
4040
ERROR = 'error',
4141
}
4242

43-
export interface StakingBrowserPreferences {
44-
poolsView: BrowsePoolsView;
45-
selectedPoolIds: string[];
46-
}
47-
4843
export interface IBlockchainProvider {
4944
stakePoolProvider: Wallet.StakePoolProvider;
5045
assetProvider: Wallet.AssetProvider;

packages/staking/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export { Staking, StakingPopup } from './features/staking';
2-
export { BrowsePoolsPreferencesCard } from './features/BrowsePools';
2+
export type { StakingBrowserPreferences } from 'features/BrowsePools';
3+
export { BrowsePoolsPreferencesCard, DEFAULT_STAKING_BROWSER_PREFERENCES } from './features/BrowsePools';
34
export { OutsideHandlesProvider } from './features/outside-handles-provider';
4-
export type { StakingBrowserPreferences } from './features/outside-handles-provider';
55
export { MAX_POOLS_COUNT } from './features/store';
66

77
// TODO: remove once multi delegaion feature is GA'd

0 commit comments

Comments
 (0)