@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
package/lib/useObserve.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
Subjects: function() {
|
|
13
|
+
return Subjects;
|
|
14
|
+
},
|
|
15
|
+
useObserve: function() {
|
|
16
|
+
return useObserve;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
4
19
|
var Subjects;
|
|
5
|
-
(function
|
|
20
|
+
(function(Subjects) {
|
|
6
21
|
Subjects["Orders"] = "orders";
|
|
7
22
|
Subjects["Positions"] = "positions";
|
|
8
|
-
})(Subjects || (
|
|
9
|
-
const useObserve = (key, initialValue
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.useObserve = useObserve;
|
|
23
|
+
})(Subjects || (Subjects = {}));
|
|
24
|
+
const useObserve = (key, initialValue)=>{};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=useObserve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useObserve.ts"],"sourcesContent":["import { useState } from \"react\";\n\nexport enum Subjects {\n Orders = \"orders\",\n Positions = \"positions\",\n}\n\nexport const useObserve = <T>(\n key: string,\n initialValue: T\n // @ts-ignore\n): [T, (value: T) => void] => {};\n"],"names":["useObserve","Subjects","key","initialValue"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;;;;IAOaA,UAAU;eAAVA;;;;UALDC;;;GAAAA,aAAAA;AAKL,MAAMD,aAAa,CACxBE,KACAC,gBAE6B"}
|
package/lib/useParamsCheck.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useParamsCheck", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useParamsCheck;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const useParamsCheck = (params)=>{
|
|
13
|
+
(0, _react.useEffect)(()=>{
|
|
7
14
|
if (!params.brokerId || params.brokerId === "orderly") {
|
|
8
|
-
|
|
9
|
-
"\n" +
|
|
10
|
-
"========================" +
|
|
11
|
-
"\n" +
|
|
12
|
-
"[OrderlyConfigProvider]: please provide your brokerId" +
|
|
13
|
-
"\n" +
|
|
14
|
-
"========================");
|
|
15
|
+
;
|
|
15
16
|
}
|
|
16
|
-
}, [
|
|
17
|
+
}, [
|
|
18
|
+
params.brokerId
|
|
19
|
+
]);
|
|
17
20
|
};
|
|
18
|
-
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=useParamsCheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useParamsCheck.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nexport const useParamsCheck = (params: { brokerId?: string }) => {\n useEffect(() => {\n if (!params.brokerId || params.brokerId === \"orderly\") {\n console.warn(\n \"WARNING:\" +\n \"\\n\" +\n \"========================\" +\n \"\\n\" +\n \"[OrderlyConfigProvider]: please provide your brokerId\" +\n \"\\n\" +\n \"========================\"\n );\n }\n }, [params.brokerId]);\n};\n"],"names":["useParamsCheck","params","useEffect","brokerId"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAEaA;;;eAAAA;;;uBAFa;AAEnB,MAAMA,iBAAiB,CAACC;IAC7BC,IAAAA,gBAAS,EAAC;QACR,IAAI,CAACD,OAAOE,QAAQ,IAAIF,OAAOE,QAAQ,KAAK,WAAW;;QAUvD;IACF,GAAG;QAACF,OAAOE,QAAQ;KAAC;AACtB"}
|
package/lib/usePoster.js
CHANGED
|
@@ -1,78 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
data, options) => {
|
|
26
|
-
const [error, setError] = (0, react_1.useState)(null);
|
|
27
|
-
const [canCopy, setCanCopy] = (0, react_1.useState)(() => typeof navigator.clipboard !== "undefined");
|
|
28
|
-
const painterRef = (0, react_1.useRef)(null);
|
|
29
|
-
const [target, setTarget] = (0, react_1.useState)(null);
|
|
30
|
-
(0, react_1.useEffect)(() => {
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "usePoster", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return usePoster;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const _ramda = require("ramda");
|
|
13
|
+
const _painter = require("./services/painter/painter");
|
|
14
|
+
const _layoutconfig = require("./services/painter/layout.config");
|
|
15
|
+
const _types = require("@orderly.network/types");
|
|
16
|
+
const usePoster = (/**
|
|
17
|
+
* The options to draw the poster
|
|
18
|
+
*/ data, options)=>{
|
|
19
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
20
|
+
const [canCopy, setCanCopy] = (0, _react.useState)(()=>typeof navigator.clipboard !== "undefined");
|
|
21
|
+
const painterRef = (0, _react.useRef)(null);
|
|
22
|
+
const [target, setTarget] = (0, _react.useState)(null);
|
|
23
|
+
(0, _react.useEffect)(()=>{
|
|
31
24
|
// Create the painter instance
|
|
32
25
|
if (target && !painterRef.current) {
|
|
33
|
-
painterRef.current = new
|
|
26
|
+
painterRef.current = new _painter.PosterPainter(target, {
|
|
34
27
|
ratio: 1,
|
|
35
|
-
...options
|
|
28
|
+
...options
|
|
36
29
|
});
|
|
37
|
-
painterRef.current.draw((0,
|
|
30
|
+
painterRef.current.draw((0, _ramda.mergeDeepRight)({
|
|
31
|
+
layout: _layoutconfig.DefaultLayoutConfig,
|
|
32
|
+
fontFamily: "Manrope"
|
|
33
|
+
}, data));
|
|
38
34
|
}
|
|
39
|
-
}, [
|
|
40
|
-
|
|
35
|
+
}, [
|
|
36
|
+
target
|
|
37
|
+
]);
|
|
38
|
+
(0, _react.useEffect)(()=>{
|
|
41
39
|
if (painterRef.current) {
|
|
42
|
-
painterRef.current.draw((0,
|
|
40
|
+
painterRef.current.draw((0, _ramda.mergeDeepRight)({
|
|
41
|
+
layout: _layoutconfig.DefaultLayoutConfig,
|
|
42
|
+
fontFamily: "Manrope"
|
|
43
|
+
}, data));
|
|
43
44
|
}
|
|
44
|
-
}, [
|
|
45
|
-
|
|
45
|
+
}, [
|
|
46
|
+
data
|
|
47
|
+
]);
|
|
48
|
+
const toDataURL = (type, encoderOptions)=>{
|
|
46
49
|
if (!target) {
|
|
47
|
-
throw new
|
|
50
|
+
throw new _types.SDKError("The ref must be a canvas element");
|
|
48
51
|
}
|
|
49
52
|
return target.toDataURL(type, encoderOptions);
|
|
50
53
|
};
|
|
51
54
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return new Promise((resolve) => {
|
|
55
|
+
* Converts the poster to a blob
|
|
56
|
+
*/ const toBlob = (0, _react.useCallback)((type, encoderOptions)=>{
|
|
57
|
+
return new Promise((resolve)=>{
|
|
56
58
|
if (!target) {
|
|
57
59
|
resolve(null);
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
60
62
|
target.toBlob(resolve, type, encoderOptions);
|
|
61
63
|
});
|
|
62
|
-
}, [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
}, [
|
|
65
|
+
target
|
|
66
|
+
]);
|
|
67
|
+
const ref = (ref)=>{
|
|
68
|
+
if (!ref) return;
|
|
66
69
|
if (ref.tagName.toUpperCase() !== "CANVAS") {
|
|
67
70
|
// throw new Error("The ref must be a canvas element");
|
|
68
|
-
setError(new
|
|
71
|
+
setError(new _types.SDKError("The ref must be a canvas element"));
|
|
69
72
|
return;
|
|
70
73
|
}
|
|
71
74
|
setTarget(ref);
|
|
72
75
|
};
|
|
73
|
-
const download = (0,
|
|
76
|
+
const download = (0, _react.useCallback)((filename, type = "image/png", encoderOptions)=>{
|
|
74
77
|
if (!target) {
|
|
75
|
-
throw new
|
|
78
|
+
throw new _types.SDKError("The ref must be a canvas element");
|
|
76
79
|
}
|
|
77
80
|
const img = new Image();
|
|
78
81
|
img.src = target.toDataURL(type, encoderOptions);
|
|
@@ -80,48 +83,51 @@ data, options) => {
|
|
|
80
83
|
link.href = img.src;
|
|
81
84
|
link.download = filename;
|
|
82
85
|
link.click();
|
|
83
|
-
}, [
|
|
84
|
-
|
|
86
|
+
}, [
|
|
87
|
+
target
|
|
88
|
+
]);
|
|
89
|
+
const copy = (0, _react.useCallback)(()=>{
|
|
85
90
|
if (!target) {
|
|
86
|
-
throw new
|
|
91
|
+
throw new _types.SDKError("The ref must be a canvas element");
|
|
87
92
|
}
|
|
88
93
|
// copy image to clipboard
|
|
89
|
-
return new Promise((resolve, reject)
|
|
94
|
+
return new Promise((resolve, reject)=>{
|
|
90
95
|
if (!navigator.clipboard) {
|
|
91
|
-
reject(new
|
|
96
|
+
reject(new _types.SDKError("Clipboard API is not supported"));
|
|
92
97
|
return;
|
|
93
98
|
}
|
|
94
|
-
target.toBlob((blob)
|
|
99
|
+
target.toBlob((blob)=>{
|
|
95
100
|
if (!blob) {
|
|
96
|
-
reject(new
|
|
101
|
+
reject(new _types.SDKError("Failed to create blob"));
|
|
97
102
|
return;
|
|
98
103
|
}
|
|
99
|
-
return navigator.clipboard
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
return navigator.clipboard.write([
|
|
105
|
+
new ClipboardItem({
|
|
106
|
+
[blob.type]: blob
|
|
107
|
+
})
|
|
108
|
+
]).then(resolve, reject);
|
|
102
109
|
});
|
|
103
110
|
});
|
|
104
|
-
}, [
|
|
111
|
+
}, [
|
|
112
|
+
target
|
|
113
|
+
]);
|
|
105
114
|
return {
|
|
106
115
|
error,
|
|
107
116
|
ref,
|
|
108
117
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
toDataURL,
|
|
118
|
+
* Converts the poster to a data URL
|
|
119
|
+
*/ toDataURL,
|
|
112
120
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
toBlob,
|
|
121
|
+
* Converts the poster to a blob
|
|
122
|
+
*/ toBlob,
|
|
116
123
|
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
download,
|
|
124
|
+
* Downloads the poster as an image
|
|
125
|
+
*/ download,
|
|
120
126
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
copy,
|
|
127
|
+
* Browser if supports copy image to clipboard
|
|
128
|
+
*/ canCopy,
|
|
129
|
+
copy
|
|
125
130
|
};
|
|
126
131
|
};
|
|
127
|
-
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=usePoster.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/usePoster.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { mergeDeepRight } from \"ramda\";\nimport { PosterPainter } from \"./services/painter/painter\";\nimport { type DrawOptions } from \"./services/painter/basePaint\";\nimport { DefaultLayoutConfig } from \"./services/painter/layout.config\";\nimport { SDKError } from \"@orderly.network/types\";\n\n/**\n * Generates a poster image based on position information. You can set the size, background color, font color, font size, and content position of the poster.\n * @example\n * ```tsx\n * const { ref, toDataURL, toBlob, download, copy } = usePoster({\n * backgroundColor: \"#0b8c70\",\n * backgroundImg: \"/images/poster_bg.png\",\n * color: \"rgba(255, 255, 255, 0.98)\",\n * profitColor: \"rgb(0,181,159)\",\n * ...\n * });\n */\nexport const usePoster = (\n /**\n * The options to draw the poster\n */\n data: DrawOptions,\n options?: {\n /**\n * The ratio of the poster\n */\n ratio?: number;\n }\n) => {\n const [error, setError] = useState<Error | null>(null);\n const [canCopy, setCanCopy] = useState<boolean>(\n () => typeof navigator.clipboard !== \"undefined\"\n );\n\n const painterRef = useRef<PosterPainter | null>(null);\n\n const [target, setTarget] = useState<HTMLCanvasElement | null>(null);\n\n useEffect(() => {\n // Create the painter instance\n if (target && !painterRef.current) {\n painterRef.current = new PosterPainter(target, {\n ratio: 1,\n ...options,\n });\n painterRef.current.draw(\n mergeDeepRight<Partial<DrawOptions>, DrawOptions>(\n { layout: DefaultLayoutConfig, fontFamily: \"Manrope\" },\n data\n )\n );\n }\n }, [target]);\n\n useEffect(() => {\n if (painterRef.current) {\n painterRef.current.draw(\n mergeDeepRight<Partial<DrawOptions>, DrawOptions>(\n { layout: DefaultLayoutConfig, fontFamily: \"Manrope\" },\n data\n )\n );\n }\n }, [data]);\n\n const toDataURL = (type?: string, encoderOptions?: number) => {\n if (!target) {\n throw new SDKError(\"The ref must be a canvas element\");\n }\n return target.toDataURL(type, encoderOptions);\n };\n\n /**\n * Converts the poster to a blob\n */\n const toBlob = useCallback(\n (type?: string, encoderOptions?: number): Promise<Blob | null> => {\n return new Promise<Blob | null>((resolve) => {\n if (!target) {\n resolve(null);\n return;\n }\n target.toBlob(resolve, type, encoderOptions);\n });\n },\n [target]\n );\n\n const ref = (ref: HTMLCanvasElement | null) => {\n if (!ref) return;\n if (ref.tagName.toUpperCase() !== \"CANVAS\") {\n // throw new Error(\"The ref must be a canvas element\");\n setError(new SDKError(\"The ref must be a canvas element\"));\n return;\n }\n setTarget(ref);\n };\n\n const download = useCallback(\n (filename: string, type: string = \"image/png\", encoderOptions?: number) => {\n if (!target) {\n throw new SDKError(\"The ref must be a canvas element\");\n }\n const img = new Image();\n img.src = target.toDataURL(type, encoderOptions);\n const link = document.createElement(\"a\");\n link.href = img.src;\n link.download = filename;\n link.click();\n },\n [target]\n );\n\n const copy = useCallback(() => {\n if (!target) {\n throw new SDKError(\"The ref must be a canvas element\");\n }\n // copy image to clipboard\n return new Promise<void>((resolve, reject) => {\n if (!navigator.clipboard) {\n reject(new SDKError(\"Clipboard API is not supported\"));\n return;\n }\n target.toBlob((blob) => {\n if (!blob) {\n reject(new SDKError(\"Failed to create blob\"));\n return;\n }\n return navigator.clipboard\n .write([new ClipboardItem({ [blob.type]: blob })])\n .then(resolve, reject);\n });\n });\n }, [target]);\n\n return {\n error,\n ref,\n /**\n * Converts the poster to a data URL\n */\n toDataURL,\n /**\n * Converts the poster to a blob\n */\n toBlob,\n /**\n * Downloads the poster as an image\n */\n download,\n /**\n * Browser if supports copy image to clipboard\n */\n canCopy,\n copy,\n } as const;\n};\n"],"names":["usePoster","data","options","error","setError","useState","canCopy","setCanCopy","navigator","clipboard","painterRef","useRef","target","setTarget","useEffect","current","PosterPainter","ratio","draw","mergeDeepRight","layout","DefaultLayoutConfig","fontFamily","toDataURL","type","encoderOptions","SDKError","toBlob","useCallback","Promise","resolve","ref","tagName","toUpperCase","download","filename","img","Image","src","link","document","createElement","href","click","copy","reject","blob","write","ClipboardItem","then"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"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"}
|
package/lib/usePreloadData.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "usePreLoadData", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return usePreLoadData;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
const _ = require(".");
|
|
13
|
+
const usePreLoadData = ()=>{
|
|
14
|
+
const { error: tokenError, data: tokenData } = (0, _.useQuery)("https://api-evm.orderly.org/v1/public/token", {
|
|
15
|
+
revalidateOnFocus: false
|
|
9
16
|
});
|
|
10
|
-
const isDone = (0,
|
|
17
|
+
const isDone = (0, _react.useMemo)(()=>{
|
|
11
18
|
return !!tokenData;
|
|
12
|
-
}, [
|
|
19
|
+
}, [
|
|
20
|
+
tokenData
|
|
21
|
+
]);
|
|
13
22
|
return {
|
|
14
23
|
error: tokenError,
|
|
15
|
-
done: isDone
|
|
24
|
+
done: isDone
|
|
16
25
|
};
|
|
17
26
|
};
|
|
18
|
-
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=usePreloadData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/usePreloadData.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { useQuery } from \".\";\n\nexport const usePreLoadData = () => {\n const { error: tokenError, data: tokenData } = useQuery(\n \"https://api-evm.orderly.org/v1/public/token\",\n {\n revalidateOnFocus: false,\n }\n );\n\n const isDone = useMemo(() => {\n return !!tokenData;\n }, [tokenData]);\n\n return {\n error: tokenError,\n done: isDone,\n };\n};\n"],"names":["usePreLoadData","error","tokenError","data","tokenData","useQuery","revalidateOnFocus","isDone","useMemo","done"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAGaA;;;eAAAA;;;uBAHW;kBACC;AAElB,MAAMA,iBAAiB;IAC5B,MAAM,EAAEC,OAAOC,UAAU,EAAEC,MAAMC,SAAS,EAAE,GAAGC,IAAAA,UAAQ,EACrD,+CACA;QACEC,mBAAmB;IACrB;IAGF,MAAMC,SAASC,IAAAA,cAAO,EAAC;QACrB,OAAO,CAAC,CAACJ;IACX,GAAG;QAACA;KAAU;IAEd,OAAO;QACLH,OAAOC;QACPO,MAAMF;IACR;AACF"}
|
|
@@ -1,32 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "usePrivateInfiniteQuery", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return usePrivateInfiniteQuery;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _infinite = /*#__PURE__*/ _interop_require_default(require("swr/infinite"));
|
|
12
|
+
const _signatureMiddleware = require("./middleware/signatureMiddleware");
|
|
13
|
+
const _net = require("@orderly.network/net");
|
|
14
|
+
const _useAccount = require("./useAccount");
|
|
15
|
+
const _types = require("@orderly.network/types");
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const usePrivateInfiniteQuery = (getKey, options)=>{
|
|
13
22
|
const { formatter, ...restOptions } = options || {};
|
|
14
|
-
const account = (0,
|
|
15
|
-
const middleware = Array.isArray(restOptions?.use)
|
|
16
|
-
|
|
17
|
-
: [];
|
|
18
|
-
const result = (0, infinite_1.default)((pageIndex, previousPageData) => {
|
|
23
|
+
const account = (0, _useAccount.useAccount)();
|
|
24
|
+
const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
|
|
25
|
+
const result = (0, _infinite.default)((pageIndex, previousPageData)=>{
|
|
19
26
|
const queryKey = getKey(pageIndex, previousPageData);
|
|
20
|
-
if (account.state.status <
|
|
27
|
+
if (account.state.status < _types.AccountStatusEnum.EnableTrading || !queryKey) {
|
|
21
28
|
return null;
|
|
22
29
|
}
|
|
23
|
-
return [
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
return [
|
|
31
|
+
queryKey,
|
|
32
|
+
account.state.accountId
|
|
33
|
+
];
|
|
34
|
+
}, (url, init)=>{
|
|
35
|
+
return restOptions.fetcher?.(url, init) || (0, _net.get)(url, init, formatter);
|
|
26
36
|
}, {
|
|
27
37
|
...restOptions,
|
|
28
|
-
use: [
|
|
38
|
+
use: [
|
|
39
|
+
_signatureMiddleware.signatureMiddleware,
|
|
40
|
+
...middleware
|
|
41
|
+
]
|
|
29
42
|
});
|
|
30
43
|
return result;
|
|
31
44
|
};
|
|
32
|
-
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=usePrivateInfiniteQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/usePrivateInfiniteQuery.ts"],"sourcesContent":["import useSWRInfinite, {\n type SWRInfiniteKeyLoader,\n type SWRInfiniteConfiguration,\n} from \"swr/infinite\";\nimport { signatureMiddleware } from \"./middleware/signatureMiddleware\";\nimport { get } from \"@orderly.network/net\";\nimport { useAccount } from \"./useAccount\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\n\nexport const usePrivateInfiniteQuery = (\n getKey: SWRInfiniteKeyLoader,\n options?: SWRInfiniteConfiguration & {\n formatter?: (data: any) => any;\n }\n) => {\n const { formatter, ...restOptions } = options || {};\n const account = useAccount();\n\n const middleware = Array.isArray(restOptions?.use)\n ? restOptions?.use ?? []\n : [];\n\n const result = useSWRInfinite(\n (pageIndex: number, previousPageData) => {\n const queryKey = getKey(pageIndex, previousPageData);\n if (account.state.status < AccountStatusEnum.EnableTrading || !queryKey) {\n return null;\n }\n return [queryKey, account.state.accountId];\n },\n (url: string, init: RequestInit) => {\n return restOptions.fetcher?.(url, init) || get(url, init, formatter);\n },\n {\n ...restOptions,\n use: [signatureMiddleware, ...middleware],\n }\n );\n\n return result;\n};\n"],"names":["usePrivateInfiniteQuery","getKey","options","formatter","restOptions","account","useAccount","middleware","Array","isArray","use","result","useSWRInfinite","pageIndex","previousPageData","queryKey","state","status","AccountStatusEnum","EnableTrading","accountId","url","init","fetcher","get","signatureMiddleware"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BASaA;;;eAAAA;;;iEANN;qCAC6B;qBAChB;4BACO;uBACO;;;;;;AAE3B,MAAMA,0BAA0B,CACrCC,QACAC;IAIA,MAAM,EAAEC,SAAS,EAAE,GAAGC,aAAa,GAAGF,WAAW,CAAC;IAClD,MAAMG,UAAUC,IAAAA,sBAAU;IAE1B,MAAMC,aAAaC,MAAMC,OAAO,CAACL,aAAaM,OAC1CN,aAAaM,OAAO,EAAE,GACtB,EAAE;IAEN,MAAMC,SAASC,IAAAA,iBAAc,EAC3B,CAACC,WAAmBC;QAClB,MAAMC,WAAWd,OAAOY,WAAWC;QACnC,IAAIT,QAAQW,KAAK,CAACC,MAAM,GAAGC,wBAAiB,CAACC,aAAa,IAAI,CAACJ,UAAU;YACvE,OAAO;QACT;QACA,OAAO;YAACA;YAAUV,QAAQW,KAAK,CAACI,SAAS;SAAC;IAC5C,GACA,CAACC,KAAaC;QACZ,OAAOlB,YAAYmB,OAAO,GAAGF,KAAKC,SAASE,IAAAA,QAAG,EAACH,KAAKC,MAAMnB;IAC5D,GACA;QACE,GAAGC,WAAW;QACdM,KAAK;YAACe,wCAAmB;eAAKlB;SAAW;IAC3C;IAGF,OAAOI;AACT"}
|
package/lib/usePrivateQuery.js
CHANGED
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "usePrivateQuery", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return usePrivateQuery;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _swr = /*#__PURE__*/ _interop_require_default(require("swr"));
|
|
12
|
+
const _signatureMiddleware = require("./middleware/signatureMiddleware");
|
|
13
|
+
const _fetcher = require("./utils/fetcher");
|
|
14
|
+
const _useAccount = require("./useAccount");
|
|
15
|
+
const _types = require("@orderly.network/types");
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const usePrivateQuery = (query, options)=>{
|
|
19
22
|
const { formatter, ...swrOptions } = options || {};
|
|
20
|
-
const account = (0,
|
|
23
|
+
const account = (0, _useAccount.useAccount)();
|
|
21
24
|
const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
|
|
22
25
|
// @ts-ignore
|
|
23
|
-
return (0,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
return (0, _swr.default)(()=>account.state.status >= _types.AccountStatusEnum.EnableTrading ? [
|
|
27
|
+
query,
|
|
28
|
+
account.state.accountId
|
|
29
|
+
] : null, (url, init)=>{
|
|
30
|
+
return (0, _fetcher.fetcher)(url, init, {
|
|
31
|
+
formatter
|
|
32
|
+
});
|
|
27
33
|
}, {
|
|
28
34
|
...swrOptions,
|
|
29
|
-
use: [
|
|
30
|
-
|
|
35
|
+
use: [
|
|
36
|
+
_signatureMiddleware.signatureMiddleware,
|
|
37
|
+
...middleware
|
|
38
|
+
],
|
|
39
|
+
onError: (err)=>{}
|
|
31
40
|
});
|
|
32
41
|
};
|
|
33
|
-
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=usePrivateQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/usePrivateQuery.ts"],"sourcesContent":["import useSWR, { SWRResponse } from \"swr\";\nimport { signatureMiddleware } from \"./middleware/signatureMiddleware\";\nimport { fetcher, useQueryOptions } from \"./utils/fetcher\";\nimport { useAccount } from \"./useAccount\";\nimport { AccountStatusEnum } from \"@orderly.network/types\";\n\n/**\n * usePrivateQuery\n * @description for private api\n * @param query\n * @param options\n */\nexport const usePrivateQuery = <T>(\n query: string,\n options?: useQueryOptions<T>\n): SWRResponse<T> => {\n const { formatter, ...swrOptions } = options || {};\n const account = useAccount();\n const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];\n\n // @ts-ignore\n return useSWR<T>(\n () =>\n account.state.status >= AccountStatusEnum.EnableTrading\n ? [query, account.state.accountId]\n : null,\n (url: string, init: RequestInit) => {\n return fetcher(url, init, { formatter });\n },\n {\n ...swrOptions,\n use: [signatureMiddleware, ...middleware],\n onError: (err) => {},\n }\n );\n};\n"],"names":["usePrivateQuery","query","options","formatter","swrOptions","account","useAccount","middleware","Array","isArray","use","useSWR","state","status","AccountStatusEnum","EnableTrading","accountId","url","init","fetcher","signatureMiddleware","onError","err"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAYaA;;;eAAAA;;;4DAZuB;qCACA;yBACK;4BACd;uBACO;;;;;;AAQ3B,MAAMA,kBAAkB,CAC7BC,OACAC;IAEA,MAAM,EAAEC,SAAS,EAAE,GAAGC,YAAY,GAAGF,WAAW,CAAC;IACjD,MAAMG,UAAUC,IAAAA,sBAAU;IAC1B,MAAMC,aAAaC,MAAMC,OAAO,CAACP,SAASQ,OAAOR,SAASQ,OAAO,EAAE,GAAG,EAAE;IAExE,aAAa;IACb,OAAOC,IAAAA,YAAM,EACX,IACEN,QAAQO,KAAK,CAACC,MAAM,IAAIC,wBAAiB,CAACC,aAAa,GACnD;YAACd;YAAOI,QAAQO,KAAK,CAACI,SAAS;SAAC,GAChC,MACN,CAACC,KAAaC;QACZ,OAAOC,IAAAA,gBAAO,EAACF,KAAKC,MAAM;YAAEf;QAAU;IACxC,GACA;QACE,GAAGC,UAAU;QACbM,KAAK;YAACU,wCAAmB;eAAKb;SAAW;QACzCc,SAAS,CAACC,OAAS;IACrB;AAEJ"}
|
package/lib/useQuery.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useQuery", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useQuery;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _swr = /*#__PURE__*/ _interop_require_default(require("swr"));
|
|
12
|
+
const _fetcher = require("./utils/fetcher");
|
|
13
|
+
const _useConfig = require("./useConfig");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const useQuery = (query, options)=>{
|
|
20
|
+
const apiBaseUrl = (0, _useConfig.useConfig)("apiBaseUrl");
|
|
18
21
|
const { formatter, ...swrOptions } = options || {};
|
|
19
22
|
if (typeof apiBaseUrl === "undefined") {
|
|
20
23
|
throw new Error("please add OrderlyConfigProvider to your app");
|
|
21
24
|
}
|
|
22
25
|
// @ts-ignore
|
|
23
|
-
return (0,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
return (0, _swr.default)(query, (url, init)=>(0, _fetcher.fetcher)(url.startsWith("http") ? url : `${apiBaseUrl}${url}`, init, {
|
|
27
|
+
formatter
|
|
28
|
+
}), swrOptions);
|
|
26
29
|
};
|
|
27
|
-
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=useQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useQuery.ts"],"sourcesContent":["import useSWR, { SWRResponse } from \"swr\";\nimport { fetcher, useQueryOptions } from \"./utils/fetcher\";\nimport { useConfig } from \"./useConfig\";\n\n/**\n * useQuery\n * @description for public api\n * @param query\n * @param options\n */\nexport const useQuery = <T>(\n query: Parameters<typeof useSWR>[\"0\"],\n options?: useQueryOptions<T>\n): SWRResponse<T> => {\n const apiBaseUrl = useConfig(\"apiBaseUrl\");\n const { formatter, ...swrOptions } = options || {};\n\n if (typeof apiBaseUrl === \"undefined\") {\n throw new Error(\"please add OrderlyConfigProvider to your app\");\n }\n\n // @ts-ignore\n return useSWR<T>(\n query,\n (url, init) =>\n fetcher(url.startsWith(\"http\") ? url : `${apiBaseUrl}${url}`, init, {\n formatter,\n }),\n swrOptions\n );\n};\n"],"names":["useQuery","query","options","apiBaseUrl","useConfig","formatter","swrOptions","Error","useSWR","url","init","fetcher","startsWith"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAUaA;;;eAAAA;;;4DAVuB;yBACK;2BACf;;;;;;AAQnB,MAAMA,WAAW,CACtBC,OACAC;IAEA,MAAMC,aAAaC,IAAAA,oBAAS,EAAC;IAC7B,MAAM,EAAEC,SAAS,EAAE,GAAGC,YAAY,GAAGJ,WAAW,CAAC;IAEjD,IAAI,OAAOC,eAAe,aAAa;QACrC,MAAM,IAAII,MAAM;IAClB;IAEA,aAAa;IACb,OAAOC,IAAAA,YAAM,EACXP,OACA,CAACQ,KAAKC,OACJC,IAAAA,gBAAO,EAACF,IAAIG,UAAU,CAAC,UAAUH,MAAM,CAAC,EAAEN,WAAW,EAAEM,IAAI,CAAC,EAAEC,MAAM;YAClEL;QACF,IACFC;AAEJ"}
|