From 8c7ef3689b4016b9eab83f5914255933f59bec4a Mon Sep 17 00:00:00 2001 From: Bojan Angjelkoski Date: Tue, 29 Oct 2024 22:35:10 +0100 Subject: [PATCH] fix: imports --- .../{ => exceptions}/BitGetException.ts | 0 .../{ => exceptions}/CosmosWalletException.ts | 0 .../{ => exceptions}/GeneralException.ts | 0 .../GrpcUnaryRequestException.ts | 0 .../{ => exceptions}/HttpRequestException.ts | 0 .../{ => exceptions}/LedgerCosmosException.ts | 0 .../{ => exceptions}/LedgerException.ts | 0 .../{ => exceptions}/MetamaskException.ts | 0 .../{ => exceptions}/OkxWalletException.ts | 0 .../{ => exceptions}/TransactionException.ts | 0 .../{ => exceptions}/TrezorException.ts | 0 .../{ => exceptions}/TrustWalletException.ts | 0 .../{ => exceptions}/WalletException.ts | 0 .../{ => exceptions}/Web3Exception.ts | 0 .../src/exceptions/exceptions/index.ts | 31 +++++ packages/exceptions/src/exceptions/index.ts | 81 +------------ packages/exceptions/src/exceptions/types.ts | 32 +++++ packages/exceptions/src/exceptions/utils.ts | 31 +++++ packages/exceptions/src/types/context.ts | 111 +++++++++++++++++ packages/exceptions/src/types/index.ts | 113 +----------------- packages/sdk-ts/src/core/modules/index.ts | 2 +- packages/sdk-ts/src/core/tx/api/index.ts | 8 -- packages/sdk-ts/src/types/cosmos.ts | 25 ++++ packages/sdk-ts/src/types/index.ts | 27 +---- packages/ts-types/src/common.ts | 28 +++++ packages/ts-types/src/index.ts | 30 +---- 26 files changed, 265 insertions(+), 254 deletions(-) rename packages/exceptions/src/exceptions/{ => exceptions}/BitGetException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/CosmosWalletException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/GeneralException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/GrpcUnaryRequestException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/HttpRequestException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/LedgerCosmosException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/LedgerException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/MetamaskException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/OkxWalletException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/TransactionException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/TrezorException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/TrustWalletException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/WalletException.ts (100%) rename packages/exceptions/src/exceptions/{ => exceptions}/Web3Exception.ts (100%) create mode 100644 packages/exceptions/src/exceptions/exceptions/index.ts create mode 100644 packages/exceptions/src/exceptions/types.ts create mode 100644 packages/exceptions/src/exceptions/utils.ts create mode 100644 packages/exceptions/src/types/context.ts create mode 100644 packages/sdk-ts/src/types/cosmos.ts create mode 100644 packages/ts-types/src/common.ts diff --git a/packages/exceptions/src/exceptions/BitGetException.ts b/packages/exceptions/src/exceptions/exceptions/BitGetException.ts similarity index 100% rename from packages/exceptions/src/exceptions/BitGetException.ts rename to packages/exceptions/src/exceptions/exceptions/BitGetException.ts diff --git a/packages/exceptions/src/exceptions/CosmosWalletException.ts b/packages/exceptions/src/exceptions/exceptions/CosmosWalletException.ts similarity index 100% rename from packages/exceptions/src/exceptions/CosmosWalletException.ts rename to packages/exceptions/src/exceptions/exceptions/CosmosWalletException.ts diff --git a/packages/exceptions/src/exceptions/GeneralException.ts b/packages/exceptions/src/exceptions/exceptions/GeneralException.ts similarity index 100% rename from packages/exceptions/src/exceptions/GeneralException.ts rename to packages/exceptions/src/exceptions/exceptions/GeneralException.ts diff --git a/packages/exceptions/src/exceptions/GrpcUnaryRequestException.ts b/packages/exceptions/src/exceptions/exceptions/GrpcUnaryRequestException.ts similarity index 100% rename from packages/exceptions/src/exceptions/GrpcUnaryRequestException.ts rename to packages/exceptions/src/exceptions/exceptions/GrpcUnaryRequestException.ts diff --git a/packages/exceptions/src/exceptions/HttpRequestException.ts b/packages/exceptions/src/exceptions/exceptions/HttpRequestException.ts similarity index 100% rename from packages/exceptions/src/exceptions/HttpRequestException.ts rename to packages/exceptions/src/exceptions/exceptions/HttpRequestException.ts diff --git a/packages/exceptions/src/exceptions/LedgerCosmosException.ts b/packages/exceptions/src/exceptions/exceptions/LedgerCosmosException.ts similarity index 100% rename from packages/exceptions/src/exceptions/LedgerCosmosException.ts rename to packages/exceptions/src/exceptions/exceptions/LedgerCosmosException.ts diff --git a/packages/exceptions/src/exceptions/LedgerException.ts b/packages/exceptions/src/exceptions/exceptions/LedgerException.ts similarity index 100% rename from packages/exceptions/src/exceptions/LedgerException.ts rename to packages/exceptions/src/exceptions/exceptions/LedgerException.ts diff --git a/packages/exceptions/src/exceptions/MetamaskException.ts b/packages/exceptions/src/exceptions/exceptions/MetamaskException.ts similarity index 100% rename from packages/exceptions/src/exceptions/MetamaskException.ts rename to packages/exceptions/src/exceptions/exceptions/MetamaskException.ts diff --git a/packages/exceptions/src/exceptions/OkxWalletException.ts b/packages/exceptions/src/exceptions/exceptions/OkxWalletException.ts similarity index 100% rename from packages/exceptions/src/exceptions/OkxWalletException.ts rename to packages/exceptions/src/exceptions/exceptions/OkxWalletException.ts diff --git a/packages/exceptions/src/exceptions/TransactionException.ts b/packages/exceptions/src/exceptions/exceptions/TransactionException.ts similarity index 100% rename from packages/exceptions/src/exceptions/TransactionException.ts rename to packages/exceptions/src/exceptions/exceptions/TransactionException.ts diff --git a/packages/exceptions/src/exceptions/TrezorException.ts b/packages/exceptions/src/exceptions/exceptions/TrezorException.ts similarity index 100% rename from packages/exceptions/src/exceptions/TrezorException.ts rename to packages/exceptions/src/exceptions/exceptions/TrezorException.ts diff --git a/packages/exceptions/src/exceptions/TrustWalletException.ts b/packages/exceptions/src/exceptions/exceptions/TrustWalletException.ts similarity index 100% rename from packages/exceptions/src/exceptions/TrustWalletException.ts rename to packages/exceptions/src/exceptions/exceptions/TrustWalletException.ts diff --git a/packages/exceptions/src/exceptions/WalletException.ts b/packages/exceptions/src/exceptions/exceptions/WalletException.ts similarity index 100% rename from packages/exceptions/src/exceptions/WalletException.ts rename to packages/exceptions/src/exceptions/exceptions/WalletException.ts diff --git a/packages/exceptions/src/exceptions/Web3Exception.ts b/packages/exceptions/src/exceptions/exceptions/Web3Exception.ts similarity index 100% rename from packages/exceptions/src/exceptions/Web3Exception.ts rename to packages/exceptions/src/exceptions/exceptions/Web3Exception.ts diff --git a/packages/exceptions/src/exceptions/exceptions/index.ts b/packages/exceptions/src/exceptions/exceptions/index.ts new file mode 100644 index 000000000..21ec4e134 --- /dev/null +++ b/packages/exceptions/src/exceptions/exceptions/index.ts @@ -0,0 +1,31 @@ +import { GrpcUnaryRequestException } from './GrpcUnaryRequestException' +import { HttpRequestException } from './HttpRequestException' +import { Web3Exception } from './Web3Exception' +import { GeneralException } from './GeneralException' +import { LedgerException } from './LedgerException' +import { LedgerCosmosException } from './LedgerCosmosException' +import { MetamaskException } from './MetamaskException' +import { TrustWalletException } from './TrustWalletException' +import { OkxWalletException } from './OkxWalletException' +import { TrezorException } from './TrezorException' +import { CosmosWalletException } from './CosmosWalletException' +import { TransactionException } from './TransactionException' +import { WalletException } from './WalletException' +import { BitGetException } from './BitGetException' + +export { + Web3Exception, + LedgerException, + TrezorException, + WalletException, + GeneralException, + BitGetException, + MetamaskException, + TransactionException, + TrustWalletException, + OkxWalletException, + HttpRequestException, + LedgerCosmosException, + CosmosWalletException, + GrpcUnaryRequestException, +} diff --git a/packages/exceptions/src/exceptions/index.ts b/packages/exceptions/src/exceptions/index.ts index be8d6fb0c..c396f545e 100644 --- a/packages/exceptions/src/exceptions/index.ts +++ b/packages/exceptions/src/exceptions/index.ts @@ -1,78 +1,3 @@ -import { GrpcUnaryRequestException } from './GrpcUnaryRequestException' -import { HttpRequestException } from './HttpRequestException' -import { Web3Exception } from './Web3Exception' -import { GeneralException } from './GeneralException' -import { LedgerException } from './LedgerException' -import { LedgerCosmosException } from './LedgerCosmosException' -import { MetamaskException } from './MetamaskException' -import { TrustWalletException } from './TrustWalletException' -import { OkxWalletException } from './OkxWalletException' -import { TrezorException } from './TrezorException' -import { CosmosWalletException } from './CosmosWalletException' -import { TransactionException } from './TransactionException' -import { WalletException } from './WalletException' -import { Exception } from '../types' -import { ConcreteException } from '../exception' -import { BitGetException } from './BitGetException' - -export type ThrownException = - | GrpcUnaryRequestException - | HttpRequestException - | Web3Exception - | GeneralException - | LedgerException - | MetamaskException - | TrustWalletException - | OkxWalletException - | TrezorException - | CosmosWalletException - | TransactionException - | WalletException - | LedgerCosmosException - | BitGetException - -export const isThrownException = (exception: Error | Exception): boolean => { - if (exception instanceof ConcreteException) { - return true - } - - if ( - [ - 'GrpcUnaryRequestException', - 'HttpRequestException', - 'Web3Exception', - 'GeneralException', - 'LedgerException', - 'LedgerCosmosException', - 'MetamaskException', - 'TrezorException', - 'CosmosWalletException', - 'TransactionException', - 'WalletException', - 'TrustWalletException', - 'OkxWalletException', - 'BitGetException', - ].includes(exception.constructor.name) - ) { - return true - } - - return false -} - -export { - Web3Exception, - LedgerException, - TrezorException, - WalletException, - GeneralException, - BitGetException, - MetamaskException, - TransactionException, - TrustWalletException, - OkxWalletException, - HttpRequestException, - LedgerCosmosException, - CosmosWalletException, - GrpcUnaryRequestException, -} +export * from './exceptions' +export * from './types' +export * from './utils' diff --git a/packages/exceptions/src/exceptions/types.ts b/packages/exceptions/src/exceptions/types.ts new file mode 100644 index 000000000..eced8067f --- /dev/null +++ b/packages/exceptions/src/exceptions/types.ts @@ -0,0 +1,32 @@ +import { + Web3Exception, + WalletException, + TrezorException, + BitGetException, + LedgerException, + GeneralException, + MetamaskException, + OkxWalletException, + HttpRequestException, + LedgerCosmosException, + TrustWalletException, + CosmosWalletException, + TransactionException, + GrpcUnaryRequestException, +} from './exceptions' + +export type ThrownException = + | GrpcUnaryRequestException + | HttpRequestException + | Web3Exception + | GeneralException + | LedgerException + | MetamaskException + | TrustWalletException + | OkxWalletException + | TrezorException + | CosmosWalletException + | TransactionException + | WalletException + | LedgerCosmosException + | BitGetException diff --git a/packages/exceptions/src/exceptions/utils.ts b/packages/exceptions/src/exceptions/utils.ts new file mode 100644 index 000000000..242629ea3 --- /dev/null +++ b/packages/exceptions/src/exceptions/utils.ts @@ -0,0 +1,31 @@ +import { ConcreteException } from "../exception" +import { Exception } from "../types" + +export const isThrownException = (exception: Error | Exception): boolean => { + if (exception instanceof ConcreteException) { + return true + } + + if ( + [ + 'GrpcUnaryRequestException', + 'HttpRequestException', + 'Web3Exception', + 'GeneralException', + 'LedgerException', + 'LedgerCosmosException', + 'MetamaskException', + 'TrezorException', + 'CosmosWalletException', + 'TransactionException', + 'WalletException', + 'TrustWalletException', + 'OkxWalletException', + 'BitGetException', + ].includes(exception.constructor.name) + ) { + return true + } + + return false +} diff --git a/packages/exceptions/src/types/context.ts b/packages/exceptions/src/types/context.ts new file mode 100644 index 000000000..36a9fb903 --- /dev/null +++ b/packages/exceptions/src/types/context.ts @@ -0,0 +1,111 @@ +import { ErrorCode, ErrorContextCode } from './codes' + +export enum HttpRequestMethod { + Get = 'GET', + Post = 'POST', + Options = 'OPTIONS', +} + +export enum ErrorType { + Unspecified = 'unspecified', + ChainError = 'chain-error', + ExecutionError = 'execution-error', + NotFoundError = 'not-found-error', + ValidationError = 'validation-error', + WalletError = 'wallet-error', + WalletNotInstalledError = 'wallet-not-installed-error', + GrpcUnaryRequest = 'grpc-unary-request', + HttpRequest = 'http-request', + Web3 = 'web3', + Web3Gateway = 'web3-gateway', +} + +export interface ErrorContext { + code?: ErrorCode + type?: ErrorType + + /** + * Additional context needed for the exception + */ + context?: string + + /** + * Where is the exception thrown + */ + contextModule?: string + + /** + * Needed when we get a code error from a Http/Grpc Request + * and we need to specify the error code for the particular message + * for example why the transaction has failed + * */ + contextCode?: ErrorContextCode +} + +export interface Exception { + /** + * The type of the Error + */ + type: ErrorType + + /** + * Error specific code (HttpStatus, GrpcStatus, etc) + */ + code: ErrorCode + + /** + * The name of the error (the name of the instance of the Exception) + */ + name: string + + /** + * Providing more context as to where the exception was thrown + * (ex: on-chain module, etc) + */ + contextModule?: string + + /** + * Providing more context as to why the exception was thrown + * (ex: on-chain error code, etc) + */ + contextCode?: ErrorContextCode + + /** + * Parsed message of the exception + */ + message: string + + /** + * The original stack of the error + */ + stack?: string + + /** + * The original message of the error + */ + originalMessage: string + + parse?(): void + + parseError(error: Error): void + + parseContext(context?: ErrorContext): void + + setType(type: ErrorType): void + + setCode(code: ErrorCode): void + + setStack(stack: string): void + + setName(name: string): void + + setMessage(message: string): void + + setContextModule(contextModule: string): void + + toOriginalError(): Error + + toError(): Error + + toString(): string +} diff --git a/packages/exceptions/src/types/index.ts b/packages/exceptions/src/types/index.ts index c07bbdb61..5bf04923d 100644 --- a/packages/exceptions/src/types/index.ts +++ b/packages/exceptions/src/types/index.ts @@ -1,114 +1,3 @@ -import { ErrorCode, ErrorContextCode } from './codes' - export * from './modules' export * from './codes' - -export enum HttpRequestMethod { - Get = 'GET', - Post = 'POST', - Options = 'OPTIONS', -} - -export enum ErrorType { - Unspecified = 'unspecified', - ChainError = 'chain-error', - ExecutionError = 'execution-error', - NotFoundError = 'not-found-error', - ValidationError = 'validation-error', - WalletError = 'wallet-error', - WalletNotInstalledError = 'wallet-not-installed-error', - GrpcUnaryRequest = 'grpc-unary-request', - HttpRequest = 'http-request', - Web3 = 'web3', - Web3Gateway = 'web3-gateway', -} - -export interface ErrorContext { - code?: ErrorCode - type?: ErrorType - - /** - * Additional context needed for the exception - */ - context?: string - - /** - * Where is the exception thrown - */ - contextModule?: string - - /** - * Needed when we get a code error from a Http/Grpc Request - * and we need to specify the error code for the particular message - * for example why the transaction has failed - * */ - contextCode?: ErrorContextCode -} - -export interface Exception { - /** - * The type of the Error - */ - type: ErrorType - - /** - * Error specific code (HttpStatus, GrpcStatus, etc) - */ - code: ErrorCode - - /** - * The name of the error (the name of the instance of the Exception) - */ - name: string - - /** - * Providing more context as to where the exception was thrown - * (ex: on-chain module, etc) - */ - contextModule?: string - - /** - * Providing more context as to why the exception was thrown - * (ex: on-chain error code, etc) - */ - contextCode?: ErrorContextCode - - /** - * Parsed message of the exception - */ - message: string - - /** - * The original stack of the error - */ - stack?: string - - /** - * The original message of the error - */ - originalMessage: string - - parse?(): void - - parseError(error: Error): void - - parseContext(context?: ErrorContext): void - - setType(type: ErrorType): void - - setCode(code: ErrorCode): void - - setStack(stack: string): void - - setName(name: string): void - - setMessage(message: string): void - - setContextModule(contextModule: string): void - - toOriginalError(): Error - - toError(): Error - - toString(): string -} +export * from './context' diff --git a/packages/sdk-ts/src/core/modules/index.ts b/packages/sdk-ts/src/core/modules/index.ts index 3f05a6950..5426047f4 100644 --- a/packages/sdk-ts/src/core/modules/index.ts +++ b/packages/sdk-ts/src/core/modules/index.ts @@ -10,6 +10,6 @@ export * from './peggy' export * from './staking' export * from './tokenfactory' export * from './wasm' -export * from './msgs' export * from './feegrant' export * from './permissions' +export * from './msgs' diff --git a/packages/sdk-ts/src/core/tx/api/index.ts b/packages/sdk-ts/src/core/tx/api/index.ts index 237c4714d..f950ff46e 100644 --- a/packages/sdk-ts/src/core/tx/api/index.ts +++ b/packages/sdk-ts/src/core/tx/api/index.ts @@ -1,11 +1,3 @@ -import { TxRestApi } from './TxRestApi' -import { TxGrpcApi } from './TxGrpcApi' - export * from './TxGrpcApi' export * from './TxRestApi' export * from './utils' - -/** - * @deprecated use TxRestApi and TxGrpcApi - **/ -export { TxRestApi as TxRestClient, TxGrpcApi as TxGrpcClient } diff --git a/packages/sdk-ts/src/types/cosmos.ts b/packages/sdk-ts/src/types/cosmos.ts new file mode 100644 index 000000000..44347c01d --- /dev/null +++ b/packages/sdk-ts/src/types/cosmos.ts @@ -0,0 +1,25 @@ +import { DirectSignResponse } from '@cosmjs/proto-signing' +import { AminoSignResponse } from '@cosmjs/amino' +import { + CosmosTxV1Beta1Tx, + CosmosBaseV1Beta1Coin, +} from '@injectivelabs/core-proto-ts' + +export interface Coin { + denom: string + amount: string +} + +export enum StreamOperation { + Insert = 'insert', + Delete = 'delete', + Replace = 'replace', + Update = 'update', + Invalidate = 'invalidate', +} + +export type GrpcCoin = CosmosBaseV1Beta1Coin.Coin +export type TxRaw = CosmosTxV1Beta1Tx.TxRaw +export type SignDoc = CosmosTxV1Beta1Tx.SignDoc + +export { DirectSignResponse, AminoSignResponse } diff --git a/packages/sdk-ts/src/types/index.ts b/packages/sdk-ts/src/types/index.ts index c78f735aa..124bf7241 100644 --- a/packages/sdk-ts/src/types/index.ts +++ b/packages/sdk-ts/src/types/index.ts @@ -1,29 +1,4 @@ -import { DirectSignResponse } from '@cosmjs/proto-signing' -import { AminoSignResponse } from '@cosmjs/amino' -import { - CosmosTxV1Beta1Tx, - CosmosBaseV1Beta1Coin, -} from '@injectivelabs/core-proto-ts' - export * from './token' export * from './exchange' export * from './pagination' - -export interface Coin { - denom: string - amount: string -} - -export enum StreamOperation { - Insert = 'insert', - Delete = 'delete', - Replace = 'replace', - Update = 'update', - Invalidate = 'invalidate', -} - -export type GrpcCoin = CosmosBaseV1Beta1Coin.Coin -export type TxRaw = CosmosTxV1Beta1Tx.TxRaw -export type SignDoc = CosmosTxV1Beta1Tx.SignDoc - -export { DirectSignResponse, AminoSignResponse } +export * from './cosmos' diff --git a/packages/ts-types/src/common.ts b/packages/ts-types/src/common.ts new file mode 100644 index 000000000..b52f94a44 --- /dev/null +++ b/packages/ts-types/src/common.ts @@ -0,0 +1,28 @@ +export interface StreamStatusResponse { + details: string + code: number + metadata: any +} + +export enum StreamOperation { + Insert = 'insert', + Delete = 'delete', + Replace = 'replace', + Update = 'update', + Invalidate = 'invalidate', +} + +export interface PaginationOption { + key: string + offset?: number + skip?: number + limit?: number + reverse?: boolean + countTotal?: boolean +} + +export interface Constructable { + new (...args: never): T +} + +export type UnwrappedPromise = T extends Promise ? Return : T diff --git a/packages/ts-types/src/index.ts b/packages/ts-types/src/index.ts index b9f19e953..f792a317c 100644 --- a/packages/ts-types/src/index.ts +++ b/packages/ts-types/src/index.ts @@ -3,32 +3,4 @@ export * from './aliases' export * from './transactions' export * from './cosmos' export * from './trade' - -export interface StreamStatusResponse { - details: string - code: number - metadata: any -} - -export enum StreamOperation { - Insert = 'insert', - Delete = 'delete', - Replace = 'replace', - Update = 'update', - Invalidate = 'invalidate', -} - -export interface PaginationOption { - key: string - offset?: number - skip?: number - limit?: number - reverse?: boolean - countTotal?: boolean -} - -export interface Constructable { - new (...args: never): T -} - -export type UnwrappedPromise = T extends Promise ? Return : T +export * from './common'