Socket
Socket
Sign inDemoInstall

use-upbit-api

Package Overview
Dependencies
7
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

13

lib/src/hooks/useWsOrderbook.js

@@ -10,3 +10,2 @@ "use strict";

const socketDataEncoder_1 = __importDefault(require("../functions/socketDataEncoder"));
const isImarketCodes_1 = __importDefault(require("../functions/isImarketCodes"));
// extend extend OptionsInterface

@@ -28,3 +27,3 @@ /**

const [socketData, setSocketData] = (0, react_1.useState)();
const throttled = (0, react_1.useCallback)((0, lodash_1.throttle)(() => {
const throttled = (0, lodash_1.throttle)(() => {
try {

@@ -38,9 +37,11 @@ const lastBuffers = (0, getLastBuffers_1.default)(buffer.current, [targetMarketCodes].length);

}
}, throttle_time), [targetMarketCodes]);
}, throttle_time);
// socket 세팅
(0, react_1.useEffect)(() => {
try {
if (targetMarketCodes && !(0, isImarketCodes_1.default)(targetMarketCodes)) {
throw new Error('targetMarketCodes does not have the correct interface');
}
// if (targetMarketCodes && !isImarketCodes(targetMarketCodes)) {
// throw new Error(
// 'targetMarketCodes does not have the correct interface',
// );
// }
if ([targetMarketCodes].length > 0 && !socket.current) {

@@ -47,0 +48,0 @@ socket.current = new WebSocket(SOCKET_URL);

@@ -12,3 +12,2 @@ "use strict";

const updateSocketData_1 = __importDefault(require("../functions/updateSocketData"));
const isArrayOfImarketCodes_1 = __importDefault(require("../functions/isArrayOfImarketCodes"));
/**

@@ -30,3 +29,3 @@ * useWsTicker is a custom hook that connects to a WebSocket API

const [socketData, setSocketData] = (0, react_1.useState)();
const throttled = (0, react_1.useCallback)((0, lodash_1.throttle)(() => {
const throttled = (0, lodash_1.throttle)(() => {
try {

@@ -42,10 +41,14 @@ const lastBuffers = (0, getLastBuffers_1.default)(buffer.current, targetMarketCodes.length);

}
}, throttle_time), [targetMarketCodes]);
}, throttle_time);
// socket 세팅
(0, react_1.useEffect)(() => {
try {
if (targetMarketCodes.length > 0 &&
!(0, isArrayOfImarketCodes_1.default)(targetMarketCodes)) {
throw new Error('targetMarketCodes does not have the correct interface');
}
// if (
// targetMarketCodes.length > 0 &&
// !isArrayOfImarketCodes(targetMarketCodes)
// ) {
// throw new Error(
// 'targetMarketCodes does not have the correct interface',
// );
// }
if (targetMarketCodes.length > 0 && !socket.current) {

@@ -52,0 +55,0 @@ socket.current = new WebSocket(SOCKET_URL);

@@ -10,3 +10,2 @@ "use strict";

const socketDataEncoder_1 = __importDefault(require("../functions/socketDataEncoder"));
const isImarketCodes_1 = __importDefault(require("../functions/isImarketCodes"));
/**

@@ -28,3 +27,3 @@ * useWsTrade is a custom hook that connects to a WebSocket API

const [socketData, setSocketData] = (0, react_1.useState)();
const throttled = (0, react_1.useCallback)((0, lodash_1.throttle)(() => {
const throttled = (0, lodash_1.throttle)(() => {
try {

@@ -38,9 +37,11 @@ const updatedBuffer = (0, updateQueueBuffer_1.default)(buffer.current, max_length_queue);

}
}, throttle_time), [targetMarketCodes]);
}, throttle_time);
// socket 세팅
(0, react_1.useEffect)(() => {
try {
if (targetMarketCodes && !(0, isImarketCodes_1.default)(targetMarketCodes)) {
throw new Error('targetMarketCodes does not have the correct interface');
}
// if (targetMarketCodes && !isImarketCodes(targetMarketCodes)) {
// throw new Error(
// 'targetMarketCodes does not have the correct interface',
// );
// }
if ([targetMarketCodes].length > 0 && !socket.current) {

@@ -47,0 +48,0 @@ socket.current = new WebSocket(SOCKET_URL);

@@ -44,3 +44,2 @@ "use strict";

require("@testing-library/jest-dom/extend-expect");
const ErrorBoundary_1 = __importDefault(require("./ErrorBoundary"));
const debugTest = false;

@@ -71,14 +70,22 @@ const TestOrderbookComponent = ({ customMarketCode, onError, }) => {

// Test invalid targetMarketCodes
it('useWsOrderbook should throw error with invalid targetMarketCodes', () => {
const onError = jest.fn();
const invalidTargetMarketCodes = {
market: 'test_market',
korean_name: 'test_korean',
};
// Render the TestOrderbookComponent
(0, react_2.render)(React.createElement(ErrorBoundary_1.default, { onError: onError },
React.createElement(TestOrderbookComponent, { customMarketCode: invalidTargetMarketCodes, onError: onError })));
expect(onError).toHaveBeenCalled();
expect(onError.mock.calls[0][0].message).toBe('targetMarketCodes does not have the correct interface');
});
// it('useWsOrderbook should throw error with invalid targetMarketCodes', () => {
// const onError: jest.MockedFunction<(error: Error) => void> = jest.fn();
// const invalidTargetMarketCodes = {
// market: 'test_market',
// korean_name: 'test_korean',
// };
// // Render the TestOrderbookComponent
// render(
// <ErrorBoundary onError={onError}>
// <TestOrderbookComponent
// customMarketCode={invalidTargetMarketCodes}
// onError={onError}
// />
// </ErrorBoundary>,
// );
// expect(onError).toHaveBeenCalled();
// expect(onError.mock.calls[0][0].message).toBe(
// 'targetMarketCodes does not have the correct interface',
// );
// });
it('received socket data correctly', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -85,0 +92,0 @@ // Render the TestOrderbookComponent

@@ -43,3 +43,2 @@ "use strict";

require("@testing-library/jest-dom/extend-expect");
const ErrorBoundary_1 = __importDefault(require("./ErrorBoundary"));
const debugTest = false;

@@ -56,3 +55,2 @@ const TestTickerComponent = ({ customMarketCode, onError, }) => {

if (customMarketCode) {
console.log('here', customMarketCode);
setMarketCode(() => customMarketCode);

@@ -73,21 +71,29 @@ }

// Test invalid targetMarketCodes
it('useWsTicker should throw error with invalid targetMarketCodes', () => {
const onError = jest.fn();
const invalidTargetMarketCodes = [
{
market: 'KRW-BTC',
korean_name: '비트코인',
english_name: 'Bitcoin',
},
{
market: 'KRW-ETH',
korean_name: '이더리움',
},
];
// Render the TestOrderbookComponent
(0, react_2.render)(React.createElement(ErrorBoundary_1.default, { onError: onError },
React.createElement(TestTickerComponent, { customMarketCode: invalidTargetMarketCodes, onError: onError })));
expect(onError).toHaveBeenCalled();
expect(onError.mock.calls[0][0].message).toBe('targetMarketCodes does not have the correct interface');
});
// it('useWsTicker should throw error with invalid targetMarketCodes', () => {
// const onError: jest.MockedFunction<(error: Error) => void> = jest.fn();
// const invalidTargetMarketCodes = [
// {
// market: 'KRW-BTC',
// korean_name: '비트코인',
// english_name: 'Bitcoin',
// },
// {
// market: 'KRW-ETH',
// korean_name: '이더리움',
// },
// ];
// // Render the TestOrderbookComponent
// render(
// <ErrorBoundary onError={onError}>
// <TestTickerComponent
// customMarketCode={invalidTargetMarketCodes}
// onError={onError}
// />
// </ErrorBoundary>,
// );
// expect(onError).toHaveBeenCalled();
// expect(onError.mock.calls[0][0].message).toBe(
// 'targetMarketCodes does not have the correct interface',
// );
// });
it('renders connection status and received socket data', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -94,0 +100,0 @@ // Render the TestTickerComponent

@@ -45,3 +45,2 @@ "use strict";

const react_3 = require("react");
const ErrorBoundary_1 = __importDefault(require("./ErrorBoundary"));
const debugTest = false;

@@ -72,14 +71,22 @@ const TestTradeComponent = ({ customMarketCode, onError, }) => {

// Test invalid targetMarketCodes
it('useWsTrade should throw error with invalid targetMarketCodes', () => {
const onError = jest.fn();
const invalidTargetMarketCodes = {
market: 'test_market',
korean_name: 'test_korean',
};
// Render the TestTradeComponent
(0, react_2.render)(React.createElement(ErrorBoundary_1.default, { onError: onError },
React.createElement(TestTradeComponent, { customMarketCode: invalidTargetMarketCodes, onError: onError })));
expect(onError).toHaveBeenCalled();
expect(onError.mock.calls[0][0].message).toBe('targetMarketCodes does not have the correct interface');
});
// it('useWsTrade should throw error with invalid targetMarketCodes', () => {
// const onError: jest.MockedFunction<(error: Error) => void> = jest.fn();
// const invalidTargetMarketCodes = {
// market: 'test_market',
// korean_name: 'test_korean',
// };
// // Render the TestTradeComponent
// render(
// <ErrorBoundary onError={onError}>
// <TestTradeComponent
// customMarketCode={invalidTargetMarketCodes}
// onError={onError}
// />
// </ErrorBoundary>,
// );
// expect(onError).toHaveBeenCalled();
// expect(onError.mock.calls[0][0].message).toBe(
// 'targetMarketCodes does not have the correct interface',
// );
// });
it('renders connection status and received socket data', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -86,0 +93,0 @@ // Render the TestTradeComponent

{
"name": "use-upbit-api",
"version": "2.0.2",
"version": "2.0.3",
"description": "This is React Custom Hook for upbit api",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc