From 375dadbe357945729dc6915d9f20c64df8ab467e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 19 Sep 2020 08:46:35 +0200 Subject: [PATCH] Optional votingOf for democracy locks (#2626) --- CHANGELOG.md | 1 + packages/api-derive/src/democracy/locks.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a089245c14..c75bfa05af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Changes: - Support for Metadata v12 with fixed indices - Cleanups for WebSocket class detection and creation - Ensure that ignored map params yield an error on `iterKey` +- Cater for older chains in derive democracy locks (availability detection) ## 1.33.1 Sep 14, 2020 diff --git a/packages/api-derive/src/democracy/locks.ts b/packages/api-derive/src/democracy/locks.ts index 77e799262a..65dd36f59b 100644 --- a/packages/api-derive/src/democracy/locks.ts +++ b/packages/api-derive/src/democracy/locks.ts @@ -75,14 +75,16 @@ function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable< export function locks (instanceId: string, api: ApiInterfaceRx): (accountId: string | AccountId) => Observable { return memo(instanceId, (accountId: string | AccountId): Observable => - api.query.democracy.votingOf(accountId).pipe( - switchMap((voting): Observable => - voting.isDirect - ? directLocks(api, voting.asDirect) - : voting.isDelegating - ? delegateLocks(api, voting.asDelegating) - : of([]) + api.query.democracy.votingOf + ? api.query.democracy.votingOf(accountId).pipe( + switchMap((voting): Observable => + voting.isDirect + ? directLocks(api, voting.asDirect) + : voting.isDelegating + ? delegateLocks(api, voting.asDelegating) + : of([]) + ) ) - ) + : of([]) ); }