|
1 | 1 | import {shouldShowDRep2UsOnTxHistory, useBanner} from '@yoroi/banners'
|
| 2 | +import {GOVERNANCE_YOROI_DREP_ID_HEX, useStakingKeyState} from '@yoroi/staking' |
| 3 | +import {useTheme} from '@yoroi/theme' |
2 | 4 | import {Banners} from '@yoroi/types'
|
3 | 5 | import * as React from 'react'
|
| 6 | +import {StyleSheet} from 'react-native' |
4 | 7 |
|
| 8 | +import {useStakingInfo} from '../../../legacy/Dashboard/StakePoolInfos' |
| 9 | +import {useStakingKey} from '../../../yoroi-wallets/hooks' |
| 10 | +import {usePortfolioPrimaryBalance} from '../../Portfolio/common/hooks/usePortfolioPrimaryBalance' |
| 11 | +import {mapStakingKeyStateToGovernanceAction} from '../../Staking/Governance/common/helpers' |
5 | 12 | import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'
|
6 | 13 | import {DelegateToYoroiDRepBanner} from '../common/DelegateToYoroiDRepBanner/DelegateToYoroiDRepBanner'
|
7 |
| -import {GOVERNANCE_YOROI_DREP_ID_HEX} from '@yoroi/staking' |
8 | 14 |
|
9 | 15 | export const ConsiderDRepToUsTxHistoryBanner = () => {
|
10 | 16 | const {
|
11 | 17 | wallet: {bannersManager: manager},
|
12 | 18 | } = useSelectedWallet()
|
13 | 19 | const {dismiss, dismissedAt} = useBanner({id: Banners.Id.DRep2UsTxHistory, manager})
|
| 20 | + const {styles} = useStyles() |
| 21 | + const {wallet} = useSelectedWallet() |
| 22 | + const stakingInfo = useStakingInfo(wallet, {suspense: true}) |
| 23 | + const hasStakingKeyRegistered = stakingInfo?.data?.status !== 'not-registered' |
| 24 | + const stakingKeyHash = useStakingKey(wallet) |
| 25 | + |
| 26 | + const {data: stakingStatus} = useStakingKeyState(stakingKeyHash, { |
| 27 | + refetchOnMount: true, |
| 28 | + suspense: true, |
| 29 | + }) |
| 30 | + |
| 31 | + const action = stakingStatus ? mapStakingKeyStateToGovernanceAction(stakingStatus) : null |
| 32 | + const ptDecimals = wallet?.portfolioPrimaryTokenInfo.decimals ?? 0 |
| 33 | + const balance = usePortfolioPrimaryBalance({wallet}) |
14 | 34 |
|
15 | 35 | const isVisible = shouldShowDRep2UsOnTxHistory({
|
16 | 36 | yoroiDRepIdHex: GOVERNANCE_YOROI_DREP_ID_HEX,
|
17 |
| - currentDRepIdHex: 'hi', |
18 |
| - isStaking: true, |
| 37 | + currentDRepIdHex: action?.kind === 'delegate' ? action.hash : '', |
| 38 | + isStaking: hasStakingKeyRegistered, |
19 | 39 | dismissedAt,
|
20 |
| - ptBalance: 0n, |
21 |
| - ptMinBalance: 0n, |
| 40 | + ptBalance: balance.quantity, |
| 41 | + ptMinBalance: 5n * BigInt(ptDecimals), |
| 42 | + }) |
| 43 | + |
| 44 | + return <DelegateToYoroiDRepBanner style={styles.root} onDismiss={dismiss} isVisible={isVisible} /> |
| 45 | +} |
| 46 | + |
| 47 | +const useStyles = () => { |
| 48 | + const {atoms} = useTheme() |
| 49 | + const styles = StyleSheet.create({ |
| 50 | + root: { |
| 51 | + ...atoms.px_lg, |
| 52 | + }, |
22 | 53 | })
|
23 | 54 |
|
24 |
| - return <DelegateToYoroiDRepBanner onDismiss={dismiss} isVisible={isVisible} /> |
| 55 | + return {styles} |
25 | 56 | }
|
0 commit comments