Skip to content

Commit

Permalink
wip: standarize userId vs userAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
hthieu1110 committed Aug 10, 2023
1 parent ae88cfc commit 8ac1c27
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions packages/components/socialFeed/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Post, Reaction } from "../../api/feed/v1/feed";
import { getUserId } from "../../networks";

export const decodeGnoPost = (postData: string): Post => {
export const decodeGnoPost = (networkId: string, postData: string): Post => {
const buf = Buffer.from(postData, "base64");

let offset = 0;
Expand Down Expand Up @@ -31,7 +32,7 @@ export const decodeGnoPost = (postData: string): Post => {

const addrLen = buf.readUInt16BE(offset);
offset += 2;
const authorId = buf.slice(offset, offset + addrLen).toString();
const authorAddress = buf.slice(offset, offset + addrLen).toString();
offset += addrLen;

const createdAt = buf.readUInt32BE(offset);
Expand Down Expand Up @@ -70,7 +71,7 @@ export const decodeGnoPost = (postData: string): Post => {
metadata,
parentPostIdentifier: parentPostIdentifier ? "" + parentPostIdentifier : "",
subPostLength: subpostIDs.length,
authorId,
authorId: getUserId(networkId, authorAddress),
createdAt: +createdAt * 1000,
tipAmount: 0,
reactions,
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/feed/useFetchComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const fetchGnoComments = async (

const outputStr = extractGnoString(output);
for (const postData of outputStr.split(",")) {
const post = decodeGnoPost(postData);
const post = decodeGnoPost(selectedNetwork.id, postData);

posts.push({
identifier: post.identifier,
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/feed/useFetchFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const fetchGnoFeed = async (

const outputStr = extractGnoString(output);
for (const postData of outputStr.split(",")) {
const post = decodeGnoPost(postData);
const post = decodeGnoPost(selectedNetwork.id, postData);
posts.push(post);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/hooks/feed/usePost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Post } from "../../api/feed/v1/feed";
import { nonSigningSocialFeedClient } from "../../client-creators/socialFeedClient";
import { GNO_SOCIAL_FEEDS_PKG_PATH } from "../../components/socialFeed/const";
import { decodeGnoPost } from "../../components/socialFeed/utils";
import { NetworkKind, getNetwork } from "../../networks";
import { NetworkKind, getNetwork, getUserId } from "../../networks";
import { extractGnoString } from "../../utils/gno";

export const usePost = (id: string, networkId: string) => {
Expand All @@ -21,7 +21,7 @@ export const usePost = (id: string, networkId: string) => {
);

const postData = extractGnoString(output);
const post = decodeGnoPost(postData);
const post = decodeGnoPost(networkId, postData);
return post;
} else {
const client = await nonSigningSocialFeedClient({
Expand All @@ -31,12 +31,12 @@ export const usePost = (id: string, networkId: string) => {

const post: Post = {
identifier: id,
parentPostIdentifier: res.parent_post_identifier,
parentPostIdentifier: res.parent_post_identifier || "",
category: res.category,
metadata: res.metadata,
reactions: res.user_reactions,
authorId: res.post_by,
isDeleted: res.delete,
reactions: res.reactions,
authorId: getUserId(networkId, res.post_by),
isDeleted: res.deleted,
subPostLength: res.sub_post_length,
createdAt: res.created_at,
tipAmount: res.tip_amount,
Expand Down
5 changes: 3 additions & 2 deletions packages/screens/FeedPostView/FeedPostViewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { useIsMobile } from "../../hooks/useIsMobile";
import { useMaxResolution } from "../../hooks/useMaxResolution";
import { useNSUserInfo } from "../../hooks/useNSUserInfo";
import { useSelectedNetworkId } from "../../hooks/useSelectedNetwork";
import { NetworkFeature, getUserId, parseUserId } from "../../networks";
import { NetworkFeature, parseUserId } from "../../networks";
import { ScreenFC, useAppNavigation } from "../../utils/navigation";
import { DEFAULT_USERNAME } from "../../utils/social-feed";
import { primaryColor } from "../../utils/style/colors";
Expand Down Expand Up @@ -70,7 +70,8 @@ export const FeedPostViewScreen: ScreenFC<"FeedPostView"> = ({
id,
selectedNetworkId
);
const authorId = getUserId(selectedNetworkId, postResult?.authorId);

const authorId = postResult?.authorId;
const authorNSInfo = useNSUserInfo(authorId);

const [, authorAddress] = parseUserId(postResult?.authorId);
Expand Down

0 comments on commit 8ac1c27

Please sign in to comment.