Skip to content

Commit

Permalink
fix unnecessary profile queries
Browse files Browse the repository at this point in the history
  • Loading branch information
NickJ202 committed Jan 4, 2025
1 parent dcab5e1 commit 506dcb1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
37 changes: 26 additions & 11 deletions src/api/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,33 @@ export async function getAndUpdateRegistryProfiles(ids: string[]): Promise<Regis
return uniqueProfiles;
}, [] as RegistryProfileType[]);

// Get current Redux state
const profilesReducer = store.getState().profilesReducer;
store.dispatch(
profilesActions.setProfiles({
...(profilesReducer ?? {}),
registryProfiles: [
...(profilesReducer?.registryProfiles || []),
...newProfiles.filter(
(profile) => !profilesReducer?.registryProfiles?.some((p: RegistryProfileType) => p.id === profile.id)
),
],
})
);
const currentRegistryProfiles = profilesReducer?.registryProfiles || [];

// Find profiles that are new or have changed
const updatedProfiles = newProfiles.filter((newProfile) => {
const existingProfile = currentRegistryProfiles.find((p) => p.id === newProfile.id);
return (
!existingProfile || // New profile
JSON.stringify(existingProfile) !== JSON.stringify(newProfile) // Updated profile
);
});

// Only dispatch if there are updates
if (updatedProfiles.length > 0) {
store.dispatch(
profilesActions.setProfiles({
...(profilesReducer ?? {}),
registryProfiles: [
...currentRegistryProfiles.filter(
(profile) => !updatedProfiles.some((p: RegistryProfileType) => p.id === profile.id)
),
...updatedProfiles,
],
})
);
}
} finally {
newProfileIds.forEach((id) => registryFetchQueue.delete(id));
}
Expand Down
6 changes: 5 additions & 1 deletion src/views/Asset/AssetAction/AssetAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function AssetAction(props: IProps) {
(async function () {
if (props.asset && props.asset.state && addressGroups && addressGroups.length > 0) {
setUpdating(true);
console.log(props.asset, addressGroups, ownersCursor, profilesReducer?.registryProfiles);
try {
let subAddresses = {};
addressGroups[ownersCursor].forEach((address: string) => {
Expand Down Expand Up @@ -303,7 +304,10 @@ export default function AssetAction(props: IProps) {
type={'alt1'}
label={language.loadMore}
handlePress={() => setOwnersCursor(ownersCursor + 1)}
disabled={addressGroups && addressGroups.length > 0 ? ownersCursor >= addressGroups.length - 1 : true}
disabled={
(addressGroups && addressGroups.length > 0 ? ownersCursor >= addressGroups.length - 1 : true) ||
updating
}
height={40}
/>
</S.MActionsWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ export default function AssetActionMarketOrders(props: IProps) {
function handleAssetUpdate() {
if (orderSuccess) {
setCurrentOrderQuantity('');
setUnitPrice(0);
setUnitPrice('');
setTransferRecipient('');
setOrderId(null);
windowUtils.scrollTo(0, 0, 'smooth');
}

Expand All @@ -406,7 +407,7 @@ export default function AssetActionMarketOrders(props: IProps) {
setShowConfirmation(false);
setOrderProcessed(false);
setCurrentOrderQuantity('');
setUnitPrice(0);
setUnitPrice('');
setTransferRecipient('');
setCurrentNotification(null);
windowUtils.scrollTo(0, 0, 'smooth');
Expand Down

0 comments on commit 506dcb1

Please sign in to comment.