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

refactor(staking): use votingPowerThreshold #3697

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion apps/wallet-mobile/.storybook/storybook.requires.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions apps/wallet-mobile/src/YoroiApp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {AsyncStorageProvider} from '@yoroi/common'
import {LinksProvider} from '@yoroi/links'
import {SetupWalletProvider} from '@yoroi/setup-wallet'
import {catalystApiMaker, catalystManagerMaker, CatalystProvider} from '@yoroi/staking'
import {ThemeProvider} from '@yoroi/theme'
import {TransferProvider} from '@yoroi/transfer'
import React from 'react'
Expand Down Expand Up @@ -38,6 +39,10 @@ if (disableLogbox) {
} else {
LogBox.ignoreLogs(['Require cycle:'])
}
const catalystApi = catalystApiMaker()
const catalystManager = catalystManagerMaker({
api: catalystApi,
})

const metricsManager = makeMetricsManager()

Expand Down Expand Up @@ -65,9 +70,11 @@ const Yoroi = () => {
<PoolTransitionProvider>
<BrowserProvider>
<AutomaticWalletOpenerProvider>
<ReviewTxProvider>
<InitApp />
</ReviewTxProvider>
<CatalystProvider manager={catalystManager}>
<ReviewTxProvider>
<InitApp />
</ReviewTxProvider>
</CatalystProvider>
</AutomaticWalletOpenerProvider>
</BrowserProvider>
</PoolTransitionProvider>
Expand Down
27 changes: 22 additions & 5 deletions apps/wallet-mobile/src/features/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import {createStackNavigator} from '@react-navigation/stack'
import {useTheme} from '@yoroi/theme'
import React from 'react'
import {useIntl} from 'react-intl'
import {Linking, ScrollView, StyleSheet, TouchableOpacity, useWindowDimensions, View} from 'react-native'
import {
ActivityIndicator,
Linking,
ScrollView,
StyleSheet,
TouchableOpacity,
useWindowDimensions,
View,
} from 'react-native'
import {SafeAreaView} from 'react-native-safe-area-context'

import {Boundary} from '../../components/Boundary/Boundary'
import {Icon} from '../../components/Icon'
import {useModal} from '../../components/Modal/ModalContext'
import {Spacer} from '../../components/Spacer/Spacer'
Expand Down Expand Up @@ -82,13 +89,23 @@ export const Menu = () => {
/>
)}

<Boundary loading={{size: 'small', style: {padding: 16}}} error={{size: 'inline'}}>
<Catalyst //
<React.Suspense
fallback={
<Item
disabled
onPress={() => null}
label={strings.catalystVoting}
left={<Icon.Catalyst size={24} color={color.gray_600} />}
right={<ActivityIndicator color={color.gray_600} />}
/>
}
>
<Catalyst
label={strings.catalystVoting}
onPress={navigateTo.catalystVoting}
left={<Icon.Catalyst size={24} color={color.gray_600} />}
/>
</Boundary>
</React.Suspense>

<KnowledgeBase //
label={strings.knowledgeBase}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {useFocusEffect, useNavigation} from '@react-navigation/native'
import {createStackNavigator} from '@react-navigation/stack'
import {catalystManagerMaker, CatalystProvider} from '@yoroi/staking'
import {catalystApiMaker} from '@yoroi/staking/src'
import {useTheme} from '@yoroi/theme'
import React from 'react'
import {useIntl} from 'react-intl'
Expand All @@ -21,11 +19,6 @@ import {DisplayPin} from './useCases/DisplayPin/DisplayPin'
import {DownloadCatalystAppScreen} from './useCases/DownloadCatalystAppScreen/DownloadCatalystAppScreen'
import {QrCode} from './useCases/ShowQrCode/ShowQrCode'

const catalystApi = catalystApiMaker()
const catalystManager = catalystManagerMaker({
api: catalystApi,
})

