@orderly.network/hooks 1.2.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/configProvider.d.ts +7 -1
- package/esm/configProvider.d.ts.map +1 -1
- package/esm/configProvider.js +44 -18
- package/esm/configProvider.js.map +1 -0
- package/esm/dataProvider.js +24 -19
- package/esm/dataProvider.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -1
- package/esm/index.js.map +1 -0
- package/esm/middleware/signatureMiddleware.js +9 -8
- package/esm/middleware/signatureMiddleware.js.map +1 -0
- package/esm/orderly/orderbook.service.js +39 -28
- package/esm/orderly/orderbook.service.js.map +1 -0
- package/esm/orderly/orderlyHooks.d.ts +3 -0
- package/esm/orderly/orderlyHooks.d.ts.map +1 -1
- package/esm/orderly/orderlyHooks.js +2 -0
- package/esm/orderly/orderlyHooks.js.map +1 -0
- package/esm/orderly/useAccountInfo.js +3 -1
- package/esm/orderly/useAccountInfo.js.map +1 -0
- package/esm/orderly/useChain.js +16 -9
- package/esm/orderly/useChain.js.map +1 -0
- package/esm/orderly/useChains.d.ts +11 -12
- package/esm/orderly/useChains.d.ts.map +1 -1
- package/esm/orderly/useChains.js +68 -46
- package/esm/orderly/useChains.js.map +1 -0
- package/esm/orderly/useCollateral.d.ts +3 -4
- package/esm/orderly/useCollateral.d.ts.map +1 -1
- package/esm/orderly/useCollateral.js +53 -20
- package/esm/orderly/useCollateral.js.map +1 -0
- package/esm/orderly/useDeposit.js +123 -125
- package/esm/orderly/useDeposit.js.map +1 -0
- package/esm/orderly/useFundingRate.js +14 -13
- package/esm/orderly/useFundingRate.js.map +1 -0
- package/esm/orderly/useFundingRates.js +6 -4
- package/esm/orderly/useFundingRates.js.map +1 -0
- package/esm/orderly/useHoldingStream.js +19 -15
- package/esm/orderly/useHoldingStream.js.map +1 -0
- package/esm/orderly/useIndexPrice.js +7 -5
- package/esm/orderly/useIndexPrice.js.map +1 -0
- package/esm/orderly/useLeverage.js +9 -12
- package/esm/orderly/useLeverage.js.map +1 -0
- package/esm/orderly/useMarginRatio.js +27 -13
- package/esm/orderly/useMarginRatio.js.map +1 -0
- package/esm/orderly/useMarkPrice.js +13 -7
- package/esm/orderly/useMarkPrice.js.map +1 -0
- package/esm/orderly/useMarkPricesStream.d.ts +1 -1
- package/esm/orderly/useMarkPricesStream.d.ts.map +1 -1
- package/esm/orderly/useMarkPricesStream.js +9 -8
- package/esm/orderly/useMarkPricesStream.js.map +1 -0
- package/esm/orderly/useMarketTradeStream.js +33 -18
- package/esm/orderly/useMarketTradeStream.js.map +1 -0
- package/esm/orderly/useMarkets.js +144 -81
- package/esm/orderly/useMarkets.js.map +1 -0
- package/esm/orderly/useMarketsStream.js +23 -28
- package/esm/orderly/useMarketsStream.js.map +1 -0
- package/esm/orderly/useMaxQty.d.ts +6 -0
- package/esm/orderly/useMaxQty.d.ts.map +1 -1
- package/esm/orderly/useMaxQty.js +26 -18
- package/esm/orderly/useMaxQty.js.map +1 -0
- package/esm/orderly/useOpenInterest.js +7 -5
- package/esm/orderly/useOpenInterest.js.map +1 -0
- package/esm/orderly/useOrderEntry.js +182 -160
- package/esm/orderly/useOrderEntry.js.map +1 -0
- package/esm/orderly/useOrderStream.js +85 -66
- package/esm/orderly/useOrderStream.js.map +1 -0
- package/esm/orderly/useOrderbookStream.d.ts +2 -3
- package/esm/orderly/useOrderbookStream.d.ts.map +1 -1
- package/esm/orderly/useOrderbookStream.js +173 -103
- package/esm/orderly/useOrderbookStream.js.map +1 -0
- package/esm/orderly/usePositionStream.js +82 -62
- package/esm/orderly/usePositionStream.js.map +1 -0
- package/esm/orderly/usePrivateDataObserver.js +55 -48
- package/esm/orderly/usePrivateDataObserver.js.map +1 -0
- package/esm/orderly/useSettleSubscription.js +8 -6
- package/esm/orderly/useSettleSubscription.js.map +1 -0
- package/esm/orderly/useSymbolPriceRange.js +14 -8
- package/esm/orderly/useSymbolPriceRange.js.map +1 -0
- package/esm/orderly/useSymbolsInfo.js +7 -5
- package/esm/orderly/useSymbolsInfo.js.map +1 -0
- package/esm/orderly/useTickerStream.d.ts +5 -1
- package/esm/orderly/useTickerStream.d.ts.map +1 -1
- package/esm/orderly/useTickerStream.js +26 -29
- package/esm/orderly/useTickerStream.js.map +1 -0
- package/esm/orderly/useWalletSubscription.js +8 -6
- package/esm/orderly/useWalletSubscription.js.map +1 -0
- package/esm/orderly/useWithdraw.js +19 -11
- package/esm/orderly/useWithdraw.js.map +1 -0
- package/esm/orderlyContext.d.ts +8 -1
- package/esm/orderlyContext.d.ts.map +1 -1
- package/esm/orderlyContext.js +2 -1
- package/esm/orderlyContext.js.map +1 -0
- package/esm/services/dataCenter.js +10 -8
- package/esm/services/dataCenter.js.map +1 -0
- package/esm/services/painter/backgroundPaint.js +11 -14
- package/esm/services/painter/backgroundPaint.js.map +1 -0
- package/esm/services/painter/basePaint.js +5 -1
- package/esm/services/painter/basePaint.js.map +1 -0
- package/esm/services/painter/dataPaint.js +53 -50
- package/esm/services/painter/dataPaint.js.map +1 -0
- package/esm/services/painter/layout.config.js +15 -13
- package/esm/services/painter/layout.config.js.map +1 -0
- package/esm/services/painter/painter.js +14 -13
- package/esm/services/painter/painter.js.map +1 -0
- package/esm/services/painter/resource.js +6 -4
- package/esm/services/painter/resource.js.map +1 -0
- package/esm/statusProvider.js +10 -3
- package/esm/statusProvider.js.map +1 -0
- package/esm/unuse/apiPrefixMiddleware.js +18 -16
- package/esm/unuse/apiPrefixMiddleware.js.map +1 -0
- package/esm/unuse/fn.js +3 -1
- package/esm/unuse/fn.js.map +1 -0
- package/esm/unuse/useBalance.js +6 -4
- package/esm/unuse/useBalance.js.map +1 -0
- package/esm/unuse/useFetures.js +26 -18
- package/esm/unuse/useFetures.js.map +1 -0
- package/esm/unuse/useRunOnce.js +10 -7
- package/esm/unuse/useRunOnce.js.map +1 -0
- package/esm/unuse/useSyncEnd.js +5 -4
- package/esm/unuse/useSyncEnd.js.map +1 -0
- package/esm/unuse/useTokenInfo.js +7 -5
- package/esm/unuse/useTokenInfo.js.map +1 -0
- package/esm/unuse/useUnsettlementPnL.js +7 -3
- package/esm/unuse/useUnsettlementPnL.js.map +1 -0
- package/esm/useAccount.js +18 -21
- package/esm/useAccount.js.map +1 -0
- package/esm/useAccountInstance.js +6 -7
- package/esm/useAccountInstance.js.map +1 -0
- package/esm/useBoolean.js +14 -5
- package/esm/useBoolean.js.map +1 -0
- package/esm/useConfig.js +3 -1
- package/esm/useConfig.js.map +1 -0
- package/esm/useEventEmitter.js +4 -2
- package/esm/useEventEmitter.js.map +1 -0
- package/esm/useLazyQuery.js +6 -7
- package/esm/useLazyQuery.js.map +1 -0
- package/esm/useLocalStorage.js +30 -20
- package/esm/useLocalStorage.js.map +1 -0
- package/esm/useMediaQuery.js +11 -9
- package/esm/useMediaQuery.js.map +1 -0
- package/esm/useMutation.js +26 -37
- package/esm/useMutation.js.map +1 -0
- package/esm/useObserve.js +4 -4
- package/esm/useObserve.js.map +1 -0
- package/esm/useParamsCheck.js +8 -10
- package/esm/useParamsCheck.js.map +1 -0
- package/esm/usePoster.js +56 -45
- package/esm/usePoster.js.map +1 -0
- package/esm/usePreloadData.js +9 -5
- package/esm/usePreloadData.js.map +1 -0
- package/esm/usePrivateInfiniteQuery.js +15 -9
- package/esm/usePrivateInfiniteQuery.js.map +1 -0
- package/esm/usePrivateQuery.js +15 -8
- package/esm/usePrivateQuery.js.map +1 -0
- package/esm/useQuery.js +6 -5
- package/esm/useQuery.js.map +1 -0
- package/esm/useSessionStorage.js +28 -19
- package/esm/useSessionStorage.js.map +1 -0
- package/esm/useWS.js +15 -13
- package/esm/useWS.js.map +1 -0
- package/esm/useWsStatus.js +12 -12
- package/esm/useWsStatus.js.map +1 -0
- package/esm/utils/createGetter.js +8 -8
- package/esm/utils/createGetter.js.map +1 -0
- package/esm/utils/createOrder.d.ts +1 -0
- package/esm/utils/createOrder.d.ts.map +1 -1
- package/esm/utils/createOrder.js +59 -43
- package/esm/utils/createOrder.js.map +1 -0
- package/esm/utils/dev.js +6 -4
- package/esm/utils/dev.js.map +1 -0
- package/esm/utils/fetcher.js +3 -1
- package/esm/utils/fetcher.js.map +1 -0
- package/esm/utils/json.js +3 -2
- package/esm/utils/json.js.map +1 -0
- package/esm/utils/orderEntryHelper.js +92 -63
- package/esm/utils/orderEntryHelper.js.map +1 -0
- package/esm/utils/parseHolding.js +10 -6
- package/esm/utils/parseHolding.js.map +1 -0
- package/esm/utils/swr.js +114 -104
- package/esm/utils/swr.js.map +1 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +4 -3
- package/esm/version.js.map +1 -0
- package/esm/walletConnectorContext.js +4 -2
- package/esm/walletConnectorContext.js.map +1 -0
- package/lib/configProvider.d.ts +7 -1
- package/lib/configProvider.d.ts.map +1 -1
- package/lib/configProvider.js +108 -56
- package/lib/configProvider.js.map +1 -0
- package/lib/dataProvider.js +50 -29
- package/lib/dataProvider.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +191 -88
- package/lib/index.js.map +1 -0
- package/lib/middleware/signatureMiddleware.js +22 -15
- package/lib/middleware/signatureMiddleware.js.map +1 -0
- package/lib/orderly/orderbook.service.js +59 -33
- package/lib/orderly/orderbook.service.js.map +1 -0
- package/lib/orderly/orderlyHooks.d.ts +3 -0
- package/lib/orderly/orderlyHooks.d.ts.map +1 -1
- package/lib/orderly/orderlyHooks.js +124 -57
- package/lib/orderly/orderlyHooks.js.map +1 -0
- package/lib/orderly/useAccountInfo.js +14 -6
- package/lib/orderly/useAccountInfo.js.map +1 -0
- package/lib/orderly/useChain.js +30 -17
- package/lib/orderly/useChain.js.map +1 -0
- package/lib/orderly/useChains.d.ts +11 -12
- package/lib/orderly/useChains.d.ts.map +1 -1
- package/lib/orderly/useChains.js +100 -59
- package/lib/orderly/useChains.js.map +1 -0
- package/lib/orderly/useCollateral.d.ts +3 -4
- package/lib/orderly/useCollateral.d.ts.map +1 -1
- package/lib/orderly/useCollateral.js +81 -42
- package/lib/orderly/useCollateral.js.map +1 -0
- package/lib/orderly/useDeposit.js +154 -150
- package/lib/orderly/useDeposit.js.map +1 -0
- package/lib/orderly/useFundingRate.js +29 -22
- package/lib/orderly/useFundingRate.js.map +1 -0
- package/lib/orderly/useFundingRates.js +19 -11
- package/lib/orderly/useFundingRates.js.map +1 -0
- package/lib/orderly/useHoldingStream.js +39 -27
- package/lib/orderly/useHoldingStream.js.map +1 -0
- package/lib/orderly/useIndexPrice.js +24 -14
- package/lib/orderly/useIndexPrice.js.map +1 -0
- package/lib/orderly/useLeverage.js +27 -24
- package/lib/orderly/useLeverage.js.map +1 -0
- package/lib/orderly/useMarginRatio.js +49 -29
- package/lib/orderly/useMarginRatio.js.map +1 -0
- package/lib/orderly/useMarkPrice.js +26 -15
- package/lib/orderly/useMarkPrice.js.map +1 -0
- package/lib/orderly/useMarkPricesStream.d.ts +1 -1
- package/lib/orderly/useMarkPricesStream.d.ts.map +1 -1
- package/lib/orderly/useMarkPricesStream.js +26 -17
- package/lib/orderly/useMarkPricesStream.js.map +1 -0
- package/lib/orderly/useMarketTradeStream.js +47 -26
- package/lib/orderly/useMarketTradeStream.js.map +1 -0
- package/lib/orderly/useMarkets.js +172 -95
- package/lib/orderly/useMarkets.js.map +1 -0
- package/lib/orderly/useMarketsStream.js +44 -41
- package/lib/orderly/useMarketsStream.js.map +1 -0
- package/lib/orderly/useMaxQty.d.ts +6 -0
- package/lib/orderly/useMaxQty.d.ts.map +1 -1
- package/lib/orderly/useMaxQty.js +52 -43
- package/lib/orderly/useMaxQty.js.map +1 -0
- package/lib/orderly/useOpenInterest.js +24 -14
- package/lib/orderly/useOpenInterest.js.map +1 -0
- package/lib/orderly/useOrderEntry.js +238 -210
- package/lib/orderly/useOrderEntry.js.map +1 -0
- package/lib/orderly/useOrderStream.js +111 -84
- package/lib/orderly/useOrderStream.js.map +1 -0
- package/lib/orderly/useOrderbookStream.d.ts +2 -3
- package/lib/orderly/useOrderbookStream.d.ts.map +1 -1
- package/lib/orderly/useOrderbookStream.js +227 -148
- package/lib/orderly/useOrderbookStream.js.map +1 -0
- package/lib/orderly/usePositionStream.js +134 -100
- package/lib/orderly/usePositionStream.js.map +1 -0
- package/lib/orderly/usePrivateDataObserver.js +76 -63
- package/lib/orderly/usePrivateDataObserver.js.map +1 -0
- package/lib/orderly/useSettleSubscription.js +25 -15
- package/lib/orderly/useSettleSubscription.js.map +1 -0
- package/lib/orderly/useSymbolPriceRange.js +29 -23
- package/lib/orderly/useSymbolPriceRange.js.map +1 -0
- package/lib/orderly/useSymbolsInfo.js +23 -15
- package/lib/orderly/useSymbolsInfo.js.map +1 -0
- package/lib/orderly/useTickerStream.d.ts +5 -1
- package/lib/orderly/useTickerStream.d.ts.map +1 -1
- package/lib/orderly/useTickerStream.js +51 -48
- package/lib/orderly/useTickerStream.js.map +1 -0
- package/lib/orderly/useWalletSubscription.js +25 -15
- package/lib/orderly/useWalletSubscription.js.map +1 -0
- package/lib/orderly/useWithdraw.js +36 -22
- package/lib/orderly/useWithdraw.js.map +1 -0
- package/lib/orderlyContext.d.ts +8 -1
- package/lib/orderlyContext.d.ts.map +1 -1
- package/lib/orderlyContext.js +22 -6
- package/lib/orderlyContext.js.map +1 -0
- package/lib/services/dataCenter.js +15 -11
- package/lib/services/dataCenter.js.map +1 -0
- package/lib/services/painter/backgroundPaint.js +21 -18
- package/lib/services/painter/backgroundPaint.js.map +1 -0
- package/lib/services/painter/basePaint.js +14 -4
- package/lib/services/painter/basePaint.js.map +1 -0
- package/lib/services/painter/dataPaint.js +67 -58
- package/lib/services/painter/dataPaint.js.map +1 -0
- package/lib/services/painter/layout.config.js +25 -16
- package/lib/services/painter/layout.config.js.map +1 -0
- package/lib/services/painter/painter.js +27 -20
- package/lib/services/painter/painter.js.map +1 -0
- package/lib/services/painter/resource.js +15 -7
- package/lib/services/painter/resource.js.map +1 -0
- package/lib/statusProvider.js +31 -10
- package/lib/statusProvider.js.map +1 -0
- package/lib/unuse/apiPrefixMiddleware.js +30 -22
- package/lib/unuse/apiPrefixMiddleware.js.map +1 -0
- package/lib/unuse/fn.js +14 -5
- package/lib/unuse/fn.js.map +1 -0
- package/lib/unuse/useBalance.js +23 -13
- package/lib/unuse/useBalance.js.map +1 -0
- package/lib/unuse/useFetures.js +41 -28
- package/lib/unuse/useFetures.js.map +1 -0
- package/lib/unuse/useRunOnce.js +61 -11
- package/lib/unuse/useRunOnce.js.map +1 -0
- package/lib/unuse/useSyncEnd.js +17 -10
- package/lib/unuse/useSyncEnd.js.map +1 -0
- package/lib/unuse/useTokenInfo.js +20 -12
- package/lib/unuse/useTokenInfo.js.map +1 -0
- package/lib/unuse/useUnsettlementPnL.js +21 -11
- package/lib/unuse/useUnsettlementPnL.js.map +1 -0
- package/lib/useAccount.js +32 -29
- package/lib/useAccount.js.map +1 -0
- package/lib/useAccountInstance.js +27 -20
- package/lib/useAccountInstance.js.map +1 -0
- package/lib/useBoolean.js +25 -10
- package/lib/useBoolean.js.map +1 -0
- package/lib/useConfig.js +15 -7
- package/lib/useConfig.js.map +1 -0
- package/lib/useEventEmitter.js +23 -13
- package/lib/useEventEmitter.js.map +1 -0
- package/lib/useLazyQuery.js +25 -23
- package/lib/useLazyQuery.js.map +1 -0
- package/lib/useLocalStorage.js +44 -28
- package/lib/useLocalStorage.js.map +1 -0
- package/lib/useMediaQuery.js +22 -14
- package/lib/useMediaQuery.js.map +1 -0
- package/lib/useMutation.js +47 -52
- package/lib/useMutation.js.map +1 -0
- package/lib/useObserve.js +22 -8
- package/lib/useObserve.js.map +1 -0
- package/lib/useParamsCheck.js +18 -14
- package/lib/useParamsCheck.js.map +1 -0
- package/lib/usePoster.js +80 -74
- package/lib/usePoster.js.map +1 -0
- package/lib/usePreloadData.js +21 -11
- package/lib/usePreloadData.js.map +1 -0
- package/lib/usePrivateInfiniteQuery.js +36 -22
- package/lib/usePrivateInfiniteQuery.js.map +1 -0
- package/lib/usePrivateQuery.js +35 -25
- package/lib/usePrivateQuery.js.map +1 -0
- package/lib/useQuery.js +24 -20
- package/lib/useQuery.js.map +1 -0
- package/lib/useSessionStorage.js +41 -26
- package/lib/useSessionStorage.js.map +1 -0
- package/lib/useWS.js +42 -32
- package/lib/useWS.js.map +1 -0
- package/lib/useWsStatus.js +34 -20
- package/lib/useWsStatus.js.map +1 -0
- package/lib/utils/createGetter.js +19 -14
- package/lib/utils/createGetter.js.map +1 -0
- package/lib/utils/createOrder.d.ts +1 -0
- package/lib/utils/createOrder.d.ts.map +1 -1
- package/lib/utils/createOrder.js +133 -82
- package/lib/utils/createOrder.js.map +1 -0
- package/lib/utils/dev.js +13 -9
- package/lib/utils/dev.js.map +1 -0
- package/lib/utils/fetcher.js +13 -5
- package/lib/utils/fetcher.js.map +1 -0
- package/lib/utils/json.js +12 -5
- package/lib/utils/json.js.map +1 -0
- package/lib/utils/orderEntryHelper.js +125 -82
- package/lib/utils/orderEntryHelper.js.map +1 -0
- package/lib/utils/parseHolding.js +19 -9
- package/lib/utils/parseHolding.js.map +1 -0
- package/lib/utils/swr.js +134 -111
- package/lib/utils/swr.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +13 -4
- package/lib/version.js.map +1 -0
- package/lib/walletConnectorContext.js +23 -7
- package/lib/walletConnectorContext.js.map +1 -0
- package/package.json +17 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/unuse/useFetures.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { useQuery } from \"../useQuery\";\n\nimport { useWS } from \"../useWS\";\n\ninterface MarketInfo {}\n\n// api: /public/futures\nexport const useFetures = () => {\n const { data, isLoading, error } = useQuery<MarketInfo[]>(\n `/v1/public/futures`,\n {\n revalidateOnFocus: false,\n }\n );\n\n const [sortedData, setSortedData] = useState(data);\n\n const ws = useWS();\n\n useEffect(() => {\n // const sub = ws\n // .observe<WSMessage.Ticker>(`tickers`)\n // .subscribe((value: any) => {\n //\n // // setData(value);\n // });\n // return () => {\n // sub.unsubscribe();\n // };\n }, []);\n\n useEffect(() => {\n if (data) {\n const sortedData = data.sort((a, b) => {\n return 0;\n });\n setSortedData(sortedData);\n }\n }, [data]);\n\n const sortBy = useCallback((key: string) => {}, [data]);\n\n const filterBy = useCallback((key: string) => {}, [data]);\n\n return {\n data: sortedData,\n sortBy,\n filterBy,\n isLoading,\n error,\n };\n};\n"],"names":["useCallback","useEffect","useState","useQuery","useWS","useFetures","data","isLoading","error","revalidateOnFocus","sortedData","setSortedData","ws","sort","a","b","sortBy","key","filterBy"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AACzD,SAASC,QAAQ,QAAQ,cAAc;AAEvC,SAASC,KAAK,QAAQ,WAAW;AAIjC,uBAAuB;AACvB,OAAO,MAAMC,aAAa;IACxB,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGL,SACjC,CAAC,kBAAkB,CAAC,EACpB;QACEM,mBAAmB;IACrB;IAGF,MAAM,CAACC,YAAYC,cAAc,GAAGT,SAASI;IAE7C,MAAMM,KAAKR;IAEXH,UAAU;IACR,iBAAiB;IACjB,0CAA0C;IAC1C,iCAAiC;IACjC,EAAE;IACF,yBAAyB;IACzB,QAAQ;IACR,iBAAiB;IACjB,uBAAuB;IACvB,KAAK;IACP,GAAG,EAAE;IAELA,UAAU;QACR,IAAIK,MAAM;YACR,MAAMI,aAAaJ,KAAKO,IAAI,CAAC,CAACC,GAAGC;gBAC/B,OAAO;YACT;YACAJ,cAAcD;QAChB;IACF,GAAG;QAACJ;KAAK;IAET,MAAMU,SAAShB,YAAY,CAACiB,OAAiB,GAAG;QAACX;KAAK;IAEtD,MAAMY,WAAWlB,YAAY,CAACiB,OAAiB,GAAG;QAACX;KAAK;IAExD,OAAO;QACLA,MAAMI;QACNM;QACAE;QACAX;QACAC;IACF;AACF,EAAE"}
|
package/esm/unuse/useRunOnce.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
export const useRunOnce = ({ fn, sessionKey })
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
export const useRunOnce = ({ fn, sessionKey })=>{
|
|
3
3
|
const triggered = useRef(false);
|
|
4
|
-
useEffect(()
|
|
5
|
-
const hasBeenTriggered = sessionKey
|
|
6
|
-
? sessionStorage.getItem(sessionKey)
|
|
7
|
-
: triggered.current;
|
|
4
|
+
useEffect(()=>{
|
|
5
|
+
const hasBeenTriggered = sessionKey ? sessionStorage.getItem(sessionKey) : triggered.current;
|
|
8
6
|
if (!hasBeenTriggered) {
|
|
9
7
|
fn();
|
|
10
8
|
triggered.current = true;
|
|
@@ -12,6 +10,11 @@ export const useRunOnce = ({ fn, sessionKey }) => {
|
|
|
12
10
|
sessionStorage.setItem(sessionKey, "true");
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
|
-
}, [
|
|
13
|
+
}, [
|
|
14
|
+
fn,
|
|
15
|
+
sessionKey
|
|
16
|
+
]);
|
|
16
17
|
return null;
|
|
17
18
|
};
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=useRunOnce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/unuse/useRunOnce.ts"],"sourcesContent":["import React, { useEffect, useRef } from \"react\";\n\nexport type useRunOnceProps = {\n fn: () => any;\n sessionKey?: string;\n};\n\nexport const useRunOnce: React.FC<useRunOnceProps> = ({ fn, sessionKey }) => {\n const triggered = useRef<boolean>(false);\n\n useEffect(() => {\n const hasBeenTriggered = sessionKey\n ? sessionStorage.getItem(sessionKey)\n : triggered.current;\n\n if (!hasBeenTriggered) {\n fn();\n triggered.current = true;\n\n if (sessionKey) {\n sessionStorage.setItem(sessionKey, \"true\");\n }\n }\n }, [fn, sessionKey]);\n\n return null;\n};\n"],"names":["React","useEffect","useRef","useRunOnce","fn","sessionKey","triggered","hasBeenTriggered","sessionStorage","getItem","current","setItem"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,SAASC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAOjD,OAAO,MAAMC,aAAwC,CAAC,EAAEC,EAAE,EAAEC,UAAU,EAAE;IACtE,MAAMC,YAAYJ,OAAgB;IAElCD,UAAU;QACR,MAAMM,mBAAmBF,aACrBG,eAAeC,OAAO,CAACJ,cACvBC,UAAUI,OAAO;QAErB,IAAI,CAACH,kBAAkB;YACrBH;YACAE,UAAUI,OAAO,GAAG;YAEpB,IAAIL,YAAY;gBACdG,eAAeG,OAAO,CAACN,YAAY;YACrC;QACF;IACF,GAAG;QAACD;QAAIC;KAAW;IAEnB,OAAO;AACT,EAAE"}
|
package/esm/unuse/useSyncEnd.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
import { useConfig } from "../useConfig";
|
|
3
|
-
export const useSyncEnd = ()
|
|
3
|
+
export const useSyncEnd = ()=>{
|
|
4
4
|
const config = useConfig();
|
|
5
|
-
useEffect(()
|
|
5
|
+
useEffect(()=>{
|
|
6
6
|
fetch(`${config.get("apiBaseUrl")}/v1/public/system_info`, {
|
|
7
|
-
|
|
8
|
-
}).then((res) => { });
|
|
7
|
+
}).then((res)=>{});
|
|
9
8
|
}, []);
|
|
10
9
|
};
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=useSyncEnd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/unuse/useSyncEnd.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useConfig } from \"../useConfig\";\nimport { ConfigStore } from \"@orderly.network/core\";\n\nexport const useSyncEnd = () => {\n const config = useConfig<ConfigStore>();\n useEffect(() => {\n fetch(`${config.get(\"apiBaseUrl\")}/v1/public/system_info`, {\n // method: \"HEAD\",\n }).then((res) => {});\n }, []);\n};\n"],"names":["useEffect","useConfig","useSyncEnd","config","fetch","get","then","res"],"rangeMappings":";;;;;;;;","mappings":"AAAA,SAASA,SAAS,QAAQ,QAAQ;AAClC,SAASC,SAAS,QAAQ,eAAe;AAGzC,OAAO,MAAMC,aAAa;IACxB,MAAMC,SAASF;IACfD,UAAU;QACRI,MAAM,CAAC,EAAED,OAAOE,GAAG,CAAC,cAAc,sBAAsB,CAAC,EAAE;QAE3D,GAAGC,IAAI,CAAC,CAACC,OAAS;IACpB,GAAG,EAAE;AACP,EAAE"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { useQuery } from "../useQuery";
|
|
2
2
|
import { createGetter } from "../utils/createGetter";
|
|
3
|
-
export const useTokenInfo = ()
|
|
3
|
+
export const useTokenInfo = ()=>{
|
|
4
4
|
const { data = {} } = useQuery("/v1/public/token", {
|
|
5
5
|
focusThrottleInterval: 1000 * 60 * 60 * 24,
|
|
6
6
|
revalidateOnFocus: false,
|
|
7
|
-
formatter(data) {
|
|
7
|
+
formatter (data) {
|
|
8
8
|
if (!data?.rows || !data?.rows?.length) {
|
|
9
9
|
return {};
|
|
10
10
|
}
|
|
11
11
|
const obj = Object.create(null);
|
|
12
|
-
for
|
|
12
|
+
for(let index = 0; index < data.rows.length; index++){
|
|
13
13
|
const item = data.rows[index];
|
|
14
|
-
|
|
14
|
+
// obj[item.token] = item;
|
|
15
15
|
}
|
|
16
16
|
return obj;
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
});
|
|
19
19
|
return createGetter(data);
|
|
20
20
|
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=useTokenInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/unuse/useTokenInfo.ts"],"sourcesContent":["import { useQuery } from \"../useQuery\";\nimport { type API } from \"@orderly.network/types\";\nimport { createGetter } from \"../utils/createGetter\";\n\nexport const useTokenInfo = () => {\n const { data = {} } = useQuery<Record<string, API.TokenInfo>>(\n \"/v1/public/token\",\n {\n focusThrottleInterval: 1000 * 60 * 60 * 24,\n revalidateOnFocus: false,\n formatter(data: { rows: API.TokenInfo[] }) {\n if (!data?.rows || !data?.rows?.length) {\n return {};\n }\n const obj = Object.create(null);\n\n for (let index = 0; index < data.rows.length; index++) {\n const item = data.rows[index];\n\n // obj[item.token] = item;\n }\n\n return obj;\n },\n }\n );\n\n return createGetter<API.TokenInfo>(data as any);\n};\n"],"names":["useQuery","createGetter","useTokenInfo","data","focusThrottleInterval","revalidateOnFocus","formatter","rows","length","obj","Object","create","index","item"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,SAASC,YAAY,QAAQ,wBAAwB;AAErD,OAAO,MAAMC,eAAe;IAC1B,MAAM,EAAEC,OAAO,CAAC,CAAC,EAAE,GAAGH,SACpB,oBACA;QACEI,uBAAuB,OAAO,KAAK,KAAK;QACxCC,mBAAmB;QACnBC,WAAUH,IAA+B;YACvC,IAAI,CAACA,MAAMI,QAAQ,CAACJ,MAAMI,MAAMC,QAAQ;gBACtC,OAAO,CAAC;YACV;YACA,MAAMC,MAAMC,OAAOC,MAAM,CAAC;YAE1B,IAAK,IAAIC,QAAQ,GAAGA,QAAQT,KAAKI,IAAI,CAACC,MAAM,EAAEI,QAAS;gBACrD,MAAMC,OAAOV,KAAKI,IAAI,CAACK,MAAM;YAE7B,0BAA0B;YAC5B;YAEA,OAAOH;QACT;IACF;IAGF,OAAOR,aAA4BE;AACrC,EAAE"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { usePrivateQuery } from "../usePrivateQuery";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useFundingRates } from "../orderly/useFundingRates";
|
|
4
|
-
export const useUnsettlementPnL = ()
|
|
4
|
+
export const useUnsettlementPnL = ()=>{
|
|
5
5
|
const { data } = usePrivateQuery(`/v1/positions`);
|
|
6
6
|
const fundingRates = useFundingRates();
|
|
7
|
-
const unSettlementPnL = useMemo(()
|
|
7
|
+
const unSettlementPnL = useMemo(()=>{
|
|
8
8
|
// return positions.totalUnsettlementPnL(
|
|
9
9
|
// data?.rows.map((item) => ({
|
|
10
10
|
// ...item,
|
|
@@ -15,6 +15,10 @@ export const useUnsettlementPnL = () => {
|
|
|
15
15
|
// }))
|
|
16
16
|
// );
|
|
17
17
|
return 0;
|
|
18
|
-
}, [
|
|
18
|
+
}, [
|
|
19
|
+
data
|
|
20
|
+
]);
|
|
19
21
|
return unSettlementPnL;
|
|
20
22
|
};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=useUnsettlementPnL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/unuse/useUnsettlementPnL.ts"],"sourcesContent":["import { API } from \"@orderly.network/types\";\nimport { usePrivateQuery } from \"../usePrivateQuery\";\nimport { useMemo } from \"react\";\nimport { positions } from \"@orderly.network/perp\";\nimport { useFundingRates } from \"../orderly/useFundingRates\";\n\nexport const useUnsettlementPnL = () => {\n const { data } = usePrivateQuery<API.PositionInfo>(`/v1/positions`);\n const fundingRates = useFundingRates();\n\n const unSettlementPnL = useMemo(() => {\n // return positions.totalUnsettlementPnL(\n // data?.rows.map((item) => ({\n // ...item,\n // sum_unitary_funding: fundingRates[item.symbol]?.(\n // \"sum_unitary_funding\",\n // 0\n // ),\n // }))\n // );\n return 0;\n }, [data]);\n\n return unSettlementPnL;\n};\n"],"names":["usePrivateQuery","useMemo","useFundingRates","useUnsettlementPnL","data","fundingRates","unSettlementPnL"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,eAAe,QAAQ,qBAAqB;AACrD,SAASC,OAAO,QAAQ,QAAQ;AAEhC,SAASC,eAAe,QAAQ,6BAA6B;AAE7D,OAAO,MAAMC,qBAAqB;IAChC,MAAM,EAAEC,IAAI,EAAE,GAAGJ,gBAAkC,CAAC,aAAa,CAAC;IAClE,MAAMK,eAAeH;IAErB,MAAMI,kBAAkBL,QAAQ;QAC9B,yCAAyC;QACzC,kCAAkC;QAClC,iBAAiB;QACjB,0DAA0D;QAC1D,iCAAiC;QACjC,YAAY;QACZ,WAAW;QACX,UAAU;QACV,OAAO;QACP,OAAO;IACT,GAAG;QAACG;KAAK;IAET,OAAOE;AACT,EAAE"}
|
package/esm/useAccount.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { useCallback, useContext, useEffect, useState } from "react";
|
|
2
2
|
import { OrderlyContext } from "./orderlyContext";
|
|
3
3
|
import { useAccountInstance } from "./useAccountInstance";
|
|
4
|
-
export const useAccount = ()
|
|
5
|
-
const { configStore, keyStore
|
|
6
|
-
|
|
7
|
-
// onWalletDisconnect,
|
|
8
|
-
// onSetChain,
|
|
9
|
-
} = useContext(OrderlyContext);
|
|
10
|
-
if (!configStore)
|
|
11
|
-
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
4
|
+
export const useAccount = ()=>{
|
|
5
|
+
const { configStore, keyStore } = useContext(OrderlyContext);
|
|
6
|
+
if (!configStore) throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
12
7
|
if (!keyStore) {
|
|
13
8
|
throw new Error("keyStore is not defined, please use OrderlyProvider and provide keyStore");
|
|
14
9
|
}
|
|
@@ -21,13 +16,13 @@ export const useAccount = () => {
|
|
|
21
16
|
// () => account.state$,
|
|
22
17
|
// account.stateValue
|
|
23
18
|
// );
|
|
24
|
-
const statusChangeHandler = (nextState)
|
|
19
|
+
const statusChangeHandler = (nextState)=>{
|
|
25
20
|
//
|
|
26
|
-
setState(()
|
|
21
|
+
setState(()=>nextState);
|
|
27
22
|
};
|
|
28
|
-
useEffect(()
|
|
23
|
+
useEffect(()=>{
|
|
29
24
|
account.on("change:status", statusChangeHandler);
|
|
30
|
-
return ()
|
|
25
|
+
return ()=>{
|
|
31
26
|
account.off("change:status", statusChangeHandler);
|
|
32
27
|
};
|
|
33
28
|
}, []);
|
|
@@ -37,12 +32,16 @@ export const useAccount = () => {
|
|
|
37
32
|
// },
|
|
38
33
|
// [account]
|
|
39
34
|
// );
|
|
40
|
-
const createOrderlyKey = useCallback(async (remember)
|
|
35
|
+
const createOrderlyKey = useCallback(async (remember)=>{
|
|
41
36
|
return account.createOrderlyKey(remember ? 365 : 30);
|
|
42
|
-
}, [
|
|
43
|
-
|
|
37
|
+
}, [
|
|
38
|
+
account
|
|
39
|
+
]);
|
|
40
|
+
const createAccount = useCallback(async ()=>{
|
|
44
41
|
return account.createAccount();
|
|
45
|
-
}, [
|
|
42
|
+
}, [
|
|
43
|
+
account
|
|
44
|
+
]);
|
|
46
45
|
// console.log("--------", state);
|
|
47
46
|
return {
|
|
48
47
|
account,
|
|
@@ -50,10 +49,8 @@ export const useAccount = () => {
|
|
|
50
49
|
// info: {},
|
|
51
50
|
// login,
|
|
52
51
|
createOrderlyKey,
|
|
53
|
-
createAccount
|
|
54
|
-
// disconnect,
|
|
55
|
-
// connect,
|
|
56
|
-
// setChain,
|
|
57
|
-
// settlement,
|
|
52
|
+
createAccount
|
|
58
53
|
};
|
|
59
54
|
};
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=useAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useAccount.ts"],"sourcesContent":["import { useCallback, useContext, useEffect, useState } from \"react\";\nimport { AccountState } from \"@orderly.network/core\";\nimport { OrderlyContext } from \"./orderlyContext\";\nimport { useAccountInstance } from \"./useAccountInstance\";\n\nexport const useAccount = () => {\n const {\n configStore,\n keyStore,\n // onWalletConnect,\n // onWalletDisconnect,\n // onSetChain,\n } = useContext(OrderlyContext);\n\n if (!configStore)\n throw new Error(\"configStore is not defined, please use OrderlyProvider\");\n\n if (!keyStore) {\n throw new Error(\n \"keyStore is not defined, please use OrderlyProvider and provide keyStore\"\n );\n }\n\n const account = useAccountInstance();\n\n const [state, setState] = useState<AccountState>(account.stateValue);\n\n // const { data: userInfo } =\n // usePrivateQuery<API.AccountInfo>(\"/v1/client/info\");\n\n // console.log(\"userInfo\", userInfo);\n\n // const state = useObservable<AccountState>(\n // () => account.state$,\n // account.stateValue\n // );\n\n const statusChangeHandler = (nextState: AccountState) => {\n //\n setState(() => nextState);\n };\n\n useEffect(() => {\n account.on(\"change:status\", statusChangeHandler);\n\n return () => {\n account.off(\"change:status\", statusChangeHandler);\n };\n }, []);\n\n // const login = useCallback(\n // (address: string) => {\n // account.login(address);\n // },\n // [account]\n // );\n\n const createOrderlyKey = useCallback(\n async (remember: boolean) => {\n return account.createOrderlyKey(remember ? 365 : 30);\n },\n [account]\n );\n\n const createAccount = useCallback(async () => {\n return account.createAccount();\n }, [account]);\n\n // console.log(\"--------\", state);\n\n return {\n account,\n state,\n // info: {},\n // login,\n createOrderlyKey,\n createAccount,\n // disconnect,\n // connect,\n // setChain,\n // settlement,\n };\n};\n"],"names":["useCallback","useContext","useEffect","useState","OrderlyContext","useAccountInstance","useAccount","configStore","keyStore","Error","account","state","setState","stateValue","statusChangeHandler","nextState","on","off","createOrderlyKey","remember","createAccount"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAErE,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,kBAAkB,QAAQ,uBAAuB;AAE1D,OAAO,MAAMC,aAAa;IACxB,MAAM,EACJC,WAAW,EACXC,QAAQ,EAIT,GAAGP,WAAWG;IAEf,IAAI,CAACG,aACH,MAAM,IAAIE,MAAM;IAElB,IAAI,CAACD,UAAU;QACb,MAAM,IAAIC,MACR;IAEJ;IAEA,MAAMC,UAAUL;IAEhB,MAAM,CAACM,OAAOC,SAAS,GAAGT,SAAuBO,QAAQG,UAAU;IAEnE,6BAA6B;IAC7B,yDAAyD;IAEzD,qCAAqC;IAErC,6CAA6C;IAC7C,0BAA0B;IAC1B,uBAAuB;IACvB,KAAK;IAEL,MAAMC,sBAAsB,CAACC;QAC3B,EAAE;QACFH,SAAS,IAAMG;IACjB;IAEAb,UAAU;QACRQ,QAAQM,EAAE,CAAC,iBAAiBF;QAE5B,OAAO;YACLJ,QAAQO,GAAG,CAAC,iBAAiBH;QAC/B;IACF,GAAG,EAAE;IAEL,6BAA6B;IAC7B,2BAA2B;IAC3B,8BAA8B;IAC9B,OAAO;IACP,cAAc;IACd,KAAK;IAEL,MAAMI,mBAAmBlB,YACvB,OAAOmB;QACL,OAAOT,QAAQQ,gBAAgB,CAACC,WAAW,MAAM;IACnD,GACA;QAACT;KAAQ;IAGX,MAAMU,gBAAgBpB,YAAY;QAChC,OAAOU,QAAQU,aAAa;IAC9B,GAAG;QAACV;KAAQ;IAEZ,kCAAkC;IAElC,OAAO;QACLA;QACAC;QACA,YAAY;QACZ,SAAS;QACTO;QACAE;IAKF;AACF,EAAE"}
|
|
@@ -2,22 +2,21 @@ import useConstant from "use-constant";
|
|
|
2
2
|
import { Account, SimpleDI } from "@orderly.network/core";
|
|
3
3
|
import { useContext } from "react";
|
|
4
4
|
import { OrderlyContext } from "./orderlyContext";
|
|
5
|
-
export const useAccountInstance = ()
|
|
5
|
+
export const useAccountInstance = ()=>{
|
|
6
6
|
const { configStore, keyStore, getWalletAdapter } = useContext(OrderlyContext);
|
|
7
|
-
if (!configStore)
|
|
8
|
-
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
7
|
+
if (!configStore) throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
9
8
|
if (!keyStore) {
|
|
10
9
|
throw new Error("keyStore is not defined, please use OrderlyProvider and provide keyStore");
|
|
11
10
|
}
|
|
12
|
-
const account = useConstant(()
|
|
11
|
+
const account = useConstant(()=>{
|
|
13
12
|
let account = SimpleDI.get("account");
|
|
14
13
|
if (!account) {
|
|
15
|
-
account = new Account(configStore, keyStore, getWalletAdapter
|
|
16
|
-
// walletAdapter
|
|
17
|
-
);
|
|
14
|
+
account = new Account(configStore, keyStore, getWalletAdapter);
|
|
18
15
|
SimpleDI.registerByName("account", account);
|
|
19
16
|
}
|
|
20
17
|
return account;
|
|
21
18
|
});
|
|
22
19
|
return account;
|
|
23
20
|
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=useAccountInstance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useAccountInstance.ts"],"sourcesContent":["import useConstant from \"use-constant\";\nimport { Account, SimpleDI } from \"@orderly.network/core\";\nimport { useContext } from \"react\";\nimport { OrderlyContext } from \"./orderlyContext\";\n\nexport const useAccountInstance = (): Account => {\n const { configStore, keyStore, getWalletAdapter } =\n useContext(OrderlyContext);\n\n if (!configStore)\n throw new Error(\"configStore is not defined, please use OrderlyProvider\");\n\n if (!keyStore) {\n throw new Error(\n \"keyStore is not defined, please use OrderlyProvider and provide keyStore\"\n );\n }\n\n const account = useConstant(() => {\n let account = SimpleDI.get<Account>(\"account\");\n\n if (!account) {\n account = new Account(\n configStore,\n keyStore,\n\n getWalletAdapter\n // walletAdapter\n );\n\n SimpleDI.registerByName(\"account\", account);\n }\n return account;\n });\n\n return account;\n};\n"],"names":["useConstant","Account","SimpleDI","useContext","OrderlyContext","useAccountInstance","configStore","keyStore","getWalletAdapter","Error","account","get","registerByName"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,iBAAiB,eAAe;AACvC,SAASC,OAAO,EAAEC,QAAQ,QAAQ,wBAAwB;AAC1D,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,cAAc,QAAQ,mBAAmB;AAElD,OAAO,MAAMC,qBAAqB;IAChC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,gBAAgB,EAAE,GAC/CL,WAAWC;IAEb,IAAI,CAACE,aACH,MAAM,IAAIG,MAAM;IAElB,IAAI,CAACF,UAAU;QACb,MAAM,IAAIE,MACR;IAEJ;IAEA,MAAMC,UAAUV,YAAY;QAC1B,IAAIU,UAAUR,SAASS,GAAG,CAAU;QAEpC,IAAI,CAACD,SAAS;YACZA,UAAU,IAAIT,QACZK,aACAC,UAEAC;YAIFN,SAASU,cAAc,CAAC,WAAWF;QACrC;QACA,OAAOA;IACT;IAEA,OAAOA;AACT,EAAE"}
|
package/esm/useBoolean.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { useCallback, useState } from "react";
|
|
2
|
-
export const useBoolean = (initialValue = false)
|
|
2
|
+
export const useBoolean = (initialValue = false)=>{
|
|
3
3
|
const [value, setValue] = useState(initialValue);
|
|
4
|
-
const setTrue = useCallback(()
|
|
5
|
-
const setFalse = useCallback(()
|
|
6
|
-
const toggle = useCallback(()
|
|
7
|
-
return [
|
|
4
|
+
const setTrue = useCallback(()=>setValue(true), []);
|
|
5
|
+
const setFalse = useCallback(()=>setValue(false), []);
|
|
6
|
+
const toggle = useCallback(()=>setValue((v)=>!v), []);
|
|
7
|
+
return [
|
|
8
|
+
value,
|
|
9
|
+
{
|
|
10
|
+
setTrue,
|
|
11
|
+
setFalse,
|
|
12
|
+
toggle
|
|
13
|
+
}
|
|
14
|
+
];
|
|
8
15
|
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=useBoolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useBoolean.ts"],"sourcesContent":["import { useCallback, useState } from \"react\";\n\nexport const useBoolean = (\n initialValue = false\n): [\n boolean,\n {\n setTrue: () => void;\n setFalse: () => void;\n toggle: () => void;\n }\n] => {\n const [value, setValue] = useState(initialValue);\n const setTrue = useCallback(() => setValue(true), []);\n const setFalse = useCallback(() => setValue(false), []);\n const toggle = useCallback(() => setValue((v) => !v), []);\n return [value, { setTrue, setFalse, toggle }];\n};\n"],"names":["useCallback","useState","useBoolean","initialValue","value","setValue","setTrue","setFalse","toggle","v"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAE9C,OAAO,MAAMC,aAAa,CACxBC,eAAe,KAAK;IASpB,MAAM,CAACC,OAAOC,SAAS,GAAGJ,SAASE;IACnC,MAAMG,UAAUN,YAAY,IAAMK,SAAS,OAAO,EAAE;IACpD,MAAME,WAAWP,YAAY,IAAMK,SAAS,QAAQ,EAAE;IACtD,MAAMG,SAASR,YAAY,IAAMK,SAAS,CAACI,IAAM,CAACA,IAAI,EAAE;IACxD,OAAO;QAACL;QAAO;YAAEE;YAASC;YAAUC;QAAO;KAAE;AAC/C,EAAE"}
|
package/esm/useConfig.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { OrderlyContext } from "./orderlyContext";
|
|
3
|
-
export const useConfig = (key, defaultValue)
|
|
3
|
+
export const useConfig = (key, defaultValue)=>{
|
|
4
4
|
const { configStore } = useContext(OrderlyContext);
|
|
5
5
|
if (typeof key !== "undefined") {
|
|
6
6
|
if (typeof defaultValue !== "undefined") {
|
|
@@ -10,3 +10,5 @@ export const useConfig = (key, defaultValue) => {
|
|
|
10
10
|
}
|
|
11
11
|
return configStore;
|
|
12
12
|
};
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useConfig.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { OrderlyContext } from \"./orderlyContext\";\nimport { ConfigStore, type ConfigKey } from \"@orderly.network/core\";\n\nexport const useConfig = <T>(\n key?: ConfigKey,\n defaultValue?: T\n): T | ConfigStore => {\n const { configStore } = useContext(OrderlyContext);\n\n if (typeof key !== \"undefined\") {\n if (typeof defaultValue !== \"undefined\") {\n return configStore.getOr(key, defaultValue);\n }\n return configStore.get(key);\n }\n\n return configStore;\n};\n"],"names":["useContext","OrderlyContext","useConfig","key","defaultValue","configStore","getOr","get"],"rangeMappings":";;;;;;;;;;;","mappings":"AAAA,SAASA,UAAU,QAAQ,QAAQ;AACnC,SAASC,cAAc,QAAQ,mBAAmB;AAGlD,OAAO,MAAMC,YAAY,CACvBC,KACAC;IAEA,MAAM,EAAEC,WAAW,EAAE,GAAGL,WAAWC;IAEnC,IAAI,OAAOE,QAAQ,aAAa;QAC9B,IAAI,OAAOC,iBAAiB,aAAa;YACvC,OAAOC,YAAYC,KAAK,CAACH,KAAKC;QAChC;QACA,OAAOC,YAAYE,GAAG,CAACJ;IACzB;IAEA,OAAOE;AACT,EAAE"}
|
package/esm/useEventEmitter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import useConstant from "use-constant";
|
|
2
2
|
import { EventEmitter, SimpleDI } from "@orderly.network/core";
|
|
3
|
-
export const useEventEmitter = ()
|
|
4
|
-
return useConstant(()
|
|
3
|
+
export const useEventEmitter = ()=>{
|
|
4
|
+
return useConstant(()=>{
|
|
5
5
|
let ee = SimpleDI.get("EE");
|
|
6
6
|
if (!ee) {
|
|
7
7
|
ee = new EventEmitter();
|
|
@@ -10,3 +10,5 @@ export const useEventEmitter = () => {
|
|
|
10
10
|
return ee;
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useEventEmitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useEventEmitter.ts"],"sourcesContent":["import useConstant from \"use-constant\";\nimport { EventEmitter, SimpleDI } from \"@orderly.network/core\";\n\nexport const useEventEmitter = () => {\n return useConstant(() => {\n let ee = SimpleDI.get<EventEmitter>(\"EE\");\n\n if (!ee) {\n ee = new EventEmitter();\n\n SimpleDI.registerByName(\"EE\", ee);\n }\n return ee;\n });\n};\n"],"names":["useConstant","EventEmitter","SimpleDI","useEventEmitter","ee","get","registerByName"],"rangeMappings":";;;;;;;;;;;","mappings":"AAAA,OAAOA,iBAAiB,eAAe;AACvC,SAASC,YAAY,EAAEC,QAAQ,QAAQ,wBAAwB;AAE/D,OAAO,MAAMC,kBAAkB;IAC7B,OAAOH,YAAY;QACjB,IAAII,KAAKF,SAASG,GAAG,CAAe;QAEpC,IAAI,CAACD,IAAI;YACPA,KAAK,IAAIH;YAETC,SAASI,cAAc,CAAC,MAAMF;QAChC;QACA,OAAOA;IACT;AACF,EAAE"}
|
package/esm/useLazyQuery.js
CHANGED
|
@@ -6,8 +6,7 @@ import { useConfig } from "./useConfig";
|
|
|
6
6
|
* @description for public api
|
|
7
7
|
* @param query
|
|
8
8
|
* @param options
|
|
9
|
-
*/
|
|
10
|
-
export const useLazyQuery = (query, options) => {
|
|
9
|
+
*/ export const useLazyQuery = (query, options)=>{
|
|
11
10
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
12
11
|
const { formatter, init, ...swrOptions } = options || {};
|
|
13
12
|
// check the query is public api
|
|
@@ -18,18 +17,18 @@ export const useLazyQuery = (query, options) => {
|
|
|
18
17
|
throw new Error("please add OrderlyConfigProvider to your app");
|
|
19
18
|
}
|
|
20
19
|
// @ts-ignore
|
|
21
|
-
return useSWRMutation(query, (url, options)
|
|
20
|
+
return useSWRMutation(query, (url, options)=>{
|
|
22
21
|
url = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
|
|
23
22
|
if (options?.arg) {
|
|
24
23
|
// const searchParams = new URLSearchParams(init.arg);
|
|
25
24
|
// url = `${url}?${encodeURIComponent(searchParams.toString())}`;
|
|
26
|
-
const queryString = Object.entries(options.arg)
|
|
27
|
-
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
28
|
-
.join("&");
|
|
25
|
+
const queryString = Object.entries(options.arg).map(([key, value])=>`${key}=${encodeURIComponent(value)}`).join("&");
|
|
29
26
|
url = `${url}?${queryString}`;
|
|
30
27
|
}
|
|
31
28
|
return fetcher(url, init, {
|
|
32
|
-
formatter
|
|
29
|
+
formatter
|
|
33
30
|
});
|
|
34
31
|
}, swrOptions);
|
|
35
32
|
};
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=useLazyQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useLazyQuery.ts"],"sourcesContent":["import useSWR from \"swr\";\nimport { fetcher } from \"./utils/fetcher\";\nimport useSWRMutation, {\n type SWRMutationConfiguration,\n SWRMutationResponse,\n} from \"swr/mutation\";\nimport { useConfig } from \"./useConfig\";\n\n/**\n * useQuery\n * @description for public api\n * @param query\n * @param options\n */\nexport const useLazyQuery = <T, R = any>(\n query: Parameters<typeof useSWR>[\"0\"],\n options?: SWRMutationConfiguration<any, any> & {\n formatter?: (data: any) => R;\n init?: RequestInit;\n }\n): SWRMutationResponse => {\n const apiBaseUrl = useConfig(\"apiBaseUrl\");\n const { formatter, init, ...swrOptions } = options || {};\n // check the query is public api\n // if (typeof query === \"string\" && !query.startsWith(\"/v1/public\")) {\n // throw new Error(\"useQuery is only for public api\");\n // }\n\n if (typeof apiBaseUrl === \"undefined\") {\n throw new Error(\"please add OrderlyConfigProvider to your app\");\n }\n\n // @ts-ignore\n return useSWRMutation(\n query,\n (url: string, options: any) => {\n url = url.startsWith(\"http\") ? url : `${apiBaseUrl}${url}`;\n if (options?.arg) {\n // const searchParams = new URLSearchParams(init.arg);\n // url = `${url}?${encodeURIComponent(searchParams.toString())}`;\n const queryString = Object.entries(options.arg)\n .map(\n ([key, value]) => `${key}=${encodeURIComponent(value as string)}`\n )\n .join(\"&\");\n url = `${url}?${queryString}`;\n }\n return fetcher(url, init, {\n formatter,\n });\n },\n swrOptions\n );\n};\n"],"names":["fetcher","useSWRMutation","useConfig","useLazyQuery","query","options","apiBaseUrl","formatter","init","swrOptions","Error","url","startsWith","arg","queryString","Object","entries","map","key","value","encodeURIComponent","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,OAAO,QAAQ,kBAAkB;AAC1C,OAAOC,oBAGA,eAAe;AACtB,SAASC,SAAS,QAAQ,cAAc;AAExC;;;;;CAKC,GACD,OAAO,MAAMC,eAAe,CAC1BC,OACAC;IAKA,MAAMC,aAAaJ,UAAU;IAC7B,MAAM,EAAEK,SAAS,EAAEC,IAAI,EAAE,GAAGC,YAAY,GAAGJ,WAAW,CAAC;IACvD,gCAAgC;IAChC,sEAAsE;IACtE,wDAAwD;IACxD,IAAI;IAEJ,IAAI,OAAOC,eAAe,aAAa;QACrC,MAAM,IAAII,MAAM;IAClB;IAEA,aAAa;IACb,OAAOT,eACLG,OACA,CAACO,KAAaN;QACZM,MAAMA,IAAIC,UAAU,CAAC,UAAUD,MAAM,CAAC,EAAEL,WAAW,EAAEK,IAAI,CAAC;QAC1D,IAAIN,SAASQ,KAAK;YAChB,sDAAsD;YACtD,iEAAiE;YACjE,MAAMC,cAAcC,OAAOC,OAAO,CAACX,QAAQQ,GAAG,EAC3CI,GAAG,CACF,CAAC,CAACC,KAAKC,MAAM,GAAK,CAAC,EAAED,IAAI,CAAC,EAAEE,mBAAmBD,OAAiB,CAAC,EAElEE,IAAI,CAAC;YACRV,MAAM,CAAC,EAAEA,IAAI,CAAC,EAAEG,YAAY,CAAC;QAC/B;QACA,OAAOd,QAAQW,KAAKH,MAAM;YACxBD;QACF;IACF,GACAE;AAEJ,EAAE"}
|
package/esm/useLocalStorage.js
CHANGED
|
@@ -4,7 +4,7 @@ import { parseJSON } from "./utils/json";
|
|
|
4
4
|
export function useLocalStorage(key, initialValue) {
|
|
5
5
|
// Get from local storage then
|
|
6
6
|
// parse stored json or return initialValue
|
|
7
|
-
const readValue = useCallback(()
|
|
7
|
+
const readValue = useCallback(()=>{
|
|
8
8
|
// Prevent build error "window is undefined" but keeps working
|
|
9
9
|
if (typeof window === "undefined") {
|
|
10
10
|
return initialValue;
|
|
@@ -12,21 +12,23 @@ export function useLocalStorage(key, initialValue) {
|
|
|
12
12
|
try {
|
|
13
13
|
const item = window.localStorage.getItem(key);
|
|
14
14
|
return item ? parseJSON(item) : initialValue;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
console.warn(`Error reading localStorage key “${key}”:`, error);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
;
|
|
18
17
|
return initialValue;
|
|
19
18
|
}
|
|
20
|
-
}, [
|
|
19
|
+
}, [
|
|
20
|
+
initialValue,
|
|
21
|
+
key
|
|
22
|
+
]);
|
|
21
23
|
// State to store our value
|
|
22
24
|
// Pass initial state function to useState so logic is only executed once
|
|
23
25
|
const [storedValue, setStoredValue] = useState(readValue);
|
|
24
26
|
// Return a wrapped version of useState's setter function that ...
|
|
25
27
|
// ... persists the new value to localStorage.
|
|
26
|
-
const setValue = useCallback((value)
|
|
28
|
+
const setValue = useCallback((value)=>{
|
|
27
29
|
// Prevent build error "window is undefined" but keeps working
|
|
28
30
|
if (typeof window === "undefined") {
|
|
29
|
-
|
|
31
|
+
;
|
|
30
32
|
}
|
|
31
33
|
try {
|
|
32
34
|
// Allow value to be a function so we have the same API as useState
|
|
@@ -36,15 +38,16 @@ export function useLocalStorage(key, initialValue) {
|
|
|
36
38
|
// dispath event
|
|
37
39
|
window.dispatchEvent(new Event("storage"));
|
|
38
40
|
// Save state
|
|
39
|
-
setStoredValue(()
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
console.warn(`Error setting localStorage key “${key}”:`, error);
|
|
41
|
+
setStoredValue(()=>newValue);
|
|
42
|
+
// We dispatch a custom event so every useLocalStorage hook are notified
|
|
43
|
+
// window.dispatchEvent(new Event('local-storage'))
|
|
44
|
+
} catch (error) {
|
|
45
|
+
;
|
|
45
46
|
}
|
|
46
|
-
}, [
|
|
47
|
-
|
|
47
|
+
}, [
|
|
48
|
+
storedValue
|
|
49
|
+
]);
|
|
50
|
+
useEffect(()=>{
|
|
48
51
|
setStoredValue(readValue());
|
|
49
52
|
}, []);
|
|
50
53
|
// const handleStorageChange = useCallback(
|
|
@@ -56,17 +59,24 @@ export function useLocalStorage(key, initialValue) {
|
|
|
56
59
|
// },
|
|
57
60
|
// [key, readValue],
|
|
58
61
|
// )
|
|
59
|
-
useEffect(()
|
|
60
|
-
const handleStorageChange = (event)
|
|
62
|
+
useEffect(()=>{
|
|
63
|
+
const handleStorageChange = (event)=>{
|
|
61
64
|
if (event?.key && event.key !== key) {
|
|
62
65
|
return;
|
|
63
66
|
}
|
|
64
67
|
setStoredValue(readValue());
|
|
65
68
|
};
|
|
66
69
|
window.addEventListener("storage", handleStorageChange);
|
|
67
|
-
return ()
|
|
70
|
+
return ()=>{
|
|
68
71
|
window.removeEventListener("storage", handleStorageChange);
|
|
69
72
|
};
|
|
70
|
-
}, [
|
|
71
|
-
|
|
73
|
+
}, [
|
|
74
|
+
key
|
|
75
|
+
]);
|
|
76
|
+
return [
|
|
77
|
+
storedValue,
|
|
78
|
+
setValue
|
|
79
|
+
];
|
|
72
80
|
}
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=useLocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useLocalStorage.ts"],"sourcesContent":["// https://usehooks-ts.com/react-hook/use-local-storage\nimport { useCallback, useEffect, useState } from \"react\";\nimport { parseJSON } from \"./utils/json\";\n\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T\n): [any, (value: T) => void] {\n // Get from local storage then\n // parse stored json or return initialValue\n const readValue = useCallback((): T => {\n // Prevent build error \"window is undefined\" but keeps working\n if (typeof window === \"undefined\") {\n return initialValue;\n }\n\n try {\n const item = window.localStorage.getItem(key);\n return item ? (parseJSON(item) as T) : initialValue;\n } catch (error) {\n console.warn(`Error reading localStorage key “${key}”:`, error);\n return initialValue;\n }\n }, [initialValue, key]);\n\n // State to store our value\n // Pass initial state function to useState so logic is only executed once\n const [storedValue, setStoredValue] = useState<T>(readValue);\n\n // Return a wrapped version of useState's setter function that ...\n // ... persists the new value to localStorage.\n const setValue: React.Dispatch<T> = useCallback(\n (value: T) => {\n // Prevent build error \"window is undefined\" but keeps working\n if (typeof window === \"undefined\") {\n console.warn(\n `Tried setting localStorage key “${key}” even though environment is not a client`\n );\n }\n\n try {\n // Allow value to be a function so we have the same API as useState\n const newValue = value instanceof Function ? value(storedValue) : value;\n\n // Save to local storage\n window.localStorage.setItem(key, JSON.stringify(newValue));\n // dispath event\n window.dispatchEvent(new Event(\"storage\"));\n\n // Save state\n setStoredValue(() => newValue);\n\n // We dispatch a custom event so every useLocalStorage hook are notified\n // window.dispatchEvent(new Event('local-storage'))\n } catch (error) {\n console.warn(`Error setting localStorage key “${key}”:`, error);\n }\n },\n [storedValue]\n );\n\n useEffect(() => {\n setStoredValue(readValue());\n }, []);\n\n // const handleStorageChange = useCallback(\n // (event: StorageEvent | CustomEvent) => {\n // if ((event as StorageEvent)?.key && (event as StorageEvent).key !== key) {\n // return\n // }\n // setStoredValue(readValue())\n // },\n // [key, readValue],\n // )\n\n useEffect(() => {\n const handleStorageChange = (event: StorageEvent | CustomEvent) => {\n if ((event as StorageEvent)?.key && (event as StorageEvent).key !== key) {\n return;\n }\n setStoredValue(readValue());\n };\n\n window.addEventListener(\"storage\", handleStorageChange);\n\n return () => {\n window.removeEventListener(\"storage\", handleStorageChange);\n };\n }, [key]);\n\n return [storedValue, setValue];\n}\n"],"names":["useCallback","useEffect","useState","parseJSON","useLocalStorage","key","initialValue","readValue","window","item","localStorage","getItem","error","storedValue","setStoredValue","setValue","value","newValue","Function","setItem","JSON","stringify","dispatchEvent","Event","handleStorageChange","event","addEventListener","removeEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,uDAAuD;AACvD,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AACzD,SAASC,SAAS,QAAQ,eAAe;AAEzC,OAAO,SAASC,gBACdC,GAAW,EACXC,YAAe;IAEf,8BAA8B;IAC9B,2CAA2C;IAC3C,MAAMC,YAAYP,YAAY;QAC5B,8DAA8D;QAC9D,IAAI,OAAOQ,WAAW,aAAa;YACjC,OAAOF;QACT;QAEA,IAAI;YACF,MAAMG,OAAOD,OAAOE,YAAY,CAACC,OAAO,CAACN;YACzC,OAAOI,OAAQN,UAAUM,QAAcH;QACzC,EAAE,OAAOM,OAAO;;YAEd,OAAON;QACT;IACF,GAAG;QAACA;QAAcD;KAAI;IAEtB,2BAA2B;IAC3B,yEAAyE;IACzE,MAAM,CAACQ,aAAaC,eAAe,GAAGZ,SAAYK;IAElD,kEAAkE;IAClE,8CAA8C;IAC9C,MAAMQ,WAA8Bf,YAClC,CAACgB;QACC,8DAA8D;QAC9D,IAAI,OAAOR,WAAW,aAAa;;QAInC;QAEA,IAAI;YACF,mEAAmE;YACnE,MAAMS,WAAWD,iBAAiBE,WAAWF,MAAMH,eAAeG;YAElE,wBAAwB;YACxBR,OAAOE,YAAY,CAACS,OAAO,CAACd,KAAKe,KAAKC,SAAS,CAACJ;YAChD,gBAAgB;YAChBT,OAAOc,aAAa,CAAC,IAAIC,MAAM;YAE/B,aAAa;YACbT,eAAe,IAAMG;QAErB,wEAAwE;QACxE,mDAAmD;QACrD,EAAE,OAAOL,OAAO;;QAEhB;IACF,GACA;QAACC;KAAY;IAGfZ,UAAU;QACRa,eAAeP;IACjB,GAAG,EAAE;IAEL,2CAA2C;IAC3C,6CAA6C;IAC7C,iFAAiF;IACjF,eAAe;IACf,QAAQ;IACR,kCAAkC;IAClC,OAAO;IACP,sBAAsB;IACtB,IAAI;IAEJN,UAAU;QACR,MAAMuB,sBAAsB,CAACC;YAC3B,IAAI,AAACA,OAAwBpB,OAAO,AAACoB,MAAuBpB,GAAG,KAAKA,KAAK;gBACvE;YACF;YACAS,eAAeP;QACjB;QAEAC,OAAOkB,gBAAgB,CAAC,WAAWF;QAEnC,OAAO;YACLhB,OAAOmB,mBAAmB,CAAC,WAAWH;QACxC;IACF,GAAG;QAACnB;KAAI;IAER,OAAO;QAACQ;QAAaE;KAAS;AAChC"}
|
package/esm/useMediaQuery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
export function useMediaQuery(query) {
|
|
3
|
-
const getMatches = (query)
|
|
3
|
+
const getMatches = (query)=>{
|
|
4
4
|
// Prevents SSR issues
|
|
5
5
|
if (typeof window !== "undefined") {
|
|
6
6
|
return window.matchMedia(query).matches;
|
|
@@ -11,26 +11,28 @@ export function useMediaQuery(query) {
|
|
|
11
11
|
function handleChange() {
|
|
12
12
|
setMatches(getMatches(query));
|
|
13
13
|
}
|
|
14
|
-
useEffect(()
|
|
14
|
+
useEffect(()=>{
|
|
15
15
|
const matchMedia = window.matchMedia(query);
|
|
16
16
|
// Triggered at the first client-side load and if query changes
|
|
17
17
|
handleChange();
|
|
18
18
|
// Listen matchMedia
|
|
19
19
|
if (matchMedia.addListener) {
|
|
20
20
|
matchMedia.addListener(handleChange);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
21
|
+
} else {
|
|
23
22
|
matchMedia.addEventListener("change", handleChange);
|
|
24
23
|
}
|
|
25
|
-
return ()
|
|
24
|
+
return ()=>{
|
|
26
25
|
if (matchMedia.removeListener) {
|
|
27
26
|
matchMedia.removeListener(handleChange);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
27
|
+
} else {
|
|
30
28
|
matchMedia.removeEventListener("change", handleChange);
|
|
31
29
|
}
|
|
32
30
|
};
|
|
33
|
-
|
|
34
|
-
}, [
|
|
31
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
+
}, [
|
|
33
|
+
query
|
|
34
|
+
]);
|
|
35
35
|
return matches;
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=useMediaQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useMediaQuery.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nexport function useMediaQuery(query: string): boolean {\n const getMatches = (query: string): boolean => {\n // Prevents SSR issues\n if (typeof window !== \"undefined\") {\n return window.matchMedia(query).matches;\n }\n return false;\n };\n\n const [matches, setMatches] = useState<boolean>(getMatches(query));\n\n function handleChange() {\n setMatches(getMatches(query));\n }\n\n useEffect(() => {\n const matchMedia = window.matchMedia(query);\n\n // Triggered at the first client-side load and if query changes\n handleChange();\n\n // Listen matchMedia\n if (matchMedia.addListener) {\n matchMedia.addListener(handleChange);\n } else {\n matchMedia.addEventListener(\"change\", handleChange);\n }\n\n return () => {\n if (matchMedia.removeListener) {\n matchMedia.removeListener(handleChange);\n } else {\n matchMedia.removeEventListener(\"change\", handleChange);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query]);\n\n return matches;\n}\n"],"names":["useEffect","useState","useMediaQuery","query","getMatches","window","matchMedia","matches","setMatches","handleChange","addListener","addEventListener","removeListener","removeEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAE5C,OAAO,SAASC,cAAcC,KAAa;IACzC,MAAMC,aAAa,CAACD;QAClB,sBAAsB;QACtB,IAAI,OAAOE,WAAW,aAAa;YACjC,OAAOA,OAAOC,UAAU,CAACH,OAAOI,OAAO;QACzC;QACA,OAAO;IACT;IAEA,MAAM,CAACA,SAASC,WAAW,GAAGP,SAAkBG,WAAWD;IAE3D,SAASM;QACPD,WAAWJ,WAAWD;IACxB;IAEAH,UAAU;QACR,MAAMM,aAAaD,OAAOC,UAAU,CAACH;QAErC,+DAA+D;QAC/DM;QAEA,oBAAoB;QACpB,IAAIH,WAAWI,WAAW,EAAE;YAC1BJ,WAAWI,WAAW,CAACD;QACzB,OAAO;YACLH,WAAWK,gBAAgB,CAAC,UAAUF;QACxC;QAEA,OAAO;YACL,IAAIH,WAAWM,cAAc,EAAE;gBAC7BN,WAAWM,cAAc,CAACH;YAC5B,OAAO;gBACLH,WAAWO,mBAAmB,CAAC,UAAUJ;YAC3C;QACF;IACA,uDAAuD;IACzD,GAAG;QAACN;KAAM;IAEV,OAAOI;AACT"}
|
package/esm/useMutation.js
CHANGED
|
@@ -2,18 +2,17 @@ import useSWRMutation from "swr/mutation";
|
|
|
2
2
|
import { mutate } from "@orderly.network/net";
|
|
3
3
|
import { useAccountInstance } from "./useAccountInstance";
|
|
4
4
|
import { useConfig } from "./useConfig";
|
|
5
|
-
const fetcher = (url, options)
|
|
5
|
+
const fetcher = (url, options)=>{
|
|
6
6
|
const init = {
|
|
7
7
|
method: options.arg.method,
|
|
8
8
|
headers: {
|
|
9
|
-
...options.arg.signature
|
|
10
|
-
}
|
|
9
|
+
...options.arg.signature
|
|
10
|
+
}
|
|
11
11
|
};
|
|
12
12
|
if (options.arg.data) {
|
|
13
13
|
init.body = JSON.stringify(options.arg.data);
|
|
14
14
|
}
|
|
15
|
-
if (typeof options.arg.params === "object" &&
|
|
16
|
-
Object.keys(options.arg.params).length) {
|
|
15
|
+
if (typeof options.arg.params === "object" && Object.keys(options.arg.params).length) {
|
|
17
16
|
let search = new URLSearchParams(options.arg.params);
|
|
18
17
|
url = `${url}?${search.toString()}`;
|
|
19
18
|
}
|
|
@@ -21,24 +20,17 @@ const fetcher = (url, options) => {
|
|
|
21
20
|
};
|
|
22
21
|
/**
|
|
23
22
|
* This hook is used to execute API requests for data mutation, such as POST, DELETE, PUT, etc.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The configuration object for the mutation.
|
|
37
|
-
* @see [useSWRMutation](https://swr.vercel.app/docs/mutation#api)
|
|
38
|
-
*
|
|
39
|
-
* @link https://swr.vercel.app/docs/mutation#api
|
|
40
|
-
*/
|
|
41
|
-
options) => {
|
|
23
|
+
*/ export const useMutation = (/**
|
|
24
|
+
* The URL to send the request to. If the URL does not start with "http",
|
|
25
|
+
* it will be prefixed with the API base URL.
|
|
26
|
+
*/ url, /**
|
|
27
|
+
* The HTTP method to use for the request. Defaults to "POST".
|
|
28
|
+
*/ method = "POST", /**
|
|
29
|
+
* The configuration object for the mutation.
|
|
30
|
+
* @see [useSWRMutation](https://swr.vercel.app/docs/mutation#api)
|
|
31
|
+
*
|
|
32
|
+
* @link https://swr.vercel.app/docs/mutation#api
|
|
33
|
+
*/ options)=>{
|
|
42
34
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
43
35
|
let fullUrl = url;
|
|
44
36
|
if (!url.startsWith("http")) {
|
|
@@ -46,18 +38,13 @@ options) => {
|
|
|
46
38
|
}
|
|
47
39
|
const account = useAccountInstance();
|
|
48
40
|
const signer = account.signer;
|
|
49
|
-
const { trigger, data, error, reset, isMutating } = useSWRMutation(fullUrl,
|
|
50
|
-
// method === "POST" ? fetcher : deleteFetcher,
|
|
41
|
+
const { trigger, data, error, reset, isMutating } = useSWRMutation(fullUrl, // method === "POST" ? fetcher : deleteFetcher,
|
|
51
42
|
fetcher, options);
|
|
52
|
-
const mutation = async (
|
|
53
|
-
/**
|
|
43
|
+
const mutation = async (/**
|
|
54
44
|
* The data to send with the request.
|
|
55
|
-
*/
|
|
56
|
-
data,
|
|
57
|
-
/**
|
|
45
|
+
*/ data, /**
|
|
58
46
|
* The query parameters to send with the request.
|
|
59
|
-
*/
|
|
60
|
-
params, options) => {
|
|
47
|
+
*/ params, options)=>{
|
|
61
48
|
let newUrl = url;
|
|
62
49
|
if (typeof params === "object" && Object.keys(params).length) {
|
|
63
50
|
let search = new URLSearchParams(params);
|
|
@@ -66,7 +53,7 @@ options) => {
|
|
|
66
53
|
const payload = {
|
|
67
54
|
method,
|
|
68
55
|
url: newUrl,
|
|
69
|
-
data
|
|
56
|
+
data
|
|
70
57
|
};
|
|
71
58
|
const signature = await signer.sign(payload);
|
|
72
59
|
return trigger({
|
|
@@ -75,8 +62,8 @@ options) => {
|
|
|
75
62
|
method,
|
|
76
63
|
signature: {
|
|
77
64
|
...signature,
|
|
78
|
-
"orderly-account-id": account.accountId
|
|
79
|
-
}
|
|
65
|
+
"orderly-account-id": account.accountId
|
|
66
|
+
}
|
|
80
67
|
}, options);
|
|
81
68
|
};
|
|
82
69
|
return [
|
|
@@ -85,7 +72,9 @@ options) => {
|
|
|
85
72
|
data,
|
|
86
73
|
error,
|
|
87
74
|
reset,
|
|
88
|
-
isMutating
|
|
89
|
-
}
|
|
75
|
+
isMutating
|
|
76
|
+
}
|
|
90
77
|
];
|
|
91
78
|
};
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=useMutation.js.map
|