@funkit/connect 11.7.0 → 12.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/{chunk-67BKQQNG.js → chunk-2RND3WWH.js} +1 -1
  3. package/dist/{chunk-L67HP4HQ.js → chunk-53FF4ZHH.js} +1 -1
  4. package/dist/{chunk-4YEAUICE.js → chunk-DH3DS4FX.js} +1 -0
  5. package/dist/clients/chunk-27VBRE7W.js +4907 -0
  6. package/dist/clients/{chunk-44USAVWK.js → chunk-37Q6DUR7.js} +2 -2
  7. package/dist/clients/chunk-3DHSLLCU.js +331 -0
  8. package/dist/clients/{chunk-I4B5AKZC.js → chunk-3J2GOB5X.js} +1 -1
  9. package/dist/clients/{chunk-OASVWVSV.js → chunk-A5JW3UI6.js} +1 -1
  10. package/dist/clients/chunk-BCNE3ZKM.js +190 -0
  11. package/dist/clients/chunk-BWJC2WD7.js +4899 -0
  12. package/dist/clients/{chunk-FGUMPXTO.js → chunk-DYV3LRSE.js} +1 -1
  13. package/dist/clients/{chunk-Y7WLUPTX.js → chunk-EQA5U4V6.js} +8 -8
  14. package/dist/clients/chunk-EYMFEWQL.js +30 -0
  15. package/dist/clients/chunk-FPOGADLJ.js +4899 -0
  16. package/dist/clients/chunk-HB7S3NDI.js +15 -0
  17. package/dist/clients/chunk-HDFCM5UL.js +15 -0
  18. package/dist/clients/{chunk-IYCZWLAF.js → chunk-IAIRECDV.js} +8 -37
  19. package/dist/clients/chunk-JVR4CX6N.js +296 -0
  20. package/dist/clients/chunk-NEKHTWTT.js +331 -0
  21. package/dist/clients/chunk-PA7WW6VC.js +296 -0
  22. package/dist/clients/chunk-R6UAC2TB.js +190 -0
  23. package/dist/clients/chunk-RHOSJED2.js +335 -0
  24. package/dist/clients/chunk-SKDFSMAO.js +30 -0
  25. package/dist/clients/chunk-TI2NG2Z6.js +30 -0
  26. package/dist/clients/chunk-TZFXFVDW.js +296 -0
  27. package/dist/clients/chunk-VE6QD5IM.js +149 -0
  28. package/dist/clients/chunk-VXX2XK5J.js +190 -0
  29. package/dist/clients/{chunk-SG4ZS447.js → chunk-WXSFLUPZ.js} +63 -15
  30. package/dist/clients/chunk-XSRAZSYG.js +15 -0
  31. package/dist/clients/fanatics.css +4686 -4659
  32. package/dist/clients/fanatics.js +7 -9
  33. package/dist/clients/internal/nado/withdrawalCallback.js +3 -3
  34. package/dist/clients/internal/nado/withdrawalErrors.js +2 -2
  35. package/dist/clients/internal/nado/withdrawalForm.css +4712 -4682
  36. package/dist/clients/internal/nado/withdrawalForm.js +37 -13
  37. package/dist/clients/internal/nado/withdrawalStatus.js +3 -3
  38. package/dist/clients/lighter.css +4712 -4682
  39. package/dist/clients/lighter.js +50 -30
  40. package/dist/clients/mallard.js +4 -4
  41. package/dist/clients/nado.js +3 -3
  42. package/dist/clients/polymarket/createPolymarketDepositConfig.d.ts +28 -19
  43. package/dist/clients/polymarket/createPolymarketDepositConfig.js +5 -4
  44. package/dist/clients/polymarket/index.d.ts +0 -1
  45. package/dist/clients/polymarket/index.js +4 -17
  46. package/dist/clients/polymarket/polymarket.d.ts +12 -27
  47. package/dist/clients/polymarket/polymarket.js +1 -1
  48. package/dist/components/AsyncImage/useAsyncImage.d.ts +2 -0
  49. package/dist/components/Box/Box.d.ts +15 -15
  50. package/dist/components/Dialog/Dialog.d.ts +8 -1
  51. package/dist/components/FunTransactionSummary/PaymentFeesSummary.d.ts +3 -1
  52. package/dist/components/FunTransactionSummary/PaymentFeesSummary.track.d.ts +10 -0
  53. package/dist/components/ModalHeaderTabs/ModalHeaderTabs.d.ts +23 -0
  54. package/dist/consts/polymarket.d.ts +14 -0
  55. package/dist/css/sprinkles.css.d.ts +17 -15
  56. package/dist/domains/polymarketPerps.d.ts +14 -0
  57. package/dist/hooks/queries/useFops.d.ts +3 -1
  58. package/dist/hooks/track/CheckoutModalEvent.d.ts +1 -0
  59. package/dist/hooks/track/analytics/events.d.ts +18 -0
  60. package/dist/hooks/track/analytics/quote.d.ts +3 -1
  61. package/dist/hooks/track/analytics/useWithdrawalAnalytics.d.ts +12 -1
  62. package/dist/hooks/useCheckoutTransferInit.d.ts +3 -1
  63. package/dist/hooks/useFittedText.d.ts +19 -0
  64. package/dist/hooks/usePolymarketAccountBalances.d.ts +13 -25
  65. package/dist/hooks/useUpdateActiveFunkitCheckout.d.ts +10 -0
  66. package/dist/index.css +4712 -4682
  67. package/dist/index.js +3271 -2247
  68. package/dist/modals/CheckoutModal/CheckoutModalPrefetchedHooks.d.ts +2 -1
  69. package/dist/modals/CheckoutModal/InputAmount/useAmountInput.d.ts +1 -0
  70. package/dist/modals/CheckoutModal/SourceChange/CryptoCashToggle.d.ts +6 -1
  71. package/dist/modals/PolymarketPerpsTransfer/DirectionSwapButton.d.ts +1 -11
  72. package/dist/modals/PolymarketPerpsTransfer/PerpsHeaderTabs.d.ts +29 -0
  73. package/dist/modals/PolymarketPerpsTransfer/PerpsTransferAmountInput.css.d.ts +9 -0
  74. package/dist/modals/PolymarketPerpsTransfer/PerpsTransferAmountInput.d.ts +15 -0
  75. package/dist/modals/PolymarketPerpsTransfer/PerpsTransferBody.d.ts +12 -0
  76. package/dist/modals/PolymarketPerpsTransfer/PolymarketPerpsPrefetch.d.ts +7 -0
  77. package/dist/modals/PolymarketPerpsTransfer/PolymarketPerpsTransferScreen.d.ts +16 -2
  78. package/dist/modals/PolymarketPerpsTransfer/TransferAccountsCard.d.ts +12 -0
  79. package/dist/modals/PolymarketPerpsTransfer/TransferActionButton.d.ts +8 -1
  80. package/dist/modals/PolymarketPerpsTransfer/TransferPercentOptions.d.ts +13 -0
  81. package/dist/modals/PolymarketPerpsTransfer/usePerpsHeaderTabsState.d.ts +28 -0
  82. package/dist/modals/PolymarketPerpsTransfer/usePerpsTransferForm.d.ts +31 -5
  83. package/dist/modals/WithdrawalModal/LighterWithdrawal.d.ts +6 -0
  84. package/dist/modals/WithdrawalModal/RecipientAddress.d.ts +0 -5
  85. package/dist/modals/WithdrawalModal/useWithdrawalChainPreference.d.ts +17 -0
  86. package/dist/modals/WithdrawalModal/withdrawalHooks.d.ts +2 -1
  87. package/dist/providers/FunkitCheckoutContext/index.d.ts +13 -1
  88. package/dist/providers/FunkitCheckoutContext/types.d.ts +30 -3
  89. package/dist/providers/FunkitThemeProvider.d.ts +3 -0
  90. package/dist/shadow-css.js +1 -1
  91. package/dist/themes/baseTheme.js +1 -1
  92. package/dist/themes/darkTheme.js +2 -2
  93. package/dist/themes/lightTheme.js +2 -2
  94. package/dist/wallets/walletConnectors/chunk-2VP2F6EK.js +70 -0
  95. package/dist/wallets/walletConnectors/chunk-4T6ZSRJF.js +69 -0
  96. package/dist/wallets/walletConnectors/chunk-6BW3HLBG.js +96 -0
  97. package/dist/wallets/walletConnectors/chunk-CCQV2ZET.js +218 -0
  98. package/dist/wallets/walletConnectors/chunk-CPI4TD43.js +99 -0
  99. package/dist/wallets/walletConnectors/chunk-F5XEEVG6.js +98 -0
  100. package/dist/wallets/walletConnectors/chunk-HNRB7KJU.js +92 -0
  101. package/dist/wallets/walletConnectors/chunk-HTHAK6XB.js +93 -0
  102. package/dist/wallets/walletConnectors/chunk-MIQTHJ6X.js +66 -0
  103. package/dist/wallets/walletConnectors/chunk-RB3HR4R2.js +95 -0
  104. package/dist/wallets/walletConnectors/chunk-RVOY537T.js +100 -0
  105. package/dist/wallets/walletConnectors/chunk-STVVP43G.js +94 -0
  106. package/dist/wallets/walletConnectors/chunk-UK7C2JXW.js +87 -0
  107. package/dist/wallets/walletConnectors/chunk-VAPGUPHO.js +92 -0
  108. package/dist/wallets/walletConnectors/chunk-VTM6EECM.js +110 -0
  109. package/dist/wallets/walletConnectors/chunk-X6CGV36L.js +103 -0
  110. package/dist/wallets/walletConnectors/chunk-YEZM4CK4.js +96 -0
  111. package/dist/wallets/walletConnectors/chunk-ZNX4EMPB.js +106 -0
  112. package/dist/wallets/walletConnectors/index.js +37 -37
  113. package/package.json +5 -5
  114. package/dist/clients/chunk-AXLGZ5XX.js +0 -1325
  115. package/dist/clients/chunk-DSZHYQPX.js +0 -31
  116. package/dist/clients/chunk-HZP4DXIZ.js +0 -231
  117. package/dist/clients/chunk-LUHEVXPD.js +0 -109
  118. package/dist/clients/chunk-NM2NAKI3.js +0 -1195
  119. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.css +0 -17545
  120. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.d.ts +0 -30
  121. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.js +0 -20
  122. package/dist/clients/polymarket/index.css +0 -17545
  123. package/dist/modals/PolymarketPerpsTransfer/PerpsTransferRows.d.ts +0 -10
  124. package/dist/modals/PolymarketPerpsTransfer/TransferAmountRow.css.d.ts +0 -13
  125. package/dist/modals/PolymarketPerpsTransfer/TransferAmountRow.d.ts +0 -27
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import {
3
+ i18n_default
4
+ } from "./chunk-FPOGADLJ.js";
5
+
6
+ // src/hooks/useFunkitTranslation.ts
7
+ import { useTranslation } from "react-i18next";
8
+ var funkitI18nOptions = { i18n: i18n_default };
9
+ function useFunkitTranslation() {
10
+ return useTranslation(void 0, funkitI18nOptions);
11
+ }
12
+
13
+ export {
14
+ useFunkitTranslation
15
+ };
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import {
3
+ i18n_default
4
+ } from "./chunk-WXSFLUPZ.js";
5
+
6
+ // src/hooks/useFunkitTranslation.ts
7
+ import { useTranslation } from "react-i18next";
8
+ var funkitI18nOptions = { i18n: i18n_default };
9
+ function useFunkitTranslation() {
10
+ return useTranslation(void 0, funkitI18nOptions);
11
+ }
12
+
13
+ export {
14
+ useFunkitTranslation
15
+ };
@@ -23,41 +23,17 @@ import { getAddress } from "viem";
23
23
  var POLYMARKET_PUSD_ADDRESS = getAddress(
24
24
  "0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB"
25
25
  );
