Skip to content

Commit

Permalink
documentation(hub-web): Added getFnameFromFid to readme (#2433)
Browse files Browse the repository at this point in the history
## Why is this change needed?

Since changes were requested in docs
(farcasterxyz/docs#54), I have made a PR to
update Farcaster's docs (farcasterxyz/docs#356),
thus decided to update the readme file.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time
before submitting for review_

- [ ] PR title adheres to the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [ ] PR has a
[changeset](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#35-adding-changesets)
- [x] PR has been tagged with a change label(s) (i.e. documentation,
feature, bugfix, or chore)
- [ ] PR includes
[documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs)
if necessary.


<!-- start pr-codex -->

---

## PR-Codex overview
This PR adds a new function for retrieving a user's first name using
their FID from the `HubRpcClient`.

### Detailed summary
- Introduced a new function `getFnameFromFid`.
- The function takes `fid` (number) and `client` (`HubRpcClient`) as
parameters.
- It retrieves user data of type `UserDataType.FNAME`.
- Returns the user's first name or an empty string if not found.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
SVell authored Dec 12, 2024
1 parent 07831bc commit 03457c2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/hub-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ try {
}
```

### Get the username by FID

```typescript
const getFnameFromFid = async (
fid: number,
client: HubRpcClient
): HubAsyncResult<string> => {
const result = await client.getUserData({
fid: fid,
userDataType: UserDataType.FNAME,
});
return result.map((message) => {
if (isUserDataAddMessage(message)) {
return message.data.userDataBody.value;
} else {
return '';
}
});
};
```

### Running the examples

There are several examples in the `examples/` folder. To run the examples, please look at the individual README files in the examples directory. Most examples can be run by
Expand Down

0 comments on commit 03457c2

Please sign in to comment.