From 2132b082fcf67ecb9f2fa2644cf7b68defef322d Mon Sep 17 00:00:00 2001 From: yknl Date: Mon, 10 Aug 2020 23:57:21 -0400 Subject: [PATCH] feat: update common package --- packages/common/src/constants.ts | 19 ++++++++++ packages/common/src/index.ts | 3 +- packages/common/src/utils.ts | 63 -------------------------------- 3 files changed, 21 insertions(+), 64 deletions(-) create mode 100644 packages/common/src/constants.ts diff --git a/packages/common/src/constants.ts b/packages/common/src/constants.ts new file mode 100644 index 000000000..7d0520619 --- /dev/null +++ b/packages/common/src/constants.ts @@ -0,0 +1,19 @@ +enum ChainID { + Testnet = 0x80000000, + Mainnet = 0x00000001, +} + +enum TransactionVersion { + Mainnet = 0x00, + Testnet = 0x80, +} + +export { + ChainID, + TransactionVersion, +}; + +/** +* @ignore +*/ +export const BLOCKSTACK_DEFAULT_GAIA_HUB_URL = 'https://hub.blockstack.org' \ No newline at end of file diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 251163437..edc32a758 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -2,4 +2,5 @@ export * from './config'; export * from './errors'; export * from './fetchUtil'; export * from './logger'; -export * from './utils'; \ No newline at end of file +export * from './utils'; +export * from './constants'; \ No newline at end of file diff --git a/packages/common/src/utils.ts b/packages/common/src/utils.ts index 20af670cf..96b484d20 100644 --- a/packages/common/src/utils.ts +++ b/packages/common/src/utils.ts @@ -1,15 +1,4 @@ import { Logger } from './logger' -import { - BadPathError, - ConflictError, - DoesNotExist, - GaiaHubErrorResponse, - NotEnoughProofError, - PayloadTooLargeError, - ValidationError, - PreconditionFailedError -} from './errors' - /** * @ignore @@ -349,55 +338,3 @@ export function getGlobalObjects>( } return result } - -async function getGaiaErrorResponse(response: Response): Promise { - let responseMsg = '' - let responseJson: any | undefined - try { - responseMsg = await response.text() - try { - responseJson = JSON.parse(responseMsg) - } catch (error) { - // Use text instead - } - } catch (error) { - Logger.debug(`Error getting bad http response text: ${error}`) - } - const status = response.status - const statusText = response.statusText - const body = responseJson || responseMsg - return { status, statusText, body } -} - -/** - * Returns a BlockstackError correlating to the given HTTP response, - * with the provided errorMsg. Throws if the HTTP response is 'ok'. - */ -// export async function getBlockstackErrorFromResponse( -// response: Response, -// errorMsg: string, -// hubConfig: import('./storage/hub').GaiaHubConfig | null -// ): Promise { -// if (response.ok) { -// throw new Error('Cannot get a BlockstackError from a valid response.') -// } -// const gaiaResponse = await getGaiaErrorResponse(response) -// if (gaiaResponse.status === 401) { -// return new ValidationError(errorMsg, gaiaResponse) -// } else if (gaiaResponse.status === 402) { -// return new NotEnoughProofError(errorMsg, gaiaResponse) -// } else if (gaiaResponse.status === 403) { -// return new BadPathError(errorMsg, gaiaResponse) -// } else if (gaiaResponse.status === 404) { -// throw new DoesNotExist(errorMsg, gaiaResponse) -// } else if (gaiaResponse.status === 409) { -// return new ConflictError(errorMsg, gaiaResponse) -// } else if (gaiaResponse.status === 412) { -// return new PreconditionFailedError(errorMsg, gaiaResponse) -// } else if (gaiaResponse.status === 413) { -// const maxBytes = megabytesToBytes(hubConfig?.max_file_upload_size_megabytes) -// return new PayloadTooLargeError(errorMsg, gaiaResponse, maxBytes) -// } else { -// return new Error(errorMsg) -// } -// }