From dbc8b5b892652d7a241e612e82830f52fe4e62f8 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Fri, 7 Nov 2025 12:33:23 +1300 Subject: [PATCH] [Engine] Add from address to serializable transaction --- .changeset/clever-horses-turn.md | 5 +++++ .changeset/curvy-pillows-return.md | 5 +++++ packages/thirdweb/src/engine/server-wallet.ts | 1 + packages/thirdweb/src/exports/react.native.ts | 1 + packages/thirdweb/src/exports/react.ts | 1 + .../core/hooks/others/useInvalidateBalances.ts | 18 ++++++++++++++++++ 6 files changed, 31 insertions(+) create mode 100644 .changeset/clever-horses-turn.md create mode 100644 .changeset/curvy-pillows-return.md create mode 100644 packages/thirdweb/src/react/core/hooks/others/useInvalidateBalances.ts diff --git a/.changeset/clever-horses-turn.md b/.changeset/clever-horses-turn.md new file mode 100644 index 00000000000..c6a4a41b976 --- /dev/null +++ b/.changeset/clever-horses-turn.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Respect from address when simulating with Engine.serverWallet diff --git a/.changeset/curvy-pillows-return.md b/.changeset/curvy-pillows-return.md new file mode 100644 index 00000000000..f8b5921e4f9 --- /dev/null +++ b/.changeset/curvy-pillows-return.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Expose useInvalidateBalances() react hook diff --git a/packages/thirdweb/src/engine/server-wallet.ts b/packages/thirdweb/src/engine/server-wallet.ts index 7009c648581..69f935c22aa 100644 --- a/packages/thirdweb/src/engine/server-wallet.ts +++ b/packages/thirdweb/src/engine/server-wallet.ts @@ -332,6 +332,7 @@ export function serverWallet(options: ServerWalletOptions): ServerWallet { if (args.simulate) { serializedTransaction = await toSerializableTransaction({ transaction: args.transaction, + from: address, }); } else { const [to, data, value] = await Promise.all([ diff --git a/packages/thirdweb/src/exports/react.native.ts b/packages/thirdweb/src/exports/react.native.ts index 3414052b05a..3a59ddc4902 100644 --- a/packages/thirdweb/src/exports/react.native.ts +++ b/packages/thirdweb/src/exports/react.native.ts @@ -22,6 +22,7 @@ export { useContractEvents } from "../react/core/hooks/contract/useContractEvent // contract export { useReadContract } from "../react/core/hooks/contract/useReadContract.js"; export { useWaitForReceipt } from "../react/core/hooks/contract/useWaitForReceipt.js"; +export { useInvalidateBalances } from "../react/core/hooks/others/useInvalidateBalances.js"; export { useInvalidateContractQuery } from "../react/core/hooks/others/useInvalidateQueries.js"; export { useWalletBalance } from "../react/core/hooks/others/useWalletBalance.js"; export { diff --git a/packages/thirdweb/src/exports/react.ts b/packages/thirdweb/src/exports/react.ts index 337fd0d60f8..c7b12cf5b9d 100644 --- a/packages/thirdweb/src/exports/react.ts +++ b/packages/thirdweb/src/exports/react.ts @@ -29,6 +29,7 @@ export { useReadContract } from "../react/core/hooks/contract/useReadContract.js export { useWaitForReceipt } from "../react/core/hooks/contract/useWaitForReceipt.js"; // chain hooks export { useChainMetadata } from "../react/core/hooks/others/useChainQuery.js"; +export { useInvalidateBalances } from "../react/core/hooks/others/useInvalidateBalances.js"; export { useInvalidateContractQuery } from "../react/core/hooks/others/useInvalidateQueries.js"; export { useWalletBalance } from "../react/core/hooks/others/useWalletBalance.js"; export { diff --git a/packages/thirdweb/src/react/core/hooks/others/useInvalidateBalances.ts b/packages/thirdweb/src/react/core/hooks/others/useInvalidateBalances.ts new file mode 100644 index 00000000000..67b95698b69 --- /dev/null +++ b/packages/thirdweb/src/react/core/hooks/others/useInvalidateBalances.ts @@ -0,0 +1,18 @@ +import { useQueryClient } from "@tanstack/react-query"; +import { invalidateWalletBalance } from "../../providers/invalidateWalletBalance.js"; + +/** + * Invalidate the balances for a given chainId. If no chainId is provided, invalidate all balances. + * @example + * ```ts + * const invalidateBalances = useInvalidateBalances(); + * invalidateBalances(); + * ``` + */ +export function useInvalidateBalances() { + const queryClient = useQueryClient(); + + return ({ chainId }: { chainId?: number }) => { + invalidateWalletBalance(queryClient, chainId); + }; +}