@xochi/widget 0.0.0-stage → 0.1.1
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/CHANGELOG.md +79 -0
- package/LICENSE +21 -0
- package/README.md +420 -2
- package/THIRD_PARTY_NOTICES.txt +44 -0
- package/dist/ConfiguratorApp.js +19 -0
- package/dist/EmbedApp.js +57 -0
- package/dist/assets/MonaspaceArgon-Bold-D9kWRRK5.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-Light-Dt_6qXbW.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-Medium-B1gMZwrU.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-Regular-RS-2TGNg.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-SemiBold-PYusZXE_.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Italic-C9u9eioB.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Light-CJkxpyfT.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Medium-DCChELAx.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Regular-BZtV1wRa.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-Bold-KacFhGOf.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-Medium-Dqqg-cnL.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-Regular-BRsdKART.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-SemiBold-DNjPl3uE.woff2 +0 -0
- package/dist/assets/alipay-3tx9-HPp.svg +1 -0
- package/dist/assets/arb-CCfLcB_X.svg +7 -0
- package/dist/assets/arc-Dy98eSCd.svg +10 -0
- package/dist/assets/aztec-DiLp9qTG.svg +4 -0
- package/dist/assets/base-Ch0ino36.svg +4 -0
- package/dist/assets/cashapp-lOg0DIt8.svg +1 -0
- package/dist/assets/chains/arbitrum.svg.js +4 -0
- package/dist/assets/chains/arc.svg.js +4 -0
- package/dist/assets/chains/aztec.svg.js +4 -0
- package/dist/assets/chains/base.svg.js +4 -0
- package/dist/assets/chains/ethereum.svg.js +4 -0
- package/dist/assets/chains/gnosis.png.js +4 -0
- package/dist/assets/chains/index.js +31 -0
- package/dist/assets/chains/optimism.svg.js +4 -0
- package/dist/assets/chains/polygon.svg.js +4 -0
- package/dist/assets/chains/robinhood.svg.js +4 -0
- package/dist/assets/chains/tron.svg.js +4 -0
- package/dist/assets/chains/xochi.svg.js +4 -0
- package/dist/assets/dai-XuyZLceZ.png +0 -0
- package/dist/assets/defillama-BU037Unq.svg +1 -0
- package/dist/assets/defillama.svg.js +4 -0
- package/dist/assets/eth-Dvbng9UB.svg +8 -0
- package/dist/assets/eurc-NI9zNgOQ.png +0 -0
- package/dist/assets/eure-BH9vpwcv.png +0 -0
- package/dist/assets/gnosis-fRzAZQFj.png +0 -0
- package/dist/assets/mercadopago-gjsFb6F7.svg +1 -0
- package/dist/assets/monzo-B9XD4bL5.png +0 -0
- package/dist/assets/monzo-SZnIdUKN.svg +1 -0
- package/dist/assets/monzo-dark-Bwzg90UC.png +0 -0
- package/dist/assets/n26-cANcjY2T.svg +1 -0
- package/dist/assets/op-DF67SbB6.png +0 -0
- package/dist/assets/optimism-B3cTNxEQ.svg +4 -0
- package/dist/assets/paypal-D8xqXEtN.svg +1 -0
- package/dist/assets/pol-uLmSo2O8.svg +3 -0
- package/dist/assets/rails/SOURCES.md +50 -0
- package/dist/assets/rails/alipay.svg.js +4 -0
- package/dist/assets/rails/cashapp.svg.js +4 -0
- package/dist/assets/rails/index.js +59 -0
- package/dist/assets/rails/mercadopago.svg.js +4 -0
- package/dist/assets/rails/monzo-dark.png.js +4 -0
- package/dist/assets/rails/monzo.png.js +4 -0
- package/dist/assets/rails/monzo.svg.js +4 -0
- package/dist/assets/rails/n26.svg.js +4 -0
- package/dist/assets/rails/paypal.svg.js +4 -0
- package/dist/assets/rails/revolut-dark.png.js +4 -0
- package/dist/assets/rails/revolut.png.js +4 -0
- package/dist/assets/rails/revolut.svg.js +4 -0
- package/dist/assets/rails/venmo.svg.js +4 -0
- package/dist/assets/rails/wise-dark.png.js +4 -0
- package/dist/assets/rails/wise.png.js +4 -0
- package/dist/assets/rails/wise.svg.js +4 -0
- package/dist/assets/rails/xmoney.svg.js +4 -0
- package/dist/assets/rails/zelle.svg.js +4 -0
- package/dist/assets/raxol-86FmC34h.png +0 -0
- package/dist/assets/revolut-CiBtyALA.png +0 -0
- package/dist/assets/revolut-D7qr5Vzs.svg +1 -0
- package/dist/assets/revolut-dark-RQdWGM_p.png +0 -0
- package/dist/assets/robinhood-DgdGTQ1I.svg +8 -0
- package/dist/assets/tokens/arb.svg.js +4 -0
- package/dist/assets/tokens/dai.png.js +4 -0
- package/dist/assets/tokens/eth.svg.js +4 -0
- package/dist/assets/tokens/eurc.png.js +4 -0
- package/dist/assets/tokens/eure.png.js +4 -0
- package/dist/assets/tokens/index.js +36 -0
- package/dist/assets/tokens/op.png.js +4 -0
- package/dist/assets/tokens/pol.svg.js +4 -0
- package/dist/assets/tokens/raxol.png.js +4 -0
- package/dist/assets/tokens/usdc.png.js +4 -0
- package/dist/assets/tokens/usdg.png.js +4 -0
- package/dist/assets/tokens/usdt.png.js +4 -0
- package/dist/assets/tokens/wbtc.png.js +4 -0
- package/dist/assets/tokens/wsteth.png.js +4 -0
- package/dist/assets/tokens/zchf.png.js +4 -0
- package/dist/assets/tron-Dtumyzha.svg +4 -0
- package/dist/assets/usdc-UHSd0FoM.png +0 -0
- package/dist/assets/usdg-Cd5nCzbC.png +0 -0
- package/dist/assets/usdt-3G3YdPq8.png +0 -0
- package/dist/assets/venmo-CMHeCn-D.svg +1 -0
- package/dist/assets/wbtc-CV8uE44Q.png +0 -0
- package/dist/assets/wise-BUOflsWL.svg +1 -0
- package/dist/assets/wise-JLpDvCdq.png +0 -0
- package/dist/assets/wise-dark-_Q8pbCom.png +0 -0
- package/dist/assets/wsteth-BamwtTCR.png +0 -0
- package/dist/assets/xmoney-CwY9KVlD.svg +1 -0
- package/dist/assets/xochi-DL2f8G4R.svg +4 -0
- package/dist/assets/zchf-BLBNdTGJ.png +0 -0
- package/dist/assets/zelle-t15cG4SB.svg +1 -0
- package/dist/browser.js +4 -0
- package/dist/components/AccountChip.js +29 -0
- package/dist/components/ActivityFeed.js +710 -0
- package/dist/components/AssetsStrip.js +133 -0
- package/dist/components/AuthorizedAgents.js +197 -0
- package/dist/components/Chevron.js +22 -0
- package/dist/components/ErrorDisplay.js +68 -0
- package/dist/components/InfoButton.js +27 -0
- package/dist/components/IntentTimeline.js +202 -0
- package/dist/components/LinksSignIn.js +26 -0
- package/dist/components/MobileSigningBanner.js +44 -0
- package/dist/components/PrivacyBars.js +44 -0
- package/dist/components/PrivacyPanel.js +99 -0
- package/dist/components/QuoteDetails.js +327 -0
- package/dist/components/ReceiptCommand.js +46 -0
- package/dist/components/SessionReloadBanner.js +19 -0
- package/dist/components/SolverRace.js +62 -0
- package/dist/components/StealthClaims.js +179 -0
- package/dist/components/SwapFlowModal.js +408 -0
- package/dist/components/Toast.js +40 -0
- package/dist/components/TokenIcon.js +21 -0
- package/dist/components/TokenSearchModal.js +331 -0
- package/dist/components/TransactionPreview.js +230 -0
- package/dist/components/WalletProvider.js +41 -0
- package/dist/components/WrapModal.js +192 -0
- package/dist/components/swap-flow/CantonEscrowPanel.js +28 -0
- package/dist/components/swap-flow/CantonEscrowStatus.js +160 -0
- package/dist/components/swap-flow/DepositInstructions.js +156 -0
- package/dist/components/swap-flow/QrCode.js +22 -0
- package/dist/components/swap-flow/SwapResult.js +325 -0
- package/dist/components/swap-flow/depositScreen.js +36 -0
- package/dist/components/widgetTabsContext.js +17 -0
- package/dist/config.js +132 -0
- package/dist/configurator-model.js +71 -0
- package/dist/configurator.js +11 -0
- package/dist/constants.js +53 -0
- package/dist/hooks/applyTheme.js +10 -0
- package/dist/hooks/useAgentRegistry.js +28 -0
- package/dist/hooks/useAgentStream.js +89 -0
- package/dist/hooks/useCantonEscrow.js +89 -0
- package/dist/hooks/useCapabilities.js +86 -0
- package/dist/hooks/useEmbedLook.js +23 -0
- package/dist/hooks/useFocusTrap.js +44 -0
- package/dist/hooks/useIntent.js +485 -0
- package/dist/hooks/useIntentStatusPoll.js +71 -0
- package/dist/hooks/useIntentStream.js +95 -0
- package/dist/hooks/useLocalActivity.js +114 -0
- package/dist/hooks/useLocalSends.js +15 -0
- package/dist/hooks/useLocalStorage.js +26 -0
- package/dist/hooks/useOrderHistory.js +307 -0
- package/dist/hooks/usePermit.js +203 -0
- package/dist/hooks/usePrices.js +49 -0
- package/dist/hooks/usePublicBalances.js +186 -0
- package/dist/hooks/useRampSummaries.js +19 -0
- package/dist/hooks/useRecipientBalance.js +98 -0
- package/dist/hooks/useSettlements.js +33 -0
- package/dist/hooks/useStealth.js +324 -0
- package/dist/hooks/useStealthClaim.js +183 -0
- package/dist/hooks/useStealthScanner.js +259 -0
- package/dist/hooks/useTheme.js +48 -0
- package/dist/hooks/useTierInfo.js +20 -0
- package/dist/hooks/useTrustScore.js +16 -0
- package/dist/hooks/useWalletSession.js +70 -0
- package/dist/hooks/useWrapEth.js +60 -0
- package/dist/index.js +41 -0
- package/dist/integration.js +19 -0
- package/dist/lib/activityValue.js +20 -0
- package/dist/lib/agentConnect.js +11 -0
- package/dist/lib/agentRegistry.js +83 -0
- package/dist/lib/agentStreamVerify.js +47 -0
- package/dist/lib/api.js +67 -0
- package/dist/lib/auth.js +8 -0
- package/dist/lib/authFetch.js +33 -0
- package/dist/lib/aztecTokens.js +13 -0
- package/dist/lib/balances.js +77 -0
- package/dist/lib/capabilities.js +40 -0
- package/dist/lib/claimSubmitPoll.js +63 -0
- package/dist/lib/debug.js +7 -0
- package/dist/lib/declineGuidance.js +31 -0
- package/dist/lib/displayFallbacks.js +25 -0
- package/dist/lib/eip712.js +38 -0
- package/dist/lib/errorCategory.js +202 -0
- package/dist/lib/errorReport.js +19 -0
- package/dist/lib/explorerLinks.js +30 -0
- package/dist/lib/feesLabel.js +19 -0
- package/dist/lib/glyphs.js +58 -0
- package/dist/lib/hostBridge.js +41 -0
- package/dist/lib/hostOrigin.js +52 -0
- package/dist/lib/intentAPI.js +39 -0
- package/dist/lib/linksSignIn.js +9 -0
- package/dist/lib/localActivity.js +247 -0
- package/dist/lib/localSends.js +129 -0
- package/dist/lib/mobileWallet.js +17 -0
- package/dist/lib/pairAvailability.js +29 -0
- package/dist/lib/paymentSummary.js +23 -0
- package/dist/lib/permits.js +27 -0
- package/dist/lib/priceImpact.js +101 -0
- package/dist/lib/providers.js +124 -0
- package/dist/lib/qr.js +20 -0
- package/dist/lib/quoteCost.js +34 -0
- package/dist/lib/quoteCountdown.js +24 -0
- package/dist/lib/rampHostGate.js +24 -0
- package/dist/lib/rampLifecycle.js +63 -0
- package/dist/lib/receiptCost.js +64 -0
- package/dist/lib/recipient/index.js +302 -0
- package/dist/lib/recipient/recent.js +47 -0
- package/dist/lib/recipientReceipt.js +16 -0
- package/dist/lib/reportClient.js +32 -0
- package/dist/lib/sessionExpiry.js +11 -0
- package/dist/lib/settlementAvailability.js +34 -0
- package/dist/lib/stealth.js +110 -0
- package/dist/lib/swapFlowPhase.js +52 -0
- package/dist/lib/swapStatusCopy.js +59 -0
- package/dist/lib/tradeLifecycle.js +40 -0
- package/dist/lib/tronlink.js +71 -0
- package/dist/lib/walletSession.js +87 -0
- package/dist/pages/Configurator.js +390 -0
- package/dist/pages/Trade.js +635 -0
- package/dist/pages/configurator/AllowedAssetsSection.js +98 -0
- package/dist/pages/configurator/AppearanceSection.js +44 -0
- package/dist/pages/configurator/CodeDock.js +140 -0
- package/dist/pages/configurator/DeveloperSection.js +40 -0
- package/dist/pages/configurator/IntegrationSection.js +105 -0
- package/dist/pages/configurator/LayoutSection.js +83 -0
- package/dist/pages/configurator/PolicyNote.js +7 -0
- package/dist/pages/configurator/PreviewStage.js +165 -0
- package/dist/pages/configurator/PrivacySection.js +54 -0
- package/dist/pages/configurator/RouteSection.js +211 -0
- package/dist/pages/configurator/Settings.js +35 -0
- package/dist/pages/configurator/SharedLinkBanner.js +25 -0
- package/dist/pages/configurator/SurfaceSection.js +124 -0
- package/dist/pages/configurator/WhatUsersSee.js +268 -0
- package/dist/pages/configurator/codeShown.js +8 -0
- package/dist/pages/configurator/configuratorUrl.js +33 -0
- package/dist/pages/configurator/paramsDraft.js +82 -0
- package/dist/pages/configurator/previewModel.js +10 -0
- package/dist/pages/configurator/previewQuote.js +109 -0
- package/dist/pages/configurator/routePicks.js +131 -0
- package/dist/pages/configurator/snippets.js +98 -0
- package/dist/pages/configurator/surfaceParams.js +51 -0
- package/dist/pages/configurator/useCodeCheck.js +79 -0
- package/dist/pages/configurator/useConfiguratorUrl.js +24 -0
- package/dist/pages/configurator/useMediaQuery.js +20 -0
- package/dist/pages/configurator/useParamsDraft.js +33 -0
- package/dist/pages/configurator/usePreviewFee.js +100 -0
- package/dist/pages/send/MetaAddressValue.js +28 -0
- package/dist/pages/send/Receive.js +168 -0
- package/dist/pages/send/RecentRecipients.js +23 -0
- package/dist/pages/send/RecipientChip.js +26 -0
- package/dist/pages/send/ScanRecipient.js +85 -0
- package/dist/pages/send/SendForm.js +516 -0
- package/dist/pages/send/SendPanel.js +30 -0
- package/dist/pages/send/ShieldedDisclosure.js +12 -0
- package/dist/pages/send/StealthInvite.js +27 -0
- package/dist/pages/send/addressSend.js +92 -0
- package/dist/pages/send/sendCopy.js +10 -0
- package/dist/pages/send/sendRetry.js +24 -0
- package/dist/pages/send/stealthRecipient.js +65 -0
- package/dist/pages/send/stealthSend.js +15 -0
- package/dist/pages/send/useAddressSend.js +257 -0
- package/dist/pages/send/useSendRecipient.js +61 -0
- package/dist/pages/trade/BuyPanel.js +70 -0
- package/dist/pages/trade/RampRecovery.js +41 -0
- package/dist/pages/trade/RecipientSheet.js +182 -0
- package/dist/pages/trade/Selectors.js +152 -0
- package/dist/pages/trade/SwapPanel.js +972 -0
- package/dist/pages/trade/WidgetTabs.js +109 -0
- package/dist/pages/trade/canton.js +122 -0
- package/dist/pages/trade/config.js +70 -0
- package/dist/pages/trade/embedNarrowing.js +25 -0
- package/dist/pages/trade/embedParams.js +532 -0
- package/dist/pages/trade/embedTheme.js +9 -0
- package/dist/pages/trade/orderMinimum.js +8 -0
- package/dist/pages/trade/resumeSwap.js +55 -0
- package/dist/pages/trade/settlementCopy.js +32 -0
- package/dist/pages/trade/useAmountFit.js +31 -0
- package/dist/pages/trade/useEmbedDefaults.js +18 -0
- package/dist/pages/trade/useSettlementGating.js +289 -0
- package/dist/pages/trade/useSwapAmount.js +191 -0
- package/dist/pages/trade/useSwapFlow.js +511 -0
- package/dist/pages/trade/useSwapPanel.js +475 -0
- package/dist/pages/trade/useSwapRoute.js +634 -0
- package/dist/pages/trade/useTronLinkFill.js +34 -0
- package/dist/pages/trade/zkMoney.js +46 -0
- package/dist/promiseWithResolvers.js +20 -0
- package/dist/ramp/availability/RailTiles.js +156 -0
- package/dist/ramp/availability/RampDisclosure.js +38 -0
- package/dist/ramp/availability/RampRails.js +170 -0
- package/dist/ramp/availability/model.js +207 -0
- package/dist/ramp/availability/useRampDiscovery.js +83 -0
- package/dist/ramp/offramp/CompletedPrerequisite.js +23 -0
- package/dist/ramp/offramp/OfframpActivityList.js +16 -0
- package/dist/ramp/offramp/OfframpRoute.js +222 -0
- package/dist/ramp/offramp/OfframpRouteReview.js +94 -0
- package/dist/ramp/offramp/PaymentAppSend.js +765 -0
- package/dist/ramp/offramp/localOfframps.js +101 -0
- package/dist/ramp/offramp/model.js +154 -0
- package/dist/ramp/offramp/port.js +134 -0
- package/dist/ramp/offramp/prerequisite.js +143 -0
- package/dist/ramp/offramp/useOfframp.js +505 -0
- package/dist/ramp/offramp/useOfframpRails.js +73 -0
- package/dist/ramp/peer/BuyOnramp.js +292 -0
- package/dist/ramp/peer/OnrampSteps.js +148 -0
- package/dist/ramp/peer/buyerDriver.js +461 -0
- package/dist/ramp/peer/discovery.js +231 -0
- package/dist/ramp/peer/environment.js +7 -0
- package/dist/ramp/peer/liveProvider.js +87 -0
- package/dist/ramp/peer/liveReads.js +488 -0
- package/dist/ramp/peer/maker.js +92 -0
- package/dist/ramp/peer/normalization.js +184 -0
- package/dist/ramp/peer/offramp.js +648 -0
- package/dist/ramp/peer/onramp.js +353 -0
- package/dist/ramp/peer/preview.js +52 -0
- package/dist/ramp/peer/protectedMapping.js +67 -0
- package/dist/ramp/peer/runtime.js +55 -0
- package/dist/ramp/peer/sdkMaker.js +107 -0
- package/dist/ramp/recovery/ResumeOnramp.js +153 -0
- package/dist/ramp/recovery/summaries.js +173 -0
- package/dist/ramp/route/OnrampRoute.js +255 -0
- package/dist/ramp/route/RampRouteSteps.js +148 -0
- package/dist/ramp/route/routeActivity.js +12 -0
- package/dist/ramp/route/useXochiRampDriver.js +203 -0
- package/dist/styles.css +17473 -0
- package/dist/styles.js +2 -0
- package/dist/types/ConfiguratorApp.d.ts +6 -0
- package/dist/types/EmbedApp.d.ts +2 -0
- package/dist/types/activity.js +50 -0
- package/dist/types/asset.d.ts +2 -0
- package/dist/types/assets/chains/index.d.ts +3 -0
- package/dist/types/assets/rails/index.d.ts +12 -0
- package/dist/types/assets/tokens/index.d.ts +1 -0
- package/dist/types/browser.d.ts +1 -0
- package/dist/types/components/AccountChip.d.ts +10 -0
- package/dist/types/components/ActivityFeed.d.ts +46 -0
- package/dist/types/components/AssetsStrip.d.ts +14 -0
- package/dist/types/components/AuthorizedAgents.d.ts +15 -0
- package/dist/types/components/Chevron.d.ts +16 -0
- package/dist/types/components/ErrorDisplay.d.ts +46 -0
- package/dist/types/components/InfoButton.d.ts +6 -0
- package/dist/types/components/IntentTimeline.d.ts +41 -0
- package/dist/types/components/LinksSignIn.d.ts +13 -0
- package/dist/types/components/MobileSigningBanner.d.ts +16 -0
- package/dist/types/components/PermitBadge.d.ts +17 -0
- package/dist/types/components/PrivacyBars.d.ts +12 -0
- package/dist/types/components/PrivacyPanel.d.ts +33 -0
- package/dist/types/components/QuoteDetails.d.ts +56 -0
- package/dist/types/components/RampActivityList.d.ts +14 -0
- package/dist/types/components/ReceiptCommand.d.ts +12 -0
- package/dist/types/components/SessionReloadBanner.d.ts +8 -0
- package/dist/types/components/SolverRace.d.ts +35 -0
- package/dist/types/components/StealthClaims.d.ts +51 -0
- package/dist/types/components/SwapFlowModal.d.ts +142 -0
- package/dist/types/components/Toast.d.ts +10 -0
- package/dist/types/components/TokenIcon.d.ts +17 -0
- package/dist/types/components/TokenSearchModal.d.ts +28 -0
- package/dist/types/components/TransactionPreview.d.ts +37 -0
- package/dist/types/components/WalletProvider.d.ts +12 -0
- package/dist/types/components/WrapModal.d.ts +19 -0
- package/dist/types/components/swap-flow/CantonEscrowPanel.d.ts +14 -0
- package/dist/types/components/swap-flow/CantonEscrowStatus.d.ts +30 -0
- package/dist/types/components/swap-flow/DepositInstructions.d.ts +75 -0
- package/dist/types/components/swap-flow/QrCode.d.ts +18 -0
- package/dist/types/components/swap-flow/SwapResult.d.ts +68 -0
- package/dist/types/components/swap-flow/depositScreen.d.ts +67 -0
- package/dist/types/components/widgetTabsContext.d.ts +21 -0
- package/dist/types/config.d.ts +104 -0
- package/dist/types/configurator-model.d.ts +9 -0
- package/dist/types/configurator.d.ts +3 -0
- package/dist/types/constants.d.ts +52 -0
- package/dist/types/hooks/applyTheme.d.ts +7 -0
- package/dist/types/hooks/useAgentRegistry.d.ts +13 -0
- package/dist/types/hooks/useAgentStream.d.ts +15 -0
- package/dist/types/hooks/useCantonEscrow.d.ts +40 -0
- package/dist/types/hooks/useCapabilities.d.ts +83 -0
- package/dist/types/hooks/useEmbedLook.d.ts +4 -0
- package/dist/types/hooks/useFocusTrap.d.ts +7 -0
- package/dist/types/hooks/useIntent.d.ts +161 -0
- package/dist/types/hooks/useIntentStatusPoll.d.ts +107 -0
- package/dist/types/hooks/useIntentStream.d.ts +34 -0
- package/dist/types/hooks/useLocalActivity.d.ts +22 -0
- package/dist/types/hooks/useLocalSends.d.ts +8 -0
- package/dist/types/hooks/useLocalStorage.d.ts +8 -0
- package/dist/types/hooks/useOrderHistory.d.ts +52 -0
- package/dist/types/hooks/usePermit.d.ts +90 -0
- package/dist/types/hooks/usePrices.d.ts +72 -0
- package/dist/types/hooks/usePublicBalances.d.ts +19 -0
- package/dist/types/hooks/useRampSummaries.d.ts +9 -0
- package/dist/types/hooks/useRecipientBalance.d.ts +58 -0
- package/dist/types/hooks/useSettlements.d.ts +14 -0
- package/dist/types/hooks/useStealth.d.ts +72 -0
- package/dist/types/hooks/useStealthClaim.d.ts +96 -0
- package/dist/types/hooks/useStealthScanner.d.ts +44 -0
- package/dist/types/hooks/useTheme.d.ts +29 -0
- package/dist/types/hooks/useTierInfo.d.ts +23 -0
- package/dist/types/hooks/useTrustScore.d.ts +16 -0
- package/dist/types/hooks/useWalletSession.d.ts +21 -0
- package/dist/types/hooks/useWrapEth.d.ts +21 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +8 -0
- package/dist/types/integration.d.ts +9 -0
- package/dist/types/intent.js +85 -0
- package/dist/types/lib/activityValue.d.ts +16 -0
- package/dist/types/lib/agentConnect.d.ts +23 -0
- package/dist/types/lib/agentRegistry.d.ts +47 -0
- package/dist/types/lib/agentStreamVerify.d.ts +29 -0
- package/dist/types/lib/api.d.ts +41 -0
- package/dist/types/lib/auth.d.ts +6 -0
- package/dist/types/lib/authFetch.d.ts +14 -0
- package/dist/types/lib/aztecTokens.d.ts +15 -0
- package/dist/types/lib/balances.d.ts +88 -0
- package/dist/types/lib/capabilities.d.ts +3 -0
- package/dist/types/lib/claimSubmitPoll.d.ts +114 -0
- package/dist/types/lib/debug.d.ts +13 -0
- package/dist/types/lib/declineGuidance.d.ts +55 -0
- package/dist/types/lib/displayFallbacks.d.ts +7 -0
- package/dist/types/lib/eip712.d.ts +61 -0
- package/dist/types/lib/errorCategory.d.ts +50 -0
- package/dist/types/lib/errorReport.d.ts +15 -0
- package/dist/types/lib/explorerLinks.d.ts +67 -0
- package/dist/types/lib/feesLabel.d.ts +20 -0
- package/dist/types/lib/glyphs.d.ts +52 -0
- package/dist/types/lib/hostBridge.d.ts +11 -0
- package/dist/types/lib/hostOrigin.d.ts +30 -0
- package/dist/types/lib/intentAPI.d.ts +15 -0
- package/dist/types/lib/linksSignIn.d.ts +13 -0
- package/dist/types/lib/localActivity.d.ts +135 -0
- package/dist/types/lib/localSends.d.ts +55 -0
- package/dist/types/lib/mobileWallet.d.ts +27 -0
- package/dist/types/lib/pairAvailability.d.ts +106 -0
- package/dist/types/lib/paymentSummary.d.ts +18 -0
- package/dist/types/lib/permits.d.ts +25 -0
- package/dist/types/lib/priceImpact.d.ts +165 -0
- package/dist/types/lib/providers.d.ts +14 -0
- package/dist/types/lib/qr.d.ts +19 -0
- package/dist/types/lib/quoteCost.d.ts +45 -0
- package/dist/types/lib/quoteCountdown.d.ts +34 -0
- package/dist/types/lib/rampHostGate.d.ts +15 -0
- package/dist/types/lib/rampLifecycle.d.ts +20 -0
- package/dist/types/lib/receiptCost.d.ts +64 -0
- package/dist/types/lib/recipient/index.d.ts +33 -0
- package/dist/types/lib/recipient/recent.d.ts +5 -0
- package/dist/types/lib/recipientReceipt.d.ts +25 -0
- package/dist/types/lib/reportClient.d.ts +9 -0
- package/dist/types/lib/sessionExpiry.d.ts +11 -0
- package/dist/types/lib/settlementAvailability.d.ts +61 -0
- package/dist/types/lib/stealth.d.ts +75 -0
- package/dist/types/lib/swapFlowPhase.d.ts +76 -0
- package/dist/types/lib/swapStatusCopy.d.ts +57 -0
- package/dist/types/lib/tierProgressDisplay.d.ts +35 -0
- package/dist/types/lib/tierUnlock.d.ts +25 -0
- package/dist/types/lib/tradeLifecycle.d.ts +32 -0
- package/dist/types/lib/tronlink.d.ts +62 -0
- package/dist/types/lib/walletSession.d.ts +38 -0
- package/dist/types/pages/Configurator.d.ts +25 -0
- package/dist/types/pages/Trade.d.ts +36 -0
- package/dist/types/pages/configurator/AllowedAssetsSection.d.ts +17 -0
- package/dist/types/pages/configurator/AppearanceSection.d.ts +22 -0
- package/dist/types/pages/configurator/CodeDock.d.ts +19 -0
- package/dist/types/pages/configurator/DeveloperSection.d.ts +12 -0
- package/dist/types/pages/configurator/IntegrationSection.d.ts +20 -0
- package/dist/types/pages/configurator/LayoutSection.d.ts +20 -0
- package/dist/types/pages/configurator/PolicyNote.d.ts +6 -0
- package/dist/types/pages/configurator/PreviewStage.d.ts +22 -0
- package/dist/types/pages/configurator/PrivacySection.d.ts +16 -0
- package/dist/types/pages/configurator/RouteSection.d.ts +30 -0
- package/dist/types/pages/configurator/Settings.d.ts +25 -0
- package/dist/types/pages/configurator/SharedLinkBanner.d.ts +16 -0
- package/dist/types/pages/configurator/SurfaceSection.d.ts +5 -0
- package/dist/types/pages/configurator/WhatUsersSee.d.ts +30 -0
- package/dist/types/pages/configurator/codeShown.d.ts +15 -0
- package/dist/types/pages/configurator/configuratorUrl.d.ts +38 -0
- package/dist/types/pages/configurator/paramsDraft.d.ts +32 -0
- package/dist/types/pages/configurator/previewModel.d.ts +20 -0
- package/dist/types/pages/configurator/previewQuote.d.ts +96 -0
- package/dist/types/pages/configurator/routePicks.d.ts +75 -0
- package/dist/types/pages/configurator/snippets.d.ts +23 -0
- package/dist/types/pages/configurator/surfaceParams.d.ts +9 -0
- package/dist/types/pages/configurator/useCodeCheck.d.ts +56 -0
- package/dist/types/pages/configurator/useConfiguratorUrl.d.ts +21 -0
- package/dist/types/pages/configurator/useMediaQuery.d.ts +5 -0
- package/dist/types/pages/configurator/useParamsDraft.d.ts +29 -0
- package/dist/types/pages/configurator/usePreviewFee.d.ts +74 -0
- package/dist/types/pages/send/MetaAddressValue.d.ts +9 -0
- package/dist/types/pages/send/Receive.d.ts +3 -0
- package/dist/types/pages/send/RecentRecipients.d.ts +3 -0
- package/dist/types/pages/send/RecipientChip.d.ts +4 -0
- package/dist/types/pages/send/ScanRecipient.d.ts +3 -0
- package/dist/types/pages/send/SendForm.d.ts +17 -0
- package/dist/types/pages/send/SendPanel.d.ts +19 -0
- package/dist/types/pages/send/ShieldedDisclosure.d.ts +1 -0
- package/dist/types/pages/send/StealthInvite.d.ts +1 -0
- package/dist/types/pages/send/addressSend.d.ts +62 -0
- package/dist/types/pages/send/sendCopy.d.ts +9 -0
- package/dist/types/pages/send/sendRetry.d.ts +10 -0
- package/dist/types/pages/send/stealthRecipient.d.ts +37 -0
- package/dist/types/pages/send/stealthSend.d.ts +18 -0
- package/dist/types/pages/send/useAddressSend.d.ts +61 -0
- package/dist/types/pages/send/useSendRecipient.d.ts +13 -0
- package/dist/types/pages/trade/BuyPanel.d.ts +22 -0
- package/dist/types/pages/trade/RampRecovery.d.ts +22 -0
- package/dist/types/pages/trade/RecipientSheet.d.ts +11 -0
- package/dist/types/pages/trade/Selectors.d.ts +24 -0
- package/dist/types/pages/trade/SwapPanel.d.ts +34 -0
- package/dist/types/pages/trade/WidgetTabs.d.ts +46 -0
- package/dist/types/pages/trade/canton.d.ts +94 -0
- package/dist/types/pages/trade/config.d.ts +185 -0
- package/dist/types/pages/trade/embedNarrowing.d.ts +28 -0
- package/dist/types/pages/trade/embedParams.d.ts +299 -0
- package/dist/types/pages/trade/embedTheme.d.ts +14 -0
- package/dist/types/pages/trade/harness.d.ts +120 -0
- package/dist/types/pages/trade/orderMinimum.d.ts +5 -0
- package/dist/types/pages/trade/resumeSwap.d.ts +139 -0
- package/dist/types/pages/trade/settlementCopy.d.ts +42 -0
- package/dist/types/pages/trade/useAmountFit.d.ts +25 -0
- package/dist/types/pages/trade/useEmbedDefaults.d.ts +28 -0
- package/dist/types/pages/trade/useSettlementGating.d.ts +152 -0
- package/dist/types/pages/trade/useSwapAmount.d.ts +93 -0
- package/dist/types/pages/trade/useSwapFlow.d.ts +152 -0
- package/dist/types/pages/trade/useSwapPanel.d.ts +170 -0
- package/dist/types/pages/trade/useSwapRoute.d.ts +215 -0
- package/dist/types/pages/trade/useTronLinkFill.d.ts +13 -0
- package/dist/types/pages/trade/zkMoney.d.ts +28 -0
- package/dist/types/promiseWithResolvers.d.ts +12 -0
- package/dist/types/ramp/availability/RailTiles.d.ts +26 -0
- package/dist/types/ramp/availability/RampDisclosure.d.ts +9 -0
- package/dist/types/ramp/availability/RampRails.d.ts +27 -0
- package/dist/types/ramp/availability/model.d.ts +51 -0
- package/dist/types/ramp/availability/useRampDiscovery.d.ts +60 -0
- package/dist/types/ramp/offramp/CompletedPrerequisite.d.ts +5 -0
- package/dist/types/ramp/offramp/OfframpActivityList.d.ts +12 -0
- package/dist/types/ramp/offramp/OfframpRoute.d.ts +8 -0
- package/dist/types/ramp/offramp/OfframpRouteReview.d.ts +12 -0
- package/dist/types/ramp/offramp/PaymentAppSend.d.ts +27 -0
- package/dist/types/ramp/offramp/localOfframps.d.ts +58 -0
- package/dist/types/ramp/offramp/model.d.ts +46 -0
- package/dist/types/ramp/offramp/port.d.ts +55 -0
- package/dist/types/ramp/offramp/prerequisite.d.ts +271 -0
- package/dist/types/ramp/offramp/useOfframp.d.ts +87 -0
- package/dist/types/ramp/offramp/useOfframpRails.d.ts +36 -0
- package/dist/types/ramp/peer/BuyOnramp.d.ts +21 -0
- package/dist/types/ramp/peer/OnrampSteps.d.ts +32 -0
- package/dist/types/ramp/peer/buyerDriver.d.ts +48 -0
- package/dist/types/ramp/peer/discovery.d.ts +17 -0
- package/dist/types/ramp/peer/environment.d.ts +2 -0
- package/dist/types/ramp/peer/index.d.ts +14 -0
- package/dist/types/ramp/peer/liveProvider.d.ts +15 -0
- package/dist/types/ramp/peer/liveReads.d.ts +102 -0
- package/dist/types/ramp/peer/maker.d.ts +4 -0
- package/dist/types/ramp/peer/normalization.d.ts +33 -0
- package/dist/types/ramp/peer/offramp.d.ts +130 -0
- package/dist/types/ramp/peer/onramp.d.ts +134 -0
- package/dist/types/ramp/peer/preview.d.ts +14 -0
- package/dist/types/ramp/peer/protectedMapping.d.ts +22 -0
- package/dist/types/ramp/peer/runtime.d.ts +15 -0
- package/dist/types/ramp/peer/sdkMaker.d.ts +67 -0
- package/dist/types/ramp/peer/types.d.ts +64 -0
- package/dist/types/ramp/recovery/ResumeOnramp.d.ts +37 -0
- package/dist/types/ramp/recovery/summaries.d.ts +71 -0
- package/dist/types/ramp/route/OnrampRoute.d.ts +12 -0
- package/dist/types/ramp/route/RampRouteSteps.d.ts +16 -0
- package/dist/types/ramp/route/routeActivity.d.ts +4 -0
- package/dist/types/ramp/route/useXochiRampDriver.d.ts +22 -0
- package/dist/types/result.js +14 -0
- package/dist/types/styles.d.ts +1 -0
- package/dist/types/types/activity.d.ts +184 -0
- package/dist/types/types/index.d.ts +20 -0
- package/dist/types/types/intent.d.ts +85 -0
- package/dist/types/types/result.d.ts +53 -0
- package/dist/types/utils/format.d.ts +88 -0
- package/dist/types/wagmi.d.ts +143 -0
- package/dist/types/widgetLibModule.d.ts +8 -0
- package/dist/utils/format.js +109 -0
- package/dist/wagmi.js +210 -0
- package/dist/widgetLibModule.js +4 -0
- package/licenses/Monaspace-OFL-1.1.txt +93 -0
- package/licenses/assets.json +132 -0
- package/licenses/rainbowkit-MIT.txt +9 -0
- package/licenses/xochi-shared-MIT.txt +21 -0
- package/package.json +115 -4
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { useState, useRef, useEffect, useCallback, useMemo } from "react";
|
|
2
|
+
import { useAccount, useSignTypedData } from "wagmi";
|
|
3
|
+
import { isChainId, init, POLL_INFLIGHT_STATES, view, canAllocateDepositQuote, canSignQuote, LOADING_STATES, update } from "@xochi/client";
|
|
4
|
+
import { intentAPI } from "../lib/intentAPI.js";
|
|
5
|
+
import { hasWalletSession } from "../lib/walletSession.js";
|
|
6
|
+
import { debugLog } from "../lib/debug.js";
|
|
7
|
+
import { reportError } from "../lib/errorReport.js";
|
|
8
|
+
import { prepareTypedDataForSigning } from "../lib/eip712.js";
|
|
9
|
+
import { hostBridge } from "../lib/hostBridge.js";
|
|
10
|
+
import { tradeEvents } from "../lib/tradeLifecycle.js";
|
|
11
|
+
import { PULL_RECIPIENTS, SOLVER_PIN, DEPOSIT_ATTESTATION_PIN } from "../config.js";
|
|
12
|
+
import { usePermit } from "./usePermit.js";
|
|
13
|
+
import { useTierInfo } from "./useTierInfo.js";
|
|
14
|
+
import { useWalletSession } from "./useWalletSession.js";
|
|
15
|
+
import { useIntentStream } from "./useIntentStream.js";
|
|
16
|
+
const PERMIT_PLACEHOLDER_CHAIN = 8453;
|
|
17
|
+
function createRuntime(initial) {
|
|
18
|
+
const queue = [];
|
|
19
|
+
let draining = false;
|
|
20
|
+
const timers = /* @__PURE__ */ new Map();
|
|
21
|
+
const allocations = /* @__PURE__ */ new Map();
|
|
22
|
+
let refs = 0;
|
|
23
|
+
const clearTimer = (timer) => {
|
|
24
|
+
const armed = timers.get(timer);
|
|
25
|
+
if (!armed) return;
|
|
26
|
+
if (armed.repeat) clearInterval(armed.handle);
|
|
27
|
+
else clearTimeout(armed.handle);
|
|
28
|
+
timers.delete(timer);
|
|
29
|
+
};
|
|
30
|
+
const attempted = /* @__PURE__ */ new Map();
|
|
31
|
+
const dispatch = (body) => {
|
|
32
|
+
if (!rt.live) return;
|
|
33
|
+
queue.push(body);
|
|
34
|
+
if (draining) return;
|
|
35
|
+
draining = true;
|
|
36
|
+
try {
|
|
37
|
+
let next;
|
|
38
|
+
while ((next = queue.shift()) !== void 0) step(next);
|
|
39
|
+
} finally {
|
|
40
|
+
draining = false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const step = (body) => {
|
|
44
|
+
const io = rt.bindings;
|
|
45
|
+
if (!io || !rt.live) return;
|
|
46
|
+
const stamp = { now: Date.now(), hidden: document.hidden };
|
|
47
|
+
const effects = [];
|
|
48
|
+
let model = rt.model;
|
|
49
|
+
if (body.type !== "ContextChanged" && JSON.stringify(model.ctx) !== io.ctxKey) {
|
|
50
|
+
const [synced, fx2] = update(model, { type: "ContextChanged", ctx: io.ctx, ...stamp });
|
|
51
|
+
model = synced;
|
|
52
|
+
effects.push(...fx2);
|
|
53
|
+
}
|
|
54
|
+
const [after, fx] = update(model, { ...body, ...stamp });
|
|
55
|
+
effects.push(...fx);
|
|
56
|
+
const adoptedOrder = body.type === "ResumeRequested" && after.intent !== model.intent && after.intent.intentId === body.intentId;
|
|
57
|
+
if (adoptedOrder || body.type === "ResetRequested" || after.intent.intentId !== rt.model.intent.intentId || after.intent.quotedAddress !== rt.model.intent.quotedAddress || effects.some((effect) => effect.type === "Api" && effect.call.op === "quote")) {
|
|
58
|
+
rt.executionIntentId = null;
|
|
59
|
+
rt.failureSubstatus = null;
|
|
60
|
+
}
|
|
61
|
+
if (effects.some(
|
|
62
|
+
(effect) => effect.type === "Api" && (effect.call.op === "execute" || effect.call.op === "status")
|
|
63
|
+
) || adoptedOrder) {
|
|
64
|
+
rt.executionIntentId = after.intent.intentId;
|
|
65
|
+
}
|
|
66
|
+
if (body.type === "StatusReplied" && body.result.ok && body.result.status && !("notFound" in body.result.status) && body.result.status.status === "failed" && model.intent.status !== "failed" && after.intent.status === "failed" && after.intent.intentId !== null && after.intent.intentId === model.intent.intentId && rt.executionIntentId === after.intent.intentId) {
|
|
67
|
+
rt.failureSubstatus = {
|
|
68
|
+
intentId: after.intent.intentId,
|
|
69
|
+
substatus: body.result.status.substatus ?? null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (hostBridge) {
|
|
73
|
+
for (const event of tradeEvents(model, after, body, attempted)) {
|
|
74
|
+
try {
|
|
75
|
+
hostBridge.emit(event);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error(`[useIntent] Dropped host event ${event.name}`, err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
rt.model = after;
|
|
82
|
+
io.render(after);
|
|
83
|
+
for (const effect of effects) perform(effect, io);
|
|
84
|
+
};
|
|
85
|
+
const fail = (err) => ({ ok: false, error: reportError(err) });
|
|
86
|
+
const rejectStaleWalletReply = () => {
|
|
87
|
+
const wasSigning = rt.model.intent.status === "signing";
|
|
88
|
+
dispatch({ type: "CancelSignRequested" });
|
|
89
|
+
if (wasSigning && rt.model.intent.status === "quoted") {
|
|
90
|
+
dispatch({ type: "ResetRequested" });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const perform = (effect, io) => {
|
|
94
|
+
switch (effect.type) {
|
|
95
|
+
case "Emit": {
|
|
96
|
+
const event = effect.event;
|
|
97
|
+
if (event.kind === "allocation") {
|
|
98
|
+
allocations.get(event.ref)?.(event.ok);
|
|
99
|
+
allocations.delete(event.ref);
|
|
100
|
+
} else if (event.level === "debug") {
|
|
101
|
+
debugLog(event.message, ...event.data);
|
|
102
|
+
} else {
|
|
103
|
+
console[event.level](event.message, ...event.data);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
case "Timer": {
|
|
108
|
+
const call = effect.call;
|
|
109
|
+
clearTimer(call.timer);
|
|
110
|
+
if (call.op === "clear" || call.timer === "refresh" && io.manualQuoteRefresh) return;
|
|
111
|
+
const fire = () => dispatch({ type: "TimerFired", timer: call.timer });
|
|
112
|
+
const handle = call.repeat ? setInterval(fire, call.ms) : setTimeout(() => {
|
|
113
|
+
timers.delete(call.timer);
|
|
114
|
+
fire();
|
|
115
|
+
}, call.ms);
|
|
116
|
+
timers.set(call.timer, { handle, repeat: call.repeat });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
case "Api": {
|
|
120
|
+
const call = effect.call;
|
|
121
|
+
if (call.op === "quote") {
|
|
122
|
+
const reply = { type: "QuoteReplied", flight: call.flight };
|
|
123
|
+
intentAPI.getQuote(call.request, { forceRefresh: call.forceRefresh }).then(
|
|
124
|
+
(quote) => dispatch({ ...reply, result: { ok: true, quote } }),
|
|
125
|
+
(err) => dispatch({ ...reply, result: fail(err) })
|
|
126
|
+
);
|
|
127
|
+
} else if (call.op === "execute") {
|
|
128
|
+
const reply = { type: "ExecuteReplied", flow: call.flow };
|
|
129
|
+
intentAPI.execute(call.request).then(
|
|
130
|
+
({ readToken: _readToken, ...response }) => dispatch({ ...reply, result: { ok: true, response } }),
|
|
131
|
+
(err) => dispatch({ ...reply, result: fail(err) })
|
|
132
|
+
);
|
|
133
|
+
} else {
|
|
134
|
+
const reply = { type: "StatusReplied", gen: call.gen, attempt: call.attempt };
|
|
135
|
+
intentAPI.getIntentStatus(call.intentId).then(
|
|
136
|
+
(status) => dispatch({ ...reply, result: { ok: true, status } }),
|
|
137
|
+
(err) => dispatch({ ...reply, result: fail(err) })
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
case "Wallet": {
|
|
143
|
+
const call = effect.call;
|
|
144
|
+
if (call.op === "ensureSession") {
|
|
145
|
+
const reply = { type: "SessionReplied", flight: call.flight };
|
|
146
|
+
const wallet = rt.model.ctx.wallet.address;
|
|
147
|
+
if (!call.interactive && !(wallet && hasWalletSession(wallet))) {
|
|
148
|
+
dispatch({ ...reply, result: "skipped" });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
io.ensureSession().then(
|
|
152
|
+
(token) => dispatch({ ...reply, result: token ? "ok" : "refused" }),
|
|
153
|
+
(err) => {
|
|
154
|
+
console.error("[useIntent] Wallet sign-in failed:", err);
|
|
155
|
+
dispatch({ ...reply, result: "refused" });
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
} else if (call.op === "signTypedData") {
|
|
159
|
+
const reply = { type: "SignReplied", flow: call.flow, purpose: call.purpose };
|
|
160
|
+
const prepared = prepareTypedDataForSigning(call.typedData, call.chainId ?? void 0);
|
|
161
|
+
io.signTypedDataAsync(prepared).then(
|
|
162
|
+
(signature) => {
|
|
163
|
+
const current = rt.bindings;
|
|
164
|
+
if (current?.settlementAuthorized && current.ctxKey === io.ctxKey) {
|
|
165
|
+
dispatch({ ...reply, result: { ok: true, signature } });
|
|
166
|
+
} else {
|
|
167
|
+
rejectStaleWalletReply();
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
(err) => {
|
|
171
|
+
const current = rt.bindings;
|
|
172
|
+
if (current?.settlementAuthorized && current.ctxKey === io.ctxKey) {
|
|
173
|
+
dispatch({ ...reply, result: fail(err) });
|
|
174
|
+
} else {
|
|
175
|
+
rejectStaleWalletReply();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
} else if (call.op === "ensureApproval") {
|
|
180
|
+
const reply = { type: "ApprovalReplied", flow: call.flow };
|
|
181
|
+
io.ensureApproval(BigInt(call.amount)).then(
|
|
182
|
+
(approved) => {
|
|
183
|
+
const current = rt.bindings;
|
|
184
|
+
if (current?.settlementAuthorized && current.ctxKey === io.ctxKey) {
|
|
185
|
+
dispatch({ ...reply, result: { ok: true, approved } });
|
|
186
|
+
} else {
|
|
187
|
+
rejectStaleWalletReply();
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
(err) => {
|
|
191
|
+
const current = rt.bindings;
|
|
192
|
+
if (current?.settlementAuthorized && current.ctxKey === io.ctxKey) {
|
|
193
|
+
dispatch({ ...reply, result: fail(err) });
|
|
194
|
+
} else {
|
|
195
|
+
rejectStaleWalletReply();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
} else {
|
|
200
|
+
io.resetApproval();
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const rt = {
|
|
207
|
+
model: initial,
|
|
208
|
+
live: true,
|
|
209
|
+
executionIntentId: null,
|
|
210
|
+
failureSubstatus: null,
|
|
211
|
+
bindings: null,
|
|
212
|
+
dispatch,
|
|
213
|
+
allocate: () => new Promise((resolve) => {
|
|
214
|
+
refs += 1;
|
|
215
|
+
const ref = `alloc${refs}`;
|
|
216
|
+
allocations.set(ref, resolve);
|
|
217
|
+
dispatch({ type: "AllocateRequested", key: crypto.randomUUID(), ref });
|
|
218
|
+
}),
|
|
219
|
+
stop: () => {
|
|
220
|
+
rt.live = false;
|
|
221
|
+
for (const timer of [...timers.keys()]) clearTimer(timer);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
return rt;
|
|
225
|
+
}
|
|
226
|
+
function useIntent(params) {
|
|
227
|
+
const { address, connector, chainId } = useAccount();
|
|
228
|
+
const stepwise = !!connector && (connector.type === "walletConnect" || connector.id === "walletConnect");
|
|
229
|
+
const { signTypedDataAsync } = useSignTypedData();
|
|
230
|
+
const { ensureSession } = useWalletSession();
|
|
231
|
+
const {
|
|
232
|
+
fromChainId,
|
|
233
|
+
toChainId,
|
|
234
|
+
fromToken,
|
|
235
|
+
toToken,
|
|
236
|
+
settlementPreference,
|
|
237
|
+
recipientAddress,
|
|
238
|
+
recipientTag,
|
|
239
|
+
refundAddress,
|
|
240
|
+
stealthMetaAddress,
|
|
241
|
+
ref,
|
|
242
|
+
promo
|
|
243
|
+
} = params;
|
|
244
|
+
const trustScore = params.trustScore ?? 0;
|
|
245
|
+
const slippageBps = params.slippageBps ?? 50;
|
|
246
|
+
const settlementAuthorized = params.settlementAuthorized;
|
|
247
|
+
const isDepositOrigin = !isChainId(fromChainId);
|
|
248
|
+
const ctx = {
|
|
249
|
+
fromChainId,
|
|
250
|
+
toChainId,
|
|
251
|
+
fromToken,
|
|
252
|
+
toToken,
|
|
253
|
+
settlementPreference,
|
|
254
|
+
trustScore,
|
|
255
|
+
slippageBps,
|
|
256
|
+
recipientAddress: recipientAddress ?? null,
|
|
257
|
+
recipientTag: recipientTag ?? null,
|
|
258
|
+
refundAddress: refundAddress ?? null,
|
|
259
|
+
stealthMetaAddress: stealthMetaAddress ?? null,
|
|
260
|
+
ref: ref ?? null,
|
|
261
|
+
promo: promo ?? null,
|
|
262
|
+
paused: params.paused ?? false,
|
|
263
|
+
wallet: { address: address ?? null, chainId: chainId ?? null, stepwise }
|
|
264
|
+
};
|
|
265
|
+
const { paused: _paused, wallet: _wallet, ...trade } = ctx;
|
|
266
|
+
const quoteKey = JSON.stringify([trade, address, chainId]);
|
|
267
|
+
const ctxKey = JSON.stringify(ctx);
|
|
268
|
+
const [rt] = useState(
|
|
269
|
+
() => createRuntime(
|
|
270
|
+
init(
|
|
271
|
+
{
|
|
272
|
+
solverPin: SOLVER_PIN,
|
|
273
|
+
pullRecipients: PULL_RECIPIENTS,
|
|
274
|
+
depositAttestationSigner: DEPOSIT_ATTESTATION_PIN.signer || null,
|
|
275
|
+
// Off, no escrow quote can bind: every one is refused at ingest.
|
|
276
|
+
...{}
|
|
277
|
+
},
|
|
278
|
+
ctx,
|
|
279
|
+
document.hidden
|
|
280
|
+
)
|
|
281
|
+
)
|
|
282
|
+
);
|
|
283
|
+
const [model, setModel] = useState(rt.model);
|
|
284
|
+
const approvalQuote = useRef({ quote: model.intent.quote, revision: 0 });
|
|
285
|
+
if (approvalQuote.current.quote !== model.intent.quote) {
|
|
286
|
+
approvalQuote.current = {
|
|
287
|
+
quote: model.intent.quote,
|
|
288
|
+
revision: approvalQuote.current.revision + 1
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const dispatch = rt.dispatch;
|
|
292
|
+
const permit = usePermit({
|
|
293
|
+
token: fromToken,
|
|
294
|
+
chainId: isChainId(fromChainId) ? fromChainId : PERMIT_PLACEHOLDER_CHAIN,
|
|
295
|
+
pullAuthorization: model.intent.quote?.pullAuthorization,
|
|
296
|
+
servedMethod: model.intent.quote?.paymentMethod,
|
|
297
|
+
amount: model.intent.quotedFromAmount || model.intent.quote?.eip712Data?.message?.fromAmount || null,
|
|
298
|
+
enabled: !isDepositOrigin,
|
|
299
|
+
approvalContext: JSON.stringify([
|
|
300
|
+
approvalQuote.current.revision,
|
|
301
|
+
model.intent.quoteId,
|
|
302
|
+
model.amount,
|
|
303
|
+
quoteKey
|
|
304
|
+
])
|
|
305
|
+
});
|
|
306
|
+
const previousCeremony = useRef({ sign: model.sign, status: model.intent.status });
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
const previous = previousCeremony.current;
|
|
309
|
+
if (previous.status === "signing" && model.intent.status !== "signing" || previous.sign && !model.sign && (!model.awaitingPull || previous.sign.origin === "pull")) {
|
|
310
|
+
permit.setUnlimitedApproval(false);
|
|
311
|
+
}
|
|
312
|
+
previousCeremony.current = { sign: model.sign, status: model.intent.status };
|
|
313
|
+
}, [model.sign, model.awaitingPull, model.intent.status, permit.setUnlimitedApproval]);
|
|
314
|
+
rt.bindings = {
|
|
315
|
+
ctx,
|
|
316
|
+
ctxKey,
|
|
317
|
+
settlementAuthorized,
|
|
318
|
+
manualQuoteRefresh: params.manualQuoteRefresh === true,
|
|
319
|
+
render: setModel,
|
|
320
|
+
signTypedDataAsync,
|
|
321
|
+
ensureSession,
|
|
322
|
+
ensureApproval: permit.ensureApproval,
|
|
323
|
+
resetApproval: permit.reset
|
|
324
|
+
};
|
|
325
|
+
useEffect(() => {
|
|
326
|
+
rt.live = true;
|
|
327
|
+
return rt.stop;
|
|
328
|
+
}, [rt]);
|
|
329
|
+
useEffect(() => {
|
|
330
|
+
dispatch({ type: "ContextChanged", ctx });
|
|
331
|
+
}, [ctxKey, dispatch]);
|
|
332
|
+
useEffect(() => {
|
|
333
|
+
const onVisibility = () => dispatch({ type: "VisibilityChanged" });
|
|
334
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
335
|
+
return () => document.removeEventListener("visibilitychange", onVisibility);
|
|
336
|
+
}, [dispatch]);
|
|
337
|
+
const onStreamStatus = useCallback(
|
|
338
|
+
(message) => dispatch({ type: "StreamStatus", message }),
|
|
339
|
+
[dispatch]
|
|
340
|
+
);
|
|
341
|
+
const { raceEvents } = useIntentStream(
|
|
342
|
+
model.intent.quote?.streamTopic,
|
|
343
|
+
POLL_INFLIGHT_STATES.includes(model.intent.status),
|
|
344
|
+
onStreamStatus
|
|
345
|
+
);
|
|
346
|
+
const fillMs = useMemo(() => {
|
|
347
|
+
const won = raceEvents.find((e) => e.type === "race_won" && e.elapsedMs != null);
|
|
348
|
+
return won?.elapsedMs ?? model.clientFillMs;
|
|
349
|
+
}, [raceEvents, model.clientFillMs]);
|
|
350
|
+
const tier = useTierInfo(trustScore);
|
|
351
|
+
const receipt = useMemo(() => view(model), [model]);
|
|
352
|
+
const previousQuoteKey = useRef(quoteKey);
|
|
353
|
+
const requestQuote = useCallback(
|
|
354
|
+
(amount) => {
|
|
355
|
+
if (settlementAuthorized) dispatch({ type: "QuoteRequested", amount });
|
|
356
|
+
permit.setUnlimitedApproval(false);
|
|
357
|
+
},
|
|
358
|
+
[dispatch, quoteKey, ensureSession, settlementAuthorized, permit.setUnlimitedApproval]
|
|
359
|
+
);
|
|
360
|
+
const allocateDepositRoute = useCallback(
|
|
361
|
+
() => settlementAuthorized ? rt.allocate() : Promise.resolve(false),
|
|
362
|
+
[rt, settlementAuthorized]
|
|
363
|
+
);
|
|
364
|
+
const sign = useCallback(() => {
|
|
365
|
+
if (settlementAuthorized) dispatch({ type: "SignRequested" });
|
|
366
|
+
if (rt.model.intent.status !== "signing") permit.setUnlimitedApproval(false);
|
|
367
|
+
}, [dispatch, settlementAuthorized, rt, permit.setUnlimitedApproval]);
|
|
368
|
+
const cancelSign = useCallback(() => {
|
|
369
|
+
if (rt.model.intent.status !== "signing") return false;
|
|
370
|
+
permit.setUnlimitedApproval(false);
|
|
371
|
+
dispatch({ type: "CancelSignRequested" });
|
|
372
|
+
return rt.model.intent.status !== "signing";
|
|
373
|
+
}, [rt, dispatch, permit.setUnlimitedApproval]);
|
|
374
|
+
const signPull = useCallback(() => {
|
|
375
|
+
if (settlementAuthorized) dispatch({ type: "PullSignRequested" });
|
|
376
|
+
}, [dispatch, settlementAuthorized]);
|
|
377
|
+
const reset = useCallback(() => {
|
|
378
|
+
permit.setUnlimitedApproval(false);
|
|
379
|
+
dispatch({ type: "ResetRequested" });
|
|
380
|
+
}, [dispatch, permit.setUnlimitedApproval]);
|
|
381
|
+
const refreshQuote = useCallback(
|
|
382
|
+
(forceRefresh = false) => {
|
|
383
|
+
permit.setUnlimitedApproval(false);
|
|
384
|
+
if (settlementAuthorized) dispatch({ type: "RefreshRequested", forceRefresh });
|
|
385
|
+
},
|
|
386
|
+
[dispatch, settlementAuthorized, permit.setUnlimitedApproval]
|
|
387
|
+
);
|
|
388
|
+
useEffect(() => {
|
|
389
|
+
if (previousQuoteKey.current === quoteKey) return;
|
|
390
|
+
previousQuoteKey.current = quoteKey;
|
|
391
|
+
if (model.intent.status !== "signing") return;
|
|
392
|
+
dispatch({ type: "CancelSignRequested" });
|
|
393
|
+
const cancelledStatus = rt.model.intent.status;
|
|
394
|
+
if (cancelledStatus === "signing" || cancelledStatus === "quoted") {
|
|
395
|
+
dispatch({ type: "ResetRequested" });
|
|
396
|
+
}
|
|
397
|
+
}, [dispatch, model.intent.status, quoteKey, rt]);
|
|
398
|
+
useEffect(() => {
|
|
399
|
+
if (settlementAuthorized) return;
|
|
400
|
+
const status = model.intent.status;
|
|
401
|
+
if (status === "signing") {
|
|
402
|
+
dispatch({ type: "CancelSignRequested" });
|
|
403
|
+
const cancelledStatus = rt.model.intent.status;
|
|
404
|
+
if (cancelledStatus === "signing" || cancelledStatus === "quoted") {
|
|
405
|
+
dispatch({ type: "ResetRequested" });
|
|
406
|
+
}
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (status === "pending" || status === "quoting" || status === "quoted") {
|
|
410
|
+
dispatch({ type: "ResetRequested" });
|
|
411
|
+
}
|
|
412
|
+
}, [dispatch, model.intent.status, settlementAuthorized]);
|
|
413
|
+
const resume = useCallback(
|
|
414
|
+
(intentId, status, owner, depositDeadline) => dispatch({
|
|
415
|
+
type: "ResumeRequested",
|
|
416
|
+
intentId,
|
|
417
|
+
status,
|
|
418
|
+
owner,
|
|
419
|
+
depositDeadline: depositDeadline ?? null
|
|
420
|
+
}),
|
|
421
|
+
[dispatch]
|
|
422
|
+
);
|
|
423
|
+
const state = model.intent;
|
|
424
|
+
return {
|
|
425
|
+
// State
|
|
426
|
+
status: state.status,
|
|
427
|
+
quote: state.quote,
|
|
428
|
+
error: state.error,
|
|
429
|
+
refundReason: state.refundReason,
|
|
430
|
+
txHash: state.txHash,
|
|
431
|
+
receivingTxHash: state.receivingTxHash,
|
|
432
|
+
settlementTxHash: state.settlementTxHash,
|
|
433
|
+
settlementChainId: state.settlementChainId,
|
|
434
|
+
substatus: state.status === "failed" && rt.failureSubstatus?.intentId === state.intentId ? rt.failureSubstatus.substatus : state.substatus,
|
|
435
|
+
reconciling: state.reconciling,
|
|
436
|
+
intentId: state.intentId,
|
|
437
|
+
quoteId: state.quoteId,
|
|
438
|
+
quotedAddress: state.quotedAddress,
|
|
439
|
+
quotedFromAmount: state.quotedFromAmount,
|
|
440
|
+
attestedDeposit: state.attestedDeposit,
|
|
441
|
+
pollExhausted: state.pollExhausted,
|
|
442
|
+
legsWithheld: state.legsWithheld,
|
|
443
|
+
escrow: state.escrow,
|
|
444
|
+
receipt,
|
|
445
|
+
notExecuted: state.status === "failed" && receipt.phase === "failed" && state.intentId !== null && rt.executionIntentId === state.intentId,
|
|
446
|
+
// Derived state
|
|
447
|
+
isLoading: LOADING_STATES.includes(state.status),
|
|
448
|
+
canSign: canSignQuote(state.status, state.quote),
|
|
449
|
+
canAllocateDepositRoute: canAllocateDepositQuote(
|
|
450
|
+
!!address,
|
|
451
|
+
isDepositOrigin,
|
|
452
|
+
state.status,
|
|
453
|
+
state.quote
|
|
454
|
+
),
|
|
455
|
+
feeRate: tier.feeRateFormatted,
|
|
456
|
+
tierName: tier.tierName,
|
|
457
|
+
// Approval state (origin pull, from usePermit)
|
|
458
|
+
permitType: permit.permitType,
|
|
459
|
+
approval: permit.approval,
|
|
460
|
+
approvalMayNeedReset: permit.approvalMayNeedReset,
|
|
461
|
+
isApproving: permit.isApproving,
|
|
462
|
+
unlimitedApproval: permit.unlimitedApproval,
|
|
463
|
+
setUnlimitedApproval: permit.setUnlimitedApproval,
|
|
464
|
+
// Actions
|
|
465
|
+
requestQuote,
|
|
466
|
+
allocateDepositRoute,
|
|
467
|
+
sign,
|
|
468
|
+
cancelSign,
|
|
469
|
+
signPull,
|
|
470
|
+
reset,
|
|
471
|
+
resume,
|
|
472
|
+
// Two-step (deep-link) signing: the confirm modal renders a "Sign 2 of 2"
|
|
473
|
+
// affordance while awaitingPull, calling signPull on tap.
|
|
474
|
+
awaitingPull: model.awaitingPull,
|
|
475
|
+
isSigningPull: model.isSigningPull,
|
|
476
|
+
// Quote refresh
|
|
477
|
+
quoteExpiresIn: model.quoteExpiresIn,
|
|
478
|
+
refreshQuote,
|
|
479
|
+
raceEvents,
|
|
480
|
+
fillMs
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
export {
|
|
484
|
+
useIntent
|
|
485
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import { STATUS_POLL_FLAT_CEILING_ATTEMPTS, STATUS_POLL_MS } from "@xochi/client";
|
|
3
|
+
function useIntentStatusPoll({
|
|
4
|
+
active,
|
|
5
|
+
key,
|
|
6
|
+
label,
|
|
7
|
+
onPoll,
|
|
8
|
+
ceiling,
|
|
9
|
+
onExhausted,
|
|
10
|
+
immediate = true
|
|
11
|
+
}) {
|
|
12
|
+
const onPollRef = useRef(onPoll);
|
|
13
|
+
onPollRef.current = onPoll;
|
|
14
|
+
const ceilingRef = useRef(ceiling);
|
|
15
|
+
ceilingRef.current = ceiling;
|
|
16
|
+
const onExhaustedRef = useRef(onExhausted);
|
|
17
|
+
onExhaustedRef.current = onExhausted;
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!active) return;
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
let polls = 0;
|
|
22
|
+
let spent = 0;
|
|
23
|
+
const stop = () => {
|
|
24
|
+
controller.abort();
|
|
25
|
+
clearInterval(timer);
|
|
26
|
+
};
|
|
27
|
+
const maxAttempts = ceilingRef.current?.() ?? STATUS_POLL_FLAT_CEILING_ATTEMPTS;
|
|
28
|
+
const tick = async (elapsedInterval) => {
|
|
29
|
+
if (controller.signal.aborted) return;
|
|
30
|
+
polls += 1;
|
|
31
|
+
if (elapsedInterval) spent += 1;
|
|
32
|
+
const attempt = polls;
|
|
33
|
+
let verdict;
|
|
34
|
+
try {
|
|
35
|
+
verdict = await onPollRef.current({ attempt, signal: controller.signal });
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error(`[${label}] status poll threw; counting the attempt`, err);
|
|
38
|
+
verdict = void 0;
|
|
39
|
+
}
|
|
40
|
+
if (controller.signal.aborted) return;
|
|
41
|
+
if (verdict === "stop") {
|
|
42
|
+
stop();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (verdict === "progress") {
|
|
46
|
+
spent = 0;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (spent >= maxAttempts) {
|
|
50
|
+
stop();
|
|
51
|
+
console.warn(
|
|
52
|
+
`[${label}] status poll stopped after ~${Math.round(spent * STATUS_POLL_MS / 1e3)}s with no observable change (${spent} intervals, ${polls} polls); leaving resolution to reconciliation/webhooks`
|
|
53
|
+
);
|
|
54
|
+
onExhaustedRef.current?.();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const onVisible = () => {
|
|
58
|
+
if (!document.hidden) void tick(false);
|
|
59
|
+
};
|
|
60
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
61
|
+
const timer = setInterval(() => void tick(true), STATUS_POLL_MS);
|
|
62
|
+
if (immediate) void tick(false);
|
|
63
|
+
return () => {
|
|
64
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
65
|
+
stop();
|
|
66
|
+
};
|
|
67
|
+
}, [active, key, label, immediate]);
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
useIntentStatusPoll
|
|
71
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from "react";
|
|
2
|
+
import { API_URL } from "../config.js";
|
|
3
|
+
import { isRaceWebSocketMessage, mapStatusFrame } from "@xochi/client";
|
|
4
|
+
const BASE_DELAY_MS = 1e3;
|
|
5
|
+
const MULTIPLIER = 1.8;
|
|
6
|
+
const MAX_ATTEMPTS = 6;
|
|
7
|
+
const MAX_RACE_EVENTS = 64;
|
|
8
|
+
const TOPIC_PATTERN = /^[A-Za-z0-9_-]{16,64}$/;
|
|
9
|
+
function streamUrl(topic) {
|
|
10
|
+
return `${API_URL.replace(/^http/, "ws")}/api/stream/${topic}`;
|
|
11
|
+
}
|
|
12
|
+
function useIntentStream(streamTopic, active, onStatus) {
|
|
13
|
+
const [raceEvents, setRaceEvents] = useState([]);
|
|
14
|
+
const [connected, setConnected] = useState(false);
|
|
15
|
+
const onStatusRef = useRef(onStatus);
|
|
16
|
+
onStatusRef.current = onStatus;
|
|
17
|
+
const lastTopicRef = useRef(streamTopic);
|
|
18
|
+
if (streamTopic !== lastTopicRef.current) {
|
|
19
|
+
lastTopicRef.current = streamTopic;
|
|
20
|
+
if (raceEvents.length > 0) setRaceEvents([]);
|
|
21
|
+
}
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!streamTopic || !active) return;
|
|
24
|
+
if (!TOPIC_PATTERN.test(streamTopic)) return;
|
|
25
|
+
const topic = streamTopic;
|
|
26
|
+
let ws = null;
|
|
27
|
+
let attempts = 0;
|
|
28
|
+
let closed = false;
|
|
29
|
+
let timer;
|
|
30
|
+
let lastRevision = null;
|
|
31
|
+
const scheduleReconnect = () => {
|
|
32
|
+
if (closed || attempts >= MAX_ATTEMPTS) return;
|
|
33
|
+
const delay = BASE_DELAY_MS * Math.pow(MULTIPLIER, attempts);
|
|
34
|
+
attempts += 1;
|
|
35
|
+
timer = setTimeout(connect, delay);
|
|
36
|
+
};
|
|
37
|
+
const handleMessage = (raw) => {
|
|
38
|
+
let msg;
|
|
39
|
+
try {
|
|
40
|
+
msg = JSON.parse(String(raw));
|
|
41
|
+
} catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (isRaceWebSocketMessage(msg)) {
|
|
45
|
+
setRaceEvents((prev) => {
|
|
46
|
+
const key = `${msg.type}:${msg.solver ?? ""}:${msg.amountOut ?? ""}`;
|
|
47
|
+
if (prev.some((e) => `${e.type}:${e.solver ?? ""}:${e.amountOut ?? ""}` === key)) {
|
|
48
|
+
return prev;
|
|
49
|
+
}
|
|
50
|
+
const next = [...prev, msg];
|
|
51
|
+
return next.length > MAX_RACE_EVENTS ? next.slice(-MAX_RACE_EVENTS) : next;
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const status = mapStatusFrame(msg, lastRevision);
|
|
56
|
+
if (!status) return;
|
|
57
|
+
if (status.revision !== null) lastRevision = status.revision;
|
|
58
|
+
if (status.message) onStatusRef.current(status.message);
|
|
59
|
+
};
|
|
60
|
+
const connect = () => {
|
|
61
|
+
if (closed) return;
|
|
62
|
+
try {
|
|
63
|
+
ws = new WebSocket(streamUrl(topic));
|
|
64
|
+
} catch {
|
|
65
|
+
scheduleReconnect();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
ws.onopen = () => {
|
|
69
|
+
attempts = 0;
|
|
70
|
+
setConnected(true);
|
|
71
|
+
};
|
|
72
|
+
ws.onmessage = (ev) => handleMessage(ev.data);
|
|
73
|
+
ws.onclose = () => {
|
|
74
|
+
setConnected(false);
|
|
75
|
+
scheduleReconnect();
|
|
76
|
+
};
|
|
77
|
+
ws.onerror = () => {
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
connect();
|
|
81
|
+
return () => {
|
|
82
|
+
closed = true;
|
|
83
|
+
if (timer) clearTimeout(timer);
|
|
84
|
+
setConnected(false);
|
|
85
|
+
try {
|
|
86
|
+
ws?.close();
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}, [streamTopic, active]);
|
|
91
|
+
return { raceEvents, connected };
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
useIntentStream
|
|
95
|
+
};
|