-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
126 additions
and
80 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
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
77 changes: 0 additions & 77 deletions
77
packages/suite/src/components/wallet/WalletLayout/AccountBanners/StakeEthBanner.tsx
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
packages/suite/src/components/wallet/WalletLayout/AccountBanners/StakingBanner.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,120 @@ | ||
import { useTheme } from 'styled-components'; | ||
|
||
import { Button, Text, IconButton, Row, Banner, Column } from '@trezor/components'; | ||
import { spacings } from '@trezor/theme'; | ||
import { Account } from '@suite-common/wallet-types'; | ||
import { selectPoolStatsApyData } from '@suite-common/wallet-core'; | ||
import { | ||
MIN_ETH_AMOUNT_FOR_STAKING, | ||
MIN_SOL_AMOUNT_FOR_STAKING, | ||
} from '@suite-common/wallet-constants'; | ||
import { | ||
isSupportedEthStakingNetworkSymbol, | ||
isSupportedSolStakingNetworkSymbol, | ||
} from '@suite-common/wallet-utils'; | ||
import { getNetworkDisplaySymbol, NetworkType } from '@suite-common/wallet-config'; | ||
|
||
import { Translation } from 'src/components/suite'; | ||
import { goto } from 'src/actions/suite/routerActions'; | ||
import { useDispatch, useSelector } from 'src/hooks/suite'; | ||
import { setFlag } from 'src/actions/suite/suiteActions'; | ||
|
||
import { selectSuiteFlags } from '../../../../reducers/suite/suiteReducer'; | ||
|
||
interface StakingBannerProps { | ||
account: Account; | ||
} | ||
|
||
export const StakingBanner = ({ account }: StakingBannerProps) => { | ||
const dispatch = useDispatch(); | ||
const { stakeEthBannerClosed, stakeSolBannerClosed } = useSelector(selectSuiteFlags); | ||
const { route } = useSelector(state => state.router); | ||
const apy = useSelector(state => selectPoolStatsApyData(state, account.symbol)); | ||
const theme = useTheme(); | ||
|
||
const closeBanner = () => { | ||
switch (account.networkType) { | ||
case 'ethereum': | ||
dispatch(setFlag('stakeEthBannerClosed', true)); | ||
break; | ||
case 'solana': | ||
dispatch(setFlag('stakeSolBannerClosed', true)); | ||
break; | ||
} | ||
}; | ||
|
||
const goToStakingTab = () => { | ||
dispatch(goto('wallet-staking', { preserveParams: true })); | ||
}; | ||
|
||
const getNetworkDetails = (networkType: NetworkType) => { | ||
switch (networkType) { | ||
case 'ethereum': | ||
return { | ||
isStakingBannerClosed: stakeEthBannerClosed, | ||
minStakingAmount: MIN_ETH_AMOUNT_FOR_STAKING, | ||
isSupportedStakingNetworkSymbol: isSupportedEthStakingNetworkSymbol( | ||
account.symbol, | ||
), | ||
}; | ||
case 'solana': | ||
return { | ||
isStakingBannerClosed: stakeSolBannerClosed, | ||
minStakingAmount: MIN_SOL_AMOUNT_FOR_STAKING, | ||
isSupportedStakingNetworkSymbol: isSupportedSolStakingNetworkSymbol( | ||
account.symbol, | ||
), | ||
}; | ||
default: | ||
return { | ||
isStakingBannerClosed: true, | ||
minStakingAmount: undefined, | ||
isSupportedStakingNetworkSymbol: false, | ||
}; | ||
} | ||
}; | ||
|
||
const { isStakingBannerClosed, minStakingAmount, isSupportedStakingNetworkSymbol } = | ||
getNetworkDetails(account.networkType) ?? {}; | ||
|
||
if ( | ||
route?.name !== 'wallet-index' || | ||
isStakingBannerClosed || | ||
!account || | ||
!isSupportedStakingNetworkSymbol | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Banner | ||
variant="tertiary" | ||
icon="piggyBankFilled" | ||
rightContent={ | ||
<Row gap={8}> | ||
<Button size="small" onClick={goToStakingTab} textWrap={false}> | ||
<Translation id="TR_STAKE_LEARN_MORE" /> | ||
</Button> | ||
<IconButton size="small" variant="tertiary" icon="x" onClick={closeBanner} /> | ||
</Row> | ||
} | ||
> | ||
<Column gap={4} alignItems="flex-start" flex="1" margin={{ left: spacings.xs }}> | ||
<Text color={theme.textSubdued} typographyStyle="callout"> | ||
<Translation id="TR_STAKE_ETH_EARN_REPEAT" /> | ||
</Text> | ||
|
||
<Text typographyStyle="body" textWrap="balance"> | ||
<Translation | ||
id="TR_STAKE_ANY_AMOUNT_ETH" | ||
values={{ | ||
apyPercent: apy, | ||
networkDisplaySymbol: getNetworkDisplaySymbol(account.symbol), | ||
amount: minStakingAmount?.toString(), | ||
}} | ||
/> | ||
</Text> | ||
</Column> | ||
</Banner> | ||
); | ||
}; |
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
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