Skip to content

Commit

Permalink
Minimize calls to /getAddressProfile for auth user addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
mzparacha committed Sep 5, 2024
1 parent 4998787 commit 1a04d8b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/commonwealth/client/scripts/models/AddressInfo.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,14 +26,37 @@ class AddressInfo extends Account {
ghostAddress?: boolean;
lastActive?: string | moment.Moment;
}) {
const authUser = userStore.getState();
const ignoreProfile = userId === authUser.id ? true : false;
super({
address,
community,
addressId: id,
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;
Expand Down

0 comments on commit 1a04d8b

Please sign in to comment.