@ensofinance/checkout-widget 0.0.9 → 0.0.11

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.0.9",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "homepage": "https://www.enso.build/",
6
6
  "repository": {
@@ -89,6 +89,7 @@ const Checkout = ({
89
89
  }, [tokenOut, chainIdOut]);
90
90
 
91
91
  useEffect(() => {
92
+ if (!apiKey) alert("Please provide an API key");
92
93
  setEnsoApiToken(apiKey);
93
94
  }, [apiKey]);
94
95
 
@@ -8,7 +8,7 @@ import { Button, IconButton, Input } from "../ui";
8
8
  import { HeaderWrapper, HeaderTitle, BodyWrapper } from "../ui/styled";
9
9
  import { TransactionDetailRow } from "../TransactionDetailRow";
10
10
  import { useAppDetails, useRouteData } from "@/util/enso-hooks";
11
- import { getChainName } from "@/util/common";
11
+ import { useChainName } from "@/util/common";
12
12
  import QuoteParameters from "../QuoteParameters";
13
13
 
14
14
  const QuoteStep = () => {
@@ -19,6 +19,7 @@ const QuoteStep = () => {
19
19
  const { routeLoading, usdAmountIn, routeData } = useRouteData();
20
20
  const walletChainId = useChainId();
21
21
  const { switchChain } = useSwitchChain();
22
+ const chainName = useChainName(chainIdIn);
22
23
 
23
24
  const wrongChain = walletChainId !== chainIdIn;
24
25
 
@@ -95,7 +96,7 @@ const QuoteStep = () => {
95
96
  switchChain({ chainId: chainIdIn });
96
97
  }}
97
98
  >
98
- Switch to {getChainName(chainIdIn)}
99
+ Switch to {chainName}
99
100
  </Button>
100
101
  ) : (
101
102
  <Button
@@ -1,5 +1,5 @@
1
1
  import { useQuery } from "@tanstack/react-query";
2
- import { useAccount } from "wagmi";
2
+ import { useAccount, useConfig } from "wagmi";
3
3
  import { type Address, zeroAddress } from "viem";
4
4
  import {
5
5
  CHAINS_ETHERSCAN,
@@ -253,8 +253,19 @@ export const useTokenFromList = (
253
253
  );
254
254
  };
255
255
 
256
- const ALTERNATIVE_SYMBOLS = {
257
- USDT: "USDT0",
256
+ const getAlternativeMeshSymbol = (
257
+ symbol: string,
258
+ chainId: SupportedChainId,
259
+ ) => {
260
+ if (symbol === "USDT") {
261
+ if (chainId === SupportedChainId.BSC) {
262
+ return "BSC-USD";
263
+ }
264
+
265
+ return "USDT0";
266
+ }
267
+
268
+ return symbol;
258
269
  };
259
270
 
260
271
  export const useTokenFromListBySymbols = (
@@ -266,9 +277,11 @@ export const useTokenFromListBySymbols = (
266
277
  ? tokenSymbols
267
278
  : [tokenSymbols];
268
279
 
269
- return arrayData.map((symbol) =>
280
+ return arrayData.map((meshSymbol) =>
270
281
  data?.find(
271
- (token) => token.symbol == (ALTERNATIVE_SYMBOLS[symbol] ?? symbol),
282
+ (token) =>
283
+ token.symbol ==
284
+ getAlternativeMeshSymbol(meshSymbol, priorityChainId),
272
285
  ),
273
286
  );
274
287
  };
@@ -305,6 +318,12 @@ export const getChainName = (chainId: SupportedChainId) => {
305
318
  return capitalize(geckoName).split("-")[0];
306
319
  };
307
320
 
321
+ export const useChainName = (chainId: number) => {
322
+ const config = useConfig();
323
+ const chain = config.chains.find((c) => c.id === chainId);
324
+ return chain?.name || getChainName(chainId as SupportedChainId);
325
+ };
326
+
308
327
  export const shortenAddress = (address: string) => {
309
328
  return `${address.slice(0, 4)}...${address.slice(-4)}`;
310
329
  };