26
-
27
- // src/utils/statsig/checkFeatureGate.ts
28
- import { defaultFeatureGates as fallbackFeatureGates } from "@funkit/connect-core";
29
- import { StatsigClient } from "@statsig/react-bindings";
30
-
31
- // src/providers/FunkitStatsigProvider.tsx
32
- import { datadogLogs } from "@datadog/browser-logs";
33
- import {
34
- LogEventCompressionMode,
35
- LogLevel,
36
- StatsigProvider,
37
- useClientAsyncInit
38
- } from "@statsig/react-bindings";
39
- import React, { createContext, useContext, useEffect } from "react";
40
- var STATSIG_CLIENT_KEY = "client-UmFd8WIJljA7cLmZuDqs3X25M8sKd5WIQP4BSC2bRbM";
41
- var FunWhnStatsigContext = createContext(null);
42
-
43
- // src/utils/statsig/checkFeatureGate.ts
44
- function checkFeatureGate(name) {
45
- try {
46
- return StatsigClient.instance(STATSIG_CLIENT_KEY).checkGate(name);
47
- } catch (err) {
48
- logger.warn("checkFeatureGate:error", { name, err });
49
- return fallbackFeatureGates[name];
50
- }
51
- }
52
-
53
- // src/clients/polymarket/polymarket.tsx
54
- var PMCT_WITHDRAW_ACTION_TYPE = "PMCT_WITHDRAW";
26
+ var POLYMARKET_PREDICTIONS_ROUTING_ID = "POLYMARKET_PREDICTIONS";
27
+ var POLYMARKET_PERPS_ROUTING_ID = "POLYMARKET_PERPS";
55
28
  var POLYGON_USDCE = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
