ghost-portal/packages/react-api/src/util/historic.ts
Jaco f512c1a539
Bump de & api (w/ __Unused on enum) (#6326)
* Bump de & api (w/ __Unused on enum)

* Linting fixes

* tsc adjustments

* Api bump
2021-10-17 16:37:57 +03:00

17 lines
758 B
TypeScript

// Copyright 2017-2021 @polkadot/react-api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Hash } from '@polkadot/types/interfaces';
import type { Codec } from '@polkadot/types/types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type AtQuery <I extends unknown[]> = (hash: string | Uint8Array, ...params: I) => Promise<Codec>;
export default async function getHistoric <T extends Codec, I extends unknown[] = unknown[]> (atQuery: AtQuery<I>, params: I, hashes: Hash[]): Promise<[Hash, T][]> {
return Promise
.all(hashes.map((hash): Promise<T> => atQuery(hash, ...params) as Promise<T>))
.then((results): [Hash, T][] =>
results.map((value, index): [Hash, T] => [hashes[index], value])
);
}