Skip to content

Commit

Permalink
feat(governance): Add governance feature (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript authored Dec 19, 2023
1 parent 3e14cc6 commit 73abee3
Show file tree
Hide file tree
Showing 150 changed files with 6,535 additions and 2,051 deletions.
2 changes: 1 addition & 1 deletion apps/wallet-mobile/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ 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
2 changes: 1 addition & 1 deletion apps/wallet-mobile/.env.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ DISABLE_LOGBOX=true
BANXA_TEST_WALLET=addr1qyfuspldlchc5kechfe5jzdrr9jms2s9w0tq4hggy9zgkhxssydveuc8xyx4zh27fwcmr62mraeezjwf24hzkyejwfmq7yptmd

FRONTEND_FEE_ADDRESS_MAINNET=addr1q9ry6jfdgm0lcrtfpgwrgxg7qfahv80jlghhrthy6w8hmyjuw9ngccy937pm7yw0jjnxasm7hzxjrf8rzkqcj26788lqws5fke
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km
FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km
2 changes: 1 addition & 1 deletion apps/wallet-mobile/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ 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
2 changes: 1 addition & 1 deletion apps/wallet-mobile/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ 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
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",
"@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__)
}

checkCatalystFundInfo()
Expand Down
33 changes: 30 additions & 3 deletions apps/wallet-mobile/src/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ 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 {useIsGovernanceFeatureEnabled} from '../features/Staking/Governance'
import globalMessages from '../i18n/global-messages'
import {Modal} from '../legacy/Modal'
import {useWalletNavigation} from '../navigation'
Expand All @@ -30,19 +36,40 @@ 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, '')
const {stakingInfo, refetch: refetchStakingInfo, error, isLoading} = useStakingInfo(wallet)
const isGovernanceFeatureEnabled = useIsGovernanceFeatureEnabled(wallet)

const [showWithdrawalDialog, setShowWithdrawalDialog] = React.useState(false)

const {resetToTxHistory} = useWalletNavigation()

const isParticipatingInGovernance = useIsParticipatingInGovernance(wallet)
const walletNavigateTo = useWalletNavigation()

const handleOnParticipatePress = () => {
walletNavigateTo.navigateToGovernanceCentre({navigateToStakingOnSuccess: true})
}

const onWithdraw = () => {
if (isGovernanceFeatureEnabled && !isParticipatingInGovernance) {
openModal(
governanceStrings.withdrawWarningTitle,
<WithdrawWarningModal onParticipatePress={handleOnParticipatePress} />,
)
return
}
setShowWithdrawalDialog(true)
}

return (
<View style={styles.root}>
<StatusBar type="dark" />
Expand Down Expand Up @@ -77,15 +104,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
54 changes: 30 additions & 24 deletions apps/wallet-mobile/src/Dashboard/DashboardNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {createStackNavigator} from '@react-navigation/stack'
import {GovernanceProvider} from '@yoroi/staking'
import React from 'react'
import {defineMessages, useIntl} from 'react-intl'

import {SettingsButton} from '../components/Button'
import {useGovernanceManagerMaker} from '../features/Staking/Governance'
import {DashboardRoutes, defaultStackNavigationOptions, useWalletNavigation} from '../navigation'
import {useSelectedWallet} from '../SelectedWallet'
import {DelegationConfirmation} from '../Staking'
Expand All @@ -17,34 +19,38 @@ export const DashboardNavigator = () => {
const walletName = useWalletName(wallet)
const strings = useStrings()

const manager = useGovernanceManagerMaker()

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}>
<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 = () => {
const navigation = useNavigation()
const strings = useStrings()

if (!isNightly() && !__DEV__) return null

const handleOnPress = () => {
navigation.navigate('new-wallet', {
screen: 'choose-create-restore',
params: {
networkId: SANCHONET.NETWORK_ID,
walletImplementationId: SANCHONET.WALLET_IMPLEMENTATION_ID,
},
})
}

return <Button onPress={handleOnPress} title={`${strings.addWalletButton} (sanchonet)`} style={styles.button} />
}

const OnlyDevButton = () => {
const navigation = useNavigation()

Expand Down
3 changes: 2 additions & 1 deletion apps/wallet-mobile/src/TxHistory/ActionsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {TxHistoryRouteNavigation} from '../navigation'
import {useSelectedWallet} from '../SelectedWallet'
import {COLORS} from '../theme'
import {useTokenInfo} from '../yoroi-wallets/hooks'
import {isMainnetNetworkId} from '../yoroi-wallets/utils'

const ACTION_PROPS = {
size: 32,
Expand Down Expand Up @@ -62,7 +63,7 @@ export const ActionsBanner = ({disabled = false}: {disabled: boolean}) => {
track.walletPageExchangeBottomSheetClicked()
// banxa doesn't support testnet for the sandbox it needs a mainnet address
const sandboxWallet = env.getString('BANXA_TEST_WALLET')
const isMainnet = wallet.networkId !== 300
const isMainnet = isMainnetNetworkId(wallet.networkId)
const walletAddress = isMainnet ? wallet.externalAddresses[0] : sandboxWallet
const moduleOptions = {isProduction: isMainnet, partner: 'yoroi'} as const
const urlOptions = {
Expand Down
Loading

0 comments on commit 73abee3

Please sign in to comment.