Skip to content

Commit

Permalink
Refactor useErc20 and useLock hooks to use erc20IQConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthK2 committed May 14, 2024
1 parent 558fccb commit f5e15f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
28 changes: 8 additions & 20 deletions src/hooks/useErc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@ import { useAccount, useBalance } from 'wagmi'

export const useErc20 = () => {
const { address } = useAccount()
const { data: erc20Balance, refetch: refetchErc20Balance } =
config.alchemyChain === 'iqChain'
? useBalance({
address: address,
token: config.wiqAddress as `0x${string}`,
})
: useBalance({
address: address,
token: config.iqAddress as `0x${string}`,
})
const { data: erc20Balance, refetch: refetchErc20Balance } = useBalance({
address: address,
token: config.erc20IQConfig.address,
})

const { data: totalValueLocked } =
config.alchemyChain === 'iqChain'
? useBalance({
address: config.hiiqAddress as `0x${string}`,
token: config.wiqAddress as `0x${string}`,
})
: useBalance({
address: config.hiiqAddress as `0x${string}`,
token: config.iqAddress as `0x${string}`,
})
const { data: totalValueLocked } = useBalance({
address: config.hiiqAddress as `0x${string}`,
token: config.erc20IQConfig.address,
})

const getUserBalance = () => {
if (address) {
Expand Down
17 changes: 2 additions & 15 deletions src/hooks/useLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@ import hiIQABI from '@/abis/hiIQABI.abi'
import config from '@/config'
import { useAccount, useContractRead, useContractWrite } from 'wagmi'
import { waitForTransaction } from 'wagmi/actions'
import erc20Abi from '@/abis/erc20.abi'

const hiiqContractConfig = {
address: config.hiiqAddress as `0x${string}`,
abi: hiIQABI,
}

//use WIQ for dev
const erc20ContractConfig =
config.alchemyChain === 'iqChain'
? {
address: config.wiqAddress as `0x${string}`,
abi: erc20Abi,
}
: {
address: config.iqAddress as `0x${string}`,
abi: erc20Abi,
}

export const useLock = () => {
const { address } = useAccount()

Expand All @@ -46,13 +33,13 @@ export const useLock = () => {

const { data: allowanceToken, refetch: refetchedAllowanceToken } =
useContractRead({
...erc20ContractConfig,
...config.erc20IQConfig,
functionName: 'allowance',
args: [address as `0x${string}`, config.hiiqAddress as `0x${string}`],
})

const { writeAsync: approve } = useContractWrite({
...erc20ContractConfig,
...config.erc20IQConfig,
functionName: 'approve',
})

Expand Down

0 comments on commit f5e15f9

Please sign in to comment.