* 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]>
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { tokenKeys } from "../cache-keys";
|
|
import { useMutationWithInvalidate } from "./query/useQueryWithNetwork";
|
|
import { useContractMetadata } from "./useContract";
|
|
import { useWeb3 } from "@3rdweb-sdk/react";
|
|
import { useToken } from "@thirdweb-dev/react";
|
|
import { Token } from "@thirdweb-dev/sdk";
|
|
import { isAddress } from "ethers/lib/utils";
|
|
import { useQuery } from "react-query";
|
|
import invariant from "tiny-invariant";
|
|
import { isAddressZero } from "utils/zeroAddress";
|
|
|
|
export function useTokenContractMetadata(contractAddress?: string) {
|
|
return useContractMetadata(useToken(contractAddress));
|
|
}
|
|
|
|
export function useTokenData(contractAddress?: string) {
|
|
const { address } = useWeb3();
|
|
const tokenContract = useToken(contractAddress);
|
|
return useQuery(
|
|
tokenKeys.detail(contractAddress, address),
|
|
async () => {
|
|
const [currency, totalSupply, ownedBalance] = await Promise.all([
|
|
tokenContract?.get(),
|
|
tokenContract?.totalSupply(),
|
|
address ? tokenContract?.balance() : Promise.resolve(false),
|
|
]);
|
|
return {
|
|
...currency,
|
|
totalSupply,
|
|
ownedBalance,
|
|
};
|
|
},
|
|
{
|
|
enabled:
|
|
!!tokenContract &&
|
|
!!contractAddress &&
|
|
!isAddressZero(contractAddress) &&
|
|
isAddress(contractAddress),
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useTokenBalance(
|
|
contractAddress?: string,
|
|
walletAddress?: string,
|
|
) {
|
|
const { address } = useWeb3();
|
|
const tokenContract = useToken(contractAddress);
|
|
const addressToCheck = walletAddress || address;
|
|
return useQuery(
|
|
tokenKeys.balanceOf(contractAddress, addressToCheck),
|
|
async () => await tokenContract?.balanceOf(addressToCheck || ""),
|
|
{
|
|
enabled:
|
|
!!contractAddress &&
|
|
!!addressToCheck &&
|
|
!isAddressZero(contractAddress) &&
|
|
isAddress(contractAddress),
|
|
},
|
|
);
|
|
}
|
|
|
|
// ----------------------------------------------------------------
|
|
// Mutations
|
|
// ----------------------------------------------------------------
|
|
|
|
export function useTokenMintMutation(contract?: Token) {
|
|
return useMutationWithInvalidate(
|
|
async (amount: string) => {
|
|
invariant(contract, "contract is required");
|
|
return await contract.mint(amount);
|
|
},
|
|
{
|
|
onSuccess: (_data, _options, _variables, invalidate) => {
|
|
return invalidate([tokenKeys.detail(contract?.getAddress())]);
|
|
},
|
|
},
|
|
);
|
|
}
|