-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(staking): add earnings projections to the staking modal
- Loading branch information
Showing
23 changed files
with
528 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions
32
packages/suite/src/components/suite/StakingProcess/InfoRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Badge, Column, List, Paragraph, Row } from '@trezor/components'; | ||
import { Subheading } from './Subheading'; | ||
import { RowContent, RowSubheading } from './types'; | ||
|
||
interface InfoRowProps { | ||
heading: React.ReactNode; | ||
subheading: RowSubheading; | ||
content: RowContent; | ||
isExpanded?: boolean; | ||
} | ||
|
||
export const InfoRow = ({ heading, subheading, content, isExpanded = false }: InfoRowProps) => { | ||
const displayContent = content.isBadge ? ( | ||
<Badge size="tiny">{content.text}</Badge> | ||
) : ( | ||
<Paragraph variant="tertiary" typographyStyle="hint"> | ||
{content.text} | ||
</Paragraph> | ||
); | ||
|
||
return ( | ||
<List.Item> | ||
<Row justifyContent="space-between"> | ||
<Column alignItems="normal"> | ||
{heading} | ||
<Subheading isExpanded={isExpanded} subheading={subheading} /> | ||
</Column> | ||
{displayContent} | ||
</Row> | ||
</List.Item> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/suite/src/components/suite/StakingProcess/Subheading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Icon, Paragraph, Row } from '@trezor/components'; | ||
import { Translation } from '../Translation'; | ||
import { spacings } from '@trezor/theme'; | ||
import { RowSubheading } from './types'; | ||
|
||
interface SubheadingProps { | ||
subheading: RowSubheading; | ||
isExpanded?: boolean; | ||
} | ||
|
||
export const Subheading = ({ isExpanded, subheading }: SubheadingProps) => { | ||
if (!isExpanded || !subheading) return null; | ||
|
||
return subheading.isCurrentStep ? ( | ||
<Row gap={spacings.xxs}> | ||
<Icon name="mapPinFilled" variant="warning" size="medium" /> | ||
<Paragraph variant="warning" typographyStyle="hint"> | ||
<Translation id="TR_STAKING_YOU_ARE_HERE" /> | ||
</Paragraph> | ||
</Row> | ||
) : ( | ||
<Paragraph variant="tertiary" typographyStyle="hint"> | ||
{subheading.text} | ||
</Paragraph> | ||
); | ||
}; |
87 changes: 87 additions & 0 deletions
87
packages/suite/src/components/suite/StakingProcess/UnstakingInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import { | ||
selectAccountUnstakeTransactions, | ||
selectValidatorsQueue, | ||
TransactionsRootState, | ||
StakeRootState, | ||
} from '@suite-common/wallet-core'; | ||
import { Translation } from 'src/components/suite'; | ||
import { InfoRow } from './InfoRow'; | ||
import { useSelector } from 'react-redux'; | ||
import { getDaysToUnstake } from 'src/utils/suite/stake'; | ||
import { CoinjoinRootState } from 'src/reducers/wallet/coinjoinReducer'; | ||
|
||
interface UnstakingInfoProps { | ||
isExpanded?: boolean; | ||
} | ||
|
||
export const UnstakingInfo = ({ isExpanded }: UnstakingInfoProps) => { | ||
const { account } = useSelector((state: CoinjoinRootState) => state.wallet.selectedAccount); | ||
|
||
const { data } = | ||
useSelector((state: StakeRootState) => selectValidatorsQueue(state, account?.symbol)) || {}; | ||
|
||
const unstakeTxs = useSelector((state: TransactionsRootState) => | ||
selectAccountUnstakeTransactions(state, account?.key ?? ''), | ||
); | ||
|
||
if (!account) return null; | ||
|
||
const daysToUnstake = getDaysToUnstake(unstakeTxs, data); | ||
const accountSymbol = account.symbol.toUpperCase(); | ||
|
||
const infoRows = [ | ||
{ | ||
heading: <Translation id="TR_STAKE_SIGN_UNSTAKING_TRANSACTION" />, | ||
subheading: { isCurrentStep: true }, | ||
content: { | ||
text: <Translation id="TR_COINMARKET_NETWORK_FEE" />, | ||
isBadge: true, | ||
}, | ||
}, | ||
{ | ||
heading: <Translation id="TR_STAKE_LEAVE_STAKING_POOL" />, | ||
subheading: { | ||
text: ( | ||
<Translation | ||
id="TR_STAKING_CONSOLIDATING_FUNDS" | ||
values={{ symbol: accountSymbol }} | ||
/> | ||
), | ||
}, | ||
content: { | ||
text: <Translation id="TR_STAKE_DAYS" values={{ count: daysToUnstake }} />, | ||
}, | ||
}, | ||
{ | ||
heading: ( | ||
<Translation id="TR_STAKE_CLAIM_UNSTAKED" values={{ symbol: accountSymbol }} /> | ||
), | ||
subheading: { | ||
text: ( | ||
<Translation | ||
id="TR_STAKING_YOUR_UNSTAKED_FUNDS" | ||
values={{ symbol: accountSymbol }} | ||
/> | ||
), | ||
}, | ||
content: { | ||
text: <Translation id="TR_COINMARKET_NETWORK_FEE" />, | ||
isBadge: true, | ||
}, | ||
}, | ||
{ | ||
heading: <Translation id="TR_STAKE_IN_ACCOUNT" values={{ symbol: accountSymbol }} />, | ||
subheading: null, | ||
content: { text: null }, | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
{infoRows.map(({ heading, content, subheading }, index) => ( | ||
<InfoRow key={index} {...{ heading, subheading, content, isExpanded }} /> | ||
))} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type RowSubheading = { | ||
text?: React.ReactNode; | ||
isCurrentStep?: boolean; | ||
} | null; | ||
|
||
export type RowContent = { | ||
isBadge?: boolean; | ||
text?: React.ReactNode; | ||
}; |
28 changes: 0 additions & 28 deletions
28
.../components/suite/modals/ReduxModal/UserContextModal/StakeEthInANutshellModal/InfoRow.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
...nents/suite/modals/ReduxModal/UserContextModal/StakeEthInANutshellModal/UnstakingInfo.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.