Compare commits

...
19 changed files with 126 additions and 26 deletions
+7
View File
@@ -1,5 +1,12 @@
# @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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "2.0.6",
"version": "2.0.7",
"exports": {
"./package.json": "./package.json",
"./express": {
+7
View File
@@ -1,5 +1,12 @@
# 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
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "thirdweb",
"main": "dist/cli/index.js",
"version": "0.7.17",
"version": "0.7.18",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+10
View File
@@ -1,5 +1,15 @@
# @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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "3.0.6",
"version": "3.0.7",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -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: () => {
+3 -2
View File
@@ -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),
},
);
}
+6
View File
@@ -1,5 +1,11 @@
# @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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "3.0.6",
"version": "3.0.7",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
"license": "Apache-2.0",
@@ -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.
+22 -9
View File
@@ -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));
}
}
+5
View File
@@ -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);
+6
View File
@@ -1,5 +1,11 @@
# @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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/solana",
"version": "0.2.14",
"version": "0.2.15",
"description": "thirdweb Solana SDK",
"main": "dist/thirdweb-dev-solana.cjs.js",
"module": "dist/thirdweb-dev-solana.esm.js",
+11 -2
View File
@@ -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) {
+1
View File
@@ -22,6 +22,7 @@ describe("Registry", async () => {
});
nftDrop = await freshSDK.deployer.createNftDrop({
name: "Reg Test Drop",
itemsAvailable: 10,
});
});
+9
View File
@@ -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");
});
});