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

Conversation

michaeljscript
Copy link
Collaborator

@michaeljscript michaeljscript commented Dec 5, 2023

Resolves YOMO-843

This PR contains all Governance changes.

To test governance yourself

  1. Create a wallet on Sanchonet (you can also restore abandon ... share or abandon ... address)
  2. Request TADA from faucet https://sancho.network/faucet/
  3. Navigate to menu -> Governance
  4. Find DReps here if you wish to delegate to a DRep https://adanordic.com/drepsearch

Todo

  • Remove env variable and use block number instead
governance.mp4

"@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

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

walletNavigateTo.navigateToGovernanceCentre({navigateToStakingOnSuccess: true})
}

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

const walletNavigateTo = useWalletNavigation()

const onParticipatePress = () => {
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

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

@@ -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

import {mocks} from '../../yoroi-wallets/mocks'
import {ConfirmTxWithHwModal} from './ConfirmTxWithHwModal'

storiesOf('ConfirmTxWithHwModal', module)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved these TX funnel components into src/components folder, so it's easier to re-use them

Copy link
Member

Choose a reason for hiding this comment

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

nops, let's use these as base for the funnel refactor next quarter.

value={spendingPassword}
onChangeText={(text) => setSpendingPassword(text)}
autoComplete="off"
right={isPasswordCorrect ? <Checkmark /> : null}
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 now display a green check mark icon if the password is correct

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Screenshot
Screenshot 2023-12-15 at 19 04 05

color?: string
}

export const Governance = ({size = 36, color = '#6B7384'}: Props) => (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Icon used here
Screenshot 2023-12-15 at 19 05 07

@@ -56,6 +59,18 @@ export const Menu = () => {
/>
</Boundary>

{CONFIG.GOVERNANCE_CENTRE_ENABLED && isSanchoNetworkId(wallet.networkId) && (
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Menu item is shown only if enabled with feature flag and wallet is on sanchonet

showRightArrow?: boolean
}

export const Action = ({title, description, onPress, pending, children, showRightArrow}: Props) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Screenshot

Screenshot 2023-12-15 at 19 08 07

import {COLORS} from '../../../../../theme'
import {useStrings} from '../strings'

const LEARN_MORE_LINK = ''
Copy link
Collaborator Author

@michaeljscript michaeljscript Dec 15, 2023

Choose a reason for hiding this comment

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

Links are hidden until we have them ready. Not a blocker.

children: ReactNode
}

export const SafeArea = ({children}: Props) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Extracted this into a component, so it can be used as a decorator in stories

Copy link
Member

Choose a reason for hiding this comment

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

that's ok, just a friendly reminder that bottom is controlled by BottomTabNav, if eventually part of the funnel display the bottom nav, this will have to change, dunno if worth it. 🤔 it will expose 1:1 to SAV.

onSubmit?: (drepId: string) => void
}

const FIND_DREPS_LINK = ''
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Links are hidden until we have them ready. Not a blocker.

suspense: true,
})

useWalletEvent(wallet, 'utxos', refetchStakingKeyState)
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 refetch staking key state when there is a new utxo to show correct vote and hide pending status

const isTxPending = isString(submittedTxId) && !isTxConfirmed(submittedTxId, txInfos)

if (wallet.isHW) {
return <HardwareWalletSupportComingSoon />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ledger does not support governance actions yet.

@michaeljscript
Copy link
Collaborator Author

Hello @stackchain I've removed the env variables and created a hook that checks the block number based on network, see commit here 9beeb3d

return new Api({networkId, client})
}

class Api implements GovernanceApi {
Copy link
Member

@stackchain stackchain Dec 19, 2023

Choose a reason for hiding this comment

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

personally I don't like using classes in JS, cuz every time you find a callback, and sometimes it can be nested deep in the code, you have to .bind the context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I'm the same, but I saw other packages using classes as well, so I did not want to start new approaches while also this PR being so BIG

Copy link
Member

@stackchain stackchain left a comment

Choose a reason for hiding this comment

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

the manager should receive the api and storage ready, instead of configuring it locally, besides that lgtm.

@stackchain stackchain added this to the 4.25.0 milestone Dec 19, 2023
@stackchain stackchain merged commit 73abee3 into develop Dec 19, 2023
2 checks passed
@stackchain stackchain deleted the feature/governance branch December 19, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants