Skip to content

Commit 7f08161

Browse files
[SDK] Expose useInvalidateBalances() (#8373)
1 parent 881c7a9 commit 7f08161

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

.changeset/clever-horses-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Respect from address when simulating with Engine.serverWallet

.changeset/curvy-pillows-return.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Expose useInvalidateBalances() react hook

packages/thirdweb/src/engine/server-wallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ export function serverWallet(options: ServerWalletOptions): ServerWallet {
332332
if (args.simulate) {
333333
serializedTransaction = await toSerializableTransaction({
334334
transaction: args.transaction,
335+
from: address,
335336
});
336337
} else {
337338
const [to, data, value] = await Promise.all([

packages/thirdweb/src/exports/react.native.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export { useContractEvents } from "../react/core/hooks/contract/useContractEvent
2222
// contract
2323
export { useReadContract } from "../react/core/hooks/contract/useReadContract.js";
2424
export { useWaitForReceipt } from "../react/core/hooks/contract/useWaitForReceipt.js";
25+
export { useInvalidateBalances } from "../react/core/hooks/others/useInvalidateBalances.js";
2526
export { useInvalidateContractQuery } from "../react/core/hooks/others/useInvalidateQueries.js";
2627
export { useWalletBalance } from "../react/core/hooks/others/useWalletBalance.js";
2728
export {

packages/thirdweb/src/exports/react.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export { useReadContract } from "../react/core/hooks/contract/useReadContract.js
2929
export { useWaitForReceipt } from "../react/core/hooks/contract/useWaitForReceipt.js";
3030
// chain hooks
3131
export { useChainMetadata } from "../react/core/hooks/others/useChainQuery.js";
32+
export { useInvalidateBalances } from "../react/core/hooks/others/useInvalidateBalances.js";
3233
export { useInvalidateContractQuery } from "../react/core/hooks/others/useInvalidateQueries.js";
3334
export { useWalletBalance } from "../react/core/hooks/others/useWalletBalance.js";
3435
export {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useQueryClient } from "@tanstack/react-query";
2+
import { invalidateWalletBalance } from "../../providers/invalidateWalletBalance.js";
3+
4+
/**
5+
* Invalidate the balances for a given chainId. If no chainId is provided, invalidate all balances.
6+
* @example
7+
* ```ts
8+
* const invalidateBalances = useInvalidateBalances();
9+
* invalidateBalances();
10+
* ```
11+
*/
12+
export function useInvalidateBalances() {
13+
const queryClient = useQueryClient();
14+
15+
return ({ chainId }: { chainId?: number }) => {
16+
invalidateWalletBalance(queryClient, chainId);
17+
};
18+
}

0 commit comments

Comments
 (0)