Skip to content

Commit f86c32c

Browse files
Add yoroi banner to staking dashboard
1 parent 6ff464d commit f86c32c

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
11
import {shouldShowDRep2UsOnStakingCenter, useBanner} from '@yoroi/banners'
2-
import {GOVERNANCE_YOROI_DREP_ID_HEX} from '@yoroi/staking'
2+
import {GOVERNANCE_YOROI_DREP_ID_HEX, useStakingKeyState} from '@yoroi/staking'
33
import {Banners} from '@yoroi/types'
44
import * as React from 'react'
5+
import {StyleSheet} from 'react-native'
56

67
import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'
78
import {DelegateToYoroiDRepBanner} from '../common/DelegateToYoroiDRepBanner/DelegateToYoroiDRepBanner'
9+
import {useStakingInfo} from '../../../legacy/Dashboard/StakePoolInfos'
10+
import {useStakingKey} from '../../../yoroi-wallets/hooks'
11+
import {mapStakingKeyStateToGovernanceAction} from '../../Staking/Governance/common/helpers'
12+
import {useTheme} from '@yoroi/theme'
813

914
export const ConsiderDRepToUsStakingCenterBanner = () => {
1015
const {
1116
wallet: {bannersManager: manager},
1217
} = useSelectedWallet()
1318
const {dismiss, dismissedAt} = useBanner({id: Banners.Id.DRep2UsStakingCenter, manager})
19+
const {wallet} = useSelectedWallet()
20+
const stakingInfo = useStakingInfo(wallet, {suspense: true})
21+
const hasStakingKeyRegistered = stakingInfo?.data?.status !== 'not-registered'
22+
const stakingKeyHash = useStakingKey(wallet)
23+
24+
const {data: stakingStatus} = useStakingKeyState(stakingKeyHash, {
25+
refetchOnMount: true,
26+
suspense: true,
27+
})
28+
29+
const styles = useStyles()
30+
31+
const action = stakingStatus ? mapStakingKeyStateToGovernanceAction(stakingStatus) : null
1432

1533
const isVisible = shouldShowDRep2UsOnStakingCenter({
1634
yoroiDRepIdHex: GOVERNANCE_YOROI_DREP_ID_HEX,
17-
currentDRepIdHex: 'hi',
18-
isStaking: true,
35+
currentDRepIdHex: action?.kind === 'delegate' && action.type === 'key' ? action.hash : '',
36+
isStaking: hasStakingKeyRegistered,
1937
dismissedAt,
2038
})
2139

22-
return <DelegateToYoroiDRepBanner onDismiss={dismiss} isVisible={isVisible} />
40+
return <DelegateToYoroiDRepBanner style={styles.root} onDismiss={dismiss} isVisible={isVisible} />
41+
}
42+
43+
const useStyles = () => {
44+
const {atoms} = useTheme()
45+
return StyleSheet.create({
46+
root: {
47+
...atoms.pb_xl,
48+
},
49+
})
2350
}

apps/wallet-mobile/src/features/Banners/useCases/ConsiderDRepToUsTxHistoryBanner.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {mapStakingKeyStateToGovernanceAction} from '../../Staking/Governance/com
1212
import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'
1313
import {DelegateToYoroiDRepBanner} from '../common/DelegateToYoroiDRepBanner/DelegateToYoroiDRepBanner'
1414

15+
const minBalanceToDisplayBanner = 5 // 5 ADA
16+
1517
export const ConsiderDRepToUsTxHistoryBanner = () => {
1618
const {
1719
wallet: {bannersManager: manager},
@@ -38,7 +40,7 @@ export const ConsiderDRepToUsTxHistoryBanner = () => {
3840
isStaking: hasStakingKeyRegistered,
3941
dismissedAt,
4042
ptBalance: balance.quantity,
41-
ptMinBalance: 5n * BigInt(ptDecimals),
43+
ptMinBalance: BigInt(minBalanceToDisplayBanner) * BigInt(ptDecimals),
4244
})
4345

4446
return <DelegateToYoroiDRepBanner style={styles.root} onDismiss={dismiss} isVisible={isVisible} />

apps/wallet-mobile/src/legacy/Dashboard/Dashboard.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {NotDelegatedInfo} from './NotDelegatedInfo'
3838
import {StakePoolInfos, useStakingInfo} from './StakePoolInfos'
3939
import {UserSummary} from './UserSummary'
4040
import {useWithdrawStakingRewardsStrings, WithdrawStakingRewards} from './WithdrawStakingRewards/WithdrawStakingRewards'
41+
import {ConsiderDRepToUsStakingCenterBanner} from '../../features/Banners/useCases/ConsiderDRepToUsStakingCenterBanner'
4142

4243
export const Dashboard = () => {
4344
const strings = useWithdrawStakingRewardsStrings()
@@ -101,6 +102,7 @@ export const Dashboard = () => {
101102
/>
102103
}
103104
>
105+
<ConsiderDRepToUsStakingCenterBanner />
104106
{stakingInfo?.status !== 'staked' && (
105107
<>
106108
<NotDelegatedInfo />

apps/wallet-mobile/translations/messages/src/legacy/Dashboard/Dashboard.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"defaultMessage": "!!!Go to Staking Center",
55
"file": "src/legacy/Dashboard/Dashboard.tsx",
66
"start": {
7-
"line": 237,
7+
"line": 239,
88
"column": 23,
9-
"index": 7685
9+
"index": 7855
1010
},
1111
"end": {
12-
"line": 240,
12+
"line": 242,
1313
"column": 3,
14-
"index": 7818
14+
"index": 7988
1515
}
1616
}
1717
]

0 commit comments

Comments
 (0)