-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
185 additions
and
22 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
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
27 changes: 27 additions & 0 deletions
27
packages/ui/src/proposals/components/CancelProposalButton.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,27 @@ | ||
import React, { useCallback } from 'react' | ||
|
||
import { ButtonSecondary } from '@/common/components/buttons' | ||
import { useModal } from '@/common/hooks/useModal' | ||
import { Member } from '@/memberships/types' | ||
|
||
import { CancelProposalModalCall } from '../modals/CancelProposal' | ||
|
||
interface Props { | ||
member: Member | ||
proposalId: string | ||
} | ||
|
||
export const CancelProposalButton = ({ member, proposalId }: Props) => { | ||
const { showModal } = useModal() | ||
const cancelProposalModal = useCallback(() => { | ||
showModal<CancelProposalModalCall>({ | ||
modal: 'CancelProposalModal', | ||
data: { member, proposalId }, | ||
}) | ||
}, []) | ||
return ( | ||
<ButtonSecondary onClick={cancelProposalModal} size="medium"> | ||
Cancel Proposal | ||
</ButtonSecondary> | ||
) | ||
} |
70 changes: 70 additions & 0 deletions
70
packages/ui/src/proposals/modals/CancelProposal/CancelProposalModal.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,70 @@ | ||
import React, { useEffect, useMemo } from 'react' | ||
|
||
import { useTransactionFee } from '@/accounts/hooks/useTransactionFee' | ||
import { InsufficientFundsModal } from '@/accounts/modals/InsufficientFundsModal' | ||
import { useApi } from '@/api/hooks/useApi' | ||
import { TextMedium } from '@/common/components/typography' | ||
import { useMachine } from '@/common/hooks/useMachine' | ||
import { useModal } from '@/common/hooks/useModal' | ||
import { SignTransactionModal } from '@/common/modals/SignTransactionModal/SignTransactionModal' | ||
import { defaultTransactionModalMachine } from '@/common/model/machines/defaultTransactionModalMachine' | ||
|
||
import { CancelProposalModalCall } from './types' | ||
|
||
export const CancelProposalModal = () => { | ||
const { hideModal, modalData } = useModal<CancelProposalModalCall>() | ||
const { member, proposalId } = modalData | ||
const machine = useMemo( | ||
() => | ||
defaultTransactionModalMachine( | ||
'There was a problem cancelling your proposal.', | ||
'Your propsal has been cancelled.' | ||
), | ||
[] | ||
) | ||
const [state, send] = useMachine(machine, { context: { validateBeforeTransaction: true } }) | ||
const { api, isConnected } = useApi() | ||
|
||
const { transaction, feeInfo } = useTransactionFee( | ||
member.controllerAccount, | ||
() => { | ||
if (api && isConnected) { | ||
return api.tx.proposalsEngine.cancelProposal(member.id, proposalId) | ||
} | ||
}, | ||
[modalData, isConnected] | ||
) | ||
|
||
useEffect(() => { | ||
if (state.matches('requirementsVerification')) { | ||
if (transaction && feeInfo) { | ||
feeInfo.canAfford && send('PASS') | ||
!feeInfo.canAfford && send('FAIL') | ||
} | ||
} | ||
|
||
if (state.matches('beforeTransaction')) { | ||
send(feeInfo?.canAfford ? 'PASS' : 'FAIL') | ||
} | ||
}, [state.value, member, transaction, feeInfo?.canAfford]) | ||
|
||
if (state.matches('transaction') && transaction && member) { | ||
return ( | ||
<SignTransactionModal | ||
buttonText="Sign And Cancel Proposal" | ||
transaction={transaction} | ||
signer={member.controllerAccount} | ||
service={state.children.transaction} | ||
> | ||
<TextMedium>You intend to cancel your proposal.</TextMedium> | ||
</SignTransactionModal> | ||
) | ||
} | ||
|
||
if (state.matches('requirementsFailed') && member && feeInfo) { | ||
return ( | ||
<InsufficientFundsModal onClose={hideModal} address={member.controllerAccount} amount={feeInfo.transactionFee} /> | ||
) | ||
} | ||
return null | ||
} |
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,2 @@ | ||
export type { CancelProposalModalCall } from './types' | ||
export * from './CancelProposalModal' |
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,4 @@ | ||
import { ModalWithDataCall } from '@/common/providers/modal/types' | ||
import { Member } from '@/memberships/types' | ||
|
||
export type CancelProposalModalCall = ModalWithDataCall<'CancelProposalModal', { member: Member; proposalId: string }> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import BN from 'bn.js' | ||
|
||
import { A_WEEK } from '@/common/constants' | ||
import { MILLISECONDS_PER_BLOCK } from '@/common/model/formatters' | ||
|
||
export const asWeeklyRewards = (rewardPerBlock: BN) => { | ||
const BLOCKS_PER_WEEK = A_WEEK / MILLISECONDS_PER_BLOCK | ||
return rewardPerBlock.muln(BLOCKS_PER_WEEK) | ||
} |