Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet-mobile): Add delegate to Yoroi banners #3863

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
import {shouldShowDRep2UsOnStakingCenter, useBanner} from '@yoroi/banners'

Check failure on line 1 in apps/wallet-mobile/src/features/Banners/useCases/ConsiderDRepToUsStakingCenterBanner.tsx

View workflow job for this annotation

GitHub Actions / check

Run autofix to sort these imports!
import {GOVERNANCE_YOROI_DREP_ID_HEX} from '@yoroi/staking'
import {GOVERNANCE_YOROI_DREP_ID_HEX, useStakingKeyState} from '@yoroi/staking'
import {Banners} from '@yoroi/types'
import * as React from 'react'
import {StyleSheet} from 'react-native'

import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'
import {DelegateToYoroiDRepBanner} from '../common/DelegateToYoroiDRepBanner/DelegateToYoroiDRepBanner'
import {useStakingInfo} from '../../../legacy/Dashboard/StakePoolInfos'
import {useStakingKey} from '../../../yoroi-wallets/hooks'
import {mapStakingKeyStateToGovernanceAction} from '../../Staking/Governance/common/helpers'
import {useTheme} from '@yoroi/theme'

export const ConsiderDRepToUsStakingCenterBanner = () => {
const {
wallet: {bannersManager: manager},
} = useSelectedWallet()
const {dismiss, dismissedAt} = useBanner({id: Banners.Id.DRep2UsStakingCenter, manager})
const {wallet} = useSelectedWallet()
const stakingInfo = useStakingInfo(wallet, {suspense: true})
const hasStakingKeyRegistered = stakingInfo?.data?.status !== 'not-registered'
const stakingKeyHash = useStakingKey(wallet)

const {data: stakingStatus} = useStakingKeyState(stakingKeyHash, {
refetchOnMount: true,
suspense: true,
})

const styles = useStyles()

const action = stakingStatus ? mapStakingKeyStateToGovernanceAction(stakingStatus) : null

const isVisible = shouldShowDRep2UsOnStakingCenter({
yoroiDRepIdHex: GOVERNANCE_YOROI_DREP_ID_HEX,
currentDRepIdHex: 'hi',
isStaking: true,
currentDRepIdHex: action?.kind === 'delegate' && action.type === 'key' ? action.hash : '',
isStaking: hasStakingKeyRegistered,
dismissedAt,
})

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

const useStyles = () => {
const {atoms} = useTheme()
return StyleSheet.create({
root: {

Check failure on line 46 in apps/wallet-mobile/src/features/Banners/useCases/ConsiderDRepToUsStakingCenterBanner.tsx

View workflow job for this annotation

GitHub Actions / check

Unused style detected: undefined.root
...atoms.pb_xl,
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {mapStakingKeyStateToGovernanceAction} from '../../Staking/Governance/com
import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'
import {DelegateToYoroiDRepBanner} from '../common/DelegateToYoroiDRepBanner/DelegateToYoroiDRepBanner'

const minBalanceToDisplayBanner = 5 // 5 ADA

export const ConsiderDRepToUsTxHistoryBanner = () => {
const {
wallet: {bannersManager: manager},
Expand All @@ -38,7 +40,7 @@ export const ConsiderDRepToUsTxHistoryBanner = () => {
isStaking: hasStakingKeyRegistered,
dismissedAt,
ptBalance: balance.quantity,
ptMinBalance: 5n * BigInt(ptDecimals),
ptMinBalance: BigInt(minBalanceToDisplayBanner) * BigInt(ptDecimals),
})

return <DelegateToYoroiDRepBanner style={styles.root} onDismiss={dismiss} isVisible={isVisible} />
Expand Down
2 changes: 2 additions & 0 deletions apps/wallet-mobile/src/legacy/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {useNavigation} from '@react-navigation/native'

Check failure on line 2 in apps/wallet-mobile/src/legacy/Dashboard/Dashboard.tsx

View workflow job for this annotation

GitHub Actions / check

Run autofix to sort these imports!
import {StackNavigationProp} from '@react-navigation/stack'
import {useTheme} from '@yoroi/theme'
import BigNumber from 'bignumber.js'
Expand Down Expand Up @@ -38,6 +38,7 @@
import {StakePoolInfos, useStakingInfo} from './StakePoolInfos'
import {UserSummary} from './UserSummary'
import {useWithdrawStakingRewardsStrings, WithdrawStakingRewards} from './WithdrawStakingRewards/WithdrawStakingRewards'
import {ConsiderDRepToUsStakingCenterBanner} from '../../features/Banners/useCases/ConsiderDRepToUsStakingCenterBanner'

export const Dashboard = () => {
const strings = useWithdrawStakingRewardsStrings()
Expand Down Expand Up @@ -101,7 +102,8 @@
/>
}
>
<ConsiderDRepToUsStakingCenterBanner />
{stakingInfo?.status !== 'staked' && (

Check warning on line 106 in apps/wallet-mobile/src/legacy/Dashboard/Dashboard.tsx

View workflow job for this annotation

GitHub Actions / check

JSX element should start in a new line
<>
<NotDelegatedInfo />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"defaultMessage": "!!!Go to Staking Center",
"file": "src/legacy/Dashboard/Dashboard.tsx",
"start": {
"line": 237,
"line": 239,
"column": 23,
"index": 7685
"index": 7855
},
"end": {
"line": 240,
"line": 242,
"column": 3,
"index": 7818
"index": 7988
}
}
]
Loading