@funkit/connect 12.17.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 (74) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/clients/axiom.d.ts +0 -4
  3. package/dist/clients/{chunk-V4RIF2NR.js → chunk-AELXD5XA.js} +1 -1
  4. package/dist/clients/{chunk-HANOVGPH.js → chunk-FOXMRDKD.js} +1 -1
  5. package/dist/clients/{chunk-TWP5LFPX.js → chunk-G6A62MZO.js} +5 -5
  6. package/dist/clients/{chunk-LVR6RQMO.js → chunk-L6JL2XJY.js} +1 -1
  7. package/dist/clients/{chunk-I5VRAFH6.js → chunk-LCYJLY4X.js} +1 -1
  8. package/dist/clients/{chunk-2L6IKKNH.js → chunk-YSAAJSWT.js} +224 -16
  9. package/dist/clients/fanatics.js +2 -2
  10. package/dist/clients/internal/nado/withdrawalCallback.js +4 -4
  11. package/dist/clients/internal/nado/withdrawalConfig.js +2 -2
  12. package/dist/clients/internal/nado/withdrawalErrors.js +2 -2
  13. package/dist/clients/internal/nado/withdrawalForm.js +5 -5
  14. package/dist/clients/internal/nado/withdrawalStatus.js +3 -3
  15. package/dist/clients/lighter.css +8 -8
  16. package/dist/clients/lighter.js +3 -3
  17. package/dist/clients/mallard.js +2 -2
  18. package/dist/clients/nado.js +4 -4
  19. package/dist/components/LargeAmountInput/LargeAmountInput.d.ts +3 -1
  20. package/dist/components/TokenSwapWidget/TokenSelectButton/TokenSelectButton.d.ts +5 -2
  21. package/dist/components/TokenSwapWidget/TokenSwapCard/TokenSwapCard.d.ts +7 -3
  22. package/dist/components/TokenSwapWidget/TokenSwapWidget.d.ts +7 -2
  23. package/dist/domains/convert/assets.d.ts +9 -1
  24. package/dist/domains/convert/balances.d.ts +31 -8
  25. package/dist/domains/convert/errors.d.ts +2 -2
  26. package/dist/domains/convert/hostTimeout.d.ts +8 -0
  27. package/dist/domains/convert/inputAmount.d.ts +30 -1
  28. package/dist/domains/convert/quote.d.ts +17 -8
  29. package/dist/domains/convert/recipient.d.ts +2 -1
  30. package/dist/domains/convert/reducer.d.ts +112 -0
  31. package/dist/domains/convert/screen.d.ts +169 -0
  32. package/dist/domains/convert/settlement.d.ts +6 -1
  33. package/dist/domains/convert/sourceWallet.d.ts +5 -4
  34. package/dist/domains/convert/submit.d.ts +25 -4
  35. package/dist/domains/convert/types.d.ts +15 -6
  36. package/dist/domains/convert/view.d.ts +111 -0
  37. package/dist/hooks/track/CheckoutModalEvent.d.ts +2 -0
  38. package/dist/hooks/useConvertAssetList.d.ts +23 -0
  39. package/dist/hooks/useConvertAssets.d.ts +3 -1
  40. package/dist/hooks/useConvertBalances.d.ts +9 -3
  41. package/dist/hooks/useConvertExecute.d.ts +17 -61
  42. package/dist/hooks/useConvertQuote.d.ts +22 -2
  43. package/dist/hooks/useConvertSelectionWallets.d.ts +34 -0
  44. package/dist/hooks/useConvertTransactionStatus.d.ts +11 -17
  45. package/dist/index.css +8 -8
  46. package/dist/index.d.ts +2 -1
  47. package/dist/index.js +6460 -2580
  48. package/dist/modals/CheckoutModal/Convert/ConvertAssetList.d.ts +16 -0
  49. package/dist/modals/CheckoutModal/Convert/ConvertAssetRow.d.ts +21 -0
  50. package/dist/modals/CheckoutModal/Convert/ConvertChainPills.d.ts +14 -0
  51. package/dist/modals/CheckoutModal/Convert/ConvertSelectDestinationStep.d.ts +30 -0
  52. package/dist/modals/CheckoutModal/Convert/ConvertSelectSourceStep.d.ts +18 -0
  53. package/dist/modals/CheckoutModal/Convert/ConvertStep.d.ts +4 -2
  54. package/dist/modals/CheckoutModal/FunCheckoutStep.d.ts +2 -0
  55. package/dist/modals/CheckoutModal/SourceChange/SourceChange.d.ts +5 -3
  56. package/dist/modals/CheckoutModal/Withdrawal/WithdrawalComplete.d.ts +5 -2
  57. package/dist/modals/CheckoutModal/Withdrawal/WithdrawalEnterAmount.d.ts +4 -2
  58. package/dist/modals/CheckoutModal/stepTransition.d.ts +6 -0
  59. package/dist/modals/CheckoutModal/stepTransition.shared.d.ts +0 -1
  60. package/dist/modals/WithdrawalModal/WithdrawAmountInput.d.ts +15 -4
  61. package/dist/modals/WithdrawalModal/WithdrawalContent.d.ts +7 -7
  62. package/dist/modals/WithdrawalModal/useMultiSourceWithdrawal.d.ts +41 -0
  63. package/dist/providers/ConvertProvider.d.ts +40 -0
  64. package/dist/providers/FunkitCheckoutContext/index.d.ts +2 -2
  65. package/dist/providers/FunkitCheckoutContext/types.d.ts +36 -2
  66. package/dist/shadow-css.js +1 -1
  67. package/dist/utils/withdrawal.d.ts +28 -1
  68. package/dist/wallets/multiSourceWithdrawal.d.ts +36 -0
  69. package/dist/wallets/walletConnectors/index.js +43 -43
  70. package/package.json +3 -3
  71. package/dist/hooks/useConvertInputAmount.d.ts +0 -26
  72. package/dist/hooks/useConvertMaxAmount.d.ts +0 -11
  73. package/dist/hooks/usePrepareConvertSubmit.d.ts +0 -22
  74. /package/dist/clients/{chunk-4DBUYTEE.js → chunk-LICTGZXW.js} +0 -0
