Skip to content

Commit

Permalink
feat(staking): enable success and failure steps in staking drawer (#267)
Browse files Browse the repository at this point in the history
* chore(all): fix gitignore pattern

* feat(staking): enable success and failure steps in staking drawer

* feat(staking): add different staking error icon for popupView

---------

Co-authored-by: Szymon Masłowski <szymon.maslowski@iohk.io>
  • Loading branch information
przemyslaw-wlodek and szymonmaslowski authored Jul 17, 2023
1 parent 75855e2 commit 3e62376
Show file tree
Hide file tree
Showing 16 changed files with 473 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ coverage
/.cache

# Nix
result*
result
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const MultiDelegationStaking = (): JSX.Element => {
selectedStakePool
} = useDelegationStore();
const openExternalLink = useExternalLinkOpener();
const { password, setPassword, removePassword } = usePassword();
const password = usePassword();
const submittingState = useSubmitingState();
const { priceResult } = useFetchCoinPrice();
const { balance } = useBalances(priceResult?.cardano?.price);
Expand Down Expand Up @@ -53,16 +53,13 @@ export const MultiDelegationStaking = (): JSX.Element => {
fetchCoinPricePriceResult: priceResult,
openExternalLink,
password,
setPassword,
passwordRemovePassword: removePassword,
passwordSetPassword: setPassword,
stakingRewards,
submittingState,
walletStoreGetKeyAgentType: getKeyAgentType,
walletStoreInMemoryWallet: inMemoryWallet,
walletStoreWalletUICardanoCoin: cardanoCoin,
currencyStoreFiatCurrency: fiatCurrency,
executeWithPassword
walletManagerExecuteWithPassword: executeWithPassword
}}
>
<Staking theme={theme.name} />
Expand Down
60 changes: 60 additions & 0 deletions packages/staking/src/features/drawer/ResultMessage.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@import '../../../../../packages/common/src/ui/styles/theme.scss';
@import '../../../../../packages/common/src/ui/styles/abstracts/typography';

.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: size_unit(4);

.title {
color: var(--text-color-primary);
font-size: var(--heading);
font-weight: 700;
line-height: size_unit(5);
letter-spacing: -0.015em;
text-align: center;
margin-bottom: 0 !important;

max-width: 435px;

@media (max-width: $breakpoint-popup) {
font-size: var(--heading);
line-height: size_unit(4);
margin-bottom: 0;
}
}

.description {
color: var(--text-color-secondary) !important;
font-size: var(--body);
font-weight: 500;
line-height: size_unit(3);
text-align: center;
margin-bottom: 0 !important;
max-width: 450px;
padding: 10px;

@media (max-width: $breakpoint-popup) {
max-width: 260px;
padding: 0;
font-size: var(--body);
line-height: size_unit(3);
margin-bottom: 0;
}
}
.vertical {
display: flex;
flex-direction: column;
align-items: center;
gap: size_unit(2);
}
.img {
height: size_unit(14);
width: size_unit(14);
@media (max-width: $breakpoint-popup) {
width: size_unit(11);
}
}
}
48 changes: 48 additions & 0 deletions packages/staking/src/features/drawer/ResultMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import ExclamationSmall from './exclamation-circle-small.svg';
import Exclamation from './exclamation-circle.svg';
import styles from './ResultMessage.module.scss';
import Success from './success-staking.svg';

type Status = 'success' | 'error';

const iconByStatus: Record<Status, React.FC<React.SVGProps<SVGSVGElement>>> = {
error: Exclamation,
success: Success,
};

// TODO discuss with design team if we can have 1 error icon and just manipulate its size
const popupViewIconByStatus: Record<Status, React.FC<React.SVGProps<SVGSVGElement>>> = {
...iconByStatus,
error: ExclamationSmall,
};

export interface ResultMessageProps {
status?: Status;
title: React.ReactNode;
description: React.ReactNode;
popupView?: boolean;
}

export const ResultMessage = ({
status = 'success',
title,
description,
popupView,
}: ResultMessageProps): React.ReactElement => {
const Icon = popupView ? popupViewIconByStatus[status] : iconByStatus[status];

return (
<div className={styles.content} data-testid="result-message-content">
<Icon className={styles.img} data-testid="result-message-img" />
<div className={styles.vertical}>
<h4 className={styles.title} data-testid="result-message-title">
{title}
</h4>
<h5 className={styles.description} data-testid="result-message-description">
{description}
</h5>
</div>
</div>
);
};
31 changes: 17 additions & 14 deletions packages/staking/src/features/drawer/SignConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cn from 'classnames';
import React, { ReactElement, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useOutsideHandles } from '../outside-handles-provider';
import { useDelegationPortfolioStore, useStakePoolDetails } from '../store';
import { Sections, sectionsConfig, useDelegationPortfolioStore, useStakePoolDetails } from '../store';
import styles from './SignConfirmation.module.scss';

