From 8c7b6c0305f1957d57f7611db1f87d0279314d4d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 12 Feb 2020 14:22:24 +0100 Subject: [PATCH] Pull out isDefined --- packages/bcp/src/cosmwasmconnection.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index cb05efae..09aea072 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -58,6 +58,10 @@ export interface TokenConfiguration { readonly erc20Tokens?: ReadonlyArray; } +function isDefined(value: X | undefined): value is X { + return value !== undefined; +} + export class CosmWasmConnection implements BlockchainConnection { // we must know prefix and tokens a priori to understand the chain public static async establish( @@ -288,17 +292,17 @@ export class CosmWasmConnection implements BlockchainConnection { signedBy, tags, }: TransactionQuery): Promise | FailedTransaction)[]> { - if ([signedBy, tags].some(component => component !== undefined)) { + if ([signedBy, tags].some(isDefined)) { throw new Error("Transaction query by signedBy or tags not yet supported"); } - if ([maxHeight, minHeight].some(component => component !== undefined)) { + if ([maxHeight, minHeight].some(isDefined)) { throw new Error( "Transaction query by minHeight/maxHeight not yet supported. This is due to missing flexibility of the Gaia REST API, see https://github.com/cosmos/gaia/issues/75", ); } - if ([id, height, sentFromOrTo].filter(component => component !== undefined).length !== 1) { + if ([id, height, sentFromOrTo].filter(isDefined).length !== 1) { throw new Error( "Transaction query by id, height and sentFromOrTo is mutually exclusive. Exactly one must be set.", );