Skip to content

Commit 483284e

Browse files
committed
feat(staking): expose activity detail drawer in staking section to be used by staking activity
1 parent be2b44b commit 483284e

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

apps/browser-extension-wallet/src/stores/slices/activity-detail-slice.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,15 @@ const buildGetActivityDetail =
8989
walletInfo
9090
} = get();
9191

92+
set({ fetchingActivityInfo: true });
93+
9294
if (activityDetail.type === 'rewards') {
9395
const { activity, status, type } = activityDetail;
9496
const poolInfos = await getPoolInfos(
9597
activity.rewards.map(({ poolId }) => poolId),
9698
stakePoolProvider
9799
);
100+
set({ fetchingActivityInfo: false });
98101

99102
return {
100103
activity: {
@@ -128,7 +131,6 @@ const buildGetActivityDetail =
128131
const { activity: tx, status, type, direction } = activityDetail;
129132
const walletAssets = await firstValueFrom(wallet.assetInfo$);
130133
const protocolParameters = await firstValueFrom(wallet.protocolParameters$);
131-
set({ fetchingActivityInfo: true });
132134

133135
// Assets
134136
const assetIds = getTransactionAssetsId(tx.body.outputs);

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OutsideHandlesProvider, Staking } from '@lace/staking';
2-
import React, { useCallback } from 'react';
2+
import React, { useCallback, useEffect } from 'react';
33
import {
44
useAnalyticsContext,
55
useBackgroundServiceAPIContext,
@@ -17,6 +17,9 @@ import {
1717
MULTIDELEGATION_FIRST_VISIT_LS_KEY,
1818
MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY
1919
} from '@utils/constants';
20+
import { ActivityDetail } from '../../activity';
21+
import { Drawer, DrawerNavigation } from '@lace/common';
22+
import { useTranslation } from 'react-i18next';
2023

2124
export const MultiDelegationStaking = (): JSX.Element => {
2225
const { theme } = useTheme();
@@ -38,7 +41,9 @@ export const MultiDelegationStaking = (): JSX.Element => {
3841
fetchNetworkInfo,
3942
networkInfo,
4043
blockchainProvider,
41-
currentChain
44+
currentChain,
45+
activityDetail,
46+
resetActivityState
4247
} = useWalletStore((state) => ({
4348
getKeyAgentType: state.getKeyAgentType,
4449
inMemoryWallet: state.inMemoryWallet,
@@ -50,8 +55,11 @@ export const MultiDelegationStaking = (): JSX.Element => {
5055
fetchNetworkInfo: state.fetchNetworkInfo,
5156
blockchainProvider: state.blockchainProvider,
5257
walletInfo: state.walletInfo,
53-
currentChain: state.currentChain
58+
currentChain: state.currentChain,
59+
activityDetail: state.activityDetail,
60+
resetActivityState: state.resetActivityState
5461
}));
62+
const { t } = useTranslation();
5563
const sendAnalytics = useCallback(() => {
5664
// TODO implement analytics for the new flow
5765
const analytics = {
@@ -80,6 +88,11 @@ export const MultiDelegationStaking = (): JSX.Element => {
8088
const walletAddress = walletInfo.addresses?.[0].address?.toString();
8189
const analytics = useAnalyticsContext();
8290

91+
// Reset current transaction details and close drawer if network (blockchainProvider) has changed
92+
useEffect(() => {
93+
resetActivityState();
94+
}, [resetActivityState, blockchainProvider]);
95+
8396
return (
8497
<OutsideHandlesProvider
8598
{...{
@@ -119,6 +132,27 @@ export const MultiDelegationStaking = (): JSX.Element => {
119132
}}
120133
>
121134
<Staking currentChain={currentChain} theme={theme.name} />
135+
{/*
136+
Note: Mounting the browser-extension activity details drawer here is just a workaround.
137+
Ideally, the Drawer/Activity detail should be fully managed within the "Staking" component,
138+
which contains the respective "Activity" section, but that would require moving/refactoring
139+
large chunks of code, ATM tightly coupled with browser-extension state/logic,
140+
to a separate package (core perhaps?).
141+
*/}
142+
<Drawer
143+
visible={!!activityDetail}
144+
onClose={resetActivityState}
145+
navigation={
146+
<DrawerNavigation
147+
title={t('transactions.detail.title')}
148+
onCloseIconClick={() => {
149+
resetActivityState();
150+
}}
151+
/>
152+
}
153+
>
154+
{activityDetail && priceResult && <ActivityDetail price={priceResult} />}
155+
</Drawer>
122156
</OutsideHandlesProvider>
123157
);
124158
};

0 commit comments

Comments
 (0)