interface SignConfirmationProps {
Expand All @@ -14,8 +14,7 @@ interface SignConfirmationProps {
export const SignConfirmation = ({ popupView }: SignConfirmationProps): React.ReactElement => {
const { t } = useTranslation();
const {
password,
passwordSetPassword: setPassword,
password: { password, setPassword },
submittingState: { isPasswordValid },
} = useOutsideHandles();

Expand Down Expand Up @@ -54,19 +53,18 @@ export const SignConfirmation = ({ popupView }: SignConfirmationProps): React.Re
export const SignConfirmationFooter = ({ popupView }: SignConfirmationProps): ReactElement => {
const {
walletStoreInMemoryWallet: inMemoryWallet,
password,
passwordRemovePassword: removePassword,
password: { password, removePassword },
submittingState: { setSubmitingTxState, isSubmitingTx, setIsRestaking },
delegationStoreDelegationTxBuilder: delegationTxBuilder,
delegationDetails,
executeWithPassword,
walletManagerExecuteWithPassword: executeWithPassword,
} = useOutsideHandles();
const { draftPortfolio, portfolioMutators } = useDelegationPortfolioStore((store) => ({
draftPortfolio: store.draftPortfolio,
portfolioMutators: store.mutators,
}));
const { t } = useTranslation();
const { setPrevSection, setIsDrawerVisible } = useStakePoolDetails();
const { setSection } = useStakePoolDetails();
const rewardAccounts = useObservable(inMemoryWallet.delegation.rewardAccounts$);
const isDelegating = !!(rewardAccounts && (delegationDetails || draftPortfolio.length > 0));

Expand Down Expand Up @@ -106,24 +104,29 @@ export const SignConfirmationFooter = ({ popupView }: SignConfirmationProps): Re
cleanPasswordInput();
sendAnalytics();
setIsRestaking(isDelegating);
// v TODO replace this block with setSection(sectionsConfig[Sections.SUCCESS_TX]); when Success section is implemented
setIsDrawerVisible(false);
setPrevSection();
setPrevSection();
portfolioMutators.clearDraft();
// ^ TODO replace this block with setSection(sectionsConfig[Sections.SUCCESS_TX]); when Success section is implemented
setSection(sectionsConfig[Sections.SUCCESS_TX]);
setSubmitingTxState({ isPasswordValid: true, isSubmitingTx: false });
} catch (error) {
// Error name is 'AuthenticationError' in dev build but 'W' in prod build
// @ts-ignore TODO
if (error.message?.includes('Authentication failure')) {
setSubmitingTxState({ isPasswordValid: false, isSubmitingTx: false });
} else {
// setSection(sectionsConfig[Sections.FAIL_TX]);
setSection(sectionsConfig[Sections.FAIL_TX]);
setSubmitingTxState({ isSubmitingTx: false });
}
}
}, [setSubmitingTxState, signAndSubmitTransaction, cleanPasswordInput, sendAnalytics, setIsRestaking, isDelegating]);
}, [
setSubmitingTxState,
signAndSubmitTransaction,
cleanPasswordInput,
sendAnalytics,
setIsRestaking,
isDelegating,
portfolioMutators,
setSection,
]);

