* initial /publish * custom contract init (#27) * clean up customContract interface for the moment * upgrade sdk & make multi-uri publish work * upgraded dependencies and customContract workflow * more custom contract stuff * publish ui update * basic publish & deploy flow works * cleanup eslint * update sdk * add contract address to toast and log it out * integrate newer sdk version * upgrade deps * full deploy loop functional with updated sdk * upgrade sdk * upgrade deps * upgrade sdk to fix big contracts * full flow! * update deps * update to latest sdk, support custom contracts in contracts list * one more sdk update * cache keys // analytics mapping * make mr. typescript happy * try catch the resolve type (need to fix it in SDK) * fix type check * upgrade sdk & handle `ipfs=` from cli * fix yarn lock * publishBatch * add very basic code tab * fix build * init cleaning up code tab * fix zindex issue * update code segments * prep some more stuff * remove duplication * this wont build and that is ok * fix build * upgrade react package * add super basic mint button * update sdk * clean up some custom contract interfaces a bit * updated sdks all around * change minting to useNFTMint * append contract.functions to signatures so you can copy paste * add byoc page tracking * new publish page * slightly fix hook * custom deploy form update * completely overhauled deploy flow now * some improvements, empty states etc * only show coming soon on non-mumbai * tw-components * fix contract items table * upgrade deps * fix secondary cta * fix string * fixed things more * fix up code-block * small code tab improvements * Add mint drawer if ERC721 (#95) * Update thumbnail/title/desc * Add custom nft mint * Fix FormHelperText * Delete unused imports * Remove imports * fix build issues etc * Add token drop (#93) * Update thumbnail/title/desc * Merge * wip * Token drop page working * Add claim phases tab, add TokenDrop to conditionals * update font size * NFTs/token conditional * Add QuantityInputWithUnlimited * Update SDK * Fix unlimited * Remove fontSize Co-authored-by: Jonas Daniels <[email protected]> * set tokendrop back to coming soon * remove "@dev" tag for sdk installation * fix mappings file * fix indentation on custom code tab * ship central 🚢 * fix build Co-authored-by: Joaquim Verges <[email protected]> Co-authored-by: Jake Loo <[email protected]> Co-authored-by: Nacho Iacovino <[email protected]>
200 lines
5.8 KiB
TypeScript
200 lines
5.8 KiB
TypeScript
import { voteKeys } from "../cache-keys";
|
|
import {
|
|
useMutationWithInvalidate,
|
|
useQueryWithNetwork,
|
|
} from "./query/useQueryWithNetwork";
|
|
import { useContractMetadata } from "./useContract";
|
|
import { useWeb3 } from "@3rdweb-sdk/react";
|
|
import { useSDK, useToken, useVote } from "@thirdweb-dev/react";
|
|
import { VoteType } from "@thirdweb-dev/sdk";
|
|
import invariant from "tiny-invariant";
|
|
|
|
export function useVoteContractMetadata(contractAddress?: string) {
|
|
return useContractMetadata(useVote(contractAddress));
|
|
}
|
|
|
|
export function useVoteProposalList(contractAddress?: string) {
|
|
const voteContract = useVote(contractAddress);
|
|
return useQueryWithNetwork(
|
|
voteKeys.proposals(contractAddress),
|
|
async () => await voteContract?.getAll(),
|
|
{
|
|
enabled: !!voteContract && !!contractAddress,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useHasVotedOnProposal(
|
|
proposalId: string,
|
|
contractAddress?: string,
|
|
) {
|
|
const { address } = useWeb3();
|
|
const voteContract = useVote(contractAddress);
|
|
return useQueryWithNetwork(
|
|
voteKeys.userHasVotedOnProposal(proposalId, contractAddress, address),
|
|
async () => await voteContract?.hasVoted(proposalId, address),
|
|
{
|
|
enabled: !!voteContract && !!contractAddress,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useCanExecuteProposal(
|
|
proposalId: string,
|
|
contractAddress?: string,
|
|
) {
|
|
const voteContract = useVote(contractAddress);
|
|
return useQueryWithNetwork(
|
|
voteKeys.canExecuteProposal(proposalId, contractAddress),
|
|
async () => await voteContract?.canExecute(proposalId),
|
|
{
|
|
enabled: !!voteContract && !!contractAddress,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useTokensDelegated(contractAddress?: string) {
|
|
const sdk = useSDK();
|
|
const { address } = useWeb3();
|
|
const voteContract = useVote(contractAddress);
|
|
return useQueryWithNetwork(
|
|
voteKeys.delegation(contractAddress, address),
|
|
async () => {
|
|
invariant(address, "address is required");
|
|
invariant(voteContract, "vote contract is required");
|
|
|
|
const metadata = await voteContract?.metadata.get();
|
|
const tokenAddress = metadata?.voting_token_address;
|
|
const tokenContract = sdk?.getToken(tokenAddress);
|
|
const delegation = await tokenContract?.getDelegationOf(address);
|
|
return delegation?.toLowerCase() === address.toLowerCase();
|
|
},
|
|
{
|
|
enabled: !!voteContract && !!address,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useVoteTokenBalances(
|
|
contractAddress?: string,
|
|
addresses?: string[],
|
|
) {
|
|
const { data } = useVoteContractMetadata(contractAddress);
|
|
const tokenContract = useToken((data as any)?.voting_token_address || "");
|
|
|
|
return useQueryWithNetwork(
|
|
voteKeys.balances(contractAddress, addresses),
|
|
async () => {
|
|
invariant(data, "contract metadata is required");
|
|
invariant(tokenContract, "voting contract is required");
|
|
invariant(addresses, "addresses are required");
|
|
|
|
const balances = addresses.map(async (address) => {
|
|
return {
|
|
address,
|
|
balance: (await tokenContract.balanceOf(address)).displayValue,
|
|
};
|
|
});
|
|
|
|
return await Promise.all(balances);
|
|
},
|
|
{
|
|
enabled: !!data && !!contractAddress && !!addresses?.length,
|
|
},
|
|
);
|
|
}
|
|
|
|
export interface IProposalInput {
|
|
description: string;
|
|
}
|
|
|
|
export function useProposalCreateMutation(contractAddress?: string) {
|
|
const voteContract = useVote(contractAddress);
|
|
return useMutationWithInvalidate(
|
|
(proposal: IProposalInput) => {
|
|
invariant(voteContract, "contract is required");
|
|
const { description } = proposal;
|
|
return voteContract.propose(description);
|
|
},
|
|
{
|
|
onSuccess: (_data, _options, _variables, invalidate) => {
|
|
return invalidate([voteKeys.proposals(contractAddress)]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useDelegateMutation(contractAddress?: string) {
|
|
const sdk = useSDK();
|
|
const { address } = useWeb3();
|
|
const voteContract = useVote(contractAddress);
|
|
return useMutationWithInvalidate(
|
|
async () => {
|
|
invariant(address, "address is required");
|
|
invariant(contractAddress, "contract address is required");
|
|
invariant(voteContract, "vote contract is required");
|
|
|
|
const metadata = await voteContract?.metadata.get();
|
|
const tokenAddress = metadata?.voting_token_address;
|
|
const tokenContract = sdk?.getToken(tokenAddress);
|
|
return tokenContract?.delegateTo(address);
|
|
},
|
|
{
|
|
onSuccess: (_data, _options, _variables, invalidate) => {
|
|
return invalidate([voteKeys.delegation(contractAddress, address)]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
interface IVoteCast {
|
|
voteType: VoteType;
|
|
reason?: string;
|
|
}
|
|
|
|
export function useCastVoteMutation(
|
|
proposalId: string,
|
|
contractAddress?: string,
|
|
) {
|
|
const { address } = useWeb3();
|
|
const voteContract = useVote(contractAddress);
|
|
return useMutationWithInvalidate(
|
|
async (vote: IVoteCast) => {
|
|
invariant(voteContract, "contract is required");
|
|
invariant(address, "address is required");
|
|
const { voteType, reason } = vote;
|
|
return voteContract.vote(proposalId, voteType, reason);
|
|
},
|
|
{
|
|
onSuccess: (_data, _options, _variables, invalidate) => {
|
|
return invalidate([
|
|
voteKeys.proposals(contractAddress),
|
|
voteKeys.userHasVotedOnProposal(proposalId, contractAddress, address),
|
|
voteKeys.canExecuteProposal(proposalId, contractAddress),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useExecuteProposalMutation(
|
|
proposalId: string,
|
|
contractAddress?: string,
|
|
) {
|
|
const voteContract = useVote(contractAddress);
|
|
return useMutationWithInvalidate(
|
|
async () => {
|
|
invariant(voteContract, "contract is required");
|
|
return voteContract.execute(proposalId);
|
|
},
|
|
{
|
|
onSuccess: (_data, _options, _variables, invalidate) => {
|
|
return invalidate([
|
|
voteKeys.proposals(contractAddress),
|
|
voteKeys.canExecuteProposal(proposalId, contractAddress),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|