56
29
  var PUSD_TOKEN = {
57
30
  address: POLYMARKET_PUSD_ADDRESS,
58
31
  symbol: "pUSD",
59
32
  iconSrc: "https://sdk-cdn.fun.xyz/images/pusd.svg"
60
33
  };
34
+
35
+ // src/clients/polymarket/polymarket.tsx
36
+ var PMCT_WITHDRAW_ACTION_TYPE = "PMCT_WITHDRAW";
61
37
  var PUSD_OFFRAMP_ADDRESS = "0x2957922Eb93258b93368531d39fAcCA3B4dC5854";
62
38
  var PUSD_OFFRAMP_ABI = [
63
39
  {
@@ -222,14 +198,7 @@ function extractWithdrawalAmount(funQuote) {
222
198
  return BigInt(amountStr);
223
199
  }
224
200
  function createPolymarketWithdrawalConfig(config) {
225
- if ("sendPmctTransfer" in config && "sendTransactions" in config) {
226
- const walletUnwrapEnabled = checkFeatureGate(
227
- "enable-polymarket-wallet-withdrawal"
228
- );
229
- logger.info("polymarket:withdrawal:gate", { walletUnwrapEnabled });
230
- return walletUnwrapEnabled ? buildWalletUnwrapWithdrawalConfig(config) : buildUdaWithdrawalConfig(config);
231
- }
232
- return "sendPmctTransfer" in config ? buildUdaWithdrawalConfig(config) : buildWalletUnwrapWithdrawalConfig(config);
201
+ return "sendTransactions" in config ? buildWalletUnwrapWithdrawalConfig(config) : buildUdaWithdrawalConfig(config);
233
202
  }
234
203
  var COLLATERAL_ONRAMP_ADDRESS = "0x93070a847efEf7F70739046A929D47a521F5B8ee";
235
204
  var COLLATERAL_ONRAMP_ABI = [
@@ -368,6 +337,8 @@ function createPerpsGenerateActionParams(config) {
368
337
  }
369
338
 
370
339
  export {
340
+ POLYMARKET_PREDICTIONS_ROUTING_ID,
341
+ POLYMARKET_PERPS_ROUTING_ID,
371
342
  POLYGON_USDCE,
372
343
  PUSD_TOKEN,
373
344
  createPolymarketWithdrawalConfig,
@@ -0,0 +1,296 @@
1
+ "use client";
2
+ import {
3
+ toWithdrawalAmountBaseUnit
4
+ } from "./chunk-B7UU2ETA.js";
5
+ import {
6
+ isExpectedNadoWithdrawalFailure,
7
+ toNadoWithdrawalErrorMessage
8
+ } from "./chunk-DYV3LRSE.js";
9
+ import {
10
+ getAccount,
11
+ signTypedData,
12
+ switchChain
13
+ } from "./chunk-OODIKHYE.js";
14
+ import {
15
+ i18n_default
16
+ } from "./chunk-27VBRE7W.js";
17
+ import {
18
+ generateClientMetadataForTokenTransfer
19
+ } from "./chunk-PENJ5JGH.js";
20
+ import {
21
+ logger
22
+ } from "./chunk-AHYOV7AV.js";
23
+
24
+ // src/clients/internal/nado/withdrawalCallback.ts
25
+ import {
26
+ NADO_API_KEY,
27
+ initializeCheckoutTokenTransferAddress
28
+ } from "@funkit/api-base";
29
+ import {
30
+ deductFlatFee,
31
+ normalizeRecipientAddress,
32
+ safeBigInt
33
+ } from "@funkit/connect-core";
34
+ import {
35
+ INK_CHAIN_ID,
36
+ NADO_WITHDRAWAL_ACTION_TYPE,
37
+ NadoGatewayError,
38
+ NadoWithdrawalUnconfirmedError,
39
+ buildWithdrawCollateralV2TypedData,
40
+ executeNadoWithdrawCollateralV2,
41
+ getNadoMaxWithdrawable,
42
+ getNadoTxNonce,
43
+ x18ToRawBaseUnit
44
+ } from "@funkit/connect-core/clients/nado";
45
+ import { isEVMAddressEquivalent } from "@funkit/utils";
46
+
47
+ // src/utils/signature.ts
48
+ import { isSwitchChainError, isUserRejectedError } from "@funkit/connect-core";
49
+
50
+ // src/clients/internal/nado/withdrawalCallback.ts
51
+ var NadoWithdrawalInputError = class extends Error {
52
+ };
53
+ var NadoWithdrawalUserError = class extends Error {
54
+ };
55
+ function createNadoWithdrawalCallback({
56
+ walletAddress,
57
+ subaccount,
58
+ wagmiConfig
59
+ }) {
60
+ return async (param) => {
61
+ const {
62
+ customerData,
63
+ userInputAmount,
64
+ targetAssetAddress,
65
+ targetChainId,
66
+ destinationAddress
67
+ } = param;
68
+ const recipientAddr = normalizeRecipientAddress(destinationAddress);
69
+ let step = "validate";
70
+ try {
71
+ if (customerData?.customerName !== "nado" || !userInputAmount) {
72
+ throw new NadoWithdrawalInputError(
73
+ "Missing Nado customerData or userInputAmount"
74
+ );
75
+ }
76
+ const {
77
+ spotLeverage,
78
+ sequencerFeeTokenAmount,
79
+ selectedSourceToken: { productId, decimals }
80
+ } = customerData;
81
+ const netTokens = deductFlatFee(userInputAmount, sequencerFeeTokenAmount);
82
+ const netRawAmount = toWithdrawalAmountBaseUnit(netTokens, decimals);
83
+ if (netRawAmount <= 0n) {
84
+ logger.warn("nado:withdrawal:amountTooLow", {
85
+ productId,
86
+ userInputAmount,
87
+ sequencerFeeTokenAmount
88
+ });
89
+ throw new NadoWithdrawalUserError(
90
+ i18n_default.t("withdrawal.nado.errorAmountTooLow")
91
+ );
92
+ }
93
+ logger.info("nado:withdrawal:start", {
94
+ productId,
95
+ spotLeverage,
96
+ decimals,
97
+ userInputAmount,
98
+ netTokens,
99
+ sequencerFeeTokenAmount,
100
+ targetChainId,
101
+ targetAssetAddress,
102
+ destinationAddress: recipientAddr
103
+ });
104
+ await assertWithinMaxWithdrawable({
105
+ subaccount,
106
+ productId,
107
+ decimals,
108
+ spotLeverage,
109
+ netRawAmount
110
+ });
111
+ step = "switchChain";
112
+ await ensureWalletOnInk(wagmiConfig);
113
+ assertOwnerIsSigner({ walletAddress, wagmiConfig });
114
+ step = "uda";
115
+ const transferInit = await initializeCheckoutTokenTransferAddress({
116
+ apiKey: NADO_API_KEY,
117
+ // No Fun user context in a client bundle entry; the owner wallet is the
118
+ // stable per-user id and matches what sourceOfFund records.
119
+ userId: walletAddress,
120
+ recipientAddr,
121
+ toChainId: targetChainId.toString(),
122
+ toTokenAddress: targetAssetAddress,
123
+ sourceOfFund: `balance|nado|${walletAddress}`,
124
+ // Attribution only — forces a separate UDA from Nado deposits so the
125
+ // direct executions off it are tagged as withdrawals.
126
+ actionType: NADO_WITHDRAWAL_ACTION_TYPE,
127
+ logger,
128
+ clientMetadata: {
129
+ ...generateClientMetadataForTokenTransfer(),
130
+ isWithdrawal: true
131
+ }
132
+ });
133
+ const depositAddr = transferInit.depositAddr;
134
+ logger.info("nado:withdrawal:udaGenerated", {
135
+ depositAddr,
136
+ productId,
137
+ destinationAddress: recipientAddr
138
+ });
139
+ step = "sign";
140
+ const nonce = await getNadoTxNonce(walletAddress, { logger });
141
+ const signature = await signTypedData(wagmiConfig, {
142
+ ...buildWithdrawCollateralV2TypedData({
143
+ sender: subaccount,
144
+ productId,
145
+ amount: netRawAmount,
146
+ nonce,
147
+ sendTo: depositAddr
148
+ }),
149
+ account: walletAddress
150
+ });
151
+ logger.info("nado:withdrawal:signed", {
152
+ nonce: nonce.toString(),
153
+ depositAddr,
154
+ productId
155
+ });
156
+ step = "execute";
157
+ await executeNadoWithdrawCollateralV2(
158
+ {
159
+ sender: subaccount,
160
+ productId,
161
+ amount: netRawAmount,
162
+ nonce,
163
+ sendTo: depositAddr,
164
+ signature,
165
+ spotLeverage
166
+ },
167
+ { logger }
168
+ );
169
+ logger.info("nado:withdrawal:executeSubmitted", {
170
+ nonce: nonce.toString(),
171
+ depositAddr,
172
+ productId,
173
+ netRawAmount: netRawAmount.toString()
174
+ });
175
+ return depositAddr;
176
+ } catch (error) {
177
+ throw toThrownWithdrawalError(error, {
178
+ step,
179
+ walletAddress,
180
+ subaccount,
181
+ destinationAddress: recipientAddr,
182
+ targetChainId
183
+ });
184
+ }
185
+ };
186
+ }
187
+ async function assertWithinMaxWithdrawable({
188
+ subaccount,
189
+ productId,
190
+ decimals,
191
+ spotLeverage,
192
+ netRawAmount
193
+ }) {
194
+ const maxWithdrawableX18 = await getNadoMaxWithdrawable(
195
+ { productId, sender: subaccount, spotLeverage },
196
+ { logger }
197
+ );
198
+ const maxRawAmount = x18ToRawBaseUnit(
199
+ safeBigInt(maxWithdrawableX18, 0n),
200
+ decimals
201
+ );
202
+ if (netRawAmount <= maxRawAmount) {
203
+ return;
204
+ }
205
+ logger.warn("nado:withdrawal:exceedsMaxWithdrawable", {
206
+ productId,
207
+ spotLeverage,
208
+ netRawAmount: netRawAmount.toString(),
209
+ maxRawAmount: maxRawAmount.toString()
210
+ });
211
+ throw new NadoWithdrawalUserError(
212
+ i18n_default.t("withdrawal.nado.errorBalanceChanged")
213
+ );
214
+ }
215
+ async function ensureWalletOnInk(wagmiConfig) {
216
+ const connectedChainId = getAccount(wagmiConfig).chainId;
217
+ if (connectedChainId === INK_CHAIN_ID) {
218
+ return;
219
+ }
220
+ logger.info("nado:withdrawal:switchingChain", {
221
+ fromChainId: connectedChainId ?? null
222
+ });
223
+ try {
224
+ await switchChain(wagmiConfig, { chainId: INK_CHAIN_ID });
225
+ } catch (error) {
226
+ if (isUserRejectedError(error)) {
227
+ throw error;
228
+ }
229
+ logger.warn("nado:withdrawal:switchChainFailed", {
230
+ fromChainId: connectedChainId ?? null,
231
+ errorMessage: error instanceof Error ? error.message : String(error)
232
+ });
233
+ throw new NadoWithdrawalUserError(
234
+ i18n_default.t("withdrawal.nado.errorSwitchChain")
235
+ );
236
+ }
237
+ }
238
+ function assertOwnerIsSigner({
239
+ walletAddress,
240
+ wagmiConfig
241
+ }) {
242
+ const connectedAddress = getAccount(wagmiConfig).address;
243
+ if (connectedAddress && isEVMAddressEquivalent({
244
+ firstAddress: connectedAddress,
245
+ secondAddress: walletAddress
246
+ })) {
247
+ return;
248
+ }
249
+ logger.warn("nado:withdrawal:signerMismatch", {
250
+ walletAddress,
251
+ connectedAddress: connectedAddress ?? null
252
+ });
253
+ throw new NadoWithdrawalUserError(
254
+ i18n_default.t("withdrawal.nado.errorSignerMismatch")
255
+ );
256
+ }
257
+ function toThrownWithdrawalError(error, context) {
258
+ const logContext = {
259
+ ...context,
260
+ nadoErrorCode: error instanceof NadoGatewayError ? error.errorCode ?? null : null,
261
+ nadoErrorKind: error instanceof NadoGatewayError ? error.kind : null,
262
+ errorMessage: error instanceof Error ? error.message : String(error)
263
+ };
264
+ if (isUserRejectedError(error)) {
265
+ logger.warn("nado:withdrawal:rejected", logContext);
266
+ return error;
267
+ }
268
+ if (error instanceof NadoWithdrawalUserError) {
269
+ return error;
270
+ }
271
+ if (error instanceof NadoWithdrawalInputError) {
272
+ logger.error("nado:withdrawal:invalidInput", error, logContext);
273
+ return new Error(i18n_default.t("withdrawal.nado.errorGeneric"));
274
+ }
275
+ if (error instanceof NadoWithdrawalUnconfirmedError) {
276
+ return new Error(toNadoWithdrawalErrorMessage(error));
277
+ }
278
+ if (!(error instanceof NadoGatewayError)) {
279
+ logger.error(
280
+ "nado:withdrawal:failed",
281
+ error instanceof Error ? error : new Error(String(error)),
282
+ logContext
283
+ );
284
+ return error;
285
+ }
286
+ if (isExpectedNadoWithdrawalFailure(error)) {
287
+ logger.warn("nado:withdrawal:gatewayRejected", logContext);
288
+ } else {
289
+ logger.error("nado:withdrawal:gatewayFailed", error, logContext);
290
+ }
291
+ return new Error(toNadoWithdrawalErrorMessage(error));
292
+ }
293
+
294
+ export {
295
+ createNadoWithdrawalCallback
296
+ };