From a1b99515a404ca62ac1aae6ca3a17987689f1647 Mon Sep 17 00:00:00 2001 From: Rinat Date: Wed, 16 Oct 2024 16:12:19 +0200 Subject: [PATCH 1/2] Update usehooks-ts, remove use-debounce (#957) --- packages/nextjs/hooks/scaffold-eth/index.ts | 1 - .../hooks/scaffold-eth/useBurnerWallet.ts | 146 ------------------ packages/nextjs/package.json | 3 +- yarn.lock | 20 +-- 4 files changed, 6 insertions(+), 164 deletions(-) delete mode 100644 packages/nextjs/hooks/scaffold-eth/useBurnerWallet.ts diff --git a/packages/nextjs/hooks/scaffold-eth/index.ts b/packages/nextjs/hooks/scaffold-eth/index.ts index 6effb7edd..084ccc852 100644 --- a/packages/nextjs/hooks/scaffold-eth/index.ts +++ b/packages/nextjs/hooks/scaffold-eth/index.ts @@ -1,5 +1,4 @@ export * from "./useAnimationConfig"; -export * from "./useBurnerWallet"; export * from "./useContractLogs"; export * from "./useDeployedContractInfo"; export * from "./useFetchBlocks"; diff --git a/packages/nextjs/hooks/scaffold-eth/useBurnerWallet.ts b/packages/nextjs/hooks/scaffold-eth/useBurnerWallet.ts deleted file mode 100644 index 2b8cf8895..000000000 --- a/packages/nextjs/hooks/scaffold-eth/useBurnerWallet.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { useCallback, useEffect, useRef, useState } from "react"; -import { useTargetNetwork } from "./useTargetNetwork"; -import { useLocalStorage } from "usehooks-ts"; -import { Chain, Hex, HttpTransport, PrivateKeyAccount, createWalletClient, http } from "viem"; -import { WalletClient } from "viem"; -import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; -import { usePublicClient } from "wagmi"; - -const burnerStorageKey = "scaffoldEth2.burnerWallet.sk"; - -/** - * Checks if the private key is valid - */ -const isValidSk = (pk: Hex | string | undefined | null): boolean => { - return pk?.length === 64 || pk?.length === 66; -}; - -/** - * If no burner is found in localstorage, we will generate a random private key - */ -const newDefaultPrivateKey = generatePrivateKey(); - -/** - * Save the current burner private key to local storage - */ -export const saveBurnerSK = (privateKey: Hex): void => { - if (typeof window != "undefined" && window != null) { - window?.localStorage?.setItem(burnerStorageKey, privateKey); - } -}; - -/** - * Gets the current burner private key from local storage - */ -export const loadBurnerSK = (): Hex => { - let currentSk: Hex = "0x"; - if (typeof window != "undefined" && window != null) { - currentSk = (window?.localStorage?.getItem?.(burnerStorageKey)?.replaceAll('"', "") ?? "0x") as Hex; - } - - if (!!currentSk && isValidSk(currentSk)) { - return currentSk; - } else { - saveBurnerSK(newDefaultPrivateKey); - return newDefaultPrivateKey; - } -}; - -type BurnerAccount = { - walletClient: WalletClient | undefined; - account: PrivateKeyAccount | undefined; - // creates a new burner account - generateNewBurner: () => void; - // explicitly save burner to storage - saveBurner: () => void; -}; - -/** - * Creates a burner wallet - */ -export const useBurnerWallet = (): BurnerAccount => { - const [burnerSk, setBurnerSk] = useLocalStorage(burnerStorageKey, newDefaultPrivateKey, { - initializeWithValue: false, - }); - - const { targetNetwork } = useTargetNetwork(); - const publicClient = usePublicClient({ chainId: targetNetwork.id }); - const [walletClient, setWalletClient] = useState>(); - const [generatedPrivateKey, setGeneratedPrivateKey] = useState("0x"); - const [account, setAccount] = useState(); - const isCreatingNewBurnerRef = useRef(false); - - const saveBurner = useCallback(() => { - setBurnerSk(generatedPrivateKey); - }, [setBurnerSk, generatedPrivateKey]); - - const generateNewBurner = useCallback(() => { - if (publicClient && !isCreatingNewBurnerRef.current) { - console.log("🔑 Create new burner wallet..."); - isCreatingNewBurnerRef.current = true; - - const randomPrivateKey = generatePrivateKey(); - const randomAccount = privateKeyToAccount(randomPrivateKey); - - const client = createWalletClient({ - chain: publicClient.chain, - account: randomAccount, - transport: http(), - }); - - setWalletClient(client); - setGeneratedPrivateKey(randomPrivateKey); - setAccount(randomAccount); - - setBurnerSk(() => { - console.log("🔥 Saving new burner wallet"); - isCreatingNewBurnerRef.current = false; - return randomPrivateKey; - }); - return client; - } else { - console.log("⚠ Could not create burner wallet"); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [publicClient?.chain.id]); - - /** - * Load wallet with burnerSk - * connect and set wallet, once we have burnerSk and valid provider - */ - useEffect(() => { - if (burnerSk && publicClient?.chain.id) { - let wallet: WalletClient | undefined = undefined; - if (isValidSk(burnerSk)) { - const randomAccount = privateKeyToAccount(burnerSk); - - wallet = createWalletClient({ - chain: publicClient.chain, - account: randomAccount, - transport: http(), - }); - - setGeneratedPrivateKey(burnerSk); - setAccount(randomAccount); - } else { - wallet = generateNewBurner(); - } - - if (wallet == null) { - throw "Error: Could not create burner wallet"; - } - - setWalletClient(wallet); - saveBurner(); - } - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [burnerSk, publicClient?.chain.id]); - - return { - walletClient, - account, - generateNewBurner, - saveBurner, - }; -}; diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 4e69f805c..0b640bf9b 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -30,8 +30,7 @@ "react-copy-to-clipboard": "^5.1.0", "react-dom": "^18.3.1", "react-hot-toast": "^2.4.0", - "use-debounce": "^8.0.4", - "usehooks-ts": "^2.13.0", + "usehooks-ts": "^3.1.0", "viem": "2.21.7", "wagmi": "2.12.11", "zustand": "^4.1.2" diff --git a/yarn.lock b/yarn.lock index 852eb4be7..ed29f3d26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2195,8 +2195,7 @@ __metadata: tailwindcss: ^3.4.11 type-fest: ^4.6.0 typescript: 5.5.3 - use-debounce: ^8.0.4 - usehooks-ts: ^2.13.0 + usehooks-ts: ^3.1.0 vercel: ^37.4.2 viem: 2.21.7 wagmi: 2.12.11 @@ -13502,15 +13501,6 @@ __metadata: languageName: node linkType: hard -"use-debounce@npm:^8.0.4": - version: 8.0.4 - resolution: "use-debounce@npm:8.0.4" - peerDependencies: - react: ">=16.8.0" - checksum: 0f8b9e571f68a4694033ec00690bf73d781ac890140ae9ed4b330f71f7adb3f7d7df5cdaa32923c4d03fdc9de8a11be0f84301175ae4f66208af52ad03c55504 - languageName: node - linkType: hard - "use-sidecar@npm:^1.1.2": version: 1.1.2 resolution: "use-sidecar@npm:1.1.2" @@ -13545,14 +13535,14 @@ __metadata: languageName: node linkType: hard -"usehooks-ts@npm:^2.13.0": - version: 2.13.0 - resolution: "usehooks-ts@npm:2.13.0" +"usehooks-ts@npm:^3.1.0": + version: 3.1.0 + resolution: "usehooks-ts@npm:3.1.0" dependencies: lodash.debounce: ^4.0.8 peerDependencies: react: ^16.8.0 || ^17 || ^18 - checksum: ad07930e1b5c70392603eb8b3f199f44349c75406fe31013f79b0fb7fdece59f47f8dba09b6f1fafaa00d68f43240dbb13cdc1afb89b647f1d53504599a51ca0 + checksum: 4f850c0c5ab408afa52fa2ea2c93c488cd7065c82679eb1fb62cba12ca4c57ff62d52375acc6738823421fe6579ce3adcea1e2dc345ce4f549c593d2e51455b3 languageName: node linkType: hard From 62c4dc973d554332264adc6cefc7f0ae48167288 Mon Sep 17 00:00:00 2001 From: Rinat Date: Thu, 17 Oct 2024 09:19:50 +0200 Subject: [PATCH 2/2] Update other packages (#960) * feat: update other packages * feat: update zustand and react-query --- packages/hardhat/package.json | 8 +-- packages/nextjs/package.json | 10 +-- yarn.lock | 116 ++++++++++++++++------------------ 3 files changed, 63 insertions(+), 71 deletions(-) diff --git a/packages/hardhat/package.json b/packages/hardhat/package.json index 5936d5b0b..1451d284c 100644 --- a/packages/hardhat/package.json +++ b/packages/hardhat/package.json @@ -28,7 +28,7 @@ "@types/eslint": "^8", "@types/mocha": "^10.0.8", "@types/prettier": "^2", - "@types/qrcode": "^1", + "@types/qrcode": "^1.5.5", "@typescript-eslint/eslint-plugin": "latest", "@typescript-eslint/parser": "latest", "chai": "^4.5.0", @@ -43,14 +43,14 @@ "prettier": "^2.8.4", "solidity-coverage": "^0.8.13", "ts-node": "^10.9.1", - "typechain": "^8.1.0", + "typechain": "^8.3.2", "typescript": "^5.1.6" }, "dependencies": { "@openzeppelin/contracts": "^5.0.2", "@typechain/ethers-v6": "^0.5.1", - "dotenv": "^16.0.3", + "dotenv": "^16.4.5", "envfile": "^7.1.0", - "qrcode": "^1.5.1" + "qrcode": "^1.5.4" } } diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 0b640bf9b..32fe569a8 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -16,16 +16,16 @@ "dependencies": { "@heroicons/react": "^2.1.5", "@rainbow-me/rainbowkit": "2.1.6", - "@tanstack/react-query": "^5.28.6", + "@tanstack/react-query": "^5.59.15", "@uniswap/sdk-core": "^5.8.2", "@uniswap/v2-sdk": "^4.6.1", - "blo": "^1.0.1", + "blo": "^1.2.0", "burner-connector": "^0.0.8", "daisyui": "4.12.10", "next": "^14.2.11", "next-nprogress-bar": "^2.3.13", "next-themes": "^0.3.0", - "qrcode.react": "^3.1.0", + "qrcode.react": "^4.0.1", "react": "^18.3.1", "react-copy-to-clipboard": "^5.1.0", "react-dom": "^18.3.1", @@ -33,7 +33,7 @@ "usehooks-ts": "^3.1.0", "viem": "2.21.7", "wagmi": "2.12.11", - "zustand": "^4.1.2" + "zustand": "^5.0.0" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.1.1", @@ -49,7 +49,7 @@ "postcss": "^8.4.45", "prettier": "^2.8.4", "tailwindcss": "^3.4.11", - "type-fest": "^4.6.0", + "type-fest": "^4.26.1", "typescript": "5.5.3", "vercel": "^37.4.2" } diff --git a/yarn.lock b/yarn.lock index ed29f3d26..2e19f62ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2137,11 +2137,11 @@ __metadata: "@types/eslint": ^8 "@types/mocha": ^10.0.8 "@types/prettier": ^2 - "@types/qrcode": ^1 + "@types/qrcode": ^1.5.5 "@typescript-eslint/eslint-plugin": latest "@typescript-eslint/parser": latest chai: ^4.5.0 - dotenv: ^16.0.3 + dotenv: ^16.4.5 envfile: ^7.1.0 eslint: ^8.26.0 eslint-config-prettier: ^8.5.0 @@ -2152,10 +2152,10 @@ __metadata: hardhat-deploy-ethers: ^0.4.2 hardhat-gas-reporter: ^2.2.1 prettier: ^2.8.4 - qrcode: ^1.5.1 + qrcode: ^1.5.4 solidity-coverage: ^0.8.13 ts-node: ^10.9.1 - typechain: ^8.1.0 + typechain: ^8.3.2 typescript: ^5.1.6 languageName: unknown linkType: soft @@ -2166,7 +2166,7 @@ __metadata: dependencies: "@heroicons/react": ^2.1.5 "@rainbow-me/rainbowkit": 2.1.6 - "@tanstack/react-query": ^5.28.6 + "@tanstack/react-query": ^5.59.15 "@trivago/prettier-plugin-sort-imports": ^4.1.1 "@types/node": ^18.19.50 "@types/react": ^18.3.5 @@ -2175,7 +2175,7 @@ __metadata: "@uniswap/v2-sdk": ^4.6.1 abitype: 1.0.6 autoprefixer: ^10.4.20 - blo: ^1.0.1 + blo: ^1.2.0 burner-connector: ^0.0.8 daisyui: 4.12.10 eslint: ^8.15.0 @@ -2187,19 +2187,19 @@ __metadata: next-themes: ^0.3.0 postcss: ^8.4.45 prettier: ^2.8.4 - qrcode.react: ^3.1.0 + qrcode.react: ^4.0.1 react: ^18.3.1 react-copy-to-clipboard: ^5.1.0 react-dom: ^18.3.1 react-hot-toast: ^2.4.0 tailwindcss: ^3.4.11 - type-fest: ^4.6.0 + type-fest: ^4.26.1 typescript: 5.5.3 usehooks-ts: ^3.1.0 vercel: ^37.4.2 viem: 2.21.7 wagmi: 2.12.11 - zustand: ^4.1.2 + zustand: ^5.0.0 languageName: unknown linkType: soft @@ -2493,21 +2493,21 @@ __metadata: languageName: node linkType: hard -"@tanstack/query-core@npm:5.28.6": - version: 5.28.6 - resolution: "@tanstack/query-core@npm:5.28.6" - checksum: 2d8406e707fe36a72a90fd0f4f2975bb14b0546c9d39574e0b70a2e52e49f12bff44f6610a0c15a526c0b0561b18c65987602e4ad3ea3fd767502bb938985f88 +"@tanstack/query-core@npm:5.59.13": + version: 5.59.13 + resolution: "@tanstack/query-core@npm:5.59.13" + checksum: 2f43f53ecd0151c9f83f822f47a8c882cce234ece2fa4fc575ae1bf865094ff145f5efe7cb9c750541df143804941248aceaf85e7c5346a7897d896845996dff languageName: node linkType: hard -"@tanstack/react-query@npm:^5.28.6": - version: 5.28.6 - resolution: "@tanstack/react-query@npm:5.28.6" +"@tanstack/react-query@npm:^5.59.15": + version: 5.59.15 + resolution: "@tanstack/react-query@npm:5.59.15" dependencies: - "@tanstack/query-core": 5.28.6 + "@tanstack/query-core": 5.59.13 peerDependencies: - react: ^18.0.0 - checksum: a920991b62b2bd7f91f8a8a4377a7f50c28c60979535dad33f45d15aa865d481956724493341e8343ca71dbaf00e9ed7cefb782d5460a7447ce39125a66f869f + react: ^18 || ^19 + checksum: 465aa2cdfc83fe3ebbb3dfe94ad39ac9e047e6808890b9dfd253d7aec31cdc46198af3c3a8dfa6a7212f941db7df1fe9a724540504cc2e3efa1cdffcb2d48164 languageName: node linkType: hard @@ -2794,12 +2794,12 @@ __metadata: languageName: node linkType: hard -"@types/qrcode@npm:^1": - version: 1.5.2 - resolution: "@types/qrcode@npm:1.5.2" +"@types/qrcode@npm:^1.5.5": + version: 1.5.5 + resolution: "@types/qrcode@npm:1.5.5" dependencies: "@types/node": "*" - checksum: 2f696916e66002ecf0616451a44308b33948ce68f7ee1eae0ff8a4acc133024a3d9a7314e9dcb6455ab7f7e126963c204a687a665e3688ba39ec4ae80eb30670 + checksum: d92c1d3e77406bf13a03ec521b2ffb1ac99b2e6ea3a17cad670f2610f62e1293554c57e4074bb2fd4e9369f475f863b69e0ae8c543cb049c4a3c1b0c2d92522a languageName: node linkType: hard @@ -4529,10 +4529,10 @@ __metadata: languageName: node linkType: hard -"blo@npm:^1.0.1": - version: 1.1.1 - resolution: "blo@npm:1.1.1" - checksum: 896183e4ff43e8ebfc89153f6772e510d8f4566ef25e6bebb7e31531e1059c0517bc23d2d605758c9e5ea0c62c21203172575625a53748d013ed78ace08f30f4 +"blo@npm:^1.2.0": + version: 1.2.0 + resolution: "blo@npm:1.2.0" + checksum: be7dc5f3047d538c0038b469c309440e5b7de872ee811cc7ca97005b6b534a01dbf461150145f2f09524aeda6923197ea31290fbe9865cb8cb32152b3caf3dc7 languageName: node linkType: hard @@ -5779,10 +5779,10 @@ __metadata: languageName: node linkType: hard -"dotenv@npm:^16.0.3": - version: 16.3.1 - resolution: "dotenv@npm:16.3.1" - checksum: 15d75e7279018f4bafd0ee9706593dd14455ddb71b3bcba9c52574460b7ccaf67d5cf8b2c08a5af1a9da6db36c956a04a1192b101ee102a3e0cf8817bbcf3dfd +"dotenv@npm:^16.4.5": + version: 16.4.5 + resolution: "dotenv@npm:16.4.5" + checksum: 301a12c3d44fd49888b74eb9ccf9f07a1f5df43f489e7fcb89647a2edcd84c42d6bc349dc8df099cd18f07c35c7b04685c1a4f3e6a6a9e6b30f8d48c15b7f49c languageName: node linkType: hard @@ -11169,16 +11169,16 @@ __metadata: languageName: node linkType: hard -"qrcode.react@npm:^3.1.0": - version: 3.1.0 - resolution: "qrcode.react@npm:3.1.0" +"qrcode.react@npm:^4.0.1": + version: 4.0.1 + resolution: "qrcode.react@npm:4.0.1" peerDependencies: react: ^16.8.0 || ^17.0.0 || ^18.0.0 - checksum: 94a2942ecf83f461d869adb20305ae663c6d1abe93ef2c72442b07d756ce70cf6deb6fd588dc5b382b48c6991cfde1dfd5ac9b814c1461e71d5edb2d945e67fc + checksum: 947728a991a4b7b3e2722c20334d47622f689b482114a2f95a2befe6c985d8205b0a4a0ac68bf35514bdb7c192748a14e0cf7b07df6fcc005032b8db6d342dd9 languageName: node linkType: hard -"qrcode@npm:1.5.3, qrcode@npm:^1.5.1": +"qrcode@npm:1.5.3": version: 1.5.3 resolution: "qrcode@npm:1.5.3" dependencies: @@ -11192,7 +11192,7 @@ __metadata: languageName: node linkType: hard -"qrcode@npm:1.5.4": +"qrcode@npm:1.5.4, qrcode@npm:^1.5.4": version: 1.5.4 resolution: "qrcode@npm:1.5.4" dependencies: @@ -13092,16 +13092,16 @@ __metadata: languageName: node linkType: hard -"type-fest@npm:^4.6.0": - version: 4.9.0 - resolution: "type-fest@npm:4.9.0" - checksum: 73383de23237b399a70397a53101152548846d919aebcc7d8733000c6c354dc2632fe37c4a70b8571b79fdbfa099e2d8304c5ac56b3254780acff93e4c7a797f +"type-fest@npm:^4.26.1": + version: 4.26.1 + resolution: "type-fest@npm:4.26.1" + checksum: 7188db3bca82afa62c69a8043fb7c5eb74e63c45e7e28efb986da1629d844286f7181bc5a8185f38989fffff0d6c96be66fd13529b01932d1b6ebe725181d31a languageName: node linkType: hard -"typechain@npm:^8.1.0": - version: 8.3.1 - resolution: "typechain@npm:8.3.1" +"typechain@npm:^8.3.2": + version: 8.3.2 + resolution: "typechain@npm:8.3.2" dependencies: "@types/prettier": ^2.1.1 debug: ^4.3.1 @@ -13117,7 +13117,7 @@ __metadata: typescript: ">=4.3.0" bin: typechain: dist/cli/cli.js - checksum: c1e11ab1452d0c83be0c34a8b900b156b0c6654b95f7e7bb18dd98c0decd6009ffa1316e393f4e8def187af1bea3e931a13503815cc37155c0c945b7ae5b5215 + checksum: 146a1896fa93403404be78757790b0f95b5457efebcca16b61622e09c374d555ef4f837c1c4eedf77e03abc50276d96a2f33064ec09bb802f62d8cc2b13fce70 languageName: node linkType: hard @@ -13526,15 +13526,6 @@ __metadata: languageName: node linkType: hard -"use-sync-external-store@npm:1.2.2": - version: 1.2.2 - resolution: "use-sync-external-store@npm:1.2.2" - peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - checksum: fe07c071c4da3645f112c38c0e57beb479a8838616ff4e92598256ecce527f2888c08febc7f9b2f0ce2f0e18540ba3cde41eb2035e4fafcb4f52955037098a81 - languageName: node - linkType: hard - "usehooks-ts@npm:^3.1.0": version: 3.1.0 resolution: "usehooks-ts@npm:3.1.0" @@ -14339,15 +14330,14 @@ __metadata: languageName: node linkType: hard -"zustand@npm:^4.1.2": - version: 4.5.5 - resolution: "zustand@npm:4.5.5" - dependencies: - use-sync-external-store: 1.2.2 +"zustand@npm:^5.0.0": + version: 5.0.0 + resolution: "zustand@npm:5.0.0" peerDependencies: - "@types/react": ">=16.8" + "@types/react": ">=18.0.0" immer: ">=9.0.6" - react: ">=16.8" + react: ">=18.0.0" + use-sync-external-store: ">=1.2.0" peerDependenciesMeta: "@types/react": optional: true @@ -14355,6 +14345,8 @@ __metadata: optional: true react: optional: true - checksum: 654e47959970bc66bbf2ae80fced7e556dd488e9ee54eb678330cb036ecc7184f4b8c2cae273be28022533622c54ab6339bf3fe30d19236367c5c251b6c6679a + use-sync-external-store: + optional: true + checksum: dc7414de234f9d2c0afad472d6971e9ac32281292faa8ee0910521cad063f84eeeb6f792efab068d6750dab5854fb1a33ac6e9294b796925eb680a59fc1b42f9 languageName: node linkType: hard