Skip to content

Commit

Permalink
docs: improve chron-feed example, upgrade @Farcaster packages in exam…
Browse files Browse the repository at this point in the history
…ples (#1126)

* docs: fix chronfeed example

* bump farcaster package versions in examples

* run linter
  • Loading branch information
deodad authored Jul 13, 2023
1 parent a0dbfbd commit 1fd9b2b
Show file tree
Hide file tree
Showing 12 changed files with 435 additions and 1,283 deletions.
29 changes: 14 additions & 15 deletions packages/hub-nodejs/examples/chron-feed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ const getPrimaryCastsByFid = async (fid: number, client: HubRpcClient): HubAsync

const getFnameFromFid = async (fid: number, client: HubRpcClient): HubAsyncResult<string> => {
const result = await client.getUserData({ fid: fid, userDataType: UserDataType.USERNAME });
return result.map((message) => {
if (isUserDataAddMessage(message)) {
return message.data.userDataBody.value;
} else {
return "";
}
});
return ok(
result.match(
(message) => {
if (isUserDataAddMessage(message)) {
return message.data.userDataBody.value;
} else {
return "";
}
},
() => `${fid}!`, // fallback to FID if no username is set
),
);
};

/**
Expand All @@ -67,7 +72,7 @@ const compareCasts = (a: CastAddMessage, b: CastAddMessage) => {
* Converts a CastAddMessage into a printable string representation.
*/
const castToString = async (cast: CastAddMessage, nameMapping: Map<number, string>, client: HubRpcClient) => {
const fname = nameMapping.get(cast.data.fid);
const fname = nameMapping.get(cast.data.fid) ?? `${cast.data.fid}!`; // if the user doesn't have a username set, use their FID

// Convert the timestamp to a human readable string
// Safety: OK to do this since we know the timestamp coming from the Hub must be in the valid range
Expand Down Expand Up @@ -104,13 +109,7 @@ const castToString = async (cast: CastAddMessage, nameMapping: Map<number, strin
const fidToFname = new Map<number, string>();

const fnameResultPromises = FIDS.map((fid) => client.getUserData({ fid, userDataType: UserDataType.USERNAME }));
const fnameResults = Result.combine(await Promise.all(fnameResultPromises));

if (fnameResults.isErr()) {
console.error("Fetching fnames failed");
console.error(fnameResults.error);
return;
}
const fnameResults = await Promise.all(fnameResultPromises);

fnameResults.map((result) =>
result.map((uData) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/hub-nodejs/examples/chron-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"version": "0.0.0",
"main": "index.ts",
"scripts": {
"start": "tsx index.ts"
"start": "tsx index.ts",
"typecheck": "yarn tsc --noEmit"
},
"dependencies": {
"@farcaster/hub-nodejs": "^0.7.0",
"@farcaster/hub-nodejs": "^0.8.4",
"javascript-time-ago": "^2.5.9"
},
"devDependencies": {
Expand Down
332 changes: 92 additions & 240 deletions packages/hub-nodejs/examples/chron-feed/yarn.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/hub-nodejs/examples/make-cast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"version": "0.0.0",
"main": "index.ts",
"scripts": {
"start": "tsx index.ts"
"start": "tsx index.ts",
"typecheck": "yarn tsc --noEmit"
},
"dependencies": {
"@farcaster/hub-nodejs": "^0.7.0"
"@farcaster/hub-nodejs": "^0.8.4"
},
"devDependencies": {
"tsx": "^3.12.5",
Expand Down
Loading

0 comments on commit 1fd9b2b

Please sign in to comment.