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