Skip to content

Conversation

@cxalem
Copy link

@cxalem cxalem commented Sep 10, 2025

… owner

  • Introduced a new hook useTokenAccountsByOwner to retrieve token accounts associated with a specific owner address, with optional filtering by token mint and zero balance inclusion.
  • Updated the hooks index to export the new hook.

Problem

Based on this issue #167

Summary of Changes

Commit Summary

Added useTokenAccountsByOwner React Hook

  • What: New hook to fetch token accounts owned by a specific address
  • Key features:
    • Get all token accounts for an owner
    • Filter by specific token mint (optional)
    • Include/exclude zero balance accounts
  • Files: Added new hook file + updated exports
  • Size: 152 lines of code

Fixes #

Usage examples:

// All token accounts
useTokenAccountsByOwner({ owner: address })

// Specific token only
useTokenAccountsByOwner({ owner: address, tokenMint: "USDC_ADDRESS" })

@changeset-bot
Copy link

changeset-bot bot commented Sep 10, 2025

⚠️ No Changeset found

Latest commit: 2eed665

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator

@tobeycodes tobeycodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I did not check out the branch locally to test it but I left some of my thoughts for your review

… owner

- Introduced a new hook `useTokenAccountsByOwner` to retrieve token accounts associated with a specific owner address, with optional filtering by token mint and zero balance inclusion.
- Updated the hooks index to export the new hook.

# Conflicts:
#	packages/react/src/hooks/index.ts
…type

- Introduced a new utility type `ExistingAccount` to better represent on-chain accounts.
- Updated the `account` property in `TokenAccountWithAddress` to use the new type.
- Simplified the query function by removing unnecessary error handling and improving account processing logic.
@cxalem cxalem marked this pull request as ready for review September 17, 2025 19:56
Comment on lines +138 to +141
return {
accounts: allAccounts,
total: allAccounts.length,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request: this should be return accounts;


return {
...rest,
accounts: (data as TokenAccountsQueryResult<TAddress> | undefined)?.accounts || [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request: this should be accounts: data

@nickfrosty
Copy link
Collaborator

Same comment I made here, except #193 is now merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants