@layerswap/widget 0.1.15 → 0.1.16

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.
@@ -2,8 +2,9 @@ import { FC } from "react";
2
2
  import { SwapDirection } from "../Pages/SwapPages/Form/SwapFormValues";
3
3
  import { SelectMenuItem } from "../Pages/SwapPages/Form/Select/Shared/Props/selectMenuItem";
4
4
  import { ExchangeToken } from "../../Models/Exchange";
5
+ import { NetworkWithTokens } from "../../Models/Network";
5
6
  declare const CurrencyGroupFormField: FC<{
6
7
  direction: SwapDirection;
7
8
  }>;
8
- export declare function GenerateCurrencyMenuItems(currencies: ExchangeToken[], direction: string, lockedCurrency?: ExchangeToken | undefined): SelectMenuItem<ExchangeToken>[];
9
+ export declare function GenerateCurrencyMenuItems(currencies: ExchangeToken[], direction: string, lockedCurrency?: ExchangeToken | undefined, oppositeDirectionNetwork?: NetworkWithTokens | undefined): SelectMenuItem<ExchangeToken>[];
9
10
  export default CurrencyGroupFormField;
@@ -18,7 +18,7 @@ const CurrencyGroupFormField = ({ direction }) => {
18
18
  const exchange = direction === 'from' ? fromExchange : toExchange;
19
19
  const exchangeRoutesURL = resolveExchangesURLForSelectedToken(direction, values);
20
20
  const apiClient = new LayerSwapApiClient();
21
- const { data: exchanges, isLoading, error } = useSWR(`${exchangeRoutesURL}`, apiClient.fetcher, { keepPreviousData: true, fallbackData: { data: direction === 'from' ? sourceExchanges : destinationExchanges }, dedupingInterval: 10000 });
21
+ const { data: exchanges, } = useSWR(`${exchangeRoutesURL}`, apiClient.fetcher, { keepPreviousData: true, fallbackData: { data: direction === 'from' ? sourceExchanges : destinationExchanges }, dedupingInterval: 10000 });
22
22
  const availableAssetGroups = exchanges?.data?.find(e => e.name === exchange?.name)?.token_groups;
23
23
  const isLocked = direction === 'from' ? query?.lockFromAsset : query?.lockToAsset;
24
24
  const asset = direction === 'from' ? query?.fromAsset : query?.toAsset;
@@ -26,7 +26,8 @@ const CurrencyGroupFormField = ({ direction }) => {
26
26
  ? availableAssetGroups?.find(a => a.symbol.toUpperCase() === (asset)?.toUpperCase())
27
27
  : undefined;
28
28
  const filteredCurrencies = lockedCurrency ? [lockedCurrency] : availableAssetGroups;
29
- const currencyMenuItems = GenerateCurrencyMenuItems(filteredCurrencies, direction, lockedCurrency);
29
+ const oppositeDirectionNetwork = direction === 'from' ? to : from;
30
+ const currencyMenuItems = GenerateCurrencyMenuItems(filteredCurrencies, direction, lockedCurrency, oppositeDirectionNetwork);
30
31
  const value = currencyMenuItems?.find(x => x.id == currencyGroup?.symbol);
31
32
  useEffect(() => {
32
33
  if (value)
@@ -38,6 +39,9 @@ const CurrencyGroupFormField = ({ direction }) => {
38
39
  useEffect(() => {
39
40
  const currency = direction === 'from' ? toCurrency : fromCurrency;
40
41
  const value = availableAssetGroups?.find(r => r.symbol === currency?.symbol && r.status === 'active');
42
+ const newCurrencyGroup = availableAssetGroups?.find(r => r.symbol === currencyGroup?.symbol && r.status === 'active');
43
+ if (newCurrencyGroup)
44
+ setFieldValue(name, newCurrencyGroup);
41
45
  if (!value || currencyGroup?.manuallySet)
42
46
  return;
43
47
  (async () => {
@@ -62,8 +66,13 @@ const CurrencyGroupFormField = ({ direction }) => {
62
66
  }, [name, direction, toCurrency, fromCurrency, from, to, values]);
63
67
  return _jsx(PopoverSelectWrapper, { placeholder: "Asset", values: currencyMenuItems, value: value, setValue: handleSelect, disabled: isLocked });
64
68
  };
65
- export function GenerateCurrencyMenuItems(currencies, direction, lockedCurrency) {
66
- return currencies?.map(c => {
69
+ export function GenerateCurrencyMenuItems(currencies, direction, lockedCurrency, oppositeDirectionNetwork) {
70
+ const filterCondition = (c) => {
71
+ if (oppositeDirectionNetwork) {
72
+ return oppositeDirectionNetwork?.tokens?.some(t => t.symbol === c.symbol);
73
+ }
74
+ };
75
+ return currencies.filter(filterCondition)?.map(c => {
67
76
  const currency = c;
68
77
  const displayName = lockedCurrency?.symbol ?? currency.symbol;
69
78
  const isAvailable = (lockedCurrency || (c?.status !== "active" && c.status !== "not_found")) ? false : true;
@@ -1,7 +1,7 @@
1
1
  import { EventEmitter } from "events";
2
2
  import { KeyValueStorageOptions } from "@walletconnect/keyvaluestorage";
3
3
  import { Metadata, Namespace, UniversalProvider, UniversalProviderOpts } from "@walletconnect/universal-provider";
4
- import { AuthTypes, SessionTypes, SignClientTypes } from "@walletconnect/types";
4
+ import { AuthTypes, SignClientTypes } from "@walletconnect/types";
5
5
  import { JsonRpcResult } from "@walletconnect/jsonrpc-types";
6
6
  export type RpcMethod = "personal_sign" | "eth_sendTransaction" | "eth_accounts" | "eth_requestAccounts" | "eth_call" | "eth_getBalance" | "eth_sendRawTransaction" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "wallet_switchEthereumChain" | "wallet_addEthereumChain" | "wallet_getPermissions" | "wallet_requestPermissions" | "wallet_registerOnboarding" | "wallet_watchAsset" | "wallet_scanQRCode" | "wallet_sendCalls" | "wallet_getCapabilities" | "wallet_getCallsStatus" | "wallet_showCallsStatus";
7
7
  export type RpcEvent = "accountsChanged" | "chainChanged" | "message" | "disconnect" | "connect";
@@ -119,7 +119,7 @@ export declare class EthereumProvider implements IEthereumProvider {
119
119
  removeListener: IEthereumProviderEvents["removeListener"];
120
120
  off: IEthereumProviderEvents["off"];
121
121
  get isWalletConnect(): boolean;
122
- get session(): SessionTypes.Struct | undefined;
122
+ get session(): import("@walletconnect/types").SessionTypes.Struct | undefined;
123
123
  protected registerEventListeners(): void;
124
124
  protected switchEthereumChain(chainId: number): void;
125
125
  protected isCompatibleChainId(chainId: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerswap/widget",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Streamline your asset transaction experience with Layerswap Widget across 50+ blockchains and 15+ exchanges.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",