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 {