Preserve referenda with missing info during grouping (#11651)

* fix: improve transformation logic in OPT_MULTI for referenda mapping

* fix: streamline OPT_MULTI transformation and improve referenda grouping logic
This commit is contained in:
Arjun Porwal 2025-06-26 08:53:37 +05:30 committed by GitHub
parent 50ec1c5049
commit 6a0e834727
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,19 +52,17 @@ function sortGroups (a: ReferendaGroupKnown, b: ReferendaGroupKnown): number {
const OPT_MULTI = { const OPT_MULTI = {
transform: ([[ids], all]: [[BN[]], Option<Referendum['info']>[]]) => transform: ([[ids], all]: [[BN[]], Option<Referendum['info']>[]]) =>
all ids.map((id, i) => {
.map((o, i) => const infoOpt = all[i];
o.isSome const info = infoOpt?.isSome ? infoOpt.unwrap() : undefined;
? [ids[i], o.unwrap()]
: null return {
)
.filter((r): r is [BN, Referendum['info']] => !!r)
.map(([id, info]): Referendum => ({
id, id,
info, info,
isConvictionVote: isConvictionVote(info), isConvictionVote: info ? isConvictionVote(info) : false,
key: id.toString() key: id.toString()
})), };
}).filter((r) => r.info !== undefined),
withParamsTransform: true withParamsTransform: true
}; };
@ -84,17 +82,22 @@ function group (tracks: TrackDescription[], totalIssuance?: BN, referenda?: Refe
for (let i = 0, count = referenda.length; i < count; i++) { for (let i = 0, count = referenda.length; i < count; i++) {
const ref = referenda[i]; const ref = referenda[i];
// only ongoing have tracks if (!ref.info || !ref.info.isOngoing) {
const trackInfo = ref.info.isOngoing // info is undefined or not ongoing — can't get track
? tracks.find(({ id }) => id?.eq && id.eq(ref.info.asOngoing.track)) other.referenda.push(ref);
: undefined; continue;
}
const trackInfo = tracks.find(({ id }) =>
id?.eq && id.eq(ref.info.asOngoing.track)
);
if (trackInfo) { if (trackInfo) {
ref.trackGraph = trackInfo.graph; ref.trackGraph = trackInfo.graph;
ref.trackId = trackInfo.id; ref.trackId = trackInfo.id;
ref.track = trackInfo.info; ref.track = trackInfo.info;
if (ref.isConvictionVote && ref.info.isOngoing) { if (ref.isConvictionVote) {
const { deciding, tally } = ref.info.asOngoing; const { deciding, tally } = ref.info.asOngoing;
if (deciding.isSome) { if (deciding.isSome) {
@ -151,7 +154,7 @@ function useReferendaImpl (palletReferenda: PalletReferenda): [ReferendaGroup[],
() => [ () => [
(ids && ids.length === 0) (ids && ids.length === 0)
? [{ key: 'referenda', referenda: [] }] ? [{ key: 'referenda', referenda: [] }]
: group(tracks, totalIssuance, referenda), : group(tracks, totalIssuance, (referenda as Referendum[])),
tracks tracks
], ],
[ids, referenda, totalIssuance, tracks] [ids, referenda, totalIssuance, tracks]