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(governance): Add governance feature #2931

Merged
merged 23 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
646a868
feat(staking): Add staking package with governance feature (#2874)
michaeljscript Dec 1, 2023
ef4ebd8
feat(governance): Add governance screens (#2921)
michaeljscript Dec 4, 2023
0150cbc
Merge branch 'develop' into feature/governance
michaeljscript Dec 11, 2023
4365ccf
Fix build
michaeljscript Dec 11, 2023
2a305b6
feat(wallets): Add sanchonet wallet option (#2937)
michaeljscript Dec 12, 2023
a327350
Merge branch 'develop' into feature/governance
michaeljscript Dec 12, 2023
c19c5b2
feat(governance): Update libraries and add transaction creators (#2938)
michaeljscript Dec 15, 2023
289dc83
Merge branch 'develop' into feature/governance
michaeljscript Dec 15, 2023
f69ff8e
feat(governance): UI updates (#2941)
michaeljscript Dec 15, 2023
58e7a7c
Display governance only on sanchonet
michaeljscript Dec 15, 2023
5e7a009
Remove unused metadata helpers
michaeljscript Dec 15, 2023
a3e3a59
Improve types
michaeljscript Dec 15, 2023
0c69ac8
Fix race condition
michaeljscript Dec 15, 2023
4394c59
Fix ios spacing
michaeljscript Dec 15, 2023
1409b33
Fix lint issue
michaeljscript Dec 15, 2023
ebcb76d
Enable governance centre on nightly
michaeljscript Dec 18, 2023
374fa94
Merge branch 'develop' into feature/governance
michaeljscript Dec 18, 2023
9beeb3d
Add governance block check instead of env flag
michaeljscript Dec 18, 2023
8fe1293
Merge branch 'develop' into feature/governance
michaeljscript Dec 18, 2023
13f4dfb
Merge branch 'develop' into feature/governance
michaeljscript Dec 18, 2023
5d70d25
CR
michaeljscript Dec 18, 2023
4ddbfb4
Fix navigation
michaeljscript Dec 18, 2023
b1d618e
Sort imports
michaeljscript Dec 18, 2023
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
4 changes: 3 additions & 1 deletion apps/wallet-mobile/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ WALLET_2_MNEMONIC=abandon abandon abandon abandon abandon abandon abandon abando
BANXA_TEST_WALLET=addr1qyfuspldlchc5kechfe5jzdrr9jms2s9w0tq4hggy9zgkhxssydveuc8xyx4zh27fwcmr62mraeezjwf24hzkyejwfmq7yptmd

FRONTEND_FEE_ADDRESS_MAINNET=addr1q9ry6jfdgm0lcrtfpgwrgxg7qfahv80jlghhrthy6w8hmyjuw9ngccy937pm7yw0jjnxasm7hzxjrf8rzkqcj26788lqws5fke
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feature flag

GOVERNANCE_CENTRE_ENABLED=true
4 changes: 3 additions & 1 deletion apps/wallet-mobile/.env.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ DISABLE_LOGBOX=true
BANXA_TEST_WALLET=addr1qyfuspldlchc5kechfe5jzdrr9jms2s9w0tq4hggy9zgkhxssydveuc8xyx4zh27fwcmr62mraeezjwf24hzkyejwfmq7yptmd

FRONTEND_FEE_ADDRESS_MAINNET=addr1q9ry6jfdgm0lcrtfpgwrgxg7qfahv80jlghhrthy6w8hmyjuw9ngccy937pm7yw0jjnxasm7hzxjrf8rzkqcj26788lqws5fke
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km

michaeljscript marked this conversation as resolved.
Show resolved Hide resolved
GOVERNANCE_CENTRE_ENABLED=false
4 changes: 3 additions & 1 deletion apps/wallet-mobile/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ BUILD_VARIANT=PROD
SENTRY_DSN=https://7f7c6cb60a6f429facd34f491dfc5133@o1138840.ingest.sentry.io/6783228

FRONTEND_FEE_ADDRESS_MAINNET=addr1q9ry6jfdgm0lcrtfpgwrgxg7qfahv80jlghhrthy6w8hmyjuw9ngccy937pm7yw0jjnxasm7hzxjrf8rzkqcj26788lqws5fke
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km

GOVERNANCE_CENTRE_ENABLED=false
4 changes: 3 additions & 1 deletion apps/wallet-mobile/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ WALLET_2_MNEMONIC=abandon abandon abandon abandon abandon abandon abandon abando
BANXA_TEST_WALLET=addr1qyfuspldlchc5kechfe5jzdrr9jms2s9w0tq4hggy9zgkhxssydveuc8xyx4zh27fwcmr62mraeezjwf24hzkyejwfmq7yptmd

FRONTEND_FEE_ADDRESS_MAINNET=addr1q9ry6jfdgm0lcrtfpgwrgxg7qfahv80jlghhrthy6w8hmyjuw9ngccy937pm7yw0jjnxasm7hzxjrf8rzkqcj26788lqws5fke
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km

GOVERNANCE_CENTRE_ENABLED=false
13 changes: 12 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.

4 changes: 2 additions & 2 deletions apps/wallet-mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ PODS:
- react-native-config/App (= 1.5.1)
- react-native-config/App (1.5.1):
- React-Core
- react-native-haskell-shelley (5.1.3):
- react-native-haskell-shelley (6.0.0-alpha.2):
- React
- react-native-pager-view (6.2.0):
- React-Core
Expand Down Expand Up @@ -900,7 +900,7 @@ SPEC CHECKSUMS:
react-native-background-timer: 17ea5e06803401a379ebf1f20505b793ac44d0fe
react-native-ble-plx: f10240444452dfb2d2a13a0e4f58d7783e92d76e
react-native-config: 86038147314e2e6d10ea9972022aa171e6b1d4d8
react-native-haskell-shelley: 92544de7277b53cda2393528d530b526c81b48a6
react-native-haskell-shelley: c01783e1181b8fc1fea715a288801056d70afc07
react-native-pager-view: 0ccb8bf60e2ebd38b1f3669fa3650ecce81db2df
react-native-quick-base64: 62290829c619fbabca4c41cfec75ae759d08fc1c
react-native-randombytes: b6677f7d495c27e9ee0dbd77ebc97b3c59173729
Expand Down
11 changes: 6 additions & 5 deletions apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions apps/wallet-mobile/src/Catalyst/VotingBanner.tsx
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'
Expand All @@ -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'

Expand Down Expand Up @@ -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__)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this helper to @yoroi/staking

}

checkCatalystFundInfo()
Expand Down
34 changes: 30 additions & 4 deletions apps/wallet-mobile/src/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, '')
Expand All @@ -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})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 = () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We display this modal when person wants to withdraw rewards, but they do not participate in governance.
Screenshot 2023-12-15 at 18 57 46

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" />
Expand Down Expand Up @@ -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
/>
)}
Expand Down
68 changes: 43 additions & 25 deletions apps/wallet-mobile/src/Dashboard/DashboardNavigator.tsx
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'
Expand All @@ -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>()
Expand All @@ -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}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -89,6 +90,8 @@ export const WalletSelectionScreen = () => {

<OnlyNightlyShelleyTestnetButton />

<OnlyNightlyShelleySanchonetButton />

<OnlyDevButton />

<PleaseWaitModal title={strings.loadingWallet} spinnerText={strings.pleaseWait} visible={isLoading} />
Expand Down Expand Up @@ -197,6 +200,25 @@ const OnlyNightlyShelleyTestnetButton = () => {
)
}

const OnlyNightlyShelleySanchonetButton = () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a new button to create a wallet on SanchoNetwork

Screenshot 2023-12-15 at 19 00 34

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()

Expand Down
Loading
Loading