From 1c6a2582f31f653f6a8d00cbd1faaefe6d904882 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 19 Nov 2019 16:01:31 +0100 Subject: [PATCH] Controllers on Alex (#1587) --- packages/api-derive/src/staking/info.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/api-derive/src/staking/info.ts b/packages/api-derive/src/staking/info.ts index 09db87e093..7486f1ac00 100644 --- a/packages/api-derive/src/staking/info.ts +++ b/packages/api-derive/src/staking/info.ts @@ -188,14 +188,18 @@ function retrieveInfoV2 (api: ApiInterfaceRx, accountId: AccountId, stashId: Acc })); } -function retrieveV1 (api: ApiInterfaceRx, controllerId: AccountId): Observable { - return api.query.staking - .ledger>(controllerId) - .pipe(switchMap((stakingLedger): Observable => - stakingLedger.isSome - ? retrieveInfoV1(api, controllerId, stakingLedger.unwrap().stash, controllerId) - : of({ accountId: controllerId, nextSessionIds: [], sessionIds: [] }) - )); +function retrieveV1 (api: ApiInterfaceRx, accountId: AccountId): Observable { + // depending on where we come from, this may be a controller or stash + return combineLatest([ + api.query.staking.bonded>(accountId), + api.query.staking.ledger>(accountId) + ]).pipe(switchMap(([bonded, stakingLedger]): Observable => + stakingLedger.isSome + ? retrieveInfoV1(api, accountId, stakingLedger.unwrap().stash, accountId) + : bonded.isSome + ? retrieveInfoV1(api, accountId, accountId, bonded.unwrap()) + : of({ accountId: accountId, nextSessionIds: [], sessionIds: [] }) + )); } function retrieveV2 (api: ApiInterfaceRx, stashId: AccountId): Observable {