Skip to content

Commit

Permalink
fixup! feat: device modals improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dahaca committed May 25, 2022
1 parent c74f385 commit eb3dfcf
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 39 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/components/form/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const InputAddon = styled.div<{ align: AddonAlignment }>`
position: absolute;
top: 1px;
bottom: 1px;
right: ${({ align }) => align === 'right' && '16px'};
left: ${({ align }) => align === 'left' && '16px'};
right: ${({ align }) => align === 'right' && '10px'};
left: ${({ align }) => align === 'left' && '10px'};
display: flex;
align-items: center;
`;
Expand Down
17 changes: 11 additions & 6 deletions packages/suite/src/components/suite/Modal/DevicePromptModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ComponentType, useMemo } from 'react';
import ReactDOM from 'react-dom';
import styled, { css } from 'styled-components';
import TrezorConnect from 'trezor-connect';
import TrezorConnect from '@trezor/connect';
import {
ConfirmOnDevice,
Icon,
Expand Down Expand Up @@ -67,11 +67,13 @@ const AbortContainer = styled.div`
${expandedStyle}
}
${variables.MEDIA_QUERY.HOVER} {
${collapsedStyle}
/*Linting error because of a complex interpolation*/
${/* sc-selector */ variables.MEDIA_QUERY.HOVER} {
${/* sc-block */ collapsedStyle}
:hover {
${expandedStyle}
${/* sc-block */ expandedStyle}
}
}
`;
Expand Down Expand Up @@ -104,11 +106,14 @@ const DevicePromptModalRenderer = ({
...rest
}: DevicePromptModalProps) => {
const deviceVerions = useSelector(state => state.suite.device?.features?.major_version);
const bridgeVersion = useSelector(state => state.suite.transport?.version) as string;
const transport = useSelector(state => state.suite.transport);
const modalTarget = useModalTarget();
const theme = useTheme();

const isAbortable = versionUtils.isNewerOrEqual(bridgeVersion, '2.0.31');
const isAbortable =
transport?.type === 'bridge'
? versionUtils.isNewerOrEqual(transport?.version as string, '2.0.31')
: true; // Works via WebUSB

const AbortButton = useMemo(
() => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ const Wrapper = styled.div<{
`}
&:first-of-type {
padding-top: 12px;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
}
&:last-of-type {
padding-bottom: 12px;
border-bottom-left-radius: 12px;
border-bottom-right-radius: 12px;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/suite/src/views/onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { ReduxModal } from '@suite-components/ModalSwitcher/ReduxModal';
import WelcomeStep from '@onboarding-views/steps/Welcome';
import CreateOrRecover from '@onboarding-views/steps/CreateOrRecover';
import FirmwareStep from '@onboarding-views/steps/Firmware';
import ResetDeviceStep from '@suite/views/onboarding/steps/ResetDevice';
import RecoveryStep from '@onboarding-views/steps/Recovery';
import BackupStep from '@onboarding-views/steps/Backup';
import { ResetDeviceStep } from '@suite/views/onboarding/steps/ResetDevice';
import { RecoveryStep } from '@onboarding-views/steps/Recovery';
import { BackupStep } from '@onboarding-views/steps/Backup';
import SecurityStep from '@onboarding-views/steps/Security';
import SetPinStep from '@onboarding-views/steps/Pin';
import BasicSettingsStep from '@onboarding-views/steps/BasicSettings';
Expand Down
4 changes: 1 addition & 3 deletions packages/suite/src/views/onboarding/steps/Backup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const StyledImage = styled(Image)`
flex: 1;
`;

const BackupStep = () => {
export const BackupStep = () => {
const [showSkipConfirmation, setShowSkipConfirmation] = useState(false);
const { goToNextStep, backupDevice, goto, updateAnalytics } = useActions({
goToNextStep: onboardingActions.goToNextStep,
Expand Down Expand Up @@ -154,5 +154,3 @@ const BackupStep = () => {
</>
);
};

export default BackupStep;
22 changes: 15 additions & 7 deletions packages/suite/src/views/onboarding/steps/Recovery/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import TrezorConnect from '@trezor/connect';
import { OnboardingButtonCta } from '@onboarding-components';
import { SelectWordCount, SelectRecoveryType, SelectRecoveryWord } from '@recovery-components';
import { Translation } from '@suite-components';
import * as onboardingActions from '@onboarding-actions/onboardingActions';
import { useActions, useRecovery, useSelector } from '@suite-hooks';
import RecoveryStepBox from './RecoveryStepBox';

const RecoveryStep = () => {
export const RecoveryStep = () => {
const { goToNextStep, updateAnalytics } = useActions({
goToNextStep: onboardingActions.goToNextStep,
updateAnalytics: onboardingActions.updateAnalytics,
Expand Down Expand Up @@ -61,9 +62,7 @@ const RecoveryStep = () => {
innerActions={
<OnboardingButtonCta
data-test="@onboarding/recovery/start-button"
onClick={() => {
recoverDevice();
}}
onClick={recoverDevice}
>
<Translation id="TR_START_RECOVERY" />
</OnboardingButtonCta>
Expand Down Expand Up @@ -113,21 +112,32 @@ const RecoveryStep = () => {
</>
);
}

if (wordRequestInputType === 6 || wordRequestInputType === 9) {
return <Translation id="TR_ADVANCED_RECOVERY_TEXT" />;
}
};

return (
<RecoveryStepBox
heading={<Translation id="TR_RECOVER_YOUR_WALLET_FROM" />}
confirmOnDevice={model}
innerActions={
<OnboardingButtonCta
onClick={() => TrezorConnect.cancel()}
icon="CANCEL"
variant="danger"
>
<Translation id="TR_ABORT" />
</OnboardingButtonCta>
}
description={
model === 1 ? (
getModel1Description()
) : (
<Translation id="TR_RECOVER_SUBHEADING_MODEL_T" />
)
}
confirmOnDevice={model}
>
<SelectRecoveryWord />
</RecoveryStepBox>
Expand Down Expand Up @@ -171,5 +181,3 @@ const RecoveryStep = () => {
// We shouldn't get there, but to keep typescript sane let's return null
return null;
};

export default RecoveryStep;
57 changes: 39 additions & 18 deletions packages/suite/src/views/onboarding/steps/ResetDevice/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import TrezorConnect from '@trezor/connect';
import * as STEP from '@onboarding-constants/steps';
import {
OnboardingButtonBack,
Expand All @@ -7,12 +8,13 @@ import {
OptionWrapper,
OptionsDivider,
OnboardingStepBox,
OnboardingButtonCta,
} from '@onboarding-components';
import { Translation } from '@suite-components';
import { useActions, useSelector, useOnboarding } from '@suite-hooks';
import * as deviceSettingsActions from '@settings-actions/deviceSettingsActions';

const ResetDeviceStep = () => {
export const ResetDeviceStep = () => {
const [submitted, setSubmitted] = useState(false);
const { resetDevice } = useActions({
resetDevice: deviceSettingsActions.resetDevice,
Expand All @@ -35,19 +37,52 @@ const ResetDeviceStep = () => {
// eslint-disable-next-line camelcase
const onResetDevice = async (params?: { backup_type?: 0 | 1 | undefined }) => {
setSubmitted(false);

const result = await resetDevice(params);

setSubmitted(true);

if (result?.success) {
goToNextStep(STEP.ID_SECURITY_STEP);
}
};

const handleSingleseedReset = async () => {
if (isShamirBackupAvailable) {
await onResetDevice({ backup_type: 0 });
} else {
await onResetDevice();
}

updateAnalytics({ recoveryType: undefined, seedType: 'standard' });
};

const handleShamirReset = async () => {
await onResetDevice({ backup_type: 1 });

updateAnalytics({
recoveryType: undefined,
seedType: 'shamir',
});
};

return (
<OnboardingStepBox
image="KEY"
heading={<Translation id="TR_ONBOARDING_GENERATE_SEED" />}
description={<Translation id="TR_ONBOARDING_GENERATE_SEED_DESCRIPTION" />}
confirmOnDevice={isWaitingForConfirmation ? device?.features?.major_version : undefined}
innerActions={
isWaitingForConfirmation && (
<OnboardingButtonCta
onClick={() => TrezorConnect.cancel()}
icon="CANCEL"
variant="danger"
>
<Translation id="TR_ABORT" />
</OnboardingButtonCta>
)
}
outerActions={
!isWaitingForConfirmation ? (
// There is no point to show back button if user can't click it because confirmOnDevice bubble is active
Expand All @@ -68,32 +103,20 @@ const ResetDeviceStep = () => {
? '@onboarding/button-standard-backup'
: '@onboarding/only-backup-option-button'
}
onClick={async () => {
if (isShamirBackupAvailable) {
await onResetDevice({ backup_type: 0 });
} else {
await onResetDevice();
}
updateAnalytics({ recoveryType: undefined, seedType: 'standard' });
}}
onClick={handleSingleseedReset}
heading={<Translation id="SINGLE_SEED" />}
description={<Translation id="SINGLE_SEED_DESCRIPTION" />}
/>
</OptionWrapper>

{isShamirBackupAvailable && (
<>
<OptionsDivider />
<OptionWrapper>
<Option
icon="SEED_SHAMIR"
data-test="@onboarding/shamir-backup-option-button"
onClick={async () => {
await onResetDevice({ backup_type: 1 });
updateAnalytics({
recoveryType: undefined,
seedType: 'shamir',
});
}}
onClick={handleShamirReset}
heading={<Translation id="SHAMIR_SEED" />}
description={<Translation id="SHAMIR_SEED_DESCRIPTION" />}
/>
Expand All @@ -105,5 +128,3 @@ const ResetDeviceStep = () => {
</OnboardingStepBox>
);
};

export default ResetDeviceStep;

0 comments on commit eb3dfcf

Please sign in to comment.