-
Notifications
You must be signed in to change notification settings - Fork 27
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
75b39f5
commit c7ac849
Showing
3 changed files
with
52 additions
and
4 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, | ||
undefined, | ||
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,28 @@ | ||
import { useSendTransaction } from "./useSendTransaction" | ||
import { MaxUint256 } from "@ethersproject/constants" | ||
import { Contract } from "@ethersproject/contracts" | ||
|
||
const useApproveAndCall = ( | ||
tokenContract?: Contract, | ||
spender?: string, | ||
extraCallData?: Uint8Array, | ||
onSuccess?: () => void | Promise<void> | ||
) => { | ||
const { sendTransaction, status } = useSendTransaction( | ||
tokenContract!, | ||
"approveAndCall", | ||
onSuccess | ||
) | ||
|
||
const approveAndCall = async (amountToApprove = MaxUint256.toString()) => { | ||
await sendTransaction( | ||
spender, | ||
amountToApprove, | ||
extraCallData ?? Uint8Array.from([]) | ||
) | ||
} | ||
|
||
return { approveAndCall, status } | ||
} | ||
|
||
export default useApproveAndCall |