Created
January 18, 2023 16:20
-
-
Save sbauch/8d8121f906a28f7e88df262bb6d4517a to your computer and use it in GitHub Desktop.
Example hook for using delegate cash with wagmi hooks.
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
import { useAccount, useContractRead } from 'wagmi'; | |
import { abi, address as delegateCashAddress } from '~abis/delegateCash'; | |
import { env } from '~env/client.mjs'; | |
export function useDelegatedAccount() { | |
const { address, isConnected, ...account } = useAccount(); | |
const txConfig = { | |
address: delegateCashAddress, | |
abi, | |
chainId: env.NEXT_PUBLIC_MATIC_CHAIN_ID, | |
enabled: isConnected, | |
}; | |
const { data: delegationsByDelegate } = useContractRead({ | |
...txConfig, | |
functionName: 'getDelegationsByDelegate', | |
args: [address as `0x${string}`], | |
}); | |
const { data: delegatesForAll } = useContractRead({ | |
...txConfig, | |
functionName: 'getDelegatesForAll', | |
args: [address as `0x${string}`], | |
}); | |
return { | |
address, | |
...account, | |
isConnected, | |
vaultAddress: delegationsByDelegate?.[0]?.vault, | |
delegatedAddress: delegatesForAll?.[0], | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment