[React] - use internal Signer (#168)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@thirdweb-dev/react": patch
|
||||
---
|
||||
|
||||
use internals wherever possible to allow wider usecases with `<ThirdwebSDKProvider>` & add invariants to catch improper use of functionality that requires the full `<ThirdwebProvider` earlier
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@thirdweb-dev/react": patch
|
||||
---
|
||||
|
||||
fix case where `<ConnectWallet />` button would get stuck when user cancels connection
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@thirdweb-dev/sdk": patch
|
||||
---
|
||||
|
||||
Switch naming of exported prebuilt contract types back from `<name>Impl` to `<name>` for easier use
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@thirdweb-dev/react": patch
|
||||
---
|
||||
|
||||
allow passing `className` to `<ConnectWallet />` and `<Web3Button />` for possible style overrides
|
||||
@@ -60,7 +60,7 @@
|
||||
"eslint-plugin-tsdoc": "^0.2.16",
|
||||
"ethers": "^5.7.0",
|
||||
"express": "^4.18.1",
|
||||
"next": "12.2.0",
|
||||
"next": "^12.2.0",
|
||||
"next-auth": "^4.10.3",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^4.7.4"
|
||||
@@ -69,7 +69,7 @@
|
||||
"@thirdweb-dev/sdk": "*",
|
||||
"ethers": ">=5.5.1",
|
||||
"express": "^4.18.1",
|
||||
"next": "12.2.0",
|
||||
"next": "^12.2.0",
|
||||
"next-auth": "^4.10.3"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
"prettier": "^2.7.1",
|
||||
"ts-jest": "^28.0.8",
|
||||
"ts-node": "^10.7.0",
|
||||
"tsc": "^2.0.4",
|
||||
"tsup": "^6.2.3",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
@@ -81,4 +80,4 @@
|
||||
"sourcemap": true,
|
||||
"clean": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"main": "index.js",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
||||
"@typescript-eslint/parser": "^5.36.2",
|
||||
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
||||
"@typescript-eslint/parser": "^5.33.0",
|
||||
"eslint-config-next": "^12.0.8",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-config-turbo": "latest",
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
"@microsoft/api-documenter": "^7.19.4",
|
||||
"@microsoft/api-extractor": "^7.29.2",
|
||||
"@microsoft/tsdoc": "^0.14.1",
|
||||
"@playwright/experimental-ct-react": "^1.25.1",
|
||||
"@playwright/test": "^1.25.1",
|
||||
"@playwright/experimental-ct-react": "1.25.1",
|
||||
"@playwright/test": "1.25.1",
|
||||
"@preconstruct/cli": "^2.2.1",
|
||||
"@thirdweb-dev/sdk": "*",
|
||||
"@types/color": "^3.0.3",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ConnectWallet } from ".";
|
||||
import { ThirdwebProvider } from "../..";
|
||||
import { ThirdwebProvider } from "../../providers/full";
|
||||
import { test, expect } from "@playwright/experimental-ct-react";
|
||||
|
||||
test.use({ viewport: { width: 500, height: 500 } });
|
||||
@@ -10,5 +10,6 @@ test("should render the connect wallet button", async ({ mount }) => {
|
||||
<ConnectWallet />
|
||||
</ThirdwebProvider>,
|
||||
);
|
||||
|
||||
await expect(component).toContainText("Connect Wallet");
|
||||
});
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import { useThirdwebAuthConfig } from "../../contexts/thirdweb-auth";
|
||||
import { useBalance } from "../../hooks/async/wallet";
|
||||
import { LoginConfig, useAuth } from "../../hooks/auth";
|
||||
import { useMetamask } from "../../hooks/connectors/useMetamask";
|
||||
import { useAddress } from "../../hooks/useAddress";
|
||||
import { useChainId } from "../../hooks/useChainId";
|
||||
import { useConnect } from "../../hooks/useConnect";
|
||||
import { useDisconnect } from "../../hooks/useDisconnect";
|
||||
import { useNetwork } from "../../hooks/useNetwork";
|
||||
import { useConnect } from "../../hooks/wagmi-required/useConnect";
|
||||
import { useDisconnect } from "../../hooks/wagmi-required/useDisconnect";
|
||||
import { useNetwork } from "../../hooks/wagmi-required/useNetwork";
|
||||
import { useAddress, useBalance, useChainId } from "../../hooks/wallet";
|
||||
import { Portal } from "../../lib/portal";
|
||||
import { shortenIfAddress } from "../../utils/addresses";
|
||||
import { useClipboard } from "../hooks/useCopyClipboard";
|
||||
import { useIsMounted } from "../hooks/useIsMounted";
|
||||
import { Box } from "../shared/Box";
|
||||
import { Button } from "../shared/Button";
|
||||
import { Icon } from "../shared/Icon";
|
||||
@@ -30,8 +27,8 @@ import { FiXCircle } from "@react-icons/all-files/fi/FiXCircle";
|
||||
import { ChainId, LoginOptions, SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk";
|
||||
import * as menu from "@zag-js/menu";
|
||||
import { normalizeProps, useMachine } from "@zag-js/react";
|
||||
import React, { useId, useMemo } from "react";
|
||||
import { Connector } from "wagmi";
|
||||
import React, { useId } from "react";
|
||||
import type { Connector } from "wagmi";
|
||||
|
||||
const SUPPORTED_CONNECTORS = [
|
||||
"injected",
|
||||
@@ -65,6 +62,7 @@ interface ConnectWalletProps extends ThemeProviderProps {
|
||||
loginConfig?: LoginConfig;
|
||||
loginOptional?: boolean;
|
||||
};
|
||||
className?: string;
|
||||
}
|
||||
|
||||
let connecting = false;
|
||||
@@ -124,15 +122,12 @@ const chainIdToCurrencyMap: Record<
|
||||
*/
|
||||
export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
auth,
|
||||
className,
|
||||
...themeProps
|
||||
}) => {
|
||||
const id = useId();
|
||||
const isMounted = useIsMounted();
|
||||
const address = useAddress();
|
||||
|
||||
const mountedAddress = useMemo(() => {
|
||||
return isMounted ? address : null;
|
||||
}, [address, isMounted]);
|
||||
const walletAddress = useAddress();
|
||||
|
||||
const [state, send] = useMachine(
|
||||
menu.machine({
|
||||
@@ -165,24 +160,26 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
|
||||
const balanceQuery = useBalance();
|
||||
|
||||
const { onCopy, hasCopied } = useClipboard(mountedAddress || "");
|
||||
const { onCopy, hasCopied } = useClipboard(walletAddress || "");
|
||||
|
||||
const authConfig = useThirdwebAuthConfig();
|
||||
const { user, isLoading, login, logout } = useAuth(auth?.loginConfig);
|
||||
|
||||
const requiresSignIn = auth?.loginOptional
|
||||
? false
|
||||
: !!authConfig?.authUrl && !!mountedAddress && !user?.address;
|
||||
: !!authConfig?.authUrl && !!walletAddress && !user?.address;
|
||||
|
||||
return (
|
||||
<ThemeProvider {...themeProps}>
|
||||
<div
|
||||
style={{
|
||||
position: "relative",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
style={{ height: "50px", minWidth: "200px" }}
|
||||
className={className}
|
||||
style={{ height: "50px", minWidth: "200px", width: "100%" }}
|
||||
onClick={async (e) => {
|
||||
if (requiresSignIn) {
|
||||
e.preventDefault();
|
||||
@@ -204,7 +201,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
) : (
|
||||
<FiLock />
|
||||
)
|
||||
) : mountedAddress && chainId && chainId in chainIdToCurrencyMap ? (
|
||||
) : walletAddress && chainId && chainId in chainIdToCurrencyMap ? (
|
||||
<Icon
|
||||
boxSize="1.5em"
|
||||
name={chainIdToCurrencyMap[chainId as SUPPORTED_CHAIN_ID]}
|
||||
@@ -225,7 +222,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
)
|
||||
}
|
||||
>
|
||||
{mountedAddress ? (
|
||||
{walletAddress ? (
|
||||
requiresSignIn ? (
|
||||
<span style={{ whiteSpace: "nowrap" }}>Sign in</span>
|
||||
) : (
|
||||
@@ -249,7 +246,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
)}
|
||||
</span>
|
||||
<span style={{ fontSize: "0.9em" }}>
|
||||
{shortenIfAddress(mountedAddress)}
|
||||
{shortenIfAddress(walletAddress)}
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
@@ -267,7 +264,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
}}
|
||||
>
|
||||
<Menu {...api.contentProps}>
|
||||
{!api.isOpen ? null : mountedAddress ? (
|
||||
{!api.isOpen ? null : walletAddress ? (
|
||||
<>
|
||||
{authConfig?.authUrl && !user?.address && !requiresSignIn ? (
|
||||
<MenuItem
|
||||
@@ -396,10 +393,13 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
})}
|
||||
onClick={async () => {
|
||||
if (!connecting) {
|
||||
connecting = true;
|
||||
await connectWithMetamask();
|
||||
connecting = false;
|
||||
api.close();
|
||||
try {
|
||||
connecting = true;
|
||||
await connectWithMetamask();
|
||||
api.close();
|
||||
} finally {
|
||||
connecting = false;
|
||||
}
|
||||
}
|
||||
}}
|
||||
leftElement={<Icon boxSize="1.5em" name="metamask" />}
|
||||
@@ -421,10 +421,13 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||
})}
|
||||
onClick={async () => {
|
||||
if (!connecting) {
|
||||
connecting = true;
|
||||
await connect(c);
|
||||
connecting = false;
|
||||
api.close();
|
||||
try {
|
||||
connecting = true;
|
||||
await connect(c);
|
||||
api.close();
|
||||
} finally {
|
||||
connecting = false;
|
||||
}
|
||||
}
|
||||
}}
|
||||
leftElement={getIconForConnector(c)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Web3Button } from ".";
|
||||
import { ThirdwebProvider } from "../..";
|
||||
import { ThirdwebProvider } from "../../providers/full";
|
||||
import { test, expect } from "@playwright/experimental-ct-react";
|
||||
|
||||
test.use({ viewport: { width: 500, height: 500 } });
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useContract } from "../../hooks/async/contracts";
|
||||
import { useAddress } from "../../hooks/useAddress";
|
||||
import { useChainId } from "../../hooks/useChainId";
|
||||
import { useNetwork } from "../../hooks/useNetwork";
|
||||
import { useNetwork } from "../../hooks/wagmi-required/useNetwork";
|
||||
import { useAddress, useChainId } from "../../hooks/wallet";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import {
|
||||
createCacheKeyWithNetwork,
|
||||
createContractCacheKey,
|
||||
@@ -20,6 +19,7 @@ type ActionFn = (contract: SmartContract) => any;
|
||||
|
||||
interface Web3ButtonProps<TActionFn extends ActionFn>
|
||||
extends ThemeProviderProps {
|
||||
className?: string;
|
||||
contractAddress: `0x${string}` | `${string}.eth` | string;
|
||||
|
||||
overrides?: CallOverrides;
|
||||
@@ -64,11 +64,12 @@ export const Web3Button = <TAction extends ActionFn>({
|
||||
isDisabled,
|
||||
children,
|
||||
action,
|
||||
className,
|
||||
...themeProps
|
||||
}: PropsWithChildren<Web3ButtonProps<TAction>>) => {
|
||||
const address = useAddress();
|
||||
const walletChainId = useChainId();
|
||||
const sdkChainId = useActiveChainId();
|
||||
const sdkChainId = useSDKChainId();
|
||||
const [, switchNetwork] = useNetwork();
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
@@ -87,7 +88,7 @@ export const Web3Button = <TAction extends ActionFn>({
|
||||
if (switchToChainId) {
|
||||
if (switchNetwork) {
|
||||
await switchNetwork(switchToChainId);
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
return "__NETWORK_SWITCHED__";
|
||||
} else {
|
||||
throw new Error(
|
||||
"need to switch chain but connected wallet does not support switching",
|
||||
@@ -99,10 +100,14 @@ export const Web3Button = <TAction extends ActionFn>({
|
||||
if (onSubmit) {
|
||||
onSubmit();
|
||||
}
|
||||
|
||||
return await action(contract);
|
||||
},
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (res === "__NETWORK_SWITCHED__") {
|
||||
return;
|
||||
}
|
||||
if (onSuccess) {
|
||||
onSuccess(res);
|
||||
}
|
||||
@@ -122,13 +127,14 @@ export const Web3Button = <TAction extends ActionFn>({
|
||||
},
|
||||
);
|
||||
if (!address) {
|
||||
return <ConnectWallet {...themeProps} />;
|
||||
return <ConnectWallet className={className} {...themeProps} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<ThemeProvider {...themeProps}>
|
||||
<Button
|
||||
style={{ height: "50px" }}
|
||||
className={className}
|
||||
style={{ height: "50px", minWidth: "200px", width: "100%" }}
|
||||
isLoading={mutation.isLoading || !contract}
|
||||
onClick={() => mutation.mutate()}
|
||||
isDisabled={isDisabled}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useIsMounted() {
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
useEffect(() => {
|
||||
setIsMounted(true);
|
||||
}, []);
|
||||
return isMounted;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { useAddress } from "../../hooks/useAddress";
|
||||
import { useIsMounted } from "./useIsMounted";
|
||||
import { useMemo } from "react";
|
||||
|
||||
export function useMountedAddress() {
|
||||
const isMounted = useIsMounted();
|
||||
const address = useAddress();
|
||||
|
||||
return useMemo(() => {
|
||||
return isMounted ? address || null : null;
|
||||
}, [address, isMounted]);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
export const __DEV__ = process.env.NODE_ENV !== "production";
|
||||
@@ -0,0 +1,86 @@
|
||||
import { __DEV__ } from "../constants/runtime";
|
||||
import { useThirdwebConfigContext } from "./thirdweb-config";
|
||||
import { UserWallet } from "@thirdweb-dev/sdk";
|
||||
import { Signer } from "ethers";
|
||||
import React, {
|
||||
PropsWithChildren,
|
||||
createContext,
|
||||
useContext,
|
||||
useState,
|
||||
useEffect,
|
||||
} from "react";
|
||||
|
||||
interface ThirdwebConnectedWalletContext {
|
||||
wallet: UserWallet | undefined;
|
||||
address: string | undefined;
|
||||
chainId: number | undefined;
|
||||
signer: Signer | undefined;
|
||||
}
|
||||
|
||||
const INITIAL_CONTEXT_VALUE: ThirdwebConnectedWalletContext = {
|
||||
wallet: undefined,
|
||||
address: undefined,
|
||||
chainId: undefined,
|
||||
signer: undefined,
|
||||
};
|
||||
|
||||
const ThirdwebConnectedWalletContext =
|
||||
createContext<ThirdwebConnectedWalletContext>(INITIAL_CONTEXT_VALUE);
|
||||
|
||||
export const ThirdwebConnectedWalletProvider: React.FC<
|
||||
PropsWithChildren<{ signer?: Signer }>
|
||||
> = ({ signer, children }) => {
|
||||
const { rpcUrlMap } = useThirdwebConfigContext();
|
||||
|
||||
const [contextValue, setContextValue] =
|
||||
useState<ThirdwebConnectedWalletContext>(INITIAL_CONTEXT_VALUE);
|
||||
|
||||
useEffect(() => {
|
||||
let s = signer;
|
||||
if (signer) {
|
||||
// just get both of these up front and keep them around with the context
|
||||
Promise.all([signer.getAddress(), signer.getChainId()])
|
||||
.then(([address, chainId]) => {
|
||||
const rpcUrl = rpcUrlMap[chainId];
|
||||
// only if the signer is still the same!
|
||||
if (signer === s) {
|
||||
const wallet = new UserWallet(signer, {
|
||||
readonlySettings: rpcUrl
|
||||
? {
|
||||
rpcUrl,
|
||||
chainId,
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
setContextValue({ wallet, address, chainId, signer });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if (__DEV__) {
|
||||
console.warn(
|
||||
"failed to get wallet instance in `<ThirdwebConnectedWalletProvider />`",
|
||||
err,
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// if signer is not provided, re-set the context value to initial values
|
||||
setContextValue(INITIAL_CONTEXT_VALUE);
|
||||
}
|
||||
return () => {
|
||||
// set the previous signer to undefined because it is invalid now
|
||||
s = undefined;
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [signer]);
|
||||
|
||||
return (
|
||||
<ThirdwebConnectedWalletContext.Provider value={contextValue}>
|
||||
{children}
|
||||
</ThirdwebConnectedWalletContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export function useThirdwebConnectedWalletContext() {
|
||||
return useContext(ThirdwebConnectedWalletContext);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import {
|
||||
getErcs,
|
||||
DropContract,
|
||||
@@ -264,7 +264,7 @@ export function useSetClaimConditions(
|
||||
contract: RequiredParam<DropContract>,
|
||||
tokenId?: BigNumberish,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const { erc1155, erc721, erc20 } = getErcs(contract);
|
||||
@@ -335,7 +335,7 @@ export function useResetClaimConditions(
|
||||
contract: RequiredParam<DropContract>,
|
||||
tokenId?: BigNumberish,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const { erc1155, erc721, erc20 } = getErcs(contract);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import { RequiredParam, WalletAddress } from "../../types";
|
||||
import {
|
||||
cacheKeys,
|
||||
@@ -82,7 +82,7 @@ export function useUpdatePrimarySaleRecipient(
|
||||
) {
|
||||
const queryClient = useQueryClient();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
return useMutation(
|
||||
(newRecipient: WalletAddress) => {
|
||||
invariant(contract, "No contract provided");
|
||||
@@ -175,7 +175,7 @@ export function useUpdateRoyaltySettings(
|
||||
) {
|
||||
const queryClient = useQueryClient();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
return useMutation(
|
||||
(updatePayload: {
|
||||
seller_fee_basis_points?: number;
|
||||
@@ -270,7 +270,7 @@ export function useUpdatePlatformFees(
|
||||
) {
|
||||
const queryClient = useQueryClient();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
return useMutation(
|
||||
(updatePayload: {
|
||||
platform_fee_basis_points?: number;
|
||||
@@ -362,7 +362,7 @@ export function useUpdateMetadata(
|
||||
) {
|
||||
const queryClient = useQueryClient();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
return useMutation(
|
||||
(updatePayload: CustomContractMetadata) => {
|
||||
invariant(contract, "No contract provided");
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
useActiveChainId,
|
||||
useActiveSignerAddress,
|
||||
useActiveSignerChainId,
|
||||
useSDK,
|
||||
} from "../../Provider";
|
||||
import { useSDK, useSDKChainId } from "../../providers/base";
|
||||
import { ContractAddress, RequiredParam } from "../../types";
|
||||
import {
|
||||
cacheKeys,
|
||||
@@ -11,6 +6,7 @@ import {
|
||||
createContractCacheKey,
|
||||
} from "../../utils/cache-keys";
|
||||
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
||||
import { useAddress, useChainId } from "../wallet";
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
@@ -154,9 +150,9 @@ export function useContract<
|
||||
>(contractAddress: RequiredParam<ContractAddress>) {
|
||||
const sdk = useSDK();
|
||||
const queryClient = useQueryClient();
|
||||
const activeChainId = useActiveChainId();
|
||||
const wallet = useActiveSignerAddress();
|
||||
const walletChainId = useActiveSignerChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const wallet = useAddress();
|
||||
const walletChainId = useChainId();
|
||||
|
||||
// it's there because we put it there.
|
||||
const sdkTimestamp = (sdk as any)?._constructedAt;
|
||||
@@ -229,10 +225,14 @@ export function useContract<
|
||||
* @twfeature ContractMetadata
|
||||
* @beta
|
||||
*/
|
||||
export function useContractMetadata(
|
||||
contract: RequiredParam<ValidContractInstance>,
|
||||
export function useContractMetadata<TContract extends ValidContractInstance>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
return useQueryWithNetwork(
|
||||
return useQueryWithNetwork<
|
||||
typeof contract extends undefined
|
||||
? undefined
|
||||
: Awaited<ReturnType<TContract["metadata"]["get"]>>
|
||||
>(
|
||||
cacheKeys.contract.metadata(contract?.getAddress()),
|
||||
async () => {
|
||||
invariant(contract, "contract is required");
|
||||
@@ -250,7 +250,7 @@ export function useContractMetadata(
|
||||
export function useContractMetadataUpdate(
|
||||
contract: RequiredParam<ValidContractInstance>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -295,7 +295,7 @@ export function useContractEvents(
|
||||
const contractAddress = contract?.getAddress();
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
|
||||
const cacheKey = useMemo(
|
||||
() =>
|
||||
@@ -424,7 +424,7 @@ export function useContractWrite(
|
||||
contract: RequiredParam<ValidContractInstance>,
|
||||
functionName: RequiredParam<string>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import {
|
||||
ClaimNFTParams,
|
||||
ClaimNFTReturnType,
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
QueryAllParams,
|
||||
UploadProgressEvent,
|
||||
} from "@thirdweb-dev/sdk";
|
||||
import { NFTDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-drop";
|
||||
import { NFTDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-drop";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
/** **********************/
|
||||
@@ -44,7 +44,7 @@ import invariant from "tiny-invariant";
|
||||
* @beta
|
||||
*/
|
||||
export function useUnclaimedNFTs(
|
||||
contract: RequiredParam<NFTDropImpl>,
|
||||
contract: RequiredParam<NFTDrop>,
|
||||
queryParams?: QueryAllParams,
|
||||
) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
@@ -198,7 +198,7 @@ export function useBatchesToReveal<TContract extends RevealableContract>(
|
||||
export function useClaimNFT<TContract extends DropContract>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -251,7 +251,7 @@ export function useLazyMint<TContract extends DropContract>(
|
||||
contract: RequiredParam<TContract>,
|
||||
onProgress?: (progress: UploadProgressEvent) => void,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const { erc721, erc1155 } = getErcs(contract);
|
||||
@@ -298,7 +298,7 @@ export function useDelayedRevealLazyMint<TContract extends RevealableContract>(
|
||||
contract: RequiredParam<TContract>,
|
||||
onProgress?: (progress: UploadProgressEvent) => void,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -352,7 +352,7 @@ export function useDelayedRevealLazyMint<TContract extends RevealableContract>(
|
||||
export function useRevealLazyMint<TContract extends RevealableContract>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import { BuyNowParams, MakeBidParams, RequiredParam } from "../../types";
|
||||
import {
|
||||
cacheKeys,
|
||||
invalidateContractAndBalances,
|
||||
} from "../../utils/cache-keys";
|
||||
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
||||
import { useAddress } from "../useAddress";
|
||||
import { useAddress } from "../wallet";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import type {
|
||||
AuctionListing,
|
||||
@@ -15,7 +15,7 @@ import type {
|
||||
NewDirectListing,
|
||||
} from "@thirdweb-dev/sdk";
|
||||
import { ListingType } from "@thirdweb-dev/sdk";
|
||||
import { MarketplaceImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/marketplace";
|
||||
import { Marketplace } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/marketplace";
|
||||
import { BigNumber, BigNumberish } from "ethers";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
@@ -37,7 +37,7 @@ import invariant from "tiny-invariant";
|
||||
* @beta
|
||||
*/
|
||||
export function useListing(
|
||||
contract: RequiredParam<MarketplaceImpl>,
|
||||
contract: RequiredParam<Marketplace>,
|
||||
listingId: RequiredParam<BigNumberish>,
|
||||
) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
@@ -68,7 +68,7 @@ export function useListing(
|
||||
* @beta
|
||||
*/
|
||||
export function useListings(
|
||||
contract: RequiredParam<MarketplaceImpl>,
|
||||
contract: RequiredParam<Marketplace>,
|
||||
filter?: MarketplaceFilter,
|
||||
) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
@@ -97,7 +97,7 @@ export function useListings(
|
||||
* @returns a response object that includes an array of listings
|
||||
* @beta
|
||||
*/
|
||||
export function useListingsCount(contract: RequiredParam<MarketplaceImpl>) {
|
||||
export function useListingsCount(contract: RequiredParam<Marketplace>) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
return useQueryWithNetwork(
|
||||
cacheKeys.contract.marketplace.getTotalCount(contractAddress),
|
||||
@@ -125,7 +125,7 @@ export function useListingsCount(contract: RequiredParam<MarketplaceImpl>) {
|
||||
* @beta
|
||||
*/
|
||||
export function useActiveListings(
|
||||
contract: RequiredParam<MarketplaceImpl>,
|
||||
contract: RequiredParam<Marketplace>,
|
||||
filter?: MarketplaceFilter,
|
||||
) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
@@ -157,7 +157,7 @@ export function useActiveListings(
|
||||
* @beta
|
||||
*/
|
||||
export function useWinningBid(
|
||||
contract: RequiredParam<MarketplaceImpl>,
|
||||
contract: RequiredParam<Marketplace>,
|
||||
listingId: RequiredParam<BigNumberish>,
|
||||
) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
@@ -190,7 +190,7 @@ export function useWinningBid(
|
||||
* @beta
|
||||
*/
|
||||
export function useAuctionWinner(
|
||||
contract: RequiredParam<MarketplaceImpl>,
|
||||
contract: RequiredParam<Marketplace>,
|
||||
listingId: RequiredParam<BigNumberish>,
|
||||
) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
@@ -232,7 +232,7 @@ export function useAuctionWinner(
|
||||
* @returns a response object that includes an array of listings
|
||||
* @beta
|
||||
*/
|
||||
export function useBidBuffer(contract: RequiredParam<MarketplaceImpl>) {
|
||||
export function useBidBuffer(contract: RequiredParam<Marketplace>) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
return useQueryWithNetwork(
|
||||
cacheKeys.contract.marketplace.getBidBufferBps(contractAddress),
|
||||
@@ -281,10 +281,8 @@ export function useBidBuffer(contract: RequiredParam<MarketplaceImpl>) {
|
||||
* @returns a mutation object that can be used to create a new direct listing
|
||||
* @beta
|
||||
*/
|
||||
export function useCreateDirectListing(
|
||||
contract: RequiredParam<MarketplaceImpl>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
export function useCreateDirectListing(contract: RequiredParam<Marketplace>) {
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const walletAddress = useAddress();
|
||||
@@ -339,10 +337,8 @@ export function useCreateDirectListing(
|
||||
* @returns a mutation object that can be used to create a new auction listing
|
||||
* @beta
|
||||
*/
|
||||
export function useCreateAuctionListing(
|
||||
contract: RequiredParam<MarketplaceImpl>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
export function useCreateAuctionListing(contract: RequiredParam<Marketplace>) {
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const walletAddress = useAddress();
|
||||
@@ -397,8 +393,8 @@ export function useCreateAuctionListing(
|
||||
* @returns a mutation object that can be used to create a new auction listing
|
||||
* @beta
|
||||
*/
|
||||
export function useCancelListing(contract: RequiredParam<MarketplaceImpl>) {
|
||||
const activeChainId = useActiveChainId();
|
||||
export function useCancelListing(contract: RequiredParam<Marketplace>) {
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
@@ -451,8 +447,8 @@ export function useCancelListing(contract: RequiredParam<MarketplaceImpl>) {
|
||||
* @returns a mutation object that can be used to make a bid on an auction listing
|
||||
* @beta
|
||||
*/
|
||||
export function useMakeBid(contract: RequiredParam<MarketplaceImpl>) {
|
||||
const activeChainId = useActiveChainId();
|
||||
export function useMakeBid(contract: RequiredParam<Marketplace>) {
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const walletAddress = useAddress();
|
||||
@@ -507,8 +503,8 @@ export function useMakeBid(contract: RequiredParam<MarketplaceImpl>) {
|
||||
* @returns a mutation object that can be used to buy out an auction listing
|
||||
* @beta
|
||||
*/
|
||||
export function useBuyNow(contract: RequiredParam<MarketplaceImpl>) {
|
||||
const activeChainId = useActiveChainId();
|
||||
export function useBuyNow(contract: RequiredParam<Marketplace>) {
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const walletAddress = useAddress();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import {
|
||||
AirdropNFTParams,
|
||||
BurnNFTParams,
|
||||
@@ -420,7 +420,7 @@ export function useNFTBalance(
|
||||
export function useMintNFT<TContract extends NFTContract>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const { erc1155, erc721 } = getErcs(contract);
|
||||
@@ -490,7 +490,7 @@ export function useMintNFT<TContract extends NFTContract>(
|
||||
* @twfeature ERC1155Mintable
|
||||
*/
|
||||
export function useMintNFTSupply(contract: Erc1155) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -555,7 +555,7 @@ export function useMintNFTSupply(contract: Erc1155) {
|
||||
export function useTransferNFT<TContract extends NFTContract>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const { erc1155, erc721 } = getErcs(contract);
|
||||
@@ -649,7 +649,7 @@ export function useTransferNFT<TContract extends NFTContract>(
|
||||
* @beta
|
||||
*/
|
||||
export function useAirdropNFT(contract: Erc1155) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -734,7 +734,7 @@ export function useAirdropNFT(contract: Erc1155) {
|
||||
export function useBurnNFT<TContract extends NFTContract>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
const { erc1155, erc721 } = getErcs(contract);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import { RequiredParam, WalletAddress } from "../../types";
|
||||
import {
|
||||
cacheKeys,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import type { Role, ValidContractInstance } from "@thirdweb-dev/sdk";
|
||||
import type { VoteImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/vote";
|
||||
import type { Vote } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/vote";
|
||||
import type { SmartContract } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/smart-contract";
|
||||
import { constants } from "ethers";
|
||||
import invariant from "tiny-invariant";
|
||||
@@ -19,7 +19,7 @@ import invariant from "tiny-invariant";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type ContractWithRoles = Exclude<ValidContractInstance, VoteImpl>;
|
||||
export type ContractWithRoles = Exclude<ValidContractInstance, Vote>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -183,7 +183,7 @@ export function useIsAddressRole<TContract extends ContractWithRoles>(
|
||||
export function useSetAllRoleMembers<TContract extends ContractWithRoles>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -243,7 +243,7 @@ export function useSetAllRoleMembers<TContract extends ContractWithRoles>(
|
||||
export function useGrantRole<TContract extends ContractWithRoles>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -302,7 +302,7 @@ export function useGrantRole<TContract extends ContractWithRoles>(
|
||||
export function useRevokeRole<TContract extends ContractWithRoles>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import {
|
||||
ClaimTokenParams,
|
||||
RequiredParam,
|
||||
@@ -141,7 +141,7 @@ export function useTokenDecimals(contract: RequiredParam<Erc20>) {
|
||||
* @beta
|
||||
*/
|
||||
export function useMintToken(contract: RequiredParam<Erc20>) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -197,7 +197,7 @@ export function useMintToken(contract: RequiredParam<Erc20>) {
|
||||
export function useClaimToken<TContract extends Erc20>(
|
||||
contract: RequiredParam<TContract>,
|
||||
) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -255,7 +255,7 @@ export function useClaimToken<TContract extends Erc20>(
|
||||
* @beta
|
||||
*/
|
||||
export function useTransferToken(contract: RequiredParam<Erc20>) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -309,7 +309,7 @@ export function useTransferToken(contract: RequiredParam<Erc20>) {
|
||||
* @beta
|
||||
*/
|
||||
export function useTransferBatchToken(contract: RequiredParam<Erc20>) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -370,7 +370,7 @@ export function useTransferBatchToken(contract: RequiredParam<Erc20>) {
|
||||
* @beta
|
||||
*/
|
||||
export function useBurnToken(contract: RequiredParam<Erc20>) {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
const contractAddress = contract?.getAddress();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import { SupportedChainId } from "../../constants/chain";
|
||||
import { useThirdwebConfigContext } from "../../contexts/thirdweb-config";
|
||||
import { ContractAddress } from "../../types";
|
||||
import { cacheKeys } from "../../utils/cache-keys";
|
||||
import { useAddress } from "../useAddress";
|
||||
import { useChainId } from "../useChainId";
|
||||
import { useSigner } from "../useSigner";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { UserWallet } from "@thirdweb-dev/sdk";
|
||||
import { useMemo } from "react";
|
||||
|
||||
/**
|
||||
* A hook to get the native or (optional) ERC20 token balance of the connected wallet.
|
||||
*
|
||||
* @param tokenAddress - the address of the token contract, if empty will use the chain's native token
|
||||
* @returns the balance of the connected wallet (native or ERC20)
|
||||
* @beta
|
||||
*/
|
||||
export function useBalance(tokenAddress?: ContractAddress) {
|
||||
const { rpcUrlMap } = useThirdwebConfigContext();
|
||||
const chainId = useChainId() as SupportedChainId;
|
||||
const signer = useSigner();
|
||||
const walletAddress = useAddress();
|
||||
|
||||
const walletSDK = useMemo(() => {
|
||||
if (signer) {
|
||||
const rpcUrl = rpcUrlMap[chainId];
|
||||
return new UserWallet(signer, {
|
||||
readonlySettings: rpcUrl
|
||||
? {
|
||||
rpcUrl,
|
||||
chainId,
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
|
||||
// we're not apssing rpcUrlMap as a dependency because it should be constant anyways
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [signer, chainId]);
|
||||
|
||||
const cacheKey = useMemo(() => {
|
||||
return cacheKeys.wallet.balance(chainId, walletAddress, tokenAddress);
|
||||
}, [chainId, tokenAddress, walletAddress]);
|
||||
|
||||
return useQuery(
|
||||
cacheKey,
|
||||
() => {
|
||||
return walletSDK?.balance(tokenAddress);
|
||||
},
|
||||
{
|
||||
// if user is not logged in no reason to try to fetch
|
||||
enabled: !!walletSDK && !!walletAddress,
|
||||
retry: true,
|
||||
keepPreviousData: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useSDK } from "../../Provider";
|
||||
import { useThirdwebAuthConfig } from "../../contexts/thirdweb-auth";
|
||||
import { useSDK } from "../../providers/base";
|
||||
import { cacheKeys } from "../../utils/cache-keys";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { LoginOptions } from "@thirdweb-dev/sdk";
|
||||
|
||||
@@ -2,9 +2,10 @@ import {
|
||||
GnosisConnectorArguments,
|
||||
GnosisSafeConnector,
|
||||
} from "../../connectors/gnosis-safe";
|
||||
import { useConnect } from "../useConnect";
|
||||
import { useConnect } from "../wagmi-required/useConnect";
|
||||
import { utils } from "ethers";
|
||||
import invariant from "tiny-invariant";
|
||||
import { useContext as useWagmiContext } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for connecting to a Gnosis Safe. This enables multisig wallets to connect to your application and sing transactions.
|
||||
@@ -32,6 +33,11 @@ import invariant from "tiny-invariant";
|
||||
* @public
|
||||
*/
|
||||
export function useGnosis() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useGnosis() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
||||
);
|
||||
const [connectors, connect] = useConnect();
|
||||
if (connectors.loading) {
|
||||
return () => Promise.reject("Gnosis connector not ready to be used, yet");
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { MagicConnector } from "../../connectors/magic";
|
||||
import { useConnect } from "../useConnect";
|
||||
import { useConnect } from "../wagmi-required/useConnect";
|
||||
import { LoginWithMagicLinkConfiguration } from "magic-sdk";
|
||||
import invariant from "tiny-invariant";
|
||||
import { useContext as useWagmiContext } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for connecting to an email wallet using magic link.
|
||||
@@ -66,6 +67,11 @@ import invariant from "tiny-invariant";
|
||||
* @public
|
||||
*/
|
||||
export function useMagic() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useMagic() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
||||
);
|
||||
const [connectors, connect] = useConnect();
|
||||
if (connectors.loading) {
|
||||
return () => Promise.reject("Magic connector not ready to be used, yet");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { isMobile } from "../../utils/isMobile";
|
||||
import { useConnect } from "../useConnect";
|
||||
import { useConnect } from "../wagmi-required/useConnect";
|
||||
import invariant from "tiny-invariant";
|
||||
import { useContext as useWagmiContext } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for connecting to a Metamask wallet.
|
||||
@@ -31,6 +32,11 @@ import invariant from "tiny-invariant";
|
||||
* @public
|
||||
*/
|
||||
export function useMetamask() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useMetamask() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
||||
);
|
||||
const [connectors, connect] = useConnect();
|
||||
|
||||
const isMetaMaskInjected =
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useConnect } from "../useConnect";
|
||||
import { useConnect } from "../wagmi-required/useConnect";
|
||||
import invariant from "tiny-invariant";
|
||||
import { useContext as useWagmiContext } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for connecting to a mobile wallet with Wallet Connect
|
||||
@@ -31,6 +32,11 @@ import invariant from "tiny-invariant";
|
||||
* @public
|
||||
*/
|
||||
export function useWalletConnect() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useWalletConnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
||||
);
|
||||
const [connectors, connect] = useConnect();
|
||||
if (connectors.loading) {
|
||||
return () =>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useConnect } from "../useConnect";
|
||||
import { useConnect } from "../wagmi-required/useConnect";
|
||||
import invariant from "tiny-invariant";
|
||||
import { useContext as useWagmiContext } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for connecting to a Coinbase wallet.
|
||||
@@ -31,6 +32,11 @@ import invariant from "tiny-invariant";
|
||||
* @public
|
||||
*/
|
||||
export function useCoinbaseWallet() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useCoinbaseWallet() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
||||
);
|
||||
const [connectors, connect] = useConnect();
|
||||
if (connectors.loading) {
|
||||
return () => Promise.reject("Coinbase connector not ready to be used, yet");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { EditionImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition";
|
||||
import { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of an `Edition` contract. This contract is used to interface with ERC1155 compliant NFTs.
|
||||
@@ -29,5 +29,5 @@ import { EditionImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/p
|
||||
*/
|
||||
export function useEdition(contractAddress?: string) {
|
||||
showDeprecationWarning("useEdition()", "useContract<Edition>()");
|
||||
return useContract<EditionImpl>(contractAddress).contract;
|
||||
return useContract<Edition>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { EditionDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition-drop";
|
||||
import { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition-drop";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of an `EditionDrop` contract. This conract is used to interface with ERC1155 compliant NFTs that can be lazily minted.
|
||||
@@ -28,5 +28,5 @@ import { EditionDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contrac
|
||||
*/
|
||||
export function useEditionDrop(contractAddress?: string) {
|
||||
showDeprecationWarning("useEditionDrop()", "useContract<EditionDrop>()");
|
||||
return useContract<EditionDropImpl>(contractAddress).contract;
|
||||
return useContract<EditionDrop>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { MarketplaceImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/marketplace";
|
||||
import { Marketplace } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/marketplace";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of a `Marketplace` contract. This contract is used to support marketplace for purchase and sale of on-chain assets.
|
||||
@@ -29,5 +29,5 @@ import { MarketplaceImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contrac
|
||||
*/
|
||||
export function useMarketplace(contractAddress?: string) {
|
||||
showDeprecationWarning("useMarketplace()", "useContract<Marketplace>()");
|
||||
return useContract<MarketplaceImpl>(contractAddress).contract;
|
||||
return useContract<Marketplace>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { MultiwrapImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/multiwrap";
|
||||
import { Multiwrap } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/multiwrap";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of an `Multiwrap` contract. This contract is an ERC721 in which you can wrap ERC721, ERC1155 and ERC20 tokens.
|
||||
@@ -28,5 +28,5 @@ import { MultiwrapImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts
|
||||
*/
|
||||
export function useMultiwrap(contractAddress?: string) {
|
||||
showDeprecationWarning("useMultiwrap()", "useContract<Multiwrap>()");
|
||||
return useContract<MultiwrapImpl>(contractAddress).contract;
|
||||
return useContract<Multiwrap>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { NFTCollectionImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-collection";
|
||||
import { NFTCollection } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-collection";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of an `NFTCollection` contract. This contract is meant to interface with ERC721 compliant NFTs.
|
||||
@@ -29,5 +29,5 @@ import { NFTCollectionImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contr
|
||||
*/
|
||||
export function useNFTCollection(contractAddress?: string) {
|
||||
showDeprecationWarning("useNFTCollection()", "useContract<NFTCollection>()");
|
||||
return useContract<NFTCollectionImpl>(contractAddress).contract;
|
||||
return useContract<NFTCollection>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { NFTDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-drop";
|
||||
import { NFTDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-drop";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of an `NFTDrop` contract. This contract is meant to interface with ERC721 compliant NFTs that can be lazily minted.
|
||||
@@ -28,5 +28,5 @@ import { NFTDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/p
|
||||
*/
|
||||
export function useNFTDrop(contractAddress?: string) {
|
||||
showDeprecationWarning("useNFTDrop()", "useContract<NFTDrop>()");
|
||||
return useContract<NFTDropImpl>(contractAddress).contract;
|
||||
return useContract<NFTDrop>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { PackImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/pack";
|
||||
import { Pack } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/pack";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of a `Pack` contract. This contract supports the creation of on-chain luck-based lootboxes.
|
||||
@@ -29,5 +29,5 @@ import { PackImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/preb
|
||||
*/
|
||||
export function usePack(contractAddress?: string) {
|
||||
showDeprecationWarning("usePack()", "useContract<Pack>()");
|
||||
return useContract<PackImpl>(contractAddress).contract;
|
||||
return useContract<Pack>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { SignatureDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/signature-drop";
|
||||
import { SignatureDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/signature-drop";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of an `SignatureDrop` contract. This contract is meant to interface with ERC721 compliant NFTs that can be lazily minted.
|
||||
@@ -28,5 +28,5 @@ import { SignatureDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contr
|
||||
*/
|
||||
export function useSignatureDrop(contractAddress?: string) {
|
||||
showDeprecationWarning("useSignatureDrop()", "useContract<SignatureDrop>()");
|
||||
return useContract<SignatureDropImpl>(contractAddress).contract;
|
||||
return useContract<SignatureDrop>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { SplitImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/split";
|
||||
import { Split } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/split";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of a `Split` contract. This contract supports fund distribution to multiple parties.
|
||||
@@ -29,5 +29,5 @@ import { SplitImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/pre
|
||||
*/
|
||||
export function useSplit(contractAddress?: string) {
|
||||
showDeprecationWarning("useSplit()", "useContract<Split>()");
|
||||
return useContract<SplitImpl>(contractAddress).contract;
|
||||
return useContract<Split>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { TokenImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/token";
|
||||
import { Token } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/token";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of a `Token` contract. This contract supports ERC20 compliant tokens.
|
||||
@@ -29,5 +29,5 @@ import { TokenImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/pre
|
||||
*/
|
||||
export function useToken(contractAddress?: string) {
|
||||
showDeprecationWarning("useToken()", "useContract<Token>()");
|
||||
return useContract<TokenImpl>(contractAddress).contract;
|
||||
return useContract<Token>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { TokenDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/token-drop";
|
||||
import { TokenDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/token-drop";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of a `Token Drop` contract.
|
||||
@@ -29,5 +29,5 @@ import { TokenDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts
|
||||
*/
|
||||
export function useTokenDrop(contractAddress?: string) {
|
||||
showDeprecationWarning("useTokenDrop()", "useContract<TokenDrop>()");
|
||||
return useContract<TokenDropImpl>(contractAddress).contract;
|
||||
return useContract<TokenDrop>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||
import { useContract } from "../async/contracts";
|
||||
import { VoteImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/vote";
|
||||
import { Vote } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/vote";
|
||||
|
||||
/**
|
||||
* Hook for getting an instance of an `Vote` contract. This contract enables fully featured voting-based decentralized governance systems.
|
||||
@@ -29,5 +29,5 @@ import { VoteImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/preb
|
||||
*/
|
||||
export function useVote(contractAddress?: string) {
|
||||
showDeprecationWarning("useVote()", "useContract<Vote>()");
|
||||
return useContract<VoteImpl>(contractAddress).contract;
|
||||
return useContract<Vote>(contractAddress).contract;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useActiveChainId } from "../../Provider";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
import { createCacheKeyWithNetwork } from "../../utils/cache-keys";
|
||||
import {
|
||||
QueryFunction,
|
||||
@@ -22,7 +22,7 @@ export function useQueryWithNetwork<
|
||||
"queryKey" | "queryFn"
|
||||
>,
|
||||
): UseQueryResult<TData, TError> {
|
||||
const activeChainId = useActiveChainId();
|
||||
const activeChainId = useSDKChainId();
|
||||
|
||||
const mergedOptions: Omit<
|
||||
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { useAccount } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for accessing the address of the connected wallet
|
||||
*
|
||||
* ```javascript
|
||||
* import { useAddress } from "@thirdweb-dev/react"
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To get the address of the connected wallet, you can use the hook as follows:
|
||||
*
|
||||
* ```javascript
|
||||
* import { useAddress } from "@thirdweb-dev/react"
|
||||
*
|
||||
* const App = () => {
|
||||
* const address = useAddress()
|
||||
*
|
||||
* return <div>{address}</div>
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* The `address` variable will hold the address of the connected wallet if a user has connected using one of the supported wallet connection hooks.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function useAddress(): string | undefined {
|
||||
const [account] = useAccount();
|
||||
return account.data?.address;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { useNetwork } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for accessing the chain ID of the network the current wallet is connected to
|
||||
*
|
||||
* ```javascript
|
||||
* import { useChainId } from "@thirdweb-dev/react"
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* You can get the chain ID of the connected wallet by using the hook as follows:
|
||||
* ```javascript
|
||||
* import { useChainId } from "@thirdweb-dev/react"
|
||||
*
|
||||
* const App = () => {
|
||||
* const chainId = useChainId()
|
||||
*
|
||||
* return <div>{chainId}</div>
|
||||
* }
|
||||
* ```
|
||||
* @public
|
||||
*/
|
||||
export function useChainId(): number | undefined {
|
||||
return useNetwork()["0"].data.chain?.id;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { useConnect as useWagmiConnect } from "wagmi";
|
||||
|
||||
/**
|
||||
* for now just re-exported
|
||||
* @internal
|
||||
*/
|
||||
export function useConnect() {
|
||||
return useWagmiConnect();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useDesiredChainId } from "../Provider";
|
||||
import { useChainId } from "./useChainId";
|
||||
import { useDesiredChainId } from "../providers/base";
|
||||
import { useChainId } from "./wallet";
|
||||
|
||||
/**
|
||||
* Hook for checking whether the connected wallet is on the correct network specified by the `desiredChainId` passed to the `<ThirdwebProvider />`.
|
||||
@@ -28,16 +28,16 @@ import { useChainId } from "./useChainId";
|
||||
*/
|
||||
export function useNetworkMismatch() {
|
||||
const desiredChainId = useDesiredChainId();
|
||||
const activeChainId = useChainId();
|
||||
const walletChainId = useChainId();
|
||||
|
||||
if (desiredChainId === -1) {
|
||||
// means no desiredChainId is set in the <ThirdwebProvider />, so we don't care about the network mismatch
|
||||
return false;
|
||||
}
|
||||
if (!activeChainId) {
|
||||
if (!walletChainId) {
|
||||
// means no wallet is connected yet, so we don't care about the network mismatch
|
||||
return false;
|
||||
}
|
||||
// check if the chainIds are different
|
||||
return desiredChainId !== activeChainId;
|
||||
return desiredChainId !== walletChainId;
|
||||
}
|
||||
|
||||
@@ -1,47 +1,10 @@
|
||||
import { Signer } from "ethers";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useAccount, useNetwork, useSigner as useWagmiSigner } from "wagmi";
|
||||
import { useThirdwebConnectedWalletContext } from "../contexts/thirdweb-wallet";
|
||||
import type { Signer } from "ethers";
|
||||
|
||||
/**
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function useSigner() {
|
||||
const [signer, getSigner] = useWagmiSigner();
|
||||
const [account] = useAccount();
|
||||
const [network] = useNetwork();
|
||||
|
||||
const _getSignerPromise = useRef<ReturnType<typeof getSigner> | null>(null);
|
||||
|
||||
const address = account.data?.address;
|
||||
const chainId = network.data.chain?.id;
|
||||
|
||||
const previousAddress = usePrevious(account.data?.address);
|
||||
const previousChainId = usePrevious(network.data?.chain?.id);
|
||||
|
||||
useEffect(() => {
|
||||
if (address !== previousAddress || chainId !== previousChainId) {
|
||||
if (!_getSignerPromise.current) {
|
||||
return;
|
||||
} else {
|
||||
_getSignerPromise.current = getSigner().finally(() => {
|
||||
_getSignerPromise.current = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [address, chainId, getSigner, previousAddress, previousChainId]);
|
||||
|
||||
return Signer.isSigner(signer.data) ? signer.data : undefined;
|
||||
}
|
||||
|
||||
function usePrevious<TVal>(value: TVal): TVal | undefined {
|
||||
// The ref object is a generic container whose current property is mutable ...
|
||||
// ... and can hold any value, similar to an instance property on a class
|
||||
const ref = useRef<TVal>();
|
||||
// Store current value in ref
|
||||
useEffect(() => {
|
||||
ref.current = value;
|
||||
}, [value]); // Only re-run if value changes
|
||||
// Return previous value (happens before update in useEffect above)
|
||||
return ref.current;
|
||||
export function useSigner(): Signer | undefined {
|
||||
return useThirdwebConnectedWalletContext().signer;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import invariant from "tiny-invariant";
|
||||
import {
|
||||
useAccount as useWagmiAccount,
|
||||
useContext as useWagmiContext,
|
||||
} from "wagmi";
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useAccount() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useNetwork() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own network logic.`,
|
||||
);
|
||||
return useWagmiAccount();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import invariant from "tiny-invariant";
|
||||
import {
|
||||
useConnect as useWagmiConnect,
|
||||
useContext as useWagmiContext,
|
||||
} from "wagmi";
|
||||
|
||||
/**
|
||||
* for now just re-exported
|
||||
* @internal
|
||||
*/
|
||||
export function useConnect() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useConnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own connection logic.`,
|
||||
);
|
||||
return useWagmiConnect();
|
||||
}
|
||||
+8
-2
@@ -1,6 +1,7 @@
|
||||
import { GnosisSafeConnector } from "../connectors/gnosis-safe";
|
||||
import { GnosisSafeConnector } from "../../connectors/gnosis-safe";
|
||||
import { useConnect } from "./useConnect";
|
||||
import { useAccount } from "wagmi";
|
||||
import invariant from "tiny-invariant";
|
||||
import { useAccount, useContext as useWagmiContext } from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for disconnecting the currently connected wallet
|
||||
@@ -31,6 +32,11 @@ import { useAccount } from "wagmi";
|
||||
* @public
|
||||
*/
|
||||
export function useDisconnect(options?: { reconnectAfterGnosis?: boolean }) {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useDisconnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own connection logic.`,
|
||||
);
|
||||
const optsWithDefaults = { ...{ reconnectAfterGnosis: true }, ...options };
|
||||
const [, connect] = useConnect();
|
||||
const [data, disconnect] = useAccount();
|
||||
+10
-1
@@ -1,4 +1,8 @@
|
||||
import { useNetwork as useWagmiNetwork } from "wagmi";
|
||||
import invariant from "tiny-invariant";
|
||||
import {
|
||||
useNetwork as useWagmiNetwork,
|
||||
useContext as useWagmiContext,
|
||||
} from "wagmi";
|
||||
|
||||
/**
|
||||
* Hook for getting metadata about the network the current wallet is connected to and switching networks
|
||||
@@ -25,5 +29,10 @@ import { useNetwork as useWagmiNetwork } from "wagmi";
|
||||
*/
|
||||
|
||||
export function useNetwork() {
|
||||
const wagmiContext = useWagmiContext();
|
||||
invariant(
|
||||
wagmiContext,
|
||||
`useNetwork() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own network logic.`,
|
||||
);
|
||||
return useWagmiNetwork();
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { useThirdwebConnectedWalletContext } from "../contexts/thirdweb-wallet";
|
||||
import { ContractAddress } from "../types";
|
||||
import { cacheKeys } from "../utils/cache-keys";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
|
||||
/**
|
||||
* A hook to get the native or (optional) ERC20 token balance of the connected wallet.
|
||||
*
|
||||
* @param tokenAddress - the address of the token contract, if empty will use the chain's native token
|
||||
* @returns the balance of the connected wallet (native or ERC20)
|
||||
* @beta
|
||||
*/
|
||||
export function useBalance(tokenAddress?: ContractAddress) {
|
||||
const walletAddress = useAddress();
|
||||
|
||||
const { wallet, address, chainId } = useThirdwebConnectedWalletContext();
|
||||
|
||||
const cacheKey = useMemo(() => {
|
||||
return cacheKeys.wallet.balance(chainId || -1, address, tokenAddress);
|
||||
}, [chainId, tokenAddress, address]);
|
||||
|
||||
return useQuery(
|
||||
cacheKey,
|
||||
() => {
|
||||
return wallet?.balance(tokenAddress);
|
||||
},
|
||||
{
|
||||
// if user is not logged in no reason to try to fetch
|
||||
enabled: !!wallet && !!walletAddress && !!chainId,
|
||||
retry: true,
|
||||
keepPreviousData: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useConnectedWallet() {
|
||||
return useThirdwebConnectedWalletContext().wallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for accessing the address of the connected wallet
|
||||
*
|
||||
* ```javascript
|
||||
* import { useAddress } from "@thirdweb-dev/react"
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To get the address of the connected wallet, you can use the hook as follows:
|
||||
*
|
||||
* ```javascript
|
||||
* import { useAddress } from "@thirdweb-dev/react"
|
||||
*
|
||||
* const App = () => {
|
||||
* const address = useAddress()
|
||||
*
|
||||
* return <div>{address}</div>
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* The `address` variable will hold the address of the connected wallet if a user has connected using one of the supported wallet connection hooks.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function useAddress(): string | undefined {
|
||||
return useThirdwebConnectedWalletContext().address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for accessing the chain ID of the network the current wallet is connected to
|
||||
*
|
||||
* ```javascript
|
||||
* import { useChainId } from "@thirdweb-dev/react"
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* You can get the chain ID of the connected wallet by using the hook as follows:
|
||||
* ```javascript
|
||||
* import { useChainId } from "@thirdweb-dev/react"
|
||||
*
|
||||
* const App = () => {
|
||||
* const chainId = useChainId()
|
||||
*
|
||||
* return <div>{chainId}</div>
|
||||
* }
|
||||
* ```
|
||||
* @public
|
||||
*/
|
||||
export function useChainId(): number | undefined {
|
||||
return useThirdwebConnectedWalletContext().chainId;
|
||||
}
|
||||
+27
-22
@@ -1,36 +1,41 @@
|
||||
// providers
|
||||
export * from "./providers/base";
|
||||
export * from "./providers/full";
|
||||
|
||||
// contract hooks
|
||||
export * from "./Provider";
|
||||
export * from "./hooks/auth";
|
||||
export * from "./hooks/contracts";
|
||||
export * from "./hooks/useDisconnect";
|
||||
export * from "./hooks/useConnect";
|
||||
export * from "./hooks/useSigner";
|
||||
export * from "./hooks/useAddress";
|
||||
export * from "./hooks/useReadonlySDK";
|
||||
export * from "./hooks/connectors/useMetamask";
|
||||
export * from "./hooks/connectors/useWalletConnect";
|
||||
export * from "./hooks/connectors/useWalletLink";
|
||||
export * from "./hooks/connectors/useGnosis";
|
||||
export * from "./hooks/connectors/useMagic";
|
||||
export * from "./hooks/useChainId";
|
||||
export * from "./hooks/useNetworkMismatch";
|
||||
export * from "./hooks/useNetwork";
|
||||
|
||||
// re-exports
|
||||
export { defaultChains, defaultL2Chains, useAccount, useProvider } from "wagmi";
|
||||
export { ChainId } from "@thirdweb-dev/sdk";
|
||||
|
||||
// async hooks
|
||||
// async contract hooks
|
||||
export * from "./hooks/async/contracts";
|
||||
export * from "./hooks/async/nft";
|
||||
export * from "./hooks/async/drop";
|
||||
export * from "./hooks/async/marketplace";
|
||||
export * from "./hooks/async/token";
|
||||
export * from "./hooks/async/claim-conditions";
|
||||
export * from "./hooks/async/wallet";
|
||||
|
||||
export * from "./hooks/async/contract-settings";
|
||||
export * from "./hooks/async/roles";
|
||||
|
||||
// thirdweb hooks (work as long as at least `<ThirdwebSDkProvider>` is used)
|
||||
export * from "./hooks/auth";
|
||||
export * from "./hooks/useSigner";
|
||||
export * from "./hooks/useReadonlySDK";
|
||||
export * from "./hooks/useNetworkMismatch";
|
||||
export * from "./hooks/wallet";
|
||||
|
||||
// require to be inside `<ThirdwebProvider />`
|
||||
export * from "./hooks/wagmi-required/useAccount";
|
||||
export * from "./hooks/wagmi-required/useNetwork";
|
||||
export * from "./hooks/wagmi-required/useDisconnect";
|
||||
export * from "./hooks/wagmi-required/useConnect";
|
||||
export * from "./hooks/connectors/useMetamask";
|
||||
export * from "./hooks/connectors/useWalletConnect";
|
||||
export * from "./hooks/connectors/useWalletLink";
|
||||
export * from "./hooks/connectors/useGnosis";
|
||||
export * from "./hooks/connectors/useMagic";
|
||||
|
||||
// re-exports
|
||||
export { ChainId } from "@thirdweb-dev/sdk";
|
||||
|
||||
// types
|
||||
export * from "./types";
|
||||
export type { ThirdwebAuthConfig } from "./contexts/thirdweb-auth";
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import {
|
||||
ThirdwebAuthConfig,
|
||||
ThirdwebAuthConfigProvider,
|
||||
} from "../contexts/thirdweb-auth";
|
||||
import {
|
||||
ThirdwebConnectedWalletProvider,
|
||||
useThirdwebConnectedWalletContext,
|
||||
} from "../contexts/thirdweb-wallet";
|
||||
import { RequiredParam } from "../types";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import {
|
||||
ChainOrRpc,
|
||||
SDKOptions,
|
||||
SignerOrProvider,
|
||||
SUPPORTED_CHAIN_ID,
|
||||
ThirdwebSDK,
|
||||
} from "@thirdweb-dev/sdk";
|
||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||
import { Signer } from "ethers";
|
||||
import { createContext, useContext, useEffect, useMemo } from "react";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
interface TWSDKContext {
|
||||
sdk?: ThirdwebSDK;
|
||||
_inProvider?: true;
|
||||
desiredChainId: number;
|
||||
}
|
||||
|
||||
const ThirdwebSDKContext = createContext<TWSDKContext>({ desiredChainId: -1 });
|
||||
|
||||
export interface ThirdwebSDKProviderProps {
|
||||
desiredChainId: RequiredParam<SUPPORTED_CHAIN_ID>;
|
||||
provider: ChainOrRpc | SignerOrProvider;
|
||||
|
||||
signer?: Signer;
|
||||
|
||||
sdkOptions?: SDKOptions;
|
||||
storageInterface?: ThirdwebStorage;
|
||||
authConfig?: ThirdwebAuthConfig;
|
||||
|
||||
queryClient?: QueryClient;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const WrappedThirdwebSDKProvider: React.FC<
|
||||
React.PropsWithChildren<Omit<ThirdwebSDKProviderProps, "signer">>
|
||||
> = ({
|
||||
sdkOptions,
|
||||
desiredChainId,
|
||||
storageInterface,
|
||||
provider,
|
||||
|
||||
queryClient,
|
||||
authConfig,
|
||||
children,
|
||||
}) => {
|
||||
const queryClientWithDefault: QueryClient = useMemo(() => {
|
||||
return queryClient ? queryClient : new QueryClient();
|
||||
}, [queryClient]);
|
||||
|
||||
const { signer } = useThirdwebConnectedWalletContext();
|
||||
|
||||
const sdk = useMemo(() => {
|
||||
if (!desiredChainId || typeof window === "undefined") {
|
||||
return undefined;
|
||||
}
|
||||
const _sdk = new ThirdwebSDK(provider, sdkOptions, storageInterface);
|
||||
(_sdk as any)._constructedAt = Date.now();
|
||||
(_sdk as any)._chainId = desiredChainId;
|
||||
return _sdk;
|
||||
}, [provider, sdkOptions, storageInterface, desiredChainId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (signer && sdk && (sdk as any)._chainId === desiredChainId) {
|
||||
sdk.updateSignerOrProvider(signer);
|
||||
}
|
||||
}, [signer, sdk, desiredChainId]);
|
||||
|
||||
const ctxValue = useMemo(
|
||||
() => ({
|
||||
sdk,
|
||||
desiredChainId: desiredChainId || -1,
|
||||
_inProvider: true as const,
|
||||
}),
|
||||
[desiredChainId, sdk],
|
||||
);
|
||||
|
||||
return (
|
||||
<ThirdwebAuthConfigProvider value={authConfig}>
|
||||
<QueryClientProvider client={queryClientWithDefault}>
|
||||
<ThirdwebSDKContext.Provider value={ctxValue}>
|
||||
{children}
|
||||
</ThirdwebSDKContext.Provider>
|
||||
</QueryClientProvider>
|
||||
</ThirdwebAuthConfigProvider>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* A basic wrapper around the Thirdweb SDK.
|
||||
*
|
||||
* You can use this in order to be able to pass a provider & signer directly to the SDK.
|
||||
*
|
||||
* @remarks Utilizing this provider will mean hooks for wallet management are not available, if you need those please use the {@link ThirdwebProvider} instead.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const ThirdwebSDKProvider: React.FC<
|
||||
React.PropsWithChildren<ThirdwebSDKProviderProps>
|
||||
> = ({ signer, children, ...restProps }) => {
|
||||
return (
|
||||
<ThirdwebConnectedWalletProvider signer={signer}>
|
||||
<WrappedThirdwebSDKProvider {...restProps}>
|
||||
{children}
|
||||
</WrappedThirdwebSDKProvider>
|
||||
</ThirdwebConnectedWalletProvider>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function useSDKContext(): TWSDKContext {
|
||||
const ctx = useContext(ThirdwebSDKContext);
|
||||
invariant(
|
||||
ctx._inProvider,
|
||||
"useSDK must be called from within a ThirdwebProvider, did you forget to wrap your app in a <ThirdwebProvider />?",
|
||||
);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {@link ThirdwebSDK}
|
||||
* Access the instance of the thirdweb SDK created by the ThirdwebProvider
|
||||
* to call methods using the connected wallet on the desiredChainId.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const sdk = useSDK();
|
||||
* ```
|
||||
*/
|
||||
export function useSDK(): ThirdwebSDK | undefined {
|
||||
const { sdk } = useSDKContext();
|
||||
return sdk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useDesiredChainId(): number {
|
||||
const { desiredChainId } = useSDKContext();
|
||||
return desiredChainId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useSDKChainId(): SUPPORTED_CHAIN_ID | undefined {
|
||||
const sdk = useSDK();
|
||||
return (sdk as any)?._chainId;
|
||||
}
|
||||
@@ -1,40 +1,32 @@
|
||||
import {
|
||||
GnosisConnectorArguments,
|
||||
GnosisSafeConnector,
|
||||
} from "./connectors/gnosis-safe";
|
||||
import { MagicConnector, MagicConnectorArguments } from "./connectors/magic";
|
||||
} from "../connectors/gnosis-safe";
|
||||
import { MagicConnector, MagicConnectorArguments } from "../connectors/magic";
|
||||
import {
|
||||
Chain,
|
||||
SupportedChain,
|
||||
defaultSupportedChains,
|
||||
} from "./constants/chain";
|
||||
import {
|
||||
ThirdwebAuthConfig,
|
||||
ThirdwebAuthConfigProvider,
|
||||
} from "./contexts/thirdweb-auth";
|
||||
} from "../constants/chain";
|
||||
import { ThirdwebAuthConfig } from "../contexts/thirdweb-auth";
|
||||
import {
|
||||
ThirdwebConfigProvider,
|
||||
defaultChainRpc,
|
||||
} from "./contexts/thirdweb-config";
|
||||
import { useSigner } from "./hooks/useSigner";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
} from "../contexts/thirdweb-config";
|
||||
import { ThirdwebSDKProvider, ThirdwebSDKProviderProps } from "./base";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
ChainOrRpc,
|
||||
SDKOptions,
|
||||
SUPPORTED_CHAIN_ID,
|
||||
SignerOrProvider,
|
||||
ThirdwebSDK,
|
||||
getProviderForNetwork,
|
||||
SDKOptionsOutput,
|
||||
} from "@thirdweb-dev/sdk";
|
||||
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||
import { Signer } from "ethers";
|
||||
import React, { createContext, useEffect, useMemo, useState } from "react";
|
||||
import invariant from "tiny-invariant";
|
||||
import React, { useMemo } from "react";
|
||||
import {
|
||||
WagmiProvider,
|
||||
ProviderProps as WagmiproviderProps,
|
||||
useProvider,
|
||||
useSigner,
|
||||
} from "wagmi";
|
||||
import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet";
|
||||
import { InjectedConnector } from "wagmi/connectors/injected";
|
||||
@@ -447,194 +439,14 @@ export const ThirdwebProvider = <
|
||||
);
|
||||
};
|
||||
|
||||
export interface ThirdwebSDKProviderWagmiWrapper
|
||||
extends Pick<
|
||||
ThirdwebProviderProps,
|
||||
"desiredChainId" | "sdkOptions" | "storageInterface" | "authConfig"
|
||||
> {
|
||||
signer?: Signer;
|
||||
provider: ChainOrRpc | SignerOrProvider;
|
||||
queryClient?: QueryClient;
|
||||
}
|
||||
|
||||
const ThirdwebSDKProviderWagmiWrapper: React.FC<
|
||||
React.PropsWithChildren<
|
||||
Omit<ThirdwebSDKProviderWagmiWrapper, "signer" | "provider">
|
||||
>
|
||||
React.PropsWithChildren<Omit<ThirdwebSDKProviderProps, "signer" | "provider">>
|
||||
> = ({ children, ...props }) => {
|
||||
const provider = useProvider();
|
||||
const signer = useSigner();
|
||||
const [signer] = useSigner();
|
||||
return (
|
||||
<ThirdwebSDKProvider signer={signer} provider={provider} {...props}>
|
||||
<ThirdwebSDKProvider signer={signer.data} provider={provider} {...props}>
|
||||
{children}
|
||||
</ThirdwebSDKProvider>
|
||||
);
|
||||
};
|
||||
|
||||
interface SDKContext {
|
||||
sdk?: ThirdwebSDK;
|
||||
_inProvider?: true;
|
||||
desiredChainId: number;
|
||||
}
|
||||
|
||||
const ThirdwebSDKContext = createContext<SDKContext>({ desiredChainId: -1 });
|
||||
|
||||
export interface ThirdwebSDKProviderProps
|
||||
extends Omit<ThirdwebSDKProviderWagmiWrapper, "queryClient"> {
|
||||
queryClient?: QueryClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* A barebones wrapper around the Thirdweb SDK.
|
||||
*
|
||||
* You can use this in order to be able to pass a provider & signer directly to the SDK.
|
||||
*
|
||||
* @remarks Utilizing this provider will mean hooks for wallet management are not available, if you need those please use the {@link ThirdwebProvider} instead.
|
||||
*
|
||||
* @beta
|
||||
*/
|
||||
export const ThirdwebSDKProvider: React.FC<
|
||||
React.PropsWithChildren<ThirdwebSDKProviderProps>
|
||||
> = ({
|
||||
sdkOptions,
|
||||
desiredChainId,
|
||||
storageInterface,
|
||||
provider,
|
||||
signer,
|
||||
queryClient,
|
||||
authConfig,
|
||||
children,
|
||||
}) => {
|
||||
const queryClientWithDefault: QueryClient = useMemo(() => {
|
||||
return queryClient ? queryClient : new QueryClient();
|
||||
}, [queryClient]);
|
||||
|
||||
const sdk = useMemo(() => {
|
||||
if (!desiredChainId || typeof window === "undefined") {
|
||||
return undefined;
|
||||
}
|
||||
const _sdk = new ThirdwebSDK(provider, sdkOptions, storageInterface);
|
||||
(_sdk as any)._constructedAt = Date.now();
|
||||
(_sdk as any)._chainId = desiredChainId;
|
||||
return _sdk;
|
||||
}, [provider, sdkOptions, storageInterface, desiredChainId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (signer && sdk && (sdk as any)._chainId === desiredChainId) {
|
||||
sdk.updateSignerOrProvider(signer);
|
||||
}
|
||||
}, [signer, sdk, desiredChainId]);
|
||||
|
||||
const ctxValue = useMemo(
|
||||
() => ({
|
||||
sdk,
|
||||
desiredChainId: desiredChainId || -1,
|
||||
_inProvider: true as const,
|
||||
}),
|
||||
[desiredChainId, sdk],
|
||||
);
|
||||
|
||||
return (
|
||||
<ThirdwebAuthConfigProvider value={authConfig}>
|
||||
<QueryClientProvider client={queryClientWithDefault}>
|
||||
<ThirdwebSDKContext.Provider value={ctxValue}>
|
||||
{children}
|
||||
</ThirdwebSDKContext.Provider>
|
||||
</QueryClientProvider>
|
||||
</ThirdwebAuthConfigProvider>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function useSDKContext(): SDKContext {
|
||||
const ctx = React.useContext(ThirdwebSDKContext);
|
||||
invariant(
|
||||
ctx._inProvider,
|
||||
"useSDK must be called from within a ThirdwebProvider, did you forget to wrap your app in a <ThirdwebProvider />?",
|
||||
);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {@link ThirdwebSDK}
|
||||
* Access the instance of the thirdweb SDK created by the ThirdwebProvider
|
||||
* to call methods using the connected wallet on the desiredChainId.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const sdk = useSDK();
|
||||
* ```
|
||||
*/
|
||||
export function useSDK(): ThirdwebSDK | undefined {
|
||||
const { sdk } = useSDKContext();
|
||||
return sdk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useDesiredChainId(): number {
|
||||
const { desiredChainId } = useSDKContext();
|
||||
return desiredChainId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useActiveChainId(): SUPPORTED_CHAIN_ID | undefined {
|
||||
const sdk = useSDK();
|
||||
return (sdk as any)?._chainId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useActiveSigner(): Signer | undefined {
|
||||
const sdk = useSDK();
|
||||
const [signer, setSigner] = useState<Signer | undefined>(sdk?.getSigner());
|
||||
useEffect(() => {
|
||||
if (sdk) {
|
||||
sdk.wallet.events.on("signerChanged", (newSigner: Signer | undefined) => {
|
||||
setSigner(newSigner);
|
||||
});
|
||||
return () => {
|
||||
sdk.wallet.events.off("signerChanged");
|
||||
};
|
||||
}
|
||||
}, [sdk]);
|
||||
return signer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useActiveSignerAddress(): string | undefined {
|
||||
const signer = useActiveSigner();
|
||||
const [address, setAddress] = useState<string | undefined>(undefined);
|
||||
useEffect(() => {
|
||||
if (signer) {
|
||||
signer.getAddress().then((a) => {
|
||||
setAddress(a);
|
||||
});
|
||||
}
|
||||
}, [signer]);
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function useActiveSignerChainId(): number | undefined {
|
||||
const signer = useActiveSigner();
|
||||
const [chainId, setChainId] = useState<number | undefined>(undefined);
|
||||
useEffect(() => {
|
||||
if (signer) {
|
||||
signer.getChainId().then((id) => {
|
||||
setChainId(id);
|
||||
});
|
||||
}
|
||||
}, [signer]);
|
||||
return chainId;
|
||||
}
|
||||
+13
-17
@@ -14,12 +14,12 @@ import type {
|
||||
Erc20,
|
||||
ClaimOptions,
|
||||
} from "@thirdweb-dev/sdk";
|
||||
import type { EditionImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition";
|
||||
import type { EditionDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition-drop";
|
||||
import type { NFTCollectionImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-collection";
|
||||
import type { NFTDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-drop";
|
||||
import type { SignatureDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/signature-drop";
|
||||
import type { TokenDropImpl } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/token-drop";
|
||||
import type { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition";
|
||||
import type { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/edition-drop";
|
||||
import type { NFTCollection } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-collection";
|
||||
import type { NFTDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/nft-drop";
|
||||
import type { SignatureDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/signature-drop";
|
||||
import type { TokenDrop } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/prebuilt-implementations/token-drop";
|
||||
import type { SmartContract } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/smart-contract";
|
||||
import type { BigNumberish } from "ethers";
|
||||
|
||||
@@ -72,8 +72,8 @@ export type TokenBurnParams = {
|
||||
* @beta
|
||||
*/
|
||||
export type NFTContract =
|
||||
| NFTCollectionImpl
|
||||
| EditionImpl
|
||||
| NFTCollection
|
||||
| Edition
|
||||
| Exclude<DropContract, "TokenDrop">;
|
||||
|
||||
/**
|
||||
@@ -172,10 +172,10 @@ export type BurnNFTParams = { tokenId: BigNumberish; amount?: Amount };
|
||||
* @beta
|
||||
*/
|
||||
export type DropContract =
|
||||
| NFTDropImpl
|
||||
| EditionDropImpl
|
||||
| SignatureDropImpl
|
||||
| TokenDropImpl
|
||||
| NFTDrop
|
||||
| EditionDrop
|
||||
| SignatureDrop
|
||||
| TokenDrop
|
||||
| SmartContract
|
||||
| null;
|
||||
|
||||
@@ -183,11 +183,7 @@ export type DropContract =
|
||||
* The possible revealable contract types.
|
||||
* @beta
|
||||
*/
|
||||
export type RevealableContract =
|
||||
| NFTDropImpl
|
||||
| SignatureDropImpl
|
||||
| SmartContract
|
||||
| null;
|
||||
export type RevealableContract = NFTDrop | SignatureDrop | SmartContract | null;
|
||||
|
||||
/**
|
||||
* The params for the {@link useDelayedRevealLazyMint} hook mutation.
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import { __DEV__ } from "../constants/runtime";
|
||||
|
||||
const warnSet = new Set<`${string}:${string}`>();
|
||||
|
||||
export const showDeprecationWarning =
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
process.env.NODE_ENV !== "production"
|
||||
? (deprecated: string, replacement: string) => {
|
||||
if (warnSet.has(`${deprecated}:${replacement}`)) {
|
||||
return;
|
||||
}
|
||||
warnSet.add(`${deprecated}:${replacement}`);
|
||||
console.warn(
|
||||
`\`${deprecated}\` is deprecated and will be removed in a future version. Please use \`${replacement}\` instead.`,
|
||||
);
|
||||
}
|
||||
: () => undefined;
|
||||
export const showDeprecationWarning = (
|
||||
deprecated: string,
|
||||
replacement: string,
|
||||
) => {
|
||||
// deprecation warnings only in dev only in dev
|
||||
if (__DEV__) {
|
||||
if (warnSet.has(`${deprecated}:${replacement}`)) {
|
||||
return;
|
||||
}
|
||||
warnSet.add(`${deprecated}:${replacement}`);
|
||||
console.warn(
|
||||
`\`${deprecated}\` is deprecated and will be removed in a future major version. Please use \`${replacement}\` instead.`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
"merkletreejs": "^0.2.24",
|
||||
"multihashes": "^4.0.3",
|
||||
"tiny-invariant": "^1.2.0",
|
||||
"uuid": "^8.3.2",
|
||||
"uuid": "^9.0.0",
|
||||
"zod": "^3.11.6"
|
||||
},
|
||||
"resolutions": {
|
||||
|
||||
@@ -46,33 +46,8 @@ function languageNameToKey(languageName) {
|
||||
}
|
||||
}
|
||||
|
||||
const additionalClassesToParse = [
|
||||
"ThirdwebSDK",
|
||||
"ContractDeployer",
|
||||
"MarketplaceDirect",
|
||||
"MarketplaceAuction",
|
||||
"ContractMetadata",
|
||||
"ContractEvents",
|
||||
"DelayedReveal",
|
||||
"ContractRoles",
|
||||
"RemoteStorage",
|
||||
"GasCostEstimator",
|
||||
"ContractInterceptor",
|
||||
"ContractRoles",
|
||||
"DropClaimConditions",
|
||||
"ContractPrimarySale",
|
||||
"ContractRoyalty",
|
||||
"ContractPlatformFee",
|
||||
"WalletAuthenticator",
|
||||
"UserWallet",
|
||||
"SmartContract",
|
||||
];
|
||||
|
||||
const modules = json.members[0].members.filter(
|
||||
(m) =>
|
||||
(m.kind === "Class" && m.name.endsWith("Impl")) ||
|
||||
additionalClassesToParse.includes(m.name),
|
||||
);
|
||||
// just include all classes
|
||||
const modules = json.members[0].members.filter((m) => m.kind === "Class");
|
||||
|
||||
const bases = ["StandardErc20", "StandardErc721", "StandardErc1155"];
|
||||
const baseClasses = json.members[0].members.filter(
|
||||
@@ -152,7 +127,7 @@ const moduleMap = modules.reduce((acc, m) => {
|
||||
const baseClassMembers = baseClassCode
|
||||
? parseMembers(baseClassCode.members, "Method", baseClassCode.name)
|
||||
: [];
|
||||
acc[m.name.replace("Impl", "")] = {
|
||||
acc[m.name] = {
|
||||
name: m.name,
|
||||
summary: Formatter.renderDocNode(docComment.summarySection),
|
||||
remarks: docComment.remarksBlock
|
||||
|
||||
@@ -24,7 +24,7 @@ type InitalizeParams = [
|
||||
options?: SDKOptions,
|
||||
];
|
||||
|
||||
export const EditionDrop = {
|
||||
export const EditionDropInitializer = {
|
||||
name: "DropERC1155" as const,
|
||||
contractType: "edition-drop" as const,
|
||||
schema: DropErc1155ContractSchema,
|
||||
@@ -33,24 +33,18 @@ export const EditionDrop = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
EditionDrop.getAbi(),
|
||||
EditionDropInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/edition-drop"),
|
||||
]);
|
||||
|
||||
return new contract.EditionDropImpl(
|
||||
network,
|
||||
address,
|
||||
storage,
|
||||
options,
|
||||
abi,
|
||||
);
|
||||
return new contract.EditionDrop(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/DropERC1155.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const Edition = {
|
||||
export const EditionInitializer = {
|
||||
name: "TokenERC1155" as const,
|
||||
contractType: "edition" as const,
|
||||
schema: TokenErc1155ContractSchema,
|
||||
@@ -59,18 +53,18 @@ export const Edition = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
Edition.getAbi(),
|
||||
EditionInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/edition"),
|
||||
]);
|
||||
|
||||
return new contract.EditionImpl(network, address, storage, options, abi);
|
||||
return new contract.Edition(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC1155.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const Marketplace = {
|
||||
export const MarketplaceInitializer = {
|
||||
name: "Marketplace" as const,
|
||||
contractType: "marketplace" as const,
|
||||
schema: MarketplaceContractSchema,
|
||||
@@ -79,24 +73,18 @@ export const Marketplace = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
Marketplace.getAbi(),
|
||||
MarketplaceInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/marketplace"),
|
||||
]);
|
||||
|
||||
return new contract.MarketplaceImpl(
|
||||
network,
|
||||
address,
|
||||
storage,
|
||||
options,
|
||||
abi,
|
||||
);
|
||||
return new contract.Marketplace(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Marketplace.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const Multiwrap = {
|
||||
export const MultiwrapInitializer = {
|
||||
name: "Multiwrap" as const,
|
||||
contractType: "multiwrap" as const,
|
||||
schema: MultiwrapContractSchema,
|
||||
@@ -105,18 +93,18 @@ export const Multiwrap = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
Multiwrap.getAbi(),
|
||||
MultiwrapInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/multiwrap"),
|
||||
]);
|
||||
|
||||
return new contract.MultiwrapImpl(network, address, storage, options, abi);
|
||||
return new contract.Multiwrap(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Multiwrap.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const NFTCollection = {
|
||||
export const NFTCollectionInitializer = {
|
||||
name: "TokenERC721" as const,
|
||||
contractType: "nft-collection" as const,
|
||||
schema: TokenErc721ContractSchema,
|
||||
@@ -126,24 +114,18 @@ export const NFTCollection = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
NFTCollection.getAbi(),
|
||||
NFTCollectionInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/nft-collection"),
|
||||
]);
|
||||
|
||||
return new contract.NFTCollectionImpl(
|
||||
network,
|
||||
address,
|
||||
storage,
|
||||
options,
|
||||
abi,
|
||||
);
|
||||
return new contract.NFTCollection(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC721.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const NFTDrop = {
|
||||
export const NFTDropInitializer = {
|
||||
name: "DropERC721" as const,
|
||||
contractType: "nft-drop" as const,
|
||||
schema: DropErc721ContractSchema,
|
||||
@@ -152,18 +134,18 @@ export const NFTDrop = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
NFTDrop.getAbi(),
|
||||
NFTDropInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/nft-drop"),
|
||||
]);
|
||||
|
||||
return new contract.NFTDropImpl(network, address, storage, options, abi);
|
||||
return new contract.NFTDrop(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/DropERC721.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const Pack = {
|
||||
export const PackInitializer = {
|
||||
name: "Pack" as const,
|
||||
contractType: "pack" as const,
|
||||
schema: PackContractSchema,
|
||||
@@ -173,17 +155,17 @@ export const Pack = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
Pack.getAbi(),
|
||||
PackInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/pack"),
|
||||
]);
|
||||
|
||||
return new contract.PackImpl(network, address, storage, options, abi);
|
||||
return new contract.Pack(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Pack.json")).default,
|
||||
};
|
||||
|
||||
export const SignatureDrop = {
|
||||
export const SignatureDropInitializer = {
|
||||
name: "SignatureDrop" as const,
|
||||
contractType: "signature-drop" as const,
|
||||
schema: DropErc721ContractSchema,
|
||||
@@ -193,24 +175,18 @@ export const SignatureDrop = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
SignatureDrop.getAbi(),
|
||||
SignatureDropInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/signature-drop"),
|
||||
]);
|
||||
|
||||
return new contract.SignatureDropImpl(
|
||||
network,
|
||||
address,
|
||||
storage,
|
||||
options,
|
||||
abi,
|
||||
);
|
||||
return new contract.SignatureDrop(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/SignatureDrop.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const Split = {
|
||||
export const SplitInitializer = {
|
||||
name: "Split" as const,
|
||||
contractType: "split" as const,
|
||||
schema: SplitsContractSchema,
|
||||
@@ -220,17 +196,17 @@ export const Split = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
Split.getAbi(),
|
||||
SplitInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/split"),
|
||||
]);
|
||||
|
||||
return new contract.SplitImpl(network, address, storage, options, abi);
|
||||
return new contract.Split(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Split.json")).default,
|
||||
};
|
||||
|
||||
export const TokenDrop = {
|
||||
export const TokenDropInitializer = {
|
||||
name: "DropERC20" as const,
|
||||
contractType: "token-drop" as const,
|
||||
schema: DropErc20ContractSchema,
|
||||
@@ -240,18 +216,18 @@ export const TokenDrop = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
TokenDrop.getAbi(),
|
||||
TokenDropInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/token-drop"),
|
||||
]);
|
||||
|
||||
return new contract.TokenDropImpl(network, address, storage, options, abi);
|
||||
return new contract.TokenDrop(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const Token = {
|
||||
export const TokenInitializer = {
|
||||
name: "TokenERC20" as const,
|
||||
contractType: "token" as const,
|
||||
schema: TokenErc20ContractSchema,
|
||||
@@ -260,18 +236,18 @@ export const Token = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
Token.getAbi(),
|
||||
TokenInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/token"),
|
||||
]);
|
||||
|
||||
return new contract.TokenImpl(network, address, storage, options, abi);
|
||||
return new contract.Token(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC20.json"))
|
||||
.default,
|
||||
};
|
||||
|
||||
export const Vote = {
|
||||
export const VoteInitializer = {
|
||||
name: "VoteERC20" as const,
|
||||
contractType: "vote" as const,
|
||||
schema: VoteContractSchema,
|
||||
@@ -281,11 +257,11 @@ export const Vote = {
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
const [abi, contract] = await Promise.all([
|
||||
Vote.getAbi(),
|
||||
VoteInitializer.getAbi(),
|
||||
import("./prebuilt-implementations/vote"),
|
||||
]);
|
||||
|
||||
return new contract.VoteImpl(network, address, storage, options, abi);
|
||||
return new contract.Vote(network, address, storage, options, abi);
|
||||
},
|
||||
getAbi: async () =>
|
||||
(await import("@thirdweb-dev/contracts-js/dist/abis/VoteERC20.json"))
|
||||
@@ -297,18 +273,18 @@ export const Vote = {
|
||||
* @internal
|
||||
*/
|
||||
export const PREBUILT_CONTRACTS_MAP = {
|
||||
[EditionDrop.contractType]: EditionDrop,
|
||||
[Edition.contractType]: Edition,
|
||||
[Marketplace.contractType]: Marketplace,
|
||||
[Multiwrap.contractType]: Multiwrap,
|
||||
[NFTCollection.contractType]: NFTCollection,
|
||||
[NFTDrop.contractType]: NFTDrop,
|
||||
[Pack.contractType]: Pack,
|
||||
[SignatureDrop.contractType]: SignatureDrop,
|
||||
[Split.contractType]: Split,
|
||||
[TokenDrop.contractType]: TokenDrop,
|
||||
[Token.contractType]: Token,
|
||||
[Vote.contractType]: Vote,
|
||||
[EditionDropInitializer.contractType]: EditionDropInitializer,
|
||||
[EditionInitializer.contractType]: EditionInitializer,
|
||||
[MarketplaceInitializer.contractType]: MarketplaceInitializer,
|
||||
[MultiwrapInitializer.contractType]: MultiwrapInitializer,
|
||||
[NFTCollectionInitializer.contractType]: NFTCollectionInitializer,
|
||||
[NFTDropInitializer.contractType]: NFTDropInitializer,
|
||||
[PackInitializer.contractType]: PackInitializer,
|
||||
[SignatureDropInitializer.contractType]: SignatureDropInitializer,
|
||||
[SplitInitializer.contractType]: SplitInitializer,
|
||||
[TokenDropInitializer.contractType]: TokenDropInitializer,
|
||||
[TokenInitializer.contractType]: TokenInitializer,
|
||||
[VoteInitializer.contractType]: VoteInitializer,
|
||||
} as const;
|
||||
|
||||
const SmartContract = {
|
||||
|
||||
@@ -44,7 +44,7 @@ import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class EditionDropImpl extends StandardErc1155<DropERC1155> {
|
||||
export class EditionDrop extends StandardErc1155<DropERC1155> {
|
||||
private static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -59,7 +59,7 @@ export class EditionDropImpl extends StandardErc1155<DropERC1155> {
|
||||
>;
|
||||
public roles: ContractRoles<
|
||||
DropERC1155,
|
||||
typeof EditionDropImpl.contractRoles[number]
|
||||
typeof EditionDrop.contractRoles[number]
|
||||
>;
|
||||
/**
|
||||
* Configure royalties
|
||||
@@ -140,7 +140,7 @@ export class EditionDropImpl extends StandardErc1155<DropERC1155> {
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
EditionDropImpl.contractRoles,
|
||||
EditionDrop.contractRoles,
|
||||
);
|
||||
this.royalties = new ContractRoyalty(this.contractWrapper, this.metadata);
|
||||
this.sales = new ContractPrimarySale(this.contractWrapper);
|
||||
|
||||
@@ -44,7 +44,7 @@ import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class EditionImpl extends StandardErc1155<TokenERC1155> {
|
||||
export class Edition extends StandardErc1155<TokenERC1155> {
|
||||
static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -54,7 +54,7 @@ export class EditionImpl extends StandardErc1155<TokenERC1155> {
|
||||
>;
|
||||
public roles: ContractRoles<
|
||||
TokenERC1155,
|
||||
typeof EditionImpl.contractRoles[number]
|
||||
typeof Edition.contractRoles[number]
|
||||
>;
|
||||
public sales: ContractPrimarySale<TokenERC1155>;
|
||||
public platformFees: ContractPlatformFee<TokenERC1155>;
|
||||
@@ -120,10 +120,7 @@ export class EditionImpl extends StandardErc1155<TokenERC1155> {
|
||||
TokenErc1155ContractSchema,
|
||||
this.storage,
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
EditionImpl.contractRoles,
|
||||
);
|
||||
this.roles = new ContractRoles(this.contractWrapper, Edition.contractRoles);
|
||||
this.royalties = new ContractRoyalty(this.contractWrapper, this.metadata);
|
||||
this.sales = new ContractPrimarySale(this.contractWrapper);
|
||||
this.encoder = new ContractEncoder(this.contractWrapper);
|
||||
|
||||
@@ -38,7 +38,7 @@ import invariant from "tiny-invariant";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class MarketplaceImpl implements UpdateableNetwork {
|
||||
export class Marketplace implements UpdateableNetwork {
|
||||
static contractRoles = ["admin", "lister", "asset"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -55,7 +55,7 @@ export class MarketplaceImpl implements UpdateableNetwork {
|
||||
>;
|
||||
public roles: ContractRoles<
|
||||
MarketplaceContract,
|
||||
typeof MarketplaceImpl.contractRoles[number]
|
||||
typeof Marketplace.contractRoles[number]
|
||||
>;
|
||||
/**
|
||||
* @internal
|
||||
@@ -155,7 +155,7 @@ export class MarketplaceImpl implements UpdateableNetwork {
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
MarketplaceImpl.contractRoles,
|
||||
Marketplace.contractRoles,
|
||||
);
|
||||
this.encoder = new ContractEncoder(this.contractWrapper);
|
||||
this.estimator = new GasCostEstimator(this.contractWrapper);
|
||||
|
||||
@@ -50,7 +50,7 @@ import { BigNumberish, CallOverrides, ethers } from "ethers";
|
||||
*
|
||||
* @beta
|
||||
*/
|
||||
export class MultiwrapImpl extends StandardErc721<MultiwrapContract> {
|
||||
export class Multiwrap extends StandardErc721<MultiwrapContract> {
|
||||
static contractRoles = ["transfer", "minter", "unwrap", "asset"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -63,7 +63,7 @@ export class MultiwrapImpl extends StandardErc721<MultiwrapContract> {
|
||||
public events: ContractEvents<MultiwrapContract>;
|
||||
public roles: ContractRoles<
|
||||
MultiwrapContract,
|
||||
typeof MultiwrapImpl.contractRoles[number]
|
||||
typeof Multiwrap.contractRoles[number]
|
||||
>;
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ export class MultiwrapImpl extends StandardErc721<MultiwrapContract> {
|
||||
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
MultiwrapImpl.contractRoles,
|
||||
Multiwrap.contractRoles,
|
||||
);
|
||||
this.encoder = new ContractEncoder(this.contractWrapper);
|
||||
this.estimator = new GasCostEstimator(this.contractWrapper);
|
||||
|
||||
@@ -39,7 +39,7 @@ import { BigNumberish, CallOverrides, constants } from "ethers";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class NFTCollectionImpl extends StandardErc721<TokenERC721> {
|
||||
export class NFTCollection extends StandardErc721<TokenERC721> {
|
||||
static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -49,7 +49,7 @@ export class NFTCollectionImpl extends StandardErc721<TokenERC721> {
|
||||
>;
|
||||
public roles: ContractRoles<
|
||||
TokenERC721,
|
||||
typeof NFTCollectionImpl.contractRoles[number]
|
||||
typeof NFTCollection.contractRoles[number]
|
||||
>;
|
||||
public encoder: ContractEncoder<TokenERC721>;
|
||||
public estimator: GasCostEstimator<TokenERC721>;
|
||||
@@ -122,7 +122,7 @@ export class NFTCollectionImpl extends StandardErc721<TokenERC721> {
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
NFTCollectionImpl.contractRoles,
|
||||
NFTCollection.contractRoles,
|
||||
);
|
||||
this.royalties = new ContractRoyalty(this.contractWrapper, this.metadata);
|
||||
this.sales = new ContractPrimarySale(this.contractWrapper);
|
||||
|
||||
@@ -65,7 +65,7 @@ import {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class NFTDropImpl extends StandardErc721<DropERC721> {
|
||||
export class NFTDrop extends StandardErc721<DropERC721> {
|
||||
static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -78,10 +78,7 @@ export class NFTDropImpl extends StandardErc721<DropERC721> {
|
||||
public sales: ContractPrimarySale<DropERC721>;
|
||||
public platformFees: ContractPlatformFee<DropERC721>;
|
||||
public events: ContractEvents<DropERC721>;
|
||||
public roles: ContractRoles<
|
||||
DropERC721,
|
||||
typeof NFTDropImpl.contractRoles[number]
|
||||
>;
|
||||
public roles: ContractRoles<DropERC721, typeof NFTDrop.contractRoles[number]>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@@ -191,10 +188,7 @@ export class NFTDropImpl extends StandardErc721<DropERC721> {
|
||||
DropErc721ContractSchema,
|
||||
this.storage,
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
NFTDropImpl.contractRoles,
|
||||
);
|
||||
this.roles = new ContractRoles(this.contractWrapper, NFTDrop.contractRoles);
|
||||
this.royalties = new ContractRoyalty(this.contractWrapper, this.metadata);
|
||||
this.sales = new ContractPrimarySale(this.contractWrapper);
|
||||
this.claimConditions = new DropClaimConditions(
|
||||
|
||||
@@ -56,15 +56,12 @@ import { BigNumber, BigNumberish, CallOverrides, ethers } from "ethers";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class PackImpl extends StandardErc1155<PackContract> {
|
||||
export class Pack extends StandardErc1155<PackContract> {
|
||||
static contractRoles = ["admin", "minter", "pauser", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
public metadata: ContractMetadata<PackContract, typeof PackContractSchema>;
|
||||
public roles: ContractRoles<
|
||||
PackContract,
|
||||
typeof PackImpl.contractRoles[number]
|
||||
>;
|
||||
public roles: ContractRoles<PackContract, typeof Pack.contractRoles[number]>;
|
||||
public encoder: ContractEncoder<PackContract>;
|
||||
public events: ContractEvents<PackContract>;
|
||||
public estimator: GasCostEstimator<PackContract>;
|
||||
@@ -124,10 +121,7 @@ export class PackImpl extends StandardErc1155<PackContract> {
|
||||
PackContractSchema,
|
||||
this.storage,
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
PackImpl.contractRoles,
|
||||
);
|
||||
this.roles = new ContractRoles(this.contractWrapper, Pack.contractRoles);
|
||||
this.royalties = new ContractRoyalty(this.contractWrapper, this.metadata);
|
||||
this.encoder = new ContractEncoder(this.contractWrapper);
|
||||
this.estimator = new GasCostEstimator(this.contractWrapper);
|
||||
|
||||
@@ -55,7 +55,7 @@ import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class SignatureDropImpl extends StandardErc721<SignatureDropContract> {
|
||||
export class SignatureDrop extends StandardErc721<SignatureDropContract> {
|
||||
static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -71,7 +71,7 @@ export class SignatureDropImpl extends StandardErc721<SignatureDropContract> {
|
||||
public events: ContractEvents<SignatureDropContract>;
|
||||
public roles: ContractRoles<
|
||||
SignatureDropContract,
|
||||
typeof SignatureDropImpl.contractRoles[number]
|
||||
typeof SignatureDrop.contractRoles[number]
|
||||
>;
|
||||
/**
|
||||
* @internal
|
||||
@@ -190,7 +190,7 @@ export class SignatureDropImpl extends StandardErc721<SignatureDropContract> {
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
SignatureDropImpl.contractRoles,
|
||||
SignatureDrop.contractRoles,
|
||||
);
|
||||
this.royalties = new ContractRoyalty(this.contractWrapper, this.metadata);
|
||||
this.sales = new ContractPrimarySale(this.contractWrapper);
|
||||
|
||||
@@ -35,7 +35,7 @@ import { BigNumber, CallOverrides, Contract } from "ethers";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class SplitImpl implements UpdateableNetwork {
|
||||
export class Split implements UpdateableNetwork {
|
||||
static contractRoles = ["admin"] as const;
|
||||
|
||||
private contractWrapper: ContractWrapper<SplitContract>;
|
||||
@@ -48,7 +48,7 @@ export class SplitImpl implements UpdateableNetwork {
|
||||
public events: ContractEvents<SplitContract>;
|
||||
public roles: ContractRoles<
|
||||
SplitContract,
|
||||
typeof SplitImpl.contractRoles[number]
|
||||
typeof Split.contractRoles[number]
|
||||
>;
|
||||
/**
|
||||
* @internal
|
||||
@@ -76,10 +76,7 @@ export class SplitImpl implements UpdateableNetwork {
|
||||
SplitsContractSchema,
|
||||
this.storage,
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
SplitImpl.contractRoles,
|
||||
);
|
||||
this.roles = new ContractRoles(this.contractWrapper, Split.contractRoles);
|
||||
this.encoder = new ContractEncoder(this.contractWrapper);
|
||||
this.estimator = new GasCostEstimator(this.contractWrapper);
|
||||
this.events = new ContractEvents(this.contractWrapper);
|
||||
|
||||
@@ -32,14 +32,14 @@ import { CallOverrides, constants } from "ethers";
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
export class TokenDropImpl extends StandardErc20<DropERC20> {
|
||||
export class TokenDrop extends StandardErc20<DropERC20> {
|
||||
static contractRoles = ["admin", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
public metadata: ContractMetadata<DropERC20, typeof DropErc20ContractSchema>;
|
||||
public roles: ContractRoles<
|
||||
DropERC20,
|
||||
typeof TokenDropImpl.contractRoles[number]
|
||||
typeof TokenDrop.contractRoles[number]
|
||||
>;
|
||||
public encoder: ContractEncoder<DropERC20>;
|
||||
public estimator: GasCostEstimator<DropERC20>;
|
||||
@@ -96,7 +96,7 @@ export class TokenDropImpl extends StandardErc20<DropERC20> {
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
TokenDropImpl.contractRoles,
|
||||
TokenDrop.contractRoles,
|
||||
);
|
||||
this.encoder = new ContractEncoder(this.contractWrapper);
|
||||
this.estimator = new GasCostEstimator(this.contractWrapper);
|
||||
|
||||
@@ -35,7 +35,7 @@ import { CallOverrides, constants } from "ethers";
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class TokenImpl extends StandardErc20<TokenERC20> {
|
||||
export class Token extends StandardErc20<TokenERC20> {
|
||||
static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
@@ -43,10 +43,7 @@ export class TokenImpl extends StandardErc20<TokenERC20> {
|
||||
TokenERC20,
|
||||
typeof TokenErc20ContractSchema
|
||||
>;
|
||||
public roles: ContractRoles<
|
||||
TokenERC20,
|
||||
typeof TokenImpl.contractRoles[number]
|
||||
>;
|
||||
public roles: ContractRoles<TokenERC20, typeof Token.contractRoles[number]>;
|
||||
public encoder: ContractEncoder<TokenERC20>;
|
||||
public estimator: GasCostEstimator<TokenERC20>;
|
||||
public history: TokenERC20History;
|
||||
@@ -92,10 +89,7 @@ export class TokenImpl extends StandardErc20<TokenERC20> {
|
||||
TokenErc20ContractSchema,
|
||||
this.storage,
|
||||
);
|
||||
this.roles = new ContractRoles(
|
||||
this.contractWrapper,
|
||||
TokenImpl.contractRoles,
|
||||
);
|
||||
this.roles = new ContractRoles(this.contractWrapper, Token.contractRoles);
|
||||
this.sales = new ContractPrimarySale(this.contractWrapper);
|
||||
this.events = new ContractEvents(this.contractWrapper);
|
||||
this.history = new TokenERC20History(this.contractWrapper, this.events);
|
||||
|
||||
@@ -51,7 +51,7 @@ import {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class VoteImpl implements UpdateableNetwork {
|
||||
export class Vote implements UpdateableNetwork {
|
||||
private contractWrapper: ContractWrapper<VoteERC20>;
|
||||
private storage: ThirdwebStorage;
|
||||
|
||||
|
||||
@@ -6,19 +6,19 @@ import {
|
||||
} from "../../common/index";
|
||||
import { getContractAddressByChainId } from "../../constants/addresses";
|
||||
import {
|
||||
EditionDropInitializer,
|
||||
EditionInitializer,
|
||||
MarketplaceInitializer,
|
||||
MultiwrapInitializer,
|
||||
NFTCollectionInitializer,
|
||||
NFTDropInitializer,
|
||||
PackInitializer,
|
||||
PREBUILT_CONTRACTS_MAP,
|
||||
Edition,
|
||||
EditionDrop,
|
||||
Marketplace,
|
||||
Multiwrap,
|
||||
NFTCollection,
|
||||
NFTDrop,
|
||||
Pack,
|
||||
SignatureDrop,
|
||||
Split,
|
||||
Token,
|
||||
TokenDrop,
|
||||
Vote,
|
||||
SignatureDropInitializer,
|
||||
SplitInitializer,
|
||||
TokenDropInitializer,
|
||||
TokenInitializer,
|
||||
VoteInitializer,
|
||||
} from "../../contracts";
|
||||
import { FactoryDeploymentSchema } from "../../schema/contracts/custom";
|
||||
import { SDKOptions } from "../../schema/sdk-options";
|
||||
@@ -89,7 +89,7 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
metadata: NFTContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(
|
||||
NFTCollection.contractType,
|
||||
NFTCollectionInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
@@ -112,7 +112,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployNFTDrop(
|
||||
metadata: NFTContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(NFTDrop.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
NFTDropInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +137,7 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
metadata: NFTContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(
|
||||
SignatureDrop.contractType,
|
||||
SignatureDropInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
@@ -157,7 +160,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployMultiwrap(
|
||||
metadata: MultiwrapContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(Multiwrap.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
MultiwrapInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +184,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployEdition(
|
||||
metadata: NFTContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(Edition.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
EditionInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +208,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployEditionDrop(
|
||||
metadata: NFTContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(EditionDrop.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
EditionDropInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +232,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployToken(
|
||||
metadata: TokenContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(Token.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
TokenInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +256,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployTokenDrop(
|
||||
metadata: TokenContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(TokenDrop.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
TokenDropInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +280,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployMarketplace(
|
||||
metadata: MarketplaceContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(Marketplace.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
MarketplaceInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +304,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployPack(
|
||||
metadata: NFTContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(Pack.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
PackInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,7 +338,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deploySplit(
|
||||
metadata: SplitContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(Split.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
SplitInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +363,10 @@ export class ContractDeployer extends RPCConnectionHandler {
|
||||
public async deployVote(
|
||||
metadata: VoteContractDeployMetadata,
|
||||
): Promise<string> {
|
||||
return await this.deployBuiltInContract(Vote.contractType, metadata);
|
||||
return await this.deployBuiltInContract(
|
||||
VoteInitializer.contractType,
|
||||
metadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ import { TransactionTask } from "./TransactionTask";
|
||||
import { ContractMetadata } from "./contract-metadata";
|
||||
import { ContractWrapper } from "./contract-wrapper";
|
||||
import { DropErc1155ClaimConditions } from "./drop-erc1155-claim-conditions";
|
||||
import { DropERC1155 } from "@thirdweb-dev/contracts-js";
|
||||
import type { DropERC1155 } from "@thirdweb-dev/contracts-js";
|
||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||
import { BigNumberish, ethers } from "ethers";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { normalizePriceValue, setErc20Allowance } from "../../common/currency";
|
||||
import { uploadOrExtractURIs } from "../../common/nft";
|
||||
import { FEATURE_EDITION_SIGNATURE_MINTABLE } from "../../constants/erc1155-features";
|
||||
import type { NFTCollection } from "../../contracts";
|
||||
import type { NFTCollectionInitializer } from "../../contracts";
|
||||
import {
|
||||
FilledSignaturePayload1155WithTokenId,
|
||||
MintRequest1155,
|
||||
@@ -35,13 +35,16 @@ export class Erc1155SignatureMintable implements DetectableFeature {
|
||||
>;
|
||||
private storage: ThirdwebStorage;
|
||||
private roles:
|
||||
| ContractRoles<TokenERC1155, typeof NFTCollection.roles[number]>
|
||||
| ContractRoles<TokenERC1155, typeof NFTCollectionInitializer.roles[number]>
|
||||
| undefined;
|
||||
|
||||
constructor(
|
||||
contractWrapper: ContractWrapper<BaseSignatureMintERC1155 | TokenERC1155>,
|
||||
storage: ThirdwebStorage,
|
||||
roles?: ContractRoles<TokenERC1155, typeof NFTCollection.roles[number]>,
|
||||
roles?: ContractRoles<
|
||||
TokenERC1155,
|
||||
typeof NFTCollectionInitializer.roles[number]
|
||||
>,
|
||||
) {
|
||||
this.contractWrapper = contractWrapper;
|
||||
this.storage = storage;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { normalizePriceValue, setErc20Allowance } from "../../common/currency";
|
||||
import { FEATURE_TOKEN_SIGNATURE_MINTABLE } from "../../constants/erc20-features";
|
||||
import type { Token } from "../../contracts";
|
||||
import type { TokenInitializer } from "../../contracts";
|
||||
import {
|
||||
FilledSignaturePayload20,
|
||||
MintRequest20,
|
||||
@@ -28,12 +28,12 @@ export class Erc20SignatureMintable implements DetectableFeature {
|
||||
|
||||
private contractWrapper: ContractWrapper<TokenERC20>;
|
||||
private roles:
|
||||
| ContractRoles<TokenERC20, typeof Token.roles[number]>
|
||||
| ContractRoles<TokenERC20, typeof TokenInitializer.roles[number]>
|
||||
| undefined;
|
||||
|
||||
constructor(
|
||||
contractWrapper: ContractWrapper<TokenERC20>,
|
||||
roles?: ContractRoles<TokenERC20, typeof Token.roles[number]>,
|
||||
roles?: ContractRoles<TokenERC20, typeof TokenInitializer.roles[number]>,
|
||||
) {
|
||||
this.contractWrapper = contractWrapper;
|
||||
this.roles = roles;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { TransactionError } from "../../common";
|
||||
import { CONTRACT_ADDRESSES, SUPPORTED_CHAIN_IDS } from "../../constants";
|
||||
import {
|
||||
EditionDropInitializer,
|
||||
EditionInitializer,
|
||||
MarketplaceInitializer,
|
||||
MultiwrapInitializer,
|
||||
NFTCollectionInitializer,
|
||||
NFTDropInitializer,
|
||||
PackInitializer,
|
||||
PREBUILT_CONTRACTS_MAP,
|
||||
Edition,
|
||||
EditionDrop,
|
||||
Marketplace,
|
||||
Multiwrap,
|
||||
NFTCollection,
|
||||
NFTDrop,
|
||||
Pack,
|
||||
SignatureDrop,
|
||||
Split,
|
||||
Token,
|
||||
TokenDrop,
|
||||
Vote,
|
||||
SignatureDropInitializer,
|
||||
SplitInitializer,
|
||||
TokenDropInitializer,
|
||||
TokenInitializer,
|
||||
VoteInitializer,
|
||||
} from "../../contracts";
|
||||
import { SDKOptions } from "../../schema/sdk-options";
|
||||
import {
|
||||
@@ -145,7 +145,7 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
contractURI: string,
|
||||
): Promise<any[]> {
|
||||
let trustedForwarders =
|
||||
contractType === Pack.contractType
|
||||
contractType === PackInitializer.contractType
|
||||
? []
|
||||
: await this.getDefaultTrustedForwarders();
|
||||
// override default forwarders if custom ones are passed in
|
||||
@@ -153,9 +153,9 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
trustedForwarders = metadata.trusted_forwarders;
|
||||
}
|
||||
switch (contractType) {
|
||||
case NFTDrop.contractType:
|
||||
case NFTCollection.contractType:
|
||||
const erc721metadata = NFTDrop.schema.deploy.parse(metadata);
|
||||
case NFTDropInitializer.contractType:
|
||||
case NFTCollectionInitializer.contractType:
|
||||
const erc721metadata = NFTDropInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
erc721metadata.name,
|
||||
@@ -168,9 +168,9 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
erc721metadata.platform_fee_basis_points,
|
||||
erc721metadata.platform_fee_recipient,
|
||||
];
|
||||
case SignatureDrop.contractType:
|
||||
case SignatureDropInitializer.contractType:
|
||||
const signatureDropmetadata =
|
||||
SignatureDrop.schema.deploy.parse(metadata);
|
||||
SignatureDropInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
signatureDropmetadata.name,
|
||||
@@ -183,8 +183,9 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
signatureDropmetadata.platform_fee_basis_points,
|
||||
signatureDropmetadata.platform_fee_recipient,
|
||||
];
|
||||
case Multiwrap.contractType:
|
||||
const multiwrapMetadata = Multiwrap.schema.deploy.parse(metadata);
|
||||
case MultiwrapInitializer.contractType:
|
||||
const multiwrapMetadata =
|
||||
MultiwrapInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
multiwrapMetadata.name,
|
||||
@@ -194,9 +195,10 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
multiwrapMetadata.fee_recipient,
|
||||
multiwrapMetadata.seller_fee_basis_points,
|
||||
];
|
||||
case EditionDrop.contractType:
|
||||
case Edition.contractType:
|
||||
const erc1155metadata = EditionDrop.schema.deploy.parse(metadata);
|
||||
case EditionDropInitializer.contractType:
|
||||
case EditionInitializer.contractType:
|
||||
const erc1155metadata =
|
||||
EditionDropInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
erc1155metadata.name,
|
||||
@@ -209,9 +211,9 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
erc1155metadata.platform_fee_basis_points,
|
||||
erc1155metadata.platform_fee_recipient,
|
||||
];
|
||||
case TokenDrop.contractType:
|
||||
case Token.contractType:
|
||||
const erc20metadata = Token.schema.deploy.parse(metadata);
|
||||
case TokenDropInitializer.contractType:
|
||||
case TokenInitializer.contractType:
|
||||
const erc20metadata = TokenInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
erc20metadata.name,
|
||||
@@ -222,8 +224,8 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
erc20metadata.platform_fee_recipient,
|
||||
erc20metadata.platform_fee_basis_points,
|
||||
];
|
||||
case Vote.contractType:
|
||||
const voteMetadata = Vote.schema.deploy.parse(metadata);
|
||||
case VoteInitializer.contractType:
|
||||
const voteMetadata = VoteInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
voteMetadata.name,
|
||||
contractURI,
|
||||
@@ -234,8 +236,8 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
BigNumber.from(voteMetadata.proposal_token_threshold),
|
||||
voteMetadata.voting_quorum_fraction,
|
||||
];
|
||||
case Split.contractType:
|
||||
const splitsMetadata = Split.schema.deploy.parse(metadata);
|
||||
case SplitInitializer.contractType:
|
||||
const splitsMetadata = SplitInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
contractURI,
|
||||
@@ -243,8 +245,9 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
splitsMetadata.recipients.map((s) => s.address),
|
||||
splitsMetadata.recipients.map((s) => BigNumber.from(s.sharesBps)),
|
||||
];
|
||||
case Marketplace.contractType:
|
||||
const marketplaceMetadata = Marketplace.schema.deploy.parse(metadata);
|
||||
case MarketplaceInitializer.contractType:
|
||||
const marketplaceMetadata =
|
||||
MarketplaceInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
contractURI,
|
||||
@@ -252,8 +255,8 @@ export class ContractFactory extends ContractWrapper<TWFactory> {
|
||||
marketplaceMetadata.platform_fee_recipient,
|
||||
marketplaceMetadata.platform_fee_basis_points,
|
||||
];
|
||||
case Pack.contractType:
|
||||
const packsMetadata = Pack.schema.deploy.parse(metadata);
|
||||
case PackInitializer.contractType:
|
||||
const packsMetadata = PackInitializer.schema.deploy.parse(metadata);
|
||||
return [
|
||||
await this.getSignerAddress(),
|
||||
packsMetadata.name,
|
||||
|
||||
@@ -6,20 +6,20 @@ import {
|
||||
NATIVE_TOKEN_ADDRESS,
|
||||
} from "../constants";
|
||||
import {
|
||||
Edition,
|
||||
EditionDrop,
|
||||
EditionDropInitializer,
|
||||
EditionInitializer,
|
||||
getContractTypeForRemoteName,
|
||||
Marketplace,
|
||||
Multiwrap,
|
||||
NFTCollection,
|
||||
NFTDrop,
|
||||
Pack,
|
||||
MarketplaceInitializer,
|
||||
MultiwrapInitializer,
|
||||
NFTCollectionInitializer,
|
||||
NFTDropInitializer,
|
||||
PackInitializer,
|
||||
PREBUILT_CONTRACTS_MAP,
|
||||
SignatureDrop,
|
||||
Split,
|
||||
Token,
|
||||
TokenDrop,
|
||||
Vote,
|
||||
SignatureDropInitializer,
|
||||
SplitInitializer,
|
||||
TokenDropInitializer,
|
||||
TokenInitializer,
|
||||
VoteInitializer,
|
||||
} from "../contracts";
|
||||
import { SmartContract } from "../contracts/smart-contract";
|
||||
import { SDKOptions } from "../schema/sdk-options";
|
||||
@@ -171,7 +171,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getNFTDrop(contractAddress: string) {
|
||||
return await this.getBuiltInContract(contractAddress, NFTDrop.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
contractAddress,
|
||||
NFTDropInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +185,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
public async getSignatureDrop(contractAddress: string) {
|
||||
return await this.getBuiltInContract(
|
||||
contractAddress,
|
||||
SignatureDrop.contractType,
|
||||
SignatureDropInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -192,7 +195,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getNFTCollection(address: string) {
|
||||
return await this.getBuiltInContract(address, NFTCollection.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
NFTCollectionInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +207,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getEditionDrop(address: string) {
|
||||
return await this.getBuiltInContract(address, EditionDrop.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
EditionDropInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +219,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getEdition(address: string) {
|
||||
return await this.getBuiltInContract(address, Edition.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
EditionInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +231,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getTokenDrop(address: string) {
|
||||
return await this.getBuiltInContract(address, TokenDrop.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
TokenDropInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +243,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getToken(address: string) {
|
||||
return await this.getBuiltInContract(address, Token.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
TokenInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +255,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getVote(address: string) {
|
||||
return await this.getBuiltInContract(address, Vote.contractType);
|
||||
return await this.getBuiltInContract(address, VoteInitializer.contractType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +264,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getSplit(address: string) {
|
||||
return await this.getBuiltInContract(address, Split.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
SplitInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +276,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getMarketplace(address: string) {
|
||||
return await this.getBuiltInContract(address, Marketplace.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
MarketplaceInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,7 +288,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @returns the contract
|
||||
*/
|
||||
public async getPack(address: string) {
|
||||
return await this.getBuiltInContract(address, Pack.contractType);
|
||||
return await this.getBuiltInContract(address, PackInitializer.contractType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +298,10 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
||||
* @beta
|
||||
*/
|
||||
public async getMultiwrap(address: string) {
|
||||
return await this.getBuiltInContract(address, Multiwrap.contractType);
|
||||
return await this.getBuiltInContract(
|
||||
address,
|
||||
MultiwrapInitializer.contractType,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-12
@@ -38,15 +38,15 @@ export * from "./contracts";
|
||||
export * from "./integrations/paper-xyz";
|
||||
|
||||
// explcitly export the *TYPES* of prebuilt contracts
|
||||
export type { EditionImpl } from "./contracts/prebuilt-implementations/edition";
|
||||
export type { EditionDropImpl } from "./contracts/prebuilt-implementations/edition-drop";
|
||||
export type { MarketplaceImpl } from "./contracts/prebuilt-implementations/marketplace";
|
||||
export type { MultiwrapImpl } from "./contracts/prebuilt-implementations/multiwrap";
|
||||
export type { NFTCollectionImpl } from "./contracts/prebuilt-implementations/nft-collection";
|
||||
export type { NFTDropImpl } from "./contracts/prebuilt-implementations/nft-drop";
|
||||
export type { PackImpl } from "./contracts/prebuilt-implementations/pack";
|
||||
export type { SignatureDropImpl } from "./contracts/prebuilt-implementations/signature-drop";
|
||||
export type { SplitImpl } from "./contracts/prebuilt-implementations/split";
|
||||
export type { TokenImpl } from "./contracts/prebuilt-implementations/token";
|
||||
export type { TokenDropImpl } from "./contracts/prebuilt-implementations/token-drop";
|
||||
export type { VoteImpl } from "./contracts/prebuilt-implementations/vote";
|
||||
export type { Edition } from "./contracts/prebuilt-implementations/edition";
|
||||
export type { EditionDrop } from "./contracts/prebuilt-implementations/edition-drop";
|
||||
export type { Marketplace } from "./contracts/prebuilt-implementations/marketplace";
|
||||
export type { Multiwrap } from "./contracts/prebuilt-implementations/multiwrap";
|
||||
export type { NFTCollection } from "./contracts/prebuilt-implementations/nft-collection";
|
||||
export type { NFTDrop } from "./contracts/prebuilt-implementations/nft-drop";
|
||||
export type { Pack } from "./contracts/prebuilt-implementations/pack";
|
||||
export type { SignatureDrop } from "./contracts/prebuilt-implementations/signature-drop";
|
||||
export type { Split } from "./contracts/prebuilt-implementations/split";
|
||||
export type { Token } from "./contracts/prebuilt-implementations/token";
|
||||
export type { TokenDrop } from "./contracts/prebuilt-implementations/token-drop";
|
||||
export type { Vote } from "./contracts/prebuilt-implementations/vote";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Token } from "../src";
|
||||
import { TokenInitializer } from "../src";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { EditionDropImpl } from "../src/contracts/classes/edition-drop";
|
||||
import { EditionDrop } from "../src/contracts/prebuilt-implementations/edition-drop";
|
||||
import { ClaimEligibility } from "../src/enums";
|
||||
import { expectError, sdk, signers } from "./hooks";
|
||||
import { AddressZero } from "@ethersproject/constants";
|
||||
@@ -16,7 +16,7 @@ const deepEqualInAnyOrder = require("deep-equal-in-any-order");
|
||||
use(deepEqualInAnyOrder);
|
||||
|
||||
describe("Edition Drop Contract", async () => {
|
||||
let bdContract: EditionDropImpl;
|
||||
let bdContract: EditionDrop;
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
abbyWallet: SignerWithAddress,
|
||||
@@ -553,11 +553,14 @@ describe("Edition Drop Contract", async () => {
|
||||
|
||||
it("should check if an address has enough erc20 currency", async () => {
|
||||
const currency = await sdk.getToken(
|
||||
await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
name: "test",
|
||||
symbol: "test",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
TokenInitializer.contractType,
|
||||
{
|
||||
name: "test",
|
||||
symbol: "test",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await bdContract.claimConditions.set("0", [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EditionImpl } from "../src/contracts/classes/edition";
|
||||
import { Edition } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { expectError, sdk, signers, storage } from "./hooks";
|
||||
import { AddressZero } from "@ethersproject/constants";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
@@ -8,7 +8,7 @@ import { ethers } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Edition Contract", async () => {
|
||||
let bundleContract: EditionImpl;
|
||||
let bundleContract: Edition;
|
||||
// let nftContract: NFTContract;
|
||||
// let currencyContract: CurrencyContract;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { ContractEvent, NFTCollection, NFTDrop } from "../src";
|
||||
import { NFTCollectionImpl } from "../src/contracts/classes/nft-collection";
|
||||
import { NFTDropImpl } from "../src/contracts/classes/nft-drop";
|
||||
import {
|
||||
ContractEvent,
|
||||
NFTCollectionInitializer,
|
||||
NFTDropInitializer,
|
||||
} from "../src";
|
||||
import { NFTCollection } from "../src/contracts/prebuilt-implementations/nft-collection";
|
||||
import { NFTDrop } from "../src/contracts/prebuilt-implementations/nft-drop";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { AddressZero } from "@ethersproject/constants";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
@@ -10,9 +14,9 @@ import { ethers } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Events", async () => {
|
||||
let dropContract: NFTDropImpl;
|
||||
let dropContract2: NFTDropImpl;
|
||||
let nftContract: NFTCollectionImpl;
|
||||
let dropContract: NFTDrop;
|
||||
let dropContract2: NFTDrop;
|
||||
let nftContract: NFTCollection;
|
||||
let samWallet: SignerWithAddress;
|
||||
|
||||
before(() => {
|
||||
@@ -21,45 +25,54 @@ describe("Events", async () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
dropContract = await sdk.getNFTDrop(
|
||||
await sdk.deployer.deployBuiltInContract(NFTDrop.contractType, {
|
||||
name: `Testing drop from SDK`,
|
||||
description: "Test contract from tests",
|
||||
image:
|
||||
"https://pbs.twimg.com/profile_images/1433508973215367176/XBCfBn3g_400x400.jpg",
|
||||
primary_sale_recipient: AddressZero,
|
||||
seller_fee_basis_points: 500,
|
||||
fee_recipient: AddressZero,
|
||||
platform_fee_basis_points: 10,
|
||||
platform_fee_recipient: AddressZero,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
NFTDropInitializer.contractType,
|
||||
{
|
||||
name: `Testing drop from SDK`,
|
||||
description: "Test contract from tests",
|
||||
image:
|
||||
"https://pbs.twimg.com/profile_images/1433508973215367176/XBCfBn3g_400x400.jpg",
|
||||
primary_sale_recipient: AddressZero,
|
||||
seller_fee_basis_points: 500,
|
||||
fee_recipient: AddressZero,
|
||||
platform_fee_basis_points: 10,
|
||||
platform_fee_recipient: AddressZero,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
dropContract2 = await sdk.getNFTDrop(
|
||||
await sdk.deployer.deployBuiltInContract(NFTDrop.contractType, {
|
||||
name: `Testing drop from SDK`,
|
||||
description: "Test contract from tests",
|
||||
image:
|
||||
"https://pbs.twimg.com/profile_images/1433508973215367176/XBCfBn3g_400x400.jpg",
|
||||
primary_sale_recipient: AddressZero,
|
||||
seller_fee_basis_points: 500,
|
||||
fee_recipient: AddressZero,
|
||||
platform_fee_basis_points: 10,
|
||||
platform_fee_recipient: AddressZero,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
NFTDropInitializer.contractType,
|
||||
{
|
||||
name: `Testing drop from SDK`,
|
||||
description: "Test contract from tests",
|
||||
image:
|
||||
"https://pbs.twimg.com/profile_images/1433508973215367176/XBCfBn3g_400x400.jpg",
|
||||
primary_sale_recipient: AddressZero,
|
||||
seller_fee_basis_points: 500,
|
||||
fee_recipient: AddressZero,
|
||||
platform_fee_basis_points: 10,
|
||||
platform_fee_recipient: AddressZero,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
nftContract = await sdk.getNFTCollection(
|
||||
await sdk.deployer.deployBuiltInContract(NFTCollection.contractType, {
|
||||
name: "NFT Contract",
|
||||
description: "Test NFT contract from tests",
|
||||
image:
|
||||
"https://pbs.twimg.com/profile_images/1433508973215367176/XBCfBn3g_400x400.jpg",
|
||||
primary_sale_recipient: AddressZero,
|
||||
seller_fee_basis_points: 1000,
|
||||
fee_recipient: AddressZero,
|
||||
platform_fee_basis_points: 10,
|
||||
platform_fee_recipient: AddressZero,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
NFTCollectionInitializer.contractType,
|
||||
{
|
||||
name: "NFT Contract",
|
||||
description: "Test NFT contract from tests",
|
||||
image:
|
||||
"https://pbs.twimg.com/profile_images/1433508973215367176/XBCfBn3g_400x400.jpg",
|
||||
primary_sale_recipient: AddressZero,
|
||||
seller_fee_basis_points: 1000,
|
||||
fee_recipient: AddressZero,
|
||||
platform_fee_basis_points: 10,
|
||||
platform_fee_recipient: AddressZero,
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
+27
-27
@@ -2,20 +2,20 @@ import {
|
||||
CONTRACTS_MAP,
|
||||
ContractType,
|
||||
DEFAULT_IPFS_GATEWAY,
|
||||
Edition,
|
||||
EditionDrop,
|
||||
EditionDropInitializer,
|
||||
EditionInitializer,
|
||||
getNativeTokenByChainId,
|
||||
Marketplace,
|
||||
Multiwrap,
|
||||
NFTCollection,
|
||||
NFTDrop,
|
||||
Pack,
|
||||
SignatureDrop,
|
||||
Split,
|
||||
MarketplaceInitializer,
|
||||
MultiwrapInitializer,
|
||||
NFTCollectionInitializer,
|
||||
NFTDropInitializer,
|
||||
PackInitializer,
|
||||
SignatureDropInitializer,
|
||||
SplitInitializer,
|
||||
ThirdwebSDK,
|
||||
Token,
|
||||
TokenDrop,
|
||||
Vote,
|
||||
TokenDropInitializer,
|
||||
TokenInitializer,
|
||||
VoteInitializer,
|
||||
} from "../src";
|
||||
import { ChainId } from "../src/constants/chains";
|
||||
import { MockStorage } from "./mock/MockStorage";
|
||||
@@ -136,13 +136,13 @@ export const mochaHooks = {
|
||||
contractType: ContractType,
|
||||
): Promise<ethers.Contract> {
|
||||
switch (contractType) {
|
||||
case Marketplace.contractType:
|
||||
case Multiwrap.contractType:
|
||||
case MarketplaceInitializer.contractType:
|
||||
case MultiwrapInitializer.contractType:
|
||||
const nativeTokenWrapperAddress = getNativeTokenByChainId(
|
||||
ChainId.Hardhat,
|
||||
).wrapped.address;
|
||||
return await contractFactory.deploy(nativeTokenWrapperAddress);
|
||||
case Pack.contractType:
|
||||
case PackInitializer.contractType:
|
||||
const addr = getNativeTokenByChainId(ChainId.Hardhat).wrapped.address;
|
||||
return await contractFactory.deploy(addr, trustedForwarderAddress);
|
||||
default:
|
||||
@@ -156,40 +156,40 @@ export const mochaHooks = {
|
||||
}
|
||||
let factory;
|
||||
switch (contractType) {
|
||||
case Token.contractType:
|
||||
case TokenInitializer.contractType:
|
||||
factory = TokenERC20__factory;
|
||||
break;
|
||||
case TokenDrop.contractType:
|
||||
case TokenDropInitializer.contractType:
|
||||
factory = DropERC20__factory;
|
||||
break;
|
||||
case NFTCollection.contractType:
|
||||
case NFTCollectionInitializer.contractType:
|
||||
factory = TokenERC721__factory;
|
||||
break;
|
||||
case NFTDrop.contractType:
|
||||
case NFTDropInitializer.contractType:
|
||||
factory = DropERC721__factory;
|
||||
break;
|
||||
case SignatureDrop.contractType:
|
||||
case SignatureDropInitializer.contractType:
|
||||
factory = SignatureDrop__factory;
|
||||
break;
|
||||
case Edition.contractType:
|
||||
case EditionInitializer.contractType:
|
||||
factory = TokenERC1155__factory;
|
||||
break;
|
||||
case EditionDrop.contractType:
|
||||
case EditionDropInitializer.contractType:
|
||||
factory = DropERC1155__factory;
|
||||
break;
|
||||
case Split.contractType:
|
||||
case SplitInitializer.contractType:
|
||||
factory = Split__factory;
|
||||
break;
|
||||
case Vote.contractType:
|
||||
case VoteInitializer.contractType:
|
||||
factory = VoteERC20__factory;
|
||||
break;
|
||||
case Marketplace.contractType:
|
||||
case MarketplaceInitializer.contractType:
|
||||
factory = Marketplace__factory;
|
||||
break;
|
||||
case Pack.contractType:
|
||||
case PackInitializer.contractType:
|
||||
factory = Pack__factory;
|
||||
break;
|
||||
case Multiwrap.contractType:
|
||||
case MultiwrapInitializer.contractType:
|
||||
factory = Multiwrap__factory;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Edition, Marketplace, NFTCollection, Token } from "../src";
|
||||
import {
|
||||
EditionInitializer,
|
||||
MarketplaceInitializer,
|
||||
NFTCollectionInitializer,
|
||||
TokenInitializer,
|
||||
} from "../src";
|
||||
import {
|
||||
AuctionAlreadyStartedError,
|
||||
ListingNotFoundError,
|
||||
@@ -6,10 +11,10 @@ import {
|
||||
} from "../src/common/error";
|
||||
import { isWinningBid } from "../src/common/marketplace";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { EditionImpl } from "../src/contracts/classes/edition";
|
||||
import { MarketplaceImpl } from "../src/contracts/classes/marketplace";
|
||||
import { NFTCollectionImpl } from "../src/contracts/classes/nft-collection";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import { Edition } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { Marketplace } from "../src/contracts/prebuilt-implementations/marketplace";
|
||||
import { NFTCollection } from "../src/contracts/prebuilt-implementations/nft-collection";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import { ListingType } from "../src/enums/marketplace";
|
||||
import { AuctionListing, DirectListing, Offer } from "../src/types/marketplace";
|
||||
import {
|
||||
@@ -35,10 +40,10 @@ let tokenAddress = NATIVE_TOKEN_ADDRESS;
|
||||
* Bog and Sam and Abby wallets will be used for direct listings and auctions.
|
||||
*/
|
||||
describe("Marketplace Contract", async () => {
|
||||
let marketplaceContract: MarketplaceImpl;
|
||||
let dummyNftContract: NFTCollectionImpl;
|
||||
let dummyBundleContract: EditionImpl;
|
||||
let customTokenContract: TokenImpl;
|
||||
let marketplaceContract: Marketplace;
|
||||
let dummyNftContract: NFTCollection;
|
||||
let dummyBundleContract: Edition;
|
||||
let customTokenContract: Token;
|
||||
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
@@ -52,17 +57,23 @@ describe("Marketplace Contract", async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
|
||||
marketplaceContract = await sdk.getMarketplace(
|
||||
await sdk.deployer.deployBuiltInContract(Marketplace.contractType, {
|
||||
name: "Test Marketplace",
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
MarketplaceInitializer.contractType,
|
||||
{
|
||||
name: "Test Marketplace",
|
||||
},
|
||||
),
|
||||
);
|
||||
dummyNftContract = await sdk.getNFTCollection(
|
||||
await sdk.deployer.deployBuiltInContract(NFTCollection.contractType, {
|
||||
name: "TEST NFT",
|
||||
seller_fee_basis_points: 200,
|
||||
fee_recipient: adminWallet.address,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
NFTCollectionInitializer.contractType,
|
||||
{
|
||||
name: "TEST NFT",
|
||||
seller_fee_basis_points: 200,
|
||||
fee_recipient: adminWallet.address,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
},
|
||||
),
|
||||
);
|
||||
await dummyNftContract.mintBatch([
|
||||
{
|
||||
@@ -79,11 +90,14 @@ describe("Marketplace Contract", async () => {
|
||||
},
|
||||
]);
|
||||
dummyBundleContract = await sdk.getEdition(
|
||||
await sdk.deployer.deployBuiltInContract(Edition.contractType, {
|
||||
name: "TEST BUNDLE",
|
||||
seller_fee_basis_points: 100,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
EditionInitializer.contractType,
|
||||
{
|
||||
name: "TEST BUNDLE",
|
||||
seller_fee_basis_points: 100,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
},
|
||||
),
|
||||
);
|
||||
await dummyBundleContract.mintBatch([
|
||||
{
|
||||
@@ -101,7 +115,7 @@ describe("Marketplace Contract", async () => {
|
||||
]);
|
||||
|
||||
customTokenContract = await sdk.getToken(
|
||||
await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
await sdk.deployer.deployBuiltInContract(TokenInitializer.contractType, {
|
||||
name: "Test",
|
||||
symbol: "TEST",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import { Edition, NFTCollection, Token } from "../src";
|
||||
import { EditionImpl } from "../src/contracts/classes/edition";
|
||||
import { MultiwrapImpl } from "../src/contracts/classes/multiwrap";
|
||||
import { NFTCollectionImpl } from "../src/contracts/classes/nft-collection";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import {
|
||||
EditionInitializer,
|
||||
NFTCollectionInitializer,
|
||||
TokenInitializer,
|
||||
} from "../src";
|
||||
import { Edition } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { Multiwrap } from "../src/contracts/prebuilt-implementations/multiwrap";
|
||||
import { NFTCollection } from "../src/contracts/prebuilt-implementations/nft-collection";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { expect } from "chai";
|
||||
|
||||
describe("Multiwrap Contract", async () => {
|
||||
let multiwrapContract: MultiwrapImpl;
|
||||
let nftContract: NFTCollectionImpl;
|
||||
let editionContract: EditionImpl;
|
||||
let tokenContract: TokenImpl;
|
||||
let tokenContract2: TokenImpl;
|
||||
let multiwrapContract: Multiwrap;
|
||||
let nftContract: NFTCollection;
|
||||
let editionContract: Edition;
|
||||
let tokenContract: Token;
|
||||
let tokenContract2: Token;
|
||||
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
@@ -34,12 +38,15 @@ describe("Multiwrap Contract", async () => {
|
||||
multiwrapContract = await sdk.getMultiwrap(address);
|
||||
|
||||
nftContract = await sdk.getNFTCollection(
|
||||
await sdk.deployer.deployBuiltInContract(NFTCollection.contractType, {
|
||||
name: "TEST NFT",
|
||||
seller_fee_basis_points: 200,
|
||||
fee_recipient: adminWallet.address,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
NFTCollectionInitializer.contractType,
|
||||
{
|
||||
name: "TEST NFT",
|
||||
seller_fee_basis_points: 200,
|
||||
fee_recipient: adminWallet.address,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
},
|
||||
),
|
||||
);
|
||||
await nftContract.mintBatch([
|
||||
{
|
||||
@@ -60,11 +67,14 @@ describe("Multiwrap Contract", async () => {
|
||||
await nftContract.setApprovalForAll(multiwrapContract.getAddress(), true);
|
||||
|
||||
editionContract = await sdk.getEdition(
|
||||
await sdk.deployer.deployBuiltInContract(Edition.contractType, {
|
||||
name: "TEST BUNDLE",
|
||||
seller_fee_basis_points: 100,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
EditionInitializer.contractType,
|
||||
{
|
||||
name: "TEST BUNDLE",
|
||||
seller_fee_basis_points: 100,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
},
|
||||
),
|
||||
);
|
||||
await editionContract.mintBatch([
|
||||
{
|
||||
@@ -87,7 +97,7 @@ describe("Multiwrap Contract", async () => {
|
||||
);
|
||||
|
||||
tokenContract = await sdk.getToken(
|
||||
await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
await sdk.deployer.deployBuiltInContract(TokenInitializer.contractType, {
|
||||
name: "Test",
|
||||
symbol: "TEST",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
@@ -111,7 +121,7 @@ describe("Multiwrap Contract", async () => {
|
||||
await tokenContract.setAllowance(multiwrapContract.getAddress(), 1000);
|
||||
|
||||
tokenContract2 = await sdk.getToken(
|
||||
await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
await sdk.deployer.deployBuiltInContract(TokenInitializer.contractType, {
|
||||
name: "Test2",
|
||||
symbol: "TEST2",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NFTMetadataInput, Token } from "../src";
|
||||
import { NFTMetadataInput, TokenInitializer } from "../src";
|
||||
import { createSnapshot } from "../src/common";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { NFTDropImpl } from "../src/contracts/classes/nft-drop";
|
||||
import { NFTDrop } from "../src/contracts/prebuilt-implementations/nft-drop";
|
||||
import { ClaimEligibility } from "../src/enums";
|
||||
import { expectError, sdk, signers, storage } from "./hooks";
|
||||
import { AddressZero } from "@ethersproject/constants";
|
||||
@@ -14,7 +14,7 @@ import invariant from "tiny-invariant";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("NFT Drop Contract", async () => {
|
||||
let dropContract: NFTDropImpl;
|
||||
let dropContract: NFTDrop;
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
abbyWallet: SignerWithAddress,
|
||||
@@ -541,7 +541,7 @@ describe("NFT Drop Contract", async () => {
|
||||
|
||||
it("should check if an address has enough erc20 currency", async () => {
|
||||
const currencyAddress = await sdk.deployer.deployBuiltInContract(
|
||||
Token.contractType,
|
||||
TokenInitializer.contractType,
|
||||
{
|
||||
name: "test",
|
||||
symbol: "test",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NFTCollection, NFTMetadataInput } from "../src";
|
||||
import { NFTCollectionImpl } from "../src/contracts/classes/nft-collection";
|
||||
import { NFTCollectionInitializer, NFTMetadataInput } from "../src";
|
||||
import { NFTCollection } from "../src/contracts/prebuilt-implementations/nft-collection";
|
||||
import { sdk, signers, storage } from "./hooks";
|
||||
import { AddressZero } from "@ethersproject/constants";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
@@ -8,7 +8,7 @@ import { assert, expect } from "chai";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("NFT Contract", async () => {
|
||||
type NewType = NFTCollectionImpl;
|
||||
type NewType = NFTCollection;
|
||||
let nftContract: NewType;
|
||||
let adminWallet: SignerWithAddress, samWallet: SignerWithAddress;
|
||||
|
||||
@@ -19,7 +19,7 @@ describe("NFT Contract", async () => {
|
||||
beforeEach(async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
const address = await sdk.deployer.deployBuiltInContract(
|
||||
NFTCollection.contractType,
|
||||
NFTCollectionInitializer.contractType,
|
||||
{
|
||||
name: "NFT Contract",
|
||||
description: "Test NFT contract from tests",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Edition, EditionMetadataInput, Pack } from "../src";
|
||||
import { EditionImpl } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { PackImpl } from "../src/contracts/prebuilt-implementations/pack";
|
||||
import { EditionInitializer, PackInitializer } from "../src";
|
||||
import { Edition } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { Pack } from "../src/contracts/prebuilt-implementations/pack";
|
||||
import { EditionMetadataInput } from "../src/schema/tokens/edition";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { assert } from "chai";
|
||||
@@ -9,8 +10,8 @@ import { BigNumber } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Pack Contract", async () => {
|
||||
let packContract: PackImpl;
|
||||
let bundleContract: EditionImpl;
|
||||
let packContract: Pack;
|
||||
let bundleContract: Edition;
|
||||
|
||||
let adminWallet: SignerWithAddress, samWallet: SignerWithAddress;
|
||||
|
||||
@@ -35,18 +36,21 @@ describe("Pack Contract", async () => {
|
||||
beforeEach(async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
packContract = await sdk.getPack(
|
||||
await sdk.deployer.deployBuiltInContract(Pack.contractType, {
|
||||
await sdk.deployer.deployBuiltInContract(PackInitializer.contractType, {
|
||||
name: "Pack Contract",
|
||||
seller_fee_basis_points: 1000,
|
||||
}),
|
||||
);
|
||||
|
||||
bundleContract = await sdk.getEdition(
|
||||
await sdk.deployer.deployBuiltInContract(Edition.contractType, {
|
||||
name: "NFT Contract",
|
||||
seller_fee_basis_points: 1000,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
EditionInitializer.contractType,
|
||||
{
|
||||
name: "NFT Contract",
|
||||
seller_fee_basis_points: 1000,
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await bundleContract.setApprovalForAll(packContract.getAddress(), true);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Edition } from "../src";
|
||||
import { EditionImpl } from "../src/contracts/classes/edition";
|
||||
import { EditionInitializer } from "../src";
|
||||
import { Edition } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { AddressZero } from "@ethersproject/constants";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
@@ -8,7 +8,7 @@ import { assert } from "chai";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Roles Contract", async () => {
|
||||
let bundleContract: EditionImpl;
|
||||
let bundleContract: Edition;
|
||||
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
@@ -22,11 +22,14 @@ describe("Roles Contract", async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
|
||||
bundleContract = await sdk.getEdition(
|
||||
await sdk.deployer.deployBuiltInContract(Edition.contractType, {
|
||||
name: "NFT Contract",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 1000,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
EditionInitializer.contractType,
|
||||
{
|
||||
name: "NFT Contract",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 1000,
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Edition } from "../src";
|
||||
import { EditionImpl } from "../src/contracts/classes/edition";
|
||||
import { EditionInitializer } from "../src";
|
||||
import { Edition } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { expect } from "chai";
|
||||
@@ -7,7 +7,7 @@ import { expect } from "chai";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Royalties", async () => {
|
||||
let bundleContract: EditionImpl;
|
||||
let bundleContract: Edition;
|
||||
|
||||
let adminWallet: SignerWithAddress, samWallet: SignerWithAddress;
|
||||
|
||||
@@ -19,12 +19,15 @@ describe("Royalties", async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
|
||||
bundleContract = await sdk.getEdition(
|
||||
await sdk.deployer.deployBuiltInContract(Edition.contractType, {
|
||||
name: "NFT Contract",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
fee_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 1000,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
EditionInitializer.contractType,
|
||||
{
|
||||
name: "NFT Contract",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
fee_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 1000,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await bundleContract.mint({
|
||||
|
||||
@@ -2,12 +2,12 @@ import {
|
||||
createSnapshot,
|
||||
NFTMetadataInput,
|
||||
PayloadToSign721withQuantity,
|
||||
SignatureDrop,
|
||||
Token,
|
||||
SignatureDropInitializer,
|
||||
TokenInitializer,
|
||||
} from "../src";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { SignatureDropImpl } from "../src/contracts/classes/signature-drop";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import { SignatureDrop } from "../src/contracts/prebuilt-implementations/signature-drop";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import { SignedPayload721WithQuantitySignature } from "../src/schema/contracts/common/signature";
|
||||
import { expectError, sdk, signers, storage } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
@@ -20,8 +20,8 @@ import invariant from "tiny-invariant";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Signature drop tests", async () => {
|
||||
let signatureDropContract: SignatureDropImpl;
|
||||
let customTokenContract: TokenImpl;
|
||||
let signatureDropContract: SignatureDrop;
|
||||
let customTokenContract: Token;
|
||||
let tokenAddress: string;
|
||||
|
||||
let adminWallet: SignerWithAddress,
|
||||
@@ -43,12 +43,15 @@ describe("Signature drop tests", async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
|
||||
signatureDropContract = await sdk.getSignatureDrop(
|
||||
await sdk.deployer.deployBuiltInContract(SignatureDrop.contractType, {
|
||||
name: "OUCH VOUCH",
|
||||
symbol: "VOUCH",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 0,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
SignatureDropInitializer.contractType,
|
||||
{
|
||||
name: "OUCH VOUCH",
|
||||
symbol: "VOUCH",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 0,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
meta = {
|
||||
@@ -62,7 +65,7 @@ describe("Signature drop tests", async () => {
|
||||
};
|
||||
|
||||
customTokenContract = await sdk.getToken(
|
||||
await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
await sdk.deployer.deployBuiltInContract(TokenInitializer.contractType, {
|
||||
name: "Test",
|
||||
symbol: "TEST",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Edition, Token } from "../src";
|
||||
import { EditionInitializer, TokenInitializer } from "../src";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { EditionImpl } from "../src/contracts/classes/edition";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import { Edition } from "../src/contracts/prebuilt-implementations/edition";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import {
|
||||
PayloadToSign1155,
|
||||
SignedPayload1155,
|
||||
@@ -14,8 +14,8 @@ import { BigNumber } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Edition sig minting", async () => {
|
||||
let editionContract: EditionImpl;
|
||||
let customTokenContract: TokenImpl;
|
||||
let editionContract: Edition;
|
||||
let customTokenContract: Token;
|
||||
let tokenAddress: string;
|
||||
|
||||
let adminWallet: SignerWithAddress, samWallet: SignerWithAddress;
|
||||
@@ -30,12 +30,15 @@ describe("Edition sig minting", async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
|
||||
editionContract = await sdk.getEdition(
|
||||
await sdk.deployer.deployBuiltInContract(Edition.contractType, {
|
||||
name: "OUCH VOUCH",
|
||||
symbol: "VOUCH",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 0,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
EditionInitializer.contractType,
|
||||
{
|
||||
name: "OUCH VOUCH",
|
||||
symbol: "VOUCH",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 0,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
meta = {
|
||||
@@ -49,7 +52,7 @@ describe("Edition sig minting", async () => {
|
||||
};
|
||||
|
||||
customTokenContract = await sdk.getToken(
|
||||
await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
await sdk.deployer.deployBuiltInContract(TokenInitializer.contractType, {
|
||||
name: "Test",
|
||||
symbol: "TEST",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PayloadToSign20, SignedPayload20 } from "../src";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { assert, expect } from "chai";
|
||||
@@ -9,8 +9,8 @@ import { BigNumber } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Token sig minting", async () => {
|
||||
let contract: TokenImpl;
|
||||
let customTokenContract: TokenImpl;
|
||||
let contract: Token;
|
||||
let customTokenContract: Token;
|
||||
let tokenAddress: string;
|
||||
|
||||
let adminWallet: SignerWithAddress, samWallet: SignerWithAddress;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
NFTCollection,
|
||||
NFTCollectionInitializer,
|
||||
PayloadToSign721withQuantity,
|
||||
SignedPayload721WithQuantitySignature,
|
||||
Token,
|
||||
TokenInitializer,
|
||||
} from "../src";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { NFTCollectionImpl } from "../src/contracts/classes/nft-collection";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import { NFTCollection } from "../src/contracts/prebuilt-implementations/nft-collection";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import { sdk, signers, storage } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { assert, expect } from "chai";
|
||||
@@ -15,8 +15,8 @@ import { BigNumber } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("NFT sig minting", async () => {
|
||||
let nftContract: NFTCollectionImpl;
|
||||
let customTokenContract: TokenImpl;
|
||||
let nftContract: NFTCollection;
|
||||
let customTokenContract: Token;
|
||||
let tokenAddress: string;
|
||||
|
||||
let adminWallet: SignerWithAddress, samWallet: SignerWithAddress;
|
||||
@@ -31,12 +31,15 @@ describe("NFT sig minting", async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
|
||||
nftContract = await sdk.getNFTCollection(
|
||||
await sdk.deployer.deployBuiltInContract(NFTCollection.contractType, {
|
||||
name: "OUCH VOUCH",
|
||||
symbol: "VOUCH",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 0,
|
||||
}),
|
||||
await sdk.deployer.deployBuiltInContract(
|
||||
NFTCollectionInitializer.contractType,
|
||||
{
|
||||
name: "OUCH VOUCH",
|
||||
symbol: "VOUCH",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
seller_fee_basis_points: 0,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
meta = {
|
||||
@@ -51,7 +54,7 @@ describe("NFT sig minting", async () => {
|
||||
};
|
||||
|
||||
customTokenContract = await sdk.getToken(
|
||||
await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
await sdk.deployer.deployBuiltInContract(TokenInitializer.contractType, {
|
||||
name: "Test",
|
||||
symbol: "TEST",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Split, Token } from "../src";
|
||||
import { SplitImpl } from "../src/contracts/classes/split";
|
||||
import { SplitInitializer, TokenInitializer } from "../src";
|
||||
import { Split } from "../src/contracts/prebuilt-implementations/split";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { assert, expect } from "chai";
|
||||
@@ -8,7 +8,7 @@ import { ethers } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Splits Contract", async () => {
|
||||
let splitsContract: SplitImpl;
|
||||
let splitsContract: Split;
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
bobWallet: SignerWithAddress,
|
||||
@@ -21,7 +21,7 @@ describe("Splits Contract", async () => {
|
||||
beforeEach(async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
const address = await sdk.deployer.deployBuiltInContract(
|
||||
Split.contractType,
|
||||
SplitInitializer.contractType,
|
||||
{
|
||||
name: "Splits Contract",
|
||||
recipients: [
|
||||
@@ -81,11 +81,14 @@ describe("Splits Contract", async () => {
|
||||
});
|
||||
|
||||
it("should return all the recipients along with their token balances", async () => {
|
||||
const addr = await sdk.deployer.deployBuiltInContract(Token.contractType, {
|
||||
name: "Test Token",
|
||||
symbol: "TST",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
});
|
||||
const addr = await sdk.deployer.deployBuiltInContract(
|
||||
TokenInitializer.contractType,
|
||||
{
|
||||
name: "Test Token",
|
||||
symbol: "TST",
|
||||
primary_sale_recipient: adminWallet.address,
|
||||
},
|
||||
);
|
||||
const balances = await splitsContract.balanceOfTokenAllRecipients(addr);
|
||||
assert.equal(
|
||||
Object.keys(balances).length,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Token, TokenDrop } from "../src";
|
||||
import { TokenDropInitializer, TokenInitializer } from "../src";
|
||||
import { createSnapshot } from "../src/common";
|
||||
import { NATIVE_TOKEN_ADDRESS } from "../src/constants/currency";
|
||||
import { TokenDropImpl } from "../src/contracts/classes/token-drop";
|
||||
import { TokenDrop } from "../src/contracts/prebuilt-implementations/token-drop";
|
||||
import { ClaimEligibility } from "../src/enums";
|
||||
import { expectError, sdk, signers, storage } from "./hooks";
|
||||
import { AddressZero } from "@ethersproject/constants";
|
||||
@@ -14,7 +14,7 @@ import invariant from "tiny-invariant";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Token Drop Contract", async () => {
|
||||
let dropContract: TokenDropImpl;
|
||||
let dropContract: TokenDrop;
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
abbyWallet: SignerWithAddress,
|
||||
@@ -28,7 +28,7 @@ describe("Token Drop Contract", async () => {
|
||||
[adminWallet, samWallet, bobWallet, abbyWallet, w1, w2, w3, w4] = signers;
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
const address = await sdk.deployer.deployBuiltInContract(
|
||||
TokenDrop.contractType,
|
||||
TokenDropInitializer.contractType,
|
||||
{
|
||||
name: `Testing drop from SDK`,
|
||||
description: "Test contract from tests",
|
||||
@@ -396,7 +396,7 @@ describe("Token Drop Contract", async () => {
|
||||
|
||||
it("should check if an address has enough erc20 currency", async () => {
|
||||
const currencyAddress = await sdk.deployer.deployBuiltInContract(
|
||||
Token.contractType,
|
||||
TokenInitializer.contractType,
|
||||
{
|
||||
name: "test",
|
||||
symbol: "test",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Token } from "../src";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import { TokenInitializer } from "../src";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import { TokenMintInput } from "../src/schema/tokens/token";
|
||||
import { sdk, signers } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
@@ -9,7 +9,7 @@ import { ethers } from "ethers";
|
||||
// global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Token Contract", async () => {
|
||||
let currencyContract: TokenImpl;
|
||||
let currencyContract: Token;
|
||||
|
||||
let adminWallet: SignerWithAddress,
|
||||
samWallet: SignerWithAddress,
|
||||
@@ -22,7 +22,7 @@ describe("Token Contract", async () => {
|
||||
beforeEach(async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
const address = await sdk.deployer.deployBuiltInContract(
|
||||
Token.contractType,
|
||||
TokenInitializer.contractType,
|
||||
{
|
||||
name: `Testing token from SDK`,
|
||||
symbol: `TEST`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Token, Vote } from "../src";
|
||||
import { TokenImpl } from "../src/contracts/classes/token";
|
||||
import { VoteImpl } from "../src/contracts/classes/vote";
|
||||
import { TokenInitializer, VoteInitializer } from "../src";
|
||||
import { Token } from "../src/contracts/prebuilt-implementations/token";
|
||||
import { Vote } from "../src/contracts/prebuilt-implementations/vote";
|
||||
import { sdk, signers, hardhatEthers } from "./hooks";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { assert } from "chai";
|
||||
@@ -9,8 +9,8 @@ import { ethers } from "ethers";
|
||||
global.fetch = require("cross-fetch");
|
||||
|
||||
describe("Vote Contract", async () => {
|
||||
let voteContract: VoteImpl;
|
||||
let currencyContract: TokenImpl;
|
||||
let voteContract: Vote;
|
||||
let currencyContract: Token;
|
||||
|
||||
// const voteStartWaitTimeInSeconds = 0;
|
||||
// const voteWaitTimeInSeconds = 5;
|
||||
@@ -27,7 +27,7 @@ describe("Vote Contract", async () => {
|
||||
sdk.updateSignerOrProvider(adminWallet);
|
||||
|
||||
const tokenContractAddress = await sdk.deployer.deployBuiltInContract(
|
||||
Token.contractType,
|
||||
TokenInitializer.contractType,
|
||||
{
|
||||
name: "DAOToken #1",
|
||||
symbol: "DAO1",
|
||||
@@ -36,7 +36,7 @@ describe("Vote Contract", async () => {
|
||||
);
|
||||
currencyContract = await sdk.getToken(tokenContractAddress);
|
||||
const voteContractAddress = await sdk.deployer.deployBuiltInContract(
|
||||
Vote.contractType,
|
||||
VoteInitializer.contractType,
|
||||
{
|
||||
name: "DAO #1",
|
||||
voting_token_address: currencyContract.getAddress(),
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user