@symmio/trading-react 0.1.1 → 1.0.0
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/README.md +2 -2
- package/dist/account-layer/index.d.ts +28 -28
- package/dist/account-layer/index.js +29 -0
- package/dist/account-layer/use-account-balance-info.d.ts +16 -5
- package/dist/account-layer/use-account-balance-info.d.ts.map +1 -1
- package/dist/account-layer/use-account-balance-info.js +21 -9
- package/dist/account-layer/use-account-balance-info.js.map +1 -1
- package/dist/account-layer/use-account-balance-of.d.ts +16 -5
- package/dist/account-layer/use-account-balance-of.d.ts.map +1 -1
- package/dist/account-layer/use-account-balance-of.js +20 -9
- package/dist/account-layer/use-account-balance-of.js.map +1 -1
- package/dist/account-layer/use-add-margin.d.ts +2 -2
- package/dist/account-layer/use-allocate.d.ts +2 -2
- package/dist/account-layer/use-create-sub-accounts.d.ts +2 -2
- package/dist/account-layer/use-deallocate.d.ts +2 -2
- package/dist/account-layer/use-delete-sub-account.d.ts +2 -2
- package/dist/account-layer/use-deposit-and-allocate.d.ts +2 -2
- package/dist/account-layer/use-deposit.d.ts +5 -3
- package/dist/account-layer/use-deposit.d.ts.map +1 -1
- package/dist/account-layer/use-deposit.js +17 -15
- package/dist/account-layer/use-deposit.js.map +1 -1
- package/dist/account-layer/use-edit-account-name.d.ts +2 -2
- package/dist/account-layer/use-predicted-next-virtual-account.d.ts +1 -1
- package/dist/account-layer/use-remove-margin.d.ts +2 -2
- package/dist/account-layer/use-simulate-add-margin.d.ts +1 -1
- package/dist/account-layer/use-simulate-allocate.d.ts +1 -1
- package/dist/account-layer/use-simulate-create-sub-accounts.d.ts +1 -1
- package/dist/account-layer/use-simulate-deallocate.d.ts +1 -1
- package/dist/account-layer/use-simulate-delete-sub-account.d.ts +1 -1
- package/dist/account-layer/use-simulate-deposit-and-allocate.d.ts +1 -1
- package/dist/account-layer/use-simulate-deposit.d.ts +1 -1
- package/dist/account-layer/use-simulate-edit-account-name.d.ts +1 -1
- package/dist/account-layer/use-simulate-remove-margin.d.ts +1 -1
- package/dist/account-layer/use-sub-account-virtual-nonce.d.ts +1 -1
- package/dist/account-layer/use-sub-account.d.ts +1 -1
- package/dist/account-layer/use-sub-accounts-count-of-user.d.ts +1 -1
- package/dist/account-layer/use-user-sub-accounts-addresses.d.ts +1 -1
- package/dist/account-layer/use-user-sub-accounts.d.ts +1 -1
- package/dist/account-layer/use-virtual-account.d.ts +1 -1
- package/dist/account-layer/use-virtual-accounts-addresses-of-sub-account.d.ts +1 -1
- package/dist/balance-history/index.d.ts +3 -3
- package/dist/balance-history/use-balance-history.d.ts +1 -1
- package/dist/balance-history/use-deposit-history.d.ts +1 -1
- package/dist/balance-history/use-withdraw-history.d.ts +1 -1
- package/dist/collateral/index.d.ts +4 -4
- package/dist/collateral/use-approve-collateral.d.ts +2 -2
- package/dist/collateral/use-collateral-allowance.d.ts +1 -1
- package/dist/collateral/use-collateral-balance.d.ts +1 -1
- package/dist/collateral/use-simulate-approve-collateral.d.ts +1 -1
- package/dist/error-codes/index.d.ts +2 -2
- package/dist/error-codes/use-solver-error-codes.d.ts +1 -1
- package/dist/error-codes/use-solver-error-message.d.ts +1 -1
- package/dist/errors/index.d.ts +3 -3
- package/dist/errors/index.js +3 -0
- package/dist/errors/normalize-symm-error.d.ts +1 -1
- package/dist/errors/symmio-request-error.d.ts +1 -1
- package/dist/estimated-price/index.d.ts +2 -0
- package/dist/estimated-price/index.d.ts.map +1 -0
- package/dist/estimated-price/use-debounced-value.d.ts +9 -0
- package/dist/estimated-price/use-debounced-value.d.ts.map +1 -0
- package/dist/estimated-price/use-debounced-value.js +18 -0
- package/dist/estimated-price/use-debounced-value.js.map +1 -0
- package/dist/estimated-price/use-estimated-price.d.ts +46 -0
- package/dist/estimated-price/use-estimated-price.d.ts.map +1 -0
- package/dist/estimated-price/use-estimated-price.js +31 -0
- package/dist/estimated-price/use-estimated-price.js.map +1 -0
- package/dist/fees/index.d.ts +1 -1
- package/dist/fees/index.js +2 -0
- package/dist/fees/use-fee-for-user.d.ts +1 -1
- package/dist/funding-info/index.d.ts +2 -0
- package/dist/funding-info/index.d.ts.map +1 -0
- package/dist/funding-info/use-funding-info.d.ts +25 -0
- package/dist/funding-info/use-funding-info.d.ts.map +1 -0
- package/dist/funding-info/use-funding-info.js +27 -0
- package/dist/funding-info/use-funding-info.js.map +1 -0
- package/dist/index.d.ts +45 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -113
- package/dist/instant-layer/index.d.ts +14 -13
- package/dist/instant-layer/index.d.ts.map +1 -1
- package/dist/instant-layer/index.js +15 -0
- package/dist/instant-layer/use-delegation-expiry.d.ts +1 -1
- package/dist/instant-layer/use-grant-delegation.d.ts +2 -2
- package/dist/instant-layer/use-instant-close-auto.d.ts +1 -1
- package/dist/instant-layer/use-instant-close-bulk-auto.d.ts +1 -1
- package/dist/instant-layer/use-instant-close-bulk.d.ts +1 -1
- package/dist/instant-layer/use-instant-close.d.ts +1 -1
- package/dist/instant-layer/use-instant-closes.d.ts +1 -1
- package/dist/instant-layer/use-instant-open-auto.d.ts +1 -1
- package/dist/instant-layer/use-instant-open-quote-id.d.ts +1 -1
- package/dist/instant-layer/use-instant-open-with-tpsl.d.ts +55 -0
- package/dist/instant-layer/use-instant-open-with-tpsl.d.ts.map +1 -0
- package/dist/instant-layer/use-instant-open-with-tpsl.js +64 -0
- package/dist/instant-layer/use-instant-open-with-tpsl.js.map +1 -0
- package/dist/instant-layer/use-instant-open.d.ts +1 -1
- package/dist/instant-layer/use-instant-opens.d.ts +1 -1
- package/dist/instant-layer/use-is-delegation-active.d.ts +1 -1
- package/dist/instant-layer/use-simulate-grant-delegation.d.ts +1 -1
- package/dist/locked-params/index.d.ts +1 -1
- package/dist/locked-params/use-locked-params.d.ts +1 -1
- package/dist/margin/index.d.ts +2 -0
- package/dist/margin/index.d.ts.map +1 -0
- package/dist/margin/use-available-instant-open-margin.d.ts +51 -0
- package/dist/margin/use-available-instant-open-margin.d.ts.map +1 -0
- package/dist/margin/use-available-instant-open-margin.js +66 -0
- package/dist/margin/use-available-instant-open-margin.js.map +1 -0
- package/dist/market-info/index.d.ts +2 -0
- package/dist/market-info/index.d.ts.map +1 -0
- package/dist/market-info/use-market-info.d.ts +28 -0
- package/dist/market-info/use-market-info.d.ts.map +1 -0
- package/dist/market-info/use-market-info.js +27 -0
- package/dist/market-info/use-market-info.js.map +1 -0
- package/dist/markets/index.d.ts +2 -2
- package/dist/markets/index.js +3 -0
- package/dist/markets/use-markets.d.ts +1 -1
- package/dist/markets/use-onchain-contract-markets.d.ts +1 -1
- package/dist/muon/index.d.ts +10 -10
- package/dist/muon/use-deallocate-upnl-sig.d.ts +1 -1
- package/dist/muon/use-muon-party-a-overview.d.ts +1 -1
- package/dist/muon/use-muon-price-range.d.ts +1 -1
- package/dist/muon/use-muon-price.d.ts +1 -1
- package/dist/muon/use-muon-settle-upnl.d.ts +1 -1
- package/dist/muon/use-muon-upnl-a-with-symbol-price.d.ts +1 -1
- package/dist/muon/use-muon-upnl-a.d.ts +1 -1
- package/dist/muon/use-muon-upnl-b.d.ts +1 -1
- package/dist/muon/use-muon-upnl-with-symbol-price.d.ts +1 -1
- package/dist/muon/use-muon-upnl.d.ts +1 -1
- package/dist/notifications/index.d.ts +1 -1
- package/dist/notifications/use-search-notifications.d.ts +1 -1
- package/dist/notional-cap/index.d.ts +3 -3
- package/dist/notional-cap/use-notional-cap-all.d.ts +1 -1
- package/dist/notional-cap/use-notional-cap-by-symbol-id.d.ts +1 -1
- package/dist/notional-cap/use-open-interest-by-symbol-id.d.ts +1 -1
- package/dist/price-service/index.d.ts +8 -8
- package/dist/price-service/index.js +9 -0
- package/dist/price-service/use-enigma-price-by-market-id.d.ts +1 -1
- package/dist/price-service/use-enigma-price-by-name.d.ts +1 -1
- package/dist/price-service/use-enigma-price-service-health.d.ts +1 -1
- package/dist/price-service/use-enigma-price-service-metadata.d.ts +1 -1
- package/dist/price-service/use-enigma-price-service-prices-by-addresses.d.ts +1 -1
- package/dist/price-service/use-enigma-price-service-prices-by-names.d.ts +1 -1
- package/dist/price-service/use-enigma-price-service-symbols-info.d.ts +1 -1
- package/dist/price-service/use-enigma-prices.d.ts +1 -1
- package/dist/provider/index.d.ts +3 -3
- package/dist/provider/index.js +4 -0
- package/dist/provider/symmio-provider.d.ts +14 -5
- package/dist/provider/symmio-provider.d.ts.map +1 -1
- package/dist/provider/symmio-provider.js +2 -2
- package/dist/provider/symmio-provider.js.map +1 -1
- package/dist/quotes/index.d.ts +15 -15
- package/dist/quotes/use-account-liquidation-price.d.ts +4 -7
- package/dist/quotes/use-account-liquidation-price.d.ts.map +1 -1
- package/dist/quotes/use-account-liquidation-price.js.map +1 -1
- package/dist/quotes/use-grouped-quotes.d.ts +1 -1
- package/dist/quotes/use-managed-quotes.d.ts +1 -1
- package/dist/quotes/use-managed-quotes.d.ts.map +1 -1
- package/dist/quotes/use-managed-quotes.js +131 -128
- package/dist/quotes/use-managed-quotes.js.map +1 -1
- package/dist/quotes/use-party-a-open-positions.d.ts +4 -4
- package/dist/quotes/use-party-a-open-positions.js.map +1 -1
- package/dist/quotes/use-party-a-pending-quotes.d.ts +1 -1
- package/dist/quotes/use-quote-events-by-type.d.ts +1 -1
- package/dist/quotes/use-quote-funding.d.ts +1 -1
- package/dist/quotes/use-quote-history.d.ts +1 -1
- package/dist/quotes/use-quote-price-history.d.ts +1 -1
- package/dist/quotes/use-quote.d.ts +1 -1
- package/dist/quotes/use-quotes-funding.d.ts +1 -1
- package/dist/quotes/use-subgraph-query.d.ts +1 -1
- package/dist/tpsl/index.d.ts +8 -7
- package/dist/tpsl/index.d.ts.map +1 -1
- package/dist/tpsl/tpsl-store.d.ts +84 -0
- package/dist/tpsl/tpsl-store.d.ts.map +1 -0
- package/dist/tpsl/tpsl-store.js +154 -0
- package/dist/tpsl/tpsl-store.js.map +1 -0
- package/dist/tpsl/use-delete-quote-tpsl.d.ts +15 -0
- package/dist/tpsl/use-delete-quote-tpsl.d.ts.map +1 -0
- package/dist/tpsl/use-delete-quote-tpsl.js +31 -0
- package/dist/tpsl/use-delete-quote-tpsl.js.map +1 -0
- package/dist/tpsl/use-quote-tpsl.d.ts +19 -20
- package/dist/tpsl/use-quote-tpsl.d.ts.map +1 -1
- package/dist/tpsl/use-quote-tpsl.js +24 -53
- package/dist/tpsl/use-quote-tpsl.js.map +1 -1
- package/dist/tpsl/use-set-quote-tpsl.d.ts +11 -10
- package/dist/tpsl/use-set-quote-tpsl.d.ts.map +1 -1
- package/dist/tpsl/use-set-quote-tpsl.js +18 -22
- package/dist/tpsl/use-set-quote-tpsl.js.map +1 -1
- package/dist/tpsl/use-tpsl-config.d.ts +1 -1
- package/dist/tpsl/use-tpsl-signing-spec.d.ts +1 -1
- package/dist/tpsl/use-watch-tpsl-notifications.d.ts +1 -1
- package/dist/transactions/index.d.ts +3 -3
- package/dist/transactions/index.js +3 -0
- package/dist/transactions/resolve-write-result.d.ts +1 -1
- package/dist/transfers/index.d.ts +1 -1
- package/dist/transfers/use-transfer-history.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/wallet/index.d.ts +4 -4
- package/dist/wallet/index.js +5 -0
- package/dist/wallet/use-connect-wallet.d.ts +1 -1
- package/dist/wallet/use-switch-to-symmio-chain.d.ts +1 -1
- package/dist/websocket/index.d.ts +1 -1
- package/dist/websocket/is-settle-notification.d.ts +15 -0
- package/dist/websocket/is-settle-notification.d.ts.map +1 -0
- package/dist/websocket/is-settle-notification.js +15 -0
- package/dist/websocket/is-settle-notification.js.map +1 -0
- package/dist/websocket/use-notifications.d.ts +1 -1
- package/dist/withdraw/index.d.ts +10 -10
- package/dist/withdraw/use-finalize-withdraw-request.d.ts +2 -2
- package/dist/withdraw/use-initiate-withdraw.d.ts +2 -2
- package/dist/withdraw/use-last-withdraw-request-id.d.ts +1 -1
- package/dist/withdraw/use-pending-withdraw-requests.d.ts +1 -1
- package/dist/withdraw/use-request-cancel-withdraw.d.ts +2 -2
- package/dist/withdraw/use-simulate-finalize-withdraw-request.d.ts +1 -1
- package/dist/withdraw/use-simulate-initiate-withdraw.d.ts +1 -1
- package/dist/withdraw/use-simulate-request-cancel-withdraw.d.ts +1 -1
- package/dist/withdraw/use-withdraw-requests.d.ts +1 -1
- package/dist/withdraw/use-withdrawable-time.d.ts +1 -1
- package/package.json +11 -10
- package/dist/tpsl/tpsl-confirming.d.ts +0 -36
- package/dist/tpsl/tpsl-confirming.d.ts.map +0 -1
- package/dist/tpsl/tpsl-confirming.js +0 -28
- package/dist/tpsl/tpsl-confirming.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-party-a-open-positions.js","names":[],"sources":["../../src/quotes/use-party-a-open-positions.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getPartyAOpenPositionsQueryOptions,\n type ConfigParameter,\n type GetPartyAOpenPositionsOptions,\n type GetPartyAOpenPositionsReturnType,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\n\n/**\n * Parameters for {@link usePartyAOpenPositions}: the core query options (partyA,\n * pagination, chain id, TanStack `query` overrides) plus an optional `config`.\n */\nexport type UsePartyAOpenPositionsParameters = GetPartyAOpenPositionsOptions & ConfigParameter;\n\n/** Return type of {@link usePartyAOpenPositions}. */\nexport type UsePartyAOpenPositionsReturnType = UseQueryResult<GetPartyAOpenPositionsReturnType, SymmioRequestError>;\n\n/**\n * Read a partyA's open positions (full `Quote` structs) from the SYMMIO core.\n * `partyA` is a
|
|
1
|
+
{"version":3,"file":"use-party-a-open-positions.js","names":[],"sources":["../../src/quotes/use-party-a-open-positions.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getPartyAOpenPositionsQueryOptions,\n type ConfigParameter,\n type GetPartyAOpenPositionsOptions,\n type GetPartyAOpenPositionsReturnType,\n} from \"@symmio/trading-core\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\n\n/**\n * Parameters for {@link usePartyAOpenPositions}: the core query options (partyA,\n * pagination, chain id, TanStack `query` overrides) plus an optional `config`.\n */\nexport type UsePartyAOpenPositionsParameters = GetPartyAOpenPositionsOptions & ConfigParameter;\n\n/** Return type of {@link usePartyAOpenPositions}. */\nexport type UsePartyAOpenPositionsReturnType = UseQueryResult<GetPartyAOpenPositionsReturnType, SymmioRequestError>;\n\n/**\n * Read a partyA's open positions (full `Quote` structs) from the SYMMIO core.\n * `partyA` is a virtual account (lowcap). The query is disabled until `partyA`\n * is set. `chainId` defaults to the connected chain. Errors are normalized to\n * {@link SymmioRequestError}.\n *\n * @example\n * ```tsx\n * const { data: positions, isLoading } = usePartyAOpenPositions({ partyA: \"0xva…\" });\n * ```\n */\nexport function usePartyAOpenPositions(\n parameters: UsePartyAOpenPositionsParameters = {},\n): UsePartyAOpenPositionsReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const options = getPartyAOpenPositionsQueryOptions(config, {\n ...parameters,\n chainId: parameters.chainId ?? chainId,\n });\n\n return useQuery({\n ...options,\n queryFn: async () => {\n try {\n return await options.queryFn();\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n }) as UsePartyAOpenPositionsReturnType;\n}\n"],"mappings":";;;;;;;AAkCA,SAAgB,EACd,IAA+C,CAAC,GACd;CAClC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAU,EAAmC,GAAQ;EACzD,GAAG;EACH,SAAS,EAAW,WAAW;CACjC,CAAC;CAED,OAAO,EAAS;EACd,GAAG;EACH,SAAS,YAAY;GACnB,IAAI;IACF,OAAO,MAAM,EAAQ,QAAQ;GAC/B,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;CACF,CAAC;AACH"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigParameter, GetPartyAPendingQuotesOptions, GetPartyAPendingQuotesReturnType } from '@symmio/trading-core';
|
|
2
2
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
4
|
/**
|
|
5
5
|
* Parameters for {@link usePartyAPendingQuotes}: the core query options (partyA,
|
|
6
6
|
* chain id, TanStack `query` overrides) plus an optional `config`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigParameter, GetQuoteEventsByTypeOptions, GetQuoteEventsByTypeReturnType } from '@symmio/trading-core';
|
|
2
2
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
4
|
/**
|
|
5
5
|
* Parameters for {@link useQuoteEventsByType}: the core query options (quote id,
|
|
6
6
|
* types, paging, sort, chain id, TanStack `query` overrides) plus an optional
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConfigParameter, QuoteFundingData } from '@symmio/trading-core';
|
|
2
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
2
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parameters for {@link useQuoteFunding}.
|
|
5
5
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigParameter, GetQuoteHistoryOptions, GetQuoteHistoryReturnType } from '@symmio/trading-core';
|
|
2
2
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
4
|
/**
|
|
5
5
|
* Parameters for {@link useQuoteHistory}: the core query options (subAccounts,
|
|
6
6
|
* close type, paging, time range, chain id, TanStack `query` overrides) plus an
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConfigParameter } from '@symmio/trading-core';
|
|
2
|
-
import { UseQuoteEventsByTypeParameters, UseQuoteEventsByTypeReturnType } from './use-quote-events-by-type';
|
|
2
|
+
import { UseQuoteEventsByTypeParameters, UseQuoteEventsByTypeReturnType } from './use-quote-events-by-type.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parameters for {@link useQuotePriceHistory}. Same as {@link useQuoteEventsByType}
|
|
5
5
|
* minus the `types` field (preset to {@link PRICE_HISTORY_EVENT_TYPES}).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigParameter, GetQuoteOptions, GetQuoteReturnType } from '@symmio/trading-core';
|
|
2
2
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
4
|
/**
|
|
5
5
|
* Parameters for {@link useQuote}: the core query options (quote id, chain id,
|
|
6
6
|
* TanStack `query` overrides) plus an optional `config`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConfigParameter, GetQuoteFundingOptions, QuoteFundingData } from '@symmio/trading-core';
|
|
2
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
2
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
3
3
|
/** Minimum quote shape `useQuotesFunding` needs: just the on-chain id. */
|
|
4
4
|
export interface QuotesFundingInputQuote {
|
|
5
5
|
/** On-chain quote id. Off-chain (pending) rows pass `undefined` and are skipped. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigParameter, QuerySubgraphOptions } from '@symmio/trading-core';
|
|
2
2
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
4
|
/**
|
|
5
5
|
* Parameters for {@link useSubgraphQuery}: the raw-GraphQL query options
|
|
6
6
|
* (document, variables, optional subgraph/chain id, TanStack `query` overrides)
|
package/dist/tpsl/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export * from './to-quote-tpsl';
|
|
2
|
-
export * from './tpsl-
|
|
3
|
-
export * from './use-quote-tpsl';
|
|
4
|
-
export * from './use-
|
|
5
|
-
export * from './use-tpsl
|
|
6
|
-
export * from './use-tpsl-
|
|
7
|
-
export * from './use-
|
|
1
|
+
export * from './to-quote-tpsl.js';
|
|
2
|
+
export * from './tpsl-store.js';
|
|
3
|
+
export * from './use-delete-quote-tpsl.js';
|
|
4
|
+
export * from './use-quote-tpsl.js';
|
|
5
|
+
export * from './use-set-quote-tpsl.js';
|
|
6
|
+
export * from './use-tpsl-config.js';
|
|
7
|
+
export * from './use-tpsl-signing-spec.js';
|
|
8
|
+
export * from './use-watch-tpsl-notifications.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/tpsl/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tpsl/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tpsl/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { QuoteTpSlRow, TpSlInfoState, TpSlNotification, TpSlPriceType } from '@symmio/trading-core';
|
|
2
|
+
/**
|
|
3
|
+
* One quote's folded TP/SL state. The same record instance is referenced from
|
|
4
|
+
* every id that resolves to it via {@link TpSlStoreState.index} — the caller
|
|
5
|
+
* can pass either the on-chain `quoteId` or the hedger `tempQuoteId` and get
|
|
6
|
+
* the same record back.
|
|
7
|
+
*
|
|
8
|
+
* `tpState` / `slState` is the single source of truth for how a side is
|
|
9
|
+
* rendered — including the transient `"confirming"` phase between a POST
|
|
10
|
+
* accepting and the WS report landing. No separate overlay field.
|
|
11
|
+
*/
|
|
12
|
+
export interface TpSlRecord {
|
|
13
|
+
/** On-chain quote id — set once the quote anchors. */
|
|
14
|
+
quoteId?: bigint;
|
|
15
|
+
/** Hedger `tempQuoteId` — set during the pre-chain window. */
|
|
16
|
+
tempQuoteId?: bigint;
|
|
17
|
+
tp: string;
|
|
18
|
+
sl: string;
|
|
19
|
+
tpOpenPrice: string;
|
|
20
|
+
slOpenPrice: string;
|
|
21
|
+
tpPriceType: TpSlPriceType;
|
|
22
|
+
slPriceType: TpSlPriceType;
|
|
23
|
+
tpState: TpSlInfoState;
|
|
24
|
+
slState: TpSlInfoState;
|
|
25
|
+
tpCohQuoteId?: string;
|
|
26
|
+
slCohQuoteId?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Internal identity of a record — opaque string, never leaks to consumers. */
|
|
29
|
+
type TpSlRecordKey = string;
|
|
30
|
+
/**
|
|
31
|
+
* Zustand store shape. `records` holds one entry per quote; `index` maps every
|
|
32
|
+
* id we've ever seen for that quote — on-chain and temp — to the same
|
|
33
|
+
* `records` key.
|
|
34
|
+
*/
|
|
35
|
+
export interface TpSlStoreState {
|
|
36
|
+
records: Map<TpSlRecordKey, TpSlRecord>;
|
|
37
|
+
index: Map<bigint, TpSlRecordKey>;
|
|
38
|
+
/** Read a record via any id. Returns `undefined` when the id is unknown. */
|
|
39
|
+
get(id: bigint): TpSlRecord | undefined;
|
|
40
|
+
/** Fold the raw handler rows into snapshot fields and commit under `id`. */
|
|
41
|
+
setRows(id: bigint, rows: QuoteTpSlRow[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* Mark a side as "POST accepted, awaiting handler acknowledgement". Sets
|
|
44
|
+
* `tpState` / `slState` to `"confirming"` directly. Optional `patch`
|
|
45
|
+
* seeds the trigger price / priceType / cohQuoteId so the UI can show
|
|
46
|
+
* the target value during the confirming window; a later
|
|
47
|
+
* {@link applyNotification} transitions the state to the wire report.
|
|
48
|
+
*/
|
|
49
|
+
markConfirming(id: bigint, side: "tp" | "sl", patch?: {
|
|
50
|
+
price?: string;
|
|
51
|
+
priceType?: TpSlPriceType;
|
|
52
|
+
cohQuoteId?: string;
|
|
53
|
+
}): void;
|
|
54
|
+
/**
|
|
55
|
+
* Apply a WS notification to the record's side state (and optionally its
|
|
56
|
+
* trigger price when `details.trigger_price` is present). Maps the raw
|
|
57
|
+
* notification state onto {@link TpSlInfoState}. Failure frames
|
|
58
|
+
* (`successful: false`) are ignored — the confirming state remains until
|
|
59
|
+
* the next successful frame or REST fetch resolves it.
|
|
60
|
+
*/
|
|
61
|
+
applyNotification(id: bigint, notification: TpSlNotification): void;
|
|
62
|
+
/**
|
|
63
|
+
* Declare that two ids refer to the same TP/SL record — typically called
|
|
64
|
+
* when the quote reconciliation layer learns a `tempQuoteId ↔ quoteId`
|
|
65
|
+
* pairing from a solver notification.
|
|
66
|
+
*/
|
|
67
|
+
link(a: bigint, b: bigint): void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Module-level Zustand store for the folded TP/SL snapshot per quote. Single
|
|
71
|
+
* instance across the app is intentional (see AGENTS.md — "TP/SL data live in
|
|
72
|
+
* one place"); tests can call {@link __resetTpSlStore} between runs to reset.
|
|
73
|
+
*/
|
|
74
|
+
export declare const useTpSlStore: import('zustand').UseBoundStore<import('zustand').StoreApi<TpSlStoreState>>;
|
|
75
|
+
/**
|
|
76
|
+
* Selector hook: subscribe to the record addressed by `id`. Returns
|
|
77
|
+
* `undefined` until a row set or mutation has landed for that id (or for
|
|
78
|
+
* another id linked to the same record).
|
|
79
|
+
*/
|
|
80
|
+
export declare function useTpSlRecord(id: bigint | undefined): TpSlRecord | undefined;
|
|
81
|
+
/** Reset the store — intended for tests only. */
|
|
82
|
+
export declare function __resetTpSlStore(): void;
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=tpsl-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tpsl-store.d.ts","sourceRoot":"","sources":["../../src/tpsl/tpsl-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAEZ,aAAa,EACb,gBAAgB,EAChB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAI9B;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACzB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,aAAa,CAAC;IAC3B,WAAW,EAAE,aAAa,CAAC;IAC3B,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,+EAA+E;AAC/E,KAAK,aAAa,GAAG,MAAM,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IACxC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAElC,4EAA4E;IAC5E,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IAExC,4EAA4E;IAC5E,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAEhD;;;;;;OAMG;IACH,cAAc,CACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,aAAa,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GACzE,IAAI,CAAC;IAER;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAEpE;;;;OAIG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAoCD;;;;GAIG;AACH,eAAO,MAAM,YAAY,6EA4LvB,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAM5E;AAED,iDAAiD;AACjD,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { toQuoteTpSl as e } from "./to-quote-tpsl.js";
|
|
3
|
+
import { create as t } from "zustand";
|
|
4
|
+
//#region src/tpsl/tpsl-store.ts
|
|
5
|
+
function n() {
|
|
6
|
+
return {
|
|
7
|
+
tp: "",
|
|
8
|
+
sl: "",
|
|
9
|
+
tpOpenPrice: "",
|
|
10
|
+
slOpenPrice: "",
|
|
11
|
+
tpPriceType: "markPrice",
|
|
12
|
+
slPriceType: "markPrice",
|
|
13
|
+
tpState: "canceled",
|
|
14
|
+
slState: "canceled"
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function r(e) {
|
|
18
|
+
switch (e) {
|
|
19
|
+
case "new":
|
|
20
|
+
case "edit": return "new";
|
|
21
|
+
case "pending": return "pending";
|
|
22
|
+
case "triggered":
|
|
23
|
+
case "trigger": return "triggered";
|
|
24
|
+
case "cancel":
|
|
25
|
+
case "canceled":
|
|
26
|
+
case "cancelled":
|
|
27
|
+
case "close": return "canceled";
|
|
28
|
+
default: return "new";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var i = t((t, i) => {
|
|
32
|
+
let a = 0;
|
|
33
|
+
function o() {
|
|
34
|
+
return a += 1, `r${a}`;
|
|
35
|
+
}
|
|
36
|
+
function s(e, r) {
|
|
37
|
+
t((t) => {
|
|
38
|
+
let i = new Map(t.records), a = new Map(t.index), s = a.get(e), c;
|
|
39
|
+
s === void 0 ? (s = o(), c = n(), a.set(e, s)) : c = i.get(s) ?? n();
|
|
40
|
+
let l = r(c);
|
|
41
|
+
return e < 0n ? l.tempQuoteId ??= e : l.quoteId ??= e, i.set(s, l), {
|
|
42
|
+
records: i,
|
|
43
|
+
index: a
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
records: /* @__PURE__ */ new Map(),
|
|
49
|
+
index: /* @__PURE__ */ new Map(),
|
|
50
|
+
get(e) {
|
|
51
|
+
let t = i(), n = t.index.get(e);
|
|
52
|
+
return n === void 0 ? void 0 : t.records.get(n);
|
|
53
|
+
},
|
|
54
|
+
setRows(t, n) {
|
|
55
|
+
let r = e(n), a = n.find((e) => e.quote_id && e.quote_id !== 0)?.quote_id;
|
|
56
|
+
if (s(t, (e) => ({
|
|
57
|
+
...e,
|
|
58
|
+
...r
|
|
59
|
+
})), a !== void 0) {
|
|
60
|
+
let e = BigInt(a);
|
|
61
|
+
e !== t && i().link(t, e);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
markConfirming(e, t, n) {
|
|
65
|
+
s(e, (e) => {
|
|
66
|
+
let r = { ...e };
|
|
67
|
+
return t === "tp" ? (r.tpState = "confirming", n?.price !== void 0 && (r.tp = n.price), n?.priceType !== void 0 && (r.tpPriceType = n.priceType), n?.cohQuoteId !== void 0 && (r.tpCohQuoteId = n.cohQuoteId)) : (r.slState = "confirming", n?.price !== void 0 && (r.sl = n.price), n?.priceType !== void 0 && (r.slPriceType = n.priceType), n?.cohQuoteId !== void 0 && (r.slCohQuoteId = n.cohQuoteId)), r;
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
applyNotification(e, t) {
|
|
71
|
+
if (!t.successful) return;
|
|
72
|
+
let n = t.conditionalOrderType === "take_profit" ? "tp" : t.conditionalOrderType === "stop_loss" ? "sl" : null;
|
|
73
|
+
if (!n) return;
|
|
74
|
+
let i = r(t.state), a = t.details?.trigger_price;
|
|
75
|
+
s(e, (e) => {
|
|
76
|
+
let r = { ...e };
|
|
77
|
+
return n === "tp" ? (r.tpState = i, i === "canceled" ? (r.tp = "", r.tpOpenPrice = "", r.tpCohQuoteId = void 0) : (a !== void 0 && (r.tp = String(a)), t.cohQuoteId && (r.tpCohQuoteId = t.cohQuoteId))) : (r.slState = i, i === "canceled" ? (r.sl = "", r.slOpenPrice = "", r.slCohQuoteId = void 0) : (a !== void 0 && (r.sl = String(a)), t.cohQuoteId && (r.slCohQuoteId = t.cohQuoteId))), r;
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
link(e, r) {
|
|
81
|
+
e !== r && t((t) => {
|
|
82
|
+
let i = new Map(t.records), a = new Map(t.index), s = a.get(e), c = a.get(r);
|
|
83
|
+
if (s === void 0 && c === void 0) {
|
|
84
|
+
let t = o(), s = n();
|
|
85
|
+
return e < 0n ? s.tempQuoteId = e : s.quoteId = e, r < 0n ? s.tempQuoteId ??= r : s.quoteId ??= r, i.set(t, s), a.set(e, t), a.set(r, t), {
|
|
86
|
+
records: i,
|
|
87
|
+
index: a
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (s !== void 0 && c === void 0) {
|
|
91
|
+
a.set(r, s);
|
|
92
|
+
let e = i.get(s);
|
|
93
|
+
if (e) {
|
|
94
|
+
let t = { ...e };
|
|
95
|
+
r < 0n ? t.tempQuoteId ??= r : t.quoteId ??= r, i.set(s, t);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
records: i,
|
|
99
|
+
index: a
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (s === void 0 && c !== void 0) {
|
|
103
|
+
a.set(e, c);
|
|
104
|
+
let t = i.get(c);
|
|
105
|
+
if (t) {
|
|
106
|
+
let n = { ...t };
|
|
107
|
+
e < 0n ? n.tempQuoteId ??= e : n.quoteId ??= e, i.set(c, n);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
records: i,
|
|
111
|
+
index: a
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (s === c) return t;
|
|
115
|
+
let l = i.get(s) ?? n(), u = i.get(c) ?? n(), d = {
|
|
116
|
+
...l,
|
|
117
|
+
quoteId: l.quoteId ?? u.quoteId,
|
|
118
|
+
tempQuoteId: l.tempQuoteId ?? u.tempQuoteId,
|
|
119
|
+
...l.tpState === "canceled" && u.tpState !== "canceled" ? {
|
|
120
|
+
tp: u.tp,
|
|
121
|
+
tpOpenPrice: u.tpOpenPrice,
|
|
122
|
+
tpPriceType: u.tpPriceType,
|
|
123
|
+
tpState: u.tpState,
|
|
124
|
+
tpCohQuoteId: u.tpCohQuoteId
|
|
125
|
+
} : {},
|
|
126
|
+
...l.slState === "canceled" && u.slState !== "canceled" ? {
|
|
127
|
+
sl: u.sl,
|
|
128
|
+
slOpenPrice: u.slOpenPrice,
|
|
129
|
+
slPriceType: u.slPriceType,
|
|
130
|
+
slState: u.slState,
|
|
131
|
+
slCohQuoteId: u.slCohQuoteId
|
|
132
|
+
} : {}
|
|
133
|
+
};
|
|
134
|
+
i.set(s, d), i.delete(c);
|
|
135
|
+
for (let [e, t] of a) t === c && a.set(e, s);
|
|
136
|
+
return {
|
|
137
|
+
records: i,
|
|
138
|
+
index: a
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
function a(e) {
|
|
145
|
+
return i((t) => {
|
|
146
|
+
if (e === void 0) return;
|
|
147
|
+
let n = t.index.get(e);
|
|
148
|
+
return n === void 0 ? void 0 : t.records.get(n);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { a as useTpSlRecord, i as useTpSlStore };
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=tpsl-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tpsl-store.js","names":[],"sources":["../../src/tpsl/tpsl-store.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n QuoteTpSlRow,\n RawTpSlNotificationState,\n TpSlInfoState,\n TpSlNotification,\n TpSlPriceType,\n} from \"@symmio/trading-core\";\nimport { create } from \"zustand\";\nimport { toQuoteTpSl } from \"./to-quote-tpsl\";\n\n/**\n * One quote's folded TP/SL state. The same record instance is referenced from\n * every id that resolves to it via {@link TpSlStoreState.index} — the caller\n * can pass either the on-chain `quoteId` or the hedger `tempQuoteId` and get\n * the same record back.\n *\n * `tpState` / `slState` is the single source of truth for how a side is\n * rendered — including the transient `\"confirming\"` phase between a POST\n * accepting and the WS report landing. No separate overlay field.\n */\nexport interface TpSlRecord {\n /** On-chain quote id — set once the quote anchors. */\n quoteId?: bigint;\n /** Hedger `tempQuoteId` — set during the pre-chain window. */\n tempQuoteId?: bigint;\n\n tp: string;\n sl: string;\n tpOpenPrice: string;\n slOpenPrice: string;\n tpPriceType: TpSlPriceType;\n slPriceType: TpSlPriceType;\n tpState: TpSlInfoState;\n slState: TpSlInfoState;\n tpCohQuoteId?: string;\n slCohQuoteId?: string;\n}\n\n/** Internal identity of a record — opaque string, never leaks to consumers. */\ntype TpSlRecordKey = string;\n\n/**\n * Zustand store shape. `records` holds one entry per quote; `index` maps every\n * id we've ever seen for that quote — on-chain and temp — to the same\n * `records` key.\n */\nexport interface TpSlStoreState {\n records: Map<TpSlRecordKey, TpSlRecord>;\n index: Map<bigint, TpSlRecordKey>;\n\n /** Read a record via any id. Returns `undefined` when the id is unknown. */\n get(id: bigint): TpSlRecord | undefined;\n\n /** Fold the raw handler rows into snapshot fields and commit under `id`. */\n setRows(id: bigint, rows: QuoteTpSlRow[]): void;\n\n /**\n * Mark a side as \"POST accepted, awaiting handler acknowledgement\". Sets\n * `tpState` / `slState` to `\"confirming\"` directly. Optional `patch`\n * seeds the trigger price / priceType / cohQuoteId so the UI can show\n * the target value during the confirming window; a later\n * {@link applyNotification} transitions the state to the wire report.\n */\n markConfirming(\n id: bigint,\n side: \"tp\" | \"sl\",\n patch?: { price?: string; priceType?: TpSlPriceType; cohQuoteId?: string },\n ): void;\n\n /**\n * Apply a WS notification to the record's side state (and optionally its\n * trigger price when `details.trigger_price` is present). Maps the raw\n * notification state onto {@link TpSlInfoState}. Failure frames\n * (`successful: false`) are ignored — the confirming state remains until\n * the next successful frame or REST fetch resolves it.\n */\n applyNotification(id: bigint, notification: TpSlNotification): void;\n\n /**\n * Declare that two ids refer to the same TP/SL record — typically called\n * when the quote reconciliation layer learns a `tempQuoteId ↔ quoteId`\n * pairing from a solver notification.\n */\n link(a: bigint, b: bigint): void;\n}\n\nfunction blank(): TpSlRecord {\n return {\n tp: \"\",\n sl: \"\",\n tpOpenPrice: \"\",\n slOpenPrice: \"\",\n tpPriceType: \"markPrice\",\n slPriceType: \"markPrice\",\n tpState: \"canceled\",\n slState: \"canceled\",\n };\n}\n\n/** Map the WS notification state onto {@link TpSlInfoState}. */\nfunction mapNotificationState(state: RawTpSlNotificationState): TpSlInfoState {\n switch (state) {\n case \"new\":\n case \"edit\":\n return \"new\";\n case \"pending\":\n return \"pending\";\n case \"triggered\":\n case \"trigger\":\n return \"triggered\";\n case \"cancel\":\n case \"canceled\":\n case \"cancelled\":\n case \"close\":\n return \"canceled\";\n default:\n return \"new\";\n }\n}\n\n/**\n * Module-level Zustand store for the folded TP/SL snapshot per quote. Single\n * instance across the app is intentional (see AGENTS.md — \"TP/SL data live in\n * one place\"); tests can call {@link __resetTpSlStore} between runs to reset.\n */\nexport const useTpSlStore = create<TpSlStoreState>((set, get) => {\n let keyCounter = 0;\n function newKey(): TpSlRecordKey {\n keyCounter += 1;\n return `r${keyCounter}`;\n }\n\n function upsert(id: bigint, mutator: (prev: TpSlRecord) => TpSlRecord): void {\n set((state) => {\n const records = new Map(state.records);\n const index = new Map(state.index);\n let key = index.get(id);\n let prev: TpSlRecord;\n if (key === undefined) {\n key = newKey();\n prev = blank();\n index.set(id, key);\n } else {\n prev = records.get(key) ?? blank();\n }\n const next = mutator(prev);\n if (id < 0n) {\n next.tempQuoteId ??= id;\n } else {\n next.quoteId ??= id;\n }\n records.set(key, next);\n return { records, index };\n });\n }\n\n return {\n records: new Map(),\n index: new Map(),\n\n get(id) {\n const state = get();\n const key = state.index.get(id);\n return key === undefined ? undefined : state.records.get(key);\n },\n\n setRows(id, rows) {\n const folded = toQuoteTpSl(rows);\n const rowQuoteId = rows.find((r) => r.quote_id && r.quote_id !== 0)?.quote_id;\n upsert(id, (prev) => ({ ...prev, ...folded }));\n if (rowQuoteId !== undefined) {\n const rowId = BigInt(rowQuoteId);\n if (rowId !== id) get().link(id, rowId);\n }\n },\n\n markConfirming(id, side, patch) {\n upsert(id, (prev) => {\n const next: TpSlRecord = { ...prev };\n if (side === \"tp\") {\n next.tpState = \"confirming\";\n if (patch?.price !== undefined) next.tp = patch.price;\n if (patch?.priceType !== undefined) next.tpPriceType = patch.priceType;\n if (patch?.cohQuoteId !== undefined) next.tpCohQuoteId = patch.cohQuoteId;\n } else {\n next.slState = \"confirming\";\n if (patch?.price !== undefined) next.sl = patch.price;\n if (patch?.priceType !== undefined) next.slPriceType = patch.priceType;\n if (patch?.cohQuoteId !== undefined) next.slCohQuoteId = patch.cohQuoteId;\n }\n return next;\n });\n },\n\n applyNotification(id, notification) {\n if (!notification.successful) return;\n const side =\n notification.conditionalOrderType === \"take_profit\"\n ? \"tp\"\n : notification.conditionalOrderType === \"stop_loss\"\n ? \"sl\"\n : null;\n if (!side) return;\n const nextState = mapNotificationState(notification.state);\n const trigger = notification.details?.trigger_price;\n upsert(id, (prev) => {\n const next: TpSlRecord = { ...prev };\n if (side === \"tp\") {\n next.tpState = nextState;\n if (nextState === \"canceled\") {\n next.tp = \"\";\n next.tpOpenPrice = \"\";\n next.tpCohQuoteId = undefined;\n } else {\n if (trigger !== undefined) next.tp = String(trigger);\n if (notification.cohQuoteId) next.tpCohQuoteId = notification.cohQuoteId;\n }\n } else {\n next.slState = nextState;\n if (nextState === \"canceled\") {\n next.sl = \"\";\n next.slOpenPrice = \"\";\n next.slCohQuoteId = undefined;\n } else {\n if (trigger !== undefined) next.sl = String(trigger);\n if (notification.cohQuoteId) next.slCohQuoteId = notification.cohQuoteId;\n }\n }\n return next;\n });\n },\n\n link(a, b) {\n if (a === b) return;\n set((state) => {\n const records = new Map(state.records);\n const index = new Map(state.index);\n const keyA = index.get(a);\n const keyB = index.get(b);\n\n if (keyA === undefined && keyB === undefined) {\n const key = newKey();\n const record = blank();\n if (a < 0n) record.tempQuoteId = a;\n else record.quoteId = a;\n if (b < 0n) record.tempQuoteId ??= b;\n else record.quoteId ??= b;\n records.set(key, record);\n index.set(a, key);\n index.set(b, key);\n return { records, index };\n }\n\n if (keyA !== undefined && keyB === undefined) {\n index.set(b, keyA);\n const prev = records.get(keyA);\n if (prev) {\n const next: TpSlRecord = { ...prev };\n if (b < 0n) next.tempQuoteId ??= b;\n else next.quoteId ??= b;\n records.set(keyA, next);\n }\n return { records, index };\n }\n\n if (keyA === undefined && keyB !== undefined) {\n index.set(a, keyB);\n const prev = records.get(keyB);\n if (prev) {\n const next: TpSlRecord = { ...prev };\n if (a < 0n) next.tempQuoteId ??= a;\n else next.quoteId ??= a;\n records.set(keyB, next);\n }\n return { records, index };\n }\n\n if (keyA === keyB) return state;\n\n const recordA = records.get(keyA!) ?? blank();\n const recordB = records.get(keyB!) ?? blank();\n const merged: TpSlRecord = {\n ...recordA,\n quoteId: recordA.quoteId ?? recordB.quoteId,\n tempQuoteId: recordA.tempQuoteId ?? recordB.tempQuoteId,\n ...(recordA.tpState === \"canceled\" && recordB.tpState !== \"canceled\"\n ? {\n tp: recordB.tp,\n tpOpenPrice: recordB.tpOpenPrice,\n tpPriceType: recordB.tpPriceType,\n tpState: recordB.tpState,\n tpCohQuoteId: recordB.tpCohQuoteId,\n }\n : {}),\n ...(recordA.slState === \"canceled\" && recordB.slState !== \"canceled\"\n ? {\n sl: recordB.sl,\n slOpenPrice: recordB.slOpenPrice,\n slPriceType: recordB.slPriceType,\n slState: recordB.slState,\n slCohQuoteId: recordB.slCohQuoteId,\n }\n : {}),\n };\n records.set(keyA!, merged);\n records.delete(keyB!);\n for (const [id, k] of index) {\n if (k === keyB) index.set(id, keyA!);\n }\n return { records, index };\n });\n },\n };\n});\n\n/**\n * Selector hook: subscribe to the record addressed by `id`. Returns\n * `undefined` until a row set or mutation has landed for that id (or for\n * another id linked to the same record).\n */\nexport function useTpSlRecord(id: bigint | undefined): TpSlRecord | undefined {\n return useTpSlStore((state) => {\n if (id === undefined) return undefined;\n const key = state.index.get(id);\n return key === undefined ? undefined : state.records.get(key);\n });\n}\n\n/** Reset the store — intended for tests only. */\nexport function __resetTpSlStore(): void {\n useTpSlStore.setState({ records: new Map(), index: new Map() });\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigParameter, DeleteQuoteTpSlParameters, DeleteQuoteTpSlReturnType } from '@symmio/trading-core';
|
|
2
|
+
import { UseMutationResult } from '@tanstack/react-query';
|
|
3
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
4
|
+
/** Parameters for {@link useDeleteQuoteTpSl}. */
|
|
5
|
+
export type UseDeleteQuoteTpSlParameters = ConfigParameter;
|
|
6
|
+
/** Return type of {@link useDeleteQuoteTpSl}. */
|
|
7
|
+
export type UseDeleteQuoteTpSlReturnType = UseMutationResult<DeleteQuoteTpSlReturnType, SymmioRequestError, DeleteQuoteTpSlParameters>;
|
|
8
|
+
/**
|
|
9
|
+
* Cancel a live TP or SL by its `cohQuoteId`. Signs an EIP-712 delete message
|
|
10
|
+
* with the session-key wallet and calls `DELETE /api/v5/`. On 200 the target
|
|
11
|
+
* side is marked `"confirming"` in the shared TP/SL store; the WS `cancel`
|
|
12
|
+
* report flips it to `"canceled"` via `applyNotification`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useDeleteQuoteTpSl(parameters?: UseDeleteQuoteTpSlParameters): UseDeleteQuoteTpSlReturnType;
|
|
15
|
+
//# sourceMappingURL=use-delete-quote-tpsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-delete-quote-tpsl.d.ts","sourceRoot":"","sources":["../../src/tpsl/use-delete-quote-tpsl.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAKzE,iDAAiD;AACjD,MAAM,MAAM,4BAA4B,GAAG,eAAe,CAAC;AAE3D,iDAAiD;AACjD,MAAM,MAAM,4BAA4B,GAAG,iBAAiB,CAC1D,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,CAC1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,GAAE,4BAAiC,GAAG,4BAA4B,CAoB9G"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSymmioChainId as e } from "../provider/use-symmio-chain-id.js";
|
|
3
|
+
import { useSymmioConfig as t } from "../provider/use-symmio-config.js";
|
|
4
|
+
import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
5
|
+
import { useTpSlStore as r } from "./tpsl-store.js";
|
|
6
|
+
import { deleteQuoteTpSlMutationOptions as i } from "@symmio/trading-core";
|
|
7
|
+
import { useMutation as a } from "@tanstack/react-query";
|
|
8
|
+
//#region src/tpsl/use-delete-quote-tpsl.ts
|
|
9
|
+
function o(o = {}) {
|
|
10
|
+
let s = t(o), c = e(), l = i(s), u = r((e) => e.markConfirming);
|
|
11
|
+
return a({
|
|
12
|
+
mutationKey: l.mutationKey,
|
|
13
|
+
mutationFn: async (e) => {
|
|
14
|
+
try {
|
|
15
|
+
return await l.mutationFn({
|
|
16
|
+
...e,
|
|
17
|
+
chainId: e.chainId ?? c
|
|
18
|
+
});
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw n(e);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
onSuccess: (e, t) => {
|
|
24
|
+
t.conditionalOrderType === "take_profit" && u(t.quoteId, "tp"), t.conditionalOrderType === "stop_loss" && u(t.quoteId, "sl");
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { o as useDeleteQuoteTpSl };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=use-delete-quote-tpsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-delete-quote-tpsl.js","names":[],"sources":["../../src/tpsl/use-delete-quote-tpsl.ts"],"sourcesContent":["\"use client\";\n\nimport {\n deleteQuoteTpSlMutationOptions,\n type ConfigParameter,\n type DeleteQuoteTpSlParameters,\n type DeleteQuoteTpSlReturnType,\n} from \"@symmio/trading-core\";\nimport { useMutation, type UseMutationResult } from \"@tanstack/react-query\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { useTpSlStore } from \"./tpsl-store\";\n\n/** Parameters for {@link useDeleteQuoteTpSl}. */\nexport type UseDeleteQuoteTpSlParameters = ConfigParameter;\n\n/** Return type of {@link useDeleteQuoteTpSl}. */\nexport type UseDeleteQuoteTpSlReturnType = UseMutationResult<\n DeleteQuoteTpSlReturnType,\n SymmioRequestError,\n DeleteQuoteTpSlParameters\n>;\n\n/**\n * Cancel a live TP or SL by its `cohQuoteId`. Signs an EIP-712 delete message\n * with the session-key wallet and calls `DELETE /api/v5/`. On 200 the target\n * side is marked `\"confirming\"` in the shared TP/SL store; the WS `cancel`\n * report flips it to `\"canceled\"` via `applyNotification`.\n */\nexport function useDeleteQuoteTpSl(parameters: UseDeleteQuoteTpSlParameters = {}): UseDeleteQuoteTpSlReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const base = deleteQuoteTpSlMutationOptions(config);\n const markConfirming = useTpSlStore((state) => state.markConfirming);\n\n return useMutation<DeleteQuoteTpSlReturnType, SymmioRequestError, DeleteQuoteTpSlParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n return await base.mutationFn({ ...variables, chainId: variables.chainId ?? chainId });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n if (variables.conditionalOrderType === \"take_profit\") markConfirming(variables.quoteId, \"tp\");\n if (variables.conditionalOrderType === \"stop_loss\") markConfirming(variables.quoteId, \"sl\");\n },\n });\n}\n"],"mappings":";;;;;;;;AA+BA,SAAgB,EAAmB,IAA2C,CAAC,GAAiC;CAC9G,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAO,EAA+B,CAAM,GAC5C,IAAiB,GAAc,MAAU,EAAM,cAAc;CAEnE,OAAO,EAAsF;EAC3F,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,OAAO,MAAM,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS,EAAU,WAAW;IAAQ,CAAC;GACtF,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GAEjC,AADI,EAAU,yBAAyB,iBAAe,EAAe,EAAU,SAAS,IAAI,GACxF,EAAU,yBAAyB,eAAa,EAAe,EAAU,SAAS,IAAI;EAC5F;CACF,CAAC;AACH"}
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { ConfigParameter, GetQuoteTpSlOptions
|
|
1
|
+
import { ConfigParameter, GetQuoteTpSlOptions } from '@symmio/trading-core';
|
|
2
2
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { Address } from 'viem';
|
|
4
|
-
import { SymmioRequestError } from '../errors/symmio-request-error';
|
|
4
|
+
import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
5
|
+
import { TpSlRecord } from './tpsl-store.js';
|
|
5
6
|
/** Parameters for {@link useQuoteTpSl}. */
|
|
6
|
-
export type UseQuoteTpSlParameters = GetQuoteTpSlOptions & ConfigParameter & {
|
|
7
|
+
export type UseQuoteTpSlParameters = Omit<GetQuoteTpSlOptions, "quoteId"> & ConfigParameter & {
|
|
8
|
+
/**
|
|
9
|
+
* Quote id — accepts either the on-chain `quoteId` or the hedger
|
|
10
|
+
* `tempQuoteId`. Whichever is passed, the hook resolves to the same
|
|
11
|
+
* shared record via the store's id index.
|
|
12
|
+
*/
|
|
13
|
+
quoteId: bigint;
|
|
7
14
|
/**
|
|
8
15
|
* SubAccount address — when provided, the hook also subscribes to the
|
|
9
|
-
* TP/SL WebSocket and reconciles the
|
|
10
|
-
* without manual polling. Omit to skip WS (REST-only).
|
|
16
|
+
* TP/SL WebSocket and reconciles the record without manual polling.
|
|
11
17
|
*/
|
|
12
18
|
account?: Address;
|
|
13
19
|
};
|
|
14
20
|
/** Return type of {@link useQuoteTpSl}. */
|
|
15
|
-
export type UseQuoteTpSlReturnType = UseQueryResult<
|
|
16
|
-
/** The unfiltered conditional-order rows returned by the handler. */
|
|
17
|
-
rows: QuoteTpSlRow[] | undefined;
|
|
18
|
-
};
|
|
21
|
+
export type UseQuoteTpSlReturnType = UseQueryResult<TpSlRecord, SymmioRequestError>;
|
|
19
22
|
/**
|
|
20
|
-
* Read the TP/SL snapshot for one on-chain
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* {@link QuoteTpSl} via {@link toQuoteTpSl}.
|
|
23
|
+
* Read the folded TP/SL snapshot for one quote. Pass either the on-chain
|
|
24
|
+
* `quoteId` or the hedger `tempQuoteId` — the store keeps a single record per
|
|
25
|
+
* quote indexed under every id it has learned for that quote, so both callers
|
|
26
|
+
* get the same object.
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* until a matching WebSocket `report` arrives with `successful: true`. On
|
|
30
|
-
* that report the slot is cleared and the rows query is invalidated, so the
|
|
31
|
-
* fresh snapshot flips the side to `new` (active).
|
|
28
|
+
* The `confirming` overlay ("POST accepted, awaiting handler") is merged into
|
|
29
|
+
* `tpState` / `slState` at read time — a side flagged as confirming reports
|
|
30
|
+
* state `"confirming"` regardless of what the row set says.
|
|
32
31
|
*/
|
|
33
32
|
export declare function useQuoteTpSl(parameters: UseQuoteTpSlParameters): UseQuoteTpSlReturnType;
|
|
34
33
|
//# sourceMappingURL=use-quote-tpsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-quote-tpsl.d.ts","sourceRoot":"","sources":["../../src/tpsl/use-quote-tpsl.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-quote-tpsl.d.ts","sourceRoot":"","sources":["../../src/tpsl/use-quote-tpsl.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAEzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAG5E,2CAA2C;AAC3C,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,GACvE,eAAe,GAAG;IAChB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEJ,2CAA2C;AAC3C,MAAM,MAAM,sBAAsB,GAAG,cAAc,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;AAEpF;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,sBAAsB,GAAG,sBAAsB,CA8CvF"}
|
|
@@ -2,72 +2,43 @@
|
|
|
2
2
|
import { useSymmioChainId as e } from "../provider/use-symmio-chain-id.js";
|
|
3
3
|
import { useSymmioConfig as t } from "../provider/use-symmio-config.js";
|
|
4
4
|
import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { useEffect as u, useMemo as d } from "react";
|
|
10
|
-
import { useQuery as f, useQueryClient as p } from "@tanstack/react-query";
|
|
5
|
+
import { useTpSlRecord as r, useTpSlStore as i } from "./tpsl-store.js";
|
|
6
|
+
import { useWatchTpSlNotifications as a } from "./use-watch-tpsl-notifications.js";
|
|
7
|
+
import { getQuoteTpSlQueryOptions as o } from "@symmio/trading-core";
|
|
8
|
+
import { useQuery as s } from "@tanstack/react-query";
|
|
11
9
|
//#region src/tpsl/use-quote-tpsl.ts
|
|
12
|
-
function
|
|
13
|
-
let
|
|
10
|
+
function c(c) {
|
|
11
|
+
let u = t(c), d = e(), f = c.chainId ?? d, p = r(c.quoteId), m = o(u, {
|
|
12
|
+
...c,
|
|
13
|
+
chainId: f,
|
|
14
|
+
quoteId: c.quoteId
|
|
15
|
+
}), h = s({
|
|
14
16
|
...m,
|
|
15
|
-
chainId: y
|
|
16
|
-
}), C = f({
|
|
17
|
-
...S,
|
|
18
17
|
queryFn: async () => {
|
|
19
18
|
try {
|
|
20
|
-
|
|
19
|
+
let e = await m.queryFn();
|
|
20
|
+
return i.getState().setRows(c.quoteId, e), e;
|
|
21
21
|
} catch (e) {
|
|
22
22
|
throw n(e);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}), T = o({
|
|
30
|
-
chainId: y,
|
|
31
|
-
quoteId: m.quoteId,
|
|
32
|
-
configKey: x
|
|
33
|
-
}), E = f({
|
|
34
|
-
queryKey: T,
|
|
35
|
-
queryFn: () => b.getQueryData(T) ?? i,
|
|
36
|
-
initialData: i,
|
|
37
|
-
staleTime: Infinity,
|
|
38
|
-
gcTime: Infinity
|
|
39
|
-
}).data ?? i, D = d(() => {
|
|
40
|
-
if (C.data) return g(r(C.data), E);
|
|
41
|
-
}, [C.data, E]), O = m.account, k = m.quoteId, A = JSON.stringify(w);
|
|
42
|
-
return s({
|
|
43
|
-
account: O,
|
|
44
|
-
enabled: !!O && k > 0n,
|
|
25
|
+
});
|
|
26
|
+
return a({
|
|
27
|
+
account: c.account,
|
|
28
|
+
enabled: !!c.account && c.quoteId !== 0n,
|
|
45
29
|
onNotification: (e) => {
|
|
46
|
-
|
|
47
|
-
if (e.successful) {
|
|
48
|
-
let t = e.conditionalOrderType === "take_profit" ? "tp" : e.conditionalOrderType === "stop_loss" ? "sl" : null;
|
|
49
|
-
t && (e.state === "new" || e.state === "edit") && a(b, T, t);
|
|
50
|
-
}
|
|
51
|
-
b.invalidateQueries({ queryKey: w });
|
|
52
|
-
}
|
|
30
|
+
e.primaryIdentifier !== 0 && e.secondaryIdentifier !== 0 && i.getState().link(BigInt(e.primaryIdentifier), BigInt(e.secondaryIdentifier)), l(e, c.quoteId) && i.getState().applyNotification(c.quoteId, e);
|
|
53
31
|
}
|
|
54
|
-
}),
|
|
55
|
-
|
|
56
|
-
data:
|
|
57
|
-
rows: C.data
|
|
32
|
+
}), {
|
|
33
|
+
query: h,
|
|
34
|
+
data: p
|
|
58
35
|
};
|
|
59
36
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
function g(e, t) {
|
|
64
|
-
return !t.tp && !t.sl ? e : {
|
|
65
|
-
...e,
|
|
66
|
-
tpState: t.tp ? "confirming" : e.tpState,
|
|
67
|
-
slState: t.sl ? "confirming" : e.slState
|
|
68
|
-
};
|
|
37
|
+
function l(e, t) {
|
|
38
|
+
let n = i.getState(), r = n.get(t);
|
|
39
|
+
return r ? e.primaryIdentifier !== 0 && n.get(BigInt(e.primaryIdentifier)) === r || e.secondaryIdentifier !== 0 && n.get(BigInt(e.secondaryIdentifier)) === r : e.primaryIdentifier === Number(t) || e.secondaryIdentifier === Number(t) || e.quoteId === Number(t);
|
|
69
40
|
}
|
|
70
41
|
//#endregion
|
|
71
|
-
export {
|
|
42
|
+
export { c as useQuoteTpSl };
|
|
72
43
|
|
|
73
44
|
//# sourceMappingURL=use-quote-tpsl.js.map
|