return (
<div className={styles.footer}>
Expand Down
10 changes: 6 additions & 4 deletions packages/staking/src/features/drawer/StakePoolDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { SignConfirmation, SignConfirmationFooter } from './SignConfirmation';
import { StakePoolConfirmation, StakePoolConfirmationFooter } from './StakePoolConfirmation';
import { StakePoolDetail, StakePoolDetailFooter } from './StakePoolDetail';
import { StakePoolDetailsDrawer } from './StakePoolDetailsDrawer';
import { TransactionFail, TransactionFailFooter } from './TransactionFail';
import { TransactionSuccess, TransactionSuccessFooter } from './TransactionSuccess';

type stakePoolDetailsProps = {
onStake: () => void;
Expand Down Expand Up @@ -38,8 +40,8 @@ export const StakePoolDetails = ({
[Sections.DETAIL]: <StakePoolDetail />,
[Sections.CONFIRMATION]: <StakePoolConfirmation />,
[Sections.SIGN]: <SignConfirmation />,
[Sections.SUCCESS_TX]: <div />,
[Sections.FAIL_TX]: <div />,
[Sections.SUCCESS_TX]: <TransactionSuccess />,
[Sections.FAIL_TX]: <TransactionFail />,
}),
[]
);
Expand All @@ -49,8 +51,8 @@ export const StakePoolDetails = ({
[Sections.DETAIL]: <StakePoolDetailFooter canDelegate={canDelegate} onStake={onStake} />,
[Sections.CONFIRMATION]: <StakePoolConfirmationFooter />,
[Sections.SIGN]: <SignConfirmationFooter />,
[Sections.SUCCESS_TX]: <div />,
[Sections.FAIL_TX]: <div />,
[Sections.SUCCESS_TX]: <TransactionSuccessFooter />,
[Sections.FAIL_TX]: <TransactionFailFooter />,
}),
[onStake, canDelegate]
);
Expand Down
11 changes: 5 additions & 6 deletions packages/staking/src/features/drawer/StakePoolDetailsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export const StakePoolDetailsDrawer = ({
backgroundServiceAPIContextSetWalletPassword,
delegationStoreSetDelegationTxBuilder,
walletStoreGetKeyAgentType,
password,
passwordRemovePassword,
password: { password, removePassword },
submittingState: { setIsRestaking },
} = useOutsideHandles();

Expand All @@ -53,7 +52,7 @@ export const StakePoolDetailsDrawer = ({
backgroundServiceAPIContextSetWalletPassword();
delegationStoreSetDelegationTxBuilder();
resetStates();
passwordRemovePassword();
removePassword();
// TODO: Remove this once we pay the `keyAgent.signTransaction` Ledger tech debt up (so we are able to stake multiple times without reloading).
// if (!isInMemory && isSuccessSection) window.location.reload();
setIsDrawerVisible(false);
Expand All @@ -66,7 +65,7 @@ export const StakePoolDetailsDrawer = ({
backgroundServiceAPIContextSetWalletPassword,
delegationStoreSetDelegationTxBuilder,
resetStates,
passwordRemovePassword,
removePassword,
// isInMemory,
// isSuccessSection,
setIsDrawerVisible,
Expand All @@ -76,7 +75,7 @@ export const StakePoolDetailsDrawer = ({
const onArrowIconClick = useCallback(() => {
if (password) {
backgroundServiceAPIContextSetWalletPassword();
passwordRemovePassword();
removePassword();
}
if (simpleSendConfig.currentSection === Sections.CONFIRMATION && !isInMemory) {
return setSection(sectionsConfig[Sections.DETAIL]);
Expand All @@ -89,7 +88,7 @@ export const StakePoolDetailsDrawer = ({
closeDrawer,
isInMemory,
password,
passwordRemovePassword,
removePassword,
setPrevSection,
setSection,
simpleSendConfig.currentSection,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
@import '../../../../../packages/common/src/ui/styles/theme.scss';

.container {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
}

.header {
.title {
align-items: center;
color: var(--text-color-black);
display: flex;
font-size: var(--heading);
font-weight: bold;
line-height: size_unit(4);
}
.subTitle {
color: var(--text-color-secondary);
font-size: var(--bodyLarge);
font-weight: 600;
line-height: size_unit(3);
margin-top: size_unit(2);
}
}

.password {
display: flex;
justify-content: center;
}

.footer {
.confirmBtn {
width: 100%;
}
}

.footerFail {
display: flex;
gap: size_unit(2);
justify-content: space-between;
flex-direction: column-reverse;
}

.popupView {
&.container {
.header {
padding-left: size_unit(3);
padding-right: size_unit(3);
.title {
font-weight: 700;
font-size: var(-subHeading);
line-height: size_unit(4);
}
.subTitle {
font-size: var(--body);
margin-top: size_unit(2);
}
}
img {
max-width: initial;
max-height: initial;
}
&.fail {
img {
width: 100px;
max-width: initial;
}
}
.footer,
.footerFail {
box-shadow: 0px -2px 4px rgba(0, 0, 0, 0.05);
padding: size_unit(2) size_unit(3) 0px size_unit(3);
}
}
}

.containerFail {
display: flex;
align-items: center;
height: 80%;
justify-content: center;
}
Loading

0 comments on commit 3e62376

Please sign in to comment.