const Stack = createStackNavigator<VotingRegistrationRoutes>()
export const CatalystNavigator = () => {
const {atoms, color} = useTheme()
Expand All @@ -41,35 +34,33 @@ export const CatalystNavigator = () => {
const navigationOptions = React.useMemo(() => defaultStackNavigationOptions(atoms, color), [atoms, color])

return (
<CatalystProvider manager={catalystManager}>
<Stack.Navigator
screenOptions={{
...navigationOptions,
title: strings.title,
headerTitle: ({children}) => <NetworkTag>{children}</NetworkTag>,
}}
>
<Stack.Group>
{/* STEP 1 */}
<Stack.Screen name="download-catalyst">
{() => (
<Boundary loading={{size: 'full'}}>
<DownloadCatalystAppScreen />
</Boundary>
)}
</Stack.Screen>
<Stack.Navigator
screenOptions={{
...navigationOptions,
title: strings.title,
headerTitle: ({children}) => <NetworkTag>{children}</NetworkTag>,
}}
>
<Stack.Group>
{/* STEP 1 */}
<Stack.Screen name="download-catalyst">
{() => (
<Boundary loading={{size: 'full'}}>
<DownloadCatalystAppScreen />
</Boundary>
)}
</Stack.Screen>

{/* STEP 2 */}
<Stack.Screen name="display-pin" component={DisplayPin} />
{/* STEP 2 */}
<Stack.Screen name="display-pin" component={DisplayPin} />

{/* STEP 3 */}
<Stack.Screen name="confirm-pin" component={ConfirmPin} />
{/* STEP 3 */}
<Stack.Screen name="confirm-pin" component={ConfirmPin} />

{/* STEP 4 */}
<Stack.Screen component={QrCode} name="qr-code" options={{...navigationOptions, headerLeft: () => null}} />
</Stack.Group>
</Stack.Navigator>
</CatalystProvider>
{/* STEP 4 */}
<Stack.Screen component={QrCode} name="qr-code" options={{...navigationOptions, headerLeft: () => null}} />
</Stack.Group>
</Stack.Navigator>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {useModal} from '../../../components/Modal/ModalContext'
import {Space} from '../../../components/Space/Space'
import globalMessages, {confirmationMessages} from '../../../kernel/i18n/global-messages'
import {usePortfolioPrimaryBalance} from '../../Portfolio/common/hooks/usePortfolioPrimaryBalance'
import {catalystConfig} from '../../WalletManager/common/adapters/cardano/catalyst-config'
import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'
import {useCatalystCurrentFund} from './hooks'

const formatter = amountFormatter({template: `{{value}} {{ticker}}`, dropTraillingZeros: true})

Expand All @@ -19,11 +19,12 @@ export const InsufficientFundsModal = () => {
const styles = useStyles()
const {wallet} = useSelectedWallet()
const {closeModal} = useModal()

const primaryBalance = usePortfolioPrimaryBalance({wallet})
const {fund} = useCatalystCurrentFund()

const fmtMinPrimaryBalance = formatter({
info: wallet.portfolioPrimaryTokenInfo,
quantity: catalystConfig.minAda,
quantity: BigInt(fund.info.votingPowerThreshold),
})
const fmtPrimaryBalance = formatter(primaryBalance)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {queryInfo} from '../../../kernel/query-client'
import {YoroiWallet} from '../../../yoroi-wallets/cardano/types'
import {isShelley} from '../../../yoroi-wallets/cardano/utils'
import {usePortfolioPrimaryBalance} from '../../Portfolio/common/hooks/usePortfolioPrimaryBalance'
import {catalystConfig} from '../../WalletManager/common/adapters/cardano/catalyst-config'
import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'

export const useCanVote = (wallet: YoroiWallet) => {
const {meta} = useSelectedWallet()
const amount = usePortfolioPrimaryBalance({wallet})
const sufficientFunds = amount.quantity >= catalystConfig.minAda
const {fund} = useCatalystCurrentFund()
const sufficientFunds = amount.quantity >= fund.info.votingPowerThreshold

return {
canVote: !meta.isReadOnly && isShelley(meta.implementation),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"start": {
"line": 219,
"column": 12,
"index": 7280
"index": 7301
},
"end": {
"line": 222,
"column": 3,
"index": 7357
"index": 7378
}
}
]
2 changes: 1 addition & 1 deletion packages/staking/src/catalyst/adapters/fund-info.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const mockCatalystApiFundInfo: Catalyst.CatalystApiFundInfo = {
fund_name: 'Fund12',
fund_goal:
"{'timestamp': '2024-06-25T17:29:31Z', 'themes': ['API', 'DAO', 'DApp', 'Data tools', 'DeFi', 'Education', 'Events', 'Exchanges', 'Explorers', 'Gaming', 'Governance', 'Identity solutions', 'NFTs', 'RealFi', 'SDK', 'Wallet', 'Cardano Ambassadors', 'Marketing', 'Hackathon', 'Incubation', 'Regional expansion', 'Standards and regulation', 'Translation', 'Dev ecosystem collaboration', 'Dev team', 'Developer tools', 'SPOs', 'Node', 'Other']}",
voting_power_threshold: 500000000,
voting_power_threshold: 25000000,
fund_start_time: '2024-06-27T12:00:00Z',
fund_end_time: '2024-07-11T11:00:00Z',
next_fund_start_time: '1970-01-01T00:00:00Z',
Expand Down
1 change: 1 addition & 0 deletions packages/staking/src/catalyst/fund-info.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ export const mockFundInfo: Catalyst.FundInfo = {
resultsUrl: 'https://projectcatalyst.io/funds/12',
surveyUrl:
'https://docs.google.com/forms/d/e/1FAIpQLSdg76N8zAtZn35hclY2pEDf9mY0wUb-vsejfaYZJqoW-CZDrg/viewform?usp=sf_link',
votingPowerThreshold: 25000000,
}
1 change: 1 addition & 0 deletions packages/staking/src/catalyst/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function toFundInfo(
tallyingEnd: new Date(fundInfo.tallying_end),
resultsUrl: fundInfo.results_url,
surveyUrl: fundInfo.survey_url,
votingPowerThreshold: fundInfo.voting_power_threshold,

challenges: fundInfo.challenges?.map((challenge) => ({
id: challenge.id,
Expand Down
2 changes: 2 additions & 0 deletions packages/staking/src/catalyst/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Validators', () => {
tallyingEnd: new Date('2022-01-30'),
resultsUrl: 'https://results.com',
surveyUrl: 'https://survey.com',
votingPowerThreshold: 25000000,
}

expect(parseFundInfo(validData)).toEqual(validData)
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('Validators', () => {
tallyingEnd: new Date('2022-01-30'),
resultsUrl: 'https://results.com',
surveyUrl: 'https://survey.com',
votingPowerThreshold: 25000000,
}

expect(isFundInfo(validData)).toBe(true)
Expand Down
1 change: 1 addition & 0 deletions packages/staking/src/catalyst/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const FundInfoSchema = z.object({
tallyingEnd: z.date(),
resultsUrl: z.string(),
surveyUrl: z.string(),
votingPowerThreshold: z.number(),
})

export const isFundInfo =
Expand Down
1 change: 1 addition & 0 deletions packages/staking/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export namespace Catalyst {
tallyingEnd: Date
resultsUrl: string
surveyUrl: string
votingPowerThreshold: number
}

export type FundChallenge = {
Expand Down
Loading