-
Notifications
You must be signed in to change notification settings - Fork 26
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
1 parent
69432ce
commit 0ed85d1
Showing
3 changed files
with
56 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useToken } from "../../hooks/useToken" | ||
import { Token } from "../../enums" | ||
import { useTStakingContract } from "./useTStakingContract" | ||
import useApproveAndCall from "./userApproveAndCall" | ||
|
||
const useApproveAndCallTStaking = (onSuccess?: () => Promise<void> | void) => { | ||
const tToken = useToken(Token.T) | ||
const tStakingContract = useTStakingContract() | ||
|
||
return useApproveAndCall( | ||
tToken.contract!, | ||
tStakingContract?.address, | ||
[], | ||
onSuccess | ||
) | ||
} | ||
|
||
export default useApproveAndCallTStaking |
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,24 @@ | ||
import { useSendTransaction } from "./useSendTransaction" | ||
import { MaxUint256 } from "@ethersproject/constants" | ||
import { Contract } from "@ethersproject/contracts" | ||
|
||
const useApproveAndCall = ( | ||
tokenContract?: Contract, | ||
spender?: string, | ||
extraCallData = [], | ||
onSuccess?: () => void | Promise<void> | ||
) => { | ||
const { sendTransaction, status } = useSendTransaction( | ||
tokenContract!, | ||
"approveAndCall", | ||
onSuccess | ||
) | ||
|
||
const approveAndCall = async (amountToApprove = MaxUint256.toString()) => { | ||
await sendTransaction(spender, [amountToApprove, ...extraCallData]) | ||
} | ||
|
||
return { approveAndCall, status } | ||
} | ||
|
||
export default useApproveAndCall |