@layerswap/widget 0.1.17 → 0.1.20
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/components/Input/Amount/Balance.js +5 -6
- package/dist/components/Pages/SwapPages/Form/FeeDetails/DetailedEstimates.js +13 -5
- package/dist/components/Pages/SwapPages/Form/SecondaryComponents/ReserveGasNote.js +3 -3
- package/dist/components/Pages/SwapPages/Withdraw/Summary/Summary.js +1 -1
- package/dist/components/Pages/SwapPages/Withdraw/WalletTransferContent.js +4 -12
- package/dist/components/Wallet/WalletComponents/WalletsList.js +4 -11
- package/dist/components/utils/RoundDecimals.d.ts +1 -1
- package/dist/components/utils/RoundDecimals.js +6 -2
- package/dist/index.css +3 -0
- package/dist/lib/layerSwapApiClient.d.ts +1 -0
- package/package.json +1 -1
|
@@ -9,9 +9,9 @@ const Balance = ({ values, direction }) => {
|
|
|
9
9
|
const token = direction === 'from' ? fromCurrency : toCurrency;
|
|
10
10
|
const network = direction === 'from' ? from : to;
|
|
11
11
|
const address = direction === 'from' ? selectedSourceAccount?.address : destination_address;
|
|
12
|
-
const { balance, isBalanceLoading
|
|
12
|
+
const { balance, isBalanceLoading } = useSWRBalance(address, network);
|
|
13
13
|
const tokenBalance = balance?.find(b => b?.network === from?.name && b?.token === token?.symbol);
|
|
14
|
-
const truncatedBalance = tokenBalance?.amount
|
|
14
|
+
const truncatedBalance = tokenBalance?.amount !== undefined ? truncateDecimals(tokenBalance.amount, token?.precision) : '';
|
|
15
15
|
const previouslySelectedSource = useRef(from);
|
|
16
16
|
useEffect(() => {
|
|
17
17
|
previouslySelectedSource.current = from;
|
|
@@ -21,9 +21,8 @@ const Balance = ({ values, direction }) => {
|
|
|
21
21
|
previouslySelectedDestination.current = to;
|
|
22
22
|
}, [to, destination_address]);
|
|
23
23
|
if (isBalanceLoading)
|
|
24
|
-
return _jsx("div", { className: 'h-[10px] w-10 inline-flex bg-gray-500 rounded-sm animate-pulse' });
|
|
25
|
-
return (_jsx(_Fragment, { children:
|
|
26
|
-
(
|
|
27
|
-
_jsx("span", { children: truncatedBalance > 0 ? truncatedBalance.toFixed(token?.precision) : truncatedBalance }) }));
|
|
24
|
+
return _jsx("div", { className: 'h-[10px] w-10 inline-flex bg-gray-500 rounded-sm animate-pulse pl-2 ml-2' });
|
|
25
|
+
return (_jsx(_Fragment, { children: network && token && truncatedBalance &&
|
|
26
|
+
_jsx("span", { className: "pl-2", children: truncatedBalance }) }));
|
|
28
27
|
};
|
|
29
28
|
export default Balance;
|
|
@@ -2,19 +2,27 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { useFormikContext } from "formik";
|
|
3
3
|
import { useFee } from "../../../../../context/feeContext";
|
|
4
4
|
import AverageCompletionTime from "../../../../Common/AverageCompletionTime";
|
|
5
|
+
import { truncateDecimals } from "../../../../utils/RoundDecimals";
|
|
5
6
|
const DetailedEstimates = () => {
|
|
6
7
|
const { values } = useFormikContext();
|
|
7
8
|
const { fromCurrency } = values;
|
|
8
9
|
const { fee, isFeeLoading } = useFee();
|
|
9
|
-
const
|
|
10
|
-
const
|
|
10
|
+
const feeDiscount = fee?.quote?.fee_discount || 0;
|
|
11
|
+
const feeDiscountInUsd = feeDiscount * (fee?.quote.source_token?.price_in_usd || 0);
|
|
12
|
+
const fee_amount = fee?.quote.total_fee && fee.quote.total_fee - feeDiscount;
|
|
13
|
+
const fullFeeAmount = fee?.quote.total_fee || 0;
|
|
14
|
+
const fullParsedFeeAmount = fullFeeAmount && parseFloat(Number(fullFeeAmount).toFixed(fromCurrency?.precision));
|
|
15
|
+
const parsedFee = fee && truncateDecimals(Number(fee_amount), fromCurrency?.precision);
|
|
11
16
|
const currencyName = fromCurrency?.symbol || " ";
|
|
12
|
-
const feeAmountInUsd = fee?.quote.total_fee_in_usd;
|
|
13
|
-
const displayFee = parsedFee?.toFixed(fromCurrency?.precision);
|
|
17
|
+
const feeAmountInUsd = fee?.quote.total_fee_in_usd && (fee?.quote.total_fee_in_usd - feeDiscountInUsd);
|
|
14
18
|
const displayFeeInUsd = feeAmountInUsd ? (feeAmountInUsd < 0.01 ? '<$0.01' : `$${feeAmountInUsd?.toFixed(2)}`) : null;
|
|
15
19
|
return _jsxs("div", { className: "flex flex-col w-full gap-2", children: [fee && fee.quote.avg_completion_time !== '00:00:00' ?
|
|
16
20
|
_jsx("div", { className: "flex justify-between w-full items-center", children: _jsxs("div", { className: "flex items-baseline w-full justify-between gap-1", children: [_jsx("label", { className: "inline-flex items-center text-left text-primary-buttonTextColor", children: "Estimated time" }), _jsx("div", { className: "text-right text-secondary-text", children: _jsx(AverageCompletionTime, { avgCompletionTime: fee.quote.avg_completion_time }) })] }) })
|
|
17
21
|
:
|
|
18
|
-
_jsx(_Fragment, {}), _jsx("div", { className: "flex justify-between w-full items-center", children: _jsxs("div", { className: "flex items-baseline w-full justify-between gap-1", children: [_jsx("label", { className: "inline-flex items-center text-left text-primary-buttonTextColor", children: "Fee" }), _jsx("div", { className: "text-right text-secondary-text ", children: isFeeLoading ? (_jsx("div", { className: 'h-[10px] w-16 inline-flex bg-gray-500 rounded-sm animate-pulse' })) : (_jsxs("div", { children: [
|
|
22
|
+
_jsx(_Fragment, {}), _jsx("div", { className: "flex justify-between w-full items-center", children: _jsxs("div", { className: "flex items-baseline w-full justify-between gap-1", children: [_jsx("label", { className: "inline-flex items-center text-left text-primary-buttonTextColor", children: "Fee" }), _jsx("div", { className: "text-right text-secondary-text ", children: isFeeLoading ? (_jsx("div", { className: 'h-[10px] w-16 inline-flex bg-gray-500 rounded-sm animate-pulse' })) : (_jsxs("div", { children: [feeDiscount > 0 ?
|
|
23
|
+
_jsxs("span", { className: "ml-1", children: [_jsxs("span", { className: "line-through", children: [_jsx("span", { children: fullParsedFeeAmount || '-' }), " ", _jsx("span", { children: fee_amount == 0 ? currencyName : '' })] }), _jsxs("span", { className: "ml-1", children: [_jsx("span", { children: fee_amount && fee_amount > 0 ? parsedFee : 'Free' }), " ", _jsx("span", { children: fee_amount && fee_amount > 0 ? currencyName : '' })] })] })
|
|
24
|
+
:
|
|
25
|
+
_jsxs("span", { children: [parsedFee || '-', " "] }), _jsx("span", { children: (parsedFee && !feeDiscount) ? currencyName : '' }), displayFeeInUsd !== undefined && fee_amount ? (_jsxs("span", { className: "text-xs ml-1 font-medium", children: ["(", displayFeeInUsd, ")"] }))
|
|
26
|
+
: null] })) })] }) })] });
|
|
19
27
|
};
|
|
20
28
|
export default DetailedEstimates;
|
|
@@ -18,11 +18,11 @@ const ReserveGasNote = ({ onSubmit }) => {
|
|
|
18
18
|
&& minAllowedAmount
|
|
19
19
|
&& walletBalance.amount > minAllowedAmount
|
|
20
20
|
&& !(maxAllowedAmount && (walletBalance.amount > (maxAllowedAmount + networkGas))));
|
|
21
|
-
const gasToReserveFormatted = mightBeOutOfGas ? truncateDecimals(networkGas, values?.fromCurrency?.precision) :
|
|
22
|
-
return (_jsx(_Fragment, { children: mightBeOutOfGas && gasToReserveFormatted
|
|
21
|
+
const gasToReserveFormatted = mightBeOutOfGas ? truncateDecimals(networkGas, values?.fromCurrency?.precision) : '';
|
|
22
|
+
return (_jsx(_Fragment, { children: mightBeOutOfGas && gasToReserveFormatted &&
|
|
23
23
|
((Number(walletBalance.amount) < Number(networkGas)) ?
|
|
24
24
|
_jsx(WarningMessage, { messageType: "warning", className: "mt-4", children: _jsx("div", { className: "font-normal text-primary-text", children: "You don't have enough funds to cover gas fees." }) })
|
|
25
25
|
:
|
|
26
|
-
_jsx(WarningMessage, { messageType: "warning", className: "mt-4", children: _jsxs("div", { className: "font-normal text-primary-text", children: [_jsx("div", { children: "You might not be able to complete the transaction." }), _jsxs("div", { onClick: () => onSubmit(walletBalance, networkGas), className: "cursor-pointer border-b border-dotted border-primary-text w-fit hover:text-primary hover:border-primary text-primary-text", children: [_jsx("span", { children: "Reserve" }), " ", _jsx("span", { children: gasToReserveFormatted
|
|
26
|
+
_jsx(WarningMessage, { messageType: "warning", className: "mt-4", children: _jsxs("div", { className: "font-normal text-primary-text", children: [_jsx("div", { children: "You might not be able to complete the transaction." }), _jsxs("div", { onClick: () => onSubmit(walletBalance, networkGas), className: "cursor-pointer border-b border-dotted border-primary-text w-fit hover:text-primary hover:border-primary text-primary-text", children: [_jsx("span", { children: "Reserve" }), " ", _jsx("span", { children: gasToReserveFormatted }), " ", _jsx("span", { children: values?.fromCurrency?.symbol }), " ", _jsx("span", { children: "for gas." })] })] }) })) }));
|
|
27
27
|
};
|
|
28
28
|
export default ReserveGasNote;
|
|
@@ -20,7 +20,7 @@ const Summary = ({ sourceAccountAddress, sourceCurrency, destinationCurrency, so
|
|
|
20
20
|
const nativeCurrency = refuel?.token;
|
|
21
21
|
const truncatedRefuelAmount = nativeCurrency && !!refuel ?
|
|
22
22
|
truncateDecimals(refuel.amount, nativeCurrency?.precision) : null;
|
|
23
|
-
const refuelAmountInUsd = nativeCurrency && ((nativeCurrency?.price_in_usd || 1) * (truncatedRefuelAmount || 0)).toFixed(2);
|
|
23
|
+
const refuelAmountInUsd = nativeCurrency && ((nativeCurrency?.price_in_usd || 1) * (Number(truncatedRefuelAmount) || 0)).toFixed(2);
|
|
24
24
|
const destAddress = (hideAddress && hideTo && account) ? account : destinationAddress;
|
|
25
25
|
return (_jsx("div", { children: _jsxs("div", { className: "font-normal flex flex-col w-full relative z-10 space-y-4", children: [_jsxs("div", { className: "flex items-center justify-between w-full", children: [_jsxs("div", { className: "flex items-center gap-3", children: [sourceExchange ?
|
|
26
26
|
_jsx("img", { src: sourceExchange.logo, alt: sourceExchange.display_name, width: 32, height: 32, className: "rounded-lg" })
|
|
@@ -19,6 +19,7 @@ const WalletTransferContent = () => {
|
|
|
19
19
|
const { source_token, source_network: swap_source_network } = swap || {};
|
|
20
20
|
const source_network = swap_source_network && networks.find(n => n.name === swap_source_network?.name);
|
|
21
21
|
const { provider } = useWallet(source_network, 'withdrawal');
|
|
22
|
+
const availableWallets = provider?.connectedWallets?.filter(c => !c.isNotAvailable) || [];
|
|
22
23
|
const [openModal, setOpenModal] = useState(false);
|
|
23
24
|
const changeWallet = async (wallet, address) => {
|
|
24
25
|
provider?.switchAccount && provider.switchAccount(wallet, address);
|
|
@@ -34,15 +35,6 @@ const WalletTransferContent = () => {
|
|
|
34
35
|
address: activeWallet.address
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
|
-
else if (selectedSourceAccount && activeWallet && !activeWallet.addresses.some(a => a.toLowerCase() === selectedSourceAccount.address.toLowerCase())) {
|
|
38
|
-
const selectedWalletIsConnected = provider.connectedWallets?.some(w => w.addresses.some(a => a.toLowerCase() === selectedSourceAccount.address.toLowerCase()));
|
|
39
|
-
if (selectedWalletIsConnected) {
|
|
40
|
-
provider.switchAccount && provider.switchAccount(selectedSourceAccount.wallet, selectedSourceAccount.address);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
setSelectedSourceAccount(undefined);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
38
|
}, [activeWallet?.address, setSelectedSourceAccount, provider, selectedSourceAccount?.address]);
|
|
47
39
|
const { balance, isBalanceLoading } = useSWRBalance(selectedSourceAccount?.address, source_network);
|
|
48
40
|
const walletBalance = source_network && balance?.find(b => b?.network === source_network?.name && b?.token === source_token?.symbol);
|
|
@@ -59,10 +51,10 @@ const WalletTransferContent = () => {
|
|
|
59
51
|
}
|
|
60
52
|
return _jsxs(_Fragment, { children: [_jsx("div", { className: "grid content-end", children: selectedWallet &&
|
|
61
53
|
source_network &&
|
|
62
|
-
_jsxs("div", { onClick: () => setOpenModal(true), className: "cursor-pointer group/addressItem flex rounded-lg justify-between space-x-3 items-center shadow-sm mt-1.5 text-primary-text bg-secondary-700 border-secondary-500 border disabled:cursor-not-allowed h-12 leading-4 font-medium w-full px-3 py-7", children: [_jsx(AddressWithIcon, { addressItem: { address: accountAddress, group: AddressGroup.ConnectedWallet }, connectedWallet: selectedWallet, network: source_network, balance: (walletBalanceAmount
|
|
54
|
+
_jsxs("div", { onClick: () => setOpenModal(true), className: "cursor-pointer group/addressItem flex rounded-lg justify-between space-x-3 items-center shadow-sm mt-1.5 text-primary-text bg-secondary-700 border-secondary-500 border disabled:cursor-not-allowed h-12 leading-4 font-medium w-full px-3 py-7", children: [_jsx(AddressWithIcon, { addressItem: { address: accountAddress, group: AddressGroup.ConnectedWallet }, connectedWallet: selectedWallet, network: source_network, balance: (walletBalanceAmount && source_token) ? { amount: Number(walletBalanceAmount), symbol: source_token?.symbol, isLoading: isBalanceLoading } : undefined }), _jsx(ChevronRight, { className: "h-4 w-4" })] }) }), source_network &&
|
|
63
55
|
source_token &&
|
|
64
56
|
provider &&
|
|
65
|
-
|
|
66
|
-
_jsx(VaulDrawer, { show: openModal, setShow: setOpenModal, header: `Send from`, modalId: "connectedWallets", children: _jsx(VaulDrawer.Snap, { id: 'item-1', children: _jsx(WalletsList, { network: source_network, token: source_token, onSelect: changeWallet, selectable: true, wallets:
|
|
57
|
+
availableWallets &&
|
|
58
|
+
_jsx(VaulDrawer, { show: openModal, setShow: setOpenModal, header: `Send from`, modalId: "connectedWallets", children: _jsx(VaulDrawer.Snap, { id: 'item-1', children: _jsx(WalletsList, { network: source_network, token: source_token, onSelect: changeWallet, selectable: true, wallets: availableWallets, provider: provider }) }) })] });
|
|
67
59
|
};
|
|
68
60
|
export default WalletTransferContent;
|
|
@@ -29,7 +29,7 @@ export const WalletItem = ({ selectable, wallet, network, onWalletSelect, token,
|
|
|
29
29
|
const { balance, isBalanceLoading } = useSWRBalance(wallet.address, networkWithTokens);
|
|
30
30
|
const walletBalance = balance?.find(b => b?.token === token?.symbol);
|
|
31
31
|
const isSelected = selectable && (wallet.addresses.length == 1 && wallet.address == selectedAddress);
|
|
32
|
-
const walletBalanceAmount = walletBalance?.amount
|
|
32
|
+
const walletBalanceAmount = walletBalance?.amount !== undefined ? truncateDecimals(walletBalance.amount, token?.precision) : '';
|
|
33
33
|
return (_jsxs("div", { ...props, className: "rounded-md outline-none text-primary-tex", children: [_jsxs("div", { onClick: () => (selectable && wallet.addresses.length == 1 && onWalletSelect) && onWalletSelect(wallet, wallet.address), className: clsx('w-full relative items-center justify-between gap-2 flex rounded-lg outline-none bg-secondary-700 text-primary-text p-3 group/addressItem', {
|
|
34
34
|
'hover:bg-secondary-600 cursor-pointer': selectable && wallet.addresses.length == 1,
|
|
35
35
|
'bg-secondary-800 py-2': wallet.addresses.length > 1
|
|
@@ -41,7 +41,7 @@ export const WalletItem = ({ selectable, wallet, network, onWalletSelect, token,
|
|
|
41
41
|
:
|
|
42
42
|
_jsxs("div", { className: "w-full inline-flex items-center justify-between grow", children: [_jsxs("div", { children: [!wallet.isLoading && wallet.address &&
|
|
43
43
|
_jsx(ExtendedAddress, { address: wallet.address, network: network, addressClassNames: "font-normal text-sm", onDisconnect: () => wallet && wallet.disconnect() }), _jsx("p", { className: "text-xs text-secondary-text", children: wallet.displayName })] }), walletBalanceAmount !== undefined && token &&
|
|
44
|
-
_jsx("span", { className: "text-sm flex space-x-2 justif-end", children: walletBalanceAmount
|
|
44
|
+
_jsx("span", { className: "text-sm flex space-x-2 justif-end", children: walletBalanceAmount ?
|
|
45
45
|
_jsx("div", { className: "text-right text-secondary-text font-normal text-sm", children: isBalanceLoading ?
|
|
46
46
|
_jsx("div", { className: 'h-[14px] w-20 inline-flex bg-gray-500 rounded-sm animate-pulse' })
|
|
47
47
|
:
|
|
@@ -58,18 +58,11 @@ const NestedWalletAddress = ({ selectable, address, network, onWalletSelect, tok
|
|
|
58
58
|
const { balance, isBalanceLoading } = useSWRBalance(address, networkWithTokens);
|
|
59
59
|
const isNestedSelected = selectable && address == selectedAddress;
|
|
60
60
|
const nestedWalletBalance = balance?.find(b => b?.token === token?.symbol);
|
|
61
|
-
const nestedWalletBalanceAmount = nestedWalletBalance?.amount
|
|
61
|
+
const nestedWalletBalanceAmount = nestedWalletBalance?.amount !== undefined ? truncateDecimals(nestedWalletBalance.amount, token?.precision) : '';
|
|
62
62
|
return (_jsxs("div", { ...props, onClick: () => (selectable && onWalletSelect) && onWalletSelect(wallet, address), className: clsx('flex w-full justify-between gap-3 items-center pl-6 pr-4 py-2 group/addressItem', {
|
|
63
63
|
'hover:bg-secondary-600 cursor-pointer': selectable
|
|
64
64
|
}), children: [_jsxs("div", { className: 'flex items-center w-fit gap-3', children: [_jsx("div", { className: "flex bg-secondary-400 items-center justify-center rounded-md h-8 w-8 overflow-hidden", children: _jsx(AddressIcon, { className: "scale-150 h-8 w-8 p-0.5", address: address, size: 32 }) }), _jsx("div", { children: !wallet.isLoading && address &&
|
|
65
|
-
_jsx(ExtendedAddress, { address: address, network: network, addressClassNames: "font-normal text-sm", onDisconnect: () => wallet && wallet.disconnect() }) })] }), _jsxs("div", { className: "inline-flex gap-2", children: [nestedWalletBalanceAmount
|
|
66
|
-
_jsx("span", { className: "text-sm flex space-x-2 justif-end", children: nestedWalletBalanceAmount != undefined && !isNaN(nestedWalletBalanceAmount) ?
|
|
67
|
-
_jsx("div", { className: "text-right text-secondary-text font-normal text-sm", children: isBalanceLoading ?
|
|
68
|
-
_jsx("div", { className: 'h-[14px] w-20 inline-flex bg-gray-500 rounded-sm animate-pulse' })
|
|
69
|
-
:
|
|
70
|
-
_jsxs(_Fragment, { children: [_jsx("span", { children: nestedWalletBalanceAmount }), " ", _jsx("span", { children: token?.symbol })] }) })
|
|
71
|
-
:
|
|
72
|
-
_jsx(_Fragment, {}) }), isNestedSelected &&
|
|
65
|
+
_jsx(ExtendedAddress, { address: address, network: network, addressClassNames: "font-normal text-sm", onDisconnect: () => wallet && wallet.disconnect() }) })] }), _jsxs("div", { className: "inline-flex gap-2", children: [nestedWalletBalanceAmount && token && (_jsx("span", { className: "text-sm flex space-x-2 justify-end", children: _jsx("div", { className: "text-right text-secondary-text font-normal text-sm", children: isBalanceLoading ? (_jsx("div", { className: "h-[14px] w-20 inline-flex bg-gray-500 rounded-sm animate-pulse" })) : (_jsxs(_Fragment, { children: [_jsx("span", { children: nestedWalletBalanceAmount }), " ", _jsx("span", { children: token?.symbol })] })) }) })), isNestedSelected &&
|
|
73
66
|
_jsx("div", { className: "flex h-6 items-center", children: _jsx(FilledCheck, {}) })] })] }));
|
|
74
67
|
};
|
|
75
68
|
export default WalletsList;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function roundDecimals(value: number, decimals: number): number;
|
|
2
|
-
export declare function truncateDecimals(value: number, decimals?: number):
|
|
2
|
+
export declare function truncateDecimals(value: number, decimals?: number): string | 0;
|
|
3
3
|
export declare function truncateDecimalsToFloor(number: number, decimalPlaces: number): number;
|
|
4
4
|
export declare function findIndexOfFirstNonZeroAfterComma(number: any): number | null;
|
|
@@ -4,8 +4,12 @@ export function roundDecimals(value, decimals) {
|
|
|
4
4
|
}
|
|
5
5
|
return Number(Math.ceil(Number(value + 'e' + decimals)) + 'e-' + decimals);
|
|
6
6
|
}
|
|
7
|
-
export function truncateDecimals(value, decimals) {
|
|
8
|
-
|
|
7
|
+
export function truncateDecimals(value, decimals = 0) {
|
|
8
|
+
if (value == 0)
|
|
9
|
+
return 0;
|
|
10
|
+
const factor = Math.pow(10, decimals);
|
|
11
|
+
const truncated = Math.trunc(value * factor) / factor;
|
|
12
|
+
return truncated.toFixed(decimals).replace(/\.?0+$/, '');
|
|
9
13
|
}
|
|
10
14
|
export function truncateDecimalsToFloor(number, decimalPlaces) {
|
|
11
15
|
let factor = Math.pow(10, decimalPlaces);
|
package/dist/index.css
CHANGED
|
@@ -2950,6 +2950,9 @@ Constrain images and videos to the parent width and preserve their intrinsic asp
|
|
|
2950
2950
|
.layerswap-styles .underline {
|
|
2951
2951
|
text-decoration-line: underline;
|
|
2952
2952
|
}
|
|
2953
|
+
.layerswap-styles .line-through {
|
|
2954
|
+
text-decoration-line: line-through;
|
|
2955
|
+
}
|
|
2953
2956
|
.layerswap-styles .no-underline {
|
|
2954
2957
|
text-decoration-line: none;
|
|
2955
2958
|
}
|
package/package.json
CHANGED