@lifi/widget 2.0.0-beta.11 → 2.0.0-beta.13
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/cjs/components/SwapInput/FormPriceHelperText.d.ts +6 -0
- package/cjs/components/SwapInput/FormPriceHelperText.js +11 -5
- package/cjs/components/SwapInput/SwapInput.d.ts +9 -1
- package/cjs/components/SwapInput/SwapInput.js +25 -9
- package/cjs/components/TokenList/TokenListItem.js +1 -1
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useGasRecommendation.d.ts +1 -1
- package/cjs/hooks/useGasRecommendation.js +5 -0
- package/cjs/hooks/useTokens.js +21 -9
- package/cjs/i18n/id.json +24 -7
- package/cjs/i18n/it.json +38 -10
- package/cjs/i18n/pt.json +2 -2
- package/cjs/i18n/uk.json +2 -2
- package/cjs/i18n/vi.json +30 -5
- package/cjs/i18n/zh.json +26 -9
- package/cjs/types/events.d.ts +6 -6
- package/cjs/types/widget.d.ts +2 -1
- package/cjs/utils/format.d.ts +1 -1
- package/cjs/utils/format.js +13 -10
- package/components/SwapInput/FormPriceHelperText.d.ts +6 -0
- package/components/SwapInput/FormPriceHelperText.js +8 -3
- package/components/SwapInput/SwapInput.d.ts +9 -1
- package/components/SwapInput/SwapInput.js +26 -11
- package/components/TokenList/TokenListItem.js +1 -1
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useGasRecommendation.d.ts +1 -1
- package/hooks/useGasRecommendation.js +5 -0
- package/hooks/useTokens.js +21 -9
- package/i18n/id.json +24 -7
- package/i18n/it.json +38 -10
- package/i18n/pt.json +2 -2
- package/i18n/uk.json +2 -2
- package/i18n/vi.json +30 -5
- package/i18n/zh.json +26 -9
- package/package.json +3 -3
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +6 -6
- package/types/widget.d.ts +2 -1
- package/utils/format.d.ts +1 -1
- package/utils/format.js +13 -10
- package/cjs/components/SwapInput/FitInputText.d.ts +0 -3
- package/cjs/components/SwapInput/FitInputText.js +0 -19
- package/components/SwapInput/FitInputText.d.ts +0 -3
- package/components/SwapInput/FitInputText.js +0 -16
package/types/events.d.ts
CHANGED
|
@@ -6,12 +6,6 @@ export declare enum WidgetEvent {
|
|
|
6
6
|
RouteExecutionFailed = "routeExecutionFailed",
|
|
7
7
|
RouteHighValueLoss = "routeHighValueLoss"
|
|
8
8
|
}
|
|
9
|
-
export interface RouteHighValueLossUpdate {
|
|
10
|
-
fromAmountUsd: string;
|
|
11
|
-
gasCostUSD: string | undefined;
|
|
12
|
-
toAmountUSD: string;
|
|
13
|
-
valueLoss: string;
|
|
14
|
-
}
|
|
15
9
|
export type WidgetEvents = {
|
|
16
10
|
routeExecutionStarted: Route;
|
|
17
11
|
routeExecutionUpdated: RouteExecutionUpdate;
|
|
@@ -19,6 +13,12 @@ export type WidgetEvents = {
|
|
|
19
13
|
routeExecutionFailed: RouteExecutionUpdate;
|
|
20
14
|
routeHighValueLoss: RouteHighValueLossUpdate;
|
|
21
15
|
};
|
|
16
|
+
export interface RouteHighValueLossUpdate {
|
|
17
|
+
fromAmountUsd: string;
|
|
18
|
+
gasCostUSD?: string;
|
|
19
|
+
toAmountUSD: string;
|
|
20
|
+
valueLoss: string;
|
|
21
|
+
}
|
|
22
22
|
export interface RouteExecutionUpdate {
|
|
23
23
|
route: Route;
|
|
24
24
|
process: Process;
|
package/types/widget.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
2
|
-
import type { BaseToken, ChainKey, ConfigUpdate, Order, RouteOptions, StaticToken } from '@lifi/sdk';
|
|
2
|
+
import type { BaseToken, ChainKey, ConfigUpdate, Order, RouteOptions, StaticToken, Token } from '@lifi/sdk';
|
|
3
3
|
import type { Components, PaletteMode, PaletteOptions, Shape, Theme } from '@mui/material';
|
|
4
4
|
import type { TypographyOptions } from '@mui/material/styles/createTypography';
|
|
5
5
|
import type { CSSProperties, ReactNode, RefObject } from 'react';
|
|
@@ -103,6 +103,7 @@ export interface WidgetConfig {
|
|
|
103
103
|
};
|
|
104
104
|
tokens?: {
|
|
105
105
|
featured?: StaticToken[];
|
|
106
|
+
include?: Token[];
|
|
106
107
|
allow?: BaseToken[];
|
|
107
108
|
deny?: BaseToken[];
|
|
108
109
|
};
|
package/utils/format.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const formatTokenAmount: (amount?: string, decimals?: number, decimalPlaces?: number) => string;
|
|
7
7
|
export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string;
|
|
8
|
-
export declare const formatInputAmount: (amount: string, returnInitial?: boolean) => string;
|
|
8
|
+
export declare const formatInputAmount: (amount: string, decimals?: number | null, returnInitial?: boolean) => string;
|
|
9
9
|
export declare const formatTokenPrice: (amount?: string, price?: string) => number;
|
package/utils/format.js
CHANGED
|
@@ -21,7 +21,7 @@ export const formatTokenAmount = (amount = '0', decimals = 0, decimalPlaces = 3)
|
|
|
21
21
|
while (absAmount < 1 / 10 ** decimalPlaces) {
|
|
22
22
|
decimalPlaces++;
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return parsedAmount.toFixed(decimalPlaces + 1);
|
|
25
25
|
};
|
|
26
26
|
export const formatSlippage = (slippage = '', defaultValue = '', returnInitial = false) => {
|
|
27
27
|
if (!slippage) {
|
|
@@ -45,7 +45,7 @@ export const formatSlippage = (slippage = '', defaultValue = '', returnInitial =
|
|
|
45
45
|
}
|
|
46
46
|
return parsedSlippage.toString();
|
|
47
47
|
};
|
|
48
|
-
export const formatInputAmount = (amount, returnInitial = false) => {
|
|
48
|
+
export const formatInputAmount = (amount, decimals = null, returnInitial = false) => {
|
|
49
49
|
if (!amount) {
|
|
50
50
|
return amount;
|
|
51
51
|
}
|
|
@@ -57,16 +57,19 @@ export const formatInputAmount = (amount, returnInitial = false) => {
|
|
|
57
57
|
if (isNaN(Number(formattedAmount)) && !isNaN(parsedAmount)) {
|
|
58
58
|
return parsedAmount.toString();
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
const absFormattedAmount = Big(formattedAmount).abs();
|
|
62
|
-
if (returnInitial) {
|
|
63
|
-
return formattedAmount;
|
|
64
|
-
}
|
|
65
|
-
return absFormattedAmount.toString();
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
60
|
+
if (isNaN(Math.abs(Number(formattedAmount)))) {
|
|
68
61
|
return '';
|
|
69
62
|
}
|
|
63
|
+
if (returnInitial) {
|
|
64
|
+
return formattedAmount;
|
|
65
|
+
}
|
|
66
|
+
let [integer, fraction = ''] = formattedAmount.split('.');
|
|
67
|
+
if (decimals !== null && fraction.length > decimals) {
|
|
68
|
+
fraction = fraction.slice(0, decimals);
|
|
69
|
+
}
|
|
70
|
+
integer = integer.replace(/^0+|-/, '');
|
|
71
|
+
fraction = fraction.replace(/(0+)$/, '');
|
|
72
|
+
return `${integer || (fraction ? '0' : '')}${fraction ? `.${fraction}` : ''}`;
|
|
70
73
|
};
|
|
71
74
|
export const formatTokenPrice = (amount, price) => {
|
|
72
75
|
if (!amount || !price) {
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FitInputText = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
6
|
-
const providers_1 = require("../../providers");
|
|
7
|
-
const utils_1 = require("../../utils");
|
|
8
|
-
const SwapInput_style_1 = require("./SwapInput.style");
|
|
9
|
-
exports.FitInputText = (0, react_1.forwardRef)(({ formType }, ref) => {
|
|
10
|
-
const amountKey = providers_1.SwapFormKeyHelper.getAmountKey(formType);
|
|
11
|
-
const [amount] = (0, react_hook_form_1.useWatch)({
|
|
12
|
-
name: [amountKey],
|
|
13
|
-
});
|
|
14
|
-
(0, react_1.useLayoutEffect)(() => {
|
|
15
|
-
(0, utils_1.fitInputText)(SwapInput_style_1.maxInputFontSize, SwapInput_style_1.minInputFontSize, ref
|
|
16
|
-
.current);
|
|
17
|
-
}, [amount, ref]);
|
|
18
|
-
return null;
|
|
19
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useLayoutEffect } from 'react';
|
|
2
|
-
import { useWatch } from 'react-hook-form';
|
|
3
|
-
import { SwapFormKeyHelper } from '../../providers';
|
|
4
|
-
import { fitInputText } from '../../utils';
|
|
5
|
-
import { maxInputFontSize, minInputFontSize } from './SwapInput.style';
|
|
6
|
-
export const FitInputText = forwardRef(({ formType }, ref) => {
|
|
7
|
-
const amountKey = SwapFormKeyHelper.getAmountKey(formType);
|
|
8
|
-
const [amount] = useWatch({
|
|
9
|
-
name: [amountKey],
|
|
10
|
-
});
|
|
11
|
-
useLayoutEffect(() => {
|
|
12
|
-
fitInputText(maxInputFontSize, minInputFontSize, ref
|
|
13
|
-
.current);
|
|
14
|
-
}, [amount, ref]);
|
|
15
|
-
return null;
|
|
16
|
-
});
|