@b3dotfun/sdk 0.0.65-alpha.1 → 0.0.65-alpha.3
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/dist/cjs/anyspend/react/components/AnySpend.js +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +38 -7
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -251
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/index.js +4 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +1 -1
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/dist/esm/anyspend/react/components/AnySpend.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +38 -7
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -249
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/esm/anyspend/react/components/index.d.ts +1 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +1 -1
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/types/anyspend/react/components/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +1 -1
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +47 -7
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +36 -526
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +2 -13
- package/src/anyspend/react/components/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +1 -1
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +6 -12
|
@@ -3,6 +3,7 @@ import { GetQuoteResponse } from "@b3dotfun/sdk/anyspend/types/api_req_res";
|
|
|
3
3
|
import { normalizeAddress } from "@b3dotfun/sdk/anyspend/utils";
|
|
4
4
|
import { Button, ShinyButton, StyleRoot, TransitionPanel, useAccountWallet } from "@b3dotfun/sdk/global-account/react";
|
|
5
5
|
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
6
|
+
import { formatUnits } from "@b3dotfun/sdk/shared/utils/number";
|
|
6
7
|
import invariant from "invariant";
|
|
7
8
|
import { ArrowDown, Loader2 } from "lucide-react";
|
|
8
9
|
import { motion } from "motion/react";
|
|
@@ -46,7 +47,9 @@ export interface AnySpendCustomExactInProps {
|
|
|
46
47
|
onTokenSelect?: (token: components["schemas"]["Token"], event: { preventDefault: () => void }) => void;
|
|
47
48
|
customUsdInputValues?: string[];
|
|
48
49
|
preferEoa?: boolean;
|
|
49
|
-
customExactInConfig
|
|
50
|
+
customExactInConfig?: CustomExactInConfig;
|
|
51
|
+
orderType?: "hype_duel" | "custom_exact_in";
|
|
52
|
+
minDestinationAmount?: number;
|
|
50
53
|
header?: ({
|
|
51
54
|
anyspendPrice,
|
|
52
55
|
isLoadingAnyspendPrice,
|
|
@@ -81,9 +84,11 @@ function AnySpendCustomExactInInner({
|
|
|
81
84
|
customUsdInputValues,
|
|
82
85
|
preferEoa,
|
|
83
86
|
customExactInConfig,
|
|
87
|
+
orderType = "custom_exact_in",
|
|
88
|
+
minDestinationAmount,
|
|
84
89
|
header,
|
|
85
90
|
}: AnySpendCustomExactInProps) {
|
|
86
|
-
const actionLabel = customExactInConfig
|
|
91
|
+
const actionLabel = customExactInConfig?.action ?? "Custom Execution";
|
|
87
92
|
|
|
88
93
|
const DESTINATION_TOKEN_DETAILS = {
|
|
89
94
|
SYMBOL: destinationToken.symbol ?? "TOKEN",
|
|
@@ -140,7 +145,7 @@ function AnySpendCustomExactInInner({
|
|
|
140
145
|
destinationTokenChainId: destinationChainId,
|
|
141
146
|
slippage: SLIPPAGE_PERCENT,
|
|
142
147
|
disableUrlParamManagement: true,
|
|
143
|
-
orderType
|
|
148
|
+
orderType,
|
|
144
149
|
});
|
|
145
150
|
|
|
146
151
|
const { connectedEOAWallet } = useAccountWallet();
|
|
@@ -161,6 +166,14 @@ function AnySpendCustomExactInInner({
|
|
|
161
166
|
const expectedDstAmountRaw = anyspendQuote?.data?.currencyOut?.amount ?? "0";
|
|
162
167
|
|
|
163
168
|
const buildCustomPayload = (_recipient: string | undefined) => {
|
|
169
|
+
if (!customExactInConfig) {
|
|
170
|
+
// For hype_duel or other simple order types
|
|
171
|
+
return {
|
|
172
|
+
expectedDstAmount: expectedDstAmountRaw,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// For custom_exact_in with custom config
|
|
164
177
|
return {
|
|
165
178
|
amount: expectedDstAmountRaw,
|
|
166
179
|
expectedDstAmount: expectedDstAmountRaw,
|
|
@@ -184,6 +197,28 @@ function AnySpendCustomExactInInner({
|
|
|
184
197
|
if (!anyspendQuote || !anyspendQuote.success)
|
|
185
198
|
return { text: "Get quote error", disable: true, error: true, loading: false };
|
|
186
199
|
|
|
200
|
+
// Check minimum destination amount if specified
|
|
201
|
+
// Check minimum destination amount if specified
|
|
202
|
+
if (
|
|
203
|
+
minDestinationAmount &&
|
|
204
|
+
anyspendQuote.data?.currencyOut?.amount &&
|
|
205
|
+
anyspendQuote.data.currencyOut.currency &&
|
|
206
|
+
anyspendQuote.data.currencyOut.currency.decimals != null
|
|
207
|
+
) {
|
|
208
|
+
const rawAmountInWei = BigInt(anyspendQuote.data.currencyOut.amount);
|
|
209
|
+
const decimals = anyspendQuote.data.currencyOut.currency.decimals;
|
|
210
|
+
const actualAmount = parseFloat(formatUnits(rawAmountInWei.toString(), decimals));
|
|
211
|
+
|
|
212
|
+
if (actualAmount < minDestinationAmount) {
|
|
213
|
+
return {
|
|
214
|
+
text: `Minimum ${minDestinationAmount} ${DESTINATION_TOKEN_DETAILS.SYMBOL} deposit`,
|
|
215
|
+
disable: true,
|
|
216
|
+
error: true,
|
|
217
|
+
loading: false,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
187
222
|
if (paymentType === "crypto") {
|
|
188
223
|
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
189
224
|
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
@@ -195,7 +230,9 @@ function AnySpendCustomExactInInner({
|
|
|
195
230
|
) {
|
|
196
231
|
return { text: "Insufficient balance", disable: true, error: true, loading: false };
|
|
197
232
|
}
|
|
198
|
-
|
|
233
|
+
// Use different text based on order type
|
|
234
|
+
const buttonText = orderType === "hype_duel" ? "Continue to deposit" : `Execute ${actionLabel}`;
|
|
235
|
+
return { text: buttonText, disable: false, error: false, loading: false };
|
|
199
236
|
}
|
|
200
237
|
|
|
201
238
|
if (paymentType === "fiat") {
|
|
@@ -219,6 +256,9 @@ function AnySpendCustomExactInInner({
|
|
|
219
256
|
hasEnoughBalance,
|
|
220
257
|
isBalanceLoading,
|
|
221
258
|
actionLabel,
|
|
259
|
+
minDestinationAmount,
|
|
260
|
+
DESTINATION_TOKEN_DETAILS.SYMBOL,
|
|
261
|
+
orderType,
|
|
222
262
|
]);
|
|
223
263
|
|
|
224
264
|
const onMainButtonClick = async () => {
|
|
@@ -230,7 +270,7 @@ function AnySpendCustomExactInInner({
|
|
|
230
270
|
}
|
|
231
271
|
|
|
232
272
|
if (paymentType === "crypto") {
|
|
233
|
-
if (
|
|
273
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
234
274
|
setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
|
|
235
275
|
return;
|
|
236
276
|
}
|
|
@@ -384,7 +424,7 @@ function AnySpendCustomExactInInner({
|
|
|
384
424
|
|
|
385
425
|
createOrder({
|
|
386
426
|
recipientAddress: selectedRecipientOrDefault,
|
|
387
|
-
orderType
|
|
427
|
+
orderType,
|
|
388
428
|
srcChain: selectedSrcChainId,
|
|
389
429
|
dstChain: selectedDstChainId,
|
|
390
430
|
srcToken: selectedSrcToken,
|
|
@@ -435,7 +475,7 @@ function AnySpendCustomExactInInner({
|
|
|
435
475
|
|
|
436
476
|
createOnrampOrder({
|
|
437
477
|
recipientAddress: selectedRecipientOrDefault,
|
|
438
|
-
orderType
|
|
478
|
+
orderType,
|
|
439
479
|
dstChain: selectedDstChainId,
|
|
440
480
|
dstToken: selectedDstToken,
|
|
441
481
|
srcFiatAmount: srcAmount,
|