Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e39b66f309 | ||
|
|
5f5ab015e1 | ||
|
|
f4f05bd9a4 | ||
|
|
2f5b66bef9 | ||
|
|
63258bc9c3 | ||
|
|
a80fc97b6a | ||
|
|
24f66e38c2 |
+5
-1
@@ -26,7 +26,8 @@
|
||||
"version-packages": "changeset version",
|
||||
"release": "node ./scripts/pre-release.mjs && changeset publish",
|
||||
"version-packages:nightly": "changeset version --snapshot nightly",
|
||||
"release:nightly": "node ./scripts/pre-release.mjs && changeset publish --tag nightly"
|
||||
"release:nightly": "node ./scripts/pre-release.mjs && changeset publish --tag nightly",
|
||||
"push": "turbo run push"
|
||||
},
|
||||
"preconstruct": {
|
||||
"packages": [
|
||||
@@ -47,5 +48,8 @@
|
||||
},
|
||||
"manypkg": {
|
||||
"defaultBranch": "main"
|
||||
},
|
||||
"devDependencies": {
|
||||
"yalc": "^1.0.0-pre.53"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# @thirdweb-dev/auth
|
||||
|
||||
## 2.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`5f5ab01`](https://github.com/thirdweb-dev/js/commit/5f5ab015e1dd3c471d6affe995ef36ec88932b3c)]:
|
||||
- @thirdweb-dev/sdk@3.0.7
|
||||
|
||||
## 2.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870)]:
|
||||
- @thirdweb-dev/sdk@3.0.6
|
||||
|
||||
## 2.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/auth",
|
||||
"version": "2.0.5",
|
||||
"version": "2.0.7",
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
"./express": {
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# thirdweb
|
||||
|
||||
## 0.7.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`5f5ab01`](https://github.com/thirdweb-dev/js/commit/5f5ab015e1dd3c471d6affe995ef36ec88932b3c)]:
|
||||
- @thirdweb-dev/sdk@3.0.7
|
||||
|
||||
## 0.7.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870)]:
|
||||
- @thirdweb-dev/sdk@3.0.6
|
||||
|
||||
## 0.7.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "thirdweb",
|
||||
"main": "dist/cli/index.js",
|
||||
"version": "0.7.16",
|
||||
"version": "0.7.18",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
||||
"author": "thirdweb eng <[email protected]>",
|
||||
"license": "Apache-2.0",
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
# @thirdweb-dev/react
|
||||
|
||||
## 3.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#197](https://github.com/thirdweb-dev/js/pull/197) [`f4f05bd`](https://github.com/thirdweb-dev/js/commit/f4f05bd9a4ec98e9abc6716006353f330b7be055) Thanks [@jnsdls](https://github.com/jnsdls)! - make it obvious when the <Web3Button /> will trigger a network switch
|
||||
|
||||
- Updated dependencies [[`5f5ab01`](https://github.com/thirdweb-dev/js/commit/5f5ab015e1dd3c471d6affe995ef36ec88932b3c), [`5f5ab01`](https://github.com/thirdweb-dev/js/commit/5f5ab015e1dd3c471d6affe995ef36ec88932b3c)]:
|
||||
- @thirdweb-dev/sdk@3.0.7
|
||||
- @thirdweb-dev/solana@0.2.15
|
||||
|
||||
## 3.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#179](https://github.com/thirdweb-dev/js/pull/179) [`63258bc`](https://github.com/thirdweb-dev/js/commit/63258bc9c3443db7d12fc1dc6fbd483926c92d3e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose simple provider and useSDK hooks for Solana
|
||||
|
||||
- Updated dependencies [[`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870)]:
|
||||
- @thirdweb-dev/sdk@3.0.6
|
||||
- @thirdweb-dev/solana@0.2.14
|
||||
|
||||
## 3.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/react",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.7",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
||||
"author": "thirdweb eng <[email protected]>",
|
||||
"license": "Apache-2.0",
|
||||
@@ -8,9 +8,15 @@
|
||||
"types": "dist/thirdweb-dev-react.cjs.d.ts",
|
||||
"module": "dist/thirdweb-dev-react.esm.js",
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"patches/**/*"
|
||||
"dist/",
|
||||
"solana/"
|
||||
],
|
||||
"preconstruct": {
|
||||
"entrypoints": [
|
||||
"index.ts",
|
||||
"solana/index.ts"
|
||||
]
|
||||
},
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"format": "prettier --write 'src/**/*'",
|
||||
@@ -22,7 +28,8 @@
|
||||
"generate-snippets": "node ./scripts/generate-snippets.mjs && node ./scripts/generate-feature-snippets.mjs",
|
||||
"build": "tsc && preconstruct build",
|
||||
"e2e": "yarn test-ct",
|
||||
"test-ct": "playwright test -c playwright-ct.config.ts"
|
||||
"test-ct": "playwright test -c playwright-ct.config.ts",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"sideEffects:": false,
|
||||
"devDependencies": {
|
||||
@@ -36,6 +43,10 @@
|
||||
"@playwright/experimental-ct-react": "1.25.1",
|
||||
"@playwright/test": "1.25.1",
|
||||
"@preconstruct/cli": "^2.2.1",
|
||||
"@solana/wallet-adapter-base": "^0.9.17",
|
||||
"@solana/wallet-adapter-react": "^0.15.19",
|
||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
||||
"@solana/web3.js": "^1.63.0",
|
||||
"@thirdweb-dev/sdk": "*",
|
||||
"@types/color": "^3.0.3",
|
||||
"@types/mime": "^3.0.1",
|
||||
@@ -75,7 +86,12 @@
|
||||
"wagmi": "^0.2.28"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@solana/wallet-adapter-base": "^0.9.17",
|
||||
"@solana/wallet-adapter-react": "^0.15.19",
|
||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
||||
"@solana/web3.js": "^1.63.0",
|
||||
"@thirdweb-dev/sdk": "*",
|
||||
"@thirdweb-dev/solana": "*",
|
||||
"ethers": ">=5.5.1",
|
||||
"react": ">=18.0.0",
|
||||
"react-dom": ">=18.0.0"
|
||||
@@ -83,5 +99,22 @@
|
||||
"resolutions": {
|
||||
"ansi-regex": "^6.0.1",
|
||||
"typescript": "^4.6.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@solana/wallet-adapter-base": {
|
||||
"optional": true
|
||||
},
|
||||
"@solana/wallet-adapter-react": {
|
||||
"optional": true
|
||||
},
|
||||
"@solana/wallet-adapter-wallets": {
|
||||
"optional": true
|
||||
},
|
||||
"@solana/web3.js": {
|
||||
"optional": true
|
||||
},
|
||||
"@thirdweb-dev/solana": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "dist/thirdweb-dev-react-solana.cjs.js",
|
||||
"module": "dist/thirdweb-dev-react-solana.esm.js"
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useContract } from "../../hooks/async/contracts";
|
||||
import { useNetworkMismatch } from "../../hooks/useNetworkMismatch";
|
||||
import { useNetwork } from "../../hooks/wagmi-required/useNetwork";
|
||||
import { useAddress, useChainId } from "../../hooks/wallet";
|
||||
import { useSDKChainId } from "../../providers/base";
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
import { ConnectWallet } from "../ConnectWallet";
|
||||
import { Button } from "../shared/Button";
|
||||
import { ThemeProvider, ThemeProviderProps } from "../shared/ThemeProvider";
|
||||
import { FiWifi } from "@react-icons/all-files/fi/FiWifi";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import type { SmartContract } from "@thirdweb-dev/sdk/dist/declarations/src/contracts/smart-contract";
|
||||
import type { CallOverrides } from "ethers";
|
||||
@@ -74,6 +76,8 @@ export const Web3Button = <TAction extends ActionFn>({
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const hasMismatch = useNetworkMismatch();
|
||||
|
||||
const switchToChainId = useMemo(() => {
|
||||
if (sdkChainId && walletChainId && sdkChainId !== walletChainId) {
|
||||
return sdkChainId;
|
||||
@@ -130,6 +134,8 @@ export const Web3Button = <TAction extends ActionFn>({
|
||||
return <ConnectWallet className={className} {...themeProps} />;
|
||||
}
|
||||
|
||||
const willSwitchNetwork = hasMismatch && !!switchNetwork;
|
||||
|
||||
return (
|
||||
<ThemeProvider {...themeProps}>
|
||||
<Button
|
||||
@@ -137,9 +143,12 @@ export const Web3Button = <TAction extends ActionFn>({
|
||||
style={{ height: "50px", minWidth: "200px", width: "100%" }}
|
||||
isLoading={mutation.isLoading || !contract}
|
||||
onClick={() => mutation.mutate()}
|
||||
isDisabled={isDisabled}
|
||||
isDisabled={willSwitchNetwork ? false : isDisabled}
|
||||
leftElement={
|
||||
willSwitchNetwork ? <FiWifi width="1em" height="1em" /> : undefined
|
||||
}
|
||||
>
|
||||
{children}
|
||||
{willSwitchNetwork ? "Switch Network" : children}
|
||||
</Button>
|
||||
</ThemeProvider>
|
||||
);
|
||||
|
||||
@@ -83,7 +83,7 @@ export function useActiveClaimCondition(
|
||||
if (erc20) {
|
||||
return erc20.claimConditions.getActive();
|
||||
}
|
||||
return undefined;
|
||||
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||
},
|
||||
{
|
||||
// Checks that happen here:
|
||||
@@ -136,7 +136,7 @@ export function useClaimConditions(
|
||||
if (erc20) {
|
||||
return erc20.claimConditions.getAll();
|
||||
}
|
||||
return undefined;
|
||||
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||
},
|
||||
{
|
||||
// Checks that happen here:
|
||||
@@ -207,7 +207,7 @@ export function useClaimIneligibilityReasons(
|
||||
params.walletAddress,
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||
},
|
||||
{
|
||||
// Checks that happen here:
|
||||
@@ -284,7 +284,7 @@ export function useSetClaimConditions(
|
||||
if (erc20) {
|
||||
return erc20.claimConditions.set(phases, reset);
|
||||
}
|
||||
return undefined;
|
||||
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||
},
|
||||
{
|
||||
onSettled: () => {
|
||||
@@ -374,7 +374,7 @@ export function useResetClaimConditions(
|
||||
true,
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||
},
|
||||
{
|
||||
onSettled: () => {
|
||||
|
||||
@@ -223,7 +223,7 @@ export function useTotalCount<TContract extends NFTContract>(
|
||||
*/
|
||||
export function useTotalCirculatingSupply(
|
||||
contract: RequiredParam<NFTContract>,
|
||||
tokenId: BigNumberish,
|
||||
tokenId: RequiredParam<BigNumberish>,
|
||||
) {
|
||||
const contractAddress = contract?.getAddress();
|
||||
const { erc721, erc1155 } = getErcs(contract);
|
||||
@@ -238,6 +238,7 @@ export function useTotalCirculatingSupply(
|
||||
erc1155.totalCirculatingSupply,
|
||||
"Contract instance does not support totalCirculatingSupply",
|
||||
);
|
||||
invariant(tokenId, "No tokenId provided");
|
||||
return await erc1155.totalCirculatingSupply(tokenId);
|
||||
}
|
||||
if (erc721) {
|
||||
@@ -250,7 +251,7 @@ export function useTotalCirculatingSupply(
|
||||
invariant(false, "Unknown NFT type");
|
||||
},
|
||||
{
|
||||
enabled: !!erc721 || !!erc1155,
|
||||
enabled: !!erc721 || (!!erc1155 && tokenId !== undefined),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ThirdwebSDKContext } from "../providers/ThirdwebSDKProvider";
|
||||
import { useContext } from "react";
|
||||
|
||||
export function useSDK() {
|
||||
return useContext(ThirdwebSDKContext);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Providers
|
||||
export * from "./providers/ThirdwebSDKProvider";
|
||||
export * from "./providers/ThirdwebProvider";
|
||||
// Hooks
|
||||
export * from "./hooks/useSDK";
|
||||
@@ -0,0 +1,66 @@
|
||||
import { ThirdwebSDKProvider } from "./ThirdwebSDKProvider";
|
||||
import type { WalletAdapter } from "@solana/wallet-adapter-base";
|
||||
import {
|
||||
ConnectionProvider,
|
||||
useConnection,
|
||||
useWallet,
|
||||
WalletProvider,
|
||||
} from "@solana/wallet-adapter-react";
|
||||
import { PhantomWalletAdapter } from "@solana/wallet-adapter-wallets";
|
||||
import { getUrlForNetwork, Network } from "@thirdweb-dev/solana";
|
||||
import { PropsWithChildren } from "react";
|
||||
|
||||
interface ThirdwebProviderProps {
|
||||
endpoint: Network;
|
||||
wallets?: WalletAdapter[];
|
||||
autoConnect?: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_WALLETS = [new PhantomWalletAdapter()];
|
||||
|
||||
/**
|
||||
* Gives access to the ThirdwebSDK instance and other useful hooks to the rest of the app.
|
||||
* Requires to be wrapped with a ConnectionProvider and a WalletProvider from @solana/wallet-adapter-react.
|
||||
* @example
|
||||
* ```tsx
|
||||
* import { ThirdwebProvider } from "@thirdweb-dev/react/solana";
|
||||
*
|
||||
* const App = () => {
|
||||
* return (
|
||||
* <ThirdwebProvider endpoint="devnet">
|
||||
* <YourApp />
|
||||
* </ThirdwebProvider>
|
||||
* )};
|
||||
* ```
|
||||
* @beta
|
||||
*/
|
||||
export const ThirdwebProvider: React.FC<
|
||||
PropsWithChildren<ThirdwebProviderProps>
|
||||
> = ({ endpoint, wallets, autoConnect, children }) => {
|
||||
const clusterUrl = getUrlForNetwork(endpoint);
|
||||
return (
|
||||
<ConnectionProvider endpoint={clusterUrl}>
|
||||
<WalletProvider
|
||||
wallets={wallets || DEFAULT_WALLETS}
|
||||
autoConnect={autoConnect || true}
|
||||
>
|
||||
<ThirdwebWrapperProvider>{children}</ThirdwebWrapperProvider>
|
||||
</WalletProvider>
|
||||
</ConnectionProvider>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const ThirdwebWrapperProvider: React.FC<PropsWithChildren> = ({
|
||||
children,
|
||||
}) => {
|
||||
const { connection } = useConnection();
|
||||
const wallet = useWallet();
|
||||
return (
|
||||
<ThirdwebSDKProvider connection={connection} wallet={wallet}>
|
||||
{children}
|
||||
</ThirdwebSDKProvider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { WalletContextState } from "@solana/wallet-adapter-react";
|
||||
import type { Connection } from "@solana/web3.js";
|
||||
import { ThirdwebSDK } from "@thirdweb-dev/solana";
|
||||
import {
|
||||
createContext,
|
||||
FC,
|
||||
PropsWithChildren,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
interface ThirdwebSDKProviderProps {
|
||||
connection: Connection;
|
||||
wallet?: WalletContextState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives access to the ThirdwebSDK instance and other useful hooks to the rest of the app.
|
||||
* Requires to be wrapped with a ConnectionProvider and a WalletProvider from @solana/wallet-adapter-react.
|
||||
* @example
|
||||
* ```tsx
|
||||
* import {
|
||||
* useConnection,
|
||||
* useWallet,
|
||||
* } from "@solana/wallet-adapter-react";
|
||||
* import { ThirdwebProvider } from "@thirdweb-dev/react/solana";
|
||||
*
|
||||
* const ThirdwebApp = () => {
|
||||
* const { connection } = useConnection();
|
||||
* const wallet = useWallet();
|
||||
* return (
|
||||
* <ThirdwebSDKProvider connection={connection} wallet={wallet}>
|
||||
* <YourApp />
|
||||
* </ThirdwebSDKProvider>
|
||||
* )};
|
||||
* ```
|
||||
*/
|
||||
export const ThirdwebSDKProvider: FC<
|
||||
PropsWithChildren<ThirdwebSDKProviderProps>
|
||||
> = ({ children, connection, wallet }) => {
|
||||
const [sdk, setSDK] = useState<ThirdwebSDK | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (connection) {
|
||||
setSDK(new ThirdwebSDK(connection));
|
||||
} else {
|
||||
setSDK(null);
|
||||
}
|
||||
}, [connection]);
|
||||
|
||||
useEffect(() => {
|
||||
if (sdk) {
|
||||
if (wallet?.publicKey) {
|
||||
sdk.wallet.connect(wallet);
|
||||
} else {
|
||||
sdk.wallet.disconnect();
|
||||
}
|
||||
}
|
||||
}, [sdk, wallet]);
|
||||
|
||||
return (
|
||||
<ThirdwebSDKContext.Provider value={sdk}>
|
||||
{children}
|
||||
</ThirdwebSDKContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const ThirdwebSDKContext = createContext<ThirdwebSDK | null>(null);
|
||||
@@ -1,5 +1,20 @@
|
||||
# @thirdweb-dev/sdk
|
||||
|
||||
## 3.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#199](https://github.com/thirdweb-dev/js/pull/199) [`5f5ab01`](https://github.com/thirdweb-dev/js/commit/5f5ab015e1dd3c471d6affe995ef36ec88932b3c) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix getOwned for signature drop
|
||||
|
||||
## 3.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#195](https://github.com/thirdweb-dev/js/pull/195) [`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870) Thanks [@jnsdls](https://github.com/jnsdls)! - add missing roles for pre-built contracts
|
||||
|
||||
- Updated dependencies [[`24f66e3`](https://github.com/thirdweb-dev/js/commit/24f66e38c256f7bd69341b92ba30bd35d14b1caa)]:
|
||||
- @thirdweb-dev/storage@1.0.3
|
||||
|
||||
## 3.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/sdk",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.7",
|
||||
"description": "The main thirdweb SDK.",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
|
||||
"license": "Apache-2.0",
|
||||
@@ -20,7 +20,8 @@
|
||||
"build": "tsc && preconstruct build",
|
||||
"test:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000 --parallel './test/**/*.test.ts'",
|
||||
"test": "make test",
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000"
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
||||
|
||||
@@ -88,7 +88,7 @@ export const MultiwrapInitializer = {
|
||||
name: "Multiwrap" as const,
|
||||
contractType: "multiwrap" as const,
|
||||
schema: MultiwrapContractSchema,
|
||||
roles: ["transfer", "minter", "unwrap", "asset"] as const,
|
||||
roles: ["admin", "transfer", "minter", "unwrap", "asset"] as const,
|
||||
initialize: async (
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
@@ -149,7 +149,7 @@ export const PackInitializer = {
|
||||
name: "Pack" as const,
|
||||
contractType: "pack" as const,
|
||||
schema: PackContractSchema,
|
||||
roles: ["admin", "minter", "pauser", "transfer"] as const,
|
||||
roles: ["admin", "minter", "asset", "transfer"] as const,
|
||||
|
||||
initialize: async (
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
|
||||
@@ -51,7 +51,13 @@ import { BigNumberish, CallOverrides, ethers } from "ethers";
|
||||
* @beta
|
||||
*/
|
||||
export class Multiwrap extends StandardErc721<MultiwrapContract> {
|
||||
static contractRoles = ["transfer", "minter", "unwrap", "asset"] as const;
|
||||
static contractRoles = [
|
||||
"admin",
|
||||
"transfer",
|
||||
"minter",
|
||||
"unwrap",
|
||||
"asset",
|
||||
] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
public encoder: ContractEncoder<MultiwrapContract>;
|
||||
|
||||
@@ -57,7 +57,7 @@ import { BigNumber, BigNumberish, CallOverrides, ethers } from "ethers";
|
||||
* @public
|
||||
*/
|
||||
export class Pack extends StandardErc1155<PackContract> {
|
||||
static contractRoles = ["admin", "minter", "pauser", "transfer"] as const;
|
||||
static contractRoles = ["admin", "minter", "asset", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
public metadata: ContractMetadata<PackContract, typeof PackContractSchema>;
|
||||
@@ -712,4 +712,4 @@ export class Pack extends StandardErc1155<PackContract> {
|
||||
): Promise<any> {
|
||||
return this.contractWrapper.call(functionName, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import type {
|
||||
IERC721Enumerable,
|
||||
IERC721Supply,
|
||||
} from "@thirdweb-dev/contracts-js";
|
||||
import { BigNumber } from "ethers";
|
||||
import { BigNumber, constants } from "ethers";
|
||||
|
||||
/**
|
||||
* List ERC721 NFTs
|
||||
@@ -68,6 +68,23 @@ export class Erc721Supply implements DetectableFeature {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the owners of each token id in this contract
|
||||
* @returns
|
||||
*/
|
||||
public async allOwners() {
|
||||
return Promise.all(
|
||||
[...new Array((await this.totalCount()).toNumber()).keys()].map(
|
||||
async (i) => ({
|
||||
tokenId: i,
|
||||
owner: await this.erc721
|
||||
.ownerOf(i)
|
||||
.catch(() => constants.AddressZero),
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of NFTs minted
|
||||
* @remarks This returns the total number of NFTs minted in this contract, **not** the total supply of a given token.
|
||||
|
||||
@@ -259,6 +259,15 @@ export class Erc721<
|
||||
return assertEnabled(this.query, FEATURE_NFT_SUPPLY).all(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All owners of minted NFTs on this contract
|
||||
* @returns an array of token ids and owners
|
||||
* @twfeature ERC721Supply
|
||||
*/
|
||||
public async getAllOwners() {
|
||||
return assertEnabled(this.query, FEATURE_NFT_SUPPLY).allOwners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of NFTs minted
|
||||
* @remarks This returns the total number of NFTs minted in this contract, **not** the total supply of a given token.
|
||||
@@ -302,9 +311,13 @@ export class Erc721<
|
||||
if (this.query?.owned) {
|
||||
return this.query.owned.all(walletAddress);
|
||||
} else {
|
||||
const allNFTs = await this.getAll();
|
||||
return (allNFTs || []).filter(
|
||||
({ owner }) => walletAddress?.toLowerCase() === owner?.toLowerCase(),
|
||||
const address =
|
||||
walletAddress || (await this.contractWrapper.getSignerAddress());
|
||||
const allOwners = await this.getAllOwners();
|
||||
return Promise.all(
|
||||
(allOwners || [])
|
||||
.filter((i) => address?.toLowerCase() === i.owner?.toLowerCase())
|
||||
.map(async (i) => await this.get(i.tokenId)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -317,12 +330,12 @@ export class Erc721<
|
||||
if (this.query?.owned) {
|
||||
return this.query.owned.tokenIds(walletAddress);
|
||||
} else {
|
||||
const allNFTs = await this.getAll();
|
||||
return (allNFTs || [])
|
||||
.filter(
|
||||
({ owner }) => walletAddress?.toLowerCase() === owner?.toLowerCase(),
|
||||
)
|
||||
.map(({ metadata: { id } }) => id);
|
||||
const address =
|
||||
walletAddress || (await this.contractWrapper.getSignerAddress());
|
||||
const allOwners = await this.getAllOwners();
|
||||
return (allOwners || [])
|
||||
.filter((i) => address?.toLowerCase() === i.owner?.toLowerCase())
|
||||
.map((i) => BigNumber.from(i.tokenId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -631,9 +631,14 @@ describe("Signature drop tests", async () => {
|
||||
}
|
||||
await signatureDropContract.createBatch(metadatas);
|
||||
const all = await signatureDropContract.getAll();
|
||||
let owned = await signatureDropContract.getOwned();
|
||||
expect(all.length).to.eq(100);
|
||||
expect(owned.length).to.eq(0);
|
||||
await signatureDropContract.claimConditions.set([{}]);
|
||||
await signatureDropContract.claim(1);
|
||||
owned = await signatureDropContract.getOwned();
|
||||
expect(owned.length).to.eq(1);
|
||||
expect(owned[0].owner).to.eq(adminWallet.address);
|
||||
const claimed = await signatureDropContract.totalClaimedSupply();
|
||||
const unclaimed = await signatureDropContract.totalUnclaimedSupply();
|
||||
expect(claimed.toNumber()).to.eq(1);
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
# @thirdweb-dev/solana
|
||||
|
||||
## 0.2.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#199](https://github.com/thirdweb-dev/js/pull/199) [`5f5ab01`](https://github.com/thirdweb-dev/js/commit/5f5ab015e1dd3c471d6affe995ef36ec88932b3c) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix getting wallet balance
|
||||
|
||||
## 0.2.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`24f66e3`](https://github.com/thirdweb-dev/js/commit/24f66e38c256f7bd69341b92ba30bd35d14b1caa)]:
|
||||
- @thirdweb-dev/storage@1.0.3
|
||||
|
||||
## 0.2.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/solana",
|
||||
"version": "0.2.13",
|
||||
"version": "0.2.15",
|
||||
"description": "thirdweb Solana SDK",
|
||||
"main": "dist/thirdweb-dev-solana.cjs.js",
|
||||
"module": "dist/thirdweb-dev-solana.esm.js",
|
||||
@@ -18,7 +18,8 @@
|
||||
"node:stop": "amman stop",
|
||||
"test:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000 --parallel './test/**/*.test.ts'",
|
||||
"test": "make test",
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000"
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { CurrencyValue, WalletSigner } from "../types/common";
|
||||
import { toCurrencyValue } from "../utils/token";
|
||||
import {
|
||||
amount,
|
||||
guestIdentity,
|
||||
isIdentitySigner,
|
||||
isKeypairSigner,
|
||||
keypairIdentity,
|
||||
Metaplex,
|
||||
Signer,
|
||||
SOL,
|
||||
sol,
|
||||
walletAdapterIdentity,
|
||||
} from "@metaplex-foundation/js";
|
||||
import { Keypair } from "@solana/web3.js";
|
||||
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||
import EventEmitter from "eventemitter3";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
@@ -83,6 +85,13 @@ export class UserWallet {
|
||||
this.events.emit("disconnected");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether a wallet is connected
|
||||
*/
|
||||
public isConnected() {
|
||||
return this.metaplex.identity().publicKey !== PublicKey.default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the address of the connected wallet
|
||||
* @returns the address of the connected wallet
|
||||
@@ -123,7 +132,7 @@ export class UserWallet {
|
||||
const value = await this.metaplex.connection.getBalance(
|
||||
this.metaplex.identity().publicKey,
|
||||
);
|
||||
return toCurrencyValue(sol(value));
|
||||
return toCurrencyValue(amount(value, SOL));
|
||||
}
|
||||
|
||||
private connectToMetaplex(signer: WalletSigner) {
|
||||
|
||||
@@ -14,6 +14,8 @@ export * from "./types/index";
|
||||
export * from "./types/common";
|
||||
export * from "./types/contracts";
|
||||
export * from "./types/contracts/nft-drop";
|
||||
// utils
|
||||
export * from "./utils/urls";
|
||||
|
||||
//schema for dashboard use
|
||||
export {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe("Registry", async () => {
|
||||
});
|
||||
nftDrop = await freshSDK.deployer.createNftDrop({
|
||||
name: "Reg Test Drop",
|
||||
itemsAvailable: 10,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { sdk } from "./before-setup";
|
||||
import { expect } from "chai";
|
||||
|
||||
describe("Wallet", async () => {
|
||||
it("balance", async () => {
|
||||
const balance = await sdk.wallet.getBalance();
|
||||
expect(balance.displayValue).to.eq("100.000000000");
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,11 @@
|
||||
# @thirdweb-dev/storage
|
||||
|
||||
## 1.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#192](https://github.com/thirdweb-dev/js/pull/192) [`24f66e3`](https://github.com/thirdweb-dev/js/commit/24f66e38c256f7bd69341b92ba30bd35d14b1caa) Thanks [@adam-maj](https://github.com/adam-maj)! - Use XHR for upload
|
||||
|
||||
## 1.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/storage",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"main": "dist/thirdweb-dev-storage.cjs.js",
|
||||
"module": "dist/thirdweb-dev-storage.esm.js",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/storage",
|
||||
@@ -15,7 +15,8 @@
|
||||
"build": "tsc && preconstruct build",
|
||||
"test:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000 --parallel './test/**/*.test.ts'",
|
||||
"test": "yarn test:all",
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000"
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
|
||||
@@ -183,41 +183,102 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
let timer = setTimeout(() => {
|
||||
xhr.abort();
|
||||
reject(
|
||||
new Error(
|
||||
"Request to upload timed out! No upload progress received in 30s",
|
||||
),
|
||||
);
|
||||
}, 30000);
|
||||
|
||||
xhr.upload.addEventListener("loadstart", () => {
|
||||
console.log(`[${Date.now()}] [IPFS] Started`);
|
||||
});
|
||||
|
||||
xhr.upload.addEventListener("progress", (event) => {
|
||||
console.log(`[IPFS] Progress Event ${event.loaded}/${event.total}`);
|
||||
|
||||
clearTimeout(timer);
|
||||
|
||||
if (event.loaded < event.total) {
|
||||
timer = setTimeout(() => {
|
||||
xhr.abort();
|
||||
reject(
|
||||
new Error(
|
||||
"Request to upload timed out! No upload progress received in 30s",
|
||||
),
|
||||
);
|
||||
}, 30000);
|
||||
} else {
|
||||
console.log(
|
||||
`[${Date.now()}] [IPFS] Uploaded files. Waiting for response.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (event.lengthComputable && options?.onProgress) {
|
||||
options?.onProgress({
|
||||
progress: event.loaded,
|
||||
total: event.total,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener("load", () => {
|
||||
console.log(`[${Date.now()}] [IPFS] Load`);
|
||||
clearTimeout(timer);
|
||||
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(xhr.responseText);
|
||||
} catch (err) {
|
||||
return reject(
|
||||
new Error("Failed to parse JSON from upload response"),
|
||||
);
|
||||
}
|
||||
|
||||
const cid = body.IpfsHash;
|
||||
if (!cid) {
|
||||
throw new Error("Failed to get IPFS hash from upload response");
|
||||
}
|
||||
|
||||
if (options?.uploadWithoutDirectory) {
|
||||
return resolve([`ipfs://${cid}`]);
|
||||
} else {
|
||||
return resolve(fileNames.map((name) => `ipfs://${cid}/${name}`));
|
||||
}
|
||||
}
|
||||
|
||||
return reject(
|
||||
new Error(
|
||||
`Upload failed with status ${xhr.status} - ${xhr.responseText}`,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
xhr.addEventListener("error", () => {
|
||||
console.log("[IPFS] Load");
|
||||
clearTimeout(timer);
|
||||
|
||||
if (
|
||||
(xhr.readyState !== 0 && xhr.readyState !== 4) ||
|
||||
xhr.status === 0
|
||||
) {
|
||||
return reject(
|
||||
new Error(
|
||||
"This looks like a network error, the endpoint might be blocked by an internet provider or a firewall.",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return reject(new Error("Unknown upload error occured"));
|
||||
});
|
||||
|
||||
xhr.open("POST", PINATA_IPFS_URL);
|
||||
xhr.setRequestHeader("Authorization", `Bearer ${token}`);
|
||||
|
||||
xhr.onloadend = () => {
|
||||
if (xhr.status !== 200) {
|
||||
throw new Error("Failed to upload files to IPFS");
|
||||
}
|
||||
|
||||
const cid = JSON.parse(xhr.responseText).IpfsHash;
|
||||
if (!cid) {
|
||||
throw new Error("Failed to upload files to IPFS");
|
||||
}
|
||||
|
||||
if (options?.uploadWithoutDirectory) {
|
||||
resolve([`ipfs://${cid}`]);
|
||||
} else {
|
||||
resolve(fileNames.map((name) => `ipfs://${cid}/${name}`));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = (err) => {
|
||||
reject(err);
|
||||
};
|
||||
|
||||
if (xhr.upload) {
|
||||
xhr.upload.onprogress = (event) => {
|
||||
if (options?.onProgress) {
|
||||
options?.onProgress({
|
||||
progress: event.loaded,
|
||||
total: event.total,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
xhr.send(form as any);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@
|
||||
},
|
||||
"clean": {
|
||||
"cache": false
|
||||
},
|
||||
"push": {
|
||||
"cache": false,
|
||||
"dependsOn": ["build"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user