diff --git a/governance/ui/src/mutations/useUpdateUserDetailsMutation.ts b/governance/ui/src/mutations/useUpdateUserDetailsMutation.ts index d0b72d686..ec4640cb1 100644 --- a/governance/ui/src/mutations/useUpdateUserDetailsMutation.ts +++ b/governance/ui/src/mutations/useUpdateUserDetailsMutation.ts @@ -11,8 +11,8 @@ import { SiweMessage } from 'siwe'; import { useGetIsUUIDValidQuery } from '../queries/'; import { utils } from 'ethers'; import { GetUserDetails } from '../queries/useGetUserDetailsQuery'; -import { useWallet, useSigner } from '../queries/useWallet'; -import { profileContract } from '../utils/contracts'; +import { useWallet, useSigner, useNetwork } from '../queries/useWallet'; +import { isMotherchain, profileContract } from '../utils/contracts'; type UpdateUserDetailsResponse = { data: GetUserDetails & { @@ -52,6 +52,7 @@ function useUpdateUserDetailsMutation() { const { activeWallet } = useWallet(); const signer = useSigner(); const toast = useToast(); + const { network } = useNetwork(); const [uuid, setUuid] = useState(null); @@ -110,7 +111,7 @@ function useUpdateUserDetailsMutation() { mutationFn: async (userProfile: GetUserDetails) => { const address = await signer?.getAddress(); const isContract = await signer?.provider.getCode(address || ''); - if (isContract !== '0x' && signer) { + if (isContract !== '0x' && signer && isMotherchain(network?.id)) { await profileContract.connect(signer).updateProfile( { username: userProfile.username, diff --git a/governance/ui/src/queries/useGetUserDetailsQuery.ts b/governance/ui/src/queries/useGetUserDetailsQuery.ts index c8e835a00..9cd94e457 100644 --- a/governance/ui/src/queries/useGetUserDetailsQuery.ts +++ b/governance/ui/src/queries/useGetUserDetailsQuery.ts @@ -2,6 +2,7 @@ import { GET_PITCHES_FOR_USER_API_URL, GET_USER_DETAILS_API_URL } from '../utils import { useQuery } from '@tanstack/react-query'; import { motherShipProvider } from '../utils/providers'; import { profileContract } from '../utils/contracts'; +import { utils } from 'ethers'; export type GetUserDetails = { address: string; @@ -48,16 +49,7 @@ export async function getUserDetails( ): Promise<(T extends string ? GetUserDetails : GetUserDetails[]) | undefined> { if (typeof walletAddress === 'string') { const randomNumber = Math.random(); - const isMultiSig = await motherShipProvider(2192).getCode(walletAddress); - if (isMultiSig !== '0x') { - const profile = await profileContract - .connect(motherShipProvider(2192)) - .getProfile(walletAddress); - return { ...profile, address: walletAddress } as T extends string - ? GetUserDetails - : GetUserDetails[]; - } const userDetailsResponse = await fetch(GET_USER_DETAILS_API_URL(walletAddress), { method: 'POST', }); @@ -82,6 +74,18 @@ export async function getUserDetails( } delete userProfile.data.delegationPitches; + const isMultiSig = await motherShipProvider(2192).getCode(walletAddress); + if (isMultiSig !== '0x' && profileIsEmpty(userProfile.data)) { + const profile = await profileContract + .connect(motherShipProvider(2192)) + .getProfile(walletAddress); + + //check if on other network it exists + return { ...profile, address: walletAddress } as T extends string + ? GetUserDetails + : GetUserDetails[]; + } + return { ...userProfile.data, delegationPitch: synthetixPitch } as T extends string ? GetUserDetails : GetUserDetails[]; @@ -141,6 +145,13 @@ export async function getUserDetails( return userProfile; } }) - .concat(multiSigsProfiles) as T extends string ? GetUserDetails : GetUserDetails[]; + .concat(multiSigsProfiles.filter((profile) => !profileIsEmpty(profile))) as T extends string + ? GetUserDetails + : GetUserDetails[]; } } + +const profileIsEmpty = (profile: GetUserDetails) => { + const values = Object.values(profile).filter((val) => !utils.isAddress(val) && !!val.trim()); + return values.every((val) => !!val); +};