Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retry button on transfaction failure should check old firmware error for ledger #961

Merged
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') {
rhyslbw marked this conversation as resolved.
Show resolved Hide resolved
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