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(staking): clicking on drift warning not working (popup) LW-9438 #918

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -111,7 +111,8 @@ export const MultiDelegationStakingPopup = (): JSX.Element => {
setMultidelegationFirstVisit(false);
setMultidelegationFirstVisitSincePortfolioPersistence(false);
},
expandStakingView: () => handleOpenBrowser({ section: BrowserViewSections.STAKING }),
expandStakingView: (urlSearchParams?: string) =>
handleOpenBrowser({ section: BrowserViewSections.STAKING, urlSearchParams }),
balancesBalance: balance,
delegationStoreSetDelegationTxBuilder: setDelegationTxBuilder,
delegationStoreDelegationTxBuilder: delegationTxBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface TokenAPIResponse {

const migrationState$ = new BehaviorSubject<MigrationState | undefined>(undefined);

// eslint-disable-next-line complexity
const handleOpenBrowser = async (data: OpenBrowserData) => {
let path = '';
switch (data.section) {
Expand Down Expand Up @@ -79,7 +80,8 @@ const handleOpenBrowser = async (data: OpenBrowserData) => {
path = walletRoutePaths.sharedWallet.root;
break;
}
await tabs.create({ url: `app.html#${path}` }).catch((error) => console.error(error));
const params = data.urlSearchParams ? `?${data.urlSearchParams}` : '';
await tabs.create({ url: `app.html#${path}${params}` }).catch((error) => console.error(error));
};

const handleChangeTheme = (data: ChangeThemeData) => requestMessage$.next({ type: MessageTypes.CHANGE_THEME, data });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum BrowserViewSections {

export interface OpenBrowserData {
section: BrowserViewSections;
urlSearchParams?: string;
}

interface ChangeThemeMessage {
Expand All @@ -56,7 +57,7 @@ interface OpenBrowserMessage {
export type Message = ChangeThemeMessage | HTTPConnectionMessage | OpenBrowserMessage;

export type BackgroundService = {
handleOpenBrowser: (data: OpenBrowserData) => Promise<void>;
handleOpenBrowser: (data: OpenBrowserData, urlSearchParams?: string) => Promise<void>;
requestMessage$: Subject<Message>;
migrationState$: BehaviorSubject<MigrationState | undefined>;
coinPrices: CoinPrices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type OutsideHandlesContextValue = {
stakingBrowserPreferencesPersistence: StakingBrowserPreferences;
setStakingBrowserPreferencesPersistence: (preferences: StakingBrowserPreferences) => void;
walletManagerExecuteWithPassword: <T>(action: () => Promise<T>, password?: string) => Promise<T>;
expandStakingView?: () => void;
expandStakingView?: (urlSearchParams?: string) => void;
balancesBalance?: Balance;
delegationStoreSetDelegationTxBuilder: (txBuilder?: TxBuilder) => void;
delegationStoreSetDelegationTxFee: (fee?: string) => void;
Expand Down
4 changes: 2 additions & 2 deletions packages/staking/src/features/overview/ExpandViewBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import styles from './ExpandViewBanner.module.scss';

export const ExpandViewBanner = (): React.ReactElement => {
const { t } = useTranslation();
const { expandStakingView } = useOutsideHandles();
const { expandStakingView = () => void 0 } = useOutsideHandles();

return (
<div className={styles.wrapper}>
Expand All @@ -20,7 +20,7 @@ export const ExpandViewBanner = (): React.ReactElement => {
{t('popup.expandBanner.description')}
</div>
<Button
onClick={expandStakingView}
onClick={() => expandStakingView()}
className={styles.button}
size="large"
color="gradient"
Expand Down
20 changes: 20 additions & 0 deletions packages/staking/src/features/overview/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useObservable } from '@lace/common';
import { Box, ControlButton, Flex, Text } from '@lace/ui';
import { Skeleton } from 'antd';
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { DelegationCard } from '../DelegationCard';
import { useOutsideHandles } from '../outside-handles-provider';
import { useDelegationPortfolioStore } from '../store';
import { FundWalletBanner } from './FundWalletBanner';
import { GetStartedSteps } from './GetStartedSteps';
import { hasMinimumFundsToDelegate, hasPendingDelegationTransaction, mapPortfolioToDisplayData } from './helpers';
import { useStakingSectionLoadActions } from './hooks';
import { StakeFundsBanner } from './StakeFundsBanner';
import { StakingInfoCard } from './StakingInfoCard';
import { StakingNotificationBanners, getCurrentStakingNotifications } from './StakingNotificationBanners';
Expand All @@ -29,10 +31,28 @@ export const Overview = () => {
currentPortfolio: store.currentPortfolio,
portfolioMutators: store.mutators,
}));
const { onLoad } = useStakingSectionLoadActions();
const stakingNotifications = getCurrentStakingNotifications({ currentPortfolio, walletActivities });

const totalCoinBalance = balancesBalance?.total?.coinBalance;

useEffect(() => {
if (
totalCoinBalance &&
protocolParameters?.stakeKeyDeposit &&
balancesBalance?.available?.coinBalance &&
rewardAccounts
) {
onLoad();
}
}, [
balancesBalance?.available?.coinBalance,
onLoad,
protocolParameters?.stakeKeyDeposit,
rewardAccounts,
totalCoinBalance,
]);

if (
!totalCoinBalance ||
!protocolParameters?.stakeKeyDeposit ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const PortfolioDriftBanner: VFC<PortfolioDriftBannerProps> = ({ popupView

const onBannerClick = () => {
if (popupView) {
expandStakingView();
expandStakingView('onLoadAction=ManagePortfolio');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const StakingNotificationBanners = ({ popupView, notifications }: Staking

const onPoolRetiredOrSaturatedBannerClick = () => {
if (popupView) {
expandStakingView();
expandStakingView('onLoadAction=ManagePortfolio');
return;
}

Expand Down
24 changes: 24 additions & 0 deletions packages/staking/src/features/overview/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useSearchParams } from '@lace/common';
import { useDelegationPortfolioStore } from 'features/store';
import { useCallback, useState } from 'react';

type StakingLoadActions = 'ManagePortfolio';

export const useStakingSectionLoadActions = () => {
const portfolioMutators = useDelegationPortfolioStore((store) => store.mutators);
const { onLoadAction } = useSearchParams(['onLoadAction']);
const [executed, setExecuted] = useState(false);

const onLoad = useCallback(() => {
if (!executed && ['ManagePortfolio'].includes(onLoadAction)) {
portfolioMutators.executeCommand({
type: onLoadAction as StakingLoadActions,
tommayeliog marked this conversation as resolved.
Show resolved Hide resolved
});
setExecuted(true);
}
}, [executed, onLoadAction, portfolioMutators]);

return {
onLoad,
};
};
Loading