Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f5b66bef9 | ||
|
|
63258bc9c3 | ||
|
|
a80fc97b6a | ||
|
|
24f66e38c2 |
+5
-1
@@ -26,7 +26,8 @@
|
||||
"version-packages": "changeset version",
|
||||
"release": "node ./scripts/pre-release.mjs && changeset publish",
|
||||
"version-packages:nightly": "changeset version --snapshot nightly",
|
||||
"release:nightly": "node ./scripts/pre-release.mjs && changeset publish --tag nightly"
|
||||
"release:nightly": "node ./scripts/pre-release.mjs && changeset publish --tag nightly",
|
||||
"push": "turbo run push"
|
||||
},
|
||||
"preconstruct": {
|
||||
"packages": [
|
||||
@@ -47,5 +48,8 @@
|
||||
},
|
||||
"manypkg": {
|
||||
"defaultBranch": "main"
|
||||
},
|
||||
"devDependencies": {
|
||||
"yalc": "^1.0.0-pre.53"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @thirdweb-dev/auth
|
||||
|
||||
## 2.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870)]:
|
||||
- @thirdweb-dev/sdk@3.0.6
|
||||
|
||||
## 2.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/auth",
|
||||
"version": "2.0.5",
|
||||
"version": "2.0.6",
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
"./express": {
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# thirdweb
|
||||
|
||||
## 0.7.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870)]:
|
||||
- @thirdweb-dev/sdk@3.0.6
|
||||
|
||||
## 0.7.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "thirdweb",
|
||||
"main": "dist/cli/index.js",
|
||||
"version": "0.7.16",
|
||||
"version": "0.7.17",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
||||
"author": "thirdweb eng <[email protected]>",
|
||||
"license": "Apache-2.0",
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# @thirdweb-dev/react
|
||||
|
||||
## 3.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#179](https://github.com/thirdweb-dev/js/pull/179) [`63258bc`](https://github.com/thirdweb-dev/js/commit/63258bc9c3443db7d12fc1dc6fbd483926c92d3e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose simple provider and useSDK hooks for Solana
|
||||
|
||||
- Updated dependencies [[`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870)]:
|
||||
- @thirdweb-dev/sdk@3.0.6
|
||||
- @thirdweb-dev/solana@0.2.14
|
||||
|
||||
## 3.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/react",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.6",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
||||
"author": "thirdweb eng <[email protected]>",
|
||||
"license": "Apache-2.0",
|
||||
@@ -8,9 +8,15 @@
|
||||
"types": "dist/thirdweb-dev-react.cjs.d.ts",
|
||||
"module": "dist/thirdweb-dev-react.esm.js",
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"patches/**/*"
|
||||
"dist/",
|
||||
"solana/"
|
||||
],
|
||||
"preconstruct": {
|
||||
"entrypoints": [
|
||||
"index.ts",
|
||||
"solana/index.ts"
|
||||
]
|
||||
},
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"format": "prettier --write 'src/**/*'",
|
||||
@@ -22,7 +28,8 @@
|
||||
"generate-snippets": "node ./scripts/generate-snippets.mjs && node ./scripts/generate-feature-snippets.mjs",
|
||||
"build": "tsc && preconstruct build",
|
||||
"e2e": "yarn test-ct",
|
||||
"test-ct": "playwright test -c playwright-ct.config.ts"
|
||||
"test-ct": "playwright test -c playwright-ct.config.ts",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"sideEffects:": false,
|
||||
"devDependencies": {
|
||||
@@ -36,6 +43,10 @@
|
||||
"@playwright/experimental-ct-react": "1.25.1",
|
||||
"@playwright/test": "1.25.1",
|
||||
"@preconstruct/cli": "^2.2.1",
|
||||
"@solana/wallet-adapter-base": "^0.9.17",
|
||||
"@solana/wallet-adapter-react": "^0.15.19",
|
||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
||||
"@solana/web3.js": "^1.63.0",
|
||||
"@thirdweb-dev/sdk": "*",
|
||||
"@types/color": "^3.0.3",
|
||||
"@types/mime": "^3.0.1",
|
||||
@@ -75,7 +86,12 @@
|
||||
"wagmi": "^0.2.28"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@solana/wallet-adapter-base": "^0.9.17",
|
||||
"@solana/wallet-adapter-react": "^0.15.19",
|
||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
||||
"@solana/web3.js": "^1.63.0",
|
||||
"@thirdweb-dev/sdk": "*",
|
||||
"@thirdweb-dev/solana": "*",
|
||||
"ethers": ">=5.5.1",
|
||||
"react": ">=18.0.0",
|
||||
"react-dom": ">=18.0.0"
|
||||
@@ -83,5 +99,22 @@
|
||||
"resolutions": {
|
||||
"ansi-regex": "^6.0.1",
|
||||
"typescript": "^4.6.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@solana/wallet-adapter-base": {
|
||||
"optional": true
|
||||
},
|
||||
"@solana/wallet-adapter-react": {
|
||||
"optional": true
|
||||
},
|
||||
"@solana/wallet-adapter-wallets": {
|
||||
"optional": true
|
||||
},
|
||||
"@solana/web3.js": {
|
||||
"optional": true
|
||||
},
|
||||
"@thirdweb-dev/solana": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "dist/thirdweb-dev-react-solana.cjs.js",
|
||||
"module": "dist/thirdweb-dev-react-solana.esm.js"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ThirdwebSDKContext } from "../providers/ThirdwebSDKProvider";
|
||||
import { useContext } from "react";
|
||||
|
||||
export function useSDK() {
|
||||
return useContext(ThirdwebSDKContext);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Providers
|
||||
export * from "./providers/ThirdwebSDKProvider";
|
||||
export * from "./providers/ThirdwebProvider";
|
||||
// Hooks
|
||||
export * from "./hooks/useSDK";
|
||||
@@ -0,0 +1,66 @@
|
||||
import { ThirdwebSDKProvider } from "./ThirdwebSDKProvider";
|
||||
import type { WalletAdapter } from "@solana/wallet-adapter-base";
|
||||
import {
|
||||
ConnectionProvider,
|
||||
useConnection,
|
||||
useWallet,
|
||||
WalletProvider,
|
||||
} from "@solana/wallet-adapter-react";
|
||||
import { PhantomWalletAdapter } from "@solana/wallet-adapter-wallets";
|
||||
import { getUrlForNetwork, Network } from "@thirdweb-dev/solana";
|
||||
import { PropsWithChildren } from "react";
|
||||
|
||||
interface ThirdwebProviderProps {
|
||||
endpoint: Network;
|
||||
wallets?: WalletAdapter[];
|
||||
autoConnect?: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_WALLETS = [new PhantomWalletAdapter()];
|
||||
|
||||
/**
|
||||
* Gives access to the ThirdwebSDK instance and other useful hooks to the rest of the app.
|
||||
* Requires to be wrapped with a ConnectionProvider and a WalletProvider from @solana/wallet-adapter-react.
|
||||
* @example
|
||||
* ```tsx
|
||||
* import { ThirdwebProvider } from "@thirdweb-dev/react/solana";
|
||||
*
|
||||
* const App = () => {
|
||||
* return (
|
||||
* <ThirdwebProvider endpoint="devnet">
|
||||
* <YourApp />
|
||||
* </ThirdwebProvider>
|
||||
* )};
|
||||
* ```
|
||||
* @beta
|
||||
*/
|
||||
export const ThirdwebProvider: React.FC<
|
||||
PropsWithChildren<ThirdwebProviderProps>
|
||||
> = ({ endpoint, wallets, autoConnect, children }) => {
|
||||
const clusterUrl = getUrlForNetwork(endpoint);
|
||||
return (
|
||||
<ConnectionProvider endpoint={clusterUrl}>
|
||||
<WalletProvider
|
||||
wallets={wallets || DEFAULT_WALLETS}
|
||||
autoConnect={autoConnect || true}
|
||||
>
|
||||
<ThirdwebWrapperProvider>{children}</ThirdwebWrapperProvider>
|
||||
</WalletProvider>
|
||||
</ConnectionProvider>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const ThirdwebWrapperProvider: React.FC<PropsWithChildren> = ({
|
||||
children,
|
||||
}) => {
|
||||
const { connection } = useConnection();
|
||||
const wallet = useWallet();
|
||||
return (
|
||||
<ThirdwebSDKProvider connection={connection} wallet={wallet}>
|
||||
{children}
|
||||
</ThirdwebSDKProvider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { WalletContextState } from "@solana/wallet-adapter-react";
|
||||
import type { Connection } from "@solana/web3.js";
|
||||
import { ThirdwebSDK } from "@thirdweb-dev/solana";
|
||||
import {
|
||||
createContext,
|
||||
FC,
|
||||
PropsWithChildren,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
interface ThirdwebSDKProviderProps {
|
||||
connection: Connection;
|
||||
wallet?: WalletContextState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives access to the ThirdwebSDK instance and other useful hooks to the rest of the app.
|
||||
* Requires to be wrapped with a ConnectionProvider and a WalletProvider from @solana/wallet-adapter-react.
|
||||
* @example
|
||||
* ```tsx
|
||||
* import {
|
||||
* useConnection,
|
||||
* useWallet,
|
||||
* } from "@solana/wallet-adapter-react";
|
||||
* import { ThirdwebProvider } from "@thirdweb-dev/react/solana";
|
||||
*
|
||||
* const ThirdwebApp = () => {
|
||||
* const { connection } = useConnection();
|
||||
* const wallet = useWallet();
|
||||
* return (
|
||||
* <ThirdwebSDKProvider connection={connection} wallet={wallet}>
|
||||
* <YourApp />
|
||||
* </ThirdwebSDKProvider>
|
||||
* )};
|
||||
* ```
|
||||
*/
|
||||
export const ThirdwebSDKProvider: FC<
|
||||
PropsWithChildren<ThirdwebSDKProviderProps>
|
||||
> = ({ children, connection, wallet }) => {
|
||||
const [sdk, setSDK] = useState<ThirdwebSDK | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (connection) {
|
||||
setSDK(new ThirdwebSDK(connection));
|
||||
} else {
|
||||
setSDK(null);
|
||||
}
|
||||
}, [connection]);
|
||||
|
||||
useEffect(() => {
|
||||
if (sdk) {
|
||||
if (wallet?.publicKey) {
|
||||
sdk.wallet.connect(wallet);
|
||||
} else {
|
||||
sdk.wallet.disconnect();
|
||||
}
|
||||
}
|
||||
}, [sdk, wallet]);
|
||||
|
||||
return (
|
||||
<ThirdwebSDKContext.Provider value={sdk}>
|
||||
{children}
|
||||
</ThirdwebSDKContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const ThirdwebSDKContext = createContext<ThirdwebSDK | null>(null);
|
||||
@@ -1,5 +1,14 @@
|
||||
# @thirdweb-dev/sdk
|
||||
|
||||
## 3.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#195](https://github.com/thirdweb-dev/js/pull/195) [`a80fc97`](https://github.com/thirdweb-dev/js/commit/a80fc97b6a1e72ed46a400b4b602e180947fb870) Thanks [@jnsdls](https://github.com/jnsdls)! - add missing roles for pre-built contracts
|
||||
|
||||
- Updated dependencies [[`24f66e3`](https://github.com/thirdweb-dev/js/commit/24f66e38c256f7bd69341b92ba30bd35d14b1caa)]:
|
||||
- @thirdweb-dev/storage@1.0.3
|
||||
|
||||
## 3.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/sdk",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.6",
|
||||
"description": "The main thirdweb SDK.",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
|
||||
"license": "Apache-2.0",
|
||||
@@ -20,7 +20,8 @@
|
||||
"build": "tsc && preconstruct build",
|
||||
"test:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000 --parallel './test/**/*.test.ts'",
|
||||
"test": "make test",
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000"
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
||||
|
||||
@@ -88,7 +88,7 @@ export const MultiwrapInitializer = {
|
||||
name: "Multiwrap" as const,
|
||||
contractType: "multiwrap" as const,
|
||||
schema: MultiwrapContractSchema,
|
||||
roles: ["transfer", "minter", "unwrap", "asset"] as const,
|
||||
roles: ["admin", "transfer", "minter", "unwrap", "asset"] as const,
|
||||
initialize: async (
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
) => {
|
||||
@@ -149,7 +149,7 @@ export const PackInitializer = {
|
||||
name: "Pack" as const,
|
||||
contractType: "pack" as const,
|
||||
schema: PackContractSchema,
|
||||
roles: ["admin", "minter", "pauser", "transfer"] as const,
|
||||
roles: ["admin", "minter", "asset", "transfer"] as const,
|
||||
|
||||
initialize: async (
|
||||
...[network, address, storage, options]: InitalizeParams
|
||||
|
||||
@@ -51,7 +51,13 @@ import { BigNumberish, CallOverrides, ethers } from "ethers";
|
||||
* @beta
|
||||
*/
|
||||
export class Multiwrap extends StandardErc721<MultiwrapContract> {
|
||||
static contractRoles = ["transfer", "minter", "unwrap", "asset"] as const;
|
||||
static contractRoles = [
|
||||
"admin",
|
||||
"transfer",
|
||||
"minter",
|
||||
"unwrap",
|
||||
"asset",
|
||||
] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
public encoder: ContractEncoder<MultiwrapContract>;
|
||||
|
||||
@@ -57,7 +57,7 @@ import { BigNumber, BigNumberish, CallOverrides, ethers } from "ethers";
|
||||
* @public
|
||||
*/
|
||||
export class Pack extends StandardErc1155<PackContract> {
|
||||
static contractRoles = ["admin", "minter", "pauser", "transfer"] as const;
|
||||
static contractRoles = ["admin", "minter", "asset", "transfer"] as const;
|
||||
|
||||
public abi: typeof ABI;
|
||||
public metadata: ContractMetadata<PackContract, typeof PackContractSchema>;
|
||||
@@ -712,4 +712,4 @@ export class Pack extends StandardErc1155<PackContract> {
|
||||
): Promise<any> {
|
||||
return this.contractWrapper.call(functionName, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @thirdweb-dev/solana
|
||||
|
||||
## 0.2.14
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`24f66e3`](https://github.com/thirdweb-dev/js/commit/24f66e38c256f7bd69341b92ba30bd35d14b1caa)]:
|
||||
- @thirdweb-dev/storage@1.0.3
|
||||
|
||||
## 0.2.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/solana",
|
||||
"version": "0.2.13",
|
||||
"version": "0.2.14",
|
||||
"description": "thirdweb Solana SDK",
|
||||
"main": "dist/thirdweb-dev-solana.cjs.js",
|
||||
"module": "dist/thirdweb-dev-solana.esm.js",
|
||||
@@ -18,7 +18,8 @@
|
||||
"node:stop": "amman stop",
|
||||
"test:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000 --parallel './test/**/*.test.ts'",
|
||||
"test": "make test",
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000"
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
|
||||
@@ -14,6 +14,8 @@ export * from "./types/index";
|
||||
export * from "./types/common";
|
||||
export * from "./types/contracts";
|
||||
export * from "./types/contracts/nft-drop";
|
||||
// utils
|
||||
export * from "./utils/urls";
|
||||
|
||||
//schema for dashboard use
|
||||
export {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @thirdweb-dev/storage
|
||||
|
||||
## 1.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#192](https://github.com/thirdweb-dev/js/pull/192) [`24f66e3`](https://github.com/thirdweb-dev/js/commit/24f66e38c256f7bd69341b92ba30bd35d14b1caa) Thanks [@adam-maj](https://github.com/adam-maj)! - Use XHR for upload
|
||||
|
||||
## 1.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@thirdweb-dev/storage",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"main": "dist/thirdweb-dev-storage.cjs.js",
|
||||
"module": "dist/thirdweb-dev-storage.esm.js",
|
||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/storage",
|
||||
@@ -15,7 +15,8 @@
|
||||
"build": "tsc && preconstruct build",
|
||||
"test:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000 --parallel './test/**/*.test.ts'",
|
||||
"test": "yarn test:all",
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000"
|
||||
"test:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --timeout 30000",
|
||||
"push": "yalc push"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
|
||||
@@ -183,41 +183,102 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
let timer = setTimeout(() => {
|
||||
xhr.abort();
|
||||
reject(
|
||||
new Error(
|
||||
"Request to upload timed out! No upload progress received in 30s",
|
||||
),
|
||||
);
|
||||
}, 30000);
|
||||
|
||||
xhr.upload.addEventListener("loadstart", () => {
|
||||
console.log(`[${Date.now()}] [IPFS] Started`);
|
||||
});
|
||||
|
||||
xhr.upload.addEventListener("progress", (event) => {
|
||||
console.log(`[IPFS] Progress Event ${event.loaded}/${event.total}`);
|
||||
|
||||
clearTimeout(timer);
|
||||
|
||||
if (event.loaded < event.total) {
|
||||
timer = setTimeout(() => {
|
||||
xhr.abort();
|
||||
reject(
|
||||
new Error(
|
||||
"Request to upload timed out! No upload progress received in 30s",
|
||||
),
|
||||
);
|
||||
}, 30000);
|
||||
} else {
|
||||
console.log(
|
||||
`[${Date.now()}] [IPFS] Uploaded files. Waiting for response.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (event.lengthComputable && options?.onProgress) {
|
||||
options?.onProgress({
|
||||
progress: event.loaded,
|
||||
total: event.total,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener("load", () => {
|
||||
console.log(`[${Date.now()}] [IPFS] Load`);
|
||||
clearTimeout(timer);
|
||||
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(xhr.responseText);
|
||||
} catch (err) {
|
||||
return reject(
|
||||
new Error("Failed to parse JSON from upload response"),
|
||||
);
|
||||
}
|
||||
|
||||
const cid = body.IpfsHash;
|
||||
if (!cid) {
|
||||
throw new Error("Failed to get IPFS hash from upload response");
|
||||
}
|
||||
|
||||
if (options?.uploadWithoutDirectory) {
|
||||
return resolve([`ipfs://${cid}`]);
|
||||
} else {
|
||||
return resolve(fileNames.map((name) => `ipfs://${cid}/${name}`));
|
||||
}
|
||||
}
|
||||
|
||||
return reject(
|
||||
new Error(
|
||||
`Upload failed with status ${xhr.status} - ${xhr.responseText}`,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
xhr.addEventListener("error", () => {
|
||||
console.log("[IPFS] Load");
|
||||
clearTimeout(timer);
|
||||
|
||||
if (
|
||||
(xhr.readyState !== 0 && xhr.readyState !== 4) ||
|
||||
xhr.status === 0
|
||||
) {
|
||||
return reject(
|
||||
new Error(
|
||||
"This looks like a network error, the endpoint might be blocked by an internet provider or a firewall.",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return reject(new Error("Unknown upload error occured"));
|
||||
});
|
||||
|
||||
xhr.open("POST", PINATA_IPFS_URL);
|
||||
xhr.setRequestHeader("Authorization", `Bearer ${token}`);
|
||||
|
||||
xhr.onloadend = () => {
|
||||
if (xhr.status !== 200) {
|
||||
throw new Error("Failed to upload files to IPFS");
|
||||
}
|
||||
|
||||
const cid = JSON.parse(xhr.responseText).IpfsHash;
|
||||
if (!cid) {
|
||||
throw new Error("Failed to upload files to IPFS");
|
||||
}
|
||||
|
||||
if (options?.uploadWithoutDirectory) {
|
||||
resolve([`ipfs://${cid}`]);
|
||||
} else {
|
||||
resolve(fileNames.map((name) => `ipfs://${cid}/${name}`));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = (err) => {
|
||||
reject(err);
|
||||
};
|
||||
|
||||
if (xhr.upload) {
|
||||
xhr.upload.onprogress = (event) => {
|
||||
if (options?.onProgress) {
|
||||
options?.onProgress({
|
||||
progress: event.loaded,
|
||||
total: event.total,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
xhr.send(form as any);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@
|
||||
},
|
||||
"clean": {
|
||||
"cache": false
|
||||
},
|
||||
"push": {
|
||||
"cache": false,
|
||||
"dependsOn": ["build"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user