From f71c7b5751862980fcd3fcd2f654d6a03cefba9d Mon Sep 17 00:00:00 2001 From: xdzurman Date: Mon, 30 Oct 2023 16:07:16 +0100 Subject: [PATCH 1/8] feat(staking): load multi-delegation for HW wallets --- .../src/hooks/useMultiDelegationEnabled.ts | 14 +--- .../StakePoolConfirmationFooter.tsx | 58 ++++++++------- .../stateMachine/commands.ts | 22 +++++- .../stateMachine/processExpandedViewCases.ts | 73 +++++++++++-------- 4 files changed, 96 insertions(+), 71 deletions(-) diff --git a/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts b/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts index e30e558e39..0135fdf8b2 100644 --- a/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts +++ b/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts @@ -1,13 +1 @@ -import { Wallet } from '@lace/cardano'; -import { useWalletStore } from '@src/stores'; -import { useMemo } from 'react'; - -export const useMultiDelegationEnabled = (): boolean => { - const { getKeyAgentType } = useWalletStore(); - const inMemoryWallet = useMemo( - () => getKeyAgentType() === Wallet.KeyManagement.KeyAgentType.InMemory, - [getKeyAgentType] - ); - - return process.env.USE_MULTI_DELEGATION_STAKING === 'true' && inMemoryWallet; -}; +export const useMultiDelegationEnabled = (): boolean => process.env.USE_MULTI_DELEGATION_STAKING === 'true'; diff --git a/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx b/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx index 14acc6116e..43a04ebb2d 100644 --- a/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx +++ b/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx @@ -19,10 +19,10 @@ export const StakePoolConfirmationFooter = ({ popupView }: StakePoolConfirmation const { t } = useTranslation(); const { analytics } = useOutsideHandles(); const { - // walletStoreInMemoryWallet: inMemoryWallet, + walletStoreInMemoryWallet: inMemoryWallet, walletStoreGetKeyAgentType: getKeyAgentType, - // submittingState: { setIsRestaking }, - // delegationStoreDelegationTxBuilder: delegationTxBuilder, + submittingState: { setIsRestaking }, + delegationStoreDelegationTxBuilder: delegationTxBuilder, } = useOutsideHandles(); const { isBuildingTx, stakingError } = useStakingStore(); const [isConfirmingTx, setIsConfirmingTx] = useState(false); @@ -38,13 +38,32 @@ export const StakePoolConfirmationFooter = ({ popupView }: StakePoolConfirmation const isInMemory = useMemo(() => keyAgentType === Wallet.KeyManagement.KeyAgentType.InMemory, [keyAgentType]); // TODO unify - // const signAndSubmitTransaction = useCallback(async () => { - // if (!delegationTxBuilder) throw new Error('Unable to submit transaction. The delegationTxBuilder not available'); - // const signedTx = await delegationTxBuilder.build().sign(); - // await inMemoryWallet.submitTx(signedTx.tx); - // }, [delegationTxBuilder, inMemoryWallet]); + const signAndSubmitTransaction = useCallback(async () => { + if (!delegationTxBuilder) throw new Error('Unable to submit transaction. The delegationTxBuilder not available'); + const signedTx = await delegationTxBuilder.build().sign(); + await inMemoryWallet.submitTx(signedTx.tx); + }, [delegationTxBuilder, inMemoryWallet]); - const handleConfirmation = useCallback(async () => { + const handleSubmission = useCallback(async () => { + if (!isInMemory) { + // HW-WALLET + setIsConfirmingTx(true); + try { + await signAndSubmitTransaction(); + setIsRestaking(currentPortfolio.length > 0); + portfolioMutators.executeCommand({ type: 'HwSkipToSuccess' }); + } catch { + portfolioMutators.executeCommand({ type: 'HwSkipToFailure' }); + } finally { + setIsConfirmingTx(false); + } + } else { + // Mnemonic wallet continues to password verification + portfolioMutators.executeCommand({ type: 'DrawerContinue' }); + } + }, [currentPortfolio, isInMemory, portfolioMutators, setIsRestaking, signAndSubmitTransaction]); + + const onClick = useCallback(async () => { analytics.sendEventToPostHog(PostHogAction.StakingManageDelegationStakePoolConfirmationNextClick); setIsConfirmingTx(false); @@ -61,21 +80,8 @@ export const StakePoolConfirmationFooter = ({ popupView }: StakePoolConfirmation if (isPoolsReduced) return setOpenPoolsManagementConfirmationModal(PoolsManagementModalType.REDUCTION); - // HW-WALLET (FIX LATER): - // if (!isInMemory) { - // setIsConfirmingTx(true); - // try { - // await signAndSubmitTransaction(); - // setIsRestaking(currentPortfolio.length > 0); - // return setSection(sectionsConfig[Sections.SUCCESS_TX]); - // } catch { - // return setSection(sectionsConfig[Sections.FAIL_TX]); - // } finally { - // setIsConfirmingTx(false); - // } - // } - return portfolioMutators.executeCommand({ type: 'DrawerContinue' }); - }, [analytics, currentPortfolio, draftPortfolio, portfolioMutators]); + return handleSubmission(); + }, [analytics, currentPortfolio, draftPortfolio, handleSubmission]); const confirmLabel = useMemo(() => { if (!isInMemory) { @@ -94,7 +100,7 @@ export const StakePoolConfirmationFooter = ({ popupView }: StakePoolConfirmation data-testid="stake-pool-confirmation-btn" disabled={isBuildingTx || !!stakingError} loading={isConfirmingTx || isBuildingTx} - onClick={handleConfirmation} + onClick={onClick} style={{ width: '100%' }} size="large" > @@ -104,7 +110,7 @@ export const StakePoolConfirmationFooter = ({ popupView }: StakePoolConfirmation portfolioMutators.executeCommand({ type: 'DrawerContinue' })} + onConfirm={handleSubmission} onCancel={() => setOpenPoolsManagementConfirmationModal(null)} /> diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts index 416f966414..529e446eb5 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts @@ -96,6 +96,14 @@ export type DrawerFailure = { type: 'DrawerFailure'; }; +export type HwSkipToSuccess = { + type: 'HwSkipToSuccess'; +}; + +export type HwSkipToFailure = { + type: 'HwSkipToFailure'; +}; + export type OverviewCommand = ShowDelegatedPoolDetails | ManagePortfolio | GoToBrowsePools; export type BrowsePoolsCommand = @@ -117,7 +125,12 @@ export type PortfolioManagementPreferencesCommand = | RemoveStakePool | UpdateStakePercentage; -export type PortfolioManagementConfirmationCommand = CancelDrawer | DrawerContinue | DrawerBack; +export type PortfolioManagementConfirmationCommand = + | CancelDrawer + | DrawerContinue + | DrawerBack + | HwSkipToSuccess + | HwSkipToFailure; export type PortfolioManagementSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; @@ -134,7 +147,12 @@ export type NewPortfolioPreferencesCommand = | RemoveStakePool | UpdateStakePercentage; -export type NewPortfolioConfirmationCommand = CancelDrawer | DrawerContinue | DrawerBack; +export type NewPortfolioConfirmationCommand = + | CancelDrawer + | DrawerContinue + | DrawerBack + | HwSkipToSuccess + | HwSkipToFailure; export type NewPortfolioSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts index 05c5ab2e79..cd2c63872f 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts @@ -16,6 +16,8 @@ import { DrawerFailure, GoToBrowsePools, GoToOverview, + HwSkipToFailure, + HwSkipToSuccess, ManagePortfolio, NewPortfolioConfirmationCommand, NewPortfolioFailureCommand, @@ -268,6 +270,18 @@ export const processExpandedViewCases: Handler = (params) => activeDrawerStep: DrawerManagementStep.Sign, }) ), + HwSkipToFailure: handler( + ({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Failure, + }) + ), + HwSkipToSuccess: handler( + ({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Success, + }) + ), }, params.command.type, DrawerManagementStep.Confirmation @@ -379,12 +393,10 @@ export const processExpandedViewCases: Handler = (params) => ...atomicStateMutators.cancelDrawer({ state, targetFlow: DelegationFlow.BrowsePools }), draftPortfolio: undefined, })), - DrawerContinue: handler( - ({ state }) => ({ - ...state, - activeDrawerStep: DrawerManagementStep.Confirmation, - }) - ), + DrawerContinue: handler(({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Confirmation, + })), RemoveStakePool: handler( ({ state, command: { data } }) => ({ ...state, @@ -417,12 +429,18 @@ export const processExpandedViewCases: Handler = (params) => ...state, activeDrawerStep: DrawerManagementStep.Preferences, })), - DrawerContinue: handler( - ({ state }) => ({ - ...state, - activeDrawerStep: DrawerManagementStep.Sign, - }) - ), + DrawerContinue: handler(({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Sign, + })), + HwSkipToFailure: handler(({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Failure, + })), + HwSkipToSuccess: handler(({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Success, + })), }, params.command.type, DrawerManagementStep.Confirmation @@ -439,18 +457,14 @@ export const processExpandedViewCases: Handler = (params) => ...state, activeDrawerStep: DrawerManagementStep.Confirmation, })), - DrawerContinue: handler( - ({ state }) => ({ - ...state, - activeDrawerStep: DrawerManagementStep.Success, - }) - ), - DrawerFailure: handler( - ({ state }) => ({ - ...state, - activeDrawerStep: DrawerManagementStep.Failure, - }) - ), + DrawerContinue: handler(({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Success, + })), + DrawerFailure: handler(({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Failure, + })), }, params.command.type, DrawerManagementStep.Sign @@ -478,13 +492,12 @@ export const processExpandedViewCases: Handler = (params) => DrawerBack: handler(({ state }) => ({ ...state, activeDrawerStep: DrawerManagementStep.Sign, + // TODO: fix for hw wallet skip + })), + DrawerContinue: handler(({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.Success, })), - DrawerContinue: handler( - ({ state }) => ({ - ...state, - activeDrawerStep: DrawerManagementStep.Success, - }) - ), }, params.command.type, DrawerManagementStep.Failure From bb6fb849d3b119a386b45244c62e1f8071b89c97 Mon Sep 17 00:00:00 2001 From: xdzurman Date: Tue, 31 Oct 2023 13:38:00 +0100 Subject: [PATCH 2/8] fix(staking): fix double-click staking modal bug --- .../features/Drawer/confirmation/StakePoolConfirmationFooter.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx b/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx index 43a04ebb2d..9412a89185 100644 --- a/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx +++ b/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx @@ -45,6 +45,7 @@ export const StakePoolConfirmationFooter = ({ popupView }: StakePoolConfirmation }, [delegationTxBuilder, inMemoryWallet]); const handleSubmission = useCallback(async () => { + setOpenPoolsManagementConfirmationModal(null); if (!isInMemory) { // HW-WALLET setIsConfirmingTx(true); From adc990c5476d745a7b9e267c678f20323ad45906 Mon Sep 17 00:00:00 2001 From: xdzurman Date: Tue, 31 Oct 2023 14:55:09 +0100 Subject: [PATCH 3/8] fix(staking): fix broken go-back common button --- packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx b/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx index 6675b0c912..5af35f99cc 100644 --- a/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx +++ b/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx @@ -82,7 +82,7 @@ export const StakePoolDetailsDrawer = ({ const createArrowIconCallback = () => { if (activeDrawerStep && typeof showBackIcon === 'function' ? showBackIcon(activeDrawerStep) : showBackIcon) { - return popupView ? closeDrawer : onGoBack; + return popupView ? closeDrawer() : onGoBack(); } // eslint-disable-next-line consistent-return, unicorn/no-useless-undefined return undefined; From e2290836631a896b57a4f02d49c940c07ba3075e Mon Sep 17 00:00:00 2001 From: xdzurman Date: Tue, 31 Oct 2023 15:29:23 +0100 Subject: [PATCH 4/8] fix(staking): do not render back button if not intended --- .../Drawer/StakePoolDetailsDrawer.tsx | 19 +++++++++++++------ .../stateMachine/commands.ts | 2 ++ .../stateMachine/processExpandedViewCases.ts | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx b/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx index 5af35f99cc..837946910f 100644 --- a/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx +++ b/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx @@ -72,8 +72,11 @@ export const StakePoolDetailsDrawer = ({ }); }, [password, portfolioMutators, backgroundServiceAPIContextSetWalletPassword, removePassword]); + const shouldShowBackIcon = + activeDrawerStep && typeof showBackIcon === 'function' ? showBackIcon(activeDrawerStep) : showBackIcon; + useKeyboardShortcut(['Escape'], () => { - if (activeDrawerStep && typeof showBackIcon === 'function' ? showBackIcon(activeDrawerStep) : showBackIcon) { + if (shouldShowBackIcon) { onGoBack(); } else { closeDrawer(); @@ -81,7 +84,7 @@ export const StakePoolDetailsDrawer = ({ }); const createArrowIconCallback = () => { - if (activeDrawerStep && typeof showBackIcon === 'function' ? showBackIcon(activeDrawerStep) : showBackIcon) { + if (shouldShowBackIcon) { return popupView ? closeDrawer() : onGoBack(); } // eslint-disable-next-line consistent-return, unicorn/no-useless-undefined @@ -97,10 +100,14 @@ export const StakePoolDetailsDrawer = ({ { - onBackButtonClick?.(); - createArrowIconCallback(); - }} + onArrowIconClick={ + !shouldShowBackIcon + ? undefined + : () => { + onBackButtonClick?.(); + createArrowIconCallback(); + } + } onCloseIconClick={() => { if ( activeDrawerStep && typeof showCloseIcon === 'function' ? showCloseIcon(activeDrawerStep) : showCloseIcon diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts index 529e446eb5..30498ecf02 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts @@ -134,6 +134,7 @@ export type PortfolioManagementConfirmationCommand = export type PortfolioManagementSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; +// TODO: should not have DrawerBack, it's not used export type PortfolioManagementFailureCommand = CancelDrawer | DrawerContinue | DrawerBack; export type PortfolioManagementSuccessCommand = CancelDrawer; @@ -156,6 +157,7 @@ export type NewPortfolioConfirmationCommand = export type NewPortfolioSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; +// TODO: should not have DrawerBack, it's not used export type NewPortfolioFailureCommand = CancelDrawer | DrawerContinue | DrawerBack; export type NewPortfolioSuccessCommand = CancelDrawer; diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts index cd2c63872f..909d23a0fe 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts @@ -491,8 +491,8 @@ export const processExpandedViewCases: Handler = (params) => })), DrawerBack: handler(({ state }) => ({ ...state, - activeDrawerStep: DrawerManagementStep.Sign, // TODO: fix for hw wallet skip + activeDrawerStep: DrawerManagementStep.Sign, })), DrawerContinue: handler(({ state }) => ({ ...state, From 40e4053be724ee06aa205f053d770cdc1b46886d Mon Sep 17 00:00:00 2001 From: xdzurman Date: Thu, 2 Nov 2023 10:27:39 +0100 Subject: [PATCH 5/8] fix(staking): implement pr suggestions --- .../Drawer/StakePoolDetailsDrawer.tsx | 4 +-- .../StakePoolConfirmationFooter.tsx | 28 +++++++++---------- .../stateMachine/commands.ts | 6 ++-- .../stateMachine/processExpandedViewCases.ts | 9 ------ 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx b/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx index 837946910f..3e0c481dcf 100644 --- a/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx +++ b/packages/staking/src/features/Drawer/StakePoolDetailsDrawer.tsx @@ -83,7 +83,7 @@ export const StakePoolDetailsDrawer = ({ } }); - const createArrowIconCallback = () => { + const arrowIconCallback = () => { if (shouldShowBackIcon) { return popupView ? closeDrawer() : onGoBack(); } @@ -105,7 +105,7 @@ export const StakePoolDetailsDrawer = ({ ? undefined : () => { onBackButtonClick?.(); - createArrowIconCallback(); + arrowIconCallback(); } } onCloseIconClick={() => { diff --git a/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx b/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx index 9412a89185..e7a8f82aa3 100644 --- a/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx +++ b/packages/staking/src/features/Drawer/confirmation/StakePoolConfirmationFooter.tsx @@ -46,21 +46,21 @@ export const StakePoolConfirmationFooter = ({ popupView }: StakePoolConfirmation const handleSubmission = useCallback(async () => { setOpenPoolsManagementConfirmationModal(null); - if (!isInMemory) { - // HW-WALLET - setIsConfirmingTx(true); - try { - await signAndSubmitTransaction(); - setIsRestaking(currentPortfolio.length > 0); - portfolioMutators.executeCommand({ type: 'HwSkipToSuccess' }); - } catch { - portfolioMutators.executeCommand({ type: 'HwSkipToFailure' }); - } finally { - setIsConfirmingTx(false); - } - } else { - // Mnemonic wallet continues to password verification + if (isInMemory) { portfolioMutators.executeCommand({ type: 'DrawerContinue' }); + return; + } + + // HW-WALLET + setIsConfirmingTx(true); + try { + await signAndSubmitTransaction(); + setIsRestaking(currentPortfolio.length > 0); + portfolioMutators.executeCommand({ type: 'HwSkipToSuccess' }); + } catch { + portfolioMutators.executeCommand({ type: 'HwSkipToFailure' }); + } finally { + setIsConfirmingTx(false); } }, [currentPortfolio, isInMemory, portfolioMutators, setIsRestaking, signAndSubmitTransaction]); diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts index 30498ecf02..bc4b314a26 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts @@ -134,8 +134,7 @@ export type PortfolioManagementConfirmationCommand = export type PortfolioManagementSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; -// TODO: should not have DrawerBack, it's not used -export type PortfolioManagementFailureCommand = CancelDrawer | DrawerContinue | DrawerBack; +export type PortfolioManagementFailureCommand = CancelDrawer | DrawerContinue; export type PortfolioManagementSuccessCommand = CancelDrawer; @@ -157,8 +156,7 @@ export type NewPortfolioConfirmationCommand = export type NewPortfolioSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; -// TODO: should not have DrawerBack, it's not used -export type NewPortfolioFailureCommand = CancelDrawer | DrawerContinue | DrawerBack; +export type NewPortfolioFailureCommand = CancelDrawer | DrawerContinue; export type NewPortfolioSuccessCommand = CancelDrawer; diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts index 909d23a0fe..83530d31dd 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts @@ -334,10 +334,6 @@ export const processExpandedViewCases: Handler = (params) => ...atomicStateMutators.cancelDrawer({ state, targetFlow: DelegationFlow.Overview }), draftPortfolio: undefined, })), - DrawerBack: handler(({ state }) => ({ - ...state, - activeDrawerStep: DrawerManagementStep.Sign, - })), DrawerContinue: handler( ({ state }) => ({ ...state, @@ -489,11 +485,6 @@ export const processExpandedViewCases: Handler = (params) => ...atomicStateMutators.cancelDrawer({ state, targetFlow: DelegationFlow.BrowsePools }), draftPortfolio: undefined, })), - DrawerBack: handler(({ state }) => ({ - ...state, - // TODO: fix for hw wallet skip - activeDrawerStep: DrawerManagementStep.Sign, - })), DrawerContinue: handler(({ state }) => ({ ...state, activeDrawerStep: DrawerManagementStep.Success, From 8f7470a7afa930e714b8b7f16e184610cbc01661 Mon Sep 17 00:00:00 2001 From: xdzurman Date: Thu, 9 Nov 2023 10:53:46 +0100 Subject: [PATCH 6/8] feat(staking): introduce feature flags for HW wallets multidelegation --- apps/browser-extension-wallet/.env.defaults | 3 ++- apps/browser-extension-wallet/.env.example | 3 ++- .../src/hooks/useMultiDelegationEnabled.ts | 20 ++++++++++++++++++- .../src/features/Drawer/TransactionFail.tsx | 4 ++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/apps/browser-extension-wallet/.env.defaults b/apps/browser-extension-wallet/.env.defaults index fded3830dc..5a9f3df675 100644 --- a/apps/browser-extension-wallet/.env.defaults +++ b/apps/browser-extension-wallet/.env.defaults @@ -18,7 +18,8 @@ USE_DIFFERENT_MNEMONIC_LENGTHS=true USE_NFT_FOLDERS=true USE_MULTI_CURRENCY=true USE_HIDE_MY_BALANCE=true -USE_MULTI_DELEGATION_STAKING=true +USE_MULTI_DELEGATION_STAKING_LEDGER=false +USE_MULTI_DELEGATION_STAKING_TREZOR=false USE_ADA_HANDLE=true USE_DATA_CHECK=false USE_POSTHOG_ANALYTICS=true diff --git a/apps/browser-extension-wallet/.env.example b/apps/browser-extension-wallet/.env.example index f3897cd232..7bdd95bdb6 100644 --- a/apps/browser-extension-wallet/.env.example +++ b/apps/browser-extension-wallet/.env.example @@ -18,7 +18,8 @@ USE_DIFFERENT_MNEMONIC_LENGTHS=true USE_NFT_FOLDERS=true USE_MULTI_CURRENCY=true USE_HIDE_MY_BALANCE=true -USE_MULTI_DELEGATION_STAKING=true +USE_MULTI_DELEGATION_STAKING_LEDGER=false +USE_MULTI_DELEGATION_STAKING_TREZOR=false USE_ADA_HANDLE=true USE_HANDLE_AB=false USE_DATA_CHECK=false diff --git a/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts b/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts index 0135fdf8b2..f1731066f3 100644 --- a/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts +++ b/apps/browser-extension-wallet/src/hooks/useMultiDelegationEnabled.ts @@ -1 +1,19 @@ -export const useMultiDelegationEnabled = (): boolean => process.env.USE_MULTI_DELEGATION_STAKING === 'true'; +import { Wallet } from '@lace/cardano'; +import { useWalletStore } from '@src/stores'; +import { useMemo } from 'react'; + +export const useMultiDelegationEnabled = (): boolean => { + const { getKeyAgentType } = useWalletStore(); + + return useMemo(() => { + const keyAgentType = getKeyAgentType(); + switch (keyAgentType) { + case Wallet.KeyManagement.KeyAgentType.Ledger: + return process.env.USE_MULTI_DELEGATION_STAKING_LEDGER === 'true'; + case Wallet.KeyManagement.KeyAgentType.Trezor: + return process.env.USE_MULTI_DELEGATION_STAKING_TREZOR === 'true'; + default: + return true; + } + }, [getKeyAgentType]); +}; diff --git a/packages/staking/src/features/Drawer/TransactionFail.tsx b/packages/staking/src/features/Drawer/TransactionFail.tsx index 149b5d8479..369f861b5c 100644 --- a/packages/staking/src/features/Drawer/TransactionFail.tsx +++ b/packages/staking/src/features/Drawer/TransactionFail.tsx @@ -99,8 +99,8 @@ export const TransactionFailFooter = ({ popupView }: TransactionFailProps): Reac ) : (