@layerswap/widget 1.0.3 → 1.0.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.
Files changed (45) hide show
  1. package/dist/esm/Models/Theme.js +44 -2
  2. package/dist/esm/components/Buttons/secondaryButton.js +1 -1
  3. package/dist/esm/components/ColorSchema.js +0 -1
  4. package/dist/esm/components/Input/Amount/Balance.js +2 -2
  5. package/dist/esm/components/Input/Amount/ReceiveAmount.js +1 -1
  6. package/dist/esm/components/Modal/vaulModal.js +1 -1
  7. package/dist/esm/components/Pages/Swap/Form/FeeDetails/index.js +5 -5
  8. package/dist/esm/components/Pages/Swap/Withdraw/Wallet/index.js +2 -2
  9. package/dist/esm/components/Pages/Swap/Withdraw/messages/TransactionMessages.js +3 -3
  10. package/dist/esm/components/Widget/Index.js +1 -1
  11. package/dist/esm/context/LayerswapProvider.js +1 -0
  12. package/dist/esm/context/balanceAccounts.js +1 -1
  13. package/dist/esm/helpers/{getSettings.js → getSettings/getSettings.js} +1 -16
  14. package/dist/esm/helpers/getSettings/index.js +2 -0
  15. package/dist/esm/helpers/getSettings/useSettings.js +17 -0
  16. package/dist/esm/hooks/useAllWithdrawalBalances.js +4 -4
  17. package/dist/esm/lib/AppSettings.js +1 -0
  18. package/dist/esm/lib/apiClients/index.js +2 -1
  19. package/dist/esm/stores/balanceStore.js +44 -77
  20. package/dist/index.css +1 -1
  21. package/dist/tsconfig.tsbuildinfo +1 -1
  22. package/dist/types/Models/Theme.d.ts +0 -1
  23. package/dist/types/Models/Theme.d.ts.map +1 -1
  24. package/dist/types/components/ColorSchema.d.ts.map +1 -1
  25. package/dist/types/components/Pages/Swap/Withdraw/messages/TransactionMessages.d.ts +2 -2
  26. package/dist/types/components/Pages/Swap/Withdraw/messages/TransactionMessages.d.ts.map +1 -1
  27. package/dist/types/context/LayerswapProvider.d.ts +1 -0
  28. package/dist/types/context/LayerswapProvider.d.ts.map +1 -1
  29. package/dist/types/helpers/getSettings/getSettings.d.ts +7 -0
  30. package/dist/types/helpers/getSettings/getSettings.d.ts.map +1 -0
  31. package/dist/types/helpers/getSettings/index.d.ts +3 -0
  32. package/dist/types/helpers/getSettings/index.d.ts.map +1 -0
  33. package/dist/types/helpers/getSettings/useSettings.d.ts +6 -0
  34. package/dist/types/helpers/getSettings/useSettings.d.ts.map +1 -0
  35. package/dist/types/lib/AppSettings.d.ts +1 -0
  36. package/dist/types/lib/AppSettings.d.ts.map +1 -1
  37. package/dist/types/lib/apiClients/index.d.ts +2 -1
  38. package/dist/types/lib/apiClients/index.d.ts.map +1 -1
  39. package/dist/types/stores/balanceStore.d.ts +6 -4
  40. package/dist/types/stores/balanceStore.d.ts.map +1 -1
  41. package/dist/types/types/wallet.d.ts +1 -1
  42. package/dist/types/types/wallet.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/types/helpers/getSettings.d.ts +0 -12
  45. package/dist/types/helpers/getSettings.d.ts.map +0 -1
@@ -1,6 +1,5 @@
1
1
  export const THEME_COLORS = {
2
2
  "imxMarketplace": {
3
- backdrop: "0, 121, 133",
4
3
  buttonTextColor: '255, 255, 255',
5
4
  tertiary: '140, 152, 192',
6
5
  logo: '255, 255, 255',
@@ -65,7 +64,6 @@ export const THEME_COLORS = {
65
64
  },
66
65
  },
67
66
  "default": {
68
- backdrop: "62, 18, 64",
69
67
  tertiary: '118, 128, 147',
70
68
  buttonTextColor: '228, 229, 240',
71
69
  logo: '255, 0, 147',
@@ -110,6 +108,50 @@ export const THEME_COLORS = {
110
108
  'text': '163, 173, 194',
111
109
  },
112
110
  },
111
+ "halloween": {
112
+ tertiary: "110, 80, 140",
113
+ buttonTextColor: "255, 240, 200",
114
+ logo: '255, 0, 147',
115
+ footerLogo: "none",
116
+ warning: {
117
+ Foreground: "255, 180, 70",
118
+ Background: "45, 30, 10",
119
+ },
120
+ error: {
121
+ Foreground: "255, 90, 90",
122
+ Background: "40, 15, 15",
123
+ },
124
+ success: {
125
+ Foreground: "150, 255, 180",
126
+ Background: "20, 40, 25",
127
+ },
128
+ primary: {
129
+ DEFAULT: "230, 80, 25",
130
+ "100": "255, 180, 120",
131
+ "200": "255, 150, 70",
132
+ "300": "255, 120, 50",
133
+ "400": "255, 100, 30",
134
+ "500": "230, 80, 25",
135
+ "600": "190, 60, 20",
136
+ "700": "150, 45, 15",
137
+ "800": "100, 30, 10",
138
+ "900": "50, 15, 5",
139
+ "text": "255, 240, 200",
140
+ },
141
+ secondary: {
142
+ DEFAULT: "35, 25, 60",
143
+ "100": "90, 75, 130",
144
+ "200": "75, 60, 120",
145
+ "300": "60, 50, 110",
146
+ "400": "50, 40, 90",
147
+ "500": "40, 30, 75",
148
+ "600": "30, 25, 65",
149
+ "700": "25, 20, 55",
150
+ "800": "18, 15, 45",
151
+ "900": "12, 10, 35",
152
+ "text": "220, 210, 250",
153
+ },
154
+ },
113
155
  "ton": {
114
156
  tertiary: '134, 134, 134',
115
157
  buttonTextColor: '15, 15, 15',
@@ -4,7 +4,7 @@ import SpinIcon from "../Icons/spinIcon";
4
4
  const SecondaryButton = (props) => {
5
5
  const { className, isLoading, children, ...buttonProps } = props;
6
6
  const size = props.size || 'md';
7
- return (_jsxs("button", { ...buttonProps, type: "button", disabled: props.disabled || isLoading, className: clsx('rounded-md duration-200 break-keep transition bg-secondary-500 hover:bg-secondary-400 border border-secondary-400 hover:border-secondary-200 font-semibold text-primary-buttonTextColor shadow-xs cursor-pointer disabled:bg-secondary-300 disabled:text-secondary-text/50 disabled:cursor-not-allowed relative flex items-center justify-center space-x-2', className, {
7
+ return (_jsxs("button", { ...buttonProps, type: "button", disabled: props.disabled || isLoading, className: clsx('rounded-md duration-200 break-keep transition bg-secondary-500 hover:bg-secondary-400 border border-secondary-400 hover:border-secondary-200 font-semibold text-primary-text shadow-xs cursor-pointer disabled:bg-secondary-300 disabled:text-secondary-text/50 disabled:cursor-not-allowed relative flex items-center justify-center space-x-2', className, {
8
8
  'px-2 py-1 text-xs': size === 'xs',
9
9
  'px-2 py-1 text-sm': size === 'sm',
10
10
  'px-2.5 py-1.5 text-sm': size === 'md',
@@ -57,7 +57,6 @@ const ColorSchema = ({ themeData }) => {
57
57
  --ls-border-radius-full: 9999px;
58
58
  --ls-border-radius-default: ${adjustBorderRadius('small', mergedTheme.borderRadius)};
59
59
 
60
- --ls-colors-backdrop: ${mergedTheme.backdrop};
61
60
  --ls-colors-logo: ${mergedTheme.logo};
62
61
  --ls-colors-primary: ${mergedTheme.primary?.DEFAULT};
63
62
  --ls-colors-primary-100: ${mergedTheme.primary?.[100]};
@@ -10,12 +10,12 @@ const Balance = ({ values, direction }) => {
10
10
  const token = direction === 'from' ? fromCurrency : toCurrency;
11
11
  const network = direction === 'from' ? from : to;
12
12
  const address = direction === 'from' ? selectedSourceAccount?.address : destination_address;
13
- const { balances, isLoading } = useBalance(address, network, { refreshInterval: 20000 });
13
+ const { balances, isLoading } = useBalance(address, network, { refreshInterval: 20000, dedupeInterval: 20000 });
14
14
  const tokenBalance = balances?.find(b => b?.network === network?.name && b?.token === token?.symbol);
15
15
  const truncatedBalance = tokenBalance?.amount !== undefined ? truncateDecimals(tokenBalance?.amount, token?.precision) : '';
16
16
  if (!isLoading && !(network && token && tokenBalance))
17
17
  return null;
18
- return _jsx("div", { className: "min-w-4/5 -top-[1px] p-1 mx-2 relative rounded-b-lg text-center bg-secondary-400 py-0.5 text-xs text-secondary-text leading-[18px] font-normal", children: isLoading ?
18
+ return _jsx("div", { className: "min-w-4/5 p-1 mx-2 relative rounded-b-lg text-center bg-secondary-400 py-0.5 text-xs text-secondary-text leading-[18px] font-normal", children: isLoading ?
19
19
  _jsx("div", { className: 'h-[10px] w-fit px-4 inline-flex bg-gray-500 rounded-xs animate-pulse' })
20
20
  : !truncatedBalance ?
21
21
  _jsxs("div", { className: "flex items-center justify-center gap-1 text-orange-400", children: [_jsx(InfoIcon, { className: 'w-3 h-3' }), _jsx("span", { children: "Network issue" })] })
@@ -6,5 +6,5 @@ export const ReceiveAmount = ({ source_token, destination_token, fee, isFeeLoadi
6
6
  const receive_amount = fee?.quote.receive_amount;
7
7
  const receiveAmountInUsd = receive_amount && destination_token && fee.quote?.destination_token?.price_in_usd ? (receive_amount * fee.quote.destination_token.price_in_usd).toFixed(2) : undefined;
8
8
  const quote = fee?.quote;
9
- return (_jsx(_Fragment, { children: _jsxs("div", { className: "flex flex-col min-w-0 font-normal border-0 text-[28px] leading-7 text-primary-text w-full relative truncate", children: [_jsx("div", { className: "flex items-center justify-start w-full relative", children: _jsx("div", { className: clsx("w-full flex items-center py-[3px] pr-3", { "animate-pulse-stronger": isFeeLoading }, { "text-secondary-text": !receive_amount }), children: _jsx(NumberFlow, { value: receive_amount || 0, trend: 0, format: { maximumFractionDigits: fee?.quote.destination_token?.decimals || 2 } }) }) }), _jsxs("div", { className: "flex items-baseline space-x-2", children: [_jsx("span", { className: "text-base leading-5 font-medium text-secondary-text h-5", children: _jsx(NumberFlow, { className: "p-0", value: Number(receiveAmountInUsd) || 0, format: { style: 'currency', currency: 'USD', maximumFractionDigits: receiveAmountInUsd ? 2 : 0 }, trend: 0 }) }), _jsx(PriceImpact, { className: "h-5 text-base leading-5", bridgeFee: quote?.blockchain_fee, destinationTokenPriceUsd: quote?.destination_token?.price_in_usd, receiveAmount: quote?.receive_amount, requestedAmount: quote?.requested_amount, serviceFee: quote?.service_fee, sourceTokenPriceUsd: quote?.source_token?.price_in_usd })] })] }) }));
9
+ return (_jsx(_Fragment, { children: _jsxs("div", { className: "flex flex-col min-w-0 font-normal border-0 text-[28px] leading-7 text-primary-text w-full relative truncate", children: [_jsx("div", { className: "flex items-center justify-start w-full relative", children: _jsx("div", { className: clsx("w-full flex items-center pt-2 pr-3", { "animate-pulse-stronger": isFeeLoading }, { "text-secondary-text": !receive_amount }), children: _jsx(NumberFlow, { value: receive_amount || 0, trend: 0, format: { maximumFractionDigits: fee?.quote.destination_token?.decimals || 2 } }) }) }), _jsxs("div", { className: "flex items-baseline space-x-2 h-5", children: [_jsx("span", { className: "text-base leading-5 font-medium text-secondary-text h-5", children: _jsx(NumberFlow, { className: "p-0", value: Number(receiveAmountInUsd) || 0, format: { style: 'currency', currency: 'USD', maximumFractionDigits: receiveAmountInUsd ? 2 : 0 }, trend: 0 }) }), _jsx(PriceImpact, { className: "h-5 text-base leading-5", bridgeFee: quote?.blockchain_fee, destinationTokenPriceUsd: quote?.destination_token?.price_in_usd, receiveAmount: quote?.receive_amount, requestedAmount: quote?.requested_amount, serviceFee: quote?.service_fee, sourceTokenPriceUsd: quote?.source_token?.price_in_usd })] })] }) }));
10
10
  };
@@ -81,7 +81,7 @@ const Comp = ({ children, show, setShow, header, description, onClose, onAnimati
81
81
  return (_jsx(Drawer.Root, { open: show, onOpenChange: handleOpenChange, container: container, snapPoints: snapPointsHeight, activeSnapPoint: snap, setActiveSnapPoint: setSnap, fadeFromIndex: 0, onDrag: (e) => {
82
82
  if (e.movementY < 0 && !expandRef.current?.classList.contains('hidden'))
83
83
  expandRef.current?.classList.add('hidden');
84
- }, modal: isMobile ? true : false, repositionInputs: false, onAnimationEnd: (e) => { onAnimationEnd && onAnimationEnd(e); }, handleOnly: isMobile, children: _jsxs(Drawer.Portal, { children: [_jsx(Drawer.Close, { asChild: true, children: isMobile
84
+ }, modal: isMobile ? true : false, repositionInputs: false, onAnimationEnd: (e) => { onAnimationEnd && onAnimationEnd(e); }, handleOnly: isMobileWithoutPortal, children: _jsxs(Drawer.Portal, { children: [_jsx(Drawer.Close, { asChild: true, children: isMobile
85
85
  ? _jsx(Drawer.Overlay, { className: 'fixed inset-0 z-50 bg-black/50 block' })
86
86
  : _jsx(motion.div, { className: 'absolute inset-0 z-50 bg-black/50 block', initial: { opacity: 0.5 }, animate: { opacity: 1 }, exit: { opacity: 0 } }, "backdrop") }), _jsxs(Drawer.Content, { "data-testid": "content", className: clsx('absolute flex flex-col bg-secondary-700 rounded-t-3xl bottom-0 left-0 right-0 h-full z-50 pb-4 text-primary-text ring-0! outline-hidden! ', className, {
87
87
  'border-none! rounded-none!': snap === 1,
@@ -43,10 +43,10 @@ export const DetailsButton = ({ quote: quoteData, isQuoteLoading, swapValues: va
43
43
  const averageCompletionTime = quote?.avg_completion_time;
44
44
  const shouldCheckNFT = reward?.campaign_type === "for_nft_holders" && !!reward?.nft_contract_address;
45
45
  const { balance: nftBalance, isLoading, error } = useSWRNftBalance(destinationAddress || '', destination, reward?.nft_contract_address || '');
46
- return (_jsxs("div", { className: 'flex items-center gap-1 space-x-3', children: [gasFeeInUsd &&
46
+ return (_jsxs("div", { className: 'flex items-center gap-1 space-x-3', children: [gasFeeInUsd ?
47
47
  _jsxs(_Fragment, { children: [_jsxs("div", { className: clsx("inline-flex items-center gap-1", { "animate-pulse-strong": isQuoteLoading }), children: [_jsx("div", { className: 'p-0.5', children: !values.fromExchange ?
48
- _jsx(GasIcon, { className: 'h-4 w-4 text-secondary-text' }) : _jsx(ExchangeGasIcon, { className: 'h-5 w-5 text-secondary-text' }) }), _jsx(NumberFlow, { className: "text-primary-text text-sm leading-6", value: gasFeeInUsd < 0.01 ? '0.01' : gasFeeInUsd, format: { style: 'currency', currency: 'USD' }, prefix: gasFeeInUsd < 0.01 ? '<' : undefined })] }), _jsx("div", { className: "w-px h-3 bg-primary-text-tertiary rounded-2xl" })] }), averageCompletionTime &&
49
- _jsx(_Fragment, { children: _jsxs("div", { className: clsx("text-right inline-flex items-center gap-1 text-sm", { "animate-pulse-strong": isQuoteLoading }), children: [_jsx("div", { className: 'p-0.5', children: _jsx(Clock, { className: 'h-4 w-4 text-secondary-text' }) }), _jsx(AverageCompletionTime, { className: "text-primary-text", avgCompletionTime: quote.avg_completion_time })] }) }), reward &&
50
- (!shouldCheckNFT || (!isLoading && !error && nftBalance !== undefined && nftBalance > 0)) &&
51
- _jsxs(_Fragment, { children: [_jsx("div", { className: "w-px h-3 bg-primary-text-tertiary rounded-2xl" }), _jsxs("div", { className: 'text-right text-primary-text inline-flex items-center gap-1', children: [_jsx(CupIcon, { alt: "Reward", width: 16, height: 16 }), _jsx(NumberFlow, { value: reward?.amount_in_usd < 0.01 ? '0.01' : reward?.amount_in_usd, format: { style: 'currency', currency: 'USD' }, prefix: reward?.amount_in_usd < 0.01 ? '<' : undefined })] })] })] }));
48
+ _jsx(GasIcon, { className: 'h-4 w-4 text-secondary-text' }) : _jsx(ExchangeGasIcon, { className: 'h-5 w-5 text-secondary-text' }) }), _jsx(NumberFlow, { className: "text-primary-text text-sm leading-6", value: gasFeeInUsd < 0.01 ? '0.01' : gasFeeInUsd, format: { style: 'currency', currency: 'USD' }, prefix: gasFeeInUsd < 0.01 ? '<' : undefined })] }), _jsx("div", { className: "w-px h-3 bg-primary-text-tertiary rounded-2xl" })] }) : null, averageCompletionTime ?
49
+ _jsx(_Fragment, { children: _jsxs("div", { className: clsx("text-right inline-flex items-center gap-1 text-sm", { "animate-pulse-strong": isQuoteLoading }), children: [_jsx("div", { className: 'p-0.5', children: _jsx(Clock, { className: 'h-4 w-4 text-secondary-text' }) }), _jsx(AverageCompletionTime, { className: "text-primary-text", avgCompletionTime: quote.avg_completion_time })] }) }) : null, (reward &&
50
+ (!shouldCheckNFT || (!isLoading && !error && nftBalance !== undefined && nftBalance > 0))) ?
51
+ _jsxs(_Fragment, { children: [_jsx("div", { className: "w-px h-3 bg-primary-text-tertiary rounded-2xl" }), _jsxs("div", { className: 'text-right text-primary-text inline-flex items-center gap-1', children: [_jsx(CupIcon, { alt: "Reward", width: 16, height: 16 }), _jsx(NumberFlow, { value: reward?.amount_in_usd < 0.01 ? '0.01' : reward?.amount_in_usd, format: { style: 'currency', currency: 'USD' }, prefix: reward?.amount_in_usd < 0.01 ? '<' : undefined })] })] }) : null] }));
52
52
  };
@@ -14,7 +14,7 @@ export const WalletTransferAction = ({ swapData, swapId, refuel, onWalletWithdra
14
14
  const selectedSourceAccount = useSelectedAccount("from", source_network?.name);
15
15
  useEffect(() => {
16
16
  const selectedWallet = wallets.find(w => w.id === selectedSourceAccount?.id && w.addresses.some(a => a.toLowerCase() === selectedSourceAccount.address.toLowerCase()));
17
- if (selectedSourceAccount && selectedWallet) {
17
+ if (selectedSourceAccount && selectedWallet && provider?.switchAccount) {
18
18
  provider?.switchAccount(selectedWallet, selectedSourceAccount.address);
19
19
  }
20
20
  }, [selectedSourceAccount?.address, source_network?.name]);
@@ -147,7 +147,7 @@ const TransactionMessage = ({ error, isLoading }) => {
147
147
  // where: 'swapWithdrawalError',
148
148
  // severity: 'error',
149
149
  // });
150
- return _jsx(TransactionMessages.UexpectedErrorMessage, { message: error.message });
150
+ return _jsx(TransactionMessages.UnexpectedErrorMessage, { message: error.message });
151
151
  }
152
152
  else
153
153
  return _jsx(_Fragment, {});
@@ -25,7 +25,7 @@ const WaletMismatchMessage = ({ address }) => {
25
25
  const SwapErrorMessage = ({ message }) => {
26
26
  return _jsx(WalletMessage, { status: "error", header: 'API error', details: message });
27
27
  };
28
- const UexpectedErrorMessage = ({ message }) => {
28
+ const UnexpectedErrorMessage = ({ message }) => {
29
29
  return _jsx(WalletMessage, { status: "error", header: 'Unexpected error', details: message, showInModal: true });
30
30
  };
31
31
  const ActionMessages = {
@@ -36,7 +36,7 @@ const ActionMessages = {
36
36
  WaletMismatchMessage,
37
37
  TransactionFailedMessage,
38
38
  SwapErrorMessage,
39
- UexpectedErrorMessage,
39
+ UnexpectedErrorMessage,
40
40
  DifferentAccountsNotAllowedError
41
41
  };
42
42
  export var TransactionMessageType;
@@ -47,7 +47,7 @@ export var TransactionMessageType;
47
47
  TransactionMessageType["TransactionRejected"] = "TransactionRejected";
48
48
  TransactionMessageType["WaletMismatch"] = "WaletMismatch";
49
49
  TransactionMessageType["TransactionFailed"] = "TransactionFailed";
50
- TransactionMessageType["UexpectedErrorMessage"] = "UexpectedErrorMessage";
50
+ TransactionMessageType["UnexpectedErrorMessage"] = "UnexpectedErrorMessage";
51
51
  TransactionMessageType["DifferentAccountsNotAllowedError"] = "DifferentAccountsNotAllowedError";
52
52
  })(TransactionMessageType || (TransactionMessageType = {}));
53
53
  export default ActionMessages;
@@ -11,7 +11,7 @@ const Widget = ({ children, hideMenu, goBack, contextualMenu }) => {
11
11
  return _jsxs("div", { className: "relative p-px h-full", children: [AppSettings.ThemeData?.enableWideVersion &&
12
12
  _jsx("div", { className: "invisible sm:visible absolute inset-0 rounded-[25px] bg-gradient-to-t from-secondary-800 to-secondary-300 pointer-events-none" }), _jsxs("div", { id: "widget", style: AppSettings.ThemeData?.cardBackgroundStyle, className: clsx("sm:pb-4 rounded-3xl w-full sm:overflow-hidden relative bg-secondary-700 h-full flex flex-col", {
13
13
  "max-sm:has-openpicker:min-h-svh max-sm:min-h-[99.8svh] sm:has-openpicker:min-h-[79svh]": AppSettings.ThemeData?.enableWideVersion,
14
- "sm:has-openpicker:min-h-[650px]": !AppSettings.ThemeData?.enableWideVersion,
14
+ "has-openpicker:min-h-[650px]": !AppSettings.ThemeData?.enableWideVersion,
15
15
  "pb-4 overflow-hidden": AppSettings.ThemeData?.enablePortal == false,
16
16
  }), children: [AppSettings.ApiVersion === 'testnet' &&
17
17
  _jsx("div", { className: "relative z-20", children: _jsx("div", { className: "absolute -top-1 right-[calc(50%-68px)] bg-warning-foreground py-0.5 px-10 rounded-b-md text-xs scale-75", children: "TESTNET" }) }), !hideMenu &&
@@ -25,6 +25,7 @@ const LayerswapProviderComponent = ({ children, callbacks, config, walletProvide
25
25
  themeData = { ...THEME_COLORS['default'], ...config?.theme };
26
26
  AppSettings.ApiVersion = version || AppSettings.ApiVersion;
27
27
  AppSettings.ImtblPassportConfig = imtblPassport;
28
+ AppSettings.TonClientConfig = config?.tonConfigs || AppSettings.TonClientConfig;
28
29
  AppSettings.WalletConnectConfig = config?.walletConnect || AppSettings.WalletConnectConfig;
29
30
  AppSettings.ThemeData = themeData;
30
31
  if (apiKey)
@@ -114,7 +114,7 @@ export function useNetworkBalanceKey(direction, networkName) {
114
114
  }
115
115
  export function useNetworkBalance(direction, networkName) {
116
116
  const balanceKey = useNetworkBalanceKey(direction, networkName);
117
- const balance = useBalanceStore((s) => (s.isLoading ? undefined : s.balances[balanceKey || "unknown"]));
117
+ const balance = useBalanceStore((s) => (s.balances[balanceKey || "unknown"]));
118
118
  return balance;
119
119
  }
120
120
  export function useUpdateBalanceAccount(direction) {
@@ -1,5 +1,4 @@
1
- import { useEffect, useState } from "react";
2
- import LayerSwapApiClient from "../lib/apiClients/layerSwapApiClient";
1
+ import LayerSwapApiClient from "../../lib/apiClients/layerSwapApiClient";
3
2
  export async function getSettings(apiKey) {
4
3
  const apiClient = new LayerSwapApiClient();
5
4
  LayerSwapApiClient.apiKey = apiKey;
@@ -17,17 +16,3 @@ export async function getSettings(apiKey) {
17
16
  };
18
17
  return settings;
19
18
  }
20
- export function useSettings(apiKey) {
21
- const [loading, setLoading] = useState(true);
22
- const [settings, setSettings] = useState(null);
23
- useEffect(() => {
24
- (async () => {
25
- const settings = await getSettings(apiKey);
26
- if (!settings)
27
- throw new Error('Failed to fetch settings');
28
- setSettings(settings);
29
- setLoading(false);
30
- })();
31
- }, []);
32
- return { settings, loading };
33
- }
@@ -0,0 +1,2 @@
1
+ export * from './getSettings';
2
+ export * from './useSettings';
@@ -0,0 +1,17 @@
1
+ 'use client';
2
+ import { useEffect, useState } from "react";
3
+ import { getSettings } from "./getSettings";
4
+ export function useSettings(apiKey) {
5
+ const [loading, setLoading] = useState(true);
6
+ const [settings, setSettings] = useState(null);
7
+ useEffect(() => {
8
+ (async () => {
9
+ const settings = await getSettings(apiKey);
10
+ if (!settings)
11
+ throw new Error('Failed to fetch settings');
12
+ setSettings(settings);
13
+ setLoading(false);
14
+ })();
15
+ }, []);
16
+ return { settings, loading };
17
+ }
@@ -1,5 +1,5 @@
1
1
  import { useSettingsState } from "../context/settings";
2
- import { selectResolvedInitiatedBalances, useBalanceStore } from "../stores/balanceStore";
2
+ import { selectResolvedSortingBalances, useBalanceStore } from "../stores/balanceStore";
3
3
  import { useEffect, useMemo, useRef } from "react";
4
4
  import { useBalanceAccounts } from "../context/balanceAccounts";
5
5
  export default function useAllWithdrawalBalances() {
@@ -26,11 +26,11 @@ export default function useAllWithdrawalBalances() {
26
26
  }, [walletNetworks]);
27
27
  useEffect(() => {
28
28
  if (walletNetworks)
29
- useBalanceStore.getState().initAllBalances(walletNetworks);
29
+ useBalanceStore.getState().initSortingBalances(walletNetworks);
30
30
  }, [walletNetwokrsString]);
31
31
  const lastBalancesRef = useRef(null);
32
- const resolvedBalances = useBalanceStore(selectResolvedInitiatedBalances);
33
- const isLoading = useBalanceStore(s => s.isLoading);
32
+ const resolvedBalances = useBalanceStore(selectResolvedSortingBalances);
33
+ const isLoading = useBalanceStore(s => s.sortingDataIsLoading);
34
34
  if (resolvedBalances != null && Object.keys(resolvedBalances).length > 0) {
35
35
  lastBalancesRef.current = resolvedBalances;
36
36
  }
@@ -19,6 +19,7 @@ AppSettings.WalletConnectConfig = {
19
19
  };
20
20
  AppSettings.TonClientConfig = {
21
21
  tonApiKey: 'ac793ea74c19105d617dfbeedb827f1b267b4e91f1b15b2420d003ec49722c82',
22
+ manifestUrl: `https://layerswap.io/app/tonconnect-manifest.json`
22
23
  };
23
24
  AppSettings.ImtblPassportConfig = {
24
25
  publishableKey: "",
@@ -1,2 +1,3 @@
1
1
  export * from './jsonRpcClient';
2
- export * from './layerSwapApiClient';
2
+ import LayerswapApiClient from './layerSwapApiClient';
3
+ export { LayerswapApiClient };
@@ -19,8 +19,11 @@ function processQueue() {
19
19
  export const useBalanceStore = create()(subscribeWithSelector((set, get, api) => ({
20
20
  balances: {},
21
21
  lastFetchMap: {},
22
+ balanceKeysForSorting: {},
22
23
  initiatedBalances: null,
23
- isLoading: false,
24
+ sortingDataIsLoading: false,
25
+ partialPublished: false,
26
+ startTimeOfInit: undefined,
24
27
  fetchBalance: (address, network, options) => {
25
28
  const key = getKey(address, network);
26
29
  const entry = get().balances[key];
@@ -76,92 +79,56 @@ export const useBalanceStore = create()(subscribeWithSelector((set, get, api) =>
76
79
  }));
77
80
  return queuedPromise;
78
81
  },
79
- initAllBalances: pairs => {
80
- if (pairs.length > 0)
81
- set({ isLoading: true });
82
- set({ initiatedBalances: null });
83
- // kick off every fetch
84
- pairs.forEach(({ address, network }) => {
85
- get().fetchBalance(address, network, { dedupeInterval: 120000, ignoreCache: true, timeoutMs: 4000, retryCount: 0 });
82
+ initSortingBalances: pairs => {
83
+ const initiatedBalances = pairs.reduce((acc, { address, network }) => {
84
+ const key = getKey(address, network);
85
+ acc[network.name] = key;
86
+ return acc;
87
+ }, {});
88
+ const sortedpairs = pairs.sort((a, b) => Number(a.network.source_rank) - Number(b.network.source_rank));
89
+ sortedpairs.forEach(({ address, network }) => {
90
+ get().fetchBalance(address, network, { dedupeInterval: 120000, ignoreCache: false, timeoutMs: 4500, retryCount: 0 });
86
91
  });
87
- // subscribe to balance map changes
88
- const unsub = api.subscribe(state => state.balances, balances => {
89
- const done = pairs.every(({ address, network }) => balances[getKey(address, network)]?.status !== 'loading');
92
+ set({ sortingDataIsLoading: true });
93
+ set({ initiatedBalances });
94
+ set({ startTimeOfInit: Date.now() });
95
+ set({ partialPublished: false });
96
+ api.subscribe(state => state.balances, balances => {
97
+ const keysArray = Object.entries(get().initiatedBalances || {});
98
+ const done = keysArray.every(([_, key]) => balances[key].data);
90
99
  if (done) {
91
- const finalMap = pairs.reduce((acc, { address, network }) => {
92
- const key = getKey(address, network);
93
- const entry = balances[key];
94
- if (entry)
95
- acc[network.name] = key;
96
- return acc;
97
- }, {});
98
- set({ initiatedBalances: finalMap });
99
- set({ isLoading: false });
100
- unsub(); // cleanup subscription
100
+ set({ sortingDataIsLoading: false });
101
+ set({ balanceKeysForSorting: get().initiatedBalances });
102
+ set({ partialPublished: false });
101
103
  }
102
- });
103
- },
104
- getResolvedInitiatedBalances: () => {
105
- const keys = get().initiatedBalances;
106
- if (!keys)
107
- return null;
108
- const balances = get().balances;
109
- return Object.entries(keys).reduce((acc, [networkName, key]) => {
110
- const entry = balances[key];
111
- if (entry?.data)
112
- acc[networkName] = entry.data;
113
- return acc;
114
- }, {});
104
+ else {
105
+ const startedAt = get().startTimeOfInit ?? 0;
106
+ const elapsed = Date.now() - startedAt;
107
+ if (!get().partialPublished && elapsed >= 3000) {
108
+ const partial = {};
109
+ keysArray.forEach(([networkName, key]) => {
110
+ if (balances[key]?.data) {
111
+ partial[networkName] = key;
112
+ }
113
+ });
114
+ set({ balanceKeysForSorting: partial });
115
+ set({ partialPublished: true });
116
+ set({ sortingDataIsLoading: false });
117
+ }
118
+ }
119
+ }, { fireImmediately: true });
115
120
  }
116
121
  })));
117
- // Memoized selector to prevent unnecessary object creation
118
- let lastInitiatedBalances = null;
119
- let lastBalances = {};
120
- let memoizedResult = null;
121
- //Discuss with Babken M.
122
- export const selectResolvedInitiatedBalances = (state) => {
123
- const keys = state.initiatedBalances;
122
+ export const selectResolvedSortingBalances = (state) => {
123
+ const keys = state.balanceKeysForSorting;
124
124
  if (!keys)
125
125
  return null;
126
- // Only recalculate if initiatedBalances or balances have actually changed
127
- if (keys === lastInitiatedBalances && state.balances === lastBalances && memoizedResult) {
128
- return memoizedResult;
129
- }
130
- // Check if the actual data has changed, not just the object references
131
- if (lastInitiatedBalances && memoizedResult) {
132
- let hasChanged = false;
133
- // Check if keys are different
134
- const currentKeySet = Object.keys(keys);
135
- const lastKeySet = Object.keys(lastInitiatedBalances);
136
- if (currentKeySet.length !== lastKeySet.length ||
137
- !currentKeySet.every(k => lastKeySet.includes(k))) {
138
- hasChanged = true;
139
- }
140
- // Check if balance data has changed for existing keys
141
- if (!hasChanged) {
142
- for (const [_, key] of Object.entries(keys)) {
143
- const entry = state.balances[key];
144
- const lastEntry = lastBalances[key];
145
- if (entry?.data !== lastEntry?.data) {
146
- hasChanged = true;
147
- break;
148
- }
149
- }
150
- }
151
- if (!hasChanged) {
152
- return memoizedResult;
153
- }
154
- }
155
- // Recalculate the result
156
- const result = Object.entries(keys).reduce((acc, [networkName, key]) => {
126
+ const keysArray = Object.entries(keys);
127
+ const balanceData = keysArray.reduce((acc, [networkName, key]) => {
157
128
  const entry = state.balances[key];
158
129
  if (entry?.data)
159
130
  acc[networkName] = entry.data;
160
131
  return acc;
161
132
  }, {});
162
- // Update memoization cache
163
- lastInitiatedBalances = keys;
164
- lastBalances = state.balances;
165
- memoizedResult = result;
166
- return result;
133
+ return balanceData;
167
134
  };