Compare commits
53
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e8d3fd6e7 | ||
|
|
cc4613b5fd | ||
|
|
78566babaa | ||
|
|
65fc7ba6ff | ||
|
|
1c24c3c3c4 | ||
|
|
408c5a81fa | ||
|
|
352291791e | ||
|
|
aabbb149e8 | ||
|
|
d59450f814 | ||
|
|
7d9a4c6abc | ||
|
|
99806e595d | ||
|
|
21c21c1adf | ||
|
|
4b10719047 | ||
|
|
989cf7347c | ||
|
|
72227b2e16 | ||
|
|
ed6c54f20d | ||
|
|
26116a6f63 | ||
|
|
f11a2719ff | ||
|
|
ef27aad0aa | ||
|
|
b03a902145 | ||
|
|
340605b507 | ||
|
|
15f8006e1f | ||
|
|
811c5a1166 | ||
|
|
c41a80d86d | ||
|
|
ad851f7b4d | ||
|
|
6218c88584 | ||
|
|
c9b564feaf | ||
|
|
87fd6ab14e | ||
|
|
df74340fa5 | ||
|
|
a57b4f01f3 | ||
|
|
126752d7d0 | ||
|
|
89ff921a7d | ||
|
|
9124b3180c | ||
|
|
f41a443c57 | ||
|
|
b7cd744cd0 | ||
|
|
bb1b4e6ac3 | ||
|
|
2f8ec89c4c | ||
|
|
6ae52664e5 | ||
|
|
4f867e15ed | ||
|
|
cc8f983615 | ||
|
|
f45ef62128 | ||
|
|
9727502eb3 | ||
|
|
b6eec6146c | ||
|
|
88daa3c5cb | ||
|
|
53c6507669 | ||
|
|
782b58d3f6 | ||
|
|
e17e41f4d1 | ||
|
|
712b11a43e | ||
|
|
306debb029 | ||
|
|
86f0ceff46 | ||
|
|
7f0d1ec947 | ||
|
|
b1218cbd7d | ||
|
|
97ef35ce0f |
@@ -7,7 +7,7 @@
|
|||||||
"access": "public",
|
"access": "public",
|
||||||
"baseBranch": "main",
|
"baseBranch": "main",
|
||||||
"updateInternalDependencies": "patch",
|
"updateInternalDependencies": "patch",
|
||||||
"ignore": [],
|
"ignore": ["e2e-cra-5", "e2e-next-12", "e2e-vite-3"],
|
||||||
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
|
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
|
||||||
"updateInternalDependents": "always",
|
"updateInternalDependents": "always",
|
||||||
"onlyUpdatePeerDependentsWhenOutOfRange": true
|
"onlyUpdatePeerDependentsWhenOutOfRange": true
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ runs:
|
|||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
registry-url: "https://registry.npmjs.org"
|
registry-url: "https://registry.npmjs.org"
|
||||||
# cache: "yarn"
|
cache: "yarn"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
run: yarn install --frozen-lockfile
|
run: yarn install
|
||||||
env:
|
env:
|
||||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
# timeout-minutes: 15
|
# timeout-minutes: 15
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
||||||
env:
|
env:
|
||||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
integration-tests:
|
integration-tests:
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
@@ -28,9 +27,3 @@ jobs:
|
|||||||
run: yarn e2e
|
run: yarn e2e
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: "--max_old_space_size=4096"
|
NODE_OPTIONS: "--max_old_space_size=4096"
|
||||||
- uses: actions/upload-artifact@v2
|
|
||||||
if: always()
|
|
||||||
with:
|
|
||||||
name: playwright-report
|
|
||||||
path: packages/react/playwright-report/
|
|
||||||
retention-days: 30
|
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ jobs:
|
|||||||
comment_body: ${{ github.event.comment.body }}
|
comment_body: ${{ github.event.comment.body }}
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
needs: deploy-check
|
needs: deploy-check
|
||||||
if: needs.deploy-check.outputs.triggered == 'true'
|
if: needs.deploy-check.outputs.triggered == 'true'
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout branch
|
- name: Checkout branch
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ on: [pull_request]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -16,3 +15,5 @@ jobs:
|
|||||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
strip-hash: "\\-(\\w{8})(?:\\.esm|\\.cjs)"
|
strip-hash: "\\-(\\w{8})(?:\\.esm|\\.cjs)"
|
||||||
minimum-change-threshold: 100
|
minimum-change-threshold: 100
|
||||||
|
# exclude source maps, node modules and any test related files
|
||||||
|
exclude: "{**/*.map,**/node_modules/**,**/test/**}"
|
||||||
|
|||||||
@@ -13,3 +13,7 @@ public/dist
|
|||||||
.turbo
|
.turbo
|
||||||
./packages/contracts-js/abis
|
./packages/contracts-js/abis
|
||||||
.idea/
|
.idea/
|
||||||
|
.yalc/
|
||||||
|
yalc.lock
|
||||||
|
build/
|
||||||
|
playwright-report/
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
lib
|
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
contracts-js
|
contracts-js
|
||||||
|
|||||||
+2
-6
@@ -8,7 +8,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*",
|
||||||
|
"test/**/*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -29,11 +30,6 @@
|
|||||||
"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"
|
"push": "turbo run push"
|
||||||
},
|
},
|
||||||
"preconstruct": {
|
|
||||||
"packages": [
|
|
||||||
"packages/*"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"packageManager": "[email protected]",
|
"packageManager": "[email protected]",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@changesets/changelog-github": "^0.4.6",
|
"@changesets/changelog-github": "^0.4.6",
|
||||||
|
|||||||
@@ -1,5 +1,31 @@
|
|||||||
# @thirdweb-dev/auth
|
# @thirdweb-dev/auth
|
||||||
|
|
||||||
|
## 2.0.25
|
||||||
|
|
||||||
|
## 2.0.24
|
||||||
|
|
||||||
|
## 2.0.23
|
||||||
|
|
||||||
|
## 2.0.22
|
||||||
|
|
||||||
|
## 2.0.21
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - enable e2e testing
|
||||||
|
|
||||||
|
## 2.0.20
|
||||||
|
|
||||||
|
## 2.0.19
|
||||||
|
|
||||||
|
## 2.0.18
|
||||||
|
|
||||||
|
## 2.0.17
|
||||||
|
|
||||||
|
## 2.0.16
|
||||||
|
|
||||||
|
## 2.0.15
|
||||||
|
|
||||||
## 2.0.14
|
## 2.0.14
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/auth",
|
"name": "@thirdweb-dev/auth",
|
||||||
"version": "2.0.14",
|
"version": "2.0.25",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./next": {
|
"./next": {
|
||||||
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
||||||
|
|||||||
@@ -1,5 +1,86 @@
|
|||||||
# thirdweb
|
# thirdweb
|
||||||
|
|
||||||
|
## 0.8.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies []:
|
||||||
|
- @thirdweb-dev/sdk@3.4.4
|
||||||
|
|
||||||
|
## 0.8.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5), [`65fc7ba`](https://github.com/thirdweb-dev/js/commit/65fc7ba6fff093a971b53cb0979c39768e090ba1)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.3
|
||||||
|
|
||||||
|
## 0.8.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`21c21c1`](https://github.com/thirdweb-dev/js/commit/21c21c1adfd09b60ad563bfd4c308597140de33c), [`3522917`](https://github.com/thirdweb-dev/js/commit/352291791ee900e1500f84f095290497934d2f60)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.2
|
||||||
|
|
||||||
|
## 0.8.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`72227b2`](https://github.com/thirdweb-dev/js/commit/72227b2e166a3a68bbb41cf2b389322f5b7547a2)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.1
|
||||||
|
|
||||||
|
## 0.8.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - enable e2e testing
|
||||||
|
|
||||||
|
- Updated dependencies [[`340605b`](https://github.com/thirdweb-dev/js/commit/340605b507f384fbd2999b9c16542af3c53e84a9), [`26116a6`](https://github.com/thirdweb-dev/js/commit/26116a6f637ee845f7bd17f20ffe17caf184658e), [`15f8006`](https://github.com/thirdweb-dev/js/commit/15f8006e1fb22333b7ee239b45e7b1b12d6dccc8), [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.0
|
||||||
|
|
||||||
|
## 0.8.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`ad851f7`](https://github.com/thirdweb-dev/js/commit/ad851f7b4d6abb5ab9364ef3dec229f913e18ce5), [`6218c88`](https://github.com/thirdweb-dev/js/commit/6218c885842e6b4e44ec38ec92a9211e56c49bf4)]:
|
||||||
|
- @thirdweb-dev/sdk@3.3.1
|
||||||
|
|
||||||
|
## 0.8.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#326](https://github.com/thirdweb-dev/js/pull/326) [`126752d`](https://github.com/thirdweb-dev/js/commit/126752d7d02c9a808a63fb9e67a9df6658b5682b) Thanks [@jnsdls](https://github.com/jnsdls)! - remove tons of unused dependencies, use SDK function for extracting ipfs has from bytecode
|
||||||
|
|
||||||
|
- Updated dependencies [[`126752d`](https://github.com/thirdweb-dev/js/commit/126752d7d02c9a808a63fb9e67a9df6658b5682b), [`df74340`](https://github.com/thirdweb-dev/js/commit/df74340fa51323304c32419761d6f18628b060fa), [`89ff921`](https://github.com/thirdweb-dev/js/commit/89ff921a7d9f0e42b4e6707c8b56d0aab95c1aa0), [`a57b4f0`](https://github.com/thirdweb-dev/js/commit/a57b4f01f3a49590b897101f2730582e4124a554)]:
|
||||||
|
- @thirdweb-dev/sdk@3.3.0
|
||||||
|
|
||||||
|
## 0.8.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`4f867e1`](https://github.com/thirdweb-dev/js/commit/4f867e15edbe5757afbf54cab207458711a8986c), [`b6eec61`](https://github.com/thirdweb-dev/js/commit/b6eec6146c23b66a3681bbb48b173b9019254214), [`9727502`](https://github.com/thirdweb-dev/js/commit/9727502eb30ac139382b7c7c8e8fc0967cbfbcf1), [`782b58d`](https://github.com/thirdweb-dev/js/commit/782b58d3f6a3b49ff9b3d837551db5161f96171a), [`f41a443`](https://github.com/thirdweb-dev/js/commit/f41a443c5785240197607b5bf93ff18a1c8e8307), [`f45ef62`](https://github.com/thirdweb-dev/js/commit/f45ef62128cfefe06275a38440c90d45e9f3cef7), [`2f8ec89`](https://github.com/thirdweb-dev/js/commit/2f8ec89c4c83ae577092c840c198e6fcfb114e69), [`b7cd744`](https://github.com/thirdweb-dev/js/commit/b7cd744cd0482a6c3fe5ae0c858f20cd380d4114), [`53c6507`](https://github.com/thirdweb-dev/js/commit/53c65076696a43bd9a7e58a7493d4e65c172900f)]:
|
||||||
|
- @thirdweb-dev/sdk@3.2.6
|
||||||
|
|
||||||
|
## 0.8.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`712b11a`](https://github.com/thirdweb-dev/js/commit/712b11a43e389ae10b7f09648779a69c05b2c913)]:
|
||||||
|
- @thirdweb-dev/sdk@3.2.5
|
||||||
|
|
||||||
|
## 0.8.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies []:
|
||||||
|
- @thirdweb-dev/sdk@3.2.4
|
||||||
|
|
||||||
|
## 0.8.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies []:
|
||||||
|
- @thirdweb-dev/sdk@3.2.3
|
||||||
|
|
||||||
## 0.8.0
|
## 0.8.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "thirdweb",
|
"name": "thirdweb",
|
||||||
"main": "dist/cli/index.js",
|
"main": "dist/cli/index.js",
|
||||||
"version": "0.8.0",
|
"version": "0.8.11",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
@@ -31,24 +31,17 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@thirdweb-dev/sdk": "*",
|
"@thirdweb-dev/sdk": "*",
|
||||||
"async-retry": "^1.3.3",
|
"async-retry": "^1.3.3",
|
||||||
"cbor": "^8.1.0",
|
|
||||||
"commander": "^9.1.0",
|
"commander": "^9.1.0",
|
||||||
"cpy": "^9.0.1",
|
|
||||||
"enquirer": "^2.3.6",
|
"enquirer": "^2.3.6",
|
||||||
"ethers": "^5.7.0",
|
"ethers": "^5.7.0",
|
||||||
"form-data": "^4.0.0",
|
|
||||||
"got": "11.8.5",
|
"got": "11.8.5",
|
||||||
"inquirer": "^8.2.3",
|
"inquirer": "^8.2.3",
|
||||||
"ipfs-unixfs": "^6.0.7",
|
|
||||||
"ipld-dag-pb": "^0.22.3",
|
|
||||||
"multihashes": "^4.0.3",
|
|
||||||
"open": "^8.4.0",
|
"open": "^8.4.0",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"solc": "0.8.13",
|
"solc": "0.8.13",
|
||||||
"tar": "^6.1.11",
|
"tar": "^6.1.11",
|
||||||
"tslog": "^3.3.3",
|
"tslog": "^3.3.3",
|
||||||
"update-check": "^1.5.4",
|
|
||||||
"update-notifier": "^6.0.2",
|
"update-notifier": "^6.0.2",
|
||||||
"validate-npm-package-name": "^4.0.0",
|
"validate-npm-package-name": "^4.0.0",
|
||||||
"yaml": "^2.1.1"
|
"yaml": "^2.1.1"
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
.version(cliVersion, "-v, --version");
|
.version(cliVersion, "-v, --version");
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("create")
|
.command("create [projectPath]")
|
||||||
.description(
|
.description(
|
||||||
"Create a web3 app from any of our official templates: https://github.com/thirdweb-example/",
|
"Create a web3 app from any of our official templates: https://github.com/thirdweb-example/",
|
||||||
)
|
)
|
||||||
@@ -66,8 +66,8 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
"-t, --template [name]",
|
"-t, --template [name]",
|
||||||
`A template to start your project from. You can use an template repository name from the official thirdweb-example org.`,
|
`A template to start your project from. You can use an template repository name from the official thirdweb-example org.`,
|
||||||
)
|
)
|
||||||
.action(async (options) => {
|
.action(async (path, options) => {
|
||||||
await twCreate(options);
|
await twCreate(path, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { extractIPFSHashFromBytecode } from "../helpers/ipfs";
|
|
||||||
import { logger } from "../helpers/logger";
|
import { logger } from "../helpers/logger";
|
||||||
import { CompileOptions, IBuilder } from "../interfaces/Builder";
|
import { CompileOptions, IBuilder } from "../interfaces/Builder";
|
||||||
import { ContractPayload } from "../interfaces/ContractPayload";
|
import { ContractPayload } from "../interfaces/ContractPayload";
|
||||||
|
import { extractIPFSHashFromBytecode } from "@thirdweb-dev/sdk/evm";
|
||||||
|
|
||||||
export abstract class BaseBuilder implements IBuilder {
|
export abstract class BaseBuilder implements IBuilder {
|
||||||
abstract compile(
|
abstract compile(
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
import { decodeFirstSync } from "cbor";
|
|
||||||
import { UnixFS } from "ipfs-unixfs";
|
|
||||||
import { DAGNode } from "ipld-dag-pb";
|
|
||||||
import { toB58String } from "multihashes";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Derives IPFS hash of string
|
|
||||||
* @param {String} str
|
|
||||||
* @return {String} IPFS hash (ex: "Qm")
|
|
||||||
*/
|
|
||||||
export async function getIPFSHash(str: string) {
|
|
||||||
const file = new UnixFS({
|
|
||||||
type: "file",
|
|
||||||
data: Buffer.from(str),
|
|
||||||
});
|
|
||||||
const node = new DAGNode(file.marshal());
|
|
||||||
const metadataLink = await node.toDAGLink();
|
|
||||||
return toB58String(metadataLink.Hash.multihash);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the IPFS hash from the given bytecode
|
|
||||||
* @param bytecode
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
export function extractIPFSHashFromBytecode(
|
|
||||||
bytecode: string,
|
|
||||||
): string | undefined {
|
|
||||||
const numericBytecode = hexToBytes(bytecode);
|
|
||||||
const cborLength: number =
|
|
||||||
numericBytecode[numericBytecode.length - 2] * 0x100 +
|
|
||||||
numericBytecode[numericBytecode.length - 1];
|
|
||||||
const bytecodeBuffer = Buffer.from(
|
|
||||||
numericBytecode.slice(numericBytecode.length - 2 - cborLength, -2),
|
|
||||||
);
|
|
||||||
const cborData = decodeFirstSync(bytecodeBuffer);
|
|
||||||
if (cborData["ipfs"]) {
|
|
||||||
const uri = toB58String(cborData["ipfs"]);
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hexToBytes(hex: string | number) {
|
|
||||||
hex = hex.toString(16);
|
|
||||||
if (!hex.startsWith("0x")) {
|
|
||||||
hex = `0x${hex}`;
|
|
||||||
}
|
|
||||||
if (!isHexStrict(hex)) {
|
|
||||||
throw new Error('Given value "' + hex + '" is not a valid hex string.');
|
|
||||||
}
|
|
||||||
|
|
||||||
hex = hex.replace(/^0x/i, "");
|
|
||||||
|
|
||||||
for (var bytes = [], c = 0; c < hex.length; c += 2) {
|
|
||||||
bytes.push(parseInt(hex.slice(c, c + 2), 16));
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isHexStrict(hex: string | number) {
|
|
||||||
return (
|
|
||||||
(typeof hex === "string" || typeof hex === "number") &&
|
|
||||||
/^(-)?0x[0-9a-f]*$/i.test(hex.toString())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -17,9 +17,9 @@ let language: string = "";
|
|||||||
let baseContract: string = "";
|
let baseContract: string = "";
|
||||||
/* let createType: string = "app"; */
|
/* let createType: string = "app"; */
|
||||||
|
|
||||||
export async function twCreate(options: any) {
|
export async function twCreate(pPath: string = "", options: any) {
|
||||||
if (typeof projectPath === "string") {
|
if (typeof pPath === "string") {
|
||||||
projectPath = projectPath.trim();
|
projectPath = pPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.app) {
|
if (options.app) {
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ module.exports = {
|
|||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
"@typescript-eslint/no-non-null-assertion": "error",
|
"@typescript-eslint/no-non-null-assertion": "error",
|
||||||
"@typescript-eslint/no-parameter-properties": "error",
|
"@typescript-eslint/no-parameter-properties": "error",
|
||||||
"@typescript-eslint/no-unused-vars": "warn",
|
// making this an error going forward
|
||||||
|
"@typescript-eslint/no-unused-vars": "error",
|
||||||
|
|
||||||
// import rules
|
// import rules
|
||||||
"import/first": "error",
|
"import/first": "error",
|
||||||
|
|||||||
@@ -1,5 +1,106 @@
|
|||||||
# @thirdweb-dev/react
|
# @thirdweb-dev/react
|
||||||
|
|
||||||
|
## 3.4.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#356](https://github.com/thirdweb-dev/js/pull/356) [`cc4613b`](https://github.com/thirdweb-dev/js/commit/cc4613b5fd69840f4f9cfd0ac1c4e6743e62fe52) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add Pack and Multiwrap as NFTContract types
|
||||||
|
|
||||||
|
## 3.4.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#353](https://github.com/thirdweb-dev/js/pull/353) [`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useUpdateCreators hook, fix CreatorInput schema
|
||||||
|
|
||||||
|
## 3.4.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#348](https://github.com/thirdweb-dev/js/pull/348) [`7d9a4c6`](https://github.com/thirdweb-dev/js/commit/7d9a4c6abcad1b4f43e431ce7b0b38db9016ea9a) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - [SOL] - add `useUpdateRoyaltySettings()` hook
|
||||||
|
[SOL] - change `useRoyalty()` hook -> `useRoyaltySettings()` for consistency
|
||||||
|
|
||||||
|
- [#352](https://github.com/thirdweb-dev/js/pull/352) [`3522917`](https://github.com/thirdweb-dev/js/commit/352291791ee900e1500f84f095290497934d2f60) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - expose useExecuteAuctionSale and useAcceptDirectListingOffer
|
||||||
|
|
||||||
|
- [#351](https://github.com/thirdweb-dev/js/pull/351) [`aabbb14`](https://github.com/thirdweb-dev/js/commit/aabbb149e81d6824015a4797b2b6c929ca359545) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - fix wallet connection during dev (hot reload)
|
||||||
|
|
||||||
|
## 3.4.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#343](https://github.com/thirdweb-dev/js/pull/343) [`72227b2`](https://github.com/thirdweb-dev/js/commit/72227b2e166a3a68bbb41cf2b389322f5b7547a2) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose new useOffers and useMakeOffer hooks
|
||||||
|
|
||||||
|
## 3.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - Gnosis Safe and Magic Link connectors are no longer included in the default export. They are now available as named exports instead.
|
||||||
|
|
||||||
|
## Gnosis Safe
|
||||||
|
|
||||||
|
### Connector
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { GnosisSafeConnector } from "@thirdweb-dev/react";
|
||||||
|
+ import { GnosisSafeConnector } from "@thirdweb-dev/react/evm/connectors/gnosis-safe";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hook
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { useGnosis } from "@thirdweb-dev/react";
|
||||||
|
+ import { useGnosis } from "@thirdweb-dev/react/evm/connectors/gnosis-safe";
|
||||||
|
```
|
||||||
|
|
||||||
|
## Magic Link
|
||||||
|
|
||||||
|
### Connector
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { MagicLink } from "@thirdweb-dev/react";
|
||||||
|
+ import { MagicConnector } from "@thirdweb-dev/react/evm/connectors/magic";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hook
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { useMagic } from "@thirdweb-dev/react";
|
||||||
|
+ import { useMagic } from "@thirdweb-dev/react/evm/connectors/magic";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#339](https://github.com/thirdweb-dev/js/pull/339) [`b03a902`](https://github.com/thirdweb-dev/js/commit/b03a9021451b79f802f682f66e5ae8e9355d7e6f) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Fix docs for some functions
|
||||||
|
|
||||||
|
## 3.3.1
|
||||||
|
|
||||||
|
## 3.3.0
|
||||||
|
|
||||||
|
## 3.2.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#316](https://github.com/thirdweb-dev/js/pull/316) [`6ae5266`](https://github.com/thirdweb-dev/js/commit/6ae52664e5865564cd4fc2e00e3120675b9e0ca3) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix SIWE when using an external signer
|
||||||
|
|
||||||
|
- [#310](https://github.com/thirdweb-dev/js/pull/310) [`9727502`](https://github.com/thirdweb-dev/js/commit/9727502eb30ac139382b7c7c8e8fc0967cbfbcf1) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - [SOL] - add useMintNFTSupply hook in react and accomodate inputs for it in SDK
|
||||||
|
|
||||||
|
- [#319](https://github.com/thirdweb-dev/js/pull/319) [`2f8ec89`](https://github.com/thirdweb-dev/js/commit/2f8ec89c4c83ae577092c840c198e6fcfb114e69) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose total claimed and unclaimed supply for erc721 drop contracts
|
||||||
|
|
||||||
|
- [#318](https://github.com/thirdweb-dev/js/pull/318) [`bb1b4e6`](https://github.com/thirdweb-dev/js/commit/bb1b4e6ac39d98cc68b8e31e659cd68be3a5b967) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useMinimumNextBid hook and change invariant for other marketplace hooks
|
||||||
|
|
||||||
|
## 3.2.5
|
||||||
|
|
||||||
|
## 3.2.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#301](https://github.com/thirdweb-dev/js/pull/301) [`86f0cef`](https://github.com/thirdweb-dev/js/commit/86f0ceff46f72df8ebd81f843e3c66a245f23992) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Remove useAddress hook for now
|
||||||
|
|
||||||
|
## 3.2.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#299](https://github.com/thirdweb-dev/js/pull/299) [`b1218cb`](https://github.com/thirdweb-dev/js/commit/b1218cbd7d97ca7949d94a7e4ab93fef4ffbacd5) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Recreate SDK on wallet changes for hook propagation
|
||||||
|
|
||||||
## 3.2.2
|
## 3.2.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ The `useContractCall` hook to call a smart contract function has been renamed to
|
|||||||
|
|
||||||
### Prebuilt Contract Hooks
|
### Prebuilt Contract Hooks
|
||||||
|
|
||||||
Hooks to connect to prebuilt contracts such as `useNFTDrop` and `useMarketplace` are now deprecated in favour of using the generic `useContract` hook:
|
Hooks to connect to prebuilt contracts such as `useNFTDrop` and `useMarketplace` are now deprecated in favour of using the generic `useContract` hook followed by the contract type:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
- const contract = useNFTDrop("0x...")
|
- const contract = useNFTDrop("0x...")
|
||||||
+ const { contract } = useContract("0x...")
|
+ const { contract } = useContract("0x...", "nft-drop")
|
||||||
```
|
```
|
||||||
|
|
||||||
You can currently still continue to use the prebuilt hooks, however they provide a warning in the console informing you of their deprecation. We will likely remove these hooks in a future version of the SDK.
|
You can currently still continue to use the prebuilt hooks, however they provide a warning in the console informing you of their deprecation. We will likely remove these hooks in a future version of the SDK.
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export default function Home() {
|
|||||||
<div>
|
<div>
|
||||||
{nfts.map((nft) => (
|
{nfts.map((nft) => (
|
||||||
<ThirdwebNftMedia
|
<ThirdwebNftMedia
|
||||||
key={nft.tokenId}
|
key={nft.metadata.id}
|
||||||
metadata={nft.metadata}
|
metadata={nft.metadata}
|
||||||
height={200}
|
height={200}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"main": "dist/thirdweb-dev-react-evm-connectors-gnosis-safe.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-react-evm-connectors-gnosis-safe.esm.js"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"main": "dist/thirdweb-dev-react-evm-connectors-magic.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-react-evm-connectors-magic.esm.js"
|
||||||
|
}
|
||||||
+19
-18
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react",
|
"name": "@thirdweb-dev/react",
|
||||||
"version": "3.2.2",
|
"version": "3.4.4",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
@@ -20,6 +20,14 @@
|
|||||||
"module": "./solana/dist/thirdweb-dev-react-solana.esm.js",
|
"module": "./solana/dist/thirdweb-dev-react-solana.esm.js",
|
||||||
"default": "./solana/dist/thirdweb-dev-react-solana.cjs.js"
|
"default": "./solana/dist/thirdweb-dev-react-solana.cjs.js"
|
||||||
},
|
},
|
||||||
|
"./evm/connectors/magic": {
|
||||||
|
"module": "./evm/connectors/magic/dist/thirdweb-dev-react-evm-connectors-magic.esm.js",
|
||||||
|
"default": "./evm/connectors/magic/dist/thirdweb-dev-react-evm-connectors-magic.cjs.js"
|
||||||
|
},
|
||||||
|
"./evm/connectors/gnosis-safe": {
|
||||||
|
"module": "./evm/connectors/gnosis-safe/dist/thirdweb-dev-react-evm-connectors-gnosis-safe.esm.js",
|
||||||
|
"default": "./evm/connectors/gnosis-safe/dist/thirdweb-dev-react-evm-connectors-gnosis-safe.cjs.js"
|
||||||
|
},
|
||||||
"./package.json": "./package.json"
|
"./package.json": "./package.json"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -31,7 +39,8 @@
|
|||||||
"entrypoints": [
|
"entrypoints": [
|
||||||
"index.ts",
|
"index.ts",
|
||||||
"solana/index.ts",
|
"solana/index.ts",
|
||||||
"evm/index.ts"
|
"evm/index.ts",
|
||||||
|
"evm/connectors/**.ts"
|
||||||
],
|
],
|
||||||
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
|
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
|
||||||
"exports": true
|
"exports": true
|
||||||
@@ -49,8 +58,6 @@
|
|||||||
"generate-docs:solana": "api-extractor run --local --config ./config/api-extractor-solana.json && api-documenter markdown -i ./temp -o ./docs/solana && rm -rf ./temp-solana && mv ./temp ./temp-solana",
|
"generate-docs:solana": "api-extractor run --local --config ./config/api-extractor-solana.json && api-documenter markdown -i ./temp -o ./docs/solana && rm -rf ./temp-solana && mv ./temp ./temp-solana",
|
||||||
"generate-snippets": "node ./scripts/generate-snippets-evm.mjs && node ./scripts/generate-snippets-solana.mjs && node ./scripts/generate-feature-snippets-evm.mjs",
|
"generate-snippets": "node ./scripts/generate-snippets-evm.mjs && node ./scripts/generate-snippets-solana.mjs && node ./scripts/generate-feature-snippets-evm.mjs",
|
||||||
"build": "tsc && preconstruct build",
|
"build": "tsc && preconstruct build",
|
||||||
"e2e": "yarn test-ct",
|
|
||||||
"test-ct": "playwright test -c playwright-ct.config.ts",
|
|
||||||
"push": "yalc push"
|
"push": "yalc push"
|
||||||
},
|
},
|
||||||
"sideEffects:": false,
|
"sideEffects:": false,
|
||||||
@@ -63,15 +70,11 @@
|
|||||||
"@microsoft/api-documenter": "^7.19.4",
|
"@microsoft/api-documenter": "^7.19.4",
|
||||||
"@microsoft/api-extractor": "^7.29.2",
|
"@microsoft/api-extractor": "^7.29.2",
|
||||||
"@microsoft/tsdoc": "^0.14.1",
|
"@microsoft/tsdoc": "^0.14.1",
|
||||||
"@playwright/experimental-ct-react": "1.25.1",
|
|
||||||
"@playwright/test": "1.25.1",
|
|
||||||
"@preconstruct/cli": "^2.2.1",
|
"@preconstruct/cli": "^2.2.1",
|
||||||
"@solana/wallet-adapter-base": "^0.9.17",
|
"@solana/wallet-adapter-base": "^0.9.17",
|
||||||
"@solana/wallet-adapter-react": "^0.15.19",
|
"@solana/wallet-adapter-react": "^0.15.19",
|
||||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
"@solana/web3.js": "^1.62.0",
|
||||||
"@solana/web3.js": "^1.63.0",
|
|
||||||
"@thirdweb-dev/sdk": "*",
|
"@thirdweb-dev/sdk": "*",
|
||||||
"@thirdweb-dev/solana": "*",
|
|
||||||
"@types/color": "^3.0.3",
|
"@types/color": "^3.0.3",
|
||||||
"@types/mime": "^3.0.1",
|
"@types/mime": "^3.0.1",
|
||||||
"@types/react": "^18.0.5",
|
"@types/react": "^18.0.5",
|
||||||
@@ -93,13 +96,14 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.10.0",
|
"@emotion/react": "^11.10.0",
|
||||||
"@emotion/styled": "^11.10.0",
|
"@emotion/styled": "^11.10.0",
|
||||||
"@gnosis.pm/safe-core-sdk": "2.1.0",
|
"@gnosis.pm/safe-core-sdk": "^3.1.1",
|
||||||
"@gnosis.pm/safe-ethers-adapters": "0.1.0-alpha.9",
|
"@gnosis.pm/safe-ethers-adapters": "0.1.0-alpha.11",
|
||||||
"@gnosis.pm/safe-ethers-lib": "1.1.0",
|
"@gnosis.pm/safe-ethers-lib": "^1.6.1",
|
||||||
"@react-icons/all-files": "^4.1.0",
|
"@react-icons/all-files": "^4.1.0",
|
||||||
|
"@solana/wallet-adapter-phantom": "^0.9.17",
|
||||||
"@tanstack/react-query": "^4.0.10",
|
"@tanstack/react-query": "^4.0.10",
|
||||||
"@zag-js/menu": "0.1.14",
|
"@zag-js/menu": "^0.1.16",
|
||||||
"@zag-js/react": "0.1.16",
|
"@zag-js/react": "^0.1.18",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
"copy-to-clipboard": "^3.3.2",
|
"copy-to-clipboard": "^3.3.2",
|
||||||
@@ -114,7 +118,7 @@
|
|||||||
"@solana/wallet-adapter-base": "^0.9.17",
|
"@solana/wallet-adapter-base": "^0.9.17",
|
||||||
"@solana/wallet-adapter-react": "^0.15.19",
|
"@solana/wallet-adapter-react": "^0.15.19",
|
||||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
"@solana/wallet-adapter-wallets": "^0.19.0",
|
||||||
"@solana/web3.js": "^1.63.0",
|
"@solana/web3.js": "^1.62.0",
|
||||||
"@thirdweb-dev/sdk": "*",
|
"@thirdweb-dev/sdk": "*",
|
||||||
"ethers": ">=5.5.1",
|
"ethers": ">=5.5.1",
|
||||||
"react": ">=18.0.0",
|
"react": ">=18.0.0",
|
||||||
@@ -136,9 +140,6 @@
|
|||||||
},
|
},
|
||||||
"@solana/web3.js": {
|
"@solana/web3.js": {
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
|
||||||
"@thirdweb-dev/solana": {
|
|
||||||
"optional": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
import type { PlaywrightTestConfig } from "@playwright/experimental-ct-react";
|
|
||||||
import { devices } from "@playwright/experimental-ct-react";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See https://playwright.dev/docs/test-configuration.
|
|
||||||
*/
|
|
||||||
const config: PlaywrightTestConfig = {
|
|
||||||
testDir: "./",
|
|
||||||
/* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
|
|
||||||
snapshotDir: "./__snapshots__",
|
|
||||||
/* Maximum time one test can run for. */
|
|
||||||
timeout: 10 * 1000,
|
|
||||||
/* Run tests in files in parallel */
|
|
||||||
fullyParallel: true,
|
|
||||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
||||||
forbidOnly: !!process.env.CI,
|
|
||||||
/* Retry on CI only */
|
|
||||||
retries: process.env.CI ? 2 : 0,
|
|
||||||
/* Opt out of parallel tests on CI. */
|
|
||||||
// workers: process.env.CI ? 1 : undefined,
|
|
||||||
// we can use parallel tests because we have more cores now
|
|
||||||
workers: undefined,
|
|
||||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
||||||
reporter: "html",
|
|
||||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
||||||
use: {
|
|
||||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
||||||
trace: "on-first-retry",
|
|
||||||
|
|
||||||
/* Port to use for Playwright component endpoint. */
|
|
||||||
ctPort: 3100,
|
|
||||||
},
|
|
||||||
|
|
||||||
/* Configure projects for major browsers */
|
|
||||||
projects: [
|
|
||||||
{
|
|
||||||
name: "chromium",
|
|
||||||
use: {
|
|
||||||
...devices["Desktop Chrome"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "firefox",
|
|
||||||
use: {
|
|
||||||
...devices["Desktop Firefox"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "webkit",
|
|
||||||
use: {
|
|
||||||
...devices["Desktop Safari"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
export default config;
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// Import styles, initialize component theme here.
|
|
||||||
// import '../src/common.css';
|
|
||||||
|
|
||||||
export {};
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../types/shared";
|
import { RequiredParam } from "./required-param";
|
||||||
import type { QueryKey } from "@tanstack/react-query";
|
import type { QueryKey } from "@tanstack/react-query";
|
||||||
import type { ValidContractInstance } from "@thirdweb-dev/sdk";
|
import type { ValidContractInstance } from "@thirdweb-dev/sdk";
|
||||||
import type {
|
import type {
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a parameter required to be passed, but still allowes it to be null or undefined.
|
||||||
|
*
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export type RequiredParam<T> = T | null | undefined;
|
||||||
|
|
||||||
|
export function requiredParamInvariant<TValue>(
|
||||||
|
condition: RequiredParam<TValue>,
|
||||||
|
message?: string,
|
||||||
|
): asserts condition {
|
||||||
|
invariant(condition !== null || condition !== undefined, message);
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
/**
|
|
||||||
* Makes a parameter required to be passed, but still allowes it to be null or undefined.
|
|
||||||
*
|
|
||||||
* @beta
|
|
||||||
*/
|
|
||||||
export type RequiredParam<T> = T | null | undefined;
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { ConnectWallet } from ".";
|
|
||||||
import { ThirdwebProvider } from "../../providers/full";
|
|
||||||
import { test, expect } from "@playwright/experimental-ct-react";
|
|
||||||
|
|
||||||
test.use({ viewport: { width: 500, height: 500 } });
|
|
||||||
|
|
||||||
test("should render the connect wallet button", async ({ mount }) => {
|
|
||||||
const component = await mount(
|
|
||||||
<ThirdwebProvider desiredChainId={1}>
|
|
||||||
<ConnectWallet />
|
|
||||||
</ThirdwebProvider>,
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(component).toContainText("Connect Wallet");
|
|
||||||
});
|
|
||||||
@@ -144,7 +144,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
|||||||
},
|
},
|
||||||
connect,
|
connect,
|
||||||
] = useConnect();
|
] = useConnect();
|
||||||
const disconnect = useDisconnect({ reconnectAfterGnosis: false });
|
const disconnect = useDisconnect({ reconnectPrevious: false });
|
||||||
|
|
||||||
const supportedConnectors = connectors.filter((c) =>
|
const supportedConnectors = connectors.filter((c) =>
|
||||||
SUPPORTED_CONNECTORS.includes(c.id as typeof SUPPORTED_CONNECTORS[number]),
|
SUPPORTED_CONNECTORS.includes(c.id as typeof SUPPORTED_CONNECTORS[number]),
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ export interface ThirdwebNftMediaProps extends SharedMediaProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This component can be used to render NFTs from the thirdweb SDK.
|
||||||
|
* Props: {@link ThirdwebNftMediaProps}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```jsx
|
* ```jsx
|
||||||
* import { ThirdwebNftMedia, useNFTCollection, useNFT } from "@thirdweb-dev/react";
|
* import { ThirdwebNftMedia, useContract, useNFT } from "@thirdweb-dev/react";
|
||||||
* export default function NFTCollectionRender() {
|
* export default function NFTCollectionRender() {
|
||||||
* const contract = useNFTCollection(<your-contract-address>);
|
* const { contract } = useContract(<your-contract-address>);
|
||||||
* const { data: nft, isLoading } = useNFT(contract, 0);
|
* const { data: nft, isLoading } = useNFT(contract, 0);
|
||||||
*
|
*
|
||||||
* return (
|
* return (
|
||||||
@@ -32,11 +34,6 @@ export interface ThirdwebNftMediaProps extends SharedMediaProps {
|
|||||||
* );
|
* );
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*
|
|
||||||
* Use this to get the primary sales recipient of your {@link SmartContract}
|
|
||||||
* @param contract - an instance of a {@link SmartContract}
|
|
||||||
* @returns the wallet address of the primary sales recipient
|
|
||||||
* @beta
|
|
||||||
*/
|
*/
|
||||||
export const ThirdwebNftMedia = React.forwardRef<
|
export const ThirdwebNftMedia = React.forwardRef<
|
||||||
HTMLMediaElement,
|
HTMLMediaElement,
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { Web3Button } from ".";
|
|
||||||
import { ThirdwebProvider } from "../../providers/full";
|
|
||||||
import { test, expect } from "@playwright/experimental-ct-react";
|
|
||||||
|
|
||||||
test.use({ viewport: { width: 500, height: 500 } });
|
|
||||||
|
|
||||||
test("should render the connect wallet button", async ({ mount }) => {
|
|
||||||
const component = await mount(
|
|
||||||
<ThirdwebProvider desiredChainId={1}>
|
|
||||||
<Web3Button contractAddress="0x123" action={() => undefined}>
|
|
||||||
Do the thing
|
|
||||||
</Web3Button>
|
|
||||||
</ThirdwebProvider>,
|
|
||||||
);
|
|
||||||
await expect(component).toContainText("Connect Wallet");
|
|
||||||
});
|
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
import { ChainId } from "@thirdweb-dev/sdk";
|
import { useConnect } from "../hooks/wagmi-required/useConnect";
|
||||||
import { Signer, ethers, utils } from "ethers";
|
import { Signer, ethers, utils } from "ethers";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { Chain, Connector, ConnectorData, normalizeChainId } from "wagmi";
|
import {
|
||||||
|
Chain,
|
||||||
|
Connector,
|
||||||
|
ConnectorData,
|
||||||
|
normalizeChainId,
|
||||||
|
useContext as useWagmiContext,
|
||||||
|
} from "wagmi";
|
||||||
|
|
||||||
const CHAIN_ID_TO_GNOSIS_SERVER_URL = {
|
const CHAIN_ID_TO_GNOSIS_SERVER_URL = {
|
||||||
[ChainId.Mainnet]: "https://safe-transaction.mainnet.gnosis.io",
|
// mainnet
|
||||||
[ChainId.Avalanche]: "https://safe-transaction.avalanche.gnosis.io",
|
1: "https://safe-transaction.mainnet.gnosis.io",
|
||||||
[ChainId.Polygon]: "https://safe-transaction.polygon.gnosis.io",
|
// avalanche
|
||||||
[ChainId.Goerli]: "https://safe-transaction.goerli.gnosis.io",
|
43114: "https://safe-transaction.avalanche.gnosis.io",
|
||||||
|
// polygon
|
||||||
|
137: "https://safe-transaction.polygon.gnosis.io",
|
||||||
|
// goerli
|
||||||
|
5: "https://safe-transaction.goerli.gnosis.io",
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface GnosisConnectorArguments {
|
export interface GnosisConnectorArguments {
|
||||||
@@ -163,3 +173,67 @@ export class GnosisSafeConnector extends Connector {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for connecting to a Gnosis Safe. This enables multisig wallets to connect to your application and sing transactions.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* import { useGnosis } from "@thirdweb-dev/react"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* import { useGnosis } from "@thirdweb-dev/react"
|
||||||
|
*
|
||||||
|
* const App = () => {
|
||||||
|
* const connectWithGnosis = useGnosis()
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button onClick={() => connectWithGnosis({ safeAddress: "0x...", safeChainId: 1 })}>
|
||||||
|
* Connect Gnosis Safe
|
||||||
|
* </button>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @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");
|
||||||
|
}
|
||||||
|
const connector = connectors.data.connectors.find((c) => c.id === "gnosis");
|
||||||
|
invariant(
|
||||||
|
connector,
|
||||||
|
"Gnosis connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
||||||
|
);
|
||||||
|
|
||||||
|
return async (config: GnosisConnectorArguments) => {
|
||||||
|
const previousConnector = connectors.data.connector;
|
||||||
|
const previousConnectorChain = await previousConnector?.getChainId();
|
||||||
|
invariant(
|
||||||
|
!!previousConnector,
|
||||||
|
"Cannot connect to Gnosis Safe without first being connected to a personal wallet.",
|
||||||
|
);
|
||||||
|
invariant(
|
||||||
|
previousConnectorChain === config.safeChainId,
|
||||||
|
"Gnosis safe chain id must match personal wallet chain id.",
|
||||||
|
);
|
||||||
|
invariant(
|
||||||
|
utils.isAddress(config.safeAddress),
|
||||||
|
"Gnosis safe address must be a valid address.",
|
||||||
|
);
|
||||||
|
(connector as GnosisSafeConnector).setConfiguration(
|
||||||
|
previousConnector,
|
||||||
|
config,
|
||||||
|
);
|
||||||
|
return connect(connector);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useConnect } from "../hooks/wagmi-required/useConnect";
|
||||||
import { providers, utils } from "ethers";
|
import { providers, utils } from "ethers";
|
||||||
import type {
|
import type {
|
||||||
LoginWithMagicLinkConfiguration,
|
LoginWithMagicLinkConfiguration,
|
||||||
@@ -5,7 +6,12 @@ import type {
|
|||||||
MagicSDKAdditionalConfiguration,
|
MagicSDKAdditionalConfiguration,
|
||||||
} from "magic-sdk";
|
} from "magic-sdk";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { Chain, Connector, normalizeChainId } from "wagmi";
|
import {
|
||||||
|
Chain,
|
||||||
|
Connector,
|
||||||
|
normalizeChainId,
|
||||||
|
useContext as useWagmiContext,
|
||||||
|
} from "wagmi";
|
||||||
|
|
||||||
export interface MagicConnectorArguments
|
export interface MagicConnectorArguments
|
||||||
extends MagicSDKAdditionalConfiguration {
|
extends MagicSDKAdditionalConfiguration {
|
||||||
@@ -186,3 +192,89 @@ export class MagicConnector extends Connector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for connecting to an email wallet using magic link.
|
||||||
|
* This enables users without their own wallets to connect to your application and sign transactions securely using their email.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* import { useMagic } from "@thirdweb-dev/react"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Before using this hook, you first need to set up the magic configuration in your `ThirdwebProvider`, including your magic API key.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* // Add the magic configuration object to your wallet connectors
|
||||||
|
* const connectors = [
|
||||||
|
* "metamask",
|
||||||
|
* "walletConnect",
|
||||||
|
* "walletLink",
|
||||||
|
* {
|
||||||
|
* name: "magic",
|
||||||
|
* options: {
|
||||||
|
* apiKey: "your-magic-api-key",
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* // Add the above to the walletConnectors prop of your <ThirdwebProvider />
|
||||||
|
* const Provider = ({ children }) => (
|
||||||
|
* return (
|
||||||
|
* <ThirdwebProvider
|
||||||
|
* walletConnectors={connectors}
|
||||||
|
* // Specify remaining parameters
|
||||||
|
* ...
|
||||||
|
* >
|
||||||
|
* {children}
|
||||||
|
* </ThirdwebProvider>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* In order to use the hook to connect users with magic link, you just need to provide the users email to the connect function.
|
||||||
|
*
|
||||||
|
* You can setup the hook with the following configuration:
|
||||||
|
* ```javascript
|
||||||
|
* import { useMagic } from "@thirdweb-dev/react"
|
||||||
|
* import { useState } from "react"
|
||||||
|
*
|
||||||
|
* const LoginWithMagicLink = () => {
|
||||||
|
* const connectWithMagic = useMagic()
|
||||||
|
* const [email, setEmail] = useState()
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <div>
|
||||||
|
* <input value={email} onChange={(e) => setEmail(e.target.value)} />
|
||||||
|
* <button onClick={() => connectWithMagic({ email })}>Login</button>
|
||||||
|
* </div>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @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");
|
||||||
|
}
|
||||||
|
|
||||||
|
const connector = connectors.data.connectors.find((c) => c.id === "magic");
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
connector,
|
||||||
|
"Magic connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
||||||
|
);
|
||||||
|
|
||||||
|
return (configuration: LoginWithMagicLinkConfiguration) => {
|
||||||
|
(connector as MagicConnector).setConfiguration(configuration);
|
||||||
|
return connect(connector);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
SupportedChainId,
|
SupportedChainId,
|
||||||
defaultSupportedChains,
|
defaultSupportedChains,
|
||||||
} from "../constants/chain";
|
} from "../constants/chain";
|
||||||
import { ChainId } from "@thirdweb-dev/sdk";
|
import { DEFAULT_RPC_URLS } from "@thirdweb-dev/sdk";
|
||||||
import React, { PropsWithChildren, createContext, useContext } from "react";
|
import React, { PropsWithChildren, createContext, useContext } from "react";
|
||||||
|
|
||||||
interface ThirdwebConfigContext {
|
interface ThirdwebConfigContext {
|
||||||
@@ -11,17 +11,8 @@ interface ThirdwebConfigContext {
|
|||||||
supportedChains: Chain[];
|
supportedChains: Chain[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultChainRpc: Record<SupportedChainId | number, string> = {
|
|
||||||
[ChainId.Mainnet]: "mainnet",
|
|
||||||
[ChainId.Goerli]: "goerli",
|
|
||||||
[ChainId.Polygon]: "polygon",
|
|
||||||
[ChainId.Mumbai]: "mumbai",
|
|
||||||
[ChainId.Fantom]: "fantom",
|
|
||||||
[ChainId.Avalanche]: "avalanche",
|
|
||||||
};
|
|
||||||
|
|
||||||
const ThirdwebConfigContext = createContext<ThirdwebConfigContext>({
|
const ThirdwebConfigContext = createContext<ThirdwebConfigContext>({
|
||||||
rpcUrlMap: defaultChainRpc,
|
rpcUrlMap: DEFAULT_RPC_URLS,
|
||||||
supportedChains: defaultSupportedChains,
|
supportedChains: defaultSupportedChains,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,17 @@ export const ThirdwebConnectedWalletProvider: React.FC<
|
|||||||
const { rpcUrlMap } = useThirdwebConfigContext();
|
const { rpcUrlMap } = useThirdwebConfigContext();
|
||||||
|
|
||||||
const [contextValue, setContextValue] =
|
const [contextValue, setContextValue] =
|
||||||
useState<ThirdwebConnectedWalletContext>(INITIAL_CONTEXT_VALUE);
|
useState<ThirdwebConnectedWalletContext>({
|
||||||
|
...INITIAL_CONTEXT_VALUE,
|
||||||
|
signer: signer ? signer : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setContextValue((val) => ({
|
||||||
|
...val,
|
||||||
|
signer: signer ? signer : undefined,
|
||||||
|
}));
|
||||||
|
}, [signer]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let s = signer;
|
let s = signer;
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
RequiredParam,
|
||||||
|
requiredParamInvariant,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import { getErcs, DropContract, WalletAddress } from "../../types";
|
import { getErcs, DropContract, WalletAddress } from "../../types";
|
||||||
import {
|
import {
|
||||||
@@ -7,7 +10,11 @@ import {
|
|||||||
} from "../../utils/cache-keys";
|
} from "../../utils/cache-keys";
|
||||||
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { ClaimCondition, ClaimConditionInput } from "@thirdweb-dev/sdk";
|
import {
|
||||||
|
ClaimCondition,
|
||||||
|
ClaimConditionFetchOptions,
|
||||||
|
ClaimConditionInput,
|
||||||
|
} from "@thirdweb-dev/sdk";
|
||||||
import { BigNumberish } from "ethers";
|
import { BigNumberish } from "ethers";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
@@ -62,25 +69,30 @@ export type SetClaimConditionsParams = {
|
|||||||
export function useActiveClaimCondition(
|
export function useActiveClaimCondition(
|
||||||
contract: RequiredParam<DropContract>,
|
contract: RequiredParam<DropContract>,
|
||||||
tokenId?: BigNumberish,
|
tokenId?: BigNumberish,
|
||||||
|
options?: ClaimConditionFetchOptions,
|
||||||
) {
|
) {
|
||||||
const contractAddress = contract?.getAddress();
|
const contractAddress = contract?.getAddress();
|
||||||
const { erc1155, erc721, erc20 } = getErcs(contract);
|
const { erc1155, erc721, erc20 } = getErcs(contract);
|
||||||
|
|
||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.extensions.claimConditions.getActive(contractAddress, tokenId),
|
cacheKeys.extensions.claimConditions.getActive(
|
||||||
|
contractAddress,
|
||||||
|
tokenId,
|
||||||
|
options,
|
||||||
|
),
|
||||||
() => {
|
() => {
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(
|
requiredParamInvariant(
|
||||||
tokenId !== undefined,
|
tokenId,
|
||||||
"tokenId is required for ERC1155 claim conditions",
|
"tokenId is required for ERC1155 claim conditions",
|
||||||
);
|
);
|
||||||
return erc1155.claimConditions.getActive(tokenId);
|
return erc1155.claimConditions.getActive(tokenId, options);
|
||||||
}
|
}
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
return erc721.claimConditions.getActive();
|
return erc721.claimConditions.getActive(options);
|
||||||
}
|
}
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
return erc20.claimConditions.getActive();
|
return erc20.claimConditions.getActive(options);
|
||||||
}
|
}
|
||||||
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||||
},
|
},
|
||||||
@@ -118,22 +130,30 @@ export function useActiveClaimCondition(
|
|||||||
export function useClaimConditions(
|
export function useClaimConditions(
|
||||||
contract: RequiredParam<DropContract>,
|
contract: RequiredParam<DropContract>,
|
||||||
tokenId?: BigNumberish,
|
tokenId?: BigNumberish,
|
||||||
|
options?: ClaimConditionFetchOptions,
|
||||||
) {
|
) {
|
||||||
const contractAddress = contract?.getAddress();
|
const contractAddress = contract?.getAddress();
|
||||||
const { erc1155, erc721, erc20 } = getErcs(contract);
|
const { erc1155, erc721, erc20 } = getErcs(contract);
|
||||||
|
|
||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.extensions.claimConditions.getAll(contractAddress, tokenId),
|
cacheKeys.extensions.claimConditions.getAll(
|
||||||
|
contractAddress,
|
||||||
|
tokenId,
|
||||||
|
options,
|
||||||
|
),
|
||||||
() => {
|
() => {
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(tokenId, "tokenId is required for ERC1155 claim conditions");
|
requiredParamInvariant(
|
||||||
return erc1155.claimConditions.getAll(tokenId);
|
tokenId,
|
||||||
|
"tokenId is required for ERC1155 claim conditions",
|
||||||
|
);
|
||||||
|
return erc1155.claimConditions.getAll(tokenId, options);
|
||||||
}
|
}
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
return erc721.claimConditions.getAll();
|
return erc721.claimConditions.getAll(options);
|
||||||
}
|
}
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
return erc20.claimConditions.getAll();
|
return erc20.claimConditions.getAll(options);
|
||||||
}
|
}
|
||||||
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||||
},
|
},
|
||||||
@@ -184,7 +204,7 @@ export function useClaimIneligibilityReasons(
|
|||||||
),
|
),
|
||||||
() => {
|
() => {
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(
|
requiredParamInvariant(
|
||||||
tokenId,
|
tokenId,
|
||||||
"tokenId is required for ERC1155 claim ineligibility reasons",
|
"tokenId is required for ERC1155 claim ineligibility reasons",
|
||||||
);
|
);
|
||||||
@@ -270,11 +290,14 @@ export function useSetClaimConditions(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: SetClaimConditionsParams) => {
|
async (data: SetClaimConditionsParams) => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
const { phases, reset = false } = data;
|
const { phases, reset = false } = data;
|
||||||
invariant(phases, 'No "phases" provided');
|
invariant(phases, 'No "phases" provided');
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(tokenId, "tokenId is required for ERC1155 claim conditions");
|
requiredParamInvariant(
|
||||||
|
tokenId,
|
||||||
|
"tokenId is required for ERC1155 claim conditions",
|
||||||
|
);
|
||||||
return erc1155.claimConditions.set(tokenId, phases, reset);
|
return erc1155.claimConditions.set(tokenId, phases, reset);
|
||||||
}
|
}
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
@@ -341,7 +364,7 @@ export function useResetClaimConditions(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async () => {
|
async () => {
|
||||||
const cleanConditions = (conditions: ClaimCondition[]) => {
|
const cleanConditions = async (conditions: ClaimCondition[]) => {
|
||||||
return conditions.map((c) => ({
|
return conditions.map((c) => ({
|
||||||
...c,
|
...c,
|
||||||
price: c.currencyMetadata.displayValue,
|
price: c.currencyMetadata.displayValue,
|
||||||
@@ -351,25 +374,34 @@ export function useResetClaimConditions(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(tokenId, "tokenId is required for ERC1155 claim conditions");
|
requiredParamInvariant(
|
||||||
const claimConditions = await erc1155.claimConditions.getAll(tokenId);
|
tokenId,
|
||||||
|
"tokenId is required for ERC1155 claim conditions",
|
||||||
|
);
|
||||||
|
const claimConditions = await erc1155.claimConditions.getAll(tokenId, {
|
||||||
|
withAllowList: true,
|
||||||
|
});
|
||||||
return erc1155.claimConditions.set(
|
return erc1155.claimConditions.set(
|
||||||
tokenId,
|
tokenId,
|
||||||
cleanConditions(claimConditions || []),
|
await cleanConditions(claimConditions || []),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
const claimConditions = await erc721.claimConditions.getAll();
|
const claimConditions = await erc721.claimConditions.getAll({
|
||||||
|
withAllowList: true,
|
||||||
|
});
|
||||||
return await erc721.claimConditions.set(
|
return await erc721.claimConditions.set(
|
||||||
cleanConditions(claimConditions || []),
|
await cleanConditions(claimConditions || []),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
const claimConditions = await erc20.claimConditions.getAll();
|
const claimConditions = await erc20.claimConditions.getAll({
|
||||||
|
withAllowList: true,
|
||||||
|
});
|
||||||
return await erc20.claimConditions.set(
|
return await erc20.claimConditions.set(
|
||||||
cleanConditions(claimConditions || []),
|
await cleanConditions(claimConditions || []),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
RequiredParam,
|
||||||
|
requiredParamInvariant,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import { WalletAddress } from "../../types";
|
import { WalletAddress } from "../../types";
|
||||||
import {
|
import {
|
||||||
@@ -35,7 +38,7 @@ export function usePrimarySaleRecipient(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.extensions.sales.getRecipient(contractAddress),
|
cacheKeys.extensions.sales.getRecipient(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"sales" in contract && contract.sales,
|
"sales" in contract && contract.sales,
|
||||||
"Contract does not support primarySale",
|
"Contract does not support primarySale",
|
||||||
@@ -86,7 +89,7 @@ export function useUpdatePrimarySaleRecipient(
|
|||||||
const activeChainId = useSDKChainId();
|
const activeChainId = useSDKChainId();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
(newRecipient: WalletAddress) => {
|
(newRecipient: WalletAddress) => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"sales" in contract && contract.sales,
|
"sales" in contract && contract.sales,
|
||||||
"Contract does not support primarySale",
|
"Contract does not support primarySale",
|
||||||
@@ -128,7 +131,7 @@ export function useRoyaltySettings(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.extensions.royalties.getDefaultRoyaltyInfo(contractAddress),
|
cacheKeys.extensions.royalties.getDefaultRoyaltyInfo(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"royalties" in contract && contract.royalties,
|
"royalties" in contract && contract.royalties,
|
||||||
"Contract does not support royalties",
|
"Contract does not support royalties",
|
||||||
@@ -182,7 +185,7 @@ export function useUpdateRoyaltySettings(
|
|||||||
seller_fee_basis_points?: number;
|
seller_fee_basis_points?: number;
|
||||||
fee_recipient?: WalletAddress;
|
fee_recipient?: WalletAddress;
|
||||||
}) => {
|
}) => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"royalties" in contract && contract.royalties,
|
"royalties" in contract && contract.royalties,
|
||||||
"Contract does not support royalties",
|
"Contract does not support royalties",
|
||||||
@@ -224,7 +227,7 @@ export function usePlatformFees(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.extensions.platformFees.get(contractAddress),
|
cacheKeys.extensions.platformFees.get(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"platformFees" in contract && contract.platformFees,
|
"platformFees" in contract && contract.platformFees,
|
||||||
"Contract does not support platformFees",
|
"Contract does not support platformFees",
|
||||||
@@ -277,7 +280,7 @@ export function useUpdatePlatformFees(
|
|||||||
platform_fee_basis_points?: number;
|
platform_fee_basis_points?: number;
|
||||||
fee_recipient?: WalletAddress;
|
fee_recipient?: WalletAddress;
|
||||||
}) => {
|
}) => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"platformFees" in contract && contract.platformFees,
|
"platformFees" in contract && contract.platformFees,
|
||||||
"Contract does not support platformFees",
|
"Contract does not support platformFees",
|
||||||
@@ -317,7 +320,7 @@ export function useMetadata(contract: RequiredParam<ValidContractInstance>) {
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.extensions.metadata.get(contractAddress),
|
cacheKeys.extensions.metadata.get(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"metadata" in contract && contract.metadata,
|
"metadata" in contract && contract.metadata,
|
||||||
"Contract does not support metadata",
|
"Contract does not support metadata",
|
||||||
@@ -366,7 +369,7 @@ export function useUpdateMetadata(
|
|||||||
const activeChainId = useSDKChainId();
|
const activeChainId = useSDKChainId();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
(updatePayload: CustomContractMetadata) => {
|
(updatePayload: CustomContractMetadata) => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(
|
invariant(
|
||||||
"metadata" in contract && contract.metadata,
|
"metadata" in contract && contract.metadata,
|
||||||
"Contract does not support metadata",
|
"Contract does not support metadata",
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { neverPersist } from "../../../core/query-utils/query-key";
|
import { neverPersist } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
RequiredParam,
|
||||||
|
requiredParamInvariant,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDK, useSDKChainId } from "../../providers/base";
|
import { useSDK, useSDKChainId } from "../../providers/base";
|
||||||
import { ContractAddress } from "../../types";
|
import { ContractAddress } from "../../types";
|
||||||
import {
|
import {
|
||||||
@@ -216,7 +219,7 @@ export function useContract(
|
|||||||
{ wallet, walletChainId, sdkTimestamp },
|
{ wallet, walletChainId, sdkTimestamp },
|
||||||
]),
|
]),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contractAddress, "contract address is required");
|
requiredParamInvariant(contractAddress, "contract address is required");
|
||||||
invariant(sdk, "SDK not initialized");
|
invariant(sdk, "SDK not initialized");
|
||||||
invariant(activeChainId, "active chain id is required");
|
invariant(activeChainId, "active chain id is required");
|
||||||
|
|
||||||
@@ -290,7 +293,7 @@ export function useContractMetadata<TContract extends ValidContractInstance>(
|
|||||||
>(
|
>(
|
||||||
cacheKeys.contract.metadata(contract?.getAddress()),
|
cacheKeys.contract.metadata(contract?.getAddress()),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "contract is required");
|
requiredParamInvariant(contract, "contract is required");
|
||||||
return await contract.metadata.get();
|
return await contract.metadata.get();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -311,7 +314,7 @@ export function useContractMetadataUpdate(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (metadata: CommonContractSchemaInput) => {
|
async (metadata: CommonContractSchemaInput) => {
|
||||||
invariant(contract, "contract must be defined");
|
requiredParamInvariant(contract, "contract must be defined");
|
||||||
|
|
||||||
return contract.metadata.update(metadata);
|
return contract.metadata.update(metadata);
|
||||||
},
|
},
|
||||||
@@ -406,7 +409,7 @@ export function useContractEvents(
|
|||||||
return useQuery(
|
return useQuery(
|
||||||
cacheKey,
|
cacheKey,
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "contract must be defined");
|
requiredParamInvariant(contract, "contract must be defined");
|
||||||
if (eventName) {
|
if (eventName) {
|
||||||
return contract.events.getEvents(eventName, options.queryFilter);
|
return contract.events.getEvents(eventName, options.queryFilter);
|
||||||
}
|
}
|
||||||
@@ -447,8 +450,8 @@ export function useContractRead(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.call(contractAddress, functionName, args),
|
cacheKeys.contract.call(contractAddress, functionName, args),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "contract must be defined");
|
requiredParamInvariant(contract, "contract must be defined");
|
||||||
invariant(functionName, "function name must be provided");
|
requiredParamInvariant(functionName, "function name must be provided");
|
||||||
return contract.call(functionName, ...args);
|
return contract.call(functionName, ...args);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -485,8 +488,8 @@ export function useContractWrite(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (callParams?: unknown[] | [...unknown[], CallOverrides]) => {
|
async (callParams?: unknown[] | [...unknown[], CallOverrides]) => {
|
||||||
invariant(contract, "contract must be defined");
|
requiredParamInvariant(contract, "contract must be defined");
|
||||||
invariant(functionName, "function name must be provided");
|
requiredParamInvariant(functionName, "function name must be provided");
|
||||||
if (!callParams?.length) {
|
if (!callParams?.length) {
|
||||||
return contract.call(functionName);
|
return contract.call(functionName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
RequiredParam,
|
||||||
|
requiredParamInvariant,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import {
|
import {
|
||||||
ClaimNFTParams,
|
ClaimNFTParams,
|
||||||
@@ -51,7 +54,7 @@ export function useUnclaimedNFTs(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.nft.drop.getAllUnclaimed(contractAddress, queryParams),
|
cacheKeys.contract.nft.drop.getAllUnclaimed(contractAddress, queryParams),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
// TODO make this work for custom contracts (needs ABI change)
|
// TODO make this work for custom contracts (needs ABI change)
|
||||||
invariant(
|
invariant(
|
||||||
contract.getAllUnclaimed,
|
contract.getAllUnclaimed,
|
||||||
@@ -94,18 +97,18 @@ export function useClaimedNFTs(
|
|||||||
*/
|
*/
|
||||||
export function useUnclaimedNFTSupply(contract: RequiredParam<DropContract>) {
|
export function useUnclaimedNFTSupply(contract: RequiredParam<DropContract>) {
|
||||||
const contractAddress = contract?.getAddress();
|
const contractAddress = contract?.getAddress();
|
||||||
|
const { erc721 } = getErcs(contract);
|
||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.nft.drop.totalUnclaimedSupply(contractAddress),
|
cacheKeys.contract.nft.drop.totalUnclaimedSupply(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
// TODO make this work for custom contracts (needs ABI change)
|
if (erc721) {
|
||||||
invariant(
|
invariant(erc721, "No ERC721 Contract instance provided");
|
||||||
"totalUnclaimedSupply" in contract && contract.totalUnclaimedSupply,
|
return erc721.totalUnclaimedSupply();
|
||||||
"Contract instance does not support fetching unclaimed supply",
|
}
|
||||||
);
|
invariant(false, "Contract is not an instance of ERC721")
|
||||||
return contract.totalUnclaimedSupply();
|
|
||||||
},
|
},
|
||||||
{ enabled: !!contract },
|
{ enabled: !!erc721 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,18 +121,17 @@ export function useUnclaimedNFTSupply(contract: RequiredParam<DropContract>) {
|
|||||||
*/
|
*/
|
||||||
export function useClaimedNFTSupply(contract: RequiredParam<DropContract>) {
|
export function useClaimedNFTSupply(contract: RequiredParam<DropContract>) {
|
||||||
const contractAddress = contract?.getAddress();
|
const contractAddress = contract?.getAddress();
|
||||||
|
const { erc721 } = getErcs(contract);
|
||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.nft.drop.totalClaimedSupply(contractAddress),
|
cacheKeys.contract.nft.drop.totalClaimedSupply(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
// TODO make this work for custom contracts (needs ABI change)
|
if (erc721) {
|
||||||
invariant(
|
return erc721.totalClaimedSupply();
|
||||||
"totalClaimedSupply" in contract && contract.totalClaimedSupply,
|
}
|
||||||
"Contract instance does not support fetching unclaimed supply",
|
invariant(false, "Contract is not an instance of ERC721")
|
||||||
);
|
|
||||||
return contract.totalClaimedSupply();
|
|
||||||
},
|
},
|
||||||
{ enabled: !!contract },
|
{ enabled: !!erc721 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,10 +208,10 @@ export function useClaimNFT<TContract extends DropContract>(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: ClaimNFTParams) => {
|
async (data: ClaimNFTParams) => {
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
|
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(!!data.tokenId, "tokenId not provided");
|
requiredParamInvariant(data.tokenId, "tokenId not provided");
|
||||||
if (!data.to) {
|
if (!data.to) {
|
||||||
return (await erc1155.claim(
|
return (await erc1155.claim(
|
||||||
data.tokenId,
|
data.tokenId,
|
||||||
@@ -270,7 +272,7 @@ export function useLazyMint<TContract extends DropContract>(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: { metadatas: NFTMetadataInput[] }) => {
|
async (data: { metadatas: NFTMetadataInput[] }) => {
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
let options;
|
let options;
|
||||||
if (onProgress) {
|
if (onProgress) {
|
||||||
options = {
|
options = {
|
||||||
@@ -316,7 +318,7 @@ export function useDelayedRevealLazyMint<TContract extends RevealableContract>(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: DelayedRevealLazyMintInput) => {
|
async (data: DelayedRevealLazyMintInput) => {
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
let options;
|
let options;
|
||||||
if (onProgress) {
|
if (onProgress) {
|
||||||
options = {
|
options = {
|
||||||
@@ -370,7 +372,7 @@ export function useRevealLazyMint<TContract extends RevealableContract>(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: RevealLazyMintInput) => {
|
async (data: RevealLazyMintInput) => {
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
const { erc721, erc1155 } = getErcs(contract);
|
const { erc721, erc1155 } = getErcs(contract);
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
return await erc721.revealer.reveal(data.batchId, data.password);
|
return await erc721.revealer.reveal(data.batchId, data.password);
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
RequiredParam,
|
||||||
|
requiredParamInvariant,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import { BuyNowParams, MakeBidParams } from "../../types";
|
import {
|
||||||
|
AcceptDirectOffer,
|
||||||
|
BuyNowParams,
|
||||||
|
ExecuteAuctionSale,
|
||||||
|
MakeBidParams,
|
||||||
|
MakeOfferParams,
|
||||||
|
} from "../../types";
|
||||||
import {
|
import {
|
||||||
cacheKeys,
|
cacheKeys,
|
||||||
invalidateContractAndBalances,
|
invalidateContractAndBalances,
|
||||||
} from "../../utils/cache-keys";
|
} from "../../utils/cache-keys";
|
||||||
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
||||||
import { useAddress } from "../wallet";
|
import { useAddress } from "../wallet";
|
||||||
|
import { useContractEvents } from "./contracts";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type {
|
import type {
|
||||||
AuctionListing,
|
AuctionListing,
|
||||||
@@ -17,7 +27,7 @@ import type {
|
|||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
import { ListingType } from "@thirdweb-dev/sdk";
|
import { ListingType } from "@thirdweb-dev/sdk";
|
||||||
import { Marketplace } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/marketplace";
|
import { Marketplace } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/marketplace";
|
||||||
import { BigNumber, BigNumberish } from "ethers";
|
import { BigNumberish } from "ethers";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
/** **********************/
|
/** **********************/
|
||||||
@@ -45,8 +55,9 @@ export function useListing(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.marketplace.getListing(contractAddress, listingId),
|
cacheKeys.contract.marketplace.getListing(contractAddress, listingId),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
return contract.getListing(BigNumber.from(listingId || 0));
|
requiredParamInvariant(listingId, "No listing id provided");
|
||||||
|
return contract.getListing(listingId);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!contract,
|
enabled: !!contract,
|
||||||
@@ -76,7 +87,7 @@ export function useListings(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.marketplace.getAllListings(contractAddress, filter),
|
cacheKeys.contract.marketplace.getAllListings(contractAddress, filter),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
return contract.getAllListings(filter);
|
return contract.getAllListings(filter);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -103,7 +114,7 @@ export function useListingsCount(contract: RequiredParam<Marketplace>) {
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.marketplace.getTotalCount(contractAddress),
|
cacheKeys.contract.marketplace.getTotalCount(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
return contract.getTotalCount();
|
return contract.getTotalCount();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -133,7 +144,7 @@ export function useActiveListings(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.marketplace.getActiveListings(contractAddress, filter),
|
cacheKeys.contract.marketplace.getActiveListings(contractAddress, filter),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
|
||||||
return contract.getActiveListings(filter);
|
return contract.getActiveListings(filter);
|
||||||
},
|
},
|
||||||
@@ -168,8 +179,9 @@ export function useWinningBid(
|
|||||||
listingId,
|
listingId,
|
||||||
),
|
),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
return contract.auction.getWinningBid(BigNumber.from(listingId || 0));
|
requiredParamInvariant(listingId, "No listing id provided");
|
||||||
|
return contract.auction.getWinningBid(listingId);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!contract && listingId !== undefined,
|
enabled: !!contract && listingId !== undefined,
|
||||||
@@ -201,12 +213,11 @@ export function useAuctionWinner(
|
|||||||
listingId,
|
listingId,
|
||||||
),
|
),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
requiredParamInvariant(listingId, "No listing id provided");
|
||||||
let winner: string | undefined;
|
let winner: string | undefined;
|
||||||
try {
|
try {
|
||||||
winner = await contract.auction.getWinner(
|
winner = await contract.auction.getWinner(listingId);
|
||||||
BigNumber.from(listingId || 0),
|
|
||||||
);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!(err as Error)?.message?.includes("Could not find auction")) {
|
if (!(err as Error)?.message?.includes("Could not find auction")) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -238,7 +249,7 @@ export function useBidBuffer(contract: RequiredParam<Marketplace>) {
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.marketplace.getBidBufferBps(contractAddress),
|
cacheKeys.contract.marketplace.getBidBufferBps(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
return contract.getBidBufferBps();
|
return contract.getBidBufferBps();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -247,6 +258,40 @@ export function useBidBuffer(contract: RequiredParam<Marketplace>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to get the minimum next bid for the auction listing from your marketplace contract.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: minimumNextBid, isLoading, error } = useMinimumNextBid(<YourMarketplaceContractInstance>, <listingId>);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a marketplace contract
|
||||||
|
* @param listingId - the listing id to check
|
||||||
|
* @returns a response object that includes the minimum next bid for the auction listing
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useMinimumNextBid(
|
||||||
|
contract: RequiredParam<Marketplace>,
|
||||||
|
listingId: RequiredParam<BigNumberish>,
|
||||||
|
) {
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
return useQueryWithNetwork(
|
||||||
|
cacheKeys.contract.marketplace.auction.getWinner(
|
||||||
|
contractAddress,
|
||||||
|
listingId,
|
||||||
|
),
|
||||||
|
async () => {
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
requiredParamInvariant(listingId, "No listing id provided");
|
||||||
|
return await contract.auction.getMinimumNextBid(listingId);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: !!contract && listingId !== undefined,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** **********************/
|
/** **********************/
|
||||||
/** WRITE HOOKS **/
|
/** WRITE HOOKS **/
|
||||||
/** **********************/
|
/** **********************/
|
||||||
@@ -290,8 +335,9 @@ export function useCreateDirectListing(contract: RequiredParam<Marketplace>) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: NewDirectListing) => {
|
async (data: NewDirectListing) => {
|
||||||
invariant(walletAddress, "no wallet connected, cannot create listing");
|
invariant(walletAddress, "no wallet connected, cannot create listing");
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
invariant(
|
invariant(
|
||||||
contract?.direct?.createListing,
|
contract.direct.createListing,
|
||||||
"contract does not support direct.createListing",
|
"contract does not support direct.createListing",
|
||||||
);
|
);
|
||||||
return await contract.direct.createListing(data);
|
return await contract.direct.createListing(data);
|
||||||
@@ -346,8 +392,9 @@ export function useCreateAuctionListing(contract: RequiredParam<Marketplace>) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: NewAuctionListing) => {
|
async (data: NewAuctionListing) => {
|
||||||
invariant(walletAddress, "no wallet connected, cannot create listing");
|
invariant(walletAddress, "no wallet connected, cannot create listing");
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
invariant(
|
invariant(
|
||||||
contract?.direct?.createListing,
|
contract.direct.createListing,
|
||||||
"contract does not support auction.createListing",
|
"contract does not support auction.createListing",
|
||||||
);
|
);
|
||||||
return await contract.auction.createListing(data);
|
return await contract.auction.createListing(data);
|
||||||
@@ -456,8 +503,9 @@ export function useMakeBid(contract: RequiredParam<Marketplace>) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: MakeBidParams) => {
|
async (data: MakeBidParams) => {
|
||||||
invariant(walletAddress, "no wallet connected, cannot make bid");
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
invariant(
|
invariant(
|
||||||
contract?.auction?.makeBid,
|
contract.auction.makeBid,
|
||||||
"contract does not support auction.makeBid",
|
"contract does not support auction.makeBid",
|
||||||
);
|
);
|
||||||
return await contract.auction.makeBid(data.listingId, data.bid);
|
return await contract.auction.makeBid(data.listingId, data.bid);
|
||||||
@@ -473,6 +521,203 @@ export function useMakeBid(contract: RequiredParam<Marketplace>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to make an offer on direct or auction listing from your marketplace contract.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* const Component = () => {
|
||||||
|
* const {
|
||||||
|
* mutate: makeOffer,
|
||||||
|
* isLoading,
|
||||||
|
* error,
|
||||||
|
* } = useMakeOffer(">>YourMarketplaceContractInstance<<");
|
||||||
|
*
|
||||||
|
* if (error) {
|
||||||
|
* console.error("failed to make a bid", error);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* disabled={isLoading}
|
||||||
|
* onClick={() => makeOffer({ listingId: 1, pricePerToken: 0.5, quantity: 1 })}
|
||||||
|
* >
|
||||||
|
* Bid!
|
||||||
|
* </button>
|
||||||
|
* );
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @returns a mutation object that can be used to make a bid on an auction listing
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useMakeOffer(contract: RequiredParam<Marketplace>) {
|
||||||
|
const activeChainId = useSDKChainId();
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const walletAddress = useAddress();
|
||||||
|
return useMutation(
|
||||||
|
async (data: MakeOfferParams) => {
|
||||||
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
return await contract.makeOffer(
|
||||||
|
data.listingId,
|
||||||
|
data.pricePerToken,
|
||||||
|
data.quantity,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
invalidateContractAndBalances(
|
||||||
|
queryClient,
|
||||||
|
contractAddress,
|
||||||
|
activeChainId,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept an offer on a direct listing from an offeror, will accept the latest offer by the given offeror.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* const Component = () => {
|
||||||
|
* const {
|
||||||
|
* mutate: acceptOffer,
|
||||||
|
* isLoading,
|
||||||
|
* error,
|
||||||
|
* } = useAcceptDirectListingOffer(">>YourMarketplaceContractInstance<<");
|
||||||
|
*
|
||||||
|
* if (error) {
|
||||||
|
* console.error("failed to accept offer", error);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* disabled={isLoading}
|
||||||
|
* onClick={() => acceptOffer({ listingId: 1, addressOfOfferor: "0x..." })}
|
||||||
|
* >
|
||||||
|
* Accept offer
|
||||||
|
* </button>
|
||||||
|
* );
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @returns a mutation object that can be used to accept an offer on a direct listing
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useAcceptDirectListingOffer(
|
||||||
|
contract: RequiredParam<Marketplace>,
|
||||||
|
) {
|
||||||
|
const activeChainId = useSDKChainId();
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const walletAddress = useAddress();
|
||||||
|
return useMutation(
|
||||||
|
async (data: AcceptDirectOffer) => {
|
||||||
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(contract?.direct, "No Direct instance provided");
|
||||||
|
return await contract.direct.acceptOffer(
|
||||||
|
data.listingId,
|
||||||
|
data.addressOfOfferor,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
invalidateContractAndBalances(
|
||||||
|
queryClient,
|
||||||
|
contractAddress,
|
||||||
|
activeChainId,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute an auction sale. Can only be executed once the auction has ended and the auction has a winning bid.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* const Component = () => {
|
||||||
|
* const {
|
||||||
|
* mutate: executeAuctionSale,
|
||||||
|
* isLoading,
|
||||||
|
* error,
|
||||||
|
* } = useExecuteAuctionSale(">>YourMarketplaceContractInstance<<");
|
||||||
|
*
|
||||||
|
* if (error) {
|
||||||
|
* console.error("failed to execute sale", error);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* disabled={isLoading}
|
||||||
|
* onClick={() => executeAuctionSale({ listingId: 1 })}
|
||||||
|
* >
|
||||||
|
* Execute sale
|
||||||
|
* </button>
|
||||||
|
* );
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @returns a mutation object that can be used to accept an offer on a direct listing
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useExecuteAuctionSale(contract: RequiredParam<Marketplace>) {
|
||||||
|
const activeChainId = useSDKChainId();
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const walletAddress = useAddress();
|
||||||
|
return useMutation(
|
||||||
|
async (data: ExecuteAuctionSale) => {
|
||||||
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(
|
||||||
|
contract?.auction,
|
||||||
|
"No Auction marketplace instance provided",
|
||||||
|
);
|
||||||
|
return await contract.auction.executeSale(data.listingId);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
invalidateContractAndBalances(
|
||||||
|
queryClient,
|
||||||
|
contractAddress,
|
||||||
|
activeChainId,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the offers for a listing
|
||||||
|
*
|
||||||
|
* @remarks Fetch all the offers for a specified direct or auction listing.
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: offers, isLoading, error } = useOffers(<YourMarketplaceContractInstance>, <listingId>);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @param listingId - the id of the listing to fetch offers for
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useOffers(
|
||||||
|
contract: RequiredParam<Marketplace>,
|
||||||
|
listingId: RequiredParam<BigNumberish>,
|
||||||
|
) {
|
||||||
|
const result = useContractEvents(contract, "NewOffer");
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: result.data
|
||||||
|
?.filter((ev) => ev.data.listingId.eq(listingId))
|
||||||
|
?.map((ev) => ev.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this to buy out an auction listing from your marketplace contract.
|
* Use this to buy out an auction listing from your marketplace contract.
|
||||||
*
|
*
|
||||||
@@ -512,9 +757,10 @@ export function useBuyNow(contract: RequiredParam<Marketplace>) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: BuyNowParams) => {
|
async (data: BuyNowParams) => {
|
||||||
invariant(walletAddress, "no wallet connected, cannot make bid");
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
if (data.type === ListingType.Direct) {
|
if (data.type === ListingType.Direct) {
|
||||||
invariant(
|
invariant(
|
||||||
contract?.direct.buyoutListing,
|
contract.direct.buyoutListing,
|
||||||
"contract does not support direct.buyoutListing",
|
"contract does not support direct.buyoutListing",
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -525,7 +771,7 @@ export function useBuyNow(contract: RequiredParam<Marketplace>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
invariant(
|
invariant(
|
||||||
contract?.auction?.buyoutListing,
|
contract.auction.buyoutListing,
|
||||||
"contract does not support auction.buyoutListing",
|
"contract does not support auction.buyoutListing",
|
||||||
);
|
);
|
||||||
return await contract.auction.buyoutListing(data.id);
|
return await contract.auction.buyoutListing(data.id);
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import {
|
import {
|
||||||
AirdropNFTParams,
|
AirdropNFTParams,
|
||||||
@@ -50,7 +53,7 @@ export function useNFT<TContract extends NFTContract>(
|
|||||||
return useQueryWithNetwork<NFT>(
|
return useQueryWithNetwork<NFT>(
|
||||||
cacheKeys.contract.nft.get(contractAddress, tokenId),
|
cacheKeys.contract.nft.get(contractAddress, tokenId),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(erc1155.get, "Contract instance does not support get");
|
invariant(erc1155.get, "Contract instance does not support get");
|
||||||
@@ -93,7 +96,7 @@ export function useNFTs<TContract extends NFTContract>(
|
|||||||
return useQueryWithNetwork<NFT[]>(
|
return useQueryWithNetwork<NFT[]>(
|
||||||
cacheKeys.contract.nft.query.all(contractAddress, queryParams),
|
cacheKeys.contract.nft.query.all(contractAddress, queryParams),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
invariant(erc721.getAll, "Contract instance does not support getAll");
|
invariant(erc721.getAll, "Contract instance does not support getAll");
|
||||||
@@ -134,7 +137,7 @@ export function useTotalCount<TContract extends NFTContract>(
|
|||||||
return useQueryWithNetwork<BigNumber>(
|
return useQueryWithNetwork<BigNumber>(
|
||||||
cacheKeys.contract.nft.query.totalCount(contractAddress),
|
cacheKeys.contract.nft.query.totalCount(contractAddress),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(
|
invariant(
|
||||||
@@ -182,14 +185,14 @@ export function useTotalCirculatingSupply(
|
|||||||
return useQueryWithNetwork<BigNumber>(
|
return useQueryWithNetwork<BigNumber>(
|
||||||
cacheKeys.contract.nft.query.totalCirculatingSupply(contractAddress),
|
cacheKeys.contract.nft.query.totalCirculatingSupply(contractAddress),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(
|
invariant(
|
||||||
erc1155.totalCirculatingSupply,
|
erc1155.totalCirculatingSupply,
|
||||||
"Contract instance does not support totalCirculatingSupply",
|
"Contract instance does not support totalCirculatingSupply",
|
||||||
);
|
);
|
||||||
invariant(tokenId, "No tokenId provided");
|
requiredParamInvariant(tokenId, "No tokenId provided");
|
||||||
return await erc1155.totalCirculatingSupply(tokenId);
|
return await erc1155.totalCirculatingSupply(tokenId);
|
||||||
}
|
}
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
@@ -232,7 +235,7 @@ export function useOwnedNFTs<TContract extends NFTContract>(
|
|||||||
return useQueryWithNetwork<NFT[]>(
|
return useQueryWithNetwork<NFT[]>(
|
||||||
cacheKeys.contract.nft.query.owned.all(contractAddress, ownerWalletAddress),
|
cacheKeys.contract.nft.query.owned.all(contractAddress, ownerWalletAddress),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
invariant(ownerWalletAddress, "No wallet address provided");
|
invariant(ownerWalletAddress, "No wallet address provided");
|
||||||
if (erc721) {
|
if (erc721) {
|
||||||
return await erc721.getOwned(ownerWalletAddress);
|
return await erc721.getOwned(ownerWalletAddress);
|
||||||
@@ -277,11 +280,11 @@ export function useNFTBalance(
|
|||||||
tokenId,
|
tokenId,
|
||||||
),
|
),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
|
||||||
invariant(ownerWalletAddress, "No owner wallet address provided");
|
invariant(ownerWalletAddress, "No owner wallet address provided");
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(tokenId, "No tokenId provided");
|
requiredParamInvariant(tokenId, "No tokenId provided");
|
||||||
invariant(
|
invariant(
|
||||||
erc1155.balanceOf,
|
erc1155.balanceOf,
|
||||||
"Contract instance does not support balanceOf",
|
"Contract instance does not support balanceOf",
|
||||||
@@ -375,7 +378,7 @@ export function useMintNFT<TContract extends NFTContract>(
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: MintNFTParams) => {
|
async (data: MintNFTParams) => {
|
||||||
invariant(data.to, 'No "to" address provided');
|
invariant(data.to, 'No "to" address provided');
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant("supply" in data, "supply not provided");
|
invariant("supply" in data, "supply not provided");
|
||||||
const { to, metadata, supply } = data;
|
const { to, metadata, supply } = data;
|
||||||
@@ -444,9 +447,9 @@ export function useMintNFTSupply(contract: Erc1155) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: MintNFTSupplyParams) => {
|
async (data: MintNFTSupplyParams) => {
|
||||||
invariant(data.to, 'No "to" address provided');
|
invariant(data.to, 'No "to" address provided');
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
|
|
||||||
invariant("tokenId" in data, "tokenId not provided");
|
requiredParamInvariant(data.tokenId, "tokenId not provided");
|
||||||
invariant("additionalSupply" in data, "additionalSupply not provided");
|
invariant("additionalSupply" in data, "additionalSupply not provided");
|
||||||
const { to, tokenId, additionalSupply } = data;
|
const { to, tokenId, additionalSupply } = data;
|
||||||
return await contract.mintAdditionalSupplyTo(
|
return await contract.mintAdditionalSupplyTo(
|
||||||
@@ -512,7 +515,7 @@ export function useTransferNFT<TContract extends NFTContract>(
|
|||||||
invariant("to" in data, "to not provided");
|
invariant("to" in data, "to not provided");
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant(erc1155.transfer, "contract does not support transfer");
|
invariant(erc1155.transfer, "contract does not support transfer");
|
||||||
invariant("tokenId" in data, "tokenId not provided");
|
requiredParamInvariant(data.tokenId, "tokenId not provided");
|
||||||
invariant("amount" in data, "amount not provided");
|
invariant("amount" in data, "amount not provided");
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
return erc1155.transfer(data.to, data.tokenId, data.amount!);
|
return erc1155.transfer(data.to, data.tokenId, data.amount!);
|
||||||
@@ -539,7 +542,7 @@ export function useTransferNFT<TContract extends NFTContract>(
|
|||||||
* @example
|
* @example
|
||||||
* ```jsx
|
* ```jsx
|
||||||
* const Component = () => {
|
* const Component = () => {
|
||||||
* const editionDrop = useEditionDrop(<ContractAddress>);
|
* const editionDrop = useContract(<ContractAddress>, "edition-drop");
|
||||||
* const {
|
* const {
|
||||||
* mutate: airdropNFT,
|
* mutate: airdropNFT,
|
||||||
* isLoading,
|
* isLoading,
|
||||||
@@ -602,7 +605,8 @@ export function useAirdropNFT(contract: Erc1155) {
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
({ tokenId, addresses }: AirdropNFTParams) => {
|
({ tokenId, addresses }: AirdropNFTParams) => {
|
||||||
invariant(contract?.airdrop, "contract does not support airdrop");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
|
invariant(contract.airdrop, "contract does not support airdrop");
|
||||||
|
|
||||||
return contract.airdrop(tokenId, addresses);
|
return contract.airdrop(tokenId, addresses);
|
||||||
},
|
},
|
||||||
@@ -688,8 +692,8 @@ export function useBurnNFT<TContract extends NFTContract>(
|
|||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: BurnNFTParams) => {
|
async (data: BurnNFTParams) => {
|
||||||
invariant(data.tokenId, "No tokenId provided");
|
requiredParamInvariant(data.tokenId, "No tokenId provided");
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
if (erc1155) {
|
if (erc1155) {
|
||||||
invariant("amount" in data, "amount not provided");
|
invariant("amount" in data, "amount not provided");
|
||||||
const { tokenId, amount } = data;
|
const { tokenId, amount } = data;
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import { WalletAddress } from "../../types";
|
import { WalletAddress } from "../../types";
|
||||||
import {
|
import {
|
||||||
@@ -61,7 +64,7 @@ export function useAllRoleMembers<TContract extends ContractWithRoles>(
|
|||||||
return useQueryWithNetwork<Awaited<GetAllReturnType<TContract>>>(
|
return useQueryWithNetwork<Awaited<GetAllReturnType<TContract>>>(
|
||||||
cacheKeys.extensions.roles.getAll(contractAddress),
|
cacheKeys.extensions.roles.getAll(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(contract.roles, "Contract does not support roles");
|
invariant(contract.roles, "Contract does not support roles");
|
||||||
// have to cast to any because of role bs, type is defined in the useQueryWithNetwork definition above
|
// have to cast to any because of role bs, type is defined in the useQueryWithNetwork definition above
|
||||||
return contract.roles.getAll() as any;
|
return contract.roles.getAll() as any;
|
||||||
@@ -94,7 +97,7 @@ export function useRoleMembers<TContract extends ContractWithRoles>(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.extensions.roles.get(contractAddress, role),
|
cacheKeys.extensions.roles.get(contractAddress, role),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(contract.roles, "Contract does not support roles");
|
invariant(contract.roles, "Contract does not support roles");
|
||||||
return contract.roles.get(role);
|
return contract.roles.get(role);
|
||||||
},
|
},
|
||||||
@@ -192,7 +195,7 @@ export function useSetAllRoleMembers<TContract extends ContractWithRoles>(
|
|||||||
async (rolesWithAddresses: {
|
async (rolesWithAddresses: {
|
||||||
[role in RolesForContract<TContract>]: string[];
|
[role in RolesForContract<TContract>]: string[];
|
||||||
}) => {
|
}) => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(contract.roles, "Contract does not support roles");
|
invariant(contract.roles, "Contract does not support roles");
|
||||||
await contract.roles.setAll(rolesWithAddresses);
|
await contract.roles.setAll(rolesWithAddresses);
|
||||||
},
|
},
|
||||||
@@ -253,7 +256,7 @@ export function useGrantRole<TContract extends ContractWithRoles>(
|
|||||||
role: RolesForContract<TContract>;
|
role: RolesForContract<TContract>;
|
||||||
address: WalletAddress;
|
address: WalletAddress;
|
||||||
}) => {
|
}) => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(contract.roles, "Contract does not support roles");
|
invariant(contract.roles, "Contract does not support roles");
|
||||||
await contract.roles.grant(params.role as any, params.address);
|
await contract.roles.grant(params.role as any, params.address);
|
||||||
},
|
},
|
||||||
@@ -311,7 +314,7 @@ export function useRevokeRole<TContract extends ContractWithRoles>(
|
|||||||
role: RolesForContract<TContract>;
|
role: RolesForContract<TContract>;
|
||||||
address: WalletAddress;
|
address: WalletAddress;
|
||||||
}) => {
|
}) => {
|
||||||
invariant(contract, "No contract provided");
|
requiredParamInvariant(contract, "No contract provided");
|
||||||
invariant(contract.roles, "Contract does not support roles");
|
invariant(contract.roles, "Contract does not support roles");
|
||||||
await contract.roles.revoke(params.role as any, params.address);
|
await contract.roles.revoke(params.role as any, params.address);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import {
|
import {
|
||||||
ClaimTokenParams,
|
ClaimTokenParams,
|
||||||
@@ -39,7 +42,7 @@ export function useTokenSupply(contract: RequiredParam<TokenContract>) {
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.token.totalSupply(contractAddress),
|
cacheKeys.contract.token.totalSupply(contractAddress),
|
||||||
() => {
|
() => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
const erc20 = getErc20(contract);
|
const erc20 = getErc20(contract);
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
return erc20.totalSupply();
|
return erc20.totalSupply();
|
||||||
@@ -75,7 +78,7 @@ export function useTokenBalance(
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.token.balanceOf(contractAddress, walletAddress),
|
cacheKeys.contract.token.balanceOf(contractAddress, walletAddress),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
invariant(walletAddress, "No address provided");
|
invariant(walletAddress, "No address provided");
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
return await erc20.balanceOf(walletAddress);
|
return await erc20.balanceOf(walletAddress);
|
||||||
@@ -109,7 +112,7 @@ export function useTokenDecimals(contract: RequiredParam<TokenContract>) {
|
|||||||
return useQueryWithNetwork(
|
return useQueryWithNetwork(
|
||||||
cacheKeys.contract.token.decimals(contractAddress),
|
cacheKeys.contract.token.decimals(contractAddress),
|
||||||
async () => {
|
async () => {
|
||||||
invariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
return (await erc20.get()).decimals;
|
return (await erc20.get()).decimals;
|
||||||
@@ -168,7 +171,7 @@ export function useMintToken(contract: RequiredParam<TokenContract>) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
(data: TokenParams) => {
|
(data: TokenParams) => {
|
||||||
const { to, amount } = data;
|
const { to, amount } = data;
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
return erc20.mintTo(to, amount);
|
return erc20.mintTo(to, amount);
|
||||||
}
|
}
|
||||||
@@ -350,7 +353,7 @@ export function useTransferBatchToken(contract: RequiredParam<TokenContract>) {
|
|||||||
(data: TokenParams[]) => {
|
(data: TokenParams[]) => {
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
invariant(
|
invariant(
|
||||||
erc20?.transferBatch,
|
erc20.transferBatch,
|
||||||
"contract does not support transferBatch",
|
"contract does not support transferBatch",
|
||||||
);
|
);
|
||||||
const convertedData = data.map((token) => ({
|
const convertedData = data.map((token) => ({
|
||||||
@@ -415,9 +418,9 @@ export function useBurnToken(contract: RequiredParam<TokenContract>) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
(data: TokenBurnParams) => {
|
(data: TokenBurnParams) => {
|
||||||
const { amount } = data;
|
const { amount } = data;
|
||||||
invariant(contract, "contract is undefined");
|
requiredParamInvariant(contract, "contract is undefined");
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
invariant(erc20?.burn, "contract does not support burn");
|
invariant(erc20.burn, "contract does not support burn");
|
||||||
return erc20.burn(amount);
|
return erc20.burn(amount);
|
||||||
}
|
}
|
||||||
invariant(false, "Smart contract is not a valid erc20 contract");
|
invariant(false, "Smart contract is not a valid erc20 contract");
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import {
|
|
||||||
GnosisConnectorArguments,
|
|
||||||
GnosisSafeConnector,
|
|
||||||
} from "../../connectors/gnosis-safe";
|
|
||||||
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.
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* import { useGnosis } from "@thirdweb-dev/react"
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```javascript
|
|
||||||
* import { useGnosis } from "@thirdweb-dev/react"
|
|
||||||
*
|
|
||||||
* const App = () => {
|
|
||||||
* const connectWithGnosis = useGnosis()
|
|
||||||
*
|
|
||||||
* return (
|
|
||||||
* <button onClick={() => connectWithGnosis({ safeAddress: "0x...", safeChainId: 1 })}>
|
|
||||||
* Connect Gnosis Safe
|
|
||||||
* </button>
|
|
||||||
* )
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @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");
|
|
||||||
}
|
|
||||||
const connector = connectors.data.connectors.find((c) => c.id === "gnosis");
|
|
||||||
invariant(
|
|
||||||
connector,
|
|
||||||
"Gnosis connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
|
||||||
);
|
|
||||||
|
|
||||||
return async (config: GnosisConnectorArguments) => {
|
|
||||||
const previousConnector = connectors.data.connector;
|
|
||||||
const previousConnectorChain = await previousConnector?.getChainId();
|
|
||||||
invariant(
|
|
||||||
!!previousConnector,
|
|
||||||
"Cannot connect to Gnosis Safe without first being connected to a personal wallet.",
|
|
||||||
);
|
|
||||||
invariant(
|
|
||||||
previousConnectorChain === config.safeChainId,
|
|
||||||
"Gnosis safe chain id must match personal wallet chain id.",
|
|
||||||
);
|
|
||||||
invariant(
|
|
||||||
utils.isAddress(config.safeAddress),
|
|
||||||
"Gnosis safe address must be a valid address.",
|
|
||||||
);
|
|
||||||
(connector as GnosisSafeConnector).setConfiguration(
|
|
||||||
previousConnector,
|
|
||||||
config,
|
|
||||||
);
|
|
||||||
return connect(connector);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
import { MagicConnector } from "../../connectors/magic";
|
|
||||||
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.
|
|
||||||
* This enables users without their own wallets to connect to your application and sign transactions securely using their email.
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* import { useMagic } from "@thirdweb-dev/react"
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* Before using this hook, you first need to set up the magic configuration in your `ThirdwebProvider`, including your magic API key.
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* // Add the magic configuration object to your wallet connectors
|
|
||||||
* const connectors = [
|
|
||||||
* "metamask",
|
|
||||||
* "walletConnect",
|
|
||||||
* "walletLink",
|
|
||||||
* {
|
|
||||||
* name: "magic",
|
|
||||||
* options: {
|
|
||||||
* apiKey: "your-magic-api-key",
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* ]
|
|
||||||
*
|
|
||||||
* // Add the above to the walletConnectors prop of your <ThirdwebProvider />
|
|
||||||
* const Provider = ({ children }) => (
|
|
||||||
* return (
|
|
||||||
* <ThirdwebProvider
|
|
||||||
* walletConnectors={connectors}
|
|
||||||
* // Specify remaining parameters
|
|
||||||
* ...
|
|
||||||
* >
|
|
||||||
* {children}
|
|
||||||
* </ThirdwebProvider>
|
|
||||||
* )
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* In order to use the hook to connect users with magic link, you just need to provide the users email to the connect function.
|
|
||||||
*
|
|
||||||
* You can setup the hook with the following configuration:
|
|
||||||
* ```javascript
|
|
||||||
* import { useMagic } from "@thirdweb-dev/react"
|
|
||||||
* import { useState } from "react"
|
|
||||||
*
|
|
||||||
* const LoginWithMagicLink = () => {
|
|
||||||
* const connectWithMagic = useMagic()
|
|
||||||
* const [email, setEmail] = useState()
|
|
||||||
*
|
|
||||||
* return (
|
|
||||||
* <div>
|
|
||||||
* <input value={email} onChange={(e) => setEmail(e.target.value)} />
|
|
||||||
* <button onClick={() => connectWithMagic({ email })}>Login</button>
|
|
||||||
* </div>
|
|
||||||
* )
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @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");
|
|
||||||
}
|
|
||||||
|
|
||||||
const connector = connectors.data.connectors.find((c) => c.id === "magic");
|
|
||||||
|
|
||||||
invariant(
|
|
||||||
connector,
|
|
||||||
"Magic connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
|
||||||
);
|
|
||||||
|
|
||||||
return (configuration: LoginWithMagicLinkConfiguration) => {
|
|
||||||
(connector as MagicConnector).setConfiguration(configuration);
|
|
||||||
return connect(connector);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useConnect } from "../wagmi-required/useConnect";
|
import { useConnect } from "../wagmi-required/useConnect";
|
||||||
|
import { Buffer } from "buffer";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { useContext as useWagmiContext } from "wagmi";
|
import { useContext as useWagmiContext } from "wagmi";
|
||||||
|
|
||||||
if (!globalThis.Buffer) {
|
globalThis.Buffer = Buffer;
|
||||||
globalThis.Buffer = require("buffer/").Buffer;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Hook for connecting to a mobile wallet with Wallet Connect
|
* Hook for connecting to a mobile wallet with Wallet Connect
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useConnect } from "../wagmi-required/useConnect";
|
import { useConnect } from "../wagmi-required/useConnect";
|
||||||
|
import { Buffer } from "buffer";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { useContext as useWagmiContext } from "wagmi";
|
import { useContext as useWagmiContext } from "wagmi";
|
||||||
|
|
||||||
if (!globalThis.Buffer) {
|
globalThis.Buffer = Buffer;
|
||||||
globalThis.Buffer = require("buffer/").Buffer;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Hook for connecting to a Coinbase wallet.
|
* Hook for connecting to a Coinbase wallet.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useEdition } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const edition = useEdition("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "edition")
|
||||||
*
|
*
|
||||||
* // Now you can use the edition contract in the rest of the component
|
* // Now you can use the edition contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will return all the NFTs on this contract
|
* // For example, this function will return all the NFTs on this contract
|
||||||
* async function getNFTs() {
|
* async function getNFTs() {
|
||||||
* const nfts = await edition.getAll()
|
* const nfts = await contract.getAll()
|
||||||
* return nfts
|
* return nfts
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const edition = await sdk.useEdition("0x1234...");
|
* - const edition = useEdition("0x1234...");
|
||||||
* + const edition = await sdk.useContract("0x1234...", "edition").contract;
|
* + const edition = useContract("0x1234...", "edition").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useEdition(contractAddress: RequiredParam<string>) {
|
export function useEdition(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useEditionDrop } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const editionDrop = useEditionDrop("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "edition-drop")
|
||||||
*
|
*
|
||||||
* // Now you can use the edition drop contract in the rest of the component
|
* // Now you can use the edition drop contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will let the connected wallet claim a new NFT
|
* // For example, this function will let the connected wallet claim a new NFT
|
||||||
* async function claim(tokenId, quantity) {
|
* async function claim(tokenId, quantity) {
|
||||||
* await editionDrop.claim(tokenId, quantity)
|
* await contract.claim(tokenId, quantity)
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* ...
|
* ...
|
||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const editionDrop = await sdk.useEditionDrop("0x1234...");
|
* - const editionDrop = useEditionDrop("0x1234...");
|
||||||
* + const editionDrop = await sdk.useContract("0x1234...", "edition-drop").contract;
|
* + const editionDrop = useContract("0x1234...", "edition-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useEditionDrop(contractAddress: RequiredParam<string>) {
|
export function useEditionDrop(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useMarketplace } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const marketplace = useMarketplace("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "marketplace")
|
||||||
*
|
*
|
||||||
* // Now you can use the marketplace contract in the rest of the component
|
* // Now you can use the marketplace contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will return all the listings on the marketplace
|
* // For example, this function will return all the listings on the marketplace
|
||||||
* async function getListings() {
|
* async function getListings() {
|
||||||
* const listings = await marketplace.getAll()
|
* const listings = await contract.getAll()
|
||||||
* return listings
|
* return listings
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const marketplace = await sdk.useMarketplace("0x1234...");
|
* - const marketplace = useMarketplace("0x1234...");
|
||||||
* + const marketplace = await sdk.useContract("0x1234...", "marketplace").contract;
|
* + const marketplace = useContract("0x1234...", "marketplace").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useMarketplace(contractAddress: RequiredParam<string>) {
|
export function useMarketplace(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useMultiwrap } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const multiwrap = useMultiwrap("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "multiwrap")
|
||||||
*
|
*
|
||||||
* // Now you can use the multiwrap contract in the rest of the component
|
* // Now you can use the multiwrap contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will let the connected wallet wrap tokens
|
* // For example, this function will let the connected wallet wrap tokens
|
||||||
* async function wrap(tokensToWrap, wrappedNFTMetadata) {
|
* async function wrap(tokensToWrap, wrappedNFTMetadata) {
|
||||||
* await multiwrap.wrap(tokensToWrap, wrappedNFTMetadata)
|
* await contract.wrap(tokensToWrap, wrappedNFTMetadata)
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* ...
|
* ...
|
||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const multiwrap = await sdk.useMultiwrap("0x1234...");
|
* - const multiwrap = useMultiwrap("0x1234...");
|
||||||
* + const multiwrap = await sdk.useContract("0x1234...", "multiwrap").contract;
|
* + const multiwrap = useContract("0x1234...", "multiwrap").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useMultiwrap(contractAddress: RequiredParam<string>) {
|
export function useMultiwrap(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useNFTCollection } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const nftCollection = useNFTCollection("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useNFTCollection("<YOUR-CONTRACT-ADDRESS>", "nft-collection")
|
||||||
*
|
*
|
||||||
* // Now you can use the nftCollection contract in the rest of the component
|
* // Now you can use the nftCollection contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will return all the NFTs on this contract
|
* // For example, this function will return all the NFTs on this contract
|
||||||
* async function getNFTs() {
|
* async function getNFTs() {
|
||||||
* const nfts = await nftCollection.getAll()
|
* const nfts = await contract.getAll()
|
||||||
* return nfts
|
* return nfts
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const nftCollection = await sdk.useNFTCollection("0x1234...");
|
* - const nftCollection = useNFTCollection("0x1234...");
|
||||||
* + const nftCollection = await sdk.useContract("0x1234...", "nft-collection").contract;
|
* + const nftCollection = useContract("0x1234...", "nft-collection").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useNFTCollection(contractAddress: RequiredParam<string>) {
|
export function useNFTCollection(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useNFTDrop } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const nftDrop = useNFTDrop("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "nft-drop")
|
||||||
*
|
*
|
||||||
* // Now you can use the nft drop contract in the rest of the component
|
* // Now you can use the nft drop contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will let the connected wallet claim a new NFT
|
* // For example, this function will let the connected wallet claim a new NFT
|
||||||
* async function claim(quantity) {
|
* async function claim(quantity) {
|
||||||
* await nftDrop.claim(quantity)
|
* await contract.claim(quantity)
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* ...
|
* ...
|
||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const nftDrop = await sdk.useNFTDrop("0x1234...");
|
* - const nftDrop = useNFTDrop("0x1234...");
|
||||||
* + const nftDrop = await sdk.useContract("0x1234...", "nft-drop").contract;
|
* + const nftDrop = useContract("0x1234...", "nft-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useNFTDrop(contractAddress: RequiredParam<string>) {
|
export function useNFTDrop(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { usePack } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const pack = usePack("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = usePack("<YOUR-CONTRACT-ADDRESS>", "pack")
|
||||||
*
|
*
|
||||||
* // Now you can use the pack contract in the rest of the component
|
* // Now you can use the pack contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will get all the packs on this contract
|
* // For example, this function will get all the packs on this contract
|
||||||
* async function getPacks() {
|
* async function getPacks() {
|
||||||
* const packs = await pack.getAll()
|
* const packs = await contract.getAll()
|
||||||
* return packs
|
* return packs
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const pack = await sdk.usePack("0x1234...");
|
* - const pack = usePack("0x1234...");
|
||||||
* + const pack = await sdk.useContract("0x1234...", "pack").contract;
|
* + const pack = useContract("0x1234...", "pack").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function usePack(contractAddress: RequiredParam<string>) {
|
export function usePack(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useSignatureDrop } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const signatureDrop = useSignatureDrop("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "signature-drop")
|
||||||
*
|
*
|
||||||
* // Now you can use the Signature drop contract in the rest of the component
|
* // Now you can use the Signature drop contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will let the connected wallet claim a new NFT
|
* // For example, this function will let the connected wallet claim a new NFT
|
||||||
* async function claim(quantity) {
|
* async function claim(quantity) {
|
||||||
* await signatureDrop.claim(quantity)
|
* await contract.claim(quantity)
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* ...
|
* ...
|
||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const signatureDrop = await sdk.useSignatureDrop("0x1234...");
|
* - const signatureDrop = useSignatureDrop("0x1234...");
|
||||||
* + const signatureDrop = await sdk.useContract("0x1234...", "signature-drop").contract;
|
* + const signatureDrop = useContract("0x1234...", "signature-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useSignatureDrop(contractAddress?: RequiredParam<string>) {
|
export function useSignatureDrop(contractAddress?: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useSplit } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const split = useSplit("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "split")
|
||||||
*
|
*
|
||||||
* // Now you can use the split contract in the rest of the component
|
* // Now you can use the split contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will retrun all the receipients of the split
|
* // For example, this function will retrun all the receipients of the split
|
||||||
* async function getRecipients() {
|
* async function getRecipients() {
|
||||||
* const recipients = await split.getAllRecipients()
|
* const recipients = await contract.getAllRecipients()
|
||||||
* return recipients
|
* return recipients
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const split = await sdk.useSplit("0x1234...");
|
* - const split = useSplit("0x1234...");
|
||||||
* + const split = await sdk.useContract("0x1234...", "split").contract;
|
* + const split = useContract("0x1234...", "split").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useSplit(contractAddress: RequiredParam<string>) {
|
export function useSplit(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useToken } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const token = useToken("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "token")
|
||||||
*
|
*
|
||||||
* // Now you can use the token contract in the rest of the component
|
* // Now you can use the token contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will get the connected wallets token balance
|
* // For example, this function will get the connected wallets token balance
|
||||||
* async function balance() {
|
* async function balance() {
|
||||||
* const balance = await token.balance()
|
* const balance = await contract.balance()
|
||||||
* return balance
|
* return balance
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const token = await sdk.useToken("0x1234...");
|
* - const token = useToken("0x1234...");
|
||||||
* + const token = await sdk.useContract("0x1234...", "token").contract;
|
* + const token = useContract("0x1234...", "token").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useToken(contractAddress: RequiredParam<string>) {
|
export function useToken(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useTokenDrop } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const tokenDrop = useTokenDrop("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "token-drop")
|
||||||
*
|
*
|
||||||
* // Now you can use the token drop contract in the rest of the component
|
* // Now you can use the token drop contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will get the connected wallets token balance
|
* // For example, this function will get the connected wallets token balance
|
||||||
* async function balance() {
|
* async function balance() {
|
||||||
* const balance = await tokenDrop.balance()
|
* const balance = await contract.balance()
|
||||||
* return balance
|
* return balance
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const token = await sdk.useTokenDrop("0x1234...");
|
* - const token = useTokenDrop("0x1234...");
|
||||||
* + const token = await sdk.useContract("0x1234...", "token-drop").contract;
|
* + const token = useContract("0x1234...", "token-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useTokenDrop(contractAddress: RequiredParam<string>) {
|
export function useTokenDrop(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
import { showDeprecationWarning } from "../../utils/deprecation-warning";
|
||||||
import { useContract } from "../async/contracts";
|
import { useContract } from "../async/contracts";
|
||||||
|
|
||||||
@@ -8,16 +8,16 @@ import { useContract } from "../async/contracts";
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { useVote } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const vote = useVote("<YOUR-CONTRACT-ADDRESS>")
|
* const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "vote")
|
||||||
*
|
*
|
||||||
* // Now you can use the vote contract in the rest of the component
|
* // Now you can use the vote contract in the rest of the component
|
||||||
*
|
*
|
||||||
* // For example, this function will get all the proposals on this contract
|
* // For example, this function will get all the proposals on this contract
|
||||||
* async function getProposals() {
|
* async function getProposals() {
|
||||||
* const proposals = await vote.getAll()
|
* const proposals = await contract.getAll()
|
||||||
* return proposals
|
* return proposals
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const vote = await sdk.useVote("0x1234...");
|
* - const vote = useVote("0x1234...");
|
||||||
* + const vote = await sdk.useContract("0x1234...", "vote").contract;
|
* + const vote = useContract("0x1234...", "vote").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useVote(contractAddress: RequiredParam<string>) {
|
export function useVote(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { GnosisSafeConnector } from "../../connectors/gnosis-safe";
|
|
||||||
import { useConnect } from "./useConnect";
|
import { useConnect } from "./useConnect";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { useAccount, useContext as useWagmiContext } from "wagmi";
|
import { Connector, useAccount, useContext as useWagmiContext } from "wagmi";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for disconnecting the currently connected wallet
|
* Hook for disconnecting the currently connected wallet
|
||||||
@@ -31,23 +30,22 @@ import { useAccount, useContext as useWagmiContext } from "wagmi";
|
|||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export function useDisconnect(options?: { reconnectAfterGnosis?: boolean }) {
|
export function useDisconnect(options?: { reconnectPrevious?: boolean }) {
|
||||||
const wagmiContext = useWagmiContext();
|
const wagmiContext = useWagmiContext();
|
||||||
invariant(
|
invariant(
|
||||||
wagmiContext,
|
wagmiContext,
|
||||||
`useDisconnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own connection logic.`,
|
`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 optsWithDefaults = { ...{ reconnectPrevious: true }, ...options };
|
||||||
const [, connect] = useConnect();
|
const [, connect] = useConnect();
|
||||||
const [data, disconnect] = useAccount();
|
const [data, disconnect] = useAccount();
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
const previousConnector =
|
// if there is a previous connector get it
|
||||||
(data.data?.connector instanceof GnosisSafeConnector &&
|
const previousConnector: Connector | undefined =
|
||||||
data.data.connector.previousConnector) ||
|
(data?.data?.connector as any)?.previousConnector || undefined;
|
||||||
undefined;
|
|
||||||
// if it's gnosis, just connect the previous connector
|
// if it's gnosis, just connect the previous connector
|
||||||
if (optsWithDefaults.reconnectAfterGnosis && previousConnector) {
|
if (optsWithDefaults.reconnectPrevious && previousConnector) {
|
||||||
try {
|
try {
|
||||||
return await connect(previousConnector);
|
return await connect(previousConnector);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ export * from "./hooks/wagmi-required/useConnect";
|
|||||||
export * from "./hooks/connectors/useMetamask";
|
export * from "./hooks/connectors/useMetamask";
|
||||||
export * from "./hooks/connectors/useWalletConnect";
|
export * from "./hooks/connectors/useWalletConnect";
|
||||||
export * from "./hooks/connectors/useWalletLink";
|
export * from "./hooks/connectors/useWalletLink";
|
||||||
export * from "./hooks/connectors/useGnosis";
|
|
||||||
export * from "./hooks/connectors/useMagic";
|
|
||||||
|
|
||||||
// re-exports
|
// re-exports
|
||||||
export { ChainId } from "@thirdweb-dev/sdk";
|
export { ChainId } from "@thirdweb-dev/sdk";
|
||||||
|
|||||||
@@ -1,90 +1,93 @@
|
|||||||
import { useState, useCallback, useLayoutEffect, useEffect, useRef, PropsWithChildren } from "react";
|
import {
|
||||||
import { createPortal } from "react-dom";
|
useState,
|
||||||
|
useCallback,
|
||||||
|
useLayoutEffect,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
PropsWithChildren,
|
||||||
|
} from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
|
||||||
|
function canUseDOM() {
|
||||||
function canUseDOM() {
|
|
||||||
return !!(
|
return !!(
|
||||||
typeof window !== "undefined" &&
|
typeof window !== "undefined" &&
|
||||||
window.document &&
|
window.document &&
|
||||||
window.document.createElement
|
window.document.createElement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces a re-render, similar to `forceUpdate` in class components.
|
* Forces a re-render, similar to `forceUpdate` in class components.
|
||||||
*/
|
*/
|
||||||
function useForceUpdate() {
|
function useForceUpdate() {
|
||||||
const [, dispatch] = useState<{}>(Object.create(null));
|
const [, dispatch] = useState<{}>(Object.create(null));
|
||||||
return useCallback(() => {
|
return useCallback(() => {
|
||||||
dispatch(Object.create(null));
|
dispatch(Object.create(null));
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const useIsomorphicLayoutEffect = canUseDOM() ? useLayoutEffect : useEffect;
|
const useIsomorphicLayoutEffect = canUseDOM() ? useLayoutEffect : useEffect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Portal from `@reach/portal`
|
||||||
|
*
|
||||||
|
* @see Docs https://reach.tech/portal#portal
|
||||||
|
*/
|
||||||
|
const PortalImpl: React.FC<PortalProps> = ({
|
||||||
|
children,
|
||||||
|
type = "reach-portal",
|
||||||
|
containerRef,
|
||||||
|
}) => {
|
||||||
|
const mountNode = useRef<HTMLDivElement | null>(null);
|
||||||
|
const portalNode = useRef<HTMLElement | null>(null);
|
||||||
|
const forceUpdate = useForceUpdate();
|
||||||
|
|
||||||
/**
|
useIsomorphicLayoutEffect(() => {
|
||||||
* Portal from `@reach/portal`
|
// This ref may be null when a hot-loader replaces components on the page
|
||||||
*
|
if (!mountNode.current) {
|
||||||
* @see Docs https://reach.tech/portal#portal
|
return;
|
||||||
*/
|
}
|
||||||
const PortalImpl: React.FC<PortalProps> = ({
|
// It's possible that the content of the portal has, itself, been portaled.
|
||||||
children,
|
// In that case, it's important to append to the correct document element.
|
||||||
type = "reach-portal",
|
const ownerDocument = mountNode.current.ownerDocument;
|
||||||
containerRef,
|
const body = containerRef?.current || ownerDocument.body;
|
||||||
}) => {
|
portalNode.current = ownerDocument?.createElement(type);
|
||||||
const mountNode = useRef<HTMLDivElement | null>(null);
|
body.appendChild(portalNode.current);
|
||||||
const portalNode = useRef<HTMLElement | null>(null);
|
forceUpdate();
|
||||||
const forceUpdate = useForceUpdate();
|
return () => {
|
||||||
|
if (portalNode.current && body) {
|
||||||
|
body.removeChild(portalNode.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [type, forceUpdate, containerRef]);
|
||||||
|
|
||||||
|
return portalNode.current ? (
|
||||||
|
createPortal(children, portalNode.current)
|
||||||
|
) : (
|
||||||
|
<span ref={mountNode} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useIsomorphicLayoutEffect(() => {
|
export const Portal: React.FC<PortalProps> = ({
|
||||||
// This ref may be null when a hot-loader replaces components on the page
|
unstable_skipInitialRender,
|
||||||
if (!mountNode.current) {return;}
|
...props
|
||||||
// It's possible that the content of the portal has, itself, been portaled.
|
}) => {
|
||||||
// In that case, it's important to append to the correct document element.
|
const [hydrated, setHydrated] = useState(false);
|
||||||
const ownerDocument = mountNode.current.ownerDocument;
|
useEffect(() => {
|
||||||
const body = containerRef?.current || ownerDocument.body;
|
if (unstable_skipInitialRender) {
|
||||||
portalNode.current = ownerDocument?.createElement(type);
|
setHydrated(true);
|
||||||
body.appendChild(portalNode.current);
|
}
|
||||||
forceUpdate();
|
}, [unstable_skipInitialRender]);
|
||||||
return () => {
|
if (unstable_skipInitialRender && !hydrated) {
|
||||||
if (portalNode.current && body) {
|
return null;
|
||||||
body.removeChild(portalNode.current);
|
}
|
||||||
}
|
return <PortalImpl {...props} />;
|
||||||
};
|
};
|
||||||
}, [type, forceUpdate, containerRef]);
|
|
||||||
|
|
||||||
return portalNode.current ? (
|
export type PortalProps = PropsWithChildren<{
|
||||||
createPortal(children, portalNode.current)
|
type?: string;
|
||||||
) : (
|
containerRef?: React.RefObject<Node>;
|
||||||
<span ref={mountNode} />
|
unstable_skipInitialRender?: boolean;
|
||||||
);
|
}>;
|
||||||
};
|
|
||||||
|
|
||||||
export const Portal: React.FC<PortalProps> = ({
|
|
||||||
unstable_skipInitialRender,
|
|
||||||
...props
|
|
||||||
}) => {
|
|
||||||
const [hydrated, setHydrated] = useState(false);
|
|
||||||
useEffect(() => {
|
|
||||||
if (unstable_skipInitialRender) {
|
|
||||||
setHydrated(true);
|
|
||||||
}
|
|
||||||
}, [unstable_skipInitialRender]);
|
|
||||||
if (unstable_skipInitialRender && !hydrated) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return <PortalImpl {...props} />;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export type PortalProps = PropsWithChildren<{
|
|
||||||
type?: string;
|
|
||||||
containerRef?: React.RefObject<Node>;
|
|
||||||
unstable_skipInitialRender?: boolean;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
Portal.displayName = "Portal";
|
|
||||||
|
|
||||||
|
Portal.displayName = "Portal";
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import {
|
|||||||
QueryClientProviderProps,
|
QueryClientProviderProps,
|
||||||
QueryClientProviderWithDefault,
|
QueryClientProviderWithDefault,
|
||||||
} from "../../core/providers/query-client";
|
} from "../../core/providers/query-client";
|
||||||
|
import { RequiredParam } from "../../core/query-utils/required-param";
|
||||||
import { ComponentWithChildren } from "../../core/types/component";
|
import { ComponentWithChildren } from "../../core/types/component";
|
||||||
import { RequiredParam } from "../../core/types/shared";
|
|
||||||
import {
|
import {
|
||||||
ThirdwebAuthConfig,
|
ThirdwebAuthConfig,
|
||||||
ThirdwebAuthConfigProvider,
|
ThirdwebAuthConfigProvider,
|
||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import { Signer } from "ethers";
|
import { Signer } from "ethers";
|
||||||
import { createContext, useContext, useEffect, useMemo } from "react";
|
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
interface TWSDKContext {
|
interface TWSDKContext {
|
||||||
@@ -60,21 +60,36 @@ export const WrappedThirdwebSDKProvider: ComponentWithChildren<
|
|||||||
}) => {
|
}) => {
|
||||||
const { signer } = useThirdwebConnectedWalletContext();
|
const { signer } = useThirdwebConnectedWalletContext();
|
||||||
|
|
||||||
const sdk = useMemo(() => {
|
const [sdk, setSDK] = useState<ThirdwebSDK>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
if (!desiredChainId || typeof window === "undefined") {
|
if (!desiredChainId || typeof window === "undefined") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _sdk = new ThirdwebSDK(provider, sdkOptions, storageInterface);
|
const _sdk = new ThirdwebSDK(provider, sdkOptions, storageInterface);
|
||||||
|
// if we already have a signer from the wallet context, use it immediately
|
||||||
|
if (signer) {
|
||||||
|
_sdk.updateSignerOrProvider(signer);
|
||||||
|
}
|
||||||
|
|
||||||
(_sdk as any)._constructedAt = Date.now();
|
(_sdk as any)._constructedAt = Date.now();
|
||||||
(_sdk as any)._chainId = desiredChainId;
|
(_sdk as any)._chainId = desiredChainId;
|
||||||
return _sdk;
|
setSDK(_sdk);
|
||||||
|
|
||||||
|
// explicitly *not* passing the signer, if we have it we use it if we don't we don't
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [provider, sdkOptions, storageInterface, desiredChainId]);
|
}, [provider, sdkOptions, storageInterface, desiredChainId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (signer && sdk && (sdk as any)._chainId === desiredChainId) {
|
if (sdk && (sdk as any)._chainId === desiredChainId) {
|
||||||
sdk.updateSignerOrProvider(signer);
|
if (signer) {
|
||||||
|
sdk.updateSignerOrProvider(signer);
|
||||||
|
} else {
|
||||||
|
sdk.updateSignerOrProvider(provider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [signer, sdk, desiredChainId]);
|
}, [signer, sdk, desiredChainId, provider]);
|
||||||
|
|
||||||
const ctxValue = useMemo(
|
const ctxValue = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
import {
|
import type { GnosisSafeConnector } from "../connectors/gnosis-safe";
|
||||||
GnosisConnectorArguments,
|
import type { MagicConnector } from "../connectors/magic";
|
||||||
GnosisSafeConnector,
|
|
||||||
} from "../connectors/gnosis-safe";
|
|
||||||
import { MagicConnector, MagicConnectorArguments } from "../connectors/magic";
|
|
||||||
import {
|
import {
|
||||||
Chain,
|
Chain,
|
||||||
SupportedChain,
|
SupportedChain,
|
||||||
defaultSupportedChains,
|
defaultSupportedChains,
|
||||||
} from "../constants/chain";
|
} from "../constants/chain";
|
||||||
import { ThirdwebAuthConfig } from "../contexts/thirdweb-auth";
|
import { ThirdwebAuthConfig } from "../contexts/thirdweb-auth";
|
||||||
import {
|
import { ThirdwebConfigProvider } from "../contexts/thirdweb-config";
|
||||||
ThirdwebConfigProvider,
|
|
||||||
defaultChainRpc,
|
|
||||||
} from "../contexts/thirdweb-config";
|
|
||||||
import { ThirdwebSDKProvider, ThirdwebSDKProviderProps } from "./base";
|
import { ThirdwebSDKProvider, ThirdwebSDKProviderProps } from "./base";
|
||||||
import { QueryClient } from "@tanstack/react-query";
|
import { QueryClient } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
@@ -20,6 +14,7 @@ import {
|
|||||||
getProviderForNetwork,
|
getProviderForNetwork,
|
||||||
SDKOptionsOutput,
|
SDKOptionsOutput,
|
||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
|
import { DEFAULT_RPC_URLS } from "@thirdweb-dev/sdk";
|
||||||
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import React, { useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
import {
|
import {
|
||||||
@@ -27,6 +22,7 @@ import {
|
|||||||
ProviderProps as WagmiproviderProps,
|
ProviderProps as WagmiproviderProps,
|
||||||
useProvider,
|
useProvider,
|
||||||
useSigner,
|
useSigner,
|
||||||
|
Connector,
|
||||||
} from "wagmi";
|
} from "wagmi";
|
||||||
import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet";
|
import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet";
|
||||||
import { InjectedConnector } from "wagmi/connectors/injected";
|
import { InjectedConnector } from "wagmi/connectors/injected";
|
||||||
@@ -58,26 +54,6 @@ export type WalletLinkConnectorType =
|
|||||||
options: CoinbaseWalletConnector["options"];
|
options: CoinbaseWalletConnector["options"];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export type MagicConnectorType =
|
|
||||||
| "magic"
|
|
||||||
| {
|
|
||||||
name: "magic";
|
|
||||||
options: Omit<MagicConnectorArguments, "network">;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export type GnosisConnectorType =
|
|
||||||
| "gnosis"
|
|
||||||
| {
|
|
||||||
name: "gnosis";
|
|
||||||
options: GnosisConnectorArguments;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@@ -85,8 +61,8 @@ export type WalletConnector =
|
|||||||
| InjectedConnectorType
|
| InjectedConnectorType
|
||||||
| WalletConnectConnectorType
|
| WalletConnectConnectorType
|
||||||
| WalletLinkConnectorType
|
| WalletLinkConnectorType
|
||||||
| MagicConnectorType
|
| GnosisSafeConnector
|
||||||
| GnosisConnectorType;
|
| MagicConnector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@@ -223,7 +199,7 @@ export const ThirdwebProvider = <
|
|||||||
TSupportedChain extends SupportedChain = SupportedChain,
|
TSupportedChain extends SupportedChain = SupportedChain,
|
||||||
>({
|
>({
|
||||||
sdkOptions,
|
sdkOptions,
|
||||||
chainRpc = defaultChainRpc,
|
chainRpc = DEFAULT_RPC_URLS,
|
||||||
supportedChains = defaultSupportedChains.map(
|
supportedChains = defaultSupportedChains.map(
|
||||||
(c) => c.id,
|
(c) => c.id,
|
||||||
) as TSupportedChain[],
|
) as TSupportedChain[],
|
||||||
@@ -282,6 +258,9 @@ export const ThirdwebProvider = <
|
|||||||
connectors: ({ chainId }: { chainId?: number }) => {
|
connectors: ({ chainId }: { chainId?: number }) => {
|
||||||
return walletConnectors
|
return walletConnectors
|
||||||
.map((connector) => {
|
.map((connector) => {
|
||||||
|
if (connector instanceof Connector) {
|
||||||
|
return connector;
|
||||||
|
}
|
||||||
// injected connector
|
// injected connector
|
||||||
if (
|
if (
|
||||||
(typeof connector === "string" &&
|
(typeof connector === "string" &&
|
||||||
@@ -346,25 +325,7 @@ export const ThirdwebProvider = <
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (typeof connector === "object" && connector.name === "magic") {
|
|
||||||
const jsonRpcUrl = _rpcUrlMap[chainId || desiredChainId || 1];
|
|
||||||
return new MagicConnector({
|
|
||||||
chains: _supporrtedChains,
|
|
||||||
options: {
|
|
||||||
...connector.options,
|
|
||||||
network: { rpcUrl: jsonRpcUrl, chainId: desiredChainId || 1 },
|
|
||||||
rpcUrls: _rpcUrlMap,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
(typeof connector === "string" && connector === "gnosis") ||
|
|
||||||
(typeof connector === "object" && connector.name === "gnosis")
|
|
||||||
) {
|
|
||||||
return new GnosisSafeConnector({
|
|
||||||
chains: _supporrtedChains,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.filter((c) => c !== null);
|
.filter((c) => c !== null);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RequiredParam } from "../core/types/shared";
|
import { RequiredParam } from "../core/query-utils/required-param";
|
||||||
import type {
|
import type {
|
||||||
AirdropInput,
|
AirdropInput,
|
||||||
Amount,
|
Amount,
|
||||||
@@ -14,6 +14,8 @@ import type {
|
|||||||
ClaimOptions,
|
ClaimOptions,
|
||||||
NFTMetadataOrUri,
|
NFTMetadataOrUri,
|
||||||
Token,
|
Token,
|
||||||
|
Multiwrap,
|
||||||
|
Pack,
|
||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
import type { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition";
|
import type { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition";
|
||||||
import type { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition-drop";
|
import type { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition-drop";
|
||||||
@@ -68,6 +70,8 @@ export type TokenBurnParams = {
|
|||||||
export type NFTContract =
|
export type NFTContract =
|
||||||
| NFTCollection
|
| NFTCollection
|
||||||
| Edition
|
| Edition
|
||||||
|
| Pack
|
||||||
|
| Multiwrap
|
||||||
| Exclude<DropContract, "TokenDrop">;
|
| Exclude<DropContract, "TokenDrop">;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,6 +216,18 @@ export type ClaimNFTReturnType =
|
|||||||
// MARKETPLACE //
|
// MARKETPLACE //
|
||||||
|
|
||||||
export type MakeBidParams = { listingId: BigNumberish; bid: Price };
|
export type MakeBidParams = { listingId: BigNumberish; bid: Price };
|
||||||
|
export type MakeOfferParams = {
|
||||||
|
listingId: BigNumberish;
|
||||||
|
pricePerToken: Price;
|
||||||
|
quantity?: Amount;
|
||||||
|
};
|
||||||
|
export type AcceptDirectOffer = {
|
||||||
|
listingId: BigNumberish;
|
||||||
|
addressOfOfferor: string;
|
||||||
|
};
|
||||||
|
export type ExecuteAuctionSale = {
|
||||||
|
listingId: BigNumberish;
|
||||||
|
};
|
||||||
|
|
||||||
export type BuyNowParams<TListingType = ListingType> =
|
export type BuyNowParams<TListingType = ListingType> =
|
||||||
TListingType extends ListingType.Direct
|
TListingType extends ListingType.Direct
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { RequiredParam } from "../../core/types/shared";
|
import { RequiredParam } from "../../core/query-utils/required-param";
|
||||||
import { SupportedChainId } from "../constants/chain";
|
import { SupportedChainId } from "../constants/chain";
|
||||||
import { ContractAddress, WalletAddress } from "../types";
|
import { ContractAddress, WalletAddress } from "../types";
|
||||||
import { QueryClient, QueryKey } from "@tanstack/react-query";
|
import { QueryClient, QueryKey } from "@tanstack/react-query";
|
||||||
import type {
|
import type {
|
||||||
|
ClaimConditionFetchOptions,
|
||||||
MarketplaceFilter,
|
MarketplaceFilter,
|
||||||
QueryAllParams,
|
QueryAllParams,
|
||||||
SUPPORTED_CHAIN_ID,
|
SUPPORTED_CHAIN_ID,
|
||||||
@@ -267,22 +268,24 @@ export const cacheKeys = {
|
|||||||
getActive: (
|
getActive: (
|
||||||
contractAddress: RequiredParam<ContractAddress>,
|
contractAddress: RequiredParam<ContractAddress>,
|
||||||
tokenId?: BigNumberish,
|
tokenId?: BigNumberish,
|
||||||
|
options?: ClaimConditionFetchOptions,
|
||||||
) =>
|
) =>
|
||||||
createContractCacheKey(
|
createContractCacheKey(
|
||||||
contractAddress,
|
contractAddress,
|
||||||
tokenId
|
tokenId
|
||||||
? ["claimConditions", "getActive", { tokenId }]
|
? ["claimConditions", "getActive", { tokenId }, options]
|
||||||
: ["claimConditions", "getActive"],
|
: ["claimConditions", "getActive", options],
|
||||||
),
|
),
|
||||||
getAll: (
|
getAll: (
|
||||||
contractAddress: RequiredParam<ContractAddress>,
|
contractAddress: RequiredParam<ContractAddress>,
|
||||||
tokenId?: BigNumberish,
|
tokenId?: BigNumberish,
|
||||||
|
options?: ClaimConditionFetchOptions,
|
||||||
) =>
|
) =>
|
||||||
createContractCacheKey(
|
createContractCacheKey(
|
||||||
contractAddress,
|
contractAddress,
|
||||||
tokenId
|
tokenId
|
||||||
? ["claimConditions", "getAll", { tokenId }]
|
? ["claimConditions", "getAll", { tokenId }, options]
|
||||||
: ["claimConditions", "getAll"],
|
: ["claimConditions", "getAll", options],
|
||||||
),
|
),
|
||||||
getClaimIneligibilityReasons: (
|
getClaimIneligibilityReasons: (
|
||||||
contractAddress: RequiredParam<ContractAddress>,
|
contractAddress: RequiredParam<ContractAddress>,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// at the moment we'll re-export everything from the ethereum package (only!)
|
// at the moment we'll re-export everything from the ethereum package
|
||||||
export * from "./evm";
|
export * from "./evm";
|
||||||
|
|
||||||
// core exports
|
// core exports
|
||||||
export { shouldNeverPersistQuery } from "./core/query-utils/query-key";
|
export { shouldNeverPersistQuery } from "./core/query-utils/query-key";
|
||||||
export type { RequiredParam } from "./core/types/shared";
|
export type { RequiredParam } from "./core/query-utils/required-param";
|
||||||
|
|||||||
+8
-10
@@ -1,6 +1,6 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../../core/query-utils/required-param";
|
||||||
import { MintNFTParams } from "../../../evm/types";
|
import { MintNFTParams } from "../../../types";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { NFTCollection } from "@thirdweb-dev/sdk/solana";
|
import type { NFTCollection } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
@@ -15,15 +15,10 @@ import invariant from "tiny-invariant";
|
|||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const { program } = useProgram("{{program_address}}");
|
* const { program } = useProgram("{{program_address}}");
|
||||||
* const { mutateAsync: mint, isLoading, error } = useMintNFT(program);
|
* const { mutateAsync: mintNFT, isLoading, error } = useMintNFT(program);
|
||||||
*
|
|
||||||
* function mintNFT() {
|
|
||||||
* const metadata = { name: "First NFT", description: "This is a cool NFT!" };
|
|
||||||
* mint({ to: "{{wallet_address}}", metadata });
|
|
||||||
* }
|
|
||||||
*
|
*
|
||||||
* return (
|
* return (
|
||||||
* <button onClick={() => mintNFT()}>
|
* <button onClick={() => mintNFT({ metadata: { name: "First NFT" } })}>
|
||||||
* Mint
|
* Mint
|
||||||
* </button>
|
* </button>
|
||||||
* )
|
* )
|
||||||
@@ -37,6 +32,9 @@ export function useMintNFT(program: RequiredParam<NFTCollection>) {
|
|||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: MintNFTParams) => {
|
async (data: MintNFTParams) => {
|
||||||
invariant(program, "program is required");
|
invariant(program, "program is required");
|
||||||
|
if (!data.to) {
|
||||||
|
return await program.mint(data.metadata);
|
||||||
|
}
|
||||||
return await program.mintTo(data.to, data.metadata);
|
return await program.mintTo(data.to, data.metadata);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../../core/query-utils/required-param";
|
||||||
|
import { MintNFTSupplyParams } from "../../../types";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { NFTCollection } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mint additional supply for an NFT on your NFT program
|
||||||
|
* @param program - The NFT program to mint additional NFTs to
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useMintNFTSupply } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { mutateAsync: mintSupply, isLoading, error } = useMintNFTSupply(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button onClick={() => mintSupply({ nftAddress: "111...", amount: 10 })}>
|
||||||
|
* Mint Additional Supply
|
||||||
|
* </button>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useMintNFTSupply(program: RequiredParam<NFTCollection>) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation(
|
||||||
|
async (data: MintNFTSupplyParams) => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
if (!data.to) {
|
||||||
|
return await program.mintAdditionalSupply(data.nftAddress, data.amount);
|
||||||
|
}
|
||||||
|
return await program.mintAdditionalSupplyTo(
|
||||||
|
data.to,
|
||||||
|
data.nftAddress,
|
||||||
|
data.amount,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
queryClient.invalidateQueries(createSOLProgramQueryKey(program)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../../core/types/shared";
|
import { RequiredParam } from "../../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../../core/types/shared";
|
import { RequiredParam } from "../../../../core/query-utils/required-param";
|
||||||
import { ClaimNFTParams } from "../../../types";
|
import { ClaimNFTParams } from "../../../types";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export function dropTotalClaimedSupplyQuery(program: RequiredParam<NFTDrop>) {
|
export function dropTotalClaimedSupplyQuery(program: RequiredParam<NFTDrop>) {
|
||||||
return {
|
return {
|
||||||
@@ -11,7 +13,7 @@ export function dropTotalClaimedSupplyQuery(program: RequiredParam<NFTDrop>) {
|
|||||||
] as const),
|
] as const),
|
||||||
|
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
|
|
||||||
return await program.totalClaimedSupply();
|
return await program.totalClaimedSupply();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../../core/query-utils/required-param";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { NFTMetadataInput, UploadProgressEvent } from "@thirdweb-dev/sdk";
|
import { NFTMetadataInput, UploadProgressEvent } from "@thirdweb-dev/sdk";
|
||||||
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lazy mint NFTs on an NFT Drop program
|
* Lazy mint NFTs on an NFT Drop program
|
||||||
@@ -34,7 +36,7 @@ export function useLazyMint(
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (data: { metadatas: NFTMetadataInput[] }) => {
|
async (data: { metadatas: NFTMetadataInput[] }) => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
let options;
|
let options;
|
||||||
if (onProgress) {
|
if (onProgress) {
|
||||||
options = {
|
options = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../../core/types/shared";
|
import { RequiredParam } from "../../../../core/query-utils/required-param";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { NFTDrop, NFTDropConditionsInput } from "@thirdweb-dev/sdk/solana";
|
import type { NFTDrop, NFTDropConditionsInput } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export function dropUnclaimedSupplyQuery(program: RequiredParam<NFTDrop>) {
|
export function dropUnclaimedSupplyQuery(program: RequiredParam<NFTDrop>) {
|
||||||
return {
|
return {
|
||||||
@@ -11,7 +13,7 @@ export function dropUnclaimedSupplyQuery(program: RequiredParam<NFTDrop>) {
|
|||||||
] as const),
|
] as const),
|
||||||
|
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
|
|
||||||
return await program.totalUnclaimedSupply();
|
return await program.totalUnclaimedSupply();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Burn an NFT owned by the connected wallet
|
* Burn an NFT owned by the connected wallet
|
||||||
@@ -32,7 +34,7 @@ export function useBurnNFT(program: RequiredParam<NFTCollection | NFTDrop>) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (nftAddress: string) => {
|
async (nftAddress: string) => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
return await program.burn(nftAddress);
|
return await program.burn(nftAddress);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
export function nftCreatorsQuery(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
queryKey: createSOLProgramQueryKey(program, ["creators"] as const),
|
||||||
|
|
||||||
|
queryFn: async () => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.getCreators();
|
||||||
|
},
|
||||||
|
enabled: !!program,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the creators for an NFT program
|
||||||
|
* @param program - The NFT program to get the creators for
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useCreators } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { data: creators, isLoading } = useCreators(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <pre>{JSON.stringify(creators)}</pre>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useCreators(program: RequiredParam<NFTCollection | NFTDrop>) {
|
||||||
|
return useQuery(nftCreatorsQuery(program));
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export function nftGetOneQuery(
|
export function nftGetOneQuery(
|
||||||
program: RequiredParam<NFTCollection | NFTDrop>,
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
@@ -15,8 +17,8 @@ export function nftGetOneQuery(
|
|||||||
] as const),
|
] as const),
|
||||||
|
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
invariant(tokenAddress, "tokenAddress is required");
|
requiredParamInvariant(tokenAddress, "tokenAddress is required");
|
||||||
return await program.get(tokenAddress);
|
return await program.get(tokenAddress);
|
||||||
},
|
},
|
||||||
enabled: !!program && !!tokenAddress,
|
enabled: !!program && !!tokenAddress,
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export function nftGetAllQuery(
|
export function nftGetAllQuery(
|
||||||
program: RequiredParam<NFTCollection | NFTDrop>,
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
@@ -11,7 +13,7 @@ export function nftGetAllQuery(
|
|||||||
queryKey: createSOLProgramQueryKey(program, ["getAll"] as const),
|
queryKey: createSOLProgramQueryKey(program, ["getAll"] as const),
|
||||||
|
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
return await program.getAll();
|
return await program.getAll();
|
||||||
},
|
},
|
||||||
enabled: !!program,
|
enabled: !!program,
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
export function nftRoyaltyQuery(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
queryKey: createSOLProgramQueryKey(program, ["royalty"] as const),
|
||||||
|
|
||||||
|
queryFn: async () => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.getRoyalty();
|
||||||
|
},
|
||||||
|
enabled: !!program,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the royalty for an NFT program
|
||||||
|
* @param program - The NFT program to get the royalty for
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useRoyalty } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { data: royalty, isLoading } = useRoyaltySettings(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <p>{royalty}</p>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useRoyaltySettings(program: RequiredParam<NFTCollection | NFTDrop>) {
|
||||||
|
return useQuery(nftRoyaltyQuery(program));
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export type TransferNFTMutationParams = {
|
export type TransferNFTMutationParams = {
|
||||||
receiverAddress: string;
|
receiverAddress: string;
|
||||||
@@ -42,7 +44,7 @@ export function useTransferNFT(
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async ({ tokenAddress, receiverAddress }: TransferNFTMutationParams) => {
|
async ({ tokenAddress, receiverAddress }: TransferNFTMutationParams) => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
return await program.transfer(receiverAddress, tokenAddress);
|
return await program.transfer(receiverAddress, tokenAddress);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { CreatorInput, NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the creators for an NFT program
|
||||||
|
* @param program - The NFT program instance to update the creators for
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useUpdateCreators } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { mutateAsync: updateCreators, isLoading, error } = useUpdateCreators(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* onClick={() => updateCreators([{ address: "0x...", share: 10 }])}
|
||||||
|
* >
|
||||||
|
* Update Creators
|
||||||
|
* </button>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useUpdateCreators(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation(
|
||||||
|
async (creators: CreatorInput[]) => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.updateCreators(creators);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
queryClient.invalidateQueries(createSOLProgramQueryKey(program)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the royalty for an NFT program
|
||||||
|
* @param program - The NFT program instance to update the royalty for
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useUpdateRoyaltySettings } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { mutateAsync: updateRoyalties, isLoading, error } = useUpdateRoyaltySettings(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* onClick={() => updateRoyalties(300)}
|
||||||
|
* >
|
||||||
|
* Update Royalties
|
||||||
|
* </button>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useUpdateRoyaltySettings(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation(
|
||||||
|
async (sellerFeeBasisPoints: number) => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.updateRoyalty(sellerFeeBasisPoints);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
queryClient.invalidateQueries(createSOLProgramQueryKey(program)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,7 +2,10 @@ import {
|
|||||||
createSOLQueryKeyWithNetwork,
|
createSOLQueryKeyWithNetwork,
|
||||||
neverPersist,
|
neverPersist,
|
||||||
} from "../../../core/query-utils/query-key";
|
} from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDK } from "../../providers/base";
|
import { useSDK } from "../../providers/base";
|
||||||
import { programAccountTypeQuery } from "./useProgramAccountType";
|
import { programAccountTypeQuery } from "./useProgramAccountType";
|
||||||
import {
|
import {
|
||||||
@@ -17,7 +20,6 @@ import type {
|
|||||||
ThirdwebSDK,
|
ThirdwebSDK,
|
||||||
Token,
|
Token,
|
||||||
} from "@thirdweb-dev/sdk/solana";
|
} from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
type ProgramMap = Readonly<{
|
type ProgramMap = Readonly<{
|
||||||
"nft-collection": NFTCollection;
|
"nft-collection": NFTCollection;
|
||||||
@@ -42,8 +44,8 @@ export function programQuery<TProgramType extends ProgramType>(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
queryFn: (async () => {
|
queryFn: (async () => {
|
||||||
invariant(sdk, "sdk is required");
|
requiredParamInvariant(sdk, "sdk is required");
|
||||||
invariant(address, "Address is required");
|
requiredParamInvariant(address, "Address is required");
|
||||||
// if the type is not passed in explicitly then we'll try to resolve it
|
// if the type is not passed in explicitly then we'll try to resolve it
|
||||||
if (!type) {
|
if (!type) {
|
||||||
// why do we call `fetchQuery` here instead of calling the sdk directly?
|
// why do we call `fetchQuery` here instead of calling the sdk directly?
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { createSOLQueryKeyWithNetwork } from "../../../core/query-utils/query-key";
|
import { createSOLQueryKeyWithNetwork } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDK } from "../../providers/base";
|
import { useSDK } from "../../providers/base";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { ThirdwebSDK } from "@thirdweb-dev/sdk/solana";
|
import type { ThirdwebSDK } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export function programAccountTypeQuery(
|
export function programAccountTypeQuery(
|
||||||
sdk: RequiredParam<ThirdwebSDK>,
|
sdk: RequiredParam<ThirdwebSDK>,
|
||||||
@@ -16,8 +18,8 @@ export function programAccountTypeQuery(
|
|||||||
network || null,
|
network || null,
|
||||||
),
|
),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
invariant(sdk, "sdk is required");
|
requiredParamInvariant(sdk, "sdk is required");
|
||||||
invariant(address, "Address is required");
|
requiredParamInvariant(address, "Address is required");
|
||||||
|
|
||||||
return await sdk.registry.getProgramType(address);
|
return await sdk.registry.getProgramType(address);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { UseProgramResult } from "./useProgram";
|
import { UseProgramResult } from "./useProgram";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import type { TokenParams } from "../../../evm";
|
import type { TokenParams } from "../../../evm";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { Token } from "@thirdweb-dev/sdk/solana";
|
import type { Token } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mint tokens on your token program
|
* Mint tokens on your token program
|
||||||
@@ -31,7 +33,7 @@ export function useMintToken(program: RequiredParam<Token>) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async (params: TokenParams) => {
|
async (params: TokenParams) => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
// TODO switch this to use mintTo once that is exposed
|
// TODO switch this to use mintTo once that is exposed
|
||||||
return await program.mint(params.amount);
|
return await program.mint(params.amount);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { Token } from "@thirdweb-dev/sdk/solana";
|
import { Token } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export function tokenBalanceQuery(
|
export function tokenBalanceQuery(
|
||||||
program: RequiredParam<Token>,
|
program: RequiredParam<Token>,
|
||||||
@@ -14,9 +16,8 @@ export function tokenBalanceQuery(
|
|||||||
{ walletAddress },
|
{ walletAddress },
|
||||||
] as const),
|
] as const),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
|
requiredParamInvariant(walletAddress, "Wallet address is required");
|
||||||
invariant(walletAddress, "Wallet address is required");
|
|
||||||
return await program.balanceOf(walletAddress);
|
return await program.balanceOf(walletAddress);
|
||||||
},
|
},
|
||||||
enabled: !!program && !!walletAddress,
|
enabled: !!program && !!walletAddress,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { Token } from "@thirdweb-dev/sdk/solana";
|
import { Token } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { Amount, Token } from "@thirdweb-dev/sdk/solana";
|
import type { Amount, Token } from "@thirdweb-dev/sdk/solana";
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
|
|
||||||
export type TransferTokenMutationParams = {
|
export type TransferTokenMutationParams = {
|
||||||
amount: Amount;
|
amount: Amount;
|
||||||
@@ -35,7 +37,7 @@ export function useTransferToken(program: RequiredParam<Token>) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation(
|
return useMutation(
|
||||||
async ({ amount, receiverAddress }: TransferTokenMutationParams) => {
|
async ({ amount, receiverAddress }: TransferTokenMutationParams) => {
|
||||||
invariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
return await program.transfer(receiverAddress, amount);
|
return await program.transfer(receiverAddress, amount);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import { useSDK } from "../../providers/base";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the currently connected wallet address
|
|
||||||
*
|
|
||||||
* @returns the address of the connected wallet (in base58 string format)
|
|
||||||
*/
|
|
||||||
export function useAddress() {
|
|
||||||
const sdk = useSDK();
|
|
||||||
return sdk?.wallet?.getAddress();
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createSOLQueryKeyWithNetwork } from "../../../core/query-utils/query-key";
|
import { createSOLQueryKeyWithNetwork } from "../../../core/query-utils/query-key";
|
||||||
import { RequiredParam } from "../../../core/types/shared";
|
import { RequiredParam } from "../../../core/query-utils/required-param";
|
||||||
import { useSDK } from "../../providers/base";
|
import { useSDK } from "../../providers/base";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { ThirdwebSDK } from "@thirdweb-dev/sdk/solana";
|
import { ThirdwebSDK } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|||||||
@@ -12,10 +12,16 @@ export * from "./hooks/program/useProgramAccountType";
|
|||||||
|
|
||||||
// NFT Shared
|
// NFT Shared
|
||||||
export * from "./hooks/nft/useNFTs";
|
export * from "./hooks/nft/useNFTs";
|
||||||
export * from "./hooks/nft/useMintNFT";
|
|
||||||
export * from "./hooks/nft/useNFT";
|
|
||||||
export * from "./hooks/nft/useTransferNFT";
|
export * from "./hooks/nft/useTransferNFT";
|
||||||
export * from "./hooks/nft/useBurnNFT";
|
export * from "./hooks/nft/useBurnNFT";
|
||||||
|
export * from "./hooks/nft/useRoyaltySettings";
|
||||||
|
export * from "./hooks/nft/useUpdateRoyaltySettings";
|
||||||
|
export * from "./hooks/nft/useCreators";
|
||||||
|
export * from "./hooks/nft/useUpdateCreators";
|
||||||
|
|
||||||
|
// NFT Collection
|
||||||
|
export * from "./hooks/nft/collection/useMintNFT";
|
||||||
|
export * from "./hooks/nft/collection/useMintNFTSupply";
|
||||||
|
|
||||||
// NFT Drop
|
// NFT Drop
|
||||||
export * from "./hooks/nft/drop/useLazyMint";
|
export * from "./hooks/nft/drop/useLazyMint";
|
||||||
@@ -35,5 +41,4 @@ export * from "./hooks/token/useTransferToken";
|
|||||||
export * from "./hooks/auth";
|
export * from "./hooks/auth";
|
||||||
|
|
||||||
//Wallet
|
//Wallet
|
||||||
export * from "./hooks/wallet/useAddress";
|
|
||||||
export * from "./hooks/wallet/useBalance";
|
export * from "./hooks/wallet/useBalance";
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import {
|
|||||||
QueryClientProviderProps,
|
QueryClientProviderProps,
|
||||||
QueryClientProviderWithDefault,
|
QueryClientProviderWithDefault,
|
||||||
} from "../../core/providers/query-client";
|
} from "../../core/providers/query-client";
|
||||||
|
import { RequiredParam } from "../../core/query-utils/required-param";
|
||||||
import { ComponentWithChildren } from "../../core/types/component";
|
import { ComponentWithChildren } from "../../core/types/component";
|
||||||
import { RequiredParam } from "../../core/types/shared";
|
|
||||||
import {
|
import {
|
||||||
ThirdwebAuthConfig,
|
ThirdwebAuthConfig,
|
||||||
ThirdwebAuthConfigProvider,
|
ThirdwebAuthConfigProvider,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { ThirdwebAuthConfig } from "../contexts/thirdweb-auth";
|
import { ThirdwebAuthConfig } from "../contexts/thirdweb-auth";
|
||||||
import { ThirdwebSDKProvider } from "./base";
|
import { ThirdwebSDKProvider } from "./base";
|
||||||
import type { WalletAdapter } from "@solana/wallet-adapter-base";
|
import type { WalletAdapter } from "@solana/wallet-adapter-base";
|
||||||
|
import { PhantomWalletAdapter } from "@solana/wallet-adapter-phantom";
|
||||||
import {
|
import {
|
||||||
ConnectionProvider,
|
ConnectionProvider,
|
||||||
useWallet,
|
useWallet,
|
||||||
WalletProvider,
|
WalletProvider,
|
||||||
} from "@solana/wallet-adapter-react";
|
} from "@solana/wallet-adapter-react";
|
||||||
import { PhantomWalletAdapter } from "@solana/wallet-adapter-wallets";
|
|
||||||
import { getUrlForNetwork, Network } from "@thirdweb-dev/sdk/solana";
|
import { getUrlForNetwork, Network } from "@thirdweb-dev/sdk/solana";
|
||||||
import { PropsWithChildren } from "react";
|
import { PropsWithChildren } from "react";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
import { Amount } from "@thirdweb-dev/sdk";
|
import { Amount, NFTMetadataOrUri } from "@thirdweb-dev/sdk";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The params for the {@link useMintNFT} hook mutation.
|
||||||
|
*
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export type MintNFTParams = {
|
||||||
|
to?: string;
|
||||||
|
metadata: NFTMetadataOrUri;
|
||||||
|
amount?: Amount;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The params for the {@link useClaimNFT} hook mutation.
|
* The params for the {@link useClaimNFT} hook mutation.
|
||||||
@@ -9,3 +20,13 @@ export type ClaimNFTParams = {
|
|||||||
to?: string;
|
to?: string;
|
||||||
amount: Amount;
|
amount: Amount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The params to pass to {@link useMintNFTSupply} hook mutation
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export type MintNFTSupplyParams = {
|
||||||
|
to?: string;
|
||||||
|
nftAddress: string;
|
||||||
|
amount: Amount;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,122 @@
|
|||||||
# @thirdweb-dev/sdk
|
# @thirdweb-dev/sdk
|
||||||
|
|
||||||
|
## 3.4.4
|
||||||
|
|
||||||
|
## 3.4.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#353](https://github.com/thirdweb-dev/js/pull/353) [`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useUpdateCreators hook, fix CreatorInput schema
|
||||||
|
|
||||||
|
- [#357](https://github.com/thirdweb-dev/js/pull/357) [`65fc7ba`](https://github.com/thirdweb-dev/js/commit/65fc7ba6fff093a971b53cb0979c39768e090ba1) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose claimConditions.getClaimerProofs(address) to get allowlist information for a given address
|
||||||
|
|
||||||
|
## 3.4.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#344](https://github.com/thirdweb-dev/js/pull/344) [`21c21c1`](https://github.com/thirdweb-dev/js/commit/21c21c1adfd09b60ad563bfd4c308597140de33c) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Update internal function resolveContractUriFromAddress -> resolveContractUriFromAddress
|
||||||
|
|
||||||
|
- [#352](https://github.com/thirdweb-dev/js/pull/352) [`3522917`](https://github.com/thirdweb-dev/js/commit/352291791ee900e1500f84f095290497934d2f60) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose marketplace.auction.executeSale(listingId)
|
||||||
|
|
||||||
|
## 3.4.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#343](https://github.com/thirdweb-dev/js/pull/343) [`72227b2`](https://github.com/thirdweb-dev/js/commit/72227b2e166a3a68bbb41cf2b389322f5b7547a2) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose general marketplace.makeOffer() function
|
||||||
|
|
||||||
|
## 3.4.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#337](https://github.com/thirdweb-dev/js/pull/337) [`340605b`](https://github.com/thirdweb-dev/js/commit/340605b507f384fbd2999b9c16542af3c53e84a9) Thanks [@adam-maj](https://github.com/adam-maj)! - Clean native token address in listing
|
||||||
|
|
||||||
|
- [#342](https://github.com/thirdweb-dev/js/pull/342) [`26116a6`](https://github.com/thirdweb-dev/js/commit/26116a6f637ee845f7bd17f20ffe17caf184658e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Add new univeral RPC urls
|
||||||
|
|
||||||
|
- [#335](https://github.com/thirdweb-dev/js/pull/335) [`15f8006`](https://github.com/thirdweb-dev/js/commit/15f8006e1fb22333b7ee239b45e7b1b12d6dccc8) Thanks [@adam-maj](https://github.com/adam-maj)! - Export smart contract
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - enable e2e testing
|
||||||
|
|
||||||
|
- Updated dependencies [[`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5)]:
|
||||||
|
- @thirdweb-dev/storage@1.0.6
|
||||||
|
|
||||||
|
## 3.3.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#332](https://github.com/thirdweb-dev/js/pull/332) [`ad851f7`](https://github.com/thirdweb-dev/js/commit/ad851f7b4d6abb5ab9364ef3dec229f913e18ce5) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix for finding addresses in legacy merkle tree format
|
||||||
|
|
||||||
|
- [#330](https://github.com/thirdweb-dev/js/pull/330) [`6218c88`](https://github.com/thirdweb-dev/js/commit/6218c885842e6b4e44ec38ec92a9211e56c49bf4) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix deploying contracts with non-32 bytes parameters like bytes4
|
||||||
|
|
||||||
|
## 3.3.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#315](https://github.com/thirdweb-dev/js/pull/315) [`89ff921`](https://github.com/thirdweb-dev/js/commit/89ff921a7d9f0e42b4e6707c8b56d0aab95c1aa0) Thanks [@furqanrydhan](https://github.com/furqanrydhan)! - fixing vite, multihash moved to non lazy load + cbor-x instead of cbor-web
|
||||||
|
|
||||||
|
- [#321](https://github.com/thirdweb-dev/js/pull/321) [`a57b4f0`](https://github.com/thirdweb-dev/js/commit/a57b4f01f3a49590b897101f2730582e4124a554) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SDK] Implement sharded merkle trees for lightweight allowlist checks
|
||||||
|
|
||||||
|
**Behavior change**
|
||||||
|
|
||||||
|
We've made allowlists much more performant using sharded merkle trees. This allows us to process large allowlists (1M+) efficiently.
|
||||||
|
|
||||||
|
To support those large allowlists, fetching claim conditions does not fetch the allowlist data by default anymore. Instead, you can pass an options object to additionally fetch the allowlist data along with the rest of the claim conditions data.
|
||||||
|
|
||||||
|
This affects `ClaimConditions.getActive()` and `ClaimConditions.getAll()`
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const activeClaimCondition =
|
||||||
|
await contract.erc721.claimConditions.getActive();
|
||||||
|
// `activeClaimCondition.snapshot` is undefined
|
||||||
|
const activeclaimConditionWithtAllowList =
|
||||||
|
await contract.erc721.claimConditions.getActive({
|
||||||
|
withAllowList: true,
|
||||||
|
});
|
||||||
|
// `activeClaimCondition.snapshot` returns the allowlist data
|
||||||
|
```
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#326](https://github.com/thirdweb-dev/js/pull/326) [`126752d`](https://github.com/thirdweb-dev/js/commit/126752d7d02c9a808a63fb9e67a9df6658b5682b) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - expose fn to get ipfs hash from bytecote publicly
|
||||||
|
|
||||||
|
- [#328](https://github.com/thirdweb-dev/js/pull/328) [`df74340`](https://github.com/thirdweb-dev/js/commit/df74340fa51323304c32419761d6f18628b060fa) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Update cbor-x import to work with es2018 builds (embeds)
|
||||||
|
|
||||||
|
- Updated dependencies [[`87fd6ab`](https://github.com/thirdweb-dev/js/commit/87fd6ab14e1a67a1b12e72bd397fb21769537307)]:
|
||||||
|
- @thirdweb-dev/[email protected]
|
||||||
|
|
||||||
|
## 3.2.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#317](https://github.com/thirdweb-dev/js/pull/317) [`4f867e1`](https://github.com/thirdweb-dev/js/commit/4f867e15edbe5757afbf54cab207458711a8986c) Thanks [@adam-maj](https://github.com/adam-maj)! - Add supply to nft.get
|
||||||
|
|
||||||
|
- [#312](https://github.com/thirdweb-dev/js/pull/312) [`b6eec61`](https://github.com/thirdweb-dev/js/commit/b6eec6146c23b66a3681bbb48b173b9019254214) Thanks [@adam-maj](https://github.com/adam-maj)! - Add quantity to mint additional supply
|
||||||
|
|
||||||
|
- [#310](https://github.com/thirdweb-dev/js/pull/310) [`9727502`](https://github.com/thirdweb-dev/js/commit/9727502eb30ac139382b7c7c8e8fc0967cbfbcf1) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - [SOL] - add useMintNFTSupply hook in react and accomodate inputs for it in SDK
|
||||||
|
|
||||||
|
- [#307](https://github.com/thirdweb-dev/js/pull/307) [`782b58d`](https://github.com/thirdweb-dev/js/commit/782b58d3f6a3b49ff9b3d837551db5161f96171a) Thanks [@kumaryash90](https://github.com/kumaryash90)! - fix multicall gasless
|
||||||
|
|
||||||
|
- [#320](https://github.com/thirdweb-dev/js/pull/320) [`f41a443`](https://github.com/thirdweb-dev/js/commit/f41a443c5785240197607b5bf93ff18a1c8e8307) Thanks [@adam-maj](https://github.com/adam-maj)! - Add update creators and update royalty
|
||||||
|
|
||||||
|
- [#313](https://github.com/thirdweb-dev/js/pull/313) [`f45ef62`](https://github.com/thirdweb-dev/js/commit/f45ef62128cfefe06275a38440c90d45e9f3cef7) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Return default metadata when failing to fetch a given tokenId on NFT contracts
|
||||||
|
|
||||||
|
- [#319](https://github.com/thirdweb-dev/js/pull/319) [`2f8ec89`](https://github.com/thirdweb-dev/js/commit/2f8ec89c4c83ae577092c840c198e6fcfb114e69) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose total claimed and unclaimed supply for erc721 drop contracts
|
||||||
|
|
||||||
|
- [#322](https://github.com/thirdweb-dev/js/pull/322) [`b7cd744`](https://github.com/thirdweb-dev/js/commit/b7cd744cd0482a6c3fe5ae0c858f20cd380d4114) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SOL] Allow signing multiple claims at once
|
||||||
|
|
||||||
|
- [#306](https://github.com/thirdweb-dev/js/pull/306) [`53c6507`](https://github.com/thirdweb-dev/js/commit/53c65076696a43bd9a7e58a7493d4e65c172900f) Thanks [@adam-maj](https://github.com/adam-maj)! - Add contract deploy listener
|
||||||
|
|
||||||
|
## 3.2.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#303](https://github.com/thirdweb-dev/js/pull/303) [`712b11a`](https://github.com/thirdweb-dev/js/commit/712b11a43e389ae10b7f09648779a69c05b2c913) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SOL] Fix getting real NFT owners
|
||||||
|
|
||||||
|
## 3.2.4
|
||||||
|
|
||||||
|
## 3.2.3
|
||||||
|
|
||||||
## 3.2.2
|
## 3.2.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user