@ensofinance/checkout-widget 0.1.3 → 0.1.5

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/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { CheckoutConfig } from '../../../../../../../src/types';
2
- import { CheckoutModalProps } from '../../../../../../../src/types';
3
1
  import { ComponentType } from 'react';
4
2
  import { JSX as JSX_2 } from 'react/jsx-runtime';
5
3
  import { SystemConfig as WidgetTheme } from '@chakra-ui/react';
@@ -10,14 +8,33 @@ export declare const Checkout: ({ config: { apiKey, tokenOut, chainIdOut, theme,
10
8
  onClose?: () => void;
11
9
  }) => JSX_2.Element;
12
10
 
13
- export { CheckoutConfig }
11
+ export declare type CheckoutConfig = {
12
+ tokenOut: string;
13
+ chainIdOut: number;
14
+ apiKey: string;
15
+ theme?: WidgetTheme;
16
+ enableExchange?: SupportedExchanges[];
17
+ /** Override the default CEX bridge chain mapping (maps target chains to intermediate chains for withdrawal + bridge) */
18
+ cexBridgeChainMapping?: Record<number, number>;
19
+ /** Override recipient address (defaults to connected wallet's smart account) */
20
+ recipient?: string;
21
+ /** Force the widget to open in a specific flow, bypassing the selector */
22
+ enforceFlow?: EnforceFlow;
23
+ };
14
24
 
15
25
  export declare const CheckoutModal: ({ config, setIsActive, isActive, onClose, }: CheckoutModalProps) => JSX_2.Element;
16
26
 
17
- export { CheckoutModalProps }
27
+ export declare type CheckoutModalProps = {
28
+ config: CheckoutConfig;
29
+ isActive: boolean;
30
+ setIsActive: (active: boolean) => void;
31
+ onClose?: () => void;
32
+ };
18
33
 
19
34
  export declare const DEFAULT_CEX_BRIDGE_CHAIN_MAPPING: Record<number, number>;
20
35
 
36
+ declare type EnforceFlow = "exchange" | "wallet";
37
+
21
38
  export declare enum SupportedExchanges {
22
39
  Binance = "binance",
23
40
  Kraken = "kraken",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ensofinance/checkout-widget",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "homepage": "https://www.enso.build/",
6
6
  "repository": {
@@ -60,7 +60,6 @@
60
60
  "globals": "^15.14.0",
61
61
  "orval": "^7.10.0",
62
62
  "prettier": "^3.4.2",
63
- "source-map-explorer": "^2.5.3",
64
63
  "typescript": "~5.8.2",
65
64
  "typescript-eslint": "^8.18.2",
66
65
  "vite": "^6.0.5",
@@ -8,7 +8,7 @@ import {
8
8
  type CheckoutConfig,
9
9
  type SupportedExchanges,
10
10
  type EnforceFlow,
11
- } from "@/types";
11
+ } from "../types";
12
12
  import posthog from "posthog-js";
13
13
 
14
14
  type ICheckoutContext = {
@@ -1,7 +1,7 @@
1
1
  import { useCallback } from "react";
2
2
  import { Checkout } from "./Checkout";
3
3
  import Modal from "./modal";
4
- import { type CheckoutModalProps } from "@/types";
4
+ import { type CheckoutModalProps } from "../types";
5
5
 
6
6
  export const CheckoutModal = ({
7
7
  config,
@@ -37,7 +37,11 @@ import {
37
37
  formatUSD,
38
38
  normalizeValue,
39
39
  } from "@/util";
40
- import { useTokenFromListBySymbols, precisionizeNumber } from "@/util/common";
40
+ import {
41
+ useTokenFromListBySymbols,
42
+ precisionizeNumber,
43
+ getPositiveDecimalValue,
44
+ } from "@/util/common";
41
45
  import {
42
46
  EXCHANGE_MAX_LIMIT_GAP_USD,
43
47
  EXCHANGE_MIN_LIMIT,
@@ -56,7 +60,7 @@ import { ConfirmExchangeStep } from "../ExchangeConfirmSecurity";
56
60
 
57
61
  import SuccessIcon from "@/assets/success.svg";
58
62
  import FailIcon from "@/assets/fail.svg";
59
- import { SupportedExchanges } from "@/types";
63
+ import { SupportedExchanges } from "../../types";
60
64
  import { useLayerZeroStatus } from "@/util/tx-tracker";
61
65
  import { STARGATE_CHAIN_NAMES, CHAINS_ETHERSCAN } from "@/util/constants";
62
66
 
@@ -157,7 +161,6 @@ export enum WithdrawalStep {
157
161
  }
158
162
  const withdrawalSteps = [
159
163
  WithdrawalStep.ChooseExchange,
160
- WithdrawalStep.CheckSessionKey,
161
164
  WithdrawalStep.ChooseExchangeAsset,
162
165
  WithdrawalStep.ChooseAmount,
163
166
  WithdrawalStep.SignUserOp,
@@ -904,14 +907,19 @@ const ChooseAmountStep = ({
904
907
  }
905
908
  }, [amount, tokenInData?.decimals, setAmountIn]);
906
909
 
907
- const hasAmount = !!amount && amount !== ".";
910
+ const numericAmount = getPositiveDecimalValue(amount);
911
+ const hasPositiveAmount = numericAmount !== null;
908
912
  const hasUsdValue = !!usdValue && usdValue !== ".";
909
913
  const notEnoughBalance = selectedToken
910
- ? hasAmount && parseFloat(amount) > selectedToken.balance
914
+ ? hasPositiveAmount &&
915
+ numericAmount !== null &&
916
+ numericAmount > selectedToken.balance
911
917
  : true;
912
918
 
913
919
  // Limits validation logic - only for CEX withdrawals
914
- const currentUsdValue = hasUsdValue ? parseFloat(usdValue) : 0;
920
+ const currentUsdValue = hasUsdValue
921
+ ? getPositiveDecimalValue(usdValue) ?? 0
922
+ : 0;
915
923
  const minValueForToken =
916
924
  isWithdrawal && selectedToken
917
925
  ? EXCHANGE_MIN_LIMIT[
@@ -922,19 +930,23 @@ const ChooseAmountStep = ({
922
930
  const isBelowMinAmount =
923
931
  isWithdrawal &&
924
932
  selectedToken &&
925
- hasAmount &&
933
+ hasPositiveAmount &&
926
934
  currentUsdValue > 0 &&
927
935
  minValueForToken &&
928
- +amount < minValueForToken;
936
+ numericAmount !== null &&
937
+ numericAmount < minValueForToken;
929
938
  const isAboveMaxAmount =
930
939
  isWithdrawal &&
931
940
  selectedToken &&
932
- hasAmount &&
941
+ hasPositiveAmount &&
933
942
  currentUsdValue > 0 &&
934
943
  currentUsdValue > +maxUsdAmount;
935
944
 
936
945
  const isAmountInvalid =
937
- !hasAmount || isBelowMinAmount || isAboveMaxAmount || notEnoughBalance;
946
+ !hasPositiveAmount ||
947
+ isBelowMinAmount ||
948
+ isAboveMaxAmount ||
949
+ notEnoughBalance;
938
950
 
939
951
  if (!selectedToken) {
940
952
  return (
@@ -984,7 +996,7 @@ const ChooseAmountStep = ({
984
996
  isAmountInvalid ? "visible" : "hidden"
985
997
  }
986
998
  >
987
- {!hasAmount
999
+ {!hasPositiveAmount
988
1000
  ? "Please enter an amount"
989
1001
  : isBelowMinAmount
990
1002
  ? `Minimum amount is ${formatNumber(minValueForToken)} ${selectedToken.symbol}`
@@ -7,7 +7,7 @@ import { AmountInput, AmountInputValue } from "@/components/AmountInput";
7
7
  import CurrencySwapDisplay from "@/components/CurrencySwapDisplay";
8
8
  import { useEnsoPrice } from "@/enso-api/api";
9
9
  import { normalizeValue, denormalizeValue } from "@/util";
10
- import { precisionizeNumber } from "@/util/common";
10
+ import { precisionizeNumber, getPositiveDecimalValue } from "@/util/common";
11
11
  import { useTokenBalance } from "@/util/wallet";
12
12
  import { useAppDetails } from "@/util/enso-hooks";
13
13
  const WalletAmountStep = ({ setStep }: { setStep: (step: string) => void }) => {
@@ -100,9 +100,9 @@ const WalletAmountStep = ({ setStep }: { setStep: (step: string) => void }) => {
100
100
  }
101
101
  }, [tokenAmount, tokenInData?.decimals, setAmountIn]);
102
102
 
103
- const hasTokenAmount = !!tokenAmount && tokenAmount !== ".";
104
- const notEnoughBalance = hasTokenAmount ? +balanceIn < +amountIn : false;
105
- const isAmountInvalid = !hasTokenAmount || notEnoughBalance;
103
+ const hasPositiveAmount = getPositiveDecimalValue(tokenAmount) !== null;
104
+ const notEnoughBalance = hasPositiveAmount ? +balanceIn < +amountIn : false;
105
+ const isAmountInvalid = !hasPositiveAmount || notEnoughBalance;
106
106
 
107
107
  return (
108
108
  <BodyWrapper>
package/src/index.ts CHANGED
@@ -1,22 +1,11 @@
1
- import {
2
- CheckoutModal,
3
- type CheckoutModalProps,
4
- } from "./components/CheckoutModal";
5
- import { Checkout, type CheckoutConfig } from "./components/Checkout";
1
+ import { CheckoutModal } from "./components/CheckoutModal";
2
+ import { Checkout } from "./components/Checkout";
6
3
 
7
- // Export two versions for different integration needs
8
- export {
9
- // Modal version with isActive/setIsActive control
10
- CheckoutModal,
11
- CheckoutModalProps,
4
+ // Export components
5
+ export { CheckoutModal, Checkout };
12
6
 
13
- // Standalone widget version without modal
14
- Checkout,
15
- CheckoutConfig,
16
- };
17
-
18
- // Export theme type for TypeScript users
19
- export type { WidgetTheme } from "./types";
7
+ // Export types directly from types module for proper bundling
8
+ export type { CheckoutConfig, CheckoutModalProps, WidgetTheme } from "./types";
20
9
  export { SupportedExchanges } from "./types";
21
10
 
22
11
  // Export default CEX bridge chain mapping for users to extend
@@ -373,3 +373,12 @@ export const sanitizeDecimalInput = (value: string, maxDecimals?: number) => {
373
373
 
374
374
  return integerPart;
375
375
  };
376
+
377
+ export const getPositiveDecimalValue = (value: string) => {
378
+ if (!value || value === ".") return null;
379
+
380
+ const numeric = Number(value);
381
+ if (Number.isNaN(numeric) || numeric <= 0) return null;
382
+
383
+ return numeric;
384
+ };
package/tsconfig.json CHANGED
@@ -4,10 +4,12 @@
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "Bundler",
6
6
  "skipLibCheck": true,
7
+ "baseUrl": ".",
7
8
  "paths": {
8
9
  "@/*": ["./src/*"]
9
10
  },
10
11
  "jsx": "react-jsx",
11
12
  "declaration": true
12
- }
13
+ },
14
+ "include": ["src"]
13
15
  }
package/vite.config.ts CHANGED
@@ -8,7 +8,7 @@ export default defineConfig(({ mode }) => ({
8
8
  dts({
9
9
  insertTypesEntry: true,
10
10
  rollupTypes: true,
11
- bundledPackages: ["./src/types"],
11
+ tsconfigPath: "./tsconfig.json",
12
12
  }), // generates *.d.ts beside the JS
13
13
  ].filter(Boolean),
14
14
  resolve: {