@portal-hq/utils
Advanced tools
Comparing version 0.2.17 to 0.2.18
@@ -31,3 +31,2 @@ "use strict"; | ||
const convertCryptoToLocal = (value, from = 'ETH', countryCode) => __awaiter(void 0, void 0, void 0, function* () { | ||
console.log("to local"); | ||
const country = countries_1.countryCodes[countryCode || 'US']; | ||
@@ -49,3 +48,2 @@ if (!country) { | ||
const convertLocalToCrypto = (value, to = 'ETH', countryCode) => __awaiter(void 0, void 0, void 0, function* () { | ||
console.log("to Crypto"); | ||
const country = countries_1.countryCodes[countryCode || 'US']; | ||
@@ -52,0 +50,0 @@ if (!country) { |
@@ -5,3 +5,3 @@ "use strict"; | ||
constructor(message) { | ||
super(`[Portal] An error occurred in the MPC signing process: ${message}`); | ||
super(`[Portal] An error occurred in the MPC signing process: ${message}.`); | ||
// Set the prototype explicitly. | ||
@@ -8,0 +8,0 @@ Object.setPrototypeOf(this, MpcSigningError.prototype); |
@@ -12,19 +12,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseRequest = void 0; | ||
exports.parseRequest = exports.hexStringToString = exports.hexStringToNumber = exports.hexStringToByteArray = void 0; | ||
const currency_1 = require("../currency"); | ||
const hexStringToString = (hexInput) => { | ||
// Get the proper hex string | ||
const byteArray = Array.from(hexStringToByteArray(hexInput.replace('0x', ''))); | ||
// Create an array of characters | ||
const stringArray = byteArray.reduce((acc, charCode) => { | ||
// Add the character matching the charCode | ||
acc.push(String.fromCharCode(charCode)); | ||
// Return the accumulator | ||
return acc; | ||
}, []); | ||
// Join the array of characters | ||
const string = stringArray.join(''); | ||
// Return the final string | ||
return string; | ||
}; | ||
const hexStringToByteArray = (hexString) => { | ||
@@ -49,11 +34,27 @@ // Verify the length of the string | ||
}; | ||
exports.hexStringToByteArray = hexStringToByteArray; | ||
const hexStringToNumber = (hexBalance) => { | ||
const balanceNumber = Number(hexBalance); | ||
console.log(`balanceNumber`, balanceNumber); | ||
const balance = Math.round((balanceNumber / 1e18) * 1000000) / 1000000; | ||
const balance = Math.round((balanceNumber / 1e18) * 100000) / 100000; | ||
return balance; | ||
}; | ||
exports.hexStringToNumber = hexStringToNumber; | ||
const hexStringToString = (hexInput) => { | ||
// Get the proper hex string | ||
const byteArray = Array.from((0, exports.hexStringToByteArray)(hexInput.replace('0x', ''))); | ||
// Create an array of characters | ||
const stringArray = byteArray.reduce((acc, charCode) => { | ||
// Add the character matching the charCode | ||
acc.push(String.fromCharCode(charCode)); | ||
// Return the accumulator | ||
return acc; | ||
}, []); | ||
// Join the array of characters | ||
const string = stringArray.join(''); | ||
// Return the final string | ||
return string; | ||
}; | ||
exports.hexStringToString = hexStringToString; | ||
const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, function* () { | ||
let requestData; | ||
console.log(`Request: `, JSON.stringify({ method, params })); | ||
const txParam0 = Array.isArray(params) ? params[0] : params; | ||
@@ -64,3 +65,3 @@ switch (method) { | ||
const payload = txParam0; | ||
const value = hexStringToNumber(payload.value); | ||
const value = (0, exports.hexStringToNumber)(payload.value); | ||
requestData = { | ||
@@ -80,3 +81,3 @@ data: payload.data, | ||
requestData = { | ||
message: hexStringToString(txParam0), | ||
message: (0, exports.hexStringToString)(txParam0), | ||
}; | ||
@@ -94,5 +95,4 @@ return { | ||
}; | ||
break; | ||
} | ||
}); | ||
exports.parseRequest = parseRequest; |
@@ -19,2 +19,17 @@ "use strict"; | ||
} | ||
buildHeaders(headers = {}) { | ||
return Object.assign({ 'Content-Type': 'application/json' }, headers); | ||
} | ||
delete(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestOptions = { | ||
method: 'DELETE', | ||
url: `${this.baseUrl}${path}`, | ||
}; | ||
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {}); | ||
const request = new index_1.HttpRequest(requestOptions); | ||
const response = (yield request.send()); | ||
return response; | ||
}); | ||
} | ||
get(path, options) { | ||
@@ -26,5 +41,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
}; | ||
if (options && options.headers) { | ||
requestOptions.headers = this.buildHeaders(options.headers); | ||
} | ||
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {}); | ||
const request = new index_1.HttpRequest(requestOptions); | ||
@@ -50,6 +63,3 @@ const response = (yield request.send()); | ||
} | ||
buildHeaders(headers) { | ||
return Object.assign({ 'Content-Type': 'application/json' }, headers); | ||
} | ||
} | ||
exports.default = HttpRequester; |
@@ -27,3 +27,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
export const convertCryptoToLocal = (value, from = 'ETH', countryCode) => __awaiter(void 0, void 0, void 0, function* () { | ||
console.log("to local"); | ||
const country = countryCodes[countryCode || 'US']; | ||
@@ -44,3 +43,2 @@ if (!country) { | ||
export const convertLocalToCrypto = (value, to = 'ETH', countryCode) => __awaiter(void 0, void 0, void 0, function* () { | ||
console.log("to Crypto"); | ||
const country = countryCodes[countryCode || 'US']; | ||
@@ -47,0 +45,0 @@ if (!country) { |
class MpcSigningError extends Error { | ||
constructor(message) { | ||
super(`[Portal] An error occurred in the MPC signing process: ${message}`); | ||
super(`[Portal] An error occurred in the MPC signing process: ${message}.`); | ||
// Set the prototype explicitly. | ||
@@ -5,0 +5,0 @@ Object.setPrototypeOf(this, MpcSigningError.prototype); |
@@ -11,18 +11,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { convert } from '../currency'; | ||
const hexStringToString = (hexInput) => { | ||
// Get the proper hex string | ||
const byteArray = Array.from(hexStringToByteArray(hexInput.replace('0x', ''))); | ||
// Create an array of characters | ||
const stringArray = byteArray.reduce((acc, charCode) => { | ||
// Add the character matching the charCode | ||
acc.push(String.fromCharCode(charCode)); | ||
// Return the accumulator | ||
return acc; | ||
}, []); | ||
// Join the array of characters | ||
const string = stringArray.join(''); | ||
// Return the final string | ||
return string; | ||
}; | ||
const hexStringToByteArray = (hexString) => { | ||
export const hexStringToByteArray = (hexString) => { | ||
// Verify the length of the string | ||
@@ -46,11 +31,24 @@ if (hexString.length % 2 !== 0) { | ||
}; | ||
const hexStringToNumber = (hexBalance) => { | ||
export const hexStringToNumber = (hexBalance) => { | ||
const balanceNumber = Number(hexBalance); | ||
console.log(`balanceNumber`, balanceNumber); | ||
const balance = Math.round((balanceNumber / 1e18) * 1000000) / 1000000; | ||
const balance = Math.round((balanceNumber / 1e18) * 100000) / 100000; | ||
return balance; | ||
}; | ||
export const hexStringToString = (hexInput) => { | ||
// Get the proper hex string | ||
const byteArray = Array.from(hexStringToByteArray(hexInput.replace('0x', ''))); | ||
// Create an array of characters | ||
const stringArray = byteArray.reduce((acc, charCode) => { | ||
// Add the character matching the charCode | ||
acc.push(String.fromCharCode(charCode)); | ||
// Return the accumulator | ||
return acc; | ||
}, []); | ||
// Join the array of characters | ||
const string = stringArray.join(''); | ||
// Return the final string | ||
return string; | ||
}; | ||
export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, function* () { | ||
let requestData; | ||
console.log(`Request: `, JSON.stringify({ method, params })); | ||
const txParam0 = Array.isArray(params) ? params[0] : params; | ||
@@ -89,4 +87,3 @@ switch (method) { | ||
}; | ||
break; | ||
} | ||
}); |
@@ -17,2 +17,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
buildHeaders(headers = {}) { | ||
return Object.assign({ 'Content-Type': 'application/json' }, headers); | ||
} | ||
delete(path, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestOptions = { | ||
method: 'DELETE', | ||
url: `${this.baseUrl}${path}`, | ||
}; | ||
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {}); | ||
const request = new HttpRequest(requestOptions); | ||
const response = (yield request.send()); | ||
return response; | ||
}); | ||
} | ||
get(path, options) { | ||
@@ -24,5 +39,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
}; | ||
if (options && options.headers) { | ||
requestOptions.headers = this.buildHeaders(options.headers); | ||
} | ||
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {}); | ||
const request = new HttpRequest(requestOptions); | ||
@@ -48,6 +61,3 @@ const response = (yield request.send()); | ||
} | ||
buildHeaders(headers) { | ||
return Object.assign({ 'Content-Type': 'application/json' }, headers); | ||
} | ||
} | ||
export default HttpRequester; |
{ | ||
"name": "@portal-hq/utils", | ||
"version": "0.2.17", | ||
"version": "0.2.18", | ||
"main": "lib/commonjs/index", | ||
@@ -17,7 +17,13 @@ "module": "lib/esm/index", | ||
"prepare:cjs": "tsc --outDir lib/commonjs --module commonjs", | ||
"prepare:esm": "tsc --outDir lib/esm --module es2015 --target es2015" | ||
"prepare:esm": "tsc --outDir lib/esm --module es2015 --target es2015", | ||
"test": "jest" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@types/jest": "^29.2.0", | ||
"jest": "^29.2.1", | ||
"jest-environment-jsdom": "^29.2.2", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.8.4" | ||
} | ||
} |
@@ -35,3 +35,2 @@ import { countryCodes, currencyCodes } from './countries' | ||
): Promise<number> => { | ||
console.log("to local"); | ||
@@ -66,3 +65,2 @@ const country = countryCodes[countryCode || 'US'] | ||
): Promise<number> => { | ||
console.log("to Crypto"); | ||
@@ -69,0 +67,0 @@ const country = countryCodes[countryCode || 'US'] |
class MpcSigningError extends Error { | ||
constructor(message: string) { | ||
super(`[Portal] An error occurred in the MPC signing process: ${message}`) | ||
super(`[Portal] An error occurred in the MPC signing process: ${message}.`) | ||
@@ -5,0 +5,0 @@ // Set the prototype explicitly. |
@@ -10,26 +10,3 @@ import { convert } from '../currency' | ||
const hexStringToString = (hexInput: string): string => { | ||
// Get the proper hex string | ||
const byteArray = Array.from(hexStringToByteArray(hexInput.replace('0x', ''))) | ||
// Create an array of characters | ||
const stringArray: string[] = byteArray.reduce( | ||
(acc: string[], charCode: number): string[] => { | ||
// Add the character matching the charCode | ||
acc.push(String.fromCharCode(charCode)) | ||
// Return the accumulator | ||
return acc | ||
}, | ||
[] as string[], | ||
) | ||
// Join the array of characters | ||
const string = stringArray.join('') | ||
// Return the final string | ||
return string | ||
} | ||
const hexStringToByteArray = (hexString: string): Uint8Array => { | ||
export const hexStringToByteArray = (hexString: string): Uint8Array => { | ||
// Verify the length of the string | ||
@@ -61,10 +38,33 @@ if (hexString.length % 2 !== 0) { | ||
const hexStringToNumber = (hexBalance: string): number => { | ||
export const hexStringToNumber = (hexBalance: string): number => { | ||
const balanceNumber = Number(hexBalance) | ||
console.log(`balanceNumber`, balanceNumber) | ||
const balance: number = Math.round((balanceNumber / 1e18) * 1000000) / 1000000 | ||
const balance: number = Math.round((balanceNumber / 1e18) * 100000) / 100000 | ||
return balance | ||
} | ||
export const hexStringToString = (hexInput: string): string => { | ||
// Get the proper hex string | ||
const byteArray = Array.from(hexStringToByteArray(hexInput.replace('0x', ''))) | ||
// Create an array of characters | ||
const stringArray: string[] = byteArray.reduce( | ||
(acc: string[], charCode: number): string[] => { | ||
// Add the character matching the charCode | ||
acc.push(String.fromCharCode(charCode)) | ||
// Return the accumulator | ||
return acc | ||
}, | ||
[] as string[], | ||
) | ||
// Join the array of characters | ||
const string = stringArray.join('') | ||
// Return the final string | ||
return string | ||
} | ||
export const parseRequest = async ( | ||
@@ -76,4 +76,2 @@ method: string, | ||
console.log(`Request: `, JSON.stringify({ method, params })) | ||
const txParam0 = Array.isArray(params) ? params[0] : params | ||
@@ -115,4 +113,3 @@ | ||
} | ||
break | ||
} | ||
} |
@@ -8,7 +8,7 @@ import { | ||
class HttpRequest { | ||
private body: Record<string, any> | ||
private headers: Record<string, any> | ||
private method: ValidHttpRequestMethods | ||
private request: XMLHttpRequest | ||
private url: string | ||
public body: Record<string, any> | ||
public headers: Record<string, any> | ||
public method: ValidHttpRequestMethods | ||
public request: XMLHttpRequest | ||
public url: string | ||
@@ -15,0 +15,0 @@ constructor({ body = {}, headers = {}, method, url }: HttpRequestOptions) { |
@@ -10,3 +10,3 @@ import { HttpRequest } from '../index' | ||
class HttpRequester { | ||
private baseUrl: string | ||
public baseUrl: string | ||
@@ -19,2 +19,25 @@ constructor({ baseUrl }: HttpRequesterOptions) { | ||
public buildHeaders(headers: Record<string, any> = {}): Record<string, any> { | ||
return { | ||
'Content-Type': 'application/json', | ||
...headers, | ||
} | ||
} | ||
public async delete<T>(path: string, options?: HttpOptions): Promise<T> { | ||
const requestOptions = { | ||
method: 'DELETE', | ||
url: `${this.baseUrl}${path}`, | ||
} as HttpRequestOptions | ||
requestOptions.headers = this.buildHeaders( | ||
options && options.headers ? options.headers : {}, | ||
) | ||
const request = new HttpRequest(requestOptions) | ||
const response = (await request.send()) as T | ||
return response | ||
} | ||
public async get<T>(path: string, options?: HttpOptions): Promise<T> { | ||
@@ -26,5 +49,5 @@ const requestOptions = { | ||
if (options && options.headers) { | ||
requestOptions.headers = this.buildHeaders(options.headers) | ||
} | ||
requestOptions.headers = this.buildHeaders( | ||
options && options.headers ? options.headers : {}, | ||
) | ||
@@ -56,11 +79,4 @@ const request = new HttpRequest(requestOptions) | ||
} | ||
private buildHeaders(headers: Record<string, any>): Record<string, any> { | ||
return { | ||
'Content-Type': 'application/json', | ||
...headers, | ||
} | ||
} | ||
} | ||
export default HttpRequester |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96276
3034
6