From 517892591dedbd25688c3399c22b213c9244394c Mon Sep 17 00:00:00 2001 From: Angel Castillo Date: Mon, 18 Mar 2024 16:41:58 +0800 Subject: [PATCH 1/3] fix: retry button on transfaction failure should check old firmware error for ledger --- .../src/features/Drawer/TransactionFail.tsx | 21 +++++++++++++++++-- .../stateMachine/commands.ts | 4 ++-- .../stateMachine/processExpandedViewCases.ts | 12 +++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/staking/src/features/Drawer/TransactionFail.tsx b/packages/staking/src/features/Drawer/TransactionFail.tsx index 26e441cf5..f64908d99 100644 --- a/packages/staking/src/features/Drawer/TransactionFail.tsx +++ b/packages/staking/src/features/Drawer/TransactionFail.tsx @@ -1,4 +1,5 @@ /* eslint-disable react/no-multi-comp */ +import { WalletType } from '@cardano-sdk/web-extension'; import { Button } from '@lace/common'; import cn from 'classnames'; import React, { useCallback, useState } from 'react'; @@ -30,10 +31,12 @@ export const TransactionFailFooter = ({ popupView }: TransactionFailProps): Reac const [isLoading, setIsLoading] = useState(false); const { delegationStoreSetDelegationTxBuilder: setDelegationTxBuilder, + walletStoreWalletType: walletType, delegationStoreDelegationTxBuilder: delegationTxBuilder, password: { password, removePassword }, walletStoreInMemoryWallet: inMemoryWallet, walletManagerExecuteWithPassword: executeWithPassword, + isMultidelegationSupportedByDevice, } = useOutsideHandles(); // TODO implement analytics for the new flow const analytics = { @@ -57,23 +60,37 @@ export const TransactionFailFooter = ({ popupView }: TransactionFailProps): Reac portfolioMutators.executeCommand({ type: 'CancelDrawer' }); }; + const isInMemory = walletType === WalletType.InMemory; + // TODO unify const signAndSubmitTransaction = useCallback(async () => { if (!delegationTxBuilder) throw new Error('Unable to submit transaction. The delegationTxBuilder not available'); + + if (!isInMemory) { + const isSupported = await isMultidelegationSupportedByDevice(walletType); + if (!isSupported) { + throw new Error('MULTIDELEGATION_NOT_SUPPORTED'); + } + } const signedTx = await delegationTxBuilder.build().sign(); await inMemoryWallet.submitTx(signedTx); - }, [delegationTxBuilder, inMemoryWallet]); + }, [delegationTxBuilder, inMemoryWallet, isInMemory, isMultidelegationSupportedByDevice, walletType]); const onSubmit = async () => { setIsLoading(true); + try { await signAndSubmitTransaction(); setIsLoading(false); portfolioMutators.executeCommand({ type: 'DrawerContinue' }); removePassword(); - } catch (error) { + } catch (error: unknown) { console.error('failed to sign or submit tx due to:', error); setIsLoading(false); + + if (error instanceof Error && error.message === 'MULTIDELEGATION_NOT_SUPPORTED') { + portfolioMutators.executeCommand({ type: 'HwSkipToDeviceFailure' }); + } } }; diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts index 9391ee340..c1f363f3f 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/commands.ts @@ -181,7 +181,7 @@ export type PortfolioManagementConfirmationCommand = export type PortfolioManagementSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; -export type PortfolioManagementFailureCommand = CancelDrawer | DrawerContinue; +export type PortfolioManagementFailureCommand = CancelDrawer | DrawerContinue | HwSkipToDeviceFailure; export type PortfolioManagementHwFailureCommand = CancelDrawer | DrawerBack; @@ -206,7 +206,7 @@ export type NewPortfolioConfirmationCommand = export type NewPortfolioSignCommand = CancelDrawer | DrawerContinue | DrawerFailure | DrawerBack; -export type NewPortfolioFailureCommand = CancelDrawer | DrawerContinue; +export type NewPortfolioFailureCommand = CancelDrawer | DrawerContinue | HwSkipToDeviceFailure; export type NewPortfolioHwFailureCommand = CancelDrawer | DrawerBack; diff --git a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts index 498f2f428..076258008 100644 --- a/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts +++ b/packages/staking/src/features/store/delegationPortfolioStore/stateMachine/processExpandedViewCases.ts @@ -425,6 +425,12 @@ export const processExpandedViewCases: Handler = (params) => activeDrawerStep: DrawerManagementStep.Success, }) ), + HwSkipToDeviceFailure: handler( + ({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.HwDeviceFailure, + }) + ), }, params.command.type, DrawerManagementStep.Failure @@ -593,6 +599,12 @@ export const processExpandedViewCases: Handler = (params) => ...state, activeDrawerStep: DrawerManagementStep.Success, })), + HwSkipToDeviceFailure: handler( + ({ state }) => ({ + ...state, + activeDrawerStep: DrawerManagementStep.HwDeviceFailure, + }) + ), }, params.command.type, DrawerManagementStep.Failure From 971761c77ec98657bd631a99680fbcf7f5085fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Hora=C4=8Dek?= Date: Wed, 3 Apr 2024 10:08:13 +0200 Subject: [PATCH 2/3] fix: enable single pool delegation on tx failure re-try button click --- packages/staking/src/features/Drawer/TransactionFail.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/staking/src/features/Drawer/TransactionFail.tsx b/packages/staking/src/features/Drawer/TransactionFail.tsx index f64908d99..493e35db9 100644 --- a/packages/staking/src/features/Drawer/TransactionFail.tsx +++ b/packages/staking/src/features/Drawer/TransactionFail.tsx @@ -43,7 +43,8 @@ export const TransactionFailFooter = ({ popupView }: TransactionFailProps): Reac // eslint-disable-next-line @typescript-eslint/no-empty-function sendEvent: () => {}, }; - const { portfolioMutators } = useDelegationPortfolioStore((store) => ({ + const { portfolioMutators, draftPortfolio } = useDelegationPortfolioStore((store) => ({ + draftPortfolio: store.draftPortfolio, portfolioMutators: store.mutators, })); @@ -66,7 +67,8 @@ export const TransactionFailFooter = ({ popupView }: TransactionFailProps): Reac const signAndSubmitTransaction = useCallback(async () => { if (!delegationTxBuilder) throw new Error('Unable to submit transaction. The delegationTxBuilder not available'); - if (!isInMemory) { + const isMultidelegation = draftPortfolio && draftPortfolio.length > 1; + if (!isInMemory && isMultidelegation) { const isSupported = await isMultidelegationSupportedByDevice(walletType); if (!isSupported) { throw new Error('MULTIDELEGATION_NOT_SUPPORTED'); From a93f1c93a2dc542d82afa7a1d55c72450a9af525 Mon Sep 17 00:00:00 2001 From: Piotr Czeglik Date: Tue, 23 Apr 2024 12:01:46 +0200 Subject: [PATCH 3/3] fix: remove eslint warning --- packages/staking/src/features/Drawer/TransactionFail.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/staking/src/features/Drawer/TransactionFail.tsx b/packages/staking/src/features/Drawer/TransactionFail.tsx index 493e35db9..bca9b13fe 100644 --- a/packages/staking/src/features/Drawer/TransactionFail.tsx +++ b/packages/staking/src/features/Drawer/TransactionFail.tsx @@ -76,7 +76,7 @@ export const TransactionFailFooter = ({ popupView }: TransactionFailProps): Reac } const signedTx = await delegationTxBuilder.build().sign(); await inMemoryWallet.submitTx(signedTx); - }, [delegationTxBuilder, inMemoryWallet, isInMemory, isMultidelegationSupportedByDevice, walletType]); + }, [delegationTxBuilder, draftPortfolio, inMemoryWallet, isInMemory, isMultidelegationSupportedByDevice, walletType]); const onSubmit = async () => { setIsLoading(true);