Skip to content

Commit

Permalink
fix: retry button on transfaction failure should check old firmware e…
Browse files Browse the repository at this point in the history
…rror for ledger
  • Loading branch information
AngelCastilloB authored and tomislavhoracek committed Apr 3, 2024
1 parent 1045749 commit 5178925
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
21 changes: 19 additions & 2 deletions packages/staking/src/features/Drawer/TransactionFail.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,10 +31,12 @@ export const TransactionFailFooter = ({ popupView }: TransactionFailProps): Reac
const [isLoading, setIsLoading] = useState<boolean>(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 = {
Expand All @@ -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' });
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ export const processExpandedViewCases: Handler = (params) =>
activeDrawerStep: DrawerManagementStep.Success,
})
),
HwSkipToDeviceFailure: handler<HwSkipToDeviceFailure, StatePortfolioManagement, StatePortfolioManagement>(
({ state }) => ({
...state,
activeDrawerStep: DrawerManagementStep.HwDeviceFailure,
})
),
},
params.command.type,
DrawerManagementStep.Failure
Expand Down Expand Up @@ -593,6 +599,12 @@ export const processExpandedViewCases: Handler = (params) =>
...state,
activeDrawerStep: DrawerManagementStep.Success,
})),
HwSkipToDeviceFailure: handler<HwSkipToDeviceFailure, StatePortfolioManagement, StatePortfolioManagement>(
({ state }) => ({
...state,
activeDrawerStep: DrawerManagementStep.HwDeviceFailure,
})
),
},
params.command.type,
DrawerManagementStep.Failure
Expand Down

0 comments on commit 5178925

Please sign in to comment.