Skip to content

Commit

Permalink
use votingPowerThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed Oct 21, 2024
1 parent eb9c3bf commit 3be485a
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 55 deletions.
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: 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
}
}
]
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: 25000000n,
}
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: BigInt(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: 25000000n,
}

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: 25000000n,
}

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.bigint(),
})

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: bigint
}

export type FundChallenge = {
Expand Down

0 comments on commit 3be485a

Please sign in to comment.