Skip to content

Commit

Permalink
Call recvoer/cancel stake via TokenStaking
Browse files Browse the repository at this point in the history
Since #1893 recover/cancel stake should go directly to `TokenStaking`
contract.
  • Loading branch information
r-czajkowski committed Jul 31, 2020
1 parent 02ffda2 commit 7a00a12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 48 deletions.
36 changes: 5 additions & 31 deletions solidity/dashboard/src/components/RecoverStakeButton.jsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
import React, { useContext, useCallback, useMemo } from "react"
import React, { useCallback } from "react"
import { SubmitButton } from "./Button"
import { Web3Context } from "./WithWeb3Context"
import { useShowMessage, messageType } from "./Message"
import { ViewAddressInBlockExplorer } from "./ViewInBlockExplorer"
import { contracts } from "../contracts"
import { useModal } from "../hooks/useModal"
import { withConfirmationModal } from "./ConfirmationModal"

const RecoverStakeButton = ({ operatorAddress, ...props }) => {
const web3Context = useContext(Web3Context)
const { yourAddress, grantContract, stakingContract } = web3Context
const showMessage = useShowMessage()
const { isFromGrant, isManagedGrant, managedGrantContractInstance } = props
const { isFromGrant } = props
const { openConfirmationModal } = useModal()

const contract = useMemo(() => {
if (isManagedGrant) {
return managedGrantContractInstance
} else if (isFromGrant) {
return grantContract
} else {
return stakingContract
}
}, [
grantContract,
isFromGrant,
isManagedGrant,
managedGrantContractInstance,
stakingContract,
])

const recoverStake = useCallback(
async (onTransactionHashCallback) => {
try {
Expand All @@ -45,9 +26,9 @@ const RecoverStakeButton = ({ operatorAddress, ...props }) => {
withConfirmationModal(ConfirmRecoveringModal)
)
}
await contract.methods
await contracts.stakingContract.methods
.recoverStake(operatorAddress)
.send({ from: yourAddress })
.send()
.on("transactionHash", onTransactionHashCallback)
showMessage({
type: messageType.SUCCESS,
Expand All @@ -63,14 +44,7 @@ const RecoverStakeButton = ({ operatorAddress, ...props }) => {
throw error
}
},
[
operatorAddress,
yourAddress,
contract.methods,
showMessage,
isFromGrant,
openConfirmationModal,
]
[operatorAddress, showMessage, isFromGrant, openConfirmationModal]
)

return (
Expand Down
21 changes: 4 additions & 17 deletions solidity/dashboard/src/components/UndelegateStakeButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,13 @@ const confirmationModalOptions = {

const UndelegateStakeButton = (props) => {
const web3Context = useContext(Web3Context)
const { yourAddress, grantContract, stakingContract } = web3Context
const { yourAddress, stakingContract } = web3Context
const showMessage = useShowMessage()
const { openConfirmationModal } = useModal()

const undelegate = async (onTransactionHashCallback) => {
const {
operator,
isInInitializationPeriod,
isFromGrant,
isManagedGrant,
managedGrantContractInstance,
} = props
let contract
if (isManagedGrant) {
contract = managedGrantContractInstance
} else if (isFromGrant) {
contract = grantContract
} else {
contract = stakingContract
}
const { operator, isInInitializationPeriod, isFromGrant } = props

try {
if (isInInitializationPeriod && isFromGrant) {
await openConfirmationModal(
Expand All @@ -53,7 +40,7 @@ const UndelegateStakeButton = (props) => {
await openConfirmationModal(confirmationModalOptions)
}

await contract.methods[
await stakingContract.methods[
isInInitializationPeriod ? "cancelStake" : "undelegate"
](operator)
.send({ from: yourAddress })
Expand Down

0 comments on commit 7a00a12

Please sign in to comment.