Skip to content

Commit

Permalink
Apply rate limit optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
carina-akaia committed Dec 31, 2024
1 parent 9e33868 commit 03cf5db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/entities/voting-round/hooks/voter-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ export const useVoterProfile = ({
const { isHumanVerified } = useIsHuman(accountId);
const { data: voterInfo } = indexer.useMpdaoVoterInfo({ accountId });

const stakingTokenId = useMemo(
() => voterInfo?.staking_token_id || stakingContractAccountId,
[stakingContractAccountId, voterInfo?.staking_token_id],
);

const { data: stakingToken } = useToken({
enabled: stakingTokenId !== undefined,
tokenId: stakingTokenId as TokenId,
enabled: stakingContractAccountId !== undefined,
tokenId: stakingContractAccountId as TokenId,
});

return useMemo(
Expand Down
10 changes: 4 additions & 6 deletions src/entities/voting-round/model/round-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ export const useRoundResultsStore = create<VotingRoundResultsState>()(
...new Set(votes.map(({ voter: voterAccountId }) => voterAccountId)),
];

const stakingTokenMetadata = stakingContractAccountId
? await ftClient.ft_metadata({ tokenId: stakingContractAccountId })
: null;

const voterProfiles: Record<AccountId, VoterProfile> = await Promise.all(
uniqueVoterAccountIds.map(async (voterAccountId) => {
const { data: voterInfo } = await indexerClient
.v1MpdaoVoterInfoRetrieve({ voter_id: voterAccountId })
.catch(() => ({ data: undefined }));

const stakingTokenId = voterInfo?.staking_token_id || stakingContractAccountId;

const votingPower = voterInfo
? voterInfo?.locking_positions?.reduce(
(sum: Big, { voting_power }: { voting_power: string }) =>
Expand All @@ -69,10 +71,6 @@ export const useRoundResultsStore = create<VotingRoundResultsState>()(
() => false,
);

const stakingTokenMetadata = stakingTokenId
? await ftClient.ft_metadata({ tokenId: stakingTokenId })
: null;

const stakingTokenBalance = voterInfo?.staking_token_balance
? stringifiedU128ToBigNum(
voterInfo.staking_token_balance,
Expand Down

0 comments on commit 03cf5db

Please sign in to comment.