@layerswap/widget 1.0.4 → 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.
- package/dist/esm/Models/Theme.js +44 -2
- package/dist/esm/components/Buttons/secondaryButton.js +1 -1
- package/dist/esm/components/ColorSchema.js +0 -1
- package/dist/esm/components/Input/Amount/Balance.js +2 -2
- package/dist/esm/components/Modal/vaulModal.js +1 -1
- package/dist/esm/components/Pages/Swap/Withdraw/Wallet/index.js +1 -1
- package/dist/esm/components/Widget/Index.js +1 -1
- package/dist/esm/context/balanceAccounts.js +1 -1
- package/dist/esm/hooks/useAllWithdrawalBalances.js +4 -4
- package/dist/esm/stores/balanceStore.js +44 -77
- package/dist/index.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Models/Theme.d.ts +0 -1
- package/dist/types/Models/Theme.d.ts.map +1 -1
- package/dist/types/components/ColorSchema.d.ts.map +1 -1
- package/dist/types/stores/balanceStore.d.ts +6 -4
- package/dist/types/stores/balanceStore.d.ts.map +1 -1
- package/dist/types/types/wallet.d.ts +1 -1
- package/dist/types/types/wallet.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/Models/Theme.js
CHANGED
|
@@ -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-
|
|
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
|
|
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" })] })
|
|
@@ -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:
|
|
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,
|
|
@@ -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]);
|
|
@@ -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
|
-
"
|
|
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 &&
|
|
@@ -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.
|
|
117
|
+
const balance = useBalanceStore((s) => (s.balances[balanceKey || "unknown"]));
|
|
118
118
|
return balance;
|
|
119
119
|
}
|
|
120
120
|
export function useUpdateBalanceAccount(direction) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSettingsState } from "../context/settings";
|
|
2
|
-
import {
|
|
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().
|
|
29
|
+
useBalanceStore.getState().initSortingBalances(walletNetworks);
|
|
30
30
|
}, [walletNetwokrsString]);
|
|
31
31
|
const lastBalancesRef = useRef(null);
|
|
32
|
-
const resolvedBalances = useBalanceStore(
|
|
33
|
-
const isLoading = useBalanceStore(s => s.
|
|
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,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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
163
|
-
lastInitiatedBalances = keys;
|
|
164
|
-
lastBalances = state.balances;
|
|
165
|
-
memoizedResult = result;
|
|
166
|
-
return result;
|
|
133
|
+
return balanceData;
|
|
167
134
|
};
|