@funkit/connect 9.4.3 → 9.5.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.
- package/CHANGELOG.md +15 -0
- package/dist/domains/quoteMode/exactIn.d.ts +2 -0
- package/dist/domains/quoteMode/exactOut.d.ts +2 -0
- package/dist/domains/quoteMode/gasEstimate.d.ts +15 -0
- package/dist/domains/quoteMode/index.d.ts +9 -0
- package/dist/domains/quoteMode/oneToOne.d.ts +21 -0
- package/dist/domains/quoteMode/resolveQuoteMode.d.ts +19 -0
- package/dist/domains/quoteMode/types.d.ts +125 -0
- package/dist/hooks/queries/useFops.d.ts +1 -0
- package/dist/hooks/queries/useWithdrawFops.d.ts +9 -0
- package/dist/hooks/track/WithdrawModalEvent.d.ts +3 -0
- package/dist/hooks/useCheckoutTransferInit.d.ts +1 -0
- package/dist/index.css +205 -205
- package/dist/index.js +2742 -2532
- package/dist/modals/WithdrawalModal/WithdrawalMethodSelect.d.ts +8 -0
- package/dist/modals/WithdrawalModal/types.d.ts +1 -0
- package/dist/utils/tokenMath.d.ts +38 -0
- package/dist/wallets/walletConnectors/index.js +37 -37
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @funkit/connect
|
|
2
2
|
|
|
3
|
+
## 9.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fec5e96: Add QuoteMode types (EXACT_IN, EXACT_OUT, ONE_TO_ONE), QuoteBuilder strategy pattern, dnum-based token math utilities, and quote mode resolution logic
|
|
8
|
+
- 3b3eeba: Add swapped withdrawal method selection screen behind enableswappedwithdrawal flag
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 9993a99: fix(connect): use modal=false to prevent multiple dropdowns staying open on client sites that override body scroll locking
|
|
13
|
+
- 0de9370: fix(connect): swapped loading state
|
|
14
|
+
- Updated dependencies [fec5e96]
|
|
15
|
+
- @funkit/utils@1.2.7
|
|
16
|
+
- @funkit/api-base@3.0.5
|
|
17
|
+
|
|
3
18
|
## 9.4.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Dnum } from 'dnum';
|
|
2
|
+
/**
|
|
3
|
+
* Hardcoded gas-unit estimate for a checkout transaction involving a
|
|
4
|
+
* native token. Checkout relay/swap transactions typically consume
|
|
5
|
+
* 300k–500k gas; we use 1M as a conservative baseline. The builder
|
|
6
|
+
* applies an additional 1.5x multiplier on top, giving ~1.5M effective.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CHECKOUT_GAS_UNITS = 1000000n;
|
|
9
|
+
/**
|
|
10
|
+
* Compute a gas cost estimate in wei as an 18-decimal Dnum.
|
|
11
|
+
*
|
|
12
|
+
* @param gasPriceWei - Current gas price in wei (e.g. from `getGasPrice`)
|
|
13
|
+
* @returns Gas estimate as a Dnum: [gasUnits * gasPriceWei, 18]
|
|
14
|
+
*/
|
|
15
|
+
export declare function getGasEstimateWei(gasPriceWei: bigint): Dnum;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { QuickOptionType, QuoteBuildType, QuoteMode, RetryActionType, RetryErrorReason, } from './types';
|
|
2
|
+
export type { QuoteBuilder, QuoteBuildResult, QuoteRetryError, RetryAction, QuoteDisplayAmounts, MaxSendableParams, } from './types';
|
|
3
|
+
export type { Dnum } from 'dnum';
|
|
4
|
+
export { createExactOutBuilder } from './exactOut';
|
|
5
|
+
export { createExactInBuilder } from './exactIn';
|
|
6
|
+
export { createOneToOneBuilder } from './oneToOne';
|
|
7
|
+
export { createQuoteBuilder, _resolveQuoteMode } from './resolveQuoteMode';
|
|
8
|
+
export type { CreateQuoteBuilderParams } from './resolveQuoteMode';
|
|
9
|
+
export { getGasEstimateWei, CHECKOUT_GAS_UNITS } from './gasEstimate';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type QuoteBuilder } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @TODO: Wire it up to UI components, currently it is not used.
|
|
4
|
+
* More about the purpose of this quote mode: https://www.notion.so/the-fun-group/Refactoring-Quote-Mode-Selection-Max-Button-Behavior-327fc3b2a00281eea8f0eb0a28a08045#8d7655b63b9c416a91021718702ffe8f
|
|
5
|
+
*
|
|
6
|
+
* ONE_TO_ONE is EXACT_IN with subsidized fees — the user sends X tokens and
|
|
7
|
+
* receives exactly X tokens on the destination chain. All bridge/relay fees
|
|
8
|
+
* are absorbed by the protocol, so send === receive and feesUsd === '0'.
|
|
9
|
+
*
|
|
10
|
+
* Mechanically it inherits all EXACT_IN behavior (max sendable calculation,
|
|
11
|
+
* quote request building, retry logic, quick options) and only overrides
|
|
12
|
+
* `getDisplayAmounts` to reflect the 1:1 guarantee.
|
|
13
|
+
*
|
|
14
|
+
* @TODO: Revisit whether ONE_TO_ONE should remain a separate builder or be
|
|
15
|
+
* collapsed into EXACT_IN with overrides. Jeremy suspects it may just be
|
|
16
|
+
* EXACT_IN with some config flags. Discuss with Connor before removing since
|
|
17
|
+
* it's in the approved design doc.
|
|
18
|
+
* See: https://fun-xyz.slack.com/archives/C0AN3BXPBNK/p1775167066455859
|
|
19
|
+
* Tracked: https://linear.app/funxyz/issue/ENG-3282/revisit-one-to-one-quote-mode-consider-collapsing-into-exact-in
|
|
20
|
+
*/
|
|
21
|
+
export declare function createOneToOneBuilder(): QuoteBuilder;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type QuoteBuilder } from './types';
|
|
2
|
+
export interface CreateQuoteBuilderParams {
|
|
3
|
+
hasPostAction: boolean;
|
|
4
|
+
isExactInEnabled: boolean;
|
|
5
|
+
providerSupportsExactInWithActions?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Determines the quote mode and returns the corresponding builder.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order:
|
|
11
|
+
* 1. Feature gate off → EXACT_OUT (Stage 1 default)
|
|
12
|
+
* 2. No action params → EXACT_IN
|
|
13
|
+
* 3. Action params + provider supports → EXACT_IN
|
|
14
|
+
* 4. Action params + no support → EXACT_OUT
|
|
15
|
+
*
|
|
16
|
+
* Note: ONE_TO_ONE (subsidized routes) is not yet auto-detected.
|
|
17
|
+
* It will be enabled in a future phase when subsidy detection is implemented.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createQuoteBuilder({ hasPostAction, isExactInEnabled, providerSupportsExactInWithActions, }: CreateQuoteBuilderParams): QuoteBuilder;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Dnum } from 'dnum';
|
|
2
|
+
import type { PaymentMethod } from '../../domains/paymentMethods';
|
|
3
|
+
import type { FunkitCheckoutQuoteResult } from '../../domains/quote';
|
|
4
|
+
export declare enum QuoteMode {
|
|
5
|
+
EXACT_IN = "EXACT_IN",
|
|
6
|
+
EXACT_OUT = "EXACT_OUT",
|
|
7
|
+
ONE_TO_ONE = "ONE_TO_ONE"
|
|
8
|
+
}
|
|
9
|
+
export declare enum QuoteBuildType {
|
|
10
|
+
EXACT_IN = "exactIn",
|
|
11
|
+
EXACT_OUT = "exactOut"
|
|
12
|
+
}
|
|
13
|
+
export declare enum RetryActionType {
|
|
14
|
+
CALIBRATE_AMOUNT = "calibrateAmount",
|
|
15
|
+
REFETCH_BALANCE = "refetchBalance",
|
|
16
|
+
GIVE_UP = "giveUp"
|
|
17
|
+
}
|
|
18
|
+
export declare enum RetryErrorReason {
|
|
19
|
+
INSUFFICIENT_BALANCE = "insufficientBalance",
|
|
20
|
+
INSUFFICIENT_AMOUNT = "insufficientAmount",
|
|
21
|
+
INTERNAL = "internal"
|
|
22
|
+
}
|
|
23
|
+
export declare enum QuickOptionType {
|
|
24
|
+
SET_TOKEN_AMOUNT = "setTokenAmount",
|
|
25
|
+
SET_FIAT_AMOUNT = "setFiatAmount"
|
|
26
|
+
}
|
|
27
|
+
export interface QuoteRetryError {
|
|
28
|
+
reason: RetryErrorReason;
|
|
29
|
+
maxTargetAssetAmount?: Dnum;
|
|
30
|
+
minTargetAssetAmount?: Dnum;
|
|
31
|
+
}
|
|
32
|
+
export type QuoteBuildResult = {
|
|
33
|
+
type: QuoteBuildType.EXACT_IN;
|
|
34
|
+
fromAmountBaseUnit: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: QuoteBuildType.EXACT_OUT;
|
|
37
|
+
toAmountBaseUnit: string;
|
|
38
|
+
};
|
|
39
|
+
export type RetryAction = {
|
|
40
|
+
type: RetryActionType.CALIBRATE_AMOUNT;
|
|
41
|
+
newAmountBaseUnit: Dnum;
|
|
42
|
+
} | {
|
|
43
|
+
type: RetryActionType.REFETCH_BALANCE;
|
|
44
|
+
} | {
|
|
45
|
+
type: RetryActionType.GIVE_UP;
|
|
46
|
+
};
|
|
47
|
+
export interface QuoteDisplayAmounts {
|
|
48
|
+
/** The primary dollar/token amount shown at the top of the confirmation screen */
|
|
49
|
+
confirmationScreenDisplayAmount: string;
|
|
50
|
+
/** "You send" line */
|
|
51
|
+
sendAmount: string;
|
|
52
|
+
/** "You receive" line */
|
|
53
|
+
receiveAmount: string;
|
|
54
|
+
/** Whether the send amount is exact (vs estimated) */
|
|
55
|
+
isSendExact: boolean;
|
|
56
|
+
/** Whether the receive amount is exact (vs estimated) */
|
|
57
|
+
isReceiveExact: boolean;
|
|
58
|
+
/** Total fees in USD. '0' for ONE_TO_ONE */
|
|
59
|
+
feesUsd: string;
|
|
60
|
+
}
|
|
61
|
+
export interface MaxSendableParams {
|
|
62
|
+
/** Token balance as a Dnum */
|
|
63
|
+
tokenBalanceBaseUnit: Dnum;
|
|
64
|
+
/** Whether the token is the chain's native token (ETH, MATIC, etc.) */
|
|
65
|
+
isNativeToken: boolean;
|
|
66
|
+
/** Estimated gas price in wei (required for native tokens) */
|
|
67
|
+
gasEstimateWei?: Dnum;
|
|
68
|
+
/** Token price in USD (used for fee estimation in token terms) */
|
|
69
|
+
unitPrice: number;
|
|
70
|
+
/** Checkout target chain ID */
|
|
71
|
+
targetChainId: string;
|
|
72
|
+
/** Source asset chain ID */
|
|
73
|
+
assetChainId: string;
|
|
74
|
+
/** Payment method */
|
|
75
|
+
paymentMethod: PaymentMethod | undefined;
|
|
76
|
+
}
|
|
77
|
+
export interface UsdAvailableAmountParams {
|
|
78
|
+
/** Source asset USD value */
|
|
79
|
+
assetUsdAmount: number | null | undefined;
|
|
80
|
+
/** Checkout target chain ID */
|
|
81
|
+
targetChainId: string;
|
|
82
|
+
/** Source asset chain ID */
|
|
83
|
+
assetChainId: string | undefined;
|
|
84
|
+
/** Payment method */
|
|
85
|
+
paymentMethod: PaymentMethod | undefined;
|
|
86
|
+
}
|
|
87
|
+
export interface QuoteBuilder {
|
|
88
|
+
readonly mode: QuoteMode;
|
|
89
|
+
/** Compute the USD available amount for the source asset, accounting for fees where applicable */
|
|
90
|
+
getUsdAvailableAmount(params: UsdAvailableAmountParams): number | null;
|
|
91
|
+
/** Compute max sendable token amount for the max button */
|
|
92
|
+
getMaxSendableAmount(params: MaxSendableParams): Dnum;
|
|
93
|
+
/** Build the quote request params from the user's input */
|
|
94
|
+
buildQuoteRequest(params: {
|
|
95
|
+
tokenAmountBaseUnit: Dnum;
|
|
96
|
+
}): QuoteBuildResult;
|
|
97
|
+
/** Handle quote failure. Returns action to take. */
|
|
98
|
+
handleRetry(params: {
|
|
99
|
+
error: QuoteRetryError;
|
|
100
|
+
}): RetryAction;
|
|
101
|
+
/** Derive display amounts for confirmation screen.
|
|
102
|
+
* @param inputAmount — the user's input in human-readable form (e.g., 15.9) */
|
|
103
|
+
getDisplayAmounts(quote: FunkitCheckoutQuoteResult, inputAmount: number): QuoteDisplayAmounts;
|
|
104
|
+
/** Whether the confirmation screen can show a dollar amount before the quote resolves */
|
|
105
|
+
hasKnownAmountBeforeQuote(config: {
|
|
106
|
+
targetAssetAmount?: number;
|
|
107
|
+
targetAssetTicker: string;
|
|
108
|
+
finalizedToken?: unknown;
|
|
109
|
+
}): boolean;
|
|
110
|
+
/** Compute the token/fiat amount for a quick-option percentage button.
|
|
111
|
+
* Returns the action to dispatch to the state reducer. */
|
|
112
|
+
computeQuickOptionAmount(params: {
|
|
113
|
+
percentage: number;
|
|
114
|
+
tokenBalanceBaseUnit: Dnum | null;
|
|
115
|
+
frozenUnitPrice: number | null;
|
|
116
|
+
usdAvailableAmount: number | null;
|
|
117
|
+
}): {
|
|
118
|
+
type: QuickOptionType.SET_TOKEN_AMOUNT;
|
|
119
|
+
tokenAmountBaseUnit: Dnum;
|
|
120
|
+
frozenUnitPrice: number;
|
|
121
|
+
} | {
|
|
122
|
+
type: QuickOptionType.SET_FIAT_AMOUNT;
|
|
123
|
+
fiatAmount: number;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type GetFopsResponse } from '@funkit/api-base';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to fetch available withdrawal forms of payment.
|
|
4
|
+
* MVP: Returns static mock data. Will be replaced with a real API call later.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useWithdrawFops: () => {
|
|
7
|
+
data: GetFopsResponse;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
};
|
|
@@ -2,6 +2,9 @@ export declare enum WithdrawModalEvent {
|
|
|
2
2
|
MODAL_OPENED = "fw::modal_opened",
|
|
3
3
|
MODAL_READY = "fw::modal_ready",
|
|
4
4
|
MODAL_CLOSED = "fw::modal_closed",
|
|
5
|
+
ENTER_AMOUNT_VIEWED = "fw::enter_amount_viewed",
|
|
6
|
+
CRYPTO_ADDRESS_SELECTED = "fw::crypto_address_selected",
|
|
7
|
+
CASH_FOP_SELECTED = "fw::cash_fop_selected",
|
|
5
8
|
FINAL_QUOTE = "fw::quote::final_quote",
|
|
6
9
|
VIEW_TRANSACTION_BREAKDOWN = "fw::quote::view_transaction_breakdown",
|
|
7
10
|
PENDING_CALLBACK = "fw::pending_callback",
|
|
@@ -5,6 +5,7 @@ interface UseCheckoutTransferInitResponse {
|
|
|
5
5
|
transferInit: CheckoutInitTokenTransferResponse | undefined;
|
|
6
6
|
recipientAddr: FunAddress;
|
|
7
7
|
isLoading: boolean;
|
|
8
|
+
isFetching: boolean;
|
|
8
9
|
}
|
|
9
10
|
type CheckoutTokenTransferParams = Omit<CheckoutInitTokenTransferAddressParams, 'logger' | 'clientMetadata'>;
|
|
10
11
|
export declare function checkoutTransferFetch(params: CheckoutTokenTransferParams): Promise<CheckoutInitTokenTransferResponse>;
|