@funkit/connect 12.16.0 → 12.18.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 (97) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/dist/clients/axiom.d.ts +1 -5
  3. package/dist/clients/{chunk-BKK2BFIP.js → chunk-AELXD5XA.js} +1 -1
  4. package/dist/clients/{chunk-6IH7AWFA.js → chunk-FOXMRDKD.js} +1 -1
  5. package/dist/clients/{chunk-UZ3NA7HN.js → chunk-G6A62MZO.js} +3 -3
  6. package/dist/clients/{chunk-OB5GKTP2.js → chunk-L6JL2XJY.js} +1 -1
  7. package/dist/clients/{chunk-I5VRAFH6.js → chunk-LCYJLY4X.js} +1 -1
  8. package/dist/clients/chunk-R25GIAD5.js +59 -0
  9. package/dist/clients/{chunk-7JYLS7IF.js → chunk-YSAAJSWT.js} +272 -48
  10. package/dist/clients/fanatics.js +2 -2
  11. package/dist/clients/internal/nado/withdrawalCallback.js +4 -4
  12. package/dist/clients/internal/nado/withdrawalConfig.js +2 -2
  13. package/dist/clients/internal/nado/withdrawalErrors.js +2 -2
  14. package/dist/clients/internal/nado/withdrawalForm.js +6 -6
  15. package/dist/clients/internal/nado/withdrawalStatus.js +3 -3
  16. package/dist/clients/lighter.css +8 -8
  17. package/dist/clients/lighter.d.ts +29 -16
  18. package/dist/clients/lighter.js +149 -68
  19. package/dist/clients/mallard.js +2 -2
  20. package/dist/clients/nado.js +4 -4
  21. package/dist/components/LargeAmountInput/LargeAmountInput.d.ts +3 -1
  22. package/dist/components/TokenSwapWidget/TokenSelectButton/TokenSelectButton.d.ts +5 -2
  23. package/dist/components/TokenSwapWidget/TokenSwapCard/TokenSwapCard.d.ts +7 -3
  24. package/dist/components/TokenSwapWidget/TokenSwapWidget.d.ts +7 -2
  25. package/dist/consts/customers.d.ts +12 -1
  26. package/dist/domains/convert/assets.d.ts +30 -0
  27. package/dist/domains/convert/balances.d.ts +44 -24
  28. package/dist/domains/convert/errors.d.ts +38 -0
  29. package/dist/domains/convert/execution.d.ts +39 -0
  30. package/dist/domains/convert/hostTimeout.d.ts +8 -0
  31. package/dist/domains/convert/inputAmount.d.ts +53 -0
  32. package/dist/domains/convert/quote.d.ts +33 -0
  33. package/dist/domains/convert/recipient.d.ts +2 -1
  34. package/dist/domains/convert/reducer.d.ts +112 -0
  35. package/dist/domains/convert/screen.d.ts +169 -0
  36. package/dist/domains/convert/settlement.d.ts +52 -0
  37. package/dist/domains/convert/sourceWallet.d.ts +5 -4
  38. package/dist/domains/convert/submit.d.ts +67 -0
  39. package/dist/domains/convert/types.d.ts +52 -27
  40. package/dist/domains/convert/view.d.ts +111 -0
  41. package/dist/domains/nativeFeeReserve.d.ts +29 -0
  42. package/dist/domains/quote.d.ts +14 -1
  43. package/dist/hooks/queries/useWithdrawFops.d.ts +6 -0
  44. package/dist/hooks/queries/useWithdrawalQuote.d.ts +4 -1
  45. package/dist/hooks/track/CheckoutModalEvent.d.ts +2 -0
  46. package/dist/hooks/track/WithdrawModalEvent.d.ts +1 -0
  47. package/dist/hooks/track/analytics/events.d.ts +59 -1
  48. package/dist/hooks/track/analytics/mappers.d.ts +5 -4
  49. package/dist/hooks/track/analytics/resolveIframeStepNavigation.d.ts +18 -0
  50. package/dist/hooks/track/analytics/useDepositAnalytics.d.ts +2 -2
  51. package/dist/hooks/track/analytics/useTrackSwappedIframeEvents.d.ts +5 -0
  52. package/dist/hooks/track/analytics/useWithdrawalAnalytics.d.ts +2 -2
  53. package/dist/hooks/track/useQuoteAttemptCounter.d.ts +2 -0
  54. package/dist/hooks/useConvertAssetList.d.ts +23 -0
  55. package/dist/hooks/useConvertAssets.d.ts +11 -0
  56. package/dist/hooks/useConvertBalances.d.ts +50 -0
  57. package/dist/hooks/useConvertExecute.d.ts +33 -0
  58. package/dist/hooks/useConvertQuote.d.ts +53 -0
  59. package/dist/hooks/useConvertSelectionWallets.d.ts +34 -0
  60. package/dist/hooks/useConvertTransactionStatus.d.ts +17 -0
  61. package/dist/hooks/useMaxSpendableAmount.d.ts +19 -0
  62. package/dist/hooks/useStepQueryReadiness.d.ts +45 -15
  63. package/dist/index.css +8 -8
  64. package/dist/index.d.ts +3 -2
  65. package/dist/index.js +8169 -3491
  66. package/dist/modals/CheckoutModal/Convert/ConvertAssetList.d.ts +16 -0
  67. package/dist/modals/CheckoutModal/Convert/ConvertAssetRow.d.ts +21 -0
  68. package/dist/modals/CheckoutModal/Convert/ConvertChainPills.d.ts +14 -0
  69. package/dist/modals/CheckoutModal/Convert/ConvertSelectDestinationStep.d.ts +30 -0
  70. package/dist/modals/CheckoutModal/Convert/ConvertSelectSourceStep.d.ts +18 -0
  71. package/dist/modals/CheckoutModal/Convert/ConvertStep.d.ts +4 -2
  72. package/dist/modals/CheckoutModal/FunCheckoutStep.d.ts +2 -0
  73. package/dist/modals/CheckoutModal/SourceChange/SourceChange.d.ts +5 -3
  74. package/dist/modals/CheckoutModal/SwappedIframe/swappedIframeReady.track.d.ts +8 -0
  75. package/dist/modals/CheckoutModal/Withdrawal/WithdrawalComplete.d.ts +5 -2
  76. package/dist/modals/CheckoutModal/Withdrawal/WithdrawalEnterAmount.d.ts +4 -2
  77. package/dist/modals/CheckoutModal/stepTransition.d.ts +7 -2
  78. package/dist/modals/CheckoutModal/stepTransition.shared.d.ts +0 -1
  79. package/dist/modals/WithdrawalModal/LighterWithdrawal.d.ts +48 -15
  80. package/dist/modals/WithdrawalModal/WithdrawAmountInput.d.ts +17 -4
  81. package/dist/modals/WithdrawalModal/WithdrawalContent.d.ts +10 -7
  82. package/dist/modals/WithdrawalModal/useMaxWithdrawableAmount.d.ts +10 -0
  83. package/dist/modals/WithdrawalModal/useMultiSourceWithdrawal.d.ts +41 -0
  84. package/dist/modals/WithdrawalModal/withdrawalFormHelpers.d.ts +28 -8
  85. package/dist/providers/ConvertProvider.d.ts +40 -0
  86. package/dist/providers/FunkitCheckoutContext/index.d.ts +2 -2
  87. package/dist/providers/FunkitCheckoutContext/types.d.ts +36 -2
  88. package/dist/providers/FunkitQuoteContext.track.d.ts +23 -3
  89. package/dist/providers/SwappedProvider.d.ts +7 -0
  90. package/dist/shadow-css.js +1 -1
  91. package/dist/utils/customer.d.ts +34 -4
  92. package/dist/utils/withdrawal.d.ts +28 -1
  93. package/dist/wallets/multiSourceWithdrawal.d.ts +36 -0
  94. package/dist/wallets/walletConnectors/index.js +42 -42
  95. package/package.json +6 -6
  96. package/dist/clients/chunk-6EU6CXNH.js +0 -20
  97. /package/dist/clients/{chunk-4DBUYTEE.js → chunk-LICTGZXW.js} +0 -0
@@ -0,0 +1,52 @@
1
+ import { type DirectExecution } from '@funkit/api-base';
2
+ import type { ConvertSubmissionIds } from './execution';
3
+ import { type ConvertQuote } from './quote';
4
+ import type { ConvertResolvedAsset, ConvertSuccessResult, ConvertVm } from './types';
5
+ /**
6
+ * Tags the record as a conversion. Nothing on the backend parses this; the
7
+ * address stays third, where analytics reads a source address.
8
+ */
9
+ export declare function buildConvertSourceOfFund(vm: ConvertVm, address: string): string;
10
+ /** One submitted conversion, with everything its record and result need. */
11
+ export interface ConvertExecutionContext {
12
+ submission: ConvertSubmissionIds;
13
+ quote: ConvertQuote;
14
+ amountInBaseUnits: bigint;
15
+ sourceAsset: ConvertResolvedAsset;
16
+ sourceVm: ConvertVm;
17
+ sourceAddress: string;
18
+ destinationAsset: ConvertResolvedAsset;
19
+ recipientAddress: string;
20
+ }
21
+ /** A conversion whose deposit was sent and recorded; what settlement polling follows. */
22
+ export interface ConvertSubmittedTransaction {
23
+ context: ConvertExecutionContext;
24
+ directExecution: DirectExecution;
25
+ }
26
+ /**
27
+ * Registers the deposit as a direct execution so the backend tracks its
28
+ * settlement with Relay, the same as a checkout or withdrawal. Returns the
29
+ * record as registered, which is enough to start polling its status.
30
+ */
31
+ export declare function createConvertDirectExecution({ context, apiKey, userId, }: {
32
+ context: ConvertExecutionContext;
33
+ apiKey: string;
34
+ userId: string;
35
+ }): Promise<DirectExecution>;
36
+ /** What a settled conversion's direct execution reports beyond its status. */
37
+ export interface ConvertSettlement {
38
+ /** Relay's route id, for when the quote didn't carry one. */
39
+ requestId: string | undefined;
40
+ destinationTxIds: string[];
41
+ /** Relay's record of the filled request; never the quote. */
42
+ settledAmountOutBaseUnits: string | undefined;
43
+ }
44
+ /**
45
+ * Reads the Convert extras from a direct execution Relay settled successfully;
46
+ * `useCheckoutDirectExecutionHistory` already decides whether it did.
47
+ */
48
+ export declare function readConvertSettlement(directExecution: DirectExecution): ConvertSettlement;
49
+ export declare function buildConvertSuccessResult({ context, settlement, }: {
50
+ context: ConvertExecutionContext;
51
+ settlement: ConvertSettlement;
52
+ }): ConvertSuccessResult;
@@ -1,4 +1,4 @@
1
- import type { ConvertSourceWallet, ConvertVm, GetConvertSourceWallet } from './types';
1
+ import type { ConvertResolvedAsset, ConvertSourceWallet, ConvertVm, GetConvertSourceWallet } from './types';
2
2
  /**
3
3
  * Which wallet kind a source chain needs, or `undefined` when Convert can't
4
4
  * execute there. EVM needs the chain registered in `@funkit/chains` (wagmi
@@ -19,11 +19,12 @@ export type ConvertSourceWalletSelection = {
19
19
  /** Accepts a resolved wallet only if it is the kind the source chain needs. */
20
20
  export declare function checkConvertSourceWallet(chainId: string, wallet: ConvertSourceWallet): ConvertSourceWalletSelection;
21
21
  /**
22
- * Resolves and validates the wallet for a source chain. The resolver is not
22
+ * Resolves and validates the wallet for a source asset. The resolver is not
23
23
  * called for a chain Convert can't execute on, since a host resolver may do
24
24
  * real work (Polygon confirms the Polymarket proxy with their relayer).
25
25
  */
26
- export declare function selectConvertSourceWallet({ chainId, getSourceWallet, }: {
27
- chainId: string;
26
+ export declare function selectConvertSourceWallet({ asset, getSourceWallet, timeoutMs, }: {
27
+ asset: ConvertResolvedAsset;
28
28
  getSourceWallet: GetConvertSourceWallet;
29
+ timeoutMs?: number;
29
30
  }): Promise<ConvertSourceWalletSelection>;
@@ -0,0 +1,67 @@
1
+ import type { Dnum } from 'dnum';
2
+ import { type ConvertBalances } from './balances';
3
+ import { type ConvertQuote } from './quote';
4
+ import type { ConvertResolvedAsset } from './types';
5
+ /** Why a submit stopped before signing. Nothing was sent. */
6
+ export type ConvertSubmitBlockReason =
7
+ /** The fresh balance read failed or left this asset out. */
8
+ 'balanceUnavailable'
9
+ /** A native EVM source's gas price hasn't loaded, so Max is unknown. */
10
+ | 'feeReserveLoading'
11
+ /** The amount is above the fresh balance less its fee reserve. */
12
+ | 'insufficientBalance'
13
+ /** The quote doesn't say what the user receives. */
14
+ | 'quoteMissingReceiveAmount'
15
+ /** The quote doesn't spend the amount on screen, or doesn't say what it spends. */
16
+ | 'quoteAmountMismatch'
17
+ /** The quote prices the source in different decimals than the SDK resolved. */
18
+ | 'decimalsMismatch';
19
+ /**
20
+ * The pre-sign check's outcome. Only `ready` may sign, and it signs the quote
21
+ * on screen, like withdrawal. Nothing here edits the amount: an over-balance
22
+ * amount is reported with the fresh Max, for the screen to offer like
23
+ * checkout's "Deposit max balance".
24
+ */
25
+ export type ConvertSubmitPreparation = {
26
+ status: 'ready';
27
+ quote: ConvertQuote;
28
+ }
29
+ /** `maxBaseUnits` is 0 when nothing is left after the fee reserve. */
30
+ | {
31
+ status: 'blocked';
32
+ reason: 'insufficientBalance';
33
+ maxBaseUnits: bigint;
34
+ } | {
35
+ status: 'blocked';
36
+ reason: Exclude<ConvertSubmitBlockReason, 'insufficientBalance'>;
37
+ error?: unknown;
38
+ };
39
+ /**
40
+ * The source decimals Relay priced the quote in, when it reports them. A
41
+ * mismatch means the amount and the host's balance were both scaled with the
42
+ * wrong decimals, which the balance check can't see.
43
+ */
44
+ export declare function getQuoteSourceDecimals(quote: ConvertQuote): number | undefined;
45
+ export declare function hasQuoteDecimalsMismatch({ quote, sourceAsset, }: {
46
+ quote: ConvertQuote;
47
+ sourceAsset: ConvertResolvedAsset;
48
+ }): boolean;
49
+ /**
50
+ * The pre-sign check, run on every submit before the first source step: check
51
+ * the quote being converted, re-read the source balance and check the amount
52
+ * against the fresh Max. Returns `ready` with the quote to execute, or why not
53
+ * to sign yet. Like withdrawal, it doesn't requote. Never signs, sends, or
54
+ * edits the amount.
55
+ */
56
+ export declare function prepareConvertSubmit({ sourceAsset, amountBaseUnits, quote, isFeeReserveLoading, getMaxSpendable, refetchBalances, }: {
57
+ sourceAsset: ConvertResolvedAsset;
58
+ amountBaseUnits: bigint;
59
+ /** The quote on screen; it's the one signed. */
60
+ quote: ConvertQuote;
61
+ /** A native EVM source's gas price is loading, so Max is unknown. */
62
+ isFeeReserveLoading: boolean;
63
+ /** The balance less its fee reserve. */
64
+ getMaxSpendable: (balance: Dnum) => Dnum;
65
+ /** Called with only the source asset. */
66
+ refetchBalances: (assets: ConvertResolvedAsset[]) => Promise<ConvertBalances>;
67
+ }): Promise<ConvertSubmitPreparation>;
@@ -7,19 +7,23 @@ export type ConvertVm = 'evm' | 'svm' | 'hypevm';
7
7
  * A token the host lists for Convert, by Fun chain id and token address.
8
8
  * Every chain's native asset (ETH, BNB, SOL, Hypercore perps USDC) uses the
9
9
  * `NATIVE_TOKEN` placeholder, the same as deposit configs; the SDK resolves
10
- * chain-specific ids from it. Balance results are keyed by these same
11
- * addresses. Decimals and icon are resolved from Fun's asset list, not
12
- * supplied here.
10
+ * chain-specific ids from it. Balance entries name these same addresses.
11
+ * Decimals are resolved from Fun's asset list, not supplied here.
13
12
  * @experimental
14
13
  */
15
14
  export interface ConvertAsset {
16
15
  chainId: string;
17
16
  address: string;
18
17
  symbol: string;
18
+ /**
19
+ * Icon to show for this token. Optional: the SDK falls back to its own
20
+ * logo. Must be an http(s) URL.
21
+ */
22
+ iconSrc?: string;
19
23
  }
20
24
  /**
21
25
  * A listed asset with the decimals the SDK resolved from Fun's asset list, so
22
- * the host never has to. What {@link GetConvertSourceBalances} receives.
26
+ * the host never has to. What {@link GetConvertBalances} receives.
23
27
  * @experimental
24
28
  */
25
29
  export interface ConvertResolvedAsset extends ConvertAsset {
@@ -30,7 +34,8 @@ export interface ConvertResolvedAsset extends ConvertAsset {
30
34
  * executes with:
31
35
  * - `evm`: a {@link WithdrawalClient}. `sendTransaction` must return a real
32
36
  * on-chain hash; `sendTransactions` is opt-in and must also return a tx hash,
33
- * never a wallet calls id.
37
+ * never a wallet calls id. Its `adaptedWallet` isn't read: Solana and
38
+ * Hypercore sources use their own entries below.
34
39
  * - `svm`: a {@link SolanaWalletSigner}. `signAndSendTransaction` resolves the
35
40
  * 64-byte signature; when both signing methods are supplied the SDK uses
36
41
  * `signTransaction` and submits itself.
@@ -40,7 +45,7 @@ export interface ConvertResolvedAsset extends ConvertAsset {
40
45
  */
41
46
  export type ConvertSourceWallet = {
42
47
  vm: 'evm';
43
- wallet: WithdrawalClient;
48
+ wallet: Omit<WithdrawalClient, 'adaptedWallet'>;
44
49
  } | {
45
50
  vm: 'svm';
46
51
  signer: SolanaWalletSigner;
@@ -49,38 +54,42 @@ export type ConvertSourceWallet = {
49
54
  signer: HypercoreSigner;
50
55
  };
51
56
  /**
52
- * Resolves the signing wallet for a source chain. Called when the user picks a
53
- * source or flips direction, never for chains they haven't chosen. Polygon
54
- * resolves to the Polymarket proxy client, other EVM chains to the EOA.
57
+ * Resolves the signing wallet for a source asset. Called when the user picks a
58
+ * source or flips direction, never for assets they haven't chosen. The asset
59
+ * lets one chain resolve to different wallets, e.g. Polygon pUSD to the
60
+ * Polymarket proxy client and other Polygon tokens to the EOA.
55
61
  * @experimental
56
62
  */
57
63
  export type GetConvertSourceWallet = (params: {
58
- chainId: string;
64
+ asset: ConvertResolvedAsset;
59
65
  }) => Promise<ConvertSourceWallet>;
60
66
  /**
61
- * Balances for one chain.
62
- * - `walletAddress`: the wallet the balances were read for. Returned, not
63
- * passed in, so the host never has to resolve a wallet just to echo it back.
64
- * - `balances`: base-unit integer strings keyed by token address, in the
65
- * decimals the SDK passed. Leave a token out when it couldn't be read; the
66
- * SDK shows it as unavailable, never as 0. `"0"` means a real zero.
67
+ * One listed asset's balance, as the host read it: a base-unit integer string
68
+ * in the decimals the SDK passed. `"0"` means a real zero.
67
69
  * @experimental
68
70
  */
69
- export interface ConvertSourceBalances {
70
- walletAddress: string;
71
- balances: Record<string, string>;
71
+ export interface ConvertAssetBalance {
72
+ chainId: string;
73
+ address: string;
74
+ balance: string;
75
+ /** USD per whole token. A missing or invalid price makes the asset unavailable. */
76
+ unitPriceUsd: number;
72
77
  }
73
78
  /**
74
- * Fetches live balances for every listed asset on one chain.
79
+ * Reads live balances for the assets it's given, in one call.
80
+ * - Polled with every listed asset while the Convert screen is open.
81
+ * - Called with only the source asset right before signing; answer for
82
+ * exactly the assets passed.
75
83
  * - Read fresh from the host's balance source, not from page state.
76
84
  * - Exclude anything the user can't move (Hypercore locked collateral, margin).
77
- * - Throw on failure; the SDK shows an error state rather than a zero.
85
+ * - Leave out any asset that couldn't be read; the SDK shows it as
86
+ * unavailable, never as 0. Don't throw: an omission already says
87
+ * everything a throw could, per asset instead of for all of them.
78
88
  * @experimental
79
89
  */
80
- export type GetConvertSourceBalances = (params: {
81
- chainId: string;
90
+ export type GetConvertBalances = (params: {
82
91
  assets: ConvertResolvedAsset[];
83
- }) => Promise<ConvertSourceBalances>;
92
+ }) => Promise<ConvertAssetBalance[]>;
84
93
  /** A chain-native transaction id: an EVM hash or a base58 Solana signature. */
85
94
  export interface ConvertTransaction {
86
95
  chainId: string;
@@ -107,13 +116,23 @@ export interface ConvertSuccessResult {
107
116
  sourceTransactions: ConvertTransaction[];
108
117
  destinationTransactions: ConvertTransaction[];
109
118
  }
110
- /** @experimental */
111
- export type ConvertErrorStage = 'quote' | 'source' | 'settlement';
119
+ /**
120
+ * Where a conversion stopped:
121
+ * - `preSign`: the pre-sign check rejected the quote; nothing was signed.
122
+ * - `source`: the source-chain step (signing, sending, switching chain)
123
+ * failed before funds moved; safe to retry.
124
+ * - `unknown`: it may have been submitted but can't be tracked; check the
125
+ * wallet, and never retry.
126
+ * - `settlement`: Relay's fill on the destination failed or was refunded.
127
+ * @experimental
128
+ */
129
+ export type ConvertErrorStage = 'preSign' | 'source' | 'unknown' | 'settlement';
112
130
  /** @experimental */
113
131
  export interface ConvertErrorResult {
114
132
  stage: ConvertErrorStage;
115
133
  /** The user declined a signature; not worth alerting on. */
116
134
  userRejected: boolean;
135
+ /** For logs and debugging; not localized or meant for display. */
117
136
  message: string;
118
137
  /** Whatever was thrown, untouched: a viem, Relay or host wallet error. */
119
138
  error: unknown;
@@ -143,7 +162,13 @@ export interface ConvertConfig {
143
162
  assets: ConvertAsset[];
144
163
  recipientAddresses: ConvertRecipientAddresses;
145
164
  getSourceWallet: GetConvertSourceWallet;
146
- getSourceBalances: GetConvertSourceBalances;
165
+ getBalances: GetConvertBalances;
147
166
  onSuccess?: (result: ConvertSuccessResult) => void;
148
167
  onError?: (error: ConvertErrorResult) => void;
168
+ /**
169
+ * Close the modal a few seconds after a conversion settles, once the host's
170
+ * own UI reflects the new balances. Off, or if the user has moved to another
171
+ * tab meanwhile, the screen returns to Convert for another conversion instead.
172
+ */
173
+ closeOnSuccess?: boolean;
149
174
  }
@@ -0,0 +1,111 @@
1
+ import type { TFunction } from 'i18next';
2
+ import type { ErrorNotification } from '../../components/FunNotification/FunNotification';
3
+ import { type ConvertAssetListStatus } from './assets';
4
+ import { type ConvertBalanceState, type ConvertBalances } from './balances';
5
+ import { type ConvertAmount } from './inputAmount';
6
+ import type { ConvertQuote } from './quote';
7
+ import type { ConvertDraft, ConvertSnapshot, ConvertSubmission } from './reducer';
8
+ import type { ConvertRecipientSelection } from './recipient';
9
+ import { type ConvertActionButton, type ConvertPhase, type ConvertScreenIssue, getConvertReceiveAmounts } from './screen';
10
+ import type { ConvertSourceWalletSelection } from './sourceWallet';
11
+ import type { ConvertResolvedAsset } from './types';
12
+ /** The live reads the draft is checked against, before any quote. */
13
+ export interface ConvertLiveInputs {
14
+ status: ConvertAssetListStatus;
15
+ assets: ConvertResolvedAsset[];
16
+ balances: ConvertBalances | undefined;
17
+ isBalancesFetching: boolean;
18
+ sourceWallet: ConvertSourceWalletSelection | undefined;
19
+ isSourceWalletFetching: boolean;
20
+ recipient: ConvertRecipientSelection | undefined;
21
+ isRecipientFetching: boolean;
22
+ /** The source's Max; `null` while unknown. */
23
+ maxBaseUnits: bigint | null;
24
+ }
25
+ export interface ConvertLiveQuote {
26
+ /** The amount last sent to the quote, after the typing pause. */
27
+ amountBaseUnits: bigint | undefined;
28
+ quote: ConvertQuote | undefined;
29
+ isLoading: boolean;
30
+ isFetching: boolean;
31
+ isError: boolean;
32
+ error: Error | null;
33
+ refreshesAtMs: number | undefined;
34
+ }
35
+ export interface ConvertLive extends ConvertLiveInputs {
36
+ quote: ConvertLiveQuote;
37
+ }
38
+ /** The draft read against live data: what's picked, the amount, and what to quote. */
39
+ export interface ConvertDraftReading {
40
+ sourceAsset: ConvertResolvedAsset | undefined;
41
+ destinationAsset: ConvertResolvedAsset | undefined;
42
+ sourceBalance: ConvertBalanceState | undefined;
43
+ amount: ConvertAmount;
44
+ amountIssue: ConvertScreenIssue | undefined;
45
+ /** `undefined` while the amount has an issue, so nothing is quoted. */
46
+ quoteAmountBaseUnits: bigint | undefined;
47
+ userAddress: string | undefined;
48
+ recipientAddress: string | undefined;
49
+ }
50
+ /** What Retry asks again for; `balances` reloads the asset list too, if that failed. */
51
+ export type ConvertRetryTarget = 'balances' | 'sourceWallet' | 'recipient' | 'quote';
52
+ /** Everything the Convert screens render. */
53
+ export interface ConvertView {
54
+ status: ConvertAssetListStatus;
55
+ assets: ConvertResolvedAsset[];
56
+ balances: ConvertBalances | undefined;
57
+ sourceAsset: ConvertResolvedAsset | undefined;
58
+ destinationAsset: ConvertResolvedAsset | undefined;
59
+ /** Token units; `undefined` while unknown, so it never reads as 0. */
60
+ sourceTokenBalance: number | undefined;
61
+ destinationTokenBalance: number | undefined;
62
+ amount: ConvertAmount;
63
+ /** The source's Max; `null` while unknown or locked. */
64
+ maxBaseUnits: bigint | null;
65
+ /** Shows the unit switch; off without a price to convert with. Locked, the widget disables it. */
66
+ canToggleUnit: boolean;
67
+ quote: ConvertQuote | undefined;
68
+ isQuoteLoading: boolean;
69
+ /** `undefined` hides the countdown: no quote, or one being converted. */
70
+ refreshesAtMs: number | undefined;
71
+ receiveAmounts: ReturnType<typeof getConvertReceiveAmounts>;
72
+ notification: ErrorNotification | undefined;
73
+ actionButton: ConvertActionButton;
74
+ phase: ConvertPhase | undefined;
75
+ /** Nothing on screen can change from the submission until it settles, and after `untrackable`. */
76
+ isLocked: boolean;
77
+ /** Nothing to convert from; the source card offers Deposit instead. */
78
+ isDepositRequired: boolean;
79
+ retryTargets: ConvertRetryTarget[];
80
+ }
81
+ /**
82
+ * The draft against live data. The provider quotes `quoteAmountBaseUnits`
83
+ * with it, and {@link deriveConvertView} reads it again for the screen.
84
+ */
85
+ export declare function readConvertDraft({ draft, live, }: {
86
+ draft: ConvertDraft;
87
+ live: ConvertLiveInputs;
88
+ }): ConvertDraftReading;
89
+ /**
90
+ * What a press converts, frozen for the locked view. `undefined` without
91
+ * everything signing needs; Convert is disabled then anyway.
92
+ */
93
+ export declare function getConvertSnapshot({ reading, sourceWallet, amountBaseUnits, quote, }: {
94
+ reading: ConvertDraftReading;
95
+ sourceWallet: ConvertSourceWalletSelection | undefined;
96
+ /** The amount the quote was requested for, after the typing pause. */
97
+ amountBaseUnits: bigint | undefined;
98
+ /** The quote on screen, unless it's already been signed. */
99
+ quote: ConvertQuote | undefined;
100
+ }): ConvertSnapshot | undefined;
101
+ /**
102
+ * Everything the Convert screens render. While a submission is locked it reads
103
+ * the snapshot; otherwise the draft against live data, with a failed
104
+ * submission's issue until the next edit ends it.
105
+ */
106
+ export declare function deriveConvertView({ draft, live, submission, t, }: {
107
+ draft: ConvertDraft;
108
+ live: ConvertLive;
109
+ submission: ConvertSubmission | undefined;
110
+ t: TFunction;
111
+ }): ConvertView;
@@ -0,0 +1,29 @@
1
+ import type { Dnum } from 'dnum';
2
+ /**
3
+ * SOL held back when the source is native SOL, which also pays the fee.
4
+ * - The rent-exempt minimum: Solana rejects leaving the payer between 0 and it
5
+ * (0.00089088 SOL before SIMD-0437 began lowering it in 2026).
6
+ * - Headroom for the priority fee added at signing, which quotes leave out
7
+ * (up to ~56k lamports on Relay SOL deposits in Oct 2026).
8
+ */
9
+ export declare const SOLANA_NATIVE_FEE_RESERVE = "0.0025";
10
+ /**
11
+ * Which fee reserve a source token needs, by the VM that charges the fee:
12
+ * - `evm`: native ETH/BNB/POL; reserve live gas.
13
+ * - `svm`: native SOL; reserve {@link SOLANA_NATIVE_FEE_RESERVE}.
14
+ *
15
+ * `undefined` when the fee isn't paid from this token (ERC-20, SPL, Hypercore USDC).
16
+ */
17
+ export type NativeFeeReserveType = 'evm' | 'svm';
18
+ export declare function getNativeFeeReserveType(chainId: string, tokenAddress: string): NativeFeeReserveType | undefined;
19
+ /**
20
+ * The most a source token can send: the balance less its fee reserve, floored
21
+ * at zero, in the balance's decimals. An EVM native source without a gas
22
+ * reserve (a chain that can't be priced) gets the full balance.
23
+ */
24
+ export declare function getMaxSpendableAmount({ balance, chainId, tokenAddress, evmGasReserve, }: {
25
+ balance: Dnum;
26
+ chainId: string;
27
+ tokenAddress: string;
28
+ evmGasReserve?: Dnum;
29
+ }): Dnum;
@@ -44,6 +44,18 @@ export interface CheckedAssetAmount {
44
44
  minTargetAssetAmount?: Dnum;
45
45
  }
46
46
  export declare function checkAssetAmount(checkoutItem: FunkitActiveCheckoutItem, finalEstimation: FunkitCheckoutQuoteResult, wagmiConfig: Config, walletAddress: Address, brokerage?: BrokerageDetails): Promise<CheckedAssetAmount>;
47
+ export type QuotePhaseResult = {
48
+ phase: 'base';
49
+ quote: CheckoutQuoteResponse;
50
+ status: 'success';
51
+ } | {
52
+ phase: 'final';
53
+ quote: FunkitCheckoutQuoteResult;
54
+ status: 'success';
55
+ } | {
56
+ phase: 'base' | 'final';
57
+ status: 'failed';
58
+ };
47
59
  export interface CheckoutQuoteParams {
48
60
  checkoutItem: FunkitActiveCheckoutItem;
49
61
  walletAddress: Address;
@@ -57,8 +69,9 @@ export interface CheckoutQuoteParams {
57
69
  **/
58
70
  senderAddress?: Address;
59
71
  isWithdrawal?: boolean;
72
+ onQuotePhaseSettled?: (result: QuotePhaseResult) => void;
60
73
  }
61
- export declare function getQuoteAndEstimation({ checkoutItem, walletAddress, apiKey, newPaymentMethodInfo, wagmiConfig, loginType, directExecutionInfo, senderAddress, isWithdrawal, }: CheckoutQuoteParams): Promise<{
74
+ export declare function getQuoteAndEstimation({ checkoutItem, walletAddress, apiKey, newPaymentMethodInfo, wagmiConfig, loginType, directExecutionInfo, senderAddress, isWithdrawal, onQuotePhaseSettled, }: CheckoutQuoteParams): Promise<{
62
75
  baseQuote: CheckoutQuoteResponse;
63
76
  checkedAssetAmount: CheckedAssetAmount;
64
77
  finalEstimation: FunkitCheckoutQuoteResult;
@@ -13,6 +13,12 @@ export declare const useWithdrawFops: (params: {
13
13
  * is resolved, so the first /fops call never goes out uncapped.
14
14
  */
15
15
  enabled?: boolean;
16
+ /**
17
+ * Whether an `enabled: false` caller gate is actively pending and expected
18
+ * to become true. Keeps readiness from waiting on deliberately disabled
19
+ * queries.
20
+ */
21
+ enablePending?: boolean;
16
22
  }) => {
17
23
  data: GetFopsResponse | undefined;
18
24
  isLoading: boolean;
@@ -1,5 +1,8 @@
1
+ import type { FunCheckoutStep } from '../../modals/CheckoutModal/FunCheckoutStep';
2
+ import type { WithdrawalModalStep } from '../../modals/WithdrawalModal/types';
1
3
  import { type FunkitWithdrawalConfig } from '../../providers/FunkitCheckoutContext';
2
4
  interface CheckoutQuoteParams {
5
+ analyticsStep: FunCheckoutStep | WithdrawalModalStep;
3
6
  recipientAddress: string;
4
7
  selectedChainId: string | undefined;
5
8
  selectedTokenAddress: string | null | undefined;
@@ -12,7 +15,7 @@ export declare const PLACEHOLDER_WITHDRAWAL_WALLET_ADDRESS = "0x0000000000000000
12
15
  /**
13
16
  * Simplified quoting logic used for withdrawal UI only.
14
17
  */
15
- export declare function useWithdrawalQuote({ recipientAddress, selectedChainId, selectedTokenAddress, selectedTokenSymbol, config, isEnabled, }: CheckoutQuoteParams): {
18
+ export declare function useWithdrawalQuote({ analyticsStep, recipientAddress, selectedChainId, selectedTokenAddress, selectedTokenSymbol, config, isEnabled, }: CheckoutQuoteParams): {
16
19
  quoteEnabled: boolean;
17
20
  withdrawalWalletAddress: `0x${string}`;
18
21
  data: {
@@ -26,6 +26,8 @@ export declare enum CheckoutModalEvent {
26
26
  NAVIGATE_SWAPPED_IFRAME = "fc::navigate::swapped_iframe",
27
27
  NAVIGATE_PERPS_TRANSFER = "fc::navigate::perps_transfer",
28
28
  NAVIGATE_CONVERT = "fc::navigate::convert",
29
+ NAVIGATE_CONVERT_SELECT_SOURCE = "fc::navigate::convert_select_source",
30
+ NAVIGATE_CONVERT_SELECT_DESTINATION = "fc::navigate::convert_select_destination",
29
31
  READY_CONFIRMATION = "fc::ready::confirmation",
30
32
  READY_INPUT_AMOUNT = "fc::ready::input_amount",
31
33
  READY_SELECT_ASSET = "fc::ready::select_asset",
@@ -7,6 +7,7 @@ export declare enum WithdrawModalEvent {
7
7
  CASH_FOP_SELECTED = "fw::cash_fop_selected",
8
8
  FINAL_QUOTE = "fw::quote::final_quote",
9
9
  VIEW_TRANSACTION_BREAKDOWN = "fw::quote::view_transaction_breakdown",
10
+ QUERY_WITHDRAW_FOPS = "fw::query::withdraw_fops",
10
11
  PENDING_CALLBACK = "fw::pending_callback",
11
12
  SUCCESS = "fw::success",
12
13
  SWAPPED_IFRAME_READY = "fw::swapped::ready",
@@ -1,11 +1,12 @@
1
1
  import type { QuoteMode } from '../../../domains/quoteMode';
2
- import type { DirectExecutionType } from '@funkit/api-base';
2
+ import type { DirectExecutionType, FormOfPaymentType } from '@funkit/api-base';
3
3
  import type { CheckoutStatus } from '../../../domains/checkout';
4
4
  import type { PaymentMethodType } from '../../../hooks/usePaymentSources';
5
5
  import type { FunCheckoutStep } from '../../../modals/CheckoutModal/FunCheckoutStep';
6
6
  import type { AmountSelectionType } from '../../../modals/CheckoutModal/InputAmount/state';
7
7
  import type { WithdrawalModalStep } from '../../../modals/WithdrawalModal/types';
8
8
  import type { FunNotificationType } from '../../../components/FunNotification/FunNotification';
9
+ import type { PaymentMethod } from '@funkit/connect-core';
9
10
  /**
10
11
  * Analytics v2 — the improved, explicit Statsig event scheme that will replace
11
12
  * the `fc::`/`fw::` enums in `../CheckoutModalEvent.ts` / `../WithdrawModalEvent.ts`.
@@ -28,8 +29,12 @@ export declare enum AnalyticsEvent {
28
29
  DEPOSIT_TRANSACTION_BREAKDOWN_CLICKED = "fc_deposit_transaction_breakdown_clicked",
29
30
  DEPOSIT_TRANSACTION_SUBMITTED = "fc_deposit_transaction_submitted",
30
31
  ERROR_SHOWN = "fc_error_shown",
32
+ IFRAME_STEP_VIEWED = "fc_iframe_step_viewed",
31
33
  MODAL_CLOSED = "fc_modal_closed",
32
34
  MODAL_OPENED = "fc_modal_opened",
35
+ PERF_IFRAME_READY = "fc_perf_iframe_ready",
36
+ PERF_QUOTE = "fc_perf_quote",
37
+ PERF_STEP_READY = "fc_perf_step_ready",
33
38
  STEP_VIEWED = "fc_step_viewed",
34
39
  TAB_SWITCHED = "fc_tab_switched",
35
40
  WITHDRAWAL_AMOUNT_CONFIRMED = "fc_withdrawal_amount_confirmed",
@@ -274,6 +279,21 @@ export type StepViewedProperties = {
274
279
  */
275
280
  step_index: number;
276
281
  };
282
+ /** Payload specific to {@link AnalyticsEvent.IFRAME_STEP_VIEWED}. */
283
+ export type IframeStepViewedProperties = {
284
+ iframe_step: string;
285
+ iframe_step_index: number;
286
+ /**
287
+ * True when `iframe_step` already appears in the current iframe-controller
288
+ * navigation history. This is inferred from recurrence, not an observed Back
289
+ * action, so a forward loop to a previously visited step may also be `true`.
290
+ */
291
+ is_back_navigation: boolean;
292
+ payment_method: string;
293
+ payment_rail: 'swapped';
294
+ prev_iframe_step: string | null;
295
+ step: AnalyticsStep;
296
+ };
277
297
  export type DepositTransferInteractionAction = 'address_copied' | 'chain_changed' | 'token_changed';
278
298
  export type DepositTransferInteractedProperties = PaymentMethodProperties & {
279
299
  action: DepositTransferInteractionAction;
@@ -296,6 +316,40 @@ export type WithdrawalMethodSelectedProperties = PaymentMethodProperties & {
296
316
  connection_status: ConnectionStatus | null;
297
317
  payment_rail: AnalyticsPaymentRail | null;
298
318
  };
319
+ /** Payload specific to {@link AnalyticsEvent.PERF_QUOTE}. */
320
+ export type PerfQuoteProperties = DepositAssetContextProperties & {
321
+ execution_type: DirectExecutionType | null;
322
+ /** 1-based quote request index within the checkout and quote flow. */
323
+ quote_attempt: number;
324
+ /** 'base' measures time-to-first-quote; 'final' measures time-to-full-quote. */
325
+ quote_phase: 'base' | 'final';
326
+ source_amount: string | null;
327
+ status: 'failed' | 'success';
328
+ step: AnalyticsStep;
329
+ target_amount: string | null;
330
+ total_ms: number;
331
+ trade_type: QuoteMode;
332
+ };
333
+ export type PerfStepReadyProperties = {
334
+ [query_timing_ms: `query_timing_ms.${string}`]: number;
335
+ is_first: boolean;
336
+ payment_method: PaymentMethod | Lowercase<FormOfPaymentType> | null;
337
+ step: AnalyticsStep;
338
+ total_ms: number;
339
+ };
340
+ /** Payload specific to {@link AnalyticsEvent.PERF_IFRAME_READY}. */
341
+ export type PerfIframeReadyProperties = {
342
+ /** First time this checkout's Swapped iframe reported ready. */
343
+ is_first: boolean;
344
+ payment_method: string;
345
+ payment_rail: 'swapped';
346
+ step: AnalyticsStep;
347
+ /**
348
+ * User-visible wait time (from step mount to ready).
349
+ * May be ~0 if iframe was already fully preloaded.
350
+ */
351
+ total_ms: number;
352
+ };
299
353
  export type WithdrawalTransferInteractionAction = 'address_autofilled' | 'address_changed' | 'amount_changed' | 'chain_changed' | 'max_button_clicked' | 'token_changed';
300
354
  /** Payload specific to {@link AnalyticsEvent.WITHDRAWAL_TRANSFER_INTERACTED}. */
301
355
  export type WithdrawalTransferInteractedProperties = PaymentMethodProperties & {
@@ -357,8 +411,12 @@ export type AnalyticsEventProperties = {
357
411
  [AnalyticsEvent.DEPOSIT_TRANSACTION_BREAKDOWN_CLICKED]: TransactionBreakdownClickedProperties;
358
412
  [AnalyticsEvent.DEPOSIT_TRANSACTION_SUBMITTED]: TransactionSubmittedProperties;
359
413
  [AnalyticsEvent.ERROR_SHOWN]: ErrorShownProperties;
414
+ [AnalyticsEvent.IFRAME_STEP_VIEWED]: IframeStepViewedProperties;
360
415
  [AnalyticsEvent.MODAL_CLOSED]: ModalClosedProperties;
361
416
  [AnalyticsEvent.MODAL_OPENED]: ModalOpenedProperties;
417
+ [AnalyticsEvent.PERF_IFRAME_READY]: PerfIframeReadyProperties;
418
+ [AnalyticsEvent.PERF_QUOTE]: PerfQuoteProperties;
419
+ [AnalyticsEvent.PERF_STEP_READY]: PerfStepReadyProperties;
362
420
  [AnalyticsEvent.STEP_VIEWED]: StepViewedProperties;
363
421
  [AnalyticsEvent.TAB_SWITCHED]: TabSwitchedProperties;
364
422
  [AnalyticsEvent.WITHDRAWAL_AMOUNT_CONFIRMED]: WithdrawalAmountConfirmedProperties;
@@ -1,9 +1,9 @@
1
- import { FormOfPaymentType, type MeldServiceProvider } from '@funkit/api-base';
1
+ import { FormOfPaymentType, type MeldServiceProvider, type SwappedFormOfPayment } from '@funkit/api-base';
2
2
  import { PaymentMethod, type PaymentMethodInfo } from '../../../domains/paymentMethods';
3
- import type { AnalyticsFlow, AnalyticsStep, PaymentMethodProperties } from './events';
4
3
  import { FunCheckoutStep } from '../../../modals/CheckoutModal/FunCheckoutStep';
5
4
  import type { CheckoutModalState } from '../../../modals/CheckoutModal/stepTransition';
6
- import type { WithdrawalModalStep } from '../../../modals/WithdrawalModal/types';
5
+ import { WithdrawalModalStep } from '../../../modals/WithdrawalModal/types';
6
+ import type { AnalyticsFlow, AnalyticsStep, PaymentMethodProperties } from './events';
7
7
  /** Round analytics amounts before Statsig stringifies event metadata. */
8
8
  export declare function formatAnalyticsAmount(amount: number | null): string | null;
9
9
  export declare function formatAnalyticsStep(step: FunCheckoutStep | WithdrawalModalStep): AnalyticsStep;
@@ -19,4 +19,5 @@ export declare function resolvePaymentMethodProperties(args: {
19
19
  paymentMethodInfo: PaymentMethodInfo;
20
20
  serviceProvider?: MeldServiceProvider;
21
21
  }, connectorId: string | undefined): PaymentMethodProperties;
22
- export declare function mapSwappedFopTypeToPaymentMethod(fopType: FormOfPaymentType): PaymentMethod | null;
22
+ export declare function mapSwappedFopTypeToPaymentMethod(fopType: FormOfPaymentType): PaymentMethod | Lowercase<FormOfPaymentType>;
23
+ export declare function getWithdrawalAnalyticsPaymentMethod(step: WithdrawalModalStep, selectedFop?: Pick<SwappedFormOfPayment, 'fopType'> | null): PaymentMethod | Lowercase<FormOfPaymentType> | null;
@@ -0,0 +1,18 @@
1
+ export declare const INITIAL_SWAPPED_IFRAME_STEP = "EMPTY";
2
+ export declare const UNKNOWN_SWAPPED_IFRAME_STEP = "UNKNOWN";
3
+ /**
4
+ * Narrows the runtime value received over postMessage without preventing
5
+ * Swapped from introducing new enum-like steps.
6
+ */
7
+ export declare function sanitizeSwappedIframeStep(step: unknown): string;
8
+ export interface IframeStepNavigationResult {
9
+ history: string[];
10
+ index: number;
11
+ isBackNavigation: boolean;
12
+ }
13
+ /**
14
+ * Infers back-navigation purely from step recurrence, since the Swapped embed
15
+ * doesn't report navigation direction. A step already in history is treated
16
+ * as a rewind (history truncated to that point); a new step is appended.
17
+ */
18
+ export declare function resolveIframeStepNavigation(history: readonly string[], nextStep: string): IframeStepNavigationResult;