@@ -18,9 +18,11 @@ export interface LargeAmountInputProps {
18
18
  maxFontSize?: number;
19
19
  /** Caps the width the text shrinks to fit, on top of the measured container. */
20
20
  maxAvailableWidth?: number;
21
+ /** Overrides the measured text width, e.g. `'100%'` to widen the click target. */
22
+ width?: number | string;
21
23
  testId?: string;
22
24
  }
23
25
  /**
24
26
  * Big "$<amount>" field that shrinks its font to fit the available width.
25
27
  */
26
- export declare function LargeAmountInput({ amount, onAmountChange, ariaLabel, align, prefix, suffix, placeholder, readOnly, autoFocus, maxFontSize: maxFontSizeProp, maxAvailableWidth, testId, }: LargeAmountInputProps): React.JSX.Element;
28
+ export declare function LargeAmountInput({ amount, onAmountChange, ariaLabel, align, prefix, suffix, placeholder, readOnly, autoFocus, maxFontSize: maxFontSizeProp, maxAvailableWidth, width, testId, }: LargeAmountInputProps): React.JSX.Element;
@@ -5,13 +5,16 @@ export interface TokenSwapToken {
5
5
  chainId?: string | number;
6
6
  }
7
7
  export interface TokenSelectButtonProps {
8
- token: TokenSwapToken;
8
+ /** Omit when nothing is picked yet; the button then reads "Select token". */
9
+ token?: TokenSwapToken;
9
10
  /** Omit to render the token without the picker affordance. */
10
11
  onClick?: () => void;
12
+ /** Keeps the picker affordance but ignores clicks. */
13
+ isDisabled?: boolean;
11
14
  testId?: string;
12
15
  }
13
16
  /**
14
17
  * Token icon (with chain badge), symbol and ">" that opens the token picker.
15
18
  * Without `onClick` it renders as plain content, so it isn't a dead tab stop.
16
19
  */
17
- export declare function TokenSelectButton({ token, onClick, testId, }: TokenSelectButtonProps): React.JSX.Element;
20
+ export declare function TokenSelectButton({ token, onClick, isDisabled, testId, }: TokenSelectButtonProps): React.JSX.Element | null;
@@ -22,14 +22,18 @@ interface TokenSwapCardContentProps {
22
22
  convertedAmount: string;
23
23
  onToggleUnit?: () => void;
24
24
  balance?: string;
25
+ /** Makes the balance a button, e.g. to fill in Max. */
26
+ onBalanceClick?: () => void;
25
27
  isLoading?: boolean;
28
+ /** Keeps the layout but makes every control inert. */
29
+ isDisabled?: boolean;
26
30
  testId: string;
27
31
  }
28
32
  export type TokenSwapCardProps = TokenSwapCardContentProps & TokenSwapDepositState;
29
33
  /**
30
34
  * One card of the swap widget.
31
- * - `from`: filled background, unit toggle, highlighted balance; editable unless a deposit is required.
32
- * - `to`: outlined, read-only, amount comes from the quote.
35
+ * - `from`: outlined, unit toggle, highlighted balance; editable unless a deposit is required.
36
+ * - `to`: filled background, read-only, amount comes from the quote.
33
37
  */
34
- export declare function TokenSwapCard({ variant, label, token, isDepositRequired, onDeposit, onTokenClick, amount, amountPrefix, onAmountChange, convertedAmount, onToggleUnit, balance, isLoading, testId, }: TokenSwapCardProps): React.JSX.Element;
38
+ export declare function TokenSwapCard({ variant, label, token, isDepositRequired, onDeposit, onTokenClick, amount, amountPrefix, onAmountChange, convertedAmount, onToggleUnit, balance, onBalanceClick, isLoading, isDisabled, testId, }: TokenSwapCardProps): React.JSX.Element;
35
39
  export {};
@@ -16,6 +16,8 @@ export type TokenSwapFrom = TokenSwapAmounts & TokenSwapDepositState & {
16
16
  /** What the user typed, in `unit`. */
17
17
  inputValue: string;
18
18
  onInputChange: (next: string) => void;
19
+ /** Omit while Max is unknown; the balance then stays plain text. */
20
+ onBalanceClick?: () => void;
19
21
  };
20
22
  export interface TokenSwapTo extends TokenSwapAmounts {
21
23
  /** Shows a skeleton in place of the amount while the quote loads. */
@@ -28,11 +30,14 @@ export interface TokenSwapWidgetProps {
28
30
  unit: AmountUnit;
29
31
  /** Omit to hide the unit switch (e.g. price unknown). */
30
32
  onToggleUnit?: () => void;
31
- onSwapDirection: () => void;
33
+ /** Omit to show the swap icon as decoration only. */
34
+ onSwapDirection?: () => void;
32
35
  isSwapDirectionDisabled?: boolean;
36
+ /** Keeps the layout but makes every control inert, e.g. while converting. */
37
+ isDisabled?: boolean;
33
38
  }
34
39
  /**
35
40
  * From card, swap-direction button, To card. Layout and callbacks only; the
36
41
  * caller owns amounts, quotes and token selection.
37
42
  */
38
- export declare function TokenSwapWidget({ from, to, unit, onToggleUnit, onSwapDirection, isSwapDirectionDisabled, }: TokenSwapWidgetProps): React.JSX.Element;
43
+ export declare function TokenSwapWidget({ from, to, unit, onToggleUnit, onSwapDirection, isSwapDirectionDisabled, isDisabled, }: TokenSwapWidgetProps): React.JSX.Element;
@@ -1,13 +1,19 @@
1
1
  import type { GetSupportedAssetsResponse, SupportedAssetInfo } from '@funkit/api-base';
2
2
  import type { Config } from '../../wagmi/hooks';
3
3
  import type { ConvertAsset, ConvertResolvedAsset } from './types';
4
+ /** Where the host's asset list and balances stand: still loading, failed, or readable. */
5
+ export type ConvertAssetListStatus = 'loading' | 'error' | 'ready';
4
6
  /**
5
7
  * Looks a host-listed token up in the supported-assets list. Hosts key every
6
8
  * native asset by the `NATIVE_TOKEN` placeholder, but the list keys Hypercore's
7
9
  * under Relay's id, so a placeholder miss retries with the Relay key.
8
10
  */
9
11
  export declare function findSupportedAsset(supportedAssets: GetSupportedAssetsResponse, chainId: string, address: string): SupportedAssetInfo | undefined;
10
- /** Host icon, then the asset list's, then the symbol default. */
12
+ /**
13
+ * Host icon, then the SDK's own logo for the symbol, then the asset list's,
14
+ * then a CDN guess. The SDK logo outranks the list because list logos come
15
+ * from mixed third parties, and some are wrong (HYPE shows HyperEVM's).
16
+ */
11
17
  export declare function resolveConvertAssetIcon(asset: ConvertAsset, supportedAssetLogo: string | undefined): string;
12
18
  /**
13
19
  * Resolves decimals and an icon for every host-listed asset. The supported
@@ -20,3 +26,5 @@ export declare function resolveConvertAssets({ assets, supportedAssets, wagmiCon
20
26
  supportedAssets: GetSupportedAssetsResponse;
21
27
  wagmiConfig: Config;
22
28
  }): Promise<ConvertResolvedAsset[]>;
29
+ /** The listed asset with this {@link convertAssetKey}, if any. */
30
+ export declare function findConvertAsset(assets: ConvertResolvedAsset[] | undefined, assetKey: string | undefined): ConvertResolvedAsset | undefined;
@@ -1,3 +1,4 @@
1
+ import type { Dnum } from 'dnum';
1
2
  import type { ConvertAssetBalance, ConvertResolvedAsset, GetConvertBalances } from './types';
2
3
  /**
3
4
  * One spelling per token address.
@@ -6,30 +7,52 @@ import type { ConvertAssetBalance, ConvertResolvedAsset, GetConvertBalances } fr
6
7
  * - Anything else (Hypercore's `0x` + 32-zero placeholder): lowercase.
7
8
  */
8
9
  export declare function normalizeTokenAddress(chainId: string, tokenAddress: string): string;
9
- /** The key one asset's balance is stored under. */
10
- export declare function convertBalanceKey(chainId: string, address: string): string;
10
+ /** One asset's identity, `chainId:address`; also the key its balance is stored under. */
11
+ export declare function convertAssetKey(chainId: string, address: string): string;
11
12
  export type ConvertBalanceState = {
12
13
  status: 'available';
13
14
  baseUnits: string;
15
+ unitPriceUsd: number;
14
16
  } | {
15
17
  status: 'unavailable';
16
18
  };
17
- /** One entry per listed asset, keyed by {@link convertBalanceKey}. */
19
+ /** A readable balance in whole tokens, for display; `undefined` when unknown. */
20
+ export declare function getConvertAssetAmount(balance: ConvertBalanceState | undefined, decimals: number): number | undefined;
21
+ /** A balance read as zero: the token isn't held, so it isn't offered as a source. */
22
+ export declare function isEmptyConvertBalance(balance: ConvertBalanceState | undefined): boolean;
23
+ /** One entry per listed asset, keyed by {@link convertAssetKey}. */
18
24
  export type ConvertBalances = Record<string, ConvertBalanceState>;
19
25
  /**
20
26
  * Turns the host's asset balances into one state per listed asset. An asset
21
- * the host left out, or returned malformed, is unavailable; it never becomes
22
- * 0. Balances for assets that weren't requested are ignored.
27
+ * the host left out, or returned with a malformed balance or price, is
28
+ * unavailable; it never becomes 0. Balances for assets that weren't requested
29
+ * are ignored.
23
30
  */
24
31
  export declare function parseConvertBalances({ assets, assetBalances, }: {
25
32
  assets: ConvertResolvedAsset[];
26
33
  assetBalances: ConvertAssetBalance[];
27
34
  }): ConvertBalances;
35
+ /** The balance in USD; `undefined` when the balance is unknown. */
36
+ export declare function getConvertUsdAmount(balance: ConvertBalanceState | undefined, decimals: number): number | undefined;
28
37
  /**
29
- * Calls the host getter and parses its result. A throw is logged and
30
- * rethrown so the query keeps the last good read instead of replacing it.
38
+ * What Max fills in for a Convert source, in its base units: the balance less
39
+ * its fee reserve. `null` disables Max: no source yet, the balance is
40
+ * unavailable or not yet read, or a native EVM source's gas price is loading.
31
41
  */
32
- export declare function fetchConvertBalances({ assets, getBalances, }: {
42
+ export declare function getConvertMaxAmount({ asset, balance, isFeeReserveLoading, getMaxSpendable, }: {
43
+ asset: ConvertResolvedAsset | undefined;
44
+ balance: ConvertBalanceState | undefined;
45
+ /** A native EVM source's gas price is loading, so Max is unknown. */
46
+ isFeeReserveLoading: boolean;
47
+ /** The balance less its fee reserve. */
48
+ getMaxSpendable: (balance: Dnum) => Dnum;
49
+ }): bigint | null;
50
+ /**
51
+ * Calls the host getter and parses its result. A throw or timeout is logged
52
+ * and rethrown so the query keeps the last good read instead of replacing it.
53
+ */
54
+ export declare function fetchConvertBalances({ assets, getBalances, timeoutMs, }: {
33
55
  assets: ConvertResolvedAsset[];
34
56
  getBalances: GetConvertBalances;
57
+ timeoutMs?: number;
35
58
  }): Promise<ConvertBalances>;
@@ -31,8 +31,8 @@ export type ConvertFailure = {
31
31
  };
32
32
  /**
33
33
  * The host's `onError` payload for a failure, or `undefined` for a block the
34
- * user fixes on screen (balance, fee reserve, missing quote), which the host
35
- * never needs to hear about.
34
+ * user fixes on screen (balance, fee reserve), which the host never needs to
35
+ * hear about.
36
36
  */
37
37
  export declare function toConvertErrorResult(failure: ConvertFailure): ConvertErrorResult | undefined;
38
38
  export declare function reportConvertError(failure: ConvertFailure, onError: ConvertConfig['onError']): void;
@@ -0,0 +1,8 @@
1
+ /** How long a host callback gets before Convert treats it as failed. */
2
+ export declare const HOST_TIMEOUT_MS = 10000;
3
+ /**
4
+ * Rejects if the host's promise hasn't settled in time, so a callback that
5
+ * never answers shows as a failure the user can retry, not endless loading.
6
+ * The host's own work isn't cancelled; its late answer is ignored.
7
+ */
8
+ export declare function withHostTimeout<T>(promise: Promise<T>, timeoutMs?: number): Promise<T>;
@@ -1,4 +1,4 @@
1
- import type { AmountUnit } from '../../components/TokenSwapWidget/AmountUnitToggle/useAmountUnitToggle';
1
+ import { type AmountInUnits, type AmountUnit } from '../../components/TokenSwapWidget/AmountUnitToggle/useAmountUnitToggle';
2
2
  /**
3
3
  * A typed amount in source base units, or `undefined` when empty or unpriced.
4
4
  * - Token mode parses the typed digits, so nothing passes through a float.
@@ -22,3 +22,32 @@ export declare function formatConvertMaxInput({ baseUnits, decimals, unit, unitP
22
22
  unit: AmountUnit;
23
23
  unitPriceUsd: number | undefined;
24
24
  }): string;
25
+ /** The field text and converted amounts for an exact Max, at `unitPriceUsd`. */
26
+ export declare function getConvertMaxDisplay({ maxBaseUnits, decimals, unit, unitPriceUsd, }: {
27
+ maxBaseUnits: bigint;
28
+ decimals: number;
29
+ unit: AmountUnit;
30
+ unitPriceUsd: number | undefined;
31
+ }): AmountInUnits & {
32
+ inputValue: string;
33
+ };
34
+ export interface ConvertAmount extends AmountInUnits {
35
+ /** The field text; Max's rounded-down display while Max is on. */
36
+ inputValue: string;
37
+ unit: AmountUnit;
38
+ /** What to quote: Max's exact amount, or the typed one. */
39
+ baseUnits: bigint | undefined;
40
+ isMax: boolean;
41
+ }
42
+ /**
43
+ * The amount a draft describes at `unitPriceUsd`. While Max is on, the field
44
+ * and converted amounts derive from it, so a price change or unit flip never
45
+ * leaves them stale.
46
+ */
47
+ export declare function getConvertAmount({ inputValue, unit, maxBaseUnits, decimals, unitPriceUsd, }: {
48
+ inputValue: string;
49
+ unit: AmountUnit;
50
+ maxBaseUnits: bigint | undefined;
51
+ decimals: number;
52
+ unitPriceUsd: number | undefined;
53
+ }): ConvertAmount;
@@ -1,14 +1,12 @@
1
- import type { FeeBreakdownV2 } from '@funkit/api-base';
2
1
  import type { RelayQuote } from '@funkit/fun-relay';
2
+ import type { FunkitCheckoutQuoteResult } from '../../domains/quote';
3
3
  import type { ConvertResolvedAsset } from './types';
4
- /** One exact-in Convert quote, with what the screen reads from it. */
4
+ /** One exact-in Convert quote. */
5
5
  export interface ConvertQuote {
6
- /** The full response; execution reads `metadata.relayQuote` from it. */
6
+ /** The response, typed with its Relay metadata; execution reads it. */
7
7
  response: RelayQuote;
8
- /** Relay's expected output, in destination base units. */
9
- amountOutBaseUnits: string | undefined;
10
- /** Fee rows and the exchange rate. */
11
- feeBreakdown: FeeBreakdownV2;
8
+ /** The same response in checkout's quote shape, for the fee summary and the record. */
9
+ checkoutQuote: FunkitCheckoutQuoteResult;
12
10
  }
13
11
  interface ConvertQuoteRequest {
14
12
  apiKey: string;
@@ -19,6 +17,17 @@ interface ConvertQuoteRequest {
19
17
  userAddress: string;
20
18
  recipientAddress: string;
21
19
  }
22
- /** Requests an exact-in quote for a Convert pair. Returns the quote and the fee breakdown. */
20
+ /** Requests an exact-in quote for a Convert pair. */
23
21
  export declare function fetchConvertQuote({ apiKey, sourceAsset, destinationAsset, amountInBaseUnits, userAddress, recipientAddress, }: ConvertQuoteRequest): Promise<ConvertQuote>;
22
+ /**
23
+ * What the quote spends, in source base units: the amount Relay quoted and
24
+ * encoded in its steps, so it's what actually leaves the wallet.
25
+ */
26
+ export declare function getConvertAmountInBaseUnits(quote: ConvertQuote): string | undefined;
27
+ /**
28
+ * Relay's expected output, in destination base units. Not the backend's
29
+ * `toAmountBaseUnit`: it copies this value but turns a missing one into `'0'`,
30
+ * which would read as a real output.
31
+ */
32
+ export declare function getConvertAmountOutBaseUnits(quote: ConvertQuote): string | undefined;
24
33
  export {};
@@ -15,7 +15,8 @@ export declare function getDefaultConvertRecipient(vm: ConvertVm, recipientAddre
15
15
  * custom recipient if it returns one, else the VM default. The custom resolver
16
16
  * is not called for a chain Convert can't execute on.
17
17
  */
18
- export declare function selectConvertRecipient({ asset, recipientAddresses, }: {
18
+ export declare function selectConvertRecipient({ asset, recipientAddresses, timeoutMs, }: {
19
19
  asset: ConvertResolvedAsset;
20
20
  recipientAddresses: ConvertRecipientAddresses;
21
+ timeoutMs?: number;
21
22
  }): Promise<ConvertRecipientSelection>;
@@ -0,0 +1,112 @@
1
+ import { type AmountUnit } from '../../components/TokenSwapWidget/AmountUnitToggle/useAmountUnitToggle';
2
+ import type { ConvertQuote } from './quote';
3
+ import { type ConvertScreenIssue } from './screen';
4
+ import type { ConvertSubmittedTransaction } from './settlement';
5
+ import type { ConvertSourceWalletSelection } from './sourceWallet';
6
+ import type { ConvertSubmitPreparation } from './submit';
7
+ import type { ConvertResolvedAsset } from './types';
8
+ /** What the user is editing. Keys are {@link convertAssetKey}s. */
9
+ export interface ConvertDraft {
10
+ sourceKey: string | undefined;
11
+ destinationKey: string | undefined;
12
+ /** The field text as typed; stale while Max is on, which derives its own. */
13
+ inputValue: string;
14
+ unit: AmountUnit;
15
+ /** Max's exact amount; typing clears it. */
16
+ maxBaseUnits: bigint | undefined;
17
+ }
18
+ /** What the user converted, frozen when they did; a locked screen reads only this. */
19
+ export interface ConvertSnapshot {
20
+ sourceAsset: ConvertResolvedAsset;
21
+ destinationAsset: ConvertResolvedAsset;
22
+ amountBaseUnits: bigint;
23
+ quote: ConvertQuote;
24
+ sourceWallet: Extract<ConvertSourceWalletSelection, {
25
+ status: 'available';
26
+ }>;
27
+ recipientAddress: string;
28
+ /** The price the amount was shown at, so its USD value can't move mid-conversion. */
29
+ unitPriceUsd: number | undefined;
30
+ }
31
+ export type ConvertSubmission = {
32
+ snapshot: ConvertSnapshot;
33
+ } & ({
34
+ phase: 'converting' | 'completed' | 'untrackable';
35
+ }
36
+ /** Polling follows `transaction` until Relay fills or fails it. */
37
+ | {
38
+ phase: 'pending';
39
+ transaction: ConvertSubmittedTransaction;
40
+ } | {
41
+ phase: 'failed';
42
+ issue: ConvertScreenIssue;
43
+ });
44
+ export interface ConvertState {
45
+ draft: ConvertDraft;
46
+ submission: ConvertSubmission | undefined;
47
+ /** Counts deposits sent, so a quote whose Relay request went out is never signed again. */
48
+ sentCount: number;
49
+ }
50
+ export type ConvertEvent = {
51
+ type: 'AMOUNT_EDITED';
52
+ inputValue: string;
53
+ } | {
54
+ type: 'MAX_SET';
55
+ maxBaseUnits: bigint;
56
+ }
57
+ /** Converts the field at the live price; ignored without one. */
58
+ | {
59
+ type: 'UNIT_TOGGLED';
60
+ unitPriceUsd: number | undefined;
61
+ } | {
62
+ type: 'SOURCE_PICKED';
63
+ sourceKey: string;
64
+ } | {
65
+ type: 'DESTINATION_PICKED';
66
+ destinationKey: string;
67
+ } | {
68
+ type: 'DIRECTION_SWAPPED';
69
+ } | {
70
+ type: 'CONVERT_STARTED';
71
+ snapshot: ConvertSnapshot;
72
+ } | {
73
+ type: 'CHECK_FAILED';
74
+ preparation: Extract<ConvertSubmitPreparation, {
75
+ status: 'blocked';
76
+ }>;
77
+ }
78
+ /** The pre-sign check threw; nothing reached the wallet. */
79
+ | {
80
+ type: 'CHECK_FAILED';
81
+ error: unknown;
82
+ }
83
+ /** The wallet step failed with nothing sent. */
84
+ | {
85
+ type: 'SIGNING_FAILED';
86
+ error: unknown;
87
+ } | {
88
+ type: 'DEPOSIT_RECORDED';
89
+ transaction: ConvertSubmittedTransaction;
90
+ } | {
91
+ type: 'UNTRACKABLE';
92
+ } | {
93
+ type: 'COMPLETED';
94
+ } | {
95
+ type: 'FILL_FAILED';
96
+ } | {
97
+ type: 'RETRIED';
98
+ }
99
+ /** The success label has shown long enough; the screen opens for another conversion. */
100
+ | {
101
+ type: 'SUCCESS_SHOWN';
102
+ };
103
+ export declare const INITIAL_CONVERT_STATE: ConvertState;
104
+ /**
105
+ * Convert's draft and submission. Pure: the provider runs the wallet steps
106
+ * and polling, and dispatches what they report.
107
+ * - An edit, Max, pick or retry ends a `failed` submission; a locked one ignores them.
108
+ * - `CONVERT_STARTED` freezes the snapshot; nothing live reaches it after.
109
+ * - `untrackable` is final; `completed` ends with `SUCCESS_SHOWN`, which keeps
110
+ * the tokens and drops the amount, since it was converted.
111
+ */
112
+ export declare function convertReducer(state: ConvertState, event: ConvertEvent): ConvertState;
@@ -0,0 +1,169 @@
1
+ import type { TFunction } from 'i18next';
2
+ import type { ErrorNotification } from '../../components/FunNotification/FunNotification';
3
+ import type { ConvertSourceErrorReason } from './errors';
4
+ import { type ConvertQuote } from './quote';
5
+ import type { ConvertRecipientSelection } from './recipient';
6
+ import type { ConvertSubmission } from './reducer';
7
+ import type { ConvertSourceWalletSelection } from './sourceWallet';
8
+ import type { ConvertSubmitPreparation } from './submit';
9
+ /** What stops the user from converting the amount on screen. */
10
+ export type ConvertScreenIssue =
11
+ /** `isRetryable`: the host's resolver failed or timed out, so asking again may work. */
12
+ {
13
+ type: 'sourceWalletUnavailable';
14
+ isRetryable: boolean;
15
+ } | {
16
+ type: 'recipientUnavailable';
17
+ isRetryable: boolean;
18
+ }
19
+ /** A later balance read left the picked source out; reading again may fix it. */
20
+ | {
21
+ type: 'sourceBalanceUnavailable';
22
+ }
23
+ /** `maxBaseUnits` is `null` while Max is unknown, and `0n` with nothing to spend. */
24
+ | {
25
+ type: 'insufficientBalance';
26
+ maxBaseUnits: bigint | null;
27
+ } | {
28
+ type: 'belowMinimum';
29
+ } | {
30
+ type: 'quoteFailed';
31
+ error: Error | null;
32
+ }
33
+ /** The pre-sign balance read failed; submitting again reads it again. */
34
+ | {
35
+ type: 'balanceCheckFailed';
36
+ }
37
+ /** The pre-sign check threw before reaching the wallet; submitting again reruns it. */
38
+ | {
39
+ type: 'checkFailed';
40
+ }
41
+ /** The wallet step failed before any funds moved. */
42
+ | {
43
+ type: 'signingFailed';
44
+ reason: ConvertSourceErrorReason;
45
+ }
46
+ /** Relay's fill failed or was refunded. */
47
+ | {
48
+ type: 'fillFailed';
49
+ }
50
+ /** Funds may have moved but can't be tracked. Final. */
51
+ | {
52
+ type: 'untrackable';
53
+ };
54
+ /**
55
+ * Where a submission stands, named by what the money is doing:
56
+ * - `converting`: the pre-sign check, signing and recording; nothing sent yet,
57
+ * or sent and not yet recorded.
58
+ * - `pending`: on-chain and recorded; Relay is filling it.
59
+ * - `completed`: delivered; the modal closes.
60
+ * - `untrackable` is final: funds may have moved, so Convert stays locked.
61
+ * - `failed`: nothing is in flight; `issue` says whether anything moved.
62
+ */
63
+ export type ConvertPhase = 'converting' | 'pending' | 'completed' | 'untrackable' | 'failed';
64
+ /**
65
+ * What a blocked pre-sign check tells the user, if anything. `undefined` ends
66
+ * the submission with nothing to show beyond the live checks.
67
+ */
68
+ export declare function getConvertPreSignIssue(preparation: Extract<ConvertSubmitPreparation, {
69
+ status: 'blocked';
70
+ }>): ConvertScreenIssue | undefined;
71
+ /** Convert is locked from the submission until it settles, and for good once `untrackable`. */
72
+ export declare function isConvertSubmissionLocked(submission: ConvertSubmission | undefined): boolean;
73
+ /**
74
+ * What the banner and the main button each show. A locked submission hides the
75
+ * rest, since the balance drops as the deposit lands. Otherwise:
76
+ * - The button acts on a live problem (amount, then quote) before the submission,
77
+ * so a failed quote still offers a retry and a lowered balance offers Max.
78
+ * - The banner does the same, except a failed fill stays on top: money moved,
79
+ * so the user has to learn about it before anything newer.
80
+ */
81
+ export declare function getConvertScreenIssues({ submission, amountIssue, quoteIssue, }: {
82
+ submission: ConvertSubmission | undefined;
83
+ amountIssue: ConvertScreenIssue | undefined;
84
+ quoteIssue: ConvertScreenIssue | undefined;
85
+ }): {
86
+ bannerIssue: ConvertScreenIssue | undefined;
87
+ buttonIssue: ConvertScreenIssue | undefined;
88
+ };
89
+ /**
90
+ * Problems found before quoting; a quote is only requested without one.
91
+ * - Above the balance follows checkout: never clamp, offer Max instead.
92
+ * - Under $1 never quotes: Relay won't, and its error reads worse.
93
+ */
94
+ export declare function getConvertAmountIssue({ sourceWallet, recipient, isSourceBalanceUnavailable, amountInBaseUnits, amountUsd, balanceBaseUnits, maxBaseUnits, }: {
95
+ sourceWallet: ConvertSourceWalletSelection | undefined;
96
+ recipient: ConvertRecipientSelection | undefined;
97
+ /** Without a balance there's no price, so neither the $1 nor the balance check can run. */
98
+ isSourceBalanceUnavailable: boolean;
99
+ amountInBaseUnits: bigint | undefined;
100
+ /** `undefined` while the price is unknown. */
101
+ amountUsd: number | undefined;
102
+ /** `undefined` while the balance is unknown. */
103
+ balanceBaseUnits: string | undefined;
104
+ maxBaseUnits: bigint | null;
105
+ }): ConvertScreenIssue | undefined;
106
+ /** A failed quote, or one that doesn't say what the user receives. */
107
+ export declare function getConvertQuoteIssue({ quote, isError, error, }: {
108
+ quote: ConvertQuote | undefined;
109
+ isError: boolean;
110
+ error: Error | null;
111
+ }): ConvertScreenIssue | undefined;
112
+ /** The bottom-bar notification, worded like checkout's and withdrawal's. */
113
+ export declare function getConvertNotification({ issue, sourceSymbol, destinationSymbol, t, }: {
114
+ issue: ConvertScreenIssue | undefined;
115
+ sourceSymbol: string | undefined;
116
+ destinationSymbol: string | undefined;
117
+ t: TFunction;
118
+ }): ErrorNotification | undefined;
119
+ export type ConvertActionButton =
120
+ /** From the submission until Relay settles. */
121
+ {
122
+ action: 'converting';
123
+ }
124
+ /** Shown briefly before the modal closes. */
125
+ | {
126
+ action: 'converted';
127
+ }
128
+ /** A native EVM source's gas price is loading, so Max and the reserve are unknown. */
129
+ | {
130
+ action: 'estimatingGas';
131
+ } | {
132
+ action: 'max';
133
+ maxBaseUnits: bigint;
134
+ }
135
+ /** After a failed quote or host lookup; `isRetrying` while the retry runs. */
136
+ | {
137
+ action: 'retry';
138
+ isRetrying: boolean;
139
+ }
140
+ /** `isRefreshing`: a new quote is replacing the shown one, so it can't be signed. */
141
+ | {
142
+ action: 'convert';
143
+ isEnabled: boolean;
144
+ isRefreshing: boolean;
145
+ };
146
+ /**
147
+ * Like checkout's "Deposit max balance": above the balance, the main button
148
+ * fills in Max. After a failed quote or host lookup it retries, since neither
149
+ * tries again on its own. Otherwise it converts, once a quote says what
150
+ * arrives, and waits out a refresh like checkout's confirmation screen. A
151
+ * submission in flight overrides all of it.
152
+ */
153
+ export declare function getConvertActionButton({ submission, issue, quote, isQuoteFetching, isLookupFetching, isFeeReserveLoading, }: {
154
+ submission: ConvertSubmission | undefined;
155
+ issue: ConvertScreenIssue | undefined;
156
+ quote: ConvertQuote | undefined;
157
+ isQuoteFetching: boolean;
158
+ /** A source wallet, recipient or balance read is running. */
159
+ isLookupFetching: boolean;
160
+ /** Like the quote, the pre-sign check waits on it. */
161
+ isFeeReserveLoading: boolean;
162
+ }): ConvertActionButton;
163
+ /** The To card's amounts; `undefined` until a quote says what arrives. */
164
+ export declare function getConvertReceiveAmounts(quote: ConvertQuote | undefined, decimals: number | undefined): {
165
+ tokenAmount: number | undefined;
166
+ usdAmount: number | undefined;
167
+ };
168
+ /** Whole seconds until the quote refreshes, seeded like `LightningInvoice`. */
169
+ export declare function getConvertCountdownSeconds(refreshesAtMs: number, nowMs: number): number;
@@ -1,6 +1,6 @@
1
1
  import { type DirectExecution } from '@funkit/api-base';
2
2
  import type { ConvertSubmissionIds } from './execution';
3
- import type { ConvertQuote } from './quote';
3
+ import { type ConvertQuote } from './quote';
4
4
  import type { ConvertResolvedAsset, ConvertSuccessResult, ConvertVm } from './types';
5
5
  /**
6
6
  * Tags the record as a conversion. Nothing on the backend parses this; the
@@ -18,6 +18,11 @@ export interface ConvertExecutionContext {
18
18
  destinationAsset: ConvertResolvedAsset;
19
19
  recipientAddress: string;
20
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
+ }
21
26
  /**
22
27
  * Registers the deposit as a direct execution so the backend tracks its
23
28
  * settlement with Relay, the same as a checkout or withdrawal. Returns the
@@ -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>;
@@ -1,17 +1,19 @@
1
- import type { ConvertQuote } from './quote';
1
+ import type { Dnum } from 'dnum';
2
+ import { type ConvertBalances } from './balances';
3
+ import { type ConvertQuote } from './quote';
2
4
  import type { ConvertResolvedAsset } from './types';
3
5
  /** Why a submit stopped before signing. Nothing was sent. */
4
6
  export type ConvertSubmitBlockReason =
5
- /** No quote on screen to confirm. */
6
- 'noQuote'
7
7
  /** The fresh balance read failed or left this asset out. */
8
- | 'balanceUnavailable'
8
+ 'balanceUnavailable'
9
9
  /** A native EVM source's gas price hasn't loaded, so Max is unknown. */
10
10
  | 'feeReserveLoading'
11
11
  /** The amount is above the fresh balance less its fee reserve. */
12
12
  | 'insufficientBalance'
13
13
  /** The quote doesn't say what the user receives. */
14
14
  | 'quoteMissingReceiveAmount'
15
+ /** The quote doesn't spend the amount on screen, or doesn't say what it spends. */
16
+ | 'quoteAmountMismatch'
15
17
  /** The quote prices the source in different decimals than the SDK resolved. */
16
18
  | 'decimalsMismatch';
17
19
  /**
@@ -44,3 +46,22 @@ export declare function hasQuoteDecimalsMismatch({ quote, sourceAsset, }: {
44
46
  quote: ConvertQuote;
45
47
  sourceAsset: ConvertResolvedAsset;
46
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>;