@funkit/connect 7.1.0-next.12 → 7.1.0-next.13

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @funkit/connect
2
2
 
3
+ ## 7.1.0-next.13
4
+
5
+ ### Minor Changes
6
+
7
+ - f4552b0: Expose recent deposits hooks for SDK users with comprehensive documentation
8
+
9
+ Add two new public hooks for fetching recent deposits/direct executions:
10
+
11
+ - `useFunkitRecentDeposits`: Auto-integrates with FunkitProvider context
12
+ - `useFunkitRecentDepositsImpl`: Standalone implementation with explicit parameters
13
+
14
+ Both hooks return purified checkout history items suitable for external use and include full JSDoc documentation with usage examples.
15
+
16
+ ### Patch Changes
17
+
18
+ - 2962aaa: feat(connect): remove persisted targetAssetAmount when source token changes - fixes default input amount logic
19
+ - 6802246: feat(connect): remove no eth asset msg for lighter
20
+
3
21
  ## 7.1.0-next.12
4
22
 
5
23
  ### Patch Changes
@@ -19,13 +19,27 @@ interface RecentDirectExecutionsQuery {
19
19
  * Maximum number of deposits to fetch from the API.
20
20
  * @default 5
21
21
  */
22
- batchSize?: number;
22
+ fetchSize?: number;
23
23
  /**
24
24
  * Custom cutoff time in milliseconds for determining which deposits are "recent".
25
25
  * Deposits created after this timestamp will be included.
26
26
  * If not provided, uses Fun's default strategy.
27
27
  */
28
28
  cutOffTimeMs?: number;
29
+ /**
30
+ * API key for authenticating requests to Fun's API server.
31
+ */
32
+ apiKey: string;
33
+ /**
34
+ * User ID for which to fetch direct executions.
35
+ * Usually user's connected wallet address.
36
+ */
37
+ userId: string;
38
+ /**
39
+ * Interval in milliseconds for how often to refetch the data.
40
+ * Determines the polling frequency for keeping deposit data up to date.
41
+ */
42
+ refreshIntervalMs: number;
29
43
  }
30
44
  export interface MergedMultiStepDirectExecution extends DirectExecution {
31
45
  /**
@@ -37,10 +51,66 @@ export interface MergedMultiStepDirectExecution extends DirectExecution {
37
51
  }
38
52
  export declare function isTokenTransferDirectExecution(de: DirectExecution): boolean;
39
53
  export declare function isWithdrawalDirectExecution(de: DirectExecution): boolean;
54
+ type DefaultDEQueryKey = 'apiKey' | 'userId' | 'refreshIntervalMs';
55
+ export type RecentDEQuerySimplified = Omit<RecentDirectExecutionsQuery, DefaultDEQueryKey>;
40
56
  /**
41
57
  * @returns recent direct executions tied to a recipient address used in the token transfer flow
42
58
  */
43
- export declare const useRecentDeposits: ({ isVisible, memoizedFilterFunc, batchSize, cutOffTimeMs, }: RecentDirectExecutionsQuery) => {
59
+ export declare const useRecentDeposits: ({ isVisible, memoizedFilterFunc, fetchSize, cutOffTimeMs, }: RecentDEQuerySimplified) => {
44
60
  data: MergedMultiStepDirectExecution[] | undefined;
45
61
  };
62
+ /**
63
+ * Hook for SDK users to fetch recent deposits/direct executions with automatic context integration.
64
+ *
65
+ * **Requirements**: Must be used inside FunkitProvider context as it automatically retrieves:
66
+ * - API key, User ID, Refresh interval from Fun
67
+ *
68
+ * Returns checkout history items
69
+ *
70
+ * @param query - Simplified query parameters (excludes apiKey, userId, refreshIntervalMs)
71
+ * @returns Object with `data` property containing array of purified direct executions or undefined if not loaded
72
+ *
73
+ * @example
74
+ * ```tsx
75
+ * function MyComponent() {
76
+ * const { data: recentDeposits } = useFunkitRecentDeposits({
77
+ * isVisible: true,
78
+ * fetchSize: 10,
79
+ * cutOffTimeMs: 24 * 60 * 60 * 1000, // Last 24 hours
80
+ * })
81
+ * return <div>{recentDeposits?.length} recent deposits</div>
82
+ * }
83
+ * ```
84
+ */
85
+ export declare function useFunkitRecentDeposits(query: RecentDEQuerySimplified): {
86
+ data: import("~/utils/purifyCheckoutHistoryItem").PurifiedCheckoutHistoryItem[] | undefined;
87
+ };
88
+ /**
89
+ * Implementation hook for SDK users to fetch recent deposits with explicit parameters.
90
+ *
91
+ * **Requirements**: Does NOT require FunkitProvider context. All parameters must be provided explicitly.
92
+ * This is useful for custom implementations or when using outside the standard Funkit provider hierarchy.
93
+ *
94
+ * Returns purified checkout history items
95
+ *
96
+ * @param query - Complete query parameters including apiKey, userId, and refreshIntervalMs
97
+ * @returns Object with `data` property containing array of purified direct executions or undefined if not loaded
98
+ *
99
+ * @example
100
+ * ```tsx
101
+ * function MyCustomComponent() {
102
+ * const { data: recentDeposits } = useFunkitRecentDepositsImpl({
103
+ * isVisible: true,
104
+ * apiKey: 'your-api-key',
105
+ * userId: 'user-wallet-address',
106
+ * refreshIntervalMs: 5000,
107
+ * fetchSize: 10,
108
+ * })
109
+ * return <div>{recentDeposits?.length} recent deposits</div>
110
+ * }
111
+ * ```
112
+ */
113
+ export declare function useFunkitRecentDepositsImpl(query: RecentDirectExecutionsQuery): {
114
+ data: import("~/utils/purifyCheckoutHistoryItem").PurifiedCheckoutHistoryItem[] | undefined;
115
+ };
46
116
  export {};
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@ export type { FunkitConfig } from './providers/FunkitConfigContext';
26
26
  export type { FunkitConnectChain as Chain } from './providers/FunkitConnectChainContext';
27
27
  export type { ModalSizes } from './providers/ModalSizeContext';
28
28
  export { useCheckoutListenerByCheckoutId, useCheckoutsListenerByUserId, } from './providers/FunkitHistoryContext';
29
- export { useRecentDeposits } from './hooks/queries/useRecentDeposits';
29
+ export { useFunkitRecentDeposits, useFunkitRecentDepositsImpl, } from './hooks/queries/useRecentDeposits';
30
30
  export type { FunkitWagmiConfig, FunkitProviderProps, } from './providers/FunkitProvider';
31
31
  export { FunkitProvider } from './providers/FunkitProvider';
32
32
  export type { Theme, ThemeSet } from './providers/FunkitThemeProvider';
package/dist/index.js CHANGED
@@ -1122,11 +1122,6 @@ function isHyenaCustomer(apiKey) {
1122
1122
  function isLighterxyzCustomer(apiKey) {
1123
1123
  return apiKey === LIGHTERXYZ_API_KEY;
1124
1124
  }
1125
- function isLighterEthSpot(apiKey, checkoutConfig) {
1126
- return checkoutConfig && isLighterxyzCustomer(apiKey) && ["LIGHTER_ETH_SPOT_NEW_USER", "LIGHTER_ETH_SPOT"].includes(
1127
- checkoutConfig.dynamicRoutingId || ""
1128
- );
1129
- }
1130
1125
  function isLighterNativeFlow(apiKey, checkoutConfig) {
1131
1126
  return !!checkoutConfig && isLighterxyzCustomer(apiKey) && checkoutConfig.targetChain === mainnet4.id.toString();
1132
1127
  }
@@ -1432,7 +1427,7 @@ function setFunkitConnectVersion({ version }) {
1432
1427
  localStorage.setItem(storageKey, version);
1433
1428
  }
1434
1429
  function getCurrentSdkVersion() {
1435
- return "7.1.0-next.12";
1430
+ return "7.1.0-next.13";
1436
1431
  }
1437
1432
  function useFingerprint() {
1438
1433
  const fingerprint = useCallback3(() => {
@@ -4327,6 +4322,15 @@ function useMultiStepDirectExecutionStatus(multiStepDirectExecution, disabled =
4327
4322
  }
4328
4323
 
4329
4324
  // src/utils/purifyCheckoutHistoryItem.ts
4325
+ function resolveLastDirectExecution(de) {
4326
+ return de.latestStep ?? de;
4327
+ }
4328
+ function getTransactionHashes(first, last) {
4329
+ const all = [first.txHash, first.toTxId, last.txHash, last.toTxId].filter(
4330
+ Boolean
4331
+ );
4332
+ return Array.from(new Set(all));
4333
+ }
4330
4334
  var purifyCheckoutHistoryItem = (item) => {
4331
4335
  if ("depositAddr" in item) {
4332
4336
  return {
@@ -4345,22 +4349,26 @@ var purifyCheckoutHistoryItem = (item) => {
4345
4349
  additionalActions: item?.clientMetadata?.evaluatedActionsParams ?? []
4346
4350
  };
4347
4351
  }
4352
+ const de = resolveLastDirectExecution(item);
4348
4353
  return {
4349
4354
  directExecution: true,
4350
- id: item.txHash,
4355
+ id: de.txHash,
4356
+ // use first step's deposit address for source
4351
4357
  fromAmountBaseUnit: item.fromAmountBaseUnit,
4352
4358
  fromChainId: item.fromChainId,
4353
4359
  fromTokenAddress: item.fromTokenAddress,
4360
+ // use last step's status for target
4361
+ toChainId: de.toChainId,
4362
+ toTokenAddress: de.toTokenAddress,
4363
+ toAmountBaseUnit: de.toAmountBaseUnit,
4354
4364
  state: mapRelayExecutionStatusToCheckoutState(
4355
- item?.listenerInfo?.status ?? RelayExecutionStatus2.SUCCESS
4365
+ de?.listenerInfo?.status ?? RelayExecutionStatus2.SUCCESS
4356
4366
  ),
4357
- toChainId: item.toChainId,
4358
- toTokenAddress: item.toTokenAddress,
4359
- toAmountBaseUnit: item.toAmountBaseUnit,
4360
- txHash: item.txHash,
4367
+ txHashes: getTransactionHashes(item, de),
4368
+ // needs to use the original item's createdTimeMs for the earliest time
4361
4369
  createdTimeMs: item.createdTimeMs,
4362
- updatedTimeMs: getDirectExecutionUpdatedTimeMs(item),
4363
- additionalActions: item?.clientMetadata?.evaluatedActionsParams ?? []
4370
+ updatedTimeMs: getDirectExecutionUpdatedTimeMs(de),
4371
+ additionalActions: de?.clientMetadata?.evaluatedActionsParams ?? []
4364
4372
  };
4365
4373
  };
4366
4374
 
@@ -20408,28 +20416,28 @@ function isTokenTransferDirectExecution(de) {
20408
20416
  function isWithdrawalDirectExecution(de) {
20409
20417
  return !!de.clientMetadata.isWithdrawal;
20410
20418
  }
20411
- var useRecentDeposits = ({
20419
+ function useRecentDepositsImpl({
20412
20420
  isVisible,
20413
20421
  // WARNING! memoizedFilterFunc must be a stable reference (ie: wrap it in useMemo), otherwise hook will constantly re-render
20414
20422
  memoizedFilterFunc,
20415
- batchSize = 5,
20416
- cutOffTimeMs = DEFAULT_NOTIF_CUTOFF
20417
- }) => {
20418
- const { userInfo, isUserLoggedIn } = useGeneralWallet();
20419
- const { apiKey } = useFunkitConfig();
20420
- const { listRefresh } = useCheckoutRefreshInterval();
20423
+ fetchSize = 5,
20424
+ cutOffTimeMs = DEFAULT_NOTIF_CUTOFF,
20425
+ userId,
20426
+ refreshIntervalMs,
20427
+ apiKey
20428
+ }) {
20421
20429
  const { data: directExecutions } = useQuery14({
20422
- queryKey: ["directExecutions", userInfo.id],
20430
+ queryKey: ["useRecentDepositsImpl", userId, fetchSize],
20423
20431
  queryFn: async () => {
20424
20432
  const directExecutions2 = await getDirectExecutionsByUserId2({
20425
- userId: userInfo.id,
20426
- limit: batchSize,
20433
+ userId,
20434
+ limit: fetchSize,
20427
20435
  apiKey
20428
20436
  });
20429
20437
  return directExecutions2;
20430
20438
  },
20431
- refetchInterval: listRefresh,
20432
- enabled: isUserLoggedIn && isVisible
20439
+ refetchInterval: refreshIntervalMs,
20440
+ enabled: isVisible && !!userId
20433
20441
  });
20434
20442
  const data = useMemo24(() => {
20435
20443
  if (!directExecutions) {
@@ -20446,7 +20454,51 @@ var useRecentDeposits = ({
20446
20454
  ).sort((a, b) => b.createdTimeMs - a.createdTimeMs);
20447
20455
  }, [directExecutions, memoizedFilterFunc, cutOffTimeMs]);
20448
20456
  return { data };
20457
+ }
20458
+ function useDefaultParams() {
20459
+ const { userInfo, isUserLoggedIn } = useGeneralWallet();
20460
+ const { apiKey } = useFunkitConfig();
20461
+ const { listRefresh } = useCheckoutRefreshInterval();
20462
+ return {
20463
+ apiKey,
20464
+ userId: isUserLoggedIn ? userInfo.id : "",
20465
+ refreshIntervalMs: listRefresh
20466
+ };
20467
+ }
20468
+ var useRecentDeposits = ({
20469
+ isVisible,
20470
+ // WARNING! memoizedFilterFunc must be a stable reference (ie: wrap it in useMemo), otherwise hook will constantly re-render
20471
+ memoizedFilterFunc,
20472
+ fetchSize = 5,
20473
+ cutOffTimeMs = DEFAULT_NOTIF_CUTOFF
20474
+ }) => {
20475
+ const defaultParams = useDefaultParams();
20476
+ return useRecentDepositsImpl({
20477
+ isVisible,
20478
+ memoizedFilterFunc,
20479
+ fetchSize,
20480
+ cutOffTimeMs,
20481
+ ...defaultParams
20482
+ });
20449
20483
  };
20484
+ function useFunkitRecentDeposits(query) {
20485
+ const defaultParams = useDefaultParams();
20486
+ return useFunkitRecentDepositsImpl({
20487
+ ...query,
20488
+ ...defaultParams
20489
+ });
20490
+ }
20491
+ function useFunkitRecentDepositsImpl(query) {
20492
+ const fetchSize = query.fetchSize ?? 5;
20493
+ const { data } = useRecentDepositsImpl({
20494
+ ...query,
20495
+ fetchSize: fetchSize * 2
20496
+ // fetch extra to account for merging
20497
+ });
20498
+ return {
20499
+ data: data?.map((de) => purifyCheckoutHistoryItem(de)).slice(0, fetchSize)
20500
+ };
20501
+ }
20450
20502
 
20451
20503
  // src/hooks/useOnNewNotification.ts
20452
20504
  import { safeParseJson as safeParseJson4 } from "@funkit/utils";
@@ -32309,6 +32361,7 @@ function AccountSelectAsset({
32309
32361
  checkoutItem,
32310
32362
  updateSourceAsset,
32311
32363
  updateTargetAsset,
32364
+ updateTargetAssetAmount,
32312
32365
  applyDynamicRouting
32313
32366
  } = useCheckoutContext();
32314
32367
  const { walletAddress } = useGeneralWallet();
@@ -32411,6 +32464,17 @@ function AccountSelectAsset({
32411
32464
  if (!tokenItem) {
32412
32465
  return;
32413
32466
  }
32467
+ const currentSourceAsset = checkoutItem?.selectedSourceAssetInfo;
32468
+ const sourceAssetChanged = !isTokenEquivalent5({
32469
+ firstTokenChainId: currentSourceAsset?.chainId || "",
32470
+ firstTokenAddress: currentSourceAsset?.address || "",
32471
+ secondTokenChainId: tokenItem.pickedChainId,
32472
+ secondTokenAddress: tokenItem.tokenAddress
32473
+ });
32474
+ const shouldResetTargetAssetAmount = currentSourceAsset && sourceAssetChanged && !checkoutConfig?.isDefiMode && paymentMethodInfo.paymentMethod !== "card" /* CARD */;
32475
+ if (shouldResetTargetAssetAmount) {
32476
+ updateTargetAssetAmount(0);
32477
+ }
32414
32478
  updateSourceAsset(tokenItem);
32415
32479
  if (isBrokerageAsset(tokenItem)) {
32416
32480
  setSelectedBrokerageAsset(tokenItem);
@@ -32454,7 +32518,6 @@ function AccountSelectAsset({
32454
32518
  const isAssetsEmpty = assetOptions.length === 0;
32455
32519
  const isDisabled = isAssetsEmpty || !selectedChainTokenSymbol || isLoading;
32456
32520
  const onBalanceTopUpSwitch = checkoutItem?.initSettings.onBalanceTopUpSwitch;
32457
- const showLighterEthMessage = isLighterEthSpot(apiKey, checkoutConfig) && assetOptions.every((asset) => asset.isDisabled);
32458
32521
  const checkoutId = checkoutItem?.id;
32459
32522
  useEffect50(() => {
32460
32523
  if (checkoutId && !isLoading) {
@@ -32484,26 +32547,6 @@ function AccountSelectAsset({
32484
32547
  }
32485
32548
  ) : void 0
32486
32549
  }
32487
- ) : showLighterEthMessage ? /* @__PURE__ */ React188.createElement(
32488
- FunNoResults,
32489
- {
32490
- title: t("checkout.insufficientEth"),
32491
- text: t("checkout.insufficientEthMessage"),
32492
- variant: "actionable",
32493
- actionButton: onBalanceTopUpSwitch ? /* @__PURE__ */ React188.createElement(
32494
- FunButton,
32495
- {
32496
- type: "tertiary",
32497
- onClick: () => {
32498
- if (onBalanceTopUpSwitch) {
32499
- onBalanceTopUpSwitch();
32500
- }
32501
- onClose?.();
32502
- },
32503
- title: t("checkout.topUpWallet")
32504
- }
32505
- ) : void 0
32506
- }
32507
32550
  ) : /* @__PURE__ */ React188.createElement(Box, { display: "flex", flexDirection: "column", gap: "4" }, assetOptions.map(({ asset, isDisabled: isDisabled2, badgeText, minUsdRequired }) => /* @__PURE__ */ React188.createElement(
32508
32551
  FunAssetItem,
32509
32552
  {
@@ -39508,11 +39551,12 @@ export {
39508
39551
  useFunkitCheckout,
39509
39552
  useFunkitDisconnect,
39510
39553
  useFunkitMaxCheckoutUsdInfo,
39554
+ useFunkitRecentDeposits,
39555
+ useFunkitRecentDepositsImpl,
39511
39556
  useFunkitReconnect,
39512
39557
  useFunkitSwitchChains,
39513
39558
  useFunkitTranslation,
39514
39559
  useFunkitUserInfo,
39515
- useRecentDeposits,
39516
39560
  useSoftHiddenCheckout,
39517
39561
  useUpdateActiveFunkitCheckout
39518
39562
  };
@@ -1,6 +1,7 @@
1
- import { type CheckoutHistoryItem, type CheckoutState, type DirectExecution } from '@funkit/api-base';
1
+ import { type CheckoutHistoryItem, type CheckoutState } from '@funkit/api-base';
2
2
  import type { ApiFunkitCheckoutActionParams } from '@funkit/utils';
3
3
  import type { Address, Hex } from 'viem';
4
+ import type { MergedMultiStepDirectExecution } from '~/hooks/queries/useRecentDeposits';
4
5
  export type PurifiedCheckoutHistoryItem = {
5
6
  depositAddr?: Address;
6
7
  directExecution: boolean;
@@ -15,14 +16,12 @@ export type PurifiedCheckoutHistoryItem = {
15
16
  createdTimeMs: number;
16
17
  updatedTimeMs: number;
17
18
  additionalActions: ApiFunkitCheckoutActionParams[];
18
- txHash?: Hex;
19
19
  } & ({
20
20
  depositAddr: Address;
21
21
  directExecution: false;
22
- txHash?: never;
23
22
  } | {
24
23
  depositAddr?: never;
25
24
  directExecution: true;
26
- txHash: Hex;
25
+ txHashes: Hex[];
27
26
  });
28
- export declare const purifyCheckoutHistoryItem: (item: CheckoutHistoryItem | DirectExecution) => PurifiedCheckoutHistoryItem;
27
+ export declare const purifyCheckoutHistoryItem: (item: CheckoutHistoryItem | MergedMultiStepDirectExecution) => PurifiedCheckoutHistoryItem;
@@ -11,30 +11,30 @@ import {
11
11
  import {
12
12
  talismanWallet
13
13
  } from "./chunk-JTLLKY2O.js";
14
- import {
15
- tokenaryWallet
16
- } from "./chunk-M2HGGTFE.js";
17
14
  import {
18
15
  tokenPocketWallet
19
16
  } from "./chunk-47QF6EET.js";
17
+ import {
18
+ tokenaryWallet
19
+ } from "./chunk-M2HGGTFE.js";
20
20
  import {
21
21
  trustWallet
22
22
  } from "./chunk-JFHP4YJG.js";
23
23
  import {
24
24
  uniswapWallet
25
25
  } from "./chunk-LH7BMNFZ.js";
26
- import {
27
- walletConnectWallet
28
- } from "./chunk-NP5QGWNL.js";
29
26
  import {
30
27
  xdefiWallet
31
28
  } from "./chunk-TMFH6GXS.js";
32
29
  import {
33
- rainbowWallet
34
- } from "./chunk-77UTBHGP.js";
30
+ walletConnectWallet
31
+ } from "./chunk-NP5QGWNL.js";
35
32
  import {
36
33
  rabbyWallet
37
34
  } from "./chunk-LW6S43RE.js";
35
+ import {
36
+ rainbowWallet
37
+ } from "./chunk-77UTBHGP.js";
38
38
  import {
39
39
  ramperWallet
40
40
  } from "./chunk-FCG5Q6JX.js";
@@ -59,12 +59,12 @@ import {
59
59
  import {
60
60
  mewWallet
61
61
  } from "./chunk-CF5HOLH2.js";
62
- import {
63
- okxWallet
64
- } from "./chunk-U5QP7MI5.js";
65
62
  import {
66
63
  oktoWallet
67
64
  } from "./chunk-ADIXAKUL.js";
65
+ import {
66
+ okxWallet
67
+ } from "./chunk-U5QP7MI5.js";
68
68
  import {
69
69
  omniWallet
70
70
  } from "./chunk-7CUY5G6R.js";
@@ -80,24 +80,24 @@ import {
80
80
  import {
81
81
  foxWallet
82
82
  } from "./chunk-YLJDPTYF.js";
83
- import {
84
- frameWallet
85
- } from "./chunk-AI55G5DD.js";
86
83
  import {
87
84
  frontierWallet
88
85
  } from "./chunk-T5KHVUFR.js";
86
+ import {
87
+ frameWallet
88
+ } from "./chunk-AI55G5DD.js";
89
89
  import {
90
90
  gateWallet
91
91
  } from "./chunk-MRRZOQGZ.js";
92
92
  import {
93
93
  imTokenWallet
94
94
  } from "./chunk-COZ7MIQS.js";
95
- import {
96
- kresusWallet
97
- } from "./chunk-MJXPRJZT.js";
98
95
  import {
99
96
  injectedWallet
100
97
  } from "./chunk-MQSCN4BO.js";
98
+ import {
99
+ kresusWallet
100
+ } from "./chunk-MJXPRJZT.js";
101
101
  import {
102
102
  ledgerWallet
103
103
  } from "./chunk-BRBKM4PW.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funkit/connect",
3
- "version": "7.1.0-next.12",
3
+ "version": "7.1.0-next.13",
4
4
  "description": "Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.",
5
5
  "files": [
6
6
  "dist",