Skip to content

Commit

Permalink
Remove types and fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Apr 30, 2024
1 parent dae8e3f commit e82260d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: creating u64, u128, u256 types as wrapper of bigint, adding a from and to generic function that convert everything
import { U64_MAX } from './numbers'

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ export function bytesToStr(arr: Uint8Array): string {
const decoder = new StringDecoder('utf-8')

return decoder.write(Buffer.from(arr))
} else {
let { TextDecoder } = window
if (typeof TextDecoder === 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
TextDecoder = require('util').TextDecoder
}
const textDecoder = new TextDecoder('utf-8')

return textDecoder.decode(arr)
}
let { TextDecoder } = window

Check warning on line 36 in packages/massa-web3/src/experimental/basicElements/serializers/strings.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (typeof TextDecoder === 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
TextDecoder = require('util').TextDecoder

Check warning on line 39 in packages/massa-web3/src/experimental/basicElements/serializers/strings.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 40 in packages/massa-web3/src/experimental/basicElements/serializers/strings.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 40 in packages/massa-web3/src/experimental/basicElements/serializers/strings.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const textDecoder = new TextDecoder('utf-8')

Check warning on line 41 in packages/massa-web3/src/experimental/basicElements/serializers/strings.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

return textDecoder.decode(arr)

Check warning on line 43 in packages/massa-web3/src/experimental/basicElements/serializers/strings.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
9 changes: 3 additions & 6 deletions packages/massa-web3/src/experimental/errors/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type BaseParameters = {
}
)

export type ErrorTypeBase = ErrorBase & { name: 'WalletProviderError' }
/**
* ErrorBase extends the native Error class to provide additional metadata handling for richer error information.
* This class can serve as a base for more specific error types in a wallet or similar system.
Expand All @@ -24,12 +23,10 @@ export class ErrorBase extends Error {
metaMessages: string[]
docsPath?: string
code: ErrorCodes
cause?: Error

override name = 'MassaWeb3Error'
constructor(
shortMessage: string,
args: BaseParameters = { code: ErrorCodes.UnknownError }
) {
constructor(shortMessage: string, args: BaseParameters) {
super()

const metaMessageStr =
Expand All @@ -51,7 +48,7 @@ export class ErrorBase extends Error {

this.metaMessages = args.metaMessages || []
this.docsPath = args.docsPath
this.code = args.code
this.code = args.code ?? ErrorCodes.UnknownError
this.cause = args.cause
}
}
11 changes: 4 additions & 7 deletions packages/massa-web3/src/experimental/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export { ErrorBase, type ErrorTypeBase } from './base'
export { ErrorMaxGas, type ErrorTypeMaxGas } from './maxGas'
export { ErrorMinimalFee, type ErrorTypeMinimalFee } from './minimalFee'
export {
ErrorInsufficientBalance,
type ErrorTypeInsufficientBalance,
} from './insufficientBalance'
export { ErrorBase } from './base'
export { ErrorMaxGas } from './maxGas'
export { ErrorMinimalFee } from './minimalFee'
export { ErrorInsufficientBalance } from './insufficientBalance'
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ type InsufficientBalanceParameters = {
cause?: Error
}

export type ErrorTypeInsufficientBalance = ErrorInsufficientBalance & {
name: 'ErrorInsufficientBalance'
}

/**
* Error class for handling cases when a user's balance is insufficient for a specified operation.
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/massa-web3/src/experimental/errors/maxGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ type ErrorMaxGasParameters = {
cause?: Error
}

export type ErrorTypeMaxGas = ErrorMaxGas & { name: 'ErrorMaxGas' }

/**
* Error class for handling gas limit errors related to operations, whether exceeding max or falling below min allowed limits.
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/massa-web3/src/experimental/errors/minimalFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ type ErrorMinimalFeeParameters = {
cause?: Error
}

export type ErrorTypeMinimalFee = ErrorMinimalFee & { name: 'ErrorMinimalFee' }

/**
* ErrorMinimalFee is a specific type of error that is thrown when the provided fee for an operation
* is below the minimum required fee for that operation. It extends ErrorBase to provide additional context and metadata.
Expand Down

0 comments on commit e82260d

Please sign in to comment.