@funkit/connect 10.6.0 → 11.1.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/clients/{chunk-F6P4CN27.js → chunk-2QYQNTOI.js} +161 -18
  3. package/dist/clients/chunk-5MY7WMEJ.js +20 -0
  4. package/dist/clients/chunk-63XTVHO3.js +19 -0
  5. package/dist/clients/chunk-6T6URLBM.js +33 -0
  6. package/dist/clients/chunk-A44M6EAG.js +160 -0
  7. package/dist/clients/chunk-A6OXZWCN.js +40 -0
  8. package/dist/clients/chunk-BPDLF2R6.js +31 -0
  9. package/dist/clients/chunk-C53FRCUM.js +190 -0
  10. package/dist/clients/{chunk-6PIIYPQK.js → chunk-EJKHMZW3.js} +4 -327
  11. package/dist/clients/chunk-FAYBQQNB.js +15 -0
  12. package/dist/clients/{chunk-3LJQTM37.js → chunk-FNB7OPJI.js} +12 -198
  13. package/dist/clients/{chunk-2NBYHUIW.js → chunk-HZP4DXIZ.js} +1 -0
  14. package/dist/clients/chunk-NAVU6W7V.js +89 -0
  15. package/dist/clients/{chunk-BNMZM23Q.js → chunk-OJZNF6EM.js} +2 -2
  16. package/dist/clients/{chunk-FJ6GCMJ4.js → chunk-OODIKHYE.js} +3 -1
  17. package/dist/clients/chunk-PENJ5JGH.js +331 -0
  18. package/dist/clients/{chunk-TG2AACP2.js → chunk-QIMCURVA.js} +10 -10
  19. package/dist/clients/{chunk-YFHTV7DT.js → chunk-SH3MHRHX.js} +1 -1
  20. package/dist/clients/chunk-SO756ELD.js +35 -0
  21. package/dist/clients/chunk-SYFHMTUO.js +106 -0
  22. package/dist/clients/chunk-WVM4ZJD2.js +61 -0
  23. package/dist/clients/{chunk-L2KSNS7H.js → chunk-WZRW6WUM.js} +1 -1
  24. package/dist/clients/chunk-YMGRBJAS.js +302 -0
  25. package/dist/clients/chunk-YZSO4EMO.js +44 -0
  26. package/dist/clients/{chunk-2YWQL3AO.js → chunk-Z7HTQFEO.js} +26 -3
  27. package/dist/clients/fanatics.js +6 -6
  28. package/dist/clients/internal/nado/encoding.d.ts +5 -2
  29. package/dist/clients/internal/nado/encoding.js +4 -25
  30. package/dist/clients/internal/nado/errors.d.ts +14 -1
  31. package/dist/clients/internal/nado/errors.js +7 -3
  32. package/dist/clients/internal/nado/fetch.js +2 -2
  33. package/dist/clients/internal/nado/gateway.d.ts +19 -41
  34. package/dist/clients/internal/nado/gateway.js +3 -9
  35. package/dist/clients/internal/nado/hooks.d.ts +8 -160
  36. package/dist/clients/internal/nado/hooks.js +13 -124
  37. package/dist/clients/internal/nado/indexer.js +3 -3
  38. package/dist/clients/internal/nado/typedData.js +4 -37
  39. package/dist/clients/internal/nado/withdrawalCallback.d.ts +20 -0
  40. package/dist/clients/internal/nado/withdrawalCallback.js +20 -0
  41. package/dist/clients/internal/nado/withdrawalConfig.d.ts +8 -3
  42. package/dist/clients/internal/nado/withdrawalConfig.js +8 -14
  43. package/dist/clients/internal/nado/withdrawalErrors.d.ts +14 -0
  44. package/dist/clients/internal/nado/withdrawalErrors.js +11 -0
  45. package/dist/clients/internal/nado/withdrawalForm.css +17529 -0
  46. package/dist/clients/internal/nado/withdrawalForm.d.ts +40 -0
  47. package/dist/clients/internal/nado/withdrawalForm.js +262 -0
  48. package/dist/clients/internal/nado/withdrawalStatus.d.ts +41 -0
  49. package/dist/clients/internal/nado/withdrawalStatus.js +231 -0
  50. package/dist/clients/internal/nado/withdrawalTypes.d.ts +28 -9
  51. package/dist/clients/lighter.css +18 -18
  52. package/dist/clients/lighter.d.ts +29 -1
  53. package/dist/clients/lighter.js +109 -100
  54. package/dist/clients/mallard.js +27 -5
  55. package/dist/clients/nado.d.ts +67 -0
  56. package/dist/clients/nado.js +73 -0
  57. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.css +60 -60
  58. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.js +11 -5
  59. package/dist/clients/polymarket/createPolymarketDepositConfig.js +3 -2
  60. package/dist/clients/polymarket/index.css +60 -60
  61. package/dist/clients/polymarket/index.js +11 -5
  62. package/dist/clients/polymarket/polymarket.js +2 -1
  63. package/dist/consts/customers.d.ts +1 -1
  64. package/dist/domains/swapped.d.ts +1 -10
  65. package/dist/hooks/track/analytics/events.d.ts +57 -0
  66. package/dist/hooks/track/analytics/mappers.d.ts +6 -0
  67. package/dist/hooks/track/analytics/useDepositAnalytics.d.ts +20 -0
  68. package/dist/hooks/track/useTrack.d.ts +2 -1
  69. package/dist/hooks/useTokenAndChainDropdown.d.ts +8 -1
  70. package/dist/index.d.ts +1 -1
  71. package/dist/index.js +3647 -2728
  72. package/dist/modals/WithdrawalModal/LighterWithdrawal.d.ts +20 -31
  73. package/dist/modals/WithdrawalModal/NadoWithdrawalSuccess.d.ts +20 -0
  74. package/dist/modals/WithdrawalModal/WithdrawAmountInput.d.ts +5 -9
  75. package/dist/providers/FunkitCheckoutContext/types.d.ts +61 -5
  76. package/dist/providers/GeneralWalletProvider.d.ts +1 -0
  77. package/dist/utils/customer.d.ts +349 -0
  78. package/dist/utils/withdrawal.d.ts +13 -6
  79. package/dist/wagmi/actions.d.ts +1 -1
  80. package/dist/wallets/Wallet.d.ts +21 -1
  81. package/dist/wallets/walletConnectors/index.js +43 -43
  82. package/package.json +4 -4
  83. package/dist/clients/chunk-A4WQS6QG.js +0 -207
  84. package/dist/clients/chunk-OZ3KD24N.js +0 -107
  85. package/dist/clients/internal/nado/products.d.ts +0 -36
  86. package/dist/clients/internal/nado/products.js +0 -19
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Orchestrates the Nado enter-amount screen: maps the selected symbol to a Nado
3
+ * product, tracks the borrow toggle, and exposes the withdrawable amount +
4
+ * sequencer fee in token units.
5
+ *
6
+ * - One-way dependency: never imports from `modals/`; WithdrawalContent maps
7
+ * these outputs onto its own props.
8
+ * - Every react-query call is a no-op (zero traffic) when the config isn't Nado.
9
+ */
10
+ import type { FunkitWithdrawalConfig } from '../../../providers/FunkitCheckoutContext';
11
+ import type { NadoWithdrawalCustomerData } from './withdrawalTypes';
12
+ /** Structurally matches the shared flow's `clientAmountToggle` (no modals import). */
13
+ export interface NadoAmountToggle {
14
+ label: string;
15
+ checked: boolean;
16
+ onChange(enabled: boolean): void;
17
+ }
18
+ export interface UseNadoWithdrawalFormResult {
19
+ isNado: boolean;
20
+ /** Borrow (spot leverage) checkbox, assembled here so shared code holds no Nado state. */
21
+ amountToggle: NadoAmountToggle | undefined;
22
+ /**
23
+ * Balance the screen shows and the Max button fills: Nado's own
24
+ * `max_withdrawable` with the fee added back. Borrowing can lift it above the
25
+ * spot balance.
26
+ */
27
+ withdrawableBalanceTokenUnits: string;
28
+ /** Sequencer fee in the selected product's token units; hard 0 outside Nado. */
29
+ sequencerFeeTokenAmount: number;
30
+ /** USD price of the selected source token (stables short-circuit to 1); undefined while loading. */
31
+ sourceTokenUsdPrice: number | undefined;
32
+ /** Submit-time customerData for the withdrawal callback; logs the decision. Undefined outside Nado. */
33
+ buildSubmitCustomerData(): NadoWithdrawalCustomerData | undefined;
34
+ }
35
+ export declare function useNadoWithdrawalForm(config: FunkitWithdrawalConfig | null,
36
+ /**
37
+ * The shared active dropdown item, by symbol. The product id is derived from
38
+ * it — tracking a second copy here would leave two selections to keep in sync.
39
+ */
40
+ selectedSourceToken: string | undefined): UseNadoWithdrawalFormResult;
@@ -0,0 +1,262 @@
1
+ "use client";
2
+ import {
3
+ useNadoFeeRates,
4
+ useNadoMaxWithdrawable
5
+ } from "../../chunk-SYFHMTUO.js";
6
+ import "../../chunk-OJZNF6EM.js";
7
+ import {
8
+ safeBigInt
9
+ } from "../../chunk-63XTVHO3.js";
10
+ import {
11
+ isNadoWithdrawalConfig
12
+ } from "../../chunk-A6OXZWCN.js";
13
+ import "../../chunk-SO756ELD.js";
14
+ import {
15
+ x18ToRawBaseUnit,
16
+ x18ToTokenUnits
17
+ } from "../../chunk-6T6URLBM.js";
18
+ import "../../chunk-A44M6EAG.js";
19
+ import "../../chunk-II5CZTBC.js";
20
+ import "../../chunk-WZRW6WUM.js";
21
+ import "../../chunk-Z7HTQFEO.js";
22
+ import {
23
+ useGeneralWallet
24
+ } from "../../chunk-BPDLF2R6.js";
25
+ import "../../chunk-5MY7WMEJ.js";
26
+ import "../../chunk-NAVU6W7V.js";
27
+ import {
28
+ useFunkitConfig
29
+ } from "../../chunk-C53FRCUM.js";
30
+ import {
31
+ useFunkitTranslation
32
+ } from "../../chunk-FAYBQQNB.js";
33
+ import "../../chunk-UPZNKPYU.js";
34
+ import "../../chunk-2QYQNTOI.js";
35
+ import {
36
+ logger
37
+ } from "../../chunk-AHYOV7AV.js";
38
+
39
+ // src/clients/internal/nado/withdrawalForm.ts
40
+ import { useEffect, useMemo, useState } from "react";
41
+ import { formatUnits } from "viem";
42
+
43
+ // src/hooks/useAssetPrice.ts
44
+ import {
45
+ getAssetPriceInfo
46
+ } from "@funkit/api-base";
47
+ import {
48
+ convertFunToRelayTokenAddress,
49
+ getRelayAssetPriceInfo
50
+ } from "@funkit/fun-relay";
51
+ import { skipToken, useQuery } from "@tanstack/react-query";
52
+
53
+ // src/hooks/useIsStablecoin.ts
54
+ import { useCallback } from "react";
55
+
56
+ // src/hooks/statsig/useDynamicConfig.ts
57
+ import {
58
+ useDynamicConfig as useCoreDynamicConfig
59
+ } from "@funkit/connect-core";
60
+
61
+ // src/hooks/useUserIpInfo.ts
62
+ import { useUserIpInfo as useCoreUserIpInfo } from "@funkit/connect-core";
63
+ function useUserIpInfo() {
64
+ const { isUserLoggedIn } = useGeneralWallet();
65
+ return useCoreUserIpInfo({ logger, enabled: isUserLoggedIn });
66
+ }
67
+
68
+ // src/hooks/statsig/useDynamicConfig.ts
69
+ var useDynamicConfig = (name, options) => {
70
+ const { userIpInfo } = useUserIpInfo();
71
+ return useCoreDynamicConfig(name, {
72
+ bypassCountryCode: options?.bypassCountryCode,
73
+ countryCode: userIpInfo?.alpha2
74
+ });
75
+ };
76
+
77
+ // src/hooks/useIsStablecoin.ts
78
+ var useIsStablecoin = () => {
79
+ const stablecoinSymbols = useDynamicConfig("stablecoinsymbols");
80
+ return useCallback(
81
+ (symbol) => stablecoinSymbols.some(
82
+ (s) => symbol.toLowerCase().includes(s.toLowerCase())
83
+ ),
84
+ [stablecoinSymbols]
85
+ );
86
+ };
87
+
88
+ // src/hooks/useAssetPrice.ts
89
+ async function getFormattedRelayAssetPriceInfo({
90
+ chainId,
91
+ assetTokenAddress
92
+ }) {
93
+ try {
94
+ const relayResponse = await getRelayAssetPriceInfo({
95
+ chainId,
96
+ address: convertFunToRelayTokenAddress(
97
+ assetTokenAddress,
98
+ Number(chainId)
99
+ )
100
+ });
101
+ return {
102
+ unitPrice: relayResponse.price,
103
+ amount: 1,
104
+ total: 1
105
+ };
106
+ } catch (error) {
107
+ logger.error("Unable to fetch token price from Relay", error);
108
+ throw error;
109
+ }
110
+ }
111
+ async function getAssetPriceInfoWithFallback({
112
+ apiKey,
113
+ chainId,
114
+ assetTokenAddress
115
+ }) {
116
+ try {
117
+ return await getAssetPriceInfo({
118
+ apiKey,
119
+ assetTokenAddress,
120
+ chainId,
121
+ logger
122
+ });
123
+ } catch (primaryError) {
124
+ logger.warn(
125
+ "Unable to fetch token price from Primary provider, trying fallback",
126
+ { primaryError }
127
+ );
128
+ return await getFormattedRelayAssetPriceInfo({ chainId, assetTokenAddress });
129
+ }
130
+ }
131
+ function useAssetAddressPrice({
132
+ chainId,
133
+ assetTokenAddress,
134
+ amount = 1,
135
+ refetchInterval = 1e4,
136
+ symbol,
137
+ enabled = true
138
+ }) {
139
+ const { apiKey } = useFunkitConfig();
140
+ const isStablecoin = useIsStablecoin();
141
+ const { data, error, isLoading } = useQuery({
142
+ queryKey: ["getAssetPriceInfo", chainId, assetTokenAddress],
143
+ queryFn: enabled && chainId && assetTokenAddress ? () => getAssetPriceInfoWithFallback({
144
+ apiKey,
145
+ chainId,
146
+ assetTokenAddress
147
+ }) : skipToken,
148
+ refetchInterval
149
+ });
150
+ const unitPrice = symbol && isStablecoin(symbol) ? 1 : data?.unitPrice;
151
+ return {
152
+ error,
153
+ isLoading,
154
+ price: unitPrice !== void 0 ? unitPrice * amount : void 0
155
+ };
156
+ }
157
+
158
+ // src/clients/internal/nado/withdrawalForm.ts
159
+ var PRICE_REFRESH_MS = 6e4;
160
+ function isNadoSourceToken(option) {
161
+ const decimals = option.asset?.decimals;
162
+ return option.customData?.type === "nado" && typeof decimals === "number" && Number.isInteger(decimals) && decimals >= 0;
163
+ }
164
+ function getMaxEnterableAmount({
165
+ maxWithdrawableX18,
166
+ sequencerFee,
167
+ decimals
168
+ }) {
169
+ const max = safeBigInt(maxWithdrawableX18, 0n);
170
+ if (max <= 0n || decimals === void 0) {
171
+ return "0";
172
+ }
173
+ const maxRaw = x18ToRawBaseUnit(max, decimals);
174
+ const feeRaw = x18ToRawBaseUnit(sequencerFee, decimals);
175
+ return formatUnits(maxRaw + feeRaw, decimals);
176
+ }
177
+ function getSequencerFee(feeRates, option) {
178
+ if (!option) {
179
+ return { x18: 0n, tokenAmount: 0 };
180
+ }
181
+ const x18 = safeBigInt(
182
+ feeRates?.withdraw_sequencer_fees?.[option.productId],
183
+ 0n
184
+ );
185
+ return { x18, tokenAmount: Number(x18ToTokenUnits(x18, option.decimals)) };
186
+ }
187
+ function useNadoWithdrawalForm(config, selectedSourceToken) {
188
+ const nadoConfig = isNadoWithdrawalConfig(config) ? config : void 0;
189
+ const isNado = !!nadoConfig;
190
+ const subaccount = nadoConfig?.customerConfig.subaccount;
191
+ const { t } = useFunkitTranslation();
192
+ const [spotLeverage, setSpotLeverage] = useState(false);
193
+ const { data: feeRates } = useNadoFeeRates(subaccount);
194
+ useEffect(() => {
195
+ setSpotLeverage(false);
196
+ }, [subaccount]);
197
+ const amountToggle = {
198
+ label: t("withdrawal.enableBorrowing"),
199
+ checked: spotLeverage,
200
+ onChange: setSpotLeverage
201
+ };
202
+ const sourceOptions = useMemo(
203
+ () => (nadoConfig?.sourceTokens ?? []).filter(isNadoSourceToken).map(({ asset, customData, symbol, iconSrc }) => ({
204
+ productId: customData.productId,
205
+ symbol,
206
+ decimals: asset.decimals,
207
+ tokenAddress: asset.tokenAddress,
208
+ tokenChainId: asset.tokenChainId,
209
+ iconSrc
210
+ })),
211
+ [nadoConfig?.sourceTokens]
212
+ );
213
+ const selectedOption = sourceOptions.find(
214
+ (option) => option.symbol === selectedSourceToken
215
+ );
216
+ const { price: sourceTokenUsdPrice } = useAssetAddressPrice({
217
+ chainId: selectedOption?.tokenChainId,
218
+ assetTokenAddress: selectedOption?.tokenAddress,
219
+ symbol: selectedOption?.symbol,
220
+ refetchInterval: PRICE_REFRESH_MS,
221
+ enabled: isNado
222
+ });
223
+ const { data: maxWithdrawableX18 } = useNadoMaxWithdrawable({
224
+ productId: selectedOption?.productId,
225
+ sender: subaccount,
226
+ spotLeverage
227
+ });
228
+ const sequencerFee = getSequencerFee(feeRates, selectedOption);
229
+ const withdrawableBalanceTokenUnits = getMaxEnterableAmount({
230
+ maxWithdrawableX18,
231
+ sequencerFee: sequencerFee.x18,
232
+ decimals: selectedOption?.decimals
233
+ });
234
+ const buildSubmitCustomerData = () => {
235
+ if (!isNado || !selectedOption) {
236
+ return void 0;
237
+ }
238
+ logger.info("nado:withdrawal:submit", {
239
+ productId: selectedOption.productId,
240
+ spotLeverage,
241
+ sequencerFeeTokenAmount: sequencerFee.tokenAmount,
242
+ selectedSourceToken: selectedOption
243
+ });
244
+ return {
245
+ customerName: "nado",
246
+ spotLeverage,
247
+ sequencerFeeTokenAmount: sequencerFee.tokenAmount,
248
+ selectedSourceToken: selectedOption
249
+ };
250
+ };
251
+ return {
252
+ isNado,
253
+ amountToggle: isNado ? amountToggle : void 0,
254
+ withdrawableBalanceTokenUnits,
255
+ sequencerFeeTokenAmount: sequencerFee.tokenAmount,
256
+ sourceTokenUsdPrice,
257
+ buildSubmitCustomerData
258
+ };
259
+ }
260
+ export {
261
+ useNadoWithdrawalForm
262
+ };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Follows a submitted Nado withdrawal through to the user's wallet.
3
+ *
4
+ * Nado sends to a Fun deposit address (UDA), and the eoa scanner records the
5
+ * arrival as a direct execution against the owner wallet rather than against the
6
+ * address, so this finds that DE in the wallet's recent list and follows its
7
+ * relay status.
8
+ */
9
+ import { type MergedMultiStepDirectExecution } from '@funkit/connect-core';
10
+ import { type Address } from 'viem';
11
+ export type NadoWithdrawalStatus = 'pending' | 'completed' | 'failed';
12
+ /** The destination-chain transaction that delivered the funds. */
13
+ export interface NadoWithdrawalCompletionTx {
14
+ chainId: string;
15
+ txHash: string;
16
+ /** Set when the destination isn't served by the default explorer. */
17
+ customRedirectUrl: string | undefined;
18
+ }
19
+ export interface NadoWithdrawalTracking {
20
+ status: NadoWithdrawalStatus;
21
+ /** Only once delivered — a failed withdrawal has no completion. */
22
+ completionTx: NadoWithdrawalCompletionTx | undefined;
23
+ }
24
+ export declare function useNadoWithdrawalStatus({ depositAddress, pollIntervalMs, }: {
25
+ /** UDA the sequencer was told to send to. */
26
+ depositAddress: Address | undefined;
27
+ pollIntervalMs: number;
28
+ }): NadoWithdrawalTracking;
29
+ /**
30
+ * Ours is the direct execution at this UDA that appeared after we started
31
+ * watching.
32
+ *
33
+ * - The scanner stamps the address it saw the transfer at into `sourceOfFund`
34
+ * (`eoa_scanner|eoa|0x…`), the only field on a DE carrying the full UDA —
35
+ * `clientMetadata.depositAddress` comes back null.
36
+ * - `knownTxHashes` excludes earlier withdrawals that reused the same UDA. With
37
+ * one withdrawal in flight per destination that identifies ours exactly; two
38
+ * concurrent ones to the same destination can't be told apart by any field a
39
+ * DE carries.
40
+ */
41
+ export declare function findDirectExecutionForDepositAddress(directExecutions: MergedMultiStepDirectExecution[] | undefined, depositAddress: Address | undefined, knownTxHashes: ReadonlySet<string>): MergedMultiStepDirectExecution | undefined;
@@ -0,0 +1,231 @@
1
+ "use client";
2
+ import {
3
+ useFunkitConfig
4
+ } from "../../chunk-C53FRCUM.js";
5
+ import "../../chunk-FAYBQQNB.js";
6
+ import {
7
+ useAccount
8
+ } from "../../chunk-UPZNKPYU.js";
9
+ import "../../chunk-2QYQNTOI.js";
10
+ import {
11
+ logger
12
+ } from "../../chunk-AHYOV7AV.js";
13
+
14
+ // src/clients/internal/nado/withdrawalStatus.ts
15
+ import {
16
+ getCompletionTxInfo,
17
+ processRecentDepositsForNotifications,
18
+ useRecentDepositsApiQuery
19
+ } from "@funkit/connect-core";
20
+ import { isEVMAddressEquivalent } from "@funkit/utils";
21
+ import { useEffect, useMemo, useRef, useState } from "react";
22
+ import { zeroHash } from "viem";
23
+
24
+ // src/hooks/useCheckoutDirectExecutionHistory.ts
25
+ import {
26
+ CheckoutRefundState,
27
+ CheckoutState,
28
+ RelayExecutionStatus
29
+ } from "@funkit/api-base";
30
+ import { mapRelayExecutionStatusToCheckoutState } from "@funkit/connect-core";
31
+
32
+ // src/utils/across.ts
33
+ var ACROSS_DELAYED_AUTO_TRIGGER_CUTOFF = 60 * 5;
34
+ function isAcrossRoute(metadata) {
35
+ return !!metadata?.across?.enabled;
36
+ }
37
+
38
+ // src/hooks/useDirectExecutionInfoPolling.ts
39
+ import {
40
+ getDirectExecutionByTxHash
41
+ } from "@funkit/api-base";
42
+ import { RELAY_TERMINAL_STATUSES } from "@funkit/fun-relay";
43
+ import { useQuery } from "@tanstack/react-query";
44
+ var RELAY_FETCH_INTERVAL = 1500;
45
+ var logPrefix = "useDirectExecutionInfoPolling";
46
+ function useDirectExecutionInfoPolling({
47
+ initDirectExecution,
48
+ disabled = false
49
+ }) {
50
+ const { apiKey } = useFunkitConfig();
51
+ const { data: directExecution, isLoading } = useQuery({
52
+ queryKey: [logPrefix, initDirectExecution?.txHash],
53
+ queryFn: async () => {
54
+ try {
55
+ const data = await getDirectExecutionByTxHash({
56
+ apiKey,
57
+ logger,
58
+ txHash: initDirectExecution?.txHash
59
+ // query is disabled if txHash not present
60
+ });
61
+ logger.log(`${logPrefix}:response`, data);
62
+ return data;
63
+ } catch (error) {
64
+ logger.error(`${logPrefix}:error`, error);
65
+ throw error;
66
+ }
67
+ },
68
+ refetchOnWindowFocus: false,
69
+ refetchInterval: (query) => {
70
+ const latestData = query.state.data;
71
+ if (latestData) {
72
+ const status = latestData.listenerInfo?.status || null;
73
+ if (status && RELAY_TERMINAL_STATUSES.includes(status)) {
74
+ return 0;
75
+ }
76
+ }
77
+ return RELAY_FETCH_INTERVAL;
78
+ },
79
+ initialData: initDirectExecution,
80
+ enabled: !disabled && !!initDirectExecution?.txHash && initDirectExecution.txHash !== "0x"
81
+ });
82
+ return {
83
+ directExecution,
84
+ isLoading
85
+ };
86
+ }
87
+
88
+ // src/hooks/useCheckoutDirectExecutionHistory.ts
89
+ function mapRelayExecutionStatusToRefundState(status) {
90
+ switch (status) {
91
+ case RelayExecutionStatus.REFUND:
92
+ return CheckoutRefundState.REFUNDED;
93
+ default:
94
+ return void 0;
95
+ }
96
+ }
97
+ function useCheckoutDirectExecutionHistory({
98
+ initDirectExecution,
99
+ disabled = false
100
+ }) {
101
+ const { directExecution } = useDirectExecutionInfoPolling({
102
+ initDirectExecution,
103
+ disabled
104
+ });
105
+ const status = directExecution?.listenerInfo?.status ?? RelayExecutionStatus.PENDING;
106
+ const latestQuote = directExecution?.clientMetadata.latestQuote;
107
+ const state = mapRelayExecutionStatusToCheckoutState(status);
108
+ const refundState = mapRelayExecutionStatusToRefundState(status);
109
+ const isDelayed = status === RelayExecutionStatus.DELAYED;
110
+ return {
111
+ state,
112
+ refundState,
113
+ isAcross: isAcrossRoute(latestQuote?.baseQuote.metadata),
114
+ isLayerZero: latestQuote && !!latestQuote.baseQuote.metadata?.oftEnabled,
115
+ isRefunded: refundState === CheckoutRefundState.REFUNDED,
116
+ isCompleted: state === CheckoutState.COMPLETED,
117
+ isFailed: state === CheckoutState.CHECKOUT_ERROR,
118
+ isDelayed,
119
+ isProcessing: state === CheckoutState.PENDING_RECEIVAL,
120
+ directExecution
121
+ };
122
+ }
123
+
124
+ // src/clients/internal/nado/withdrawalStatus.ts
125
+ var RECENT_DIRECT_EXECUTION_SCAN_SIZE = 5;
126
+ function useNadoWithdrawalStatus({
127
+ depositAddress,
128
+ pollIntervalMs
129
+ }) {
130
+ const { apiKey } = useFunkitConfig();
131
+ const { address: walletAddress } = useAccount();
132
+ const [hasSettled, setHasSettled] = useState(false);
133
+ const { data: recentDirectExecutions } = useRecentDepositsApiQuery({
134
+ isVisible: !hasSettled && !!depositAddress,
135
+ fetchSize: RECENT_DIRECT_EXECUTION_SCAN_SIZE,
136
+ apiKey,
137
+ userId: walletAddress ?? "",
138
+ refreshIntervalMs: pollIntervalMs,
139
+ logger
140
+ });
141
+ const mergedDirectExecutions = useMemo(
142
+ () => processRecentDepositsForNotifications(recentDirectExecutions),
143
+ [recentDirectExecutions]
144
+ );
145
+ const [knownTxHashes, setKnownTxHashes] = useState();
146
+ useEffect(() => {
147
+ if (!knownTxHashes && mergedDirectExecutions) {
148
+ setKnownTxHashes(
149
+ new Set(mergedDirectExecutions.map(({ txHash }) => txHash))
150
+ );
151
+ }
152
+ }, [knownTxHashes, mergedDirectExecutions]);
153
+ const ourDirectExecution = knownTxHashes ? findDirectExecutionForDepositAddress(
154
+ mergedDirectExecutions,
155
+ depositAddress,
156
+ knownTxHashes
157
+ ) : void 0;
158
+ const latestStep = ourDirectExecution?.latestStep ?? ourDirectExecution;
159
+ const isFinalStep = !!latestStep && !latestStep.isIntermediaryPhase;
160
+ const { isCompleted, isFailed } = useCheckoutDirectExecutionHistory({
161
+ initDirectExecution: latestStep,
162
+ disabled: !latestStep
163
+ });
164
+ const status = toNadoWithdrawalStatus({
165
+ isCompleted: isCompleted && isFinalStep,
166
+ isFailed
167
+ });
168
+ useEffect(() => {
169
+ if (status !== "pending") {
170
+ setHasSettled(true);
171
+ }
172
+ }, [status]);
173
+ const loggedStatusRef = useRef(void 0);
174
+ useEffect(() => {
175
+ if (status === "pending" || loggedStatusRef.current === status) {
176
+ return;
177
+ }
178
+ loggedStatusRef.current = status;
179
+ logger.info("nado:withdrawal:settled", {
180
+ depositAddress,
181
+ status,
182
+ txHash: latestStep?.txHash,
183
+ relayStatus: latestStep?.listenerInfo?.status
184
+ });
185
+ }, [status, depositAddress, latestStep]);
186
+ const completionTx = useMemo(() => {
187
+ if (status !== "completed" || !latestStep) {
188
+ return void 0;
189
+ }
190
+ const { chainId, txHash, customRedirectUrl } = getCompletionTxInfo(latestStep);
191
+ const onChainTxHash = resolveOnChainCompletionTxHash(latestStep, txHash);
192
+ return onChainTxHash ? { chainId, txHash: onChainTxHash, customRedirectUrl } : void 0;
193
+ }, [status, latestStep]);
194
+ return { status, completionTx };
195
+ }
196
+ function resolveOnChainCompletionTxHash(directExecution, completionTxHash) {
197
+ const hasDestinationTx = !!completionTxHash && completionTxHash !== directExecution.txHash && completionTxHash !== zeroHash;
198
+ if (directExecution.fromChainId !== directExecution.toChainId) {
199
+ return hasDestinationTx ? completionTxHash : void 0;
200
+ }
201
+ return hasDestinationTx ? completionTxHash : directExecution.onChainTxHash ?? directExecution.txHash;
202
+ }
203
+ function findDirectExecutionForDepositAddress(directExecutions, depositAddress, knownTxHashes) {
204
+ if (!depositAddress) {
205
+ return void 0;
206
+ }
207
+ return directExecutions?.find((directExecution) => {
208
+ if (knownTxHashes.has(directExecution.txHash)) {
209
+ return false;
210
+ }
211
+ const sourceSegments = directExecution.sourceOfFund?.split("|") ?? [];
212
+ const sourceAddress = sourceSegments[sourceSegments.length - 1];
213
+ return !!sourceAddress && isEVMAddressEquivalent({
214
+ firstAddress: sourceAddress,
215
+ secondAddress: depositAddress
216
+ });
217
+ });
218
+ }
219
+ function toNadoWithdrawalStatus({
220
+ isCompleted,
221
+ isFailed
222
+ }) {
223
+ if (isCompleted) {
224
+ return "completed";
225
+ }
226
+ return isFailed ? "failed" : "pending";
227
+ }
228
+ export {
229
+ findDirectExecutionForDepositAddress,
230
+ useNadoWithdrawalStatus
231
+ };
@@ -6,25 +6,44 @@
6
6
  * the shared→customer reference stays cycle-free.
7
7
  */
8
8
  import type { Address, Hex } from 'viem';
9
+ /**
10
+ * The dropdown pick, flattened out of the config's `sourceTokens`. Travels whole
11
+ * so identity, decimals, and product id can't be resolved from disagreeing
12
+ * sources — two lookups that disagree would sign against the wrong asset or off
13
+ * by a power of ten.
14
+ */
15
+ export interface NadoWithdrawalSourceOption {
16
+ /** Nado's own key for the asset — every subaccount query is keyed on it. */
17
+ productId: number;
18
+ symbol: string;
19
+ decimals: number;
20
+ tokenAddress: Address;
21
+ tokenChainId: string;
22
+ iconSrc: string | undefined;
23
+ }
9
24
  /**
10
25
  * Nado per-submission form selections threaded to the withdrawal callback (the
11
- * static config can't know them). `spotLeverage` must be explicit — Nado treats
12
- * an absent value as borrowing, so `false` fails instead of opening a borrow.
26
+ * static config can't know them).
27
+ * - `spotLeverage` must be explicit — Nado treats an absent value as borrowing,
28
+ * so `false` fails instead of opening a borrow.
29
+ * - `sequencerFeeTokenAmount` pins the fee the screen displayed, so the callback
30
+ * signs the same net amount instead of re-reading a possibly-refreshed cache.
31
+ * - `selectedSourceToken` is the live dropdown pick. The shared form data carries
32
+ * the config's static `sourceTokenSymbol` instead, which is stale for a
33
+ * multi-source flow.
13
34
  */
14
35
  export interface NadoWithdrawalCustomerData {
15
36
  customerName: 'nado';
16
- productId: number;
17
37
  spotLeverage: boolean;
38
+ /** Sequencer fee in the product's token units, as shown at submit. */
39
+ sequencerFeeTokenAmount: number;
40
+ selectedSourceToken: NadoWithdrawalSourceOption;
18
41
  }
19
- /**
20
- * Nado config-level identity — the hook's **output**, not integrator input.
21
- * `useNadoWithdrawalConfig` takes a `subaccountName` string and packs it into
22
- * `subaccount` (Hex); consumers never author this.
23
- */
42
+ /** Nado config-level identity, supplied by the integrator on the withdrawal config. */
24
43
  export interface NadoWithdrawalCustomerConfig {
25
44
  customerName: 'nado';
26
45
  /** Connected wallet — must be the signer (Nado rejects linked signers). */
27
- owner: Address;
46
+ walletAddress: Address;
28
47
  /** Packed id of the active subaccount (`buildNadoSubaccountId`); the EIP-712/execute `sender`. */
29
48
  subaccount: Hex;
30
49
  }
@@ -16527,6 +16527,24 @@
16527
16527
  flex: 1;
16528
16528
  }
16529
16529
 
16530
+ /* vanilla-extract-css-ns:src/components/FunTransactionSummary/PaymentFeesSummary.css.ts.vanilla.css?source=LnZrd3ZlMzIgewogIGN1cnNvcjogcG9pbnRlcjsKfQoudmt3dmUzMjpmb2N1cy12aXNpYmxlIHsKICBvdXRsaW5lOiAxcHggc29saWQ7CiAgb3V0bGluZS1jb2xvcjogdmFyKC0tcmstY29sb3JzLXRlcnRpYXJ5VGV4dCk7Cn0KLnZrd3ZlMzMgewogIHRyYW5zaXRpb246IGFsbCAwLjJzIGxpbmVhcjsKICB0cmFuc2l0aW9uLWRlbGF5OiAwLjJzOwogIG9wYWNpdHk6IDE7Cn0KLnZrd3ZlMzQgewogIHRyYW5zaXRpb246IGFsbCAwLjJzIGxpbmVhcjsKICBvcGFjaXR5OiAwOwp9 */
16531
+ [data-rk] .vkwve32 {
16532
+ cursor: pointer;
16533
+ }
16534
+ [data-rk] .vkwve32:focus-visible {
16535
+ outline: 1px solid;
16536
+ outline-color: var(--rk-colors-tertiaryText);
16537
+ }
16538
+ [data-rk] .vkwve33 {
16539
+ transition: all 0.2s linear;
16540
+ transition-delay: 0.2s;
16541
+ opacity: 1;
16542
+ }
16543
+ [data-rk] .vkwve34 {
16544
+ transition: all 0.2s linear;
16545
+ opacity: 0;
16546
+ }
16547
+
16530
16548
  /* vanilla-extract-css-ns:src/components/FunAssetAvatar/FunAssetAvatar.css.ts.vanilla.css?source=LnV3cmRjMjAgewogIHBvc2l0aW9uOiByZWxhdGl2ZTsKfQoudXdyZGMyMiB7CiAgcG9zaXRpb246IGFic29sdXRlOwp9 */
16531
16549
  [data-rk] .uwrdc20 {
16532
16550
  position: relative;
@@ -16881,24 +16899,6 @@
16881
16899
  overflow: hidden;
16882
16900
  }
16883
16901
 
16884
- /* vanilla-extract-css-ns:src/components/FunTransactionSummary/PaymentFeesSummary.css.ts.vanilla.css?source=LnZrd3ZlMzIgewogIGN1cnNvcjogcG9pbnRlcjsKfQoudmt3dmUzMjpmb2N1cy12aXNpYmxlIHsKICBvdXRsaW5lOiAxcHggc29saWQ7CiAgb3V0bGluZS1jb2xvcjogdmFyKC0tcmstY29sb3JzLXRlcnRpYXJ5VGV4dCk7Cn0KLnZrd3ZlMzMgewogIHRyYW5zaXRpb246IGFsbCAwLjJzIGxpbmVhcjsKICB0cmFuc2l0aW9uLWRlbGF5OiAwLjJzOwogIG9wYWNpdHk6IDE7Cn0KLnZrd3ZlMzQgewogIHRyYW5zaXRpb246IGFsbCAwLjJzIGxpbmVhcjsKICBvcGFjaXR5OiAwOwp9 */
16885
- [data-rk] .vkwve32 {
16886
- cursor: pointer;
16887
- }
16888
- [data-rk] .vkwve32:focus-visible {
16889
- outline: 1px solid;
16890
- outline-color: var(--rk-colors-tertiaryText);
16891
- }
16892
- [data-rk] .vkwve33 {
16893
- transition: all 0.2s linear;
16894
- transition-delay: 0.2s;
16895
- opacity: 1;
16896
- }
16897
- [data-rk] .vkwve34 {
16898
- transition: all 0.2s linear;
16899
- opacity: 0;
16900
- }
16901
-
16902
16902
  /* vanilla-extract-css-ns:src/components/PaddedScrollableArea/paddedScrollableArea.css.ts.vanilla.css?source=Ll8xczAzMWEwMCB7CiAgZmxleDogMTsKICBtaW4taGVpZ2h0OiAwOwogIG92ZXJmbG93LXg6IGhpZGRlbjsKICBvdmVyZmxvdy15OiBhdXRvOwogIHBvc2l0aW9uOiByZWxhdGl2ZTsKICBzY3JvbGxiYXItZ3V0dGVyOiBzdGFibGU7CiAgc2Nyb2xsYmFyLXdpZHRoOiB1bnNldDsKfQouXzFzMDMxYTAwOjotd2Via2l0LXNjcm9sbGJhciB7CiAgZGlzcGxheTogdW5zZXQ7CiAgd2lkdGg6IDZweDsKICBiYWNrZ3JvdW5kLWNvbG9yOiB2YXIoLS1yay1jb2xvcnMtbW9kYWxCYWNrZ3JvdW5kKTsKfQouXzFzMDMxYTAwOjotd2Via2l0LXNjcm9sbGJhci10aHVtYiB7CiAgYm9yZGVyLXJhZGl1czogdmFyKC0tcmstcmFkaWktbW9kYWwpOwogIGJhY2tncm91bmQtY29sb3I6IHZhcigtLXJrLWNvbG9ycy10ZXJ0aWFyeVRleHQpOwp9Ci5fMXMwMzFhMDA6Oi13ZWJraXQtc2Nyb2xsYmFyLXRyYWNrIHsKICBiYWNrZ3JvdW5kLWNvbG9yOiB2YXIoLS1yay1jb2xvcnMtbW9kYWxCYWNrZ3JvdW5kKTsKfQouXzFzMDMxYTAxOjotd2Via2l0LXNjcm9sbGJhci10aHVtYiB7CiAgYmFja2dyb3VuZC1jb2xvcjogdmFyKC0tcmstY29sb3JzLW1vZGFsQmFja2dyb3VuZCk7Cn0KLl8xczAzMWEwMTo6LXdlYmtpdC1zY3JvbGxiYXItdGh1bWI6aG92ZXIgewogIGJhY2tncm91bmQtY29sb3I6IHZhcigtLXJrLWNvbG9ycy1zZWNvbmRhcnlUZXh0KTsKfQ */
16903
16903
  [data-rk] ._1s031a00 {
16904
16904
  flex: 1;