From 6d1060f6a48eda00c910b6c9e7e7f2507dafa129 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Thu, 14 Oct 2021 18:39:39 +0800 Subject: [PATCH 1/2] fix: snapshot getScores api --- .../Snapshot/SNSAdaptor/hooks/usePower.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts index 624b97968e4e..3f00ee85b5b6 100644 --- a/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts @@ -3,6 +3,7 @@ import { useAccount, useBlockNumber } from '@masknet/web3-shared' import { PluginSnapshotRPC } from '../../messages' import type { ProposalIdentifier } from '../../types' import { useProposal } from './useProposal' +import { mapKeys } from 'lodash-es' export function usePower(identifier: ProposalIdentifier) { const { @@ -13,14 +14,19 @@ export function usePower(identifier: ProposalIdentifier) { const blockNumber = useBlockNumber() return useAsyncRetry(async () => { if (!account) return 0 - const scores = await PluginSnapshotRPC.getScores( - message, - [account], - blockNumber, - proposal.network, - identifier.space, - proposal.strategies, + return ( + await PluginSnapshotRPC.getScores( + message, + [account], + blockNumber, + proposal.network, + identifier.space, + proposal.strategies, + ) ) - return scores[0]![account]! + .map((v) => mapKeys(v, (_value, key) => key.toLowerCase()) as { [x: string]: number }) + .reduce((acc, cur) => { + return acc + cur[account.toLowerCase()] + }, 0) }, [blockNumber, account]) } From 3800a2ff7c5327f122702423eae4c3065fb9a5ae Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Thu, 14 Oct 2021 19:10:20 +0800 Subject: [PATCH 2/2] chore: little fix --- .../maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts index 3f00ee85b5b6..893ca9e4632e 100644 --- a/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts @@ -26,7 +26,7 @@ export function usePower(identifier: ProposalIdentifier) { ) .map((v) => mapKeys(v, (_value, key) => key.toLowerCase()) as { [x: string]: number }) .reduce((acc, cur) => { - return acc + cur[account.toLowerCase()] + return acc + (cur[account.toLowerCase()] ?? 0) }, 0) }, [blockNumber, account]) }