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

LW-9459: save user preferences for staking feature #839

Merged
merged 17 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -20,7 +20,8 @@ import { BrowserViewSections } from '@lib/scripts/types';
import { useWalletActivities } from '@hooks/useWalletActivities';
import {
MULTIDELEGATION_FIRST_VISIT_LS_KEY,
MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY
MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY,
DELEGATION_PREFERENCES_LS_KEY
} from '@utils/constants';

export const MultiDelegationStakingPopup = (): JSX.Element => {
Expand Down Expand Up @@ -85,6 +86,10 @@ export const MultiDelegationStakingPopup = (): JSX.Element => {
multidelegationFirstVisitSincePortfolioPersistence,
{ updateLocalStorage: setMultidelegationFirstVisitSincePortfolioPersistence }
] = useLocalStorage(MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY, true);

const [delegationPreferencePersistence, { updateLocalStorage: setDelegationPreferencePersistence }] =
useLocalStorage(DELEGATION_PREFERENCES_LS_KEY);

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

Expand All @@ -96,6 +101,8 @@ export const MultiDelegationStakingPopup = (): JSX.Element => {
<OutsideHandlesProvider
{...{
analytics,
delegationPreferencePersistence,
setDelegationPreferencePersistence,
multidelegationFirstVisit,
triggerMultidelegationFirstVisit: () => setMultidelegationFirstVisit(false),
multidelegationFirstVisitSincePortfolioPersistence,
Expand Down
2 changes: 2 additions & 0 deletions apps/browser-extension-wallet/src/types/local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Wallet } from '@lace/cardano';
import { EnhancedAnalyticsOptInStatus, TxCreationType } from '../providers/AnalyticsProvider/analyticsTracker/types';
import { DelegationPreferences } from '@lace/staking';

export interface WalletStorage {
name: string;
Expand Down Expand Up @@ -52,4 +53,5 @@ export interface ILocalStorage {
multidelegationFirstVisit?: boolean;
multidelegationFirstVisitSincePortfolioPersistence?: boolean;
unconfirmedTransactions: UnconfirmedTransaction[];
delegationPreferences: DelegationPreferences;
}
1 change: 1 addition & 0 deletions apps/browser-extension-wallet/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ export const COINGECKO_URL = 'https://www.coingecko.com';
export const MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY =
'multidelegationFirstVisitSincePortfolioPersistence';
export const MULTIDELEGATION_FIRST_VISIT_LS_KEY = 'multidelegationFirstVisit';
export const DELEGATION_PREFERENCES_LS_KEY = 'delegationPreferences';
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useWalletStore } from '@stores';
import { compactNumberWithUnit } from '@utils/format-number';
import { useWalletActivities } from '@hooks/useWalletActivities';
import {
DELEGATION_PREFERENCES_LS_KEY,
MULTIDELEGATION_FIRST_VISIT_LS_KEY,
MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY
} from '@utils/constants';
Expand Down Expand Up @@ -85,6 +86,10 @@ export const MultiDelegationStaking = (): JSX.Element => {
multidelegationFirstVisitSincePortfolioPersistence,
{ updateLocalStorage: setMultidelegationFirstVisitSincePortfolioPersistence }
] = useLocalStorage(MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY, true);

const [delegationPreferencePersistence, { updateLocalStorage: setDelegationPreferencePersistence }] =
useLocalStorage(DELEGATION_PREFERENCES_LS_KEY);

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

Expand All @@ -97,6 +102,8 @@ export const MultiDelegationStaking = (): JSX.Element => {
<OutsideHandlesProvider
{...{
analytics,
delegationPreferencePersistence,
setDelegationPreferencePersistence,
backgroundServiceAPIContextSetWalletPassword: setWalletPassword,
balancesBalance: balance,
delegationStoreSetDelegationTxBuilder: setDelegationTxBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ const searchDebounce = 300;
const defaultFetchLimit = 100;

export const StakePoolsTable = ({ scrollableTargetId }: StakePoolsTableProps) => {
const { t } = useTranslation();
const [searchValue, setSearchValue] = useState<string>('');
const [isSearching, setIsSearching] = useState<boolean>(true);
const [isLoadingList, setIsLoadingList] = useState<boolean>(true);
const [sort, setSort] = useState<StakePoolSortOptions>(DEFAULT_SORT_OPTIONS);
const [stakePools, setStakePools] = useState<Wallet.StakePoolSearchResults['pageResults']>([]);
const [skip, setSkip] = useState<number>(0);
const selectedPortfolioStakePools = useDelegationPortfolioStore((store) =>
store.selectedPortfolio.map(({ stakePool }) => stakePool)
);
const {
currentChain,
walletStoreStakePoolSearchResults: {
Expand All @@ -47,7 +37,21 @@ export const StakePoolsTable = ({ scrollableTargetId }: StakePoolsTableProps) =>
walletStoreStakePoolSearchResultsStatus,
walletStoreFetchStakePools: fetchStakePools,
analytics,
delegationPreferencePersistence,
setDelegationPreferencePersistence,
} = useOutsideHandles();
const { t } = useTranslation();
const [searchValue, setSearchValue] = useState<string>(delegationPreferencePersistence?.searchQuery || '');
const [isSearching, setIsSearching] = useState<boolean>(true);
const [isLoadingList, setIsLoadingList] = useState<boolean>(true);
const [sort, setSort] = useState<StakePoolSortOptions>(
delegationPreferencePersistence?.sortOptions || DEFAULT_SORT_OPTIONS
);
const [stakePools, setStakePools] = useState<Wallet.StakePoolSearchResults['pageResults']>([]);
const [skip, setSkip] = useState<number>(0);
const selectedPortfolioStakePools = useDelegationPortfolioStore((store) =>
store.selectedPortfolio.map(({ stakePool }) => stakePool)
);

const fetchingPools = walletStoreStakePoolSearchResultsStatus === StateStatus.LOADING;

Expand All @@ -68,7 +72,19 @@ export const StakePoolsTable = ({ scrollableTargetId }: StakePoolsTableProps) =>
// Fetch pools on mount, network switching, searchValue change and sort change
setIsLoadingList(true);
debouncedSearch({ searchString: searchValue, sort });
}, [currentChain, searchValue, sort, debouncedSearch]);
setDelegationPreferencePersistence({
...delegationPreferencePersistence,
searchQuery: searchValue,
sortOptions: sort,
});
}, [
currentChain,
searchValue,
sort,
debouncedSearch,
setDelegationPreferencePersistence,
delegationPreferencePersistence,
]);

const loadMoreData = () => fetchStakePools({ searchString: searchValue, skip: skip + defaultFetchLimit, sort });

Expand Down Expand Up @@ -141,6 +157,7 @@ export const StakePoolsTable = ({ scrollableTargetId }: StakePoolsTableProps) =>
withSearchIcon
inputPlaceholder={t('browsePools.stakePoolTableBrowser.searchInputPlaceholder')}
onChange={onSearch}
value={searchValue}
data-testid="search-input"
loading={fetchingPools}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export enum StateStatus {
ERROR = 'error',
}

export interface DelegationPreferences {
sortOptions: StakePoolSortOptions;
searchQuery?: string;
mchappell marked this conversation as resolved.
Show resolved Hide resolved
}

export interface IBlockchainProvider {
stakePoolProvider: Wallet.StakePoolProvider;
assetProvider: Wallet.AssetProvider;
Expand All @@ -52,6 +57,8 @@ export interface IBlockchainProvider {

export type OutsideHandlesContextValue = {
analytics: IAnalyticsTracker;
delegationPreferencePersistence: DelegationPreferences;
setDelegationPreferencePersistence: (preferences: DelegationPreferences) => void;
backgroundServiceAPIContextSetWalletPassword: (password?: Uint8Array) => void;
expandStakingView?: () => void;
balancesBalance?: Balance;
Expand Down
1 change: 1 addition & 0 deletions packages/staking/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export { config as stakePooltableConfig } from './features/BrowsePools/StakePool
export type { TableRowProps } from './features/BrowsePools/StakePoolsTable/Table';
export * from './features/BrowsePools/StakePoolsTable/types';
export { OutsideHandlesProvider } from './features/outside-handles-provider';
export type { DelegationPreferences } from './features/outside-handles-provider';
export { MAX_POOLS_COUNT } from './features/store';
Loading