From c59d924ab2b8dc869a9e8fd58674235dde7f9a44 Mon Sep 17 00:00:00 2001 From: LewisB Date: Fri, 2 Feb 2024 18:22:08 +0800 Subject: [PATCH 1/4] fix: map fullnames to addresses correctly --- packages/app/package.json | 2 +- .../src/components/DonorsList/DonorsList.tsx | 3 +- .../components/DonorsList/DonorsListItem.tsx | 3 +- .../components/StewardsList/StewardsList.tsx | 2 +- packages/app/src/hooks/useFetchFullName.ts | 51 ++++++++++++++----- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index 997d0421..af2f70d6 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -10,7 +10,7 @@ "format:check": "prettier -c ./src", "start": "react-native start", "test": "jest", - "web": "vite -c web/vite.config.ts", + "web": "vite --port 3000 -c web/vite.config.ts", "build": "yarn build:web", "build:web": "tsc && vite build -c web/vite.config.ts", "preview:web": "vite preview -c web/vite.config.ts" diff --git a/packages/app/src/components/DonorsList/DonorsList.tsx b/packages/app/src/components/DonorsList/DonorsList.tsx index 3ae7e416..8af41762 100644 --- a/packages/app/src/components/DonorsList/DonorsList.tsx +++ b/packages/app/src/components/DonorsList/DonorsList.tsx @@ -24,12 +24,13 @@ function DonorsList({ donors, listStyle }: DonorsListProps) { const userAddresses = useMemo(() => { return sortedDonors.map((donor) => donor.donor as `0x${string}`); }, [sortedDonors]); + const userFullNames = useFetchFullNames(userAddresses); return ( {sortedDonors.map((donor, index) => ( - + ))} ); diff --git a/packages/app/src/components/DonorsList/DonorsListItem.tsx b/packages/app/src/components/DonorsList/DonorsListItem.tsx index 752c8c53..062957b8 100644 --- a/packages/app/src/components/DonorsList/DonorsListItem.tsx +++ b/packages/app/src/components/DonorsList/DonorsListItem.tsx @@ -14,8 +14,7 @@ interface DonorsListItemProps { userFullName?: string; } -export const DonorsListItem = (props: DonorsListItemProps) => { - const { donor, rank, userFullName } = props; +export const DonorsListItem = ({ donor, rank, userFullName }: DonorsListItemProps) => { const { navigate } = useCrossNavigate(); const formattedDonations: string = new Decimal(ethers.utils.formatEther(donor.contribution) ?? 0).toFixed( diff --git a/packages/app/src/components/StewardsList/StewardsList.tsx b/packages/app/src/components/StewardsList/StewardsList.tsx index 6f0cc632..a8f5aaca 100644 --- a/packages/app/src/components/StewardsList/StewardsList.tsx +++ b/packages/app/src/components/StewardsList/StewardsList.tsx @@ -41,7 +41,7 @@ function StewardList({ listType, stewards, titleStyle, listStyle }: StewardListP showActions={listType === 'viewStewards'} key={steward.steward} profileImage={profileImages[index % profileImages.length]} - userFullName={userFullNames[index]} + userFullName={userFullNames[steward.steward]} /> ))} diff --git a/packages/app/src/hooks/useFetchFullName.ts b/packages/app/src/hooks/useFetchFullName.ts index 424ee79c..e87da570 100644 --- a/packages/app/src/hooks/useFetchFullName.ts +++ b/packages/app/src/hooks/useFetchFullName.ts @@ -4,18 +4,32 @@ import { gql } from '@apollo/client'; import { useMongoDbQuery } from './apollo/useMongoDbQuery'; interface UserProfile { - fullName?: { display?: string }; + fullName?: { display?: string; privacy: string }; + index: { + walletAddress: { + hash: string; + display?: string; + value?: string; + }; + }; } interface UserProfilesResponse { user_profiles: (UserProfile | undefined)[]; } +//todo: needs privacy settings to be configurable in the wallet const findProfiles = gql` query FindProfiles($query: User_profileQueryInput!) { user_profiles(query: $query) { fullName { display + privacy + } + index { + walletAddress { + hash + } } } } @@ -27,22 +41,35 @@ export function useFetchFullName(address?: string): string | undefined { return names[0]; } -export function useFetchFullNames(addresses: string[]): (string | undefined)[] { - const hashedAddresses = useMemo(() => { - return addresses.map((address: string) => ethers.utils.keccak256(address)); - }, [addresses]); +export function useFetchFullNames(addresses: string[]): any { + const addressToHashMapping = addresses.reduce((acc: any, address) => { + const hash = ethers.utils.keccak256(address); + acc[hash] = address; + return acc; + }, {}); + + const hashedAddresses = Object.keys(addressToHashMapping); const { data, error } = useMongoDbQuery(findProfiles, { - variables: { query: { index: { walletAddress: { hash_in: hashedAddresses } } } }, + variables: { + query: { + fullName: { privacy: 'public' }, + index: { walletAddress: { hash_in: hashedAddresses } }, + }, + }, }); return useMemo(() => { - if (error) { - console.error(error); - } if (!data || data.user_profiles.length === 0) { - return []; + return {}; } - return data.user_profiles.map((profile) => profile?.fullName?.display); - }, [data, error]); + return data.user_profiles.reduce((acc: Record, profile) => { + if (!profile) return {}; + const { hash } = profile.index.walletAddress; + const { display } = profile.fullName ?? {}; + const address = addressToHashMapping[hash]; + acc[address] = display ?? ''; + return acc; + }, {}); + }, [data, addressToHashMapping]); } From 3bf690910c4358f9fd95fa2556878222a57b347e Mon Sep 17 00:00:00 2001 From: LewisB Date: Mon, 5 Feb 2024 12:40:13 +0800 Subject: [PATCH 2/4] fix: nested view in text --- packages/app/src/components/RowItem.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/app/src/components/RowItem.tsx b/packages/app/src/components/RowItem.tsx index 91eb8758..8a782616 100644 --- a/packages/app/src/components/RowItem.tsx +++ b/packages/app/src/components/RowItem.tsx @@ -25,15 +25,15 @@ function RowItem({ rowInfo, rowData, balance, currency, imageUrl }: RowItemProps {rowInfo} - - + + {currency} {rowData} {isDesktopResolution && currency && = {usdBalance} USD} {!isDesktopResolution && currency && = {usdBalance} USD} - - + + ); } From 91dc12f056fc9d4acf724ed8d3d8d73bd6a292c2 Mon Sep 17 00:00:00 2001 From: LewisB Date: Mon, 5 Feb 2024 12:40:31 +0800 Subject: [PATCH 3/4] remove unneccesary field --- packages/app/src/hooks/useFetchFullName.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/app/src/hooks/useFetchFullName.ts b/packages/app/src/hooks/useFetchFullName.ts index e87da570..7c6c844b 100644 --- a/packages/app/src/hooks/useFetchFullName.ts +++ b/packages/app/src/hooks/useFetchFullName.ts @@ -4,12 +4,11 @@ import { gql } from '@apollo/client'; import { useMongoDbQuery } from './apollo/useMongoDbQuery'; interface UserProfile { - fullName?: { display?: string; privacy: string }; + fullName?: { display?: string }; index: { walletAddress: { hash: string; display?: string; - value?: string; }; }; } @@ -24,7 +23,6 @@ const findProfiles = gql` user_profiles(query: $query) { fullName { display - privacy } index { walletAddress { @@ -53,7 +51,6 @@ export function useFetchFullNames(addresses: string[]): any { const { data, error } = useMongoDbQuery(findProfiles, { variables: { query: { - fullName: { privacy: 'public' }, index: { walletAddress: { hash_in: hashedAddresses } }, }, }, From c35562fcbb285ed528066c804c2d8309ebf73862 Mon Sep 17 00:00:00 2001 From: LewisB Date: Tue, 6 Feb 2024 00:59:27 +0800 Subject: [PATCH 4/4] remove comment --- packages/app/src/hooks/useFetchFullName.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/app/src/hooks/useFetchFullName.ts b/packages/app/src/hooks/useFetchFullName.ts index 7c6c844b..78df913c 100644 --- a/packages/app/src/hooks/useFetchFullName.ts +++ b/packages/app/src/hooks/useFetchFullName.ts @@ -17,7 +17,6 @@ interface UserProfilesResponse { user_profiles: (UserProfile | undefined)[]; } -//todo: needs privacy settings to be configurable in the wallet const findProfiles = gql` query FindProfiles($query: User_profileQueryInput!) { user_profiles(query: $query) {