Skip to content

Commit

Permalink
check for governance participation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vsubhuman committed Nov 19, 2024
1 parent 528aadd commit 9b528ab
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ type InjectedLayoutProps = {|
+renderLayoutComponent: LayoutComponentMap => Node,
|};

type State = {|
govStatusFetched: boolean;
|}

type AllProps = {| ...StoresAndActionsProps, ...InjectedLayoutProps |};
@observer
class StakingPageContent extends Component<AllProps> {
class StakingPageContent extends Component<AllProps, State> {
static contextTypes: {| intl: $npm$ReactIntl$IntlFormat |} = {
intl: intlShape.isRequired,
};

state: State = {
govStatusFetched: false,
};

onClose: void => void = () => {
this.props.actions.dialogs.closeActiveDialog.trigger();
};
Expand All @@ -55,10 +63,14 @@ class StakingPageContent extends Component<AllProps> {
if (wallet == null) {
throw new Error(`${nameof(StakingPageContent)} no public deriver. Should never happen`);
}
// Check governance only for certain network
if (wallet.type !== 'trezor') {
noop(this.props.stores.delegation.checkGovernanceStatus(wallet));
}
this.props.stores.delegation.checkGovernanceStatus(wallet).then(() => {
this.setState({
govStatusFetched: true,
});
return null;
}).catch(e => {
console.error('Failed to fetch governance status', e);
});
if (this.props.stores.delegation.getPoolTransitionConfig(wallet).shouldUpdatePool) {
const poolTransitionInfo = this.props.stores.delegation.getPoolTransitionInfo(wallet);
if (poolTransitionInfo?.suggestedPool) {
Expand Down Expand Up @@ -213,6 +225,16 @@ class StakingPageContent extends Component<AllProps> {

const isParticipatingToGovernance = stores.delegation.governanceStatus?.drepDelegation != null;

const handleRewardsWithdrawal = async () => {
if (!isParticipatingToGovernance) {
this.props.actions.dialogs.open.trigger({
dialog: GovernanceParticipateDialog,
});
return;
}
this.createWithdrawalTx(false) // shouldDeregister=false
};

return (
<Box>
{isWalletWithNoFunds ? (
Expand All @@ -227,17 +249,7 @@ class StakingPageContent extends Component<AllProps> {
dialog: OverviewModal,
})
}
withdrawRewards={
isParticipatingToGovernance === false
? async () => {
this.props.actions.dialogs.open.trigger({
dialog: GovernanceParticipateDialog,
});
}
: isStakeRegistered
? async () => this.createWithdrawalTx(false) // shouldDeregister=false
: undefined
}
withdrawRewards={isStakeRegistered && this.state.govStatusFetched ? handleRewardsWithdrawal : undefined}
unitOfAccount={this.toUnitOfAccount}
getTokenInfo={genLookupOrFail(stores.tokenInfoStore.tokenInfo)}
shouldHideBalance={stores.profile.shouldHideBalance}
Expand Down

0 comments on commit 9b528ab

Please sign in to comment.