-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pablo Maldonado <pablomaldonadoturci@gmail.com>
- Loading branch information
Showing
9 changed files
with
406 additions
and
219 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
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import type { Web3Provider } from "@ethersproject/providers"; | ||
import { useWeb3React } from "@web3-react/core"; | ||
import useTokenBalance from "../hooks/useTokenBalance"; | ||
import { parseBalance } from "../util"; | ||
import type { Web3Provider } from "@ethersproject/providers" | ||
import { useWeb3React } from "@web3-react/core" | ||
import useTokenBalance from "../hooks/useTokenBalance" | ||
import { parseBalance } from "../util" | ||
|
||
type TokenBalanceProps = { | ||
tokenAddress: string; | ||
symbol: string; | ||
}; | ||
tokenAddress: string | ||
symbol: string | ||
} | ||
|
||
const TokenBalance = ({ tokenAddress, symbol }: TokenBalanceProps) => { | ||
const { account } = useWeb3React<Web3Provider>(); | ||
const { data } = useTokenBalance(account, tokenAddress); | ||
const { account } = useWeb3React<Web3Provider>() | ||
const { data } = useTokenBalance(account, tokenAddress) | ||
|
||
return ( | ||
<p> | ||
{`${symbol} Balance`}: {parseBalance(data ?? 0)} | ||
</p> | ||
); | ||
}; | ||
return ( | ||
<p> | ||
{`Balance: ${symbol}`} {parseBalance(data ?? 0)} | ||
</p> | ||
) | ||
} | ||
|
||
export default TokenBalance; | ||
export default TokenBalance |
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,77 @@ | ||
import { ethers } from "ethers" | ||
import useGovernor from "./useGovernor" | ||
import { useEffect, useState } from "react" | ||
import abi from "../contracts/DefiKicksAdapterRegistry.json" | ||
|
||
export enum ProposalStatus { | ||
Pending, | ||
Active, | ||
Canceled, | ||
Defeated, | ||
Succeeded, | ||
Queued, | ||
Expired, | ||
Executed, | ||
ResolutionToRequest, | ||
ResolutionRequested, | ||
} | ||
|
||
export interface Proposal { | ||
name: string | ||
description: string | ||
link: string | ||
votesFor: number | ||
votesAgainst: number | ||
status: ProposalStatus | ||
id: string | ||
} | ||
|
||
export default function useProposals() { | ||
const [proposals, setProposals] = useState([]) | ||
const [loading, setLoading] = useState(true) | ||
|
||
const contract = useGovernor() | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
if (!contract) return | ||
const filter = contract.filters.ProposalCreated() | ||
const proposalsEvents = await contract.queryFilter(filter, 647965, "latest") | ||
|
||
console.log(proposalsEvents) | ||
// filter only proposals events with different event.args.proposalId | ||
|
||
const distinctProposalsEvents = proposalsEvents.filter( | ||
(event, index, self) => | ||
index === self.findIndex((e) => e.args.proposalId === event.args.proposalId) | ||
) | ||
|
||
const proposals = await Promise.all( | ||
distinctProposalsEvents.map(async (event) => { | ||
const status = await contract.state(event.args.proposalId) | ||
|
||
const iface = new ethers.utils.Interface(abi) | ||
const decodedData = iface.decodeFunctionData( | ||
"addAdapter", | ||
event.args.calldatas[0] | ||
) | ||
|
||
return { | ||
name: decodedData.name, | ||
description: event.args.description, | ||
link: `https://w3s.link/ipfs/${decodedData.ipfsHash}`, | ||
votesFor: 0, | ||
votesAgainst: 0, | ||
status, | ||
id: event.args.proposalId.toString(), | ||
} | ||
}) | ||
) | ||
setProposals(proposals) | ||
setLoading(false) | ||
} | ||
init() | ||
}, [contract]) | ||
|
||
return { proposals, loading } | ||
} |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.