@ensofinance/checkout-widget 0.1.1 → 0.1.2

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.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "homepage": "https://www.enso.build/",
6
6
  "repository": {
@@ -9,7 +9,7 @@ import {
9
9
  Image,
10
10
  Table,
11
11
  } from "@chakra-ui/react";
12
- import { ChevronLeft, X, ArrowDownUpIcon } from "lucide-react";
12
+ import { ChevronLeft, X, ArrowDownUpIcon, TriangleAlert } from "lucide-react";
13
13
  import { useContext, useEffect, useMemo, useState, useCallback } from "react";
14
14
  import { useAccount, useSignMessage } from "wagmi";
15
15
  import { getUserOperationHash } from "viem/account-abstraction";
@@ -878,20 +878,33 @@ const ChooseAmountStep = ({
878
878
  if (!selectedToken) return;
879
879
 
880
880
  if (inputMode === "usd") {
881
- const cleanUsd = value.replace("$", "") || "";
881
+ const cleanUsd = value.replace("$", "");
882
882
  setUsdValue(cleanUsd);
883
+ if (!cleanUsd) {
884
+ setAmount("");
885
+ return;
886
+ }
883
887
  // Calculate token amount from USD value
884
888
  const tokenPrice =
885
889
  selectedToken.marketValue / selectedToken.balance;
886
- const tokenAmount = parseFloat(cleanUsd || "0") / tokenPrice;
887
- setAmount(precisionizeNumber(tokenAmount, roundingPrecision));
890
+ const tokenAmount = parseFloat(cleanUsd) / tokenPrice;
891
+ setAmount(
892
+ isNaN(tokenAmount)
893
+ ? ""
894
+ : precisionizeNumber(tokenAmount, roundingPrecision),
895
+ );
888
896
  } else {
897
+ if (!value) {
898
+ setAmount("");
899
+ setUsdValue("");
900
+ return;
901
+ }
889
902
  setAmount(precisionizeNumber(value, roundingPrecision));
890
903
  // Calculate USD value from token amount
891
904
  const tokenPrice =
892
905
  selectedToken.marketValue / selectedToken.balance;
893
906
  const usdAmount = parseFloat(value) * tokenPrice;
894
- setUsdValue(usdAmount.toFixed(2));
907
+ setUsdValue(isNaN(usdAmount) ? "" : usdAmount.toFixed(2));
895
908
  }
896
909
  };
897
910
 
@@ -1200,6 +1213,7 @@ const InitiateWithdrawalStep = ({
1200
1213
  const { tokenInData } = useAppDetails();
1201
1214
  const sessionId = useAppStore((state) => state.sessionId);
1202
1215
  const [isLoading, setIsLoading] = useState(true);
1216
+ const [error, setError] = useState<string | null>(null);
1203
1217
  const selectedIntegration = useAppStore((s) => s.selectedIntegration);
1204
1218
 
1205
1219
  const handleMeshAccessPayload = useHandleMeshAccessPayload();
@@ -1272,6 +1286,7 @@ const InitiateWithdrawalStep = ({
1272
1286
 
1273
1287
  console.log("accessTokens", accessTokens);
1274
1288
 
1289
+ let handledByEvent = false;
1275
1290
  const link = createLink({
1276
1291
  clientId: address,
1277
1292
  accessTokens,
@@ -1285,6 +1300,7 @@ const InitiateWithdrawalStep = ({
1285
1300
  },
1286
1301
  onExit: (error) => {
1287
1302
  console.log("Mesh link exited:", error);
1303
+ if (handledByEvent) return;
1288
1304
  setIsLoading(false);
1289
1305
  setStep(WithdrawalStep.ChooseExchangeAsset);
1290
1306
  },
@@ -1294,8 +1310,18 @@ const InitiateWithdrawalStep = ({
1294
1310
  console.log(
1295
1311
  "Transfer executed, closing mesh link and moving to TrackUserOp step",
1296
1312
  );
1313
+ handledByEvent = true;
1297
1314
  link.closeLink();
1298
1315
  setStep(WithdrawalStep.TrackUserOp);
1316
+ } else if (ev.type === "transferExecutionError") {
1317
+ const errorMessage =
1318
+ ev.payload?.errorMessage ||
1319
+ "Transfer failed. Please try again.";
1320
+ console.error("Mesh transfer error:", errorMessage);
1321
+ handledByEvent = true;
1322
+ link.closeLink();
1323
+ setError(errorMessage);
1324
+ setIsLoading(false);
1299
1325
  }
1300
1326
  },
1301
1327
  });
@@ -1310,6 +1336,28 @@ const InitiateWithdrawalStep = ({
1310
1336
  fetchLinkTokenAndOpen();
1311
1337
  }, [selectedToken, userOp]);
1312
1338
 
1339
+ if (error) {
1340
+ return (
1341
+ <BodyWrapper>
1342
+ <Flex direction="column" align="center" justify="center" flex={1} p={6} gap={4}>
1343
+ <Flex
1344
+ align="center"
1345
+ justify="center"
1346
+ w={12}
1347
+ h={12}
1348
+ borderRadius="full"
1349
+ bg="orange.100"
1350
+ >
1351
+ <Icon as={TriangleAlert} boxSize={6} color="orange.500" />
1352
+ </Flex>
1353
+ <Text fontSize="md" textAlign="center" color="gray.700">
1354
+ {error}
1355
+ </Text>
1356
+ </Flex>
1357
+ </BodyWrapper>
1358
+ );
1359
+ }
1360
+
1313
1361
  return (
1314
1362
  <BodyWrapper>
1315
1363
  <Center>