-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from Concordium/p8/suspend-resume-validator
P8/suspend resume validator
- Loading branch information
Showing
25 changed files
with
447 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/components/Transfers/configureBaker/BakerSuspensionPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { MultiStepFormPageProps } from '~/components/MultiStepForm'; | ||
import Button from '~/cross-app-components/Button'; | ||
import { AccountInfo } from '~/utils/types'; | ||
import { withPendingBakerChangeGuard } from './util'; | ||
|
||
import styles from './ConfigureBakerPage.module.scss'; | ||
|
||
type Props = Pick<MultiStepFormPageProps<boolean>, 'onNext'> & { | ||
accountInfo: AccountInfo | undefined; | ||
isSuspended: boolean; | ||
}; | ||
|
||
const BakerSuspensionPage = withPendingBakerChangeGuard( | ||
({ onNext, isSuspended }: Props) => ( | ||
<> | ||
<p className="flexChildFill"> | ||
Submitting this transaction will{' '} | ||
{isSuspended ? 'resume' : 'suspend'} validation for the selected | ||
validator account. | ||
</p> | ||
<Button | ||
onClick={() => onNext(!isSuspended)} | ||
className={styles.continue} | ||
> | ||
Continue | ||
</Button> | ||
</> | ||
) | ||
); | ||
|
||
export default BakerSuspensionPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/pages/Accounts/AccountDetailsPage/Baking/BakerSuspension.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* eslint-disable react/display-name */ | ||
import React, { ComponentType, useCallback } from 'react'; | ||
|
||
import withExchangeRate from '~/components/Transfers/withExchangeRate'; | ||
import withNonce, { AccountAndNonce } from '~/components/Transfers/withNonce'; | ||
import { isDefined } from '~/utils/basicHelpers'; | ||
import { | ||
AccountInfo, | ||
ConfigureBaker as ConfigureBakerTransaction, | ||
MakeRequired, | ||
NotOptional, | ||
} from '~/utils/types'; | ||
import { ensureProps } from '~/utils/componentHelpers'; | ||
import routes from '~/constants/routes.json'; | ||
import { | ||
BakerSuspensionDependencies, | ||
BakerSuspensionFlowState, | ||
bakerSuspensionTitle, | ||
convertToBakerSuspensionTransaction, | ||
} from '~/utils/transactionFlows/bakerSuspension'; | ||
import BakerSuspensionPage from '~/components/Transfers/configureBaker/BakerSuspensionPage'; | ||
|
||
import AccountTransactionFlow, { | ||
AccountTransactionFlowLoading, | ||
} from '../../AccountTransactionFlow'; | ||
|
||
type Props = BakerSuspensionDependencies & | ||
NotOptional<AccountAndNonce> & { | ||
accountInfo: AccountInfo; | ||
isSuspended?: boolean; | ||
}; | ||
|
||
type UnsafeProps = MakeRequired<Partial<Props>, 'account' | 'accountInfo'>; | ||
|
||
const hasNecessaryProps = (props: UnsafeProps): props is Props => { | ||
return [props.exchangeRate, props.nonce].every(isDefined); | ||
}; | ||
|
||
const withDeps = (component: ComponentType<Props>) => | ||
withNonce( | ||
withExchangeRate( | ||
ensureProps( | ||
component, | ||
hasNecessaryProps, | ||
<AccountTransactionFlowLoading title="Change suspension status" /> | ||
) | ||
) | ||
); | ||
|
||
export default withDeps(function BakerSuspension(props: Props) { | ||
const { | ||
nonce, | ||
account, | ||
exchangeRate, | ||
accountInfo, | ||
isSuspended = false, | ||
} = props; | ||
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const convert = useCallback( | ||
() => | ||
convertToBakerSuspensionTransaction( | ||
account, | ||
nonce, | ||
exchangeRate | ||
)(!isSuspended), | ||
[account, nonce, exchangeRate, isSuspended] | ||
); | ||
|
||
return ( | ||
<AccountTransactionFlow< | ||
BakerSuspensionFlowState, | ||
ConfigureBakerTransaction | ||
> | ||
title={bakerSuspensionTitle(isSuspended)} | ||
convert={convert} | ||
multisigRoute={routes.MULTISIGTRANSACTIONS_UPDATE_BAKER_SUSPENSION} | ||
firstPageBack | ||
> | ||
{{ | ||
suspended: { | ||
render: (_, onNext) => ( | ||
<BakerSuspensionPage | ||
onNext={onNext} | ||
accountInfo={accountInfo} | ||
isSuspended={isSuspended} | ||
/> | ||
), | ||
}, | ||
}} | ||
</AccountTransactionFlow> | ||
); | ||
}); |
Oops, something went wrong.