@ensofinance/checkout-widget 0.1.4 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ensofinance/checkout-widget",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "homepage": "https://www.enso.build/",
6
6
  "repository": {
@@ -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,
@@ -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>
@@ -15,8 +15,16 @@ const WalletAssetStep = ({ setStep }: { setStep: (step: string) => void }) => {
15
15
  const tokenIn = useAppStore((state) => state.tokenIn);
16
16
  const setChainIdIn = useAppStore((state) => state.setChainIdIn);
17
17
  const chainIdIn = useAppStore((state) => state.chainIdIn);
18
+ const tokenOut = useAppStore((state) => state.tokenOut);
19
+ const chainIdOut = useAppStore((state) => state.chainIdOut);
18
20
  const { holdingsList, isLoading } = useWalletBalance();
19
21
 
22
+ const filteredHoldings = holdingsList?.filter(
23
+ (asset) =>
24
+ !(asset.token.toLowerCase() === tokenOut.toLowerCase() &&
25
+ asset.chainId === chainIdOut),
26
+ );
27
+
20
28
  useEffect(() => {
21
29
  setSelectedIntegration(null);
22
30
  }, []);
@@ -33,7 +41,7 @@ const WalletAssetStep = ({ setStep }: { setStep: (step: string) => void }) => {
33
41
  width="300px"
34
42
  />
35
43
  ))
36
- : holdingsList?.map((asset) => (
44
+ : filteredHoldings?.map((asset) => (
37
45
  <AssetCard
38
46
  key={`${asset.token}-${asset.chainId}`}
39
47
  chainId={asset.chainId}
@@ -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
+ };