Skip to content

Commit

Permalink
fix: imports
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Oct 29, 2024
1 parent b1c3008 commit 877486d
Show file tree
Hide file tree
Showing 31 changed files with 104 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ import {
UnspecifiedErrorCode,
ErrorContextCode,
} from './types'
import { toPascalCase } from './utils'

/**
* we have to define it here as
* well as in @injectivelabs/utils as that package is
* importing the exceptions package
* */
const toPascalCase = (str: string): string => {
return `${str}`
.toLowerCase()
.replace(new RegExp(/[-_]+/, 'g'), ' ')
.replace(new RegExp(/[^\w\s]/, 'g'), '')
.replace(
new RegExp(/\s+(.)(\w*)/, 'g'),
(_$1, $2, $3) => `${$2.toUpperCase() + $3}`,
)
.replace(new RegExp(/\w/), (s) => s.toUpperCase())
}

export abstract class ConcreteException extends Error implements Exception {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'
import { ErrorContext, ErrorType } from '../types'
import { mapMetamaskMessage } from '../utils/maps'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'
import { ErrorContext, ErrorType } from '../types'

export class CosmosWalletException extends ConcreteException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'


export class GeneralException extends ConcreteException {
public errorClass: string = 'GeneralException'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType, GRPC_REQUEST_FAILED } from '../types'

export class GrpcUnaryRequestException extends ConcreteException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType, HttpRequestMethod } from '../types'

export class HttpRequestException extends ConcreteException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'
import { isCommonLockedError } from '../utils/helpers'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'
import { isCommonLockedError } from '../utils/helpers'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'
import { mapMetamaskMessage } from '../utils/maps'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'
import { mapMetamaskMessage } from '../utils/maps'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'
import { mapFailedTransactionMessage, parseErrorMessage } from '../utils/maps'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'

export class TrezorException extends ConcreteException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'
import { mapMetamaskMessage } from '../utils/maps'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'


export class WalletException extends ConcreteException {
public errorClass: string = 'WalletException'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConcreteException } from '../exception'
import { ConcreteException } from '../base'

import { ErrorContext, ErrorType } from '../types'

export class Web3Exception extends ConcreteException {
Expand Down
1 change: 0 additions & 1 deletion packages/exceptions/src/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './exceptions'
export * from './types'
export * from './utils'
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {
ErrorContextCode,
ChainAuctionErrorCodes,
ChainCosmosErrorCode,
ChainOcrErrorCodes,
ChainOracleErrorCodes,
ChainExchangeModuleErrorCode,
ChainInsuranceErrorCodes,
ChainPeggyErrorCodes,
ChainTokenFactoryErrorCodes,
ChainWasmXErrorCodes,
TransactionChainErrorModule,
ChainStakingErrorCodes,
ChainGovErrorCodes,
ChainBankErrorCodes,
ChainDistributionErrorCodes,
ChainWasmErrorCodes,
ChainAuthZErrorCodes,
ChainPeggyErrorCodes,
ChainCosmosErrorCode,
ChainWasmXErrorCodes,
ChainOracleErrorCodes,
ChainStakingErrorCodes,
ChainAuctionErrorCodes,
ChainInsuranceErrorCodes,
ChainTokenFactoryErrorCodes,
ChainDistributionErrorCodes,
TransactionChainErrorModule,
ChainExchangeModuleErrorCode,
} from './types'

const auctionErrorMap = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion packages/exceptions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './exceptions'
export * from './exception'
export * from './utils'
export * from './types'
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
CosmosWalletException,
TransactionException,
GrpcUnaryRequestException,
} from './exceptions'
} from './exceptions/exceptions'

export type ThrownException =
| GrpcUnaryRequestException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { ConcreteException } from "../exception"
import { Exception } from "../types"
import { Exception } from './exceptions/types'

export const isThrownException = (exception: Error | Exception): boolean => {
if (exception instanceof ConcreteException) {
return true
}

if (
[
'GrpcUnaryRequestException',
Expand All @@ -29,3 +24,19 @@ export const isThrownException = (exception: Error | Exception): boolean => {

return false
}

export const formatNotificationDescription = (description: string) => {
const DESCRIPTION_CHARACTER_LIMIT = 50

if (description.length <= DESCRIPTION_CHARACTER_LIMIT) {
return {
description,
tooltip: '',
}
}

return {
description: description.slice(0, DESCRIPTION_CHARACTER_LIMIT) + ' ...',
tooltip: description,
}
}
26 changes: 0 additions & 26 deletions packages/exceptions/src/utils/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sdk-ts/src/core/tx/eip712/maps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GeneralException } from '@injectivelabs/exceptions'
import snakecaseKeys from 'snakecase-keys'
import { snakeToPascal } from '../../../utils/helpers'
import { snakeToPascal } from '@injectivelabs/utils'
import { isNumber, numberToCosmosSdkDecString } from '../../../utils/numbers'
import { TypedDataField } from './types'

Expand Down
24 changes: 0 additions & 24 deletions packages/sdk-ts/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,6 @@ export const uint8ArrayToString = (
return new TextDecoder().decode(string)
}

export const toPascalCase = (str: string): string => {
return `${str}`
.toLowerCase()
.replace(new RegExp(/[-_]+/, 'g'), ' ')
.replace(new RegExp(/[^\w\s]/, 'g'), '')
.replace(
new RegExp(/\s+(.)(\w*)/, 'g'),
(_$1, $2, $3) => `${$2.toUpperCase() + $3}`,
)
.replace(new RegExp(/\w/), (s) => s.toUpperCase())
}

export const snakeToPascal = (str: string): string => {
return str
.split('/')
.map((snake) =>
snake
.split('_')
.map((substr) => substr.charAt(0).toUpperCase() + substr.slice(1))
.join(''),
)
.join('/')
}

export const sortObjectByKeysWithReduce = <T>(obj: T): T => {
if (typeof obj !== 'object' || obj === null) return obj

Expand Down
24 changes: 24 additions & 0 deletions packages/utils/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,27 @@ export const formatWalletAddress = (
address.length,
)}`
}

export const toPascalCase = (str: string): string => {
return `${str}`
.toLowerCase()
.replace(new RegExp(/[-_]+/, 'g'), ' ')
.replace(new RegExp(/[^\w\s]/, 'g'), '')
.replace(
new RegExp(/\s+(.)(\w*)/, 'g'),
(_$1, $2, $3) => `${$2.toUpperCase() + $3}`,
)
.replace(new RegExp(/\w/), (s) => s.toUpperCase())
}

export const snakeToPascal = (str: string): string => {
return str
.split('/')
.map((snake) =>
snake
.split('_')
.map((substr) => substr.charAt(0).toUpperCase() + substr.slice(1))
.join(''),
)
.join('/')
}
11 changes: 7 additions & 4 deletions packages/wallets/wallet-evm/src/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
ErrorType,
ErrorContext,
WalletException,
ThrownException,
BitGetException,
ConcreteException,
MetamaskException,
OkxWalletException,
UnspecifiedErrorCode,
Expand Down Expand Up @@ -32,7 +32,7 @@ import {
TxGrpcApi,
TxResponse,
DirectSignResponse,
AminoSignResponse
AminoSignResponse,
} from '@injectivelabs/sdk-ts'
import {
getBitGetProvider,
Expand All @@ -50,7 +50,10 @@ const evmWallets = [
Wallet.TrustWallet,
]

export class EvmWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy {
export class EvmWallet
extends BaseConcreteStrategy
implements ConcreteWalletStrategy
{
public wallet?: Wallet

constructor(
Expand All @@ -72,7 +75,7 @@ export class EvmWallet extends BaseConcreteStrategy implements ConcreteWalletStr
public EvmWalletException(
error: Error,
context?: ErrorContext,
): ConcreteException {
): ThrownException {
if (this.wallet === Wallet.Metamask) {
return new MetamaskException(error, context)
}
Expand Down

0 comments on commit 877486d

Please sign in to comment.