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

Remove useActions from many screens #634

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/Garden/Agreement/Agreement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import MultiModal from '@components/MultiModal/MultiModal'
import SignAgreementScreens from '../ModalFlows/SignAgreementScreens/SignAgreementScreens'
import { useAgreement } from '@hooks/useAgreement'
import { useWallet } from '@providers/Wallet'
import useGardenLogic from '@/logic/garden-logic'

import warningSvg from './assets/warning.svg'

function Agreement() {
const [agreement, loading] = useAgreement()
const [signModalVisible, setSignModalVisible] = useState(false)
const { actions } = useGardenLogic()

const signed = agreement.signedLatest

Expand Down Expand Up @@ -46,7 +48,10 @@ function Agreement() {
/>
</LayoutLimiter>
<MultiModal visible={signModalVisible} onClose={handleHideModal}>
<SignAgreementScreens versionId={agreement.versionId} />
<SignAgreementScreens
versionId={agreement.versionId}
agreementActions={actions.agreementActions}
/>
</MultiModal>
</LayoutGutter>
)
Expand Down
18 changes: 16 additions & 2 deletions src/components/Garden/DecisionDetail/DecisionDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,23 @@ function DecisionDetail({ proposal, actions }) {
/>
)}
{modalMode === 'settle' && (
<SettleProposalScreens proposal={proposal} />
<SettleProposalScreens
agreementActions={{
settleAction: actions.settleAction,
}}
proposal={proposal}
/>
)}
{modalMode === 'dispute' && (
<RaiseDisputeScreens
agreementActions={{
getAllowance: actions.getAllowance,
approveTokenAmount: actions.approveTokenAmount,
disputeAction: actions.disputeAction,
}}
proposal={proposal}
/>
)}
{modalMode === 'dispute' && <RaiseDisputeScreens proposal={proposal} />}
</MultiModal>
</div>
)
Expand Down
10 changes: 7 additions & 3 deletions src/components/Garden/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const Home = React.memo(function Home() {
proposals,
proposalsFetchedCount,
} = useGardenLogic()

const history = useHistory()
const { account } = useWallet()

Expand Down Expand Up @@ -216,9 +215,14 @@ const Home = React.memo(function Home() {
<CreateProposalScreens onComplete={handleProposalCreated} />
)}
{(modalMode === 'wrap' || modalMode === 'unwrap') && (
<WrapTokenScreens mode={modalMode} />
<WrapTokenScreens
mode={modalMode}
hookedTokenManagerActions={actions.hookedTokenManagerActions}
/>
)}
{modalMode === 'claim' && (
<ClaimRewardsScreens unipoolActions={actions.unipoolActions} />
)}
{modalMode === 'claim' && <ClaimRewardsScreens />}
</MultiModal>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import React, { useCallback, useMemo, useState } from 'react'
import ClaimRewards from './ClaimRewards'
import ModalFlowBase from '../ModalFlowBase'

import useActions from '@hooks/useActions'

function ClaimRewardsScreens() {
function ClaimRewardsScreens({ unipoolActions }) {
const [transactions, setTransactions] = useState([])
const { unipoolActions } = useActions()

const getTransactions = useCallback(
async onComplete => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import React, { useMemo, useState, useCallback } from 'react'
import ModalFlowBase from '../ModalFlowBase'
import ExecuteProposal from './ExecuteProposal'

import useActions from '@hooks/useActions'

function ExecuteProposalScreens({ proposal }) {
function ExecuteProposalScreens({ proposal, convictionActions }) {
const [transactions, setTransactions] = useState([])
const { convictionActions } = useActions()

const { id: proposalId } = proposal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import PropTypes from 'prop-types'
import ModalFlowBase from '../ModalFlowBase'
import RaiseDisputeRequirements from './RaiseDisputeRequirements'

import useActions from '@hooks/useActions'
import { useCelesteSynced } from '@hooks/useCeleste'
import { useDisputeFees } from '@hooks/useDispute'
import BigNumber from '@lib/bigNumber'

const ZERO_BN = new BigNumber('0')

function RaiseDisputeScreens({ proposal }) {
function RaiseDisputeScreens({ proposal, agreementActions }) {
const [transactions, setTransactions] = useState([])
const [celesteSynced, celesteSyncLoading] = useCelesteSynced()
const disputeFees = useDisputeFees()
const { agreementActions } = useActions()

const temporatyTrx = useRef([])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import React, { useMemo, useState, useCallback } from 'react'
import ModalFlowBase from '../ModalFlowBase'
import RemoveProposal from './RemoveProposal'

import useActions from '@hooks/useActions'

function RemoveProposalScreens({ proposal, mode }) {
function RemoveProposalScreens({ proposal, mode, convictionActions }) {
const [transactions, setTransactions] = useState([])
const { convictionActions } = useActions()

const { id: proposalId } = proposal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import React, { useState, useCallback, useMemo } from 'react'
import { addressesEqual } from '@1hive/1hive-ui'
import ModalFlowBase from '../ModalFlowBase'
import SettlementDetails from './SettlementDetails'
import useActions from '@hooks/useActions'
import { useWallet } from '@providers/Wallet'

function SettleProposalScreens({ proposal }) {
function SettleProposalScreens({ proposal, agreementActions }) {
const [transactions, setTransactions] = useState([])

const { account } = useWallet()
const { agreementActions } = useActions()

const isChallenger = addressesEqual(account, proposal.challenger)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { useHistory } from 'react-router'
import { Button } from '@1hive/1hive-ui'
import ModalFlowBase from '../ModalFlowBase'
import SignOverview from './SignOverview'
import useActions from '@hooks/useActions'

import { buildGardenPath } from '@utils/routing-utils'

function SignAgreementScreens({ versionId }) {
const actions = useActions()
function SignAgreementScreens({ versionId, agreementActions }) {
const [transactions, setTransactions] = useState([])

const history = useHistory()
Expand All @@ -32,12 +30,12 @@ function SignAgreementScreens({ versionId }) {

const getTransactions = useCallback(
async onComplete => {
await actions.agreementActions.signAgreement({ versionId }, intent => {
await agreementActions.signAgreement({ versionId }, intent => {
setTransactions(intent.transactions)
onComplete()
})
},
[actions, versionId]
[agreementActions, versionId]
)

const screens = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import ModalFlowBase from '../ModalFlowBase'
import ChangeSupport from './ChangeSupport'
import SupportProposal from './SupportProposal'

import useActions from '@hooks/useActions'

function SupportProposalScreens({ proposal, mode }) {
function SupportProposalScreens({ proposal, mode, convictionActions }) {
const [transactions, setTransactions] = useState([])
const { convictionActions } = useActions()

const { id: proposalId } = proposal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import ModalFlowBase from '../ModalFlowBase'
import WrapUnwrap from './WrapUnwrap'

import { useGardenState } from '@providers/GardenState'
import useActions from '@hooks/useActions'

import BigNumber from '@lib/bigNumber'

const ZERO_BN = new BigNumber(0)

function WrapTokenScreens({ mode }) {
function WrapTokenScreens({ mode, hookedTokenManagerActions }) {
const [transactions, setTransactions] = useState([])
const { token, wrappableToken } = useGardenState()
const { hookedTokenManagerActions } = useActions()

const temporatyTrx = useRef([])

Expand Down
41 changes: 36 additions & 5 deletions src/components/Garden/ProposalDetail/ProposalDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,17 +441,48 @@ function ProposalDetail({
/>
)}
{modalMode === 'settle' && (
<SettleProposalScreens proposal={proposal} />
<SettleProposalScreens
agreementActions={{
settleAction: actions.settleAction,
}}
proposal={proposal}
/>
)}
{modalMode === 'dispute' && (
<RaiseDisputeScreens
agreementActions={{
getAllowance: actions.getAllowance,
approveTokenAmount: actions.approveTokenAmount,
disputeAction: actions.disputeAction,
}}
proposal={proposal}
/>
)}
{modalMode === 'dispute' && <RaiseDisputeScreens proposal={proposal} />}
{(modalMode === 'support' || modalMode === 'update') && (
<SupportProposalScreens proposal={proposal} mode={modalMode} />
<SupportProposalScreens
proposal={proposal}
mode={modalMode}
convictionActions={{
stakeToProposal: actions.stakeToProposal,
withdrawFromProposal: actions.withdrawFromProposal,
}}
/>
)}
{modalMode === 'remove' && (
<RemoveProposalScreens proposal={proposal} />
<RemoveProposalScreens
convictionActions={{
cancelProposal: actions.cancelProposal,
}}
proposal={proposal}
/>
)}
{modalMode === 'execute' && (
<ExecuteProposalScreens proposal={proposal} />
<ExecuteProposalScreens
convictionActions={{
executeProposal: actions.executeProposal,
}}
proposal={proposal}
/>
)}
</MultiModal>
</div>
Expand Down