-
Notifications
You must be signed in to change notification settings - Fork 50
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(governance): Add governance feature #2931
Changes from 15 commits
646a868
ef4ebd8
0150cbc
4365ccf
2a305b6
a327350
c19c5b2
289dc83
f69ff8e
58e7a7c
5e7a009
a3e3a59
0c69ac8
4394c59
1409b33
ebcb76d
374fa94
9beeb3d
8fe1293
13f4dfb
5d70d25
4ddbfb4
b1d618e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,12 +94,12 @@ | |
"@cardano-foundation/ledgerjs-hw-app-cardano": "^6.0.0", | ||
"@emurgo/cip14-js": "^3.0.1", | ||
"@emurgo/cip4-js": "1.0.7", | ||
"@emurgo/cross-csl-core": "^3.1.0", | ||
"@emurgo/cross-csl-mobile": "^3.1.0", | ||
"@emurgo/csl-mobile-bridge": "5.1.3", | ||
"@emurgo/cross-csl-core": "^4.0.0-alpha.1", | ||
"@emurgo/cross-csl-mobile": "^4.0.0-alpha.1", | ||
"@emurgo/csl-mobile-bridge": "6.0.0-alpha.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. library updates |
||
"@emurgo/react-native-blockies-svg": "^0.0.2", | ||
"@emurgo/react-native-hid": "^5.15.6", | ||
"@emurgo/yoroi-lib": "^0.11.0", | ||
"@emurgo/yoroi-lib": "^0.14.1", | ||
"@formatjs/intl-datetimeformat": "^6.7.0", | ||
"@formatjs/intl-getcanonicallocales": "^2.1.0", | ||
"@formatjs/intl-locale": "^3.2.1", | ||
|
@@ -125,6 +125,7 @@ | |
"@yoroi/banxa": "1.3.0", | ||
"@yoroi/common": "1.3.0", | ||
"@yoroi/links": "1.3.0", | ||
"@yoroi/staking": "1.0.0", | ||
"@yoroi/swap": "1.3.0", | ||
"add": "2.0.6", | ||
"assert": "^2.0.0", | ||
|
@@ -202,7 +203,7 @@ | |
"@babel/preset-react": "^7.16.7", | ||
"@babel/runtime": "^7.20.0", | ||
"@emurgo/cardano-serialization-lib-nodejs": "^9.1.4", | ||
"@emurgo/cross-csl-nodejs": "^3.1.0", | ||
"@emurgo/cross-csl-nodejs": "^4.0.0-alpha.1", | ||
"@formatjs/cli": "^6.1.0", | ||
"@formatjs/ts-transformer": "^3.13.0", | ||
"@react-navigation/devtools": "^6.0.13", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import {catalystManagerMaker} from '@yoroi/staking' | ||
import React, {useEffect, useState} from 'react' | ||
import {defineMessages, useIntl} from 'react-intl' | ||
import {StyleSheet, TouchableOpacity, View} from 'react-native' | ||
|
@@ -8,7 +9,6 @@ import globalMessages, {confirmationMessages} from '../i18n/global-messages' | |
import {isNightly} from '../legacy/config' | ||
import {Logger} from '../legacy/logging' | ||
import {COLORS} from '../theme' | ||
import {isRegistrationOpen} from '../yoroi-wallets/cardano/catalyst/catalystUtils' | ||
import {useCanVote} from './hooks' | ||
import {InsufficientFundsModal} from './InsufficientFundsModal' | ||
|
||
|
@@ -42,7 +42,9 @@ export const VotingBanner = ({onPress, disabled}: Props) => { | |
} | ||
} | ||
|
||
setShowCatalystBanner((canVote && isRegistrationOpen(fundInfo)) || isNightly() || __DEV__) | ||
const catalyst = catalystManagerMaker() | ||
|
||
setShowCatalystBanner((canVote && catalyst.isRegistrationOpen(fundInfo)) || isNightly() || __DEV__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this helper to |
||
} | ||
|
||
checkCatalystFundInfo() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,22 @@ import React from 'react' | |
import {defineMessages, useIntl} from 'react-intl' | ||
import {ActivityIndicator, RefreshControl, ScrollView, StyleSheet, View, ViewProps} from 'react-native' | ||
|
||
import {Banner, Button, StatusBar} from '../components' | ||
import {Banner, Button, StatusBar, useModal} from '../components' | ||
import { | ||
useGovernanceStrings, | ||
useIsParticipatingInGovernance, | ||
WithdrawWarningModal, | ||
} from '../features/Staking/Governance' | ||
import globalMessages from '../i18n/global-messages' | ||
import {CONFIG} from '../legacy/config' | ||
import {Modal} from '../legacy/Modal' | ||
import {useWalletNavigation} from '../navigation' | ||
import {useSelectedWallet} from '../SelectedWallet' | ||
import {isEmptyString} from '../utils/utils' | ||
import {getCardanoNetworkConfigById} from '../yoroi-wallets/cardano/networks' | ||
import {getCardanoBaseConfig} from '../yoroi-wallets/cardano/utils' | ||
import {useBalances, useIsOnline, useSync} from '../yoroi-wallets/hooks' | ||
import {Amounts} from '../yoroi-wallets/utils' | ||
import {Amounts, isSanchoNetworkId} from '../yoroi-wallets/utils' | ||
import { | ||
genCurrentEpochLength, | ||
genCurrentSlotLength, | ||
|
@@ -30,10 +36,12 @@ import {WithdrawStakingRewards} from './WithdrawStakingRewards' | |
export const Dashboard = () => { | ||
const intl = useIntl() | ||
const navigateTo = useNavigateTo() | ||
const governanceStrings = useGovernanceStrings() | ||
|
||
const wallet = useSelectedWallet() | ||
const {isLoading: isSyncing, sync} = useSync(wallet) | ||
const isOnline = useIsOnline(wallet) | ||
const {openModal} = useModal() | ||
|
||
const balances = useBalances(wallet) | ||
const primaryAmount = Amounts.getAmount(balances, '') | ||
|
@@ -43,6 +51,24 @@ export const Dashboard = () => { | |
|
||
const {resetToTxHistory} = useWalletNavigation() | ||
|
||
const isParticipatingInGovernance = useIsParticipatingInGovernance(wallet) | ||
const walletNavigateTo = useWalletNavigation() | ||
|
||
const onParticipatePress = () => { | ||
stackchain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
walletNavigateTo.navigateToGovernanceCentre({navigateToStakingOnSuccess: true}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If user clicks on participate on the modal below and they cast a vote, then they are redirected back to staking dashboard |
||
} | ||
|
||
const onWithdraw = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (CONFIG.GOVERNANCE_CENTRE_ENABLED && isSanchoNetworkId(wallet.networkId) && !isParticipatingInGovernance) { | ||
openModal( | ||
governanceStrings.withdrawWarningTitle, | ||
<WithdrawWarningModal onParticipatePress={onParticipatePress} />, | ||
) | ||
return | ||
} | ||
setShowWithdrawalDialog(true) | ||
} | ||
|
||
return ( | ||
<View style={styles.root}> | ||
<StatusBar type="dark" /> | ||
|
@@ -77,15 +103,15 @@ export const Dashboard = () => { | |
totalAdaSum={!isEmptyString(primaryAmount.quantity) ? new BigNumber(primaryAmount.quantity) : null} | ||
totalRewards={new BigNumber(stakingInfo.rewards)} | ||
totalDelegated={new BigNumber(stakingInfo.amount)} | ||
onWithdraw={() => setShowWithdrawalDialog(true)} | ||
onWithdraw={onWithdraw} | ||
disableWithdraw={wallet.isReadOnly} | ||
/> | ||
) : ( | ||
<UserSummary | ||
totalAdaSum={!isEmptyString(primaryAmount.quantity) ? new BigNumber(primaryAmount.quantity) : null} | ||
totalRewards={null} | ||
totalDelegated={null} | ||
onWithdraw={() => setShowWithdrawalDialog(true)} | ||
onWithdraw={onWithdraw} | ||
disableWithdraw | ||
/> | ||
)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import AsyncStorage from '@react-native-async-storage/async-storage' | ||
import {createStackNavigator} from '@react-navigation/stack' | ||
import React from 'react' | ||
import {governanceApiMaker, governanceManagerMaker, GovernanceProvider} from '@yoroi/staking' | ||
import React, {useMemo} from 'react' | ||
import {defineMessages, useIntl} from 'react-intl' | ||
|
||
import {SettingsButton} from '../components/Button' | ||
|
@@ -9,6 +11,7 @@ import {useSelectedWallet} from '../SelectedWallet' | |
import {DelegationConfirmation} from '../Staking' | ||
import {StakingCenter} from '../Staking/StakingCenter' | ||
import {useWalletName} from '../yoroi-wallets/hooks' | ||
import {CardanoMobile} from '../yoroi-wallets/wallets' | ||
import {Dashboard} from './Dashboard' | ||
|
||
const Stack = createStackNavigator<DashboardRoutes>() | ||
|
@@ -17,34 +20,49 @@ export const DashboardNavigator = () => { | |
const walletName = useWalletName(wallet) | ||
const strings = useStrings() | ||
|
||
const {networkId} = useSelectedWallet() | ||
const manager = useMemo( | ||
() => | ||
governanceManagerMaker({ | ||
walletId: wallet.id, | ||
networkId, | ||
api: governanceApiMaker({networkId}), | ||
cardano: CardanoMobile, | ||
storage: AsyncStorage, | ||
stackchain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}), | ||
[networkId, wallet.id], | ||
) | ||
|
||
return ( | ||
<Stack.Navigator | ||
screenOptions={{ | ||
...defaultStackNavigationOptions, | ||
detachPreviousScreen: false /* https://github.com/react-navigation/react-navigation/issues/9883 */, | ||
}} | ||
> | ||
<Stack.Screen | ||
name="staking-dashboard-main" | ||
component={Dashboard} | ||
options={{ | ||
title: walletName, | ||
headerRight: () => <HeaderRight />, | ||
<GovernanceProvider manager={manager}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GovernanceProvider needs to be here since we need to check in staking dashboard whether the user participates or not |
||
<Stack.Navigator | ||
screenOptions={{ | ||
...defaultStackNavigationOptions, | ||
detachPreviousScreen: false /* https://github.com/react-navigation/react-navigation/issues/9883 */, | ||
}} | ||
/> | ||
> | ||
<Stack.Screen | ||
name="staking-dashboard-main" | ||
component={Dashboard} | ||
options={{ | ||
title: walletName, | ||
headerRight: () => <HeaderRight />, | ||
}} | ||
/> | ||
|
||
<Stack.Screen // | ||
name="staking-center" | ||
component={StakingCenter} | ||
options={{title: strings.title}} | ||
/> | ||
<Stack.Screen // | ||
name="staking-center" | ||
component={StakingCenter} | ||
options={{title: strings.title}} | ||
/> | ||
|
||
<Stack.Screen | ||
name="delegation-confirmation" | ||
component={DelegationConfirmation} | ||
options={{title: strings.title}} | ||
/> | ||
</Stack.Navigator> | ||
<Stack.Screen | ||
name="delegation-confirmation" | ||
component={DelegationConfirmation} | ||
options={{title: strings.title}} | ||
/> | ||
</Stack.Navigator> | ||
</GovernanceProvider> | ||
) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import {useWalletNavigation} from '../../navigation' | |
import {COLORS} from '../../theme' | ||
import {useWalletManager} from '../../WalletManager' | ||
import * as HASKELL_SHELLEY from '../../yoroi-wallets/cardano/constants/mainnet/constants' | ||
import * as SANCHONET from '../../yoroi-wallets/cardano/constants/sanchonet/constants' | ||
import * as HASKELL_SHELLEY_TESTNET from '../../yoroi-wallets/cardano/constants/testnet/constants' | ||
import {InvalidState, NetworkError} from '../../yoroi-wallets/cardano/errors' | ||
import {isJormungandr} from '../../yoroi-wallets/cardano/networks' | ||
|
@@ -89,6 +90,8 @@ export const WalletSelectionScreen = () => { | |
|
||
<OnlyNightlyShelleyTestnetButton /> | ||
|
||
<OnlyNightlyShelleySanchonetButton /> | ||
|
||
<OnlyDevButton /> | ||
|
||
<PleaseWaitModal title={strings.loadingWallet} spinnerText={strings.pleaseWait} visible={isLoading} /> | ||
|
@@ -197,6 +200,25 @@ const OnlyNightlyShelleyTestnetButton = () => { | |
) | ||
} | ||
|
||
const OnlyNightlyShelleySanchonetButton = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const navigation = useNavigation() | ||
const strings = useStrings() | ||
|
||
if (!isNightly() && !__DEV__) return null | ||
|
||
const onPress = () => { | ||
navigation.navigate('new-wallet', { | ||
screen: 'choose-create-restore', | ||
params: { | ||
networkId: SANCHONET.NETWORK_ID, | ||
walletImplementationId: SANCHONET.WALLET_IMPLEMENTATION_ID, | ||
}, | ||
}) | ||
} | ||
|
||
return <Button onPress={onPress} title={`${strings.addWalletButton} (sanchonet)`} style={styles.button} /> | ||
} | ||
|
||
const OnlyDevButton = () => { | ||
const navigation = useNavigation() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feature flag