* 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]>
144 lines
3.5 KiB
TypeScript
144 lines
3.5 KiB
TypeScript
import { QuestionIcon } from "@chakra-ui/icons";
|
|
import {
|
|
Avalanche,
|
|
Ethereum,
|
|
Fantom,
|
|
Polygon,
|
|
} from "@thirdweb-dev/chain-icons";
|
|
import { useAddress, useNetwork } from "@thirdweb-dev/react";
|
|
import { alchemyUrlMap } from "components/app-layouts/providers";
|
|
import { BigNumber, ethers } from "ethers";
|
|
import { formatEther } from "ethers/lib/utils";
|
|
import { useCallback } from "react";
|
|
import { useQuery } from "react-query";
|
|
import { ChainId, SUPPORTED_CHAIN_ID } from "utils/network";
|
|
|
|
interface NetworkMetadata {
|
|
chainName: string;
|
|
icon: React.ComponentType;
|
|
symbol: string;
|
|
isTestnet: boolean;
|
|
chainId: ChainId;
|
|
}
|
|
|
|
const defaultNetworkMetadata: Record<SUPPORTED_CHAIN_ID, NetworkMetadata> = {
|
|
[ChainId.Mainnet]: {
|
|
chainName: "Ethereum",
|
|
icon: Ethereum,
|
|
symbol: "ETH",
|
|
isTestnet: false,
|
|
chainId: ChainId.Mainnet,
|
|
},
|
|
[ChainId.Rinkeby]: {
|
|
chainName: "Rinkeby",
|
|
icon: Ethereum,
|
|
symbol: "ETH",
|
|
isTestnet: true,
|
|
chainId: ChainId.Rinkeby,
|
|
},
|
|
[ChainId.Goerli]: {
|
|
chainName: "Goerli",
|
|
icon: Ethereum,
|
|
symbol: "ETH",
|
|
isTestnet: true,
|
|
chainId: ChainId.Goerli,
|
|
},
|
|
[ChainId.Polygon]: {
|
|
chainName: "Polygon",
|
|
icon: Polygon,
|
|
symbol: "MATIC",
|
|
isTestnet: false,
|
|
chainId: ChainId.Polygon,
|
|
},
|
|
[ChainId.Fantom]: {
|
|
chainName: "Fantom",
|
|
icon: Fantom,
|
|
symbol: "FTM",
|
|
isTestnet: false,
|
|
chainId: ChainId.Fantom,
|
|
},
|
|
[ChainId.Avalanche]: {
|
|
chainName: "Avalanche",
|
|
icon: Avalanche,
|
|
symbol: "AVAX",
|
|
isTestnet: false,
|
|
chainId: ChainId.Avalanche,
|
|
},
|
|
[ChainId.Mumbai]: {
|
|
chainName: "Mumbai",
|
|
icon: Polygon,
|
|
symbol: "MATIC",
|
|
isTestnet: true,
|
|
chainId: ChainId.Mumbai,
|
|
},
|
|
};
|
|
|
|
const useBalance = (address?: string) => {
|
|
const [network] = useNetwork();
|
|
const chainId = network.data.chain?.id;
|
|
return useQuery(
|
|
["balance", address, { chainId }],
|
|
async () => {
|
|
let balance = BigNumber.from(0);
|
|
if (chainId) {
|
|
const provider = ethers.getDefaultProvider(
|
|
chainId in alchemyUrlMap
|
|
? alchemyUrlMap[chainId as SUPPORTED_CHAIN_ID]
|
|
: chainId,
|
|
);
|
|
balance = await provider.getBalance(address || "");
|
|
}
|
|
|
|
balance = BigNumber.from(balance || 0);
|
|
|
|
return {
|
|
value: balance,
|
|
formatted: formatEther(balance).slice(0, 6),
|
|
};
|
|
},
|
|
{
|
|
enabled: !!chainId && !!address,
|
|
},
|
|
);
|
|
};
|
|
|
|
export function useWeb3() {
|
|
const address = useAddress();
|
|
const [network] = useNetwork();
|
|
const balance = useBalance(address);
|
|
|
|
const getNetworkMetadata = useCallback(
|
|
(chainId: SUPPORTED_CHAIN_ID) => {
|
|
const cData: NetworkMetadata = {
|
|
chainName: "Unsupported Chain",
|
|
icon: QuestionIcon,
|
|
isTestnet: false,
|
|
symbol: "",
|
|
chainId,
|
|
};
|
|
const c = network.data.chains.find((chain) => chain.id === chainId);
|
|
|
|
if (chainId in defaultNetworkMetadata) {
|
|
cData.chainName = defaultNetworkMetadata[chainId].chainName;
|
|
cData.isTestnet = defaultNetworkMetadata[chainId].isTestnet;
|
|
cData.symbol = defaultNetworkMetadata[chainId].symbol;
|
|
cData.icon = defaultNetworkMetadata[chainId].icon;
|
|
} else if (c) {
|
|
cData.chainName = c.name;
|
|
cData.isTestnet = !!c.testnet;
|
|
cData.symbol = c.nativeCurrency?.symbol || "";
|
|
}
|
|
return cData;
|
|
},
|
|
[network],
|
|
);
|
|
|
|
return {
|
|
getNetworkMetadata,
|
|
// error: account.error,
|
|
address,
|
|
chainId: network.data.chain?.id,
|
|
balance,
|
|
};
|
|
}
|