@renegade-fi/react
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -54,3 +54,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { useTaskHistoryWebSocket, } from './hooks/useTaskHistoryWebSocket.js'; | ||
export { useWallet, } from './hooks/useWalletWebSocket.js'; | ||
export { useWalletWebsocket, } from './hooks/useWalletWebSocket.js'; | ||
export { useWalletId, } from './hooks/useWalletId.js'; | ||
@@ -57,0 +57,0 @@ //////////////////////////////////////////////////////////////////////////////// |
@@ -5,3 +5,3 @@ 'use client'; | ||
import { useConfig } from './useConfig.js'; | ||
import { useWallet } from './useWalletWebSocket.js'; | ||
import { useWalletWebsocket } from './useWalletWebSocket.js'; | ||
import { useStatus } from './useStatus.js'; | ||
@@ -13,3 +13,3 @@ export function useBalances(parameters = {}) { | ||
const [balances, setBalances] = useState([]); | ||
const wallet = useWallet(); | ||
const incomingWallet = useWalletWebsocket(); | ||
useEffect(() => { | ||
@@ -29,6 +29,6 @@ if (status !== 'in relayer') { | ||
useEffect(() => { | ||
if (wallet?.balances) { | ||
setBalances(wallet.balances); | ||
if (incomingWallet?.balances) { | ||
setBalances(incomingWallet.balances); | ||
} | ||
}, [wallet]); | ||
}, [incomingWallet]); | ||
if (filter) { | ||
@@ -35,0 +35,0 @@ return balances.filter((balance) => balance.mint !== '0x0' && balance.amount); |
@@ -8,28 +8,25 @@ 'use client'; | ||
const config = useConfig(parameters); | ||
const [networkOrders, setNetworkOrders] = useState([]); | ||
const orderBook = useOrderBookWebSocket(); | ||
const [networkOrders, setNetworkOrders] = useState(new Map()); | ||
const incomingOrder = useOrderBookWebSocket(); | ||
useEffect(() => { | ||
async function fetchNetworkOrders() { | ||
const initialNetworkOrders = await getNetworkOrders(config); | ||
setNetworkOrders(initialNetworkOrders); | ||
const ordersMap = new Map(initialNetworkOrders.map((order) => [order.id, order])); | ||
setNetworkOrders(ordersMap); | ||
} | ||
fetchNetworkOrders(); | ||
const interval = setInterval(async () => { | ||
const updatedNetworkOrders = await getNetworkOrders(config); | ||
setNetworkOrders(updatedNetworkOrders); | ||
}, 5000); // Set interval to 5 second | ||
return () => clearInterval(interval); // Cleanup interval on component unmount | ||
}, [config]); | ||
useEffect(() => { | ||
if (orderBook && orderBook.length > 0) { | ||
setNetworkOrders((currentOrders) => { | ||
const updatedOrderMap = new Map(orderBook.map((order) => [order.id, order])); | ||
return currentOrders | ||
.map((order) => updatedOrderMap.get(order.id) || order) | ||
.filter((order) => order !== undefined); | ||
}); | ||
if (incomingOrder) { | ||
setNetworkOrders((prev) => new Map(prev).set(incomingOrder.id, incomingOrder)); | ||
} | ||
}, [orderBook]); | ||
return networkOrders.sort((a, b) => (a.timestamp > b.timestamp ? -1 : 1)); | ||
}, [incomingOrder]); | ||
const sortedNetworkOrders = Array.from(networkOrders.values()).sort((a, b) => { | ||
if (a.timestamp === b.timestamp) { | ||
return a.id.localeCompare(b.id); | ||
} | ||
return a.timestamp > b.timestamp ? -1 : 1; | ||
}); | ||
return sortedNetworkOrders; | ||
} | ||
//# sourceMappingURL=useOrderBook.js.map |
@@ -10,3 +10,3 @@ 'use client'; | ||
const { getWebsocketBaseUrl } = config; | ||
const [orders, setOrders] = useState([]); | ||
const [order, setOrder] = useState(); | ||
const { lastMessage, readyState, sendJsonMessage } = useWebSocket.default(getWebsocketBaseUrl(), { | ||
@@ -37,13 +37,3 @@ share: true, | ||
messageData.event?.order) { | ||
setOrders((prevOrders) => { | ||
const existingIndex = prevOrders.findIndex((o) => o.id === messageData.event.order.id); | ||
const updatedOrders = [...prevOrders]; | ||
if (existingIndex !== -1) { | ||
updatedOrders[existingIndex] = messageData.event.order; | ||
} | ||
else { | ||
updatedOrders.push(messageData.event.order); | ||
} | ||
return updatedOrders; | ||
}); | ||
setOrder(messageData.event.order); | ||
} | ||
@@ -56,4 +46,4 @@ } | ||
}, [lastMessage]); | ||
return orders; | ||
return order; | ||
} | ||
//# sourceMappingURL=useOrderBookWebSocket.js.map |
@@ -5,4 +5,4 @@ 'use client'; | ||
import { useConfig } from './useConfig.js'; | ||
import { useWallet } from './useWalletWebSocket.js'; | ||
import { useStatus } from './useStatus.js'; | ||
import { useWalletWebsocket } from './useWalletWebSocket.js'; | ||
export function useOrders(parameters = {}) { | ||
@@ -13,3 +13,3 @@ const config = useConfig(parameters); | ||
const [orders, setOrders] = useState([]); | ||
const wallet = useWallet(); | ||
const incomingWallet = useWalletWebsocket(); | ||
useEffect(() => { | ||
@@ -29,6 +29,6 @@ if (status !== 'in relayer') { | ||
useEffect(() => { | ||
if (wallet?.orders) { | ||
setOrders(wallet.orders); | ||
if (incomingWallet?.orders) { | ||
setOrders(incomingWallet.orders); | ||
} | ||
}, [wallet]); | ||
}, [incomingWallet]); | ||
if (filter) { | ||
@@ -35,0 +35,0 @@ return orders.filter((order) => order.amount > 0); |
@@ -8,3 +8,3 @@ 'use client'; | ||
import { getSkRoot, useStatus, useWalletId } from '../index.js'; | ||
export function useWallet(parameters = {}) { | ||
export function useWalletWebsocket(parameters = {}) { | ||
const config = useConfig(parameters); | ||
@@ -11,0 +11,0 @@ const status = useStatus(parameters); |
@@ -54,3 +54,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { useTaskHistoryWebSocket, } from './hooks/useTaskHistoryWebSocket.js'; | ||
export { useWallet, } from './hooks/useWalletWebSocket.js'; | ||
export { useWalletWebsocket, } from './hooks/useWalletWebSocket.js'; | ||
export { useWalletId, } from './hooks/useWalletId.js'; | ||
@@ -57,0 +57,0 @@ //////////////////////////////////////////////////////////////////////////////// |
@@ -5,4 +5,4 @@ import { type Config, type NetworkOrder } from '@renegade-fi/core'; | ||
}; | ||
export type UseOrderBookWebSocketReturnType = NetworkOrder[] | undefined; | ||
export type UseOrderBookWebSocketReturnType = NetworkOrder | undefined; | ||
export declare function useOrderBookWebSocket(parameters?: UseOrderBookWebSocketParameters): UseOrderBookWebSocketReturnType; | ||
//# sourceMappingURL=useOrderBookWebSocket.d.ts.map |
@@ -6,3 +6,3 @@ import { type Config, type Wallet } from '@renegade-fi/core'; | ||
export type UseWalletReturnType = Wallet | undefined; | ||
export declare function useWallet(parameters?: UseWalletParameters): UseWalletReturnType; | ||
export declare function useWalletWebsocket(parameters?: UseWalletParameters): UseWalletReturnType; | ||
//# sourceMappingURL=useWalletWebSocket.d.ts.map |
@@ -32,3 +32,3 @@ import { createConfig as core_createConfig } from '@renegade-fi/core'; | ||
export { useTaskHistoryWebSocket, type UseTaskHistoryWebSocketParameters, type UseTaskHistoryWebSocketReturnType, } from './hooks/useTaskHistoryWebSocket.js'; | ||
export { useWallet, type UseWalletParameters, type UseWalletReturnType, } from './hooks/useWalletWebSocket.js'; | ||
export { useWalletWebsocket, type UseWalletParameters, type UseWalletReturnType, } from './hooks/useWalletWebSocket.js'; | ||
export { useWalletId, type UseWalletIdParameters, type UseWalletIdReturnType, } from './hooks/useWalletId.js'; | ||
@@ -35,0 +35,0 @@ export { Token } from '@renegade-fi/core'; |
{ | ||
"name": "@renegade-fi/react", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "React library for Renegade", | ||
@@ -40,3 +40,3 @@ "files": [ | ||
"tiny-invariant": "^1.3.3", | ||
"@renegade-fi/core": "0.0.9" | ||
"@renegade-fi/core": "0.0.10" | ||
}, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
@@ -501,2 +501,8 @@ let wasm; | ||
}; | ||
imports.wbg.__wbindgen_object_drop_ref = function(arg0) { | ||
takeObject(arg0); | ||
}; | ||
imports.wbg.__wbg_log_5bb5f88f245d7762 = function(arg0) { | ||
console.log(getObject(arg0)); | ||
}; | ||
imports.wbg.__wbg_crypto_6a16ba611e8c0315 = function(arg0) { | ||
@@ -527,5 +533,2 @@ const ret = getObject(arg0).crypto; | ||
}; | ||
imports.wbg.__wbindgen_object_drop_ref = function(arg0) { | ||
takeObject(arg0); | ||
}; | ||
imports.wbg.__wbg_require_8c61ef97678a5df5 = function() { return handleError(function () { | ||
@@ -532,0 +535,0 @@ const ret = module.require; |
@@ -7,3 +7,3 @@ 'use client' | ||
import { useConfig } from './useConfig.js' | ||
import { useWallet } from './useWalletWebSocket.js' | ||
import { useWalletWebsocket } from './useWalletWebSocket.js' | ||
import { useStatus } from './useStatus.js' | ||
@@ -25,3 +25,3 @@ | ||
const [balances, setBalances] = useState<Balance[]>([]) | ||
const wallet = useWallet() | ||
const incomingWallet = useWalletWebsocket() | ||
@@ -46,6 +46,6 @@ useEffect(() => { | ||
useEffect(() => { | ||
if (wallet?.balances) { | ||
setBalances(wallet.balances) | ||
if (incomingWallet?.balances) { | ||
setBalances(incomingWallet.balances) | ||
} | ||
}, [wallet]) | ||
}, [incomingWallet]) | ||
@@ -52,0 +52,0 @@ if (filter) { |
@@ -19,4 +19,6 @@ 'use client' | ||
const config = useConfig(parameters) | ||
const [networkOrders, setNetworkOrders] = useState<NetworkOrder[]>([]) | ||
const orderBook = useOrderBookWebSocket() | ||
const [networkOrders, setNetworkOrders] = useState<Map<string, NetworkOrder>>( | ||
new Map(), | ||
) | ||
const incomingOrder = useOrderBookWebSocket() | ||
@@ -26,29 +28,29 @@ useEffect(() => { | ||
const initialNetworkOrders = await getNetworkOrders(config) | ||
setNetworkOrders(initialNetworkOrders) | ||
const ordersMap = new Map( | ||
initialNetworkOrders.map((order) => [order.id, order]), | ||
) | ||
setNetworkOrders(ordersMap) | ||
} | ||
fetchNetworkOrders() | ||
const interval = setInterval(async () => { | ||
const updatedNetworkOrders = await getNetworkOrders(config) | ||
setNetworkOrders(updatedNetworkOrders) | ||
}, 5000) // Set interval to 5 second | ||
return () => clearInterval(interval) // Cleanup interval on component unmount | ||
}, [config]) | ||
useEffect(() => { | ||
if (orderBook && orderBook.length > 0) { | ||
setNetworkOrders((currentOrders) => { | ||
const updatedOrderMap = new Map( | ||
orderBook.map((order) => [order.id, order]), | ||
) | ||
return currentOrders | ||
.map((order) => updatedOrderMap.get(order.id) || order) | ||
.filter((order) => order !== undefined) as NetworkOrder[] | ||
}) | ||
if (incomingOrder) { | ||
setNetworkOrders((prev) => | ||
new Map(prev).set(incomingOrder.id, incomingOrder), | ||
) | ||
} | ||
}, [orderBook]) | ||
}, [incomingOrder]) | ||
return networkOrders.sort((a, b) => (a.timestamp > b.timestamp ? -1 : 1)) | ||
const sortedNetworkOrders = Array.from(networkOrders.values()).sort( | ||
(a, b) => { | ||
if (a.timestamp === b.timestamp) { | ||
return a.id.localeCompare(b.id) | ||
} | ||
return a.timestamp > b.timestamp ? -1 : 1 | ||
}, | ||
) | ||
return sortedNetworkOrders | ||
} |
@@ -17,3 +17,3 @@ 'use client' | ||
export type UseOrderBookWebSocketReturnType = NetworkOrder[] | undefined | ||
export type UseOrderBookWebSocketReturnType = NetworkOrder | undefined | ||
@@ -25,3 +25,3 @@ export function useOrderBookWebSocket( | ||
const { getWebsocketBaseUrl } = config | ||
const [orders, setOrders] = useState<NetworkOrder[]>([]) | ||
const [order, setOrder] = useState<NetworkOrder>() | ||
@@ -62,14 +62,3 @@ const { lastMessage, readyState, sendJsonMessage } = useWebSocket.default( | ||
) { | ||
setOrders((prevOrders) => { | ||
const existingIndex = prevOrders.findIndex( | ||
(o) => o.id === messageData.event.order.id, | ||
) | ||
const updatedOrders = [...prevOrders] | ||
if (existingIndex !== -1) { | ||
updatedOrders[existingIndex] = messageData.event.order | ||
} else { | ||
updatedOrders.push(messageData.event.order) | ||
} | ||
return updatedOrders | ||
}) | ||
setOrder(messageData.event.order) | ||
} | ||
@@ -86,3 +75,3 @@ } catch (error) { | ||
return orders | ||
return order | ||
} |
@@ -7,4 +7,4 @@ 'use client' | ||
import { useConfig } from './useConfig.js' | ||
import { useWallet } from './useWalletWebSocket.js' | ||
import { useStatus } from './useStatus.js' | ||
import { useWalletWebsocket } from './useWalletWebSocket.js' | ||
@@ -25,3 +25,3 @@ export type UseOrdersParameters = { | ||
const [orders, setOrders] = useState<Order[]>([]) | ||
const wallet = useWallet() | ||
const incomingWallet = useWalletWebsocket() | ||
@@ -46,6 +46,6 @@ useEffect(() => { | ||
useEffect(() => { | ||
if (wallet?.orders) { | ||
setOrders(wallet.orders) | ||
if (incomingWallet?.orders) { | ||
setOrders(incomingWallet.orders) | ||
} | ||
}, [wallet]) | ||
}, [incomingWallet]) | ||
@@ -52,0 +52,0 @@ if (filter) { |
@@ -23,3 +23,3 @@ 'use client' | ||
export function useWallet( | ||
export function useWalletWebsocket( | ||
parameters: UseWalletParameters = {}, | ||
@@ -26,0 +26,0 @@ ): UseWalletReturnType { |
@@ -192,3 +192,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
export { | ||
useWallet, | ||
useWalletWebsocket, | ||
type UseWalletParameters, | ||
@@ -195,0 +195,0 @@ type UseWalletReturnType, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
668159
2492
+ Added@renegade-fi/core@0.0.10(transitive)
- Removed@renegade-fi/core@0.0.9(transitive)
Updated@renegade-fi/core@0.0.10