Skip to content

Commit

Permalink
feat: pool context optimisations (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat authored Nov 12, 2023
1 parent 9b5b237 commit ad4db96
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 372 deletions.
13 changes: 12 additions & 1 deletion src/canvas/ManageNominations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
NominationSelection,
NominationSelectionWithResetCounter,
} from 'library/GenerateNominations/types';
import { useBondedPools } from 'contexts/Pools/BondedPools';
import { RevertPrompt } from './Prompts/RevertPrompt';
import { CanvasSubmitTxFooter, ManageNominationsWrapper } from './Wrappers';

Expand All @@ -42,6 +43,7 @@ export const ManageNominations = () => {
const { addNotification } = useNotifications();
const { selectedActivePool } = useActivePools();
const { openPromptWith, closePrompt } = usePrompt();
const { updatePoolNominations } = useBondedPools();
const controller = getBondedAccount(activeAccount);
const { maxNominations } = consts;
const bondFor = options?.bondFor || 'nominator';
Expand Down Expand Up @@ -128,7 +130,16 @@ export const ManageNominations = () => {
callbackSubmit: () => {
setCanvasStatus('closing');
},
callbackInBlock: () => {},
callbackInBlock: () => {
if (isPool) {
// Upate bonded pool targets if updating pool nominations.
if (selectedActivePool?.id)
updatePoolNominations(
selectedActivePool.id,
newNominations.nominations.map((n) => n.address)
);
}
},
});

// Valid if there are between 1 and `maxNominations` nominations.
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/NetworkMetrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const NetworkMetricsProvider = ({

// initiate subscription, add to unsubs.
await Promise.all([subscribeToMetrics(), subscribeToActiveEra()]).then(
(u: any) => {
(u) => {
unsubsRef.current = unsubsRef.current.concat(u);
}
);
Expand Down
1 change: 1 addition & 0 deletions src/contexts/Pools/ActivePools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const ActivePoolsProvider = ({
const p = membership?.poolId ? String(membership.poolId) : '0';
return String(a.id) === p;
}) || null;

const getSelectedActivePool = () =>
activePoolsRef.current.find((a) => a.id === Number(selectedPoolId)) || null;

Expand Down
7 changes: 4 additions & 3 deletions src/contexts/Pools/BondedPools/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import type { BondedPoolsContextState } from '../types';

export const defaultBondedPoolsContext: BondedPoolsContextState = {
fetchPoolsMetaBatch: (k, v: [], r) => {},
queryBondedPool: (p) => {},
getBondedPool: (p) => null,
updateBondedPools: (p) => {},
Expand All @@ -16,7 +15,9 @@ export const defaultBondedPoolsContext: BondedPoolsContextState = {
getAccountRoles: (w) => null,
getAccountPools: (w) => null,
replacePoolRoles: (p, e) => {},
poolSearchFilter: (l, k, v) => {},
poolSearchFilter: (l, v) => {},
bondedPools: [],
meta: {},
poolsMetaData: {},
poolsNominations: {},
updatePoolNominations: (id, nominations) => {},
};
Loading

0 comments on commit ad4db96

Please sign in to comment.