// Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { Option } from '@polkadot/types'; import type { AccountId } from '@polkadot/types/interfaces'; import { map, of } from 'rxjs'; import { isFunction } from '@polkadot/util'; import { memo } from '../util'; import { getInstance } from './getInstance'; export function prime (instanceId: string, api: ApiInterfaceRx, _section: string): () => Observable { const section = getInstance(api, _section); return memo(instanceId, (): Observable => isFunction(api.query[section as 'council']?.prime) ? api.query[section as 'council'].prime>().pipe( map((optPrime): AccountId | null => optPrime.unwrapOr(null) ) ) : of(null) ); }