Skip to content

Commit

Permalink
fix: get voting power
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Jan 9, 2024
1 parent 8a443ac commit 89220dd
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions src/proposals/store/proposalsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,48 +841,40 @@ export const createProposalsSlice: StoreSlice<
}
});

set((state) =>
produce(state, (draft) => {
newBlockHashes.forEach((hash) => {
draft.blockHashBalanceLoadings[`${hash.hash}_${userAddress}`] =
true;
});
}),
);

const balances = await Promise.all(
newBlockHashes.map((item) => {
return get().delegationService.getDelegatedVotingPowerByBlockHash(
item.hash as Hex,
userAddress,
item.underlyingAssets as Hex[],
newBlockHashes.map(async (item) => {
if (!get().blockHashBalanceLoadings[`${item.hash}_${userAddress}`]) {
set((state) =>
produce(state, (draft) => {
draft.blockHashBalanceLoadings[`${item.hash}_${userAddress}`] =
true;
}),
);
}),
);

set((state) =>
produce(state, (draft) => {
balances.forEach((balance, index) => {
draft.blockHashBalance[
`${newBlockHashes[index].hash}_${userAddress}`
] = balance;
});
}),
);
const balance =
await get().delegationService.getDelegatedVotingPowerByBlockHash(
item.hash as Hex,
userAddress,
item.underlyingAssets as Hex[],
);

setTimeout(
() =>
set((state) =>
produce(state, (draft) => {
balances.forEach((balance, index) => {
draft.blockHashBalanceLoadings[
`${newBlockHashes[index].hash}_${userAddress}`
] = false;
});
draft.blockHashBalance[`${item.hash}_${userAddress}`] = balance;
}),
),
1,
);
);
}

setTimeout(
() =>
set((state) =>
produce(state, (draft) => {
draft.blockHashBalanceLoadings[`${item.hash}_${userAddress}`] =
false;
}),
),
1,
);
});
}
},

Expand Down

1 comment on commit 89220dd

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.