Skip to content

Commit

Permalink
fix(staking): clicking on drift warning not working (popup) LW-9438 (#…
Browse files Browse the repository at this point in the history
…918)

* fix(staking): clicking on drift warning not working (popup) LW-9438
  • Loading branch information
tommayeliog authored Mar 4, 2024
1 parent 90c4177 commit 3fbb664
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 9 deletions.
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
2 changes: 1 addition & 1 deletion packages/staking/src/features/overview/OverviewPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const OverviewPopup = () => {
<>
{stakingNotifications.length > 0 && (
<Flex mb="$32" flexDirection="column">
<StakingNotificationBanners notifications={stakingNotifications} />
<StakingNotificationBanners notifications={stakingNotifications} popupView />
</Flex>
)}
<Box mb="$32">
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
22 changes: 22 additions & 0 deletions packages/staking/src/features/overview/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useSearchParams } from '@lace/common';
import { useDelegationPortfolioStore } from 'features/store';
import { useCallback, useState } from 'react';

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

const onLoad = useCallback(() => {
if (!executed && onLoadAction === 'ManagePortfolio') {
portfolioMutators.executeCommand({
type: 'ManagePortfolio',
});
setExecuted(true);
}
}, [executed, onLoadAction, portfolioMutators]);

return {
onLoad,
};
};

0 comments on commit 3fbb664

Please sign in to comment.