diff --git a/packages/commonwealth/client/scripts/models/AddressInfo.ts b/packages/commonwealth/client/scripts/models/AddressInfo.ts index 2286e555af9..b78cb194b51 100644 --- a/packages/commonwealth/client/scripts/models/AddressInfo.ts +++ b/packages/commonwealth/client/scripts/models/AddressInfo.ts @@ -1,6 +1,8 @@ import type { WalletId, WalletSsoSource } from '@hicommonwealth/shared'; import moment from 'moment'; +import { userStore } from '../state/ui/user'; import Account, { AccountCommunity } from './Account'; +import MinimumProfile from './MinimumProfile'; class AddressInfo extends Account { public readonly userId: number; @@ -24,6 +26,8 @@ class AddressInfo extends Account { ghostAddress?: boolean; lastActive?: string | moment.Moment; }) { + const authUser = userStore.getState(); + const ignoreProfile = userId === authUser.id ? true : false; super({ address, community, @@ -31,7 +35,28 @@ class AddressInfo extends Account { walletId, walletSsoSource, ghostAddress, - ignoreProfile: false, + profile: (() => { + if (!ignoreProfile) return undefined; + + // if this is auth user, use already fetched address/profile data + const foundAddress = authUser.addresses.find( + (a) => + a.address === address && + a.community.id === community.id && + a.profile, + ); + const profile = new MinimumProfile(address, community.id); + profile.initialize( + userId, + '', // user name - not needed for auth user + address, + '', // user avatar url - not needed for auth user + community.id, + foundAddress?.lastActive?.toDate?.() || null, + ); + return profile; + })(), + ignoreProfile, lastActive, }); this.userId = userId;