@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.
Files changed (46) hide show
  1. package/cjs/components/SwapInput/FormPriceHelperText.d.ts +6 -0
  2. package/cjs/components/SwapInput/FormPriceHelperText.js +11 -5
  3. package/cjs/components/SwapInput/SwapInput.d.ts +9 -1
  4. package/cjs/components/SwapInput/SwapInput.js +25 -9
  5. package/cjs/components/TokenList/TokenListItem.js +1 -1
  6. package/cjs/config/version.d.ts +1 -1
  7. package/cjs/config/version.js +1 -1
  8. package/cjs/hooks/useGasRecommendation.d.ts +1 -1
  9. package/cjs/hooks/useGasRecommendation.js +5 -0
  10. package/cjs/hooks/useTokens.js +21 -9
  11. package/cjs/i18n/id.json +24 -7
  12. package/cjs/i18n/it.json +38 -10
  13. package/cjs/i18n/pt.json +2 -2
  14. package/cjs/i18n/uk.json +2 -2
  15. package/cjs/i18n/vi.json +30 -5
  16. package/cjs/i18n/zh.json +26 -9
  17. package/cjs/types/events.d.ts +6 -6
  18. package/cjs/types/widget.d.ts +2 -1
  19. package/cjs/utils/format.d.ts +1 -1
  20. package/cjs/utils/format.js +13 -10
  21. package/components/SwapInput/FormPriceHelperText.d.ts +6 -0
  22. package/components/SwapInput/FormPriceHelperText.js +8 -3
  23. package/components/SwapInput/SwapInput.d.ts +9 -1
  24. package/components/SwapInput/SwapInput.js +26 -11
  25. package/components/TokenList/TokenListItem.js +1 -1
  26. package/config/version.d.ts +1 -1
  27. package/config/version.js +1 -1
  28. package/hooks/useGasRecommendation.d.ts +1 -1
  29. package/hooks/useGasRecommendation.js +5 -0
  30. package/hooks/useTokens.js +21 -9
  31. package/i18n/id.json +24 -7
  32. package/i18n/it.json +38 -10
  33. package/i18n/pt.json +2 -2
  34. package/i18n/uk.json +2 -2
  35. package/i18n/vi.json +30 -5
  36. package/i18n/zh.json +26 -9
  37. package/package.json +3 -3
  38. package/tsconfig.cjs.tsbuildinfo +1 -1
  39. package/types/events.d.ts +6 -6
  40. package/types/widget.d.ts +2 -1
  41. package/utils/format.d.ts +1 -1
  42. package/utils/format.js +13 -10
  43. package/cjs/components/SwapInput/FitInputText.d.ts +0 -3
  44. package/cjs/components/SwapInput/FitInputText.js +0 -19
  45. package/components/SwapInput/FitInputText.d.ts +0 -3
  46. package/components/SwapInput/FitInputText.js +0 -16
package/cjs/i18n/vi.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "button": {
3
3
  "auto": "Tự động",
4
+ "buy": "Mua",
5
+ "buyNow": "Mua ngay bây giờ",
4
6
  "cancel": "Huỷ bỏ",
5
7
  "connectWallet": "Kết nối ví",
6
8
  "contactSupport": "Liên hệ hỗ trợ",
@@ -12,6 +14,7 @@
12
14
  "done": "Hoàn thành",
13
15
  "getGas": "Thiết lập gas",
14
16
  "hide": "Ẩn",
17
+ "learnMore": "Xem thêm",
15
18
  "lifiSwap": "LI.FI Swap",
16
19
  "light": "Sáng",
17
20
  "max": "Tối đa",
@@ -22,6 +25,7 @@
22
25
  "resetSettings": "Đặt lại cài đặt",
23
26
  "restartSwap": "Thiết lập lại",
24
27
  "reviewGasSwap": "Xem lại gas swap",
28
+ "reviewPurchase": "Đánh giá thanh toán",
25
29
  "reviewSwap": "Xem lại Swap",
26
30
  "seeDetails": "Xem chi tiết",
27
31
  "showAll": "Hiển thị tất cả",
@@ -29,6 +33,7 @@
29
33
  "startSwap": "Bắt đầu Swap",
30
34
  "swap": "Swap",
31
35
  "tryAgain": "Thử lại",
36
+ "viewCoverage": "Xem phạm vi bảo hiểm",
32
37
  "viewOnExplorer": "Xem tại Explorer"
33
38
  },
34
39
  "format": {
@@ -37,10 +42,14 @@
37
42
  },
38
43
  "header": {
39
44
  "activeSwaps": "Active swaps",
45
+ "bridge": "Bridge",
40
46
  "checkout": "Thanh toán",
41
47
  "from": "Swap từ",
42
48
  "gas": "Gas",
43
49
  "gasSwap": "Gas swap",
50
+ "payWith": "Thanh toán bằng",
51
+ "purchase": "Thanh toán",
52
+ "purchaseDetails": "Thông tin chi tiết",
44
53
  "routes": "Kết quả",
45
54
  "selectChain": "Chọn chain",
46
55
  "selectWallet": "Chọn ví",
@@ -73,6 +82,8 @@
73
82
  "currentAmount": "Số lượng hiện tại",
74
83
  "error": {
75
84
  "message": {
85
+ "allowanceRequired": "Chuyển số lượng {{tokenSymbol}} vượt quá mức cho phép hiện tại của bạn. Vui lòng tăng mức độ cho phép sử dụng token và thử lại.",
86
+ "insufficientFunds": "Bạn không có đủ gas để chi trả cho chi phí giao dịch.",
76
87
  "slippageThreshold": "Độ trượt giá lớn hơn ngưỡng xác định. Vui lòng yêu cầu một tuyến đường mới để nhận báo giá mới.",
77
88
  "transactionFailed": "Vui lòng kiểm tra block explorer để biết thêm thông tin.",
78
89
  "transactionNotSent": "Giao dịch chưa được gửi. {{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} tại {{chainName}} vẫn còn trong ví của bạn.",
@@ -80,10 +91,12 @@
80
91
  "unknown": "Vui lòng thử lại hoặc liên hệ hỗ trợ."
81
92
  },
82
93
  "title": {
94
+ "allowanceRequired": "Sự cho phép không đủ",
83
95
  "balanceIsTooLow": "Số dư quá thấp",
84
96
  "chainSwitch": "Yêu cầu đổi chain",
85
97
  "failed": "Việc Swap thất bại",
86
98
  "gasLimitIsTooLow": "Giới hạn gas quá thấp",
99
+ "insufficientFunds": "Không đủ tài sản",
87
100
  "slippageNotMet": "Điều kiện trượt giá không được đáp ứng",
88
101
  "transactionCanceled": "Giao dịch bị huỷ",
89
102
  "transactionFailed": "Giao dịch không thành công",
@@ -104,6 +117,12 @@
104
117
  "gasFeeEstimated": "phí Gas ước tính",
105
118
  "gasFeePaid": "phí Gas đã trả",
106
119
  "inProgress": "đang xử lý",
120
+ "insurance": {
121
+ "bridgeExploits": "Cầu trục trặc, bị hack hoặc bị khai thác",
122
+ "insure": "Bảo hiểm <strong>{{amount, number(maximumFractionDigits: 9)}}{{tokenSymbol}}</strong> trong quá trình vận chuyển.",
123
+ "insured": "Bạn đã bảo hiểm <strong>{{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}}</strong> trong quá trình vận chuyển:",
124
+ "slippageError": "Lỗi trượt giá đối với token nhận được"
125
+ },
107
126
  "info": {
108
127
  "message": {
109
128
  "autoRefuel": "Gas trên {{chainName}} chain của bạn đang thấp. Để tiếp tục, bạn nên có thêm gas để hoàn thành việc swap.",
@@ -123,7 +142,6 @@
123
142
  "onChain": "tại {{chainName}}",
124
143
  "otherTokens": "Token khác",
125
144
  "ownedBy": "Được sở hữu bởi",
126
- "payWith": "Trả bằng",
127
145
  "process": {
128
146
  "crossChain": {
129
147
  "actionRequired": "Vui lòng ký hoàn thành giao dịch",
@@ -131,6 +149,9 @@
131
149
  "pending": "Chờ giao dịch Bridge",
132
150
  "started": "Chuẩn bị giao dịch Bridge"
133
151
  },
152
+ "nft": {
153
+ "done": "NFT đã mua"
154
+ },
134
155
  "receivingChain": {
135
156
  "done": "Bridge thành công",
136
157
  "partial": "Bridge thành công 1 phần",
@@ -157,24 +178,27 @@
157
178
  "rateChange": "Thay đổi tỉ giá",
158
179
  "receiving": "Đang nhận",
159
180
  "refuelStepDetails": "Lấy gas thông qua {{tool}}",
160
- "routes": "Bạn nhận",
161
- "selectChain": "Chain",
181
+ "selectChain": "Chọn chain",
162
182
  "selectChainAndToken": "Chọn chain và token",
163
- "selectToken": "Token",
183
+ "selectToken": "Chọn Token",
164
184
  "sendToAddress": "Gửi đến {{address}}",
165
185
  "sendToWallet": "Gửi đến địa chỉ khác",
166
186
  "sentToAddress": "Gửi đến {{address}}",
167
187
  "stepBridge": "Bridge",
188
+ "stepBridgeAndBuy": "Chuyển và mua",
168
189
  "stepDetails": "{{tool}} thông qua LI.FI",
169
190
  "stepSwap": "Swap",
170
191
  "stepSwapAndBridge": "Swap và Bridge",
192
+ "stepSwapAndBuy": "Hoán đổi và mua",
171
193
  "success": {
172
194
  "message": {
173
195
  "swapPartiallySuccessful": "Chúng tôi đã cố gắng hoàn thành việc hoán đổi, nhưng {{tool}} đã cạn thanh khoản cho token {{tokenSymbol}}.",
196
+ "purchaseSuccessful": "Hiện tại bạn đang nắm giữ {{assetName}} tại ví {{walletAddress}} trên chain {{chainName}}.",
174
197
  "swapSuccessful": "Hiện tại {{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} trong ví {{walletAddress}} tại {{chainName}} chain."
175
198
  },
176
199
  "title": {
177
200
  "gasSwapSuccessful": "Gas Swap thành công",
201
+ "purchaseSuccessful": "Mua thành công",
178
202
  "refundIssued": "Đã Refund",
179
203
  "swapPartiallySuccessful": "Swap thành công một phần",
180
204
  "swapSuccessful": "Swap thành công"
@@ -195,7 +219,7 @@
195
219
  "to": "Đến",
196
220
  "tokenOnChain": "{{tokenSymbol}} tại {{chainName}}",
197
221
  "tokenOnChainAmount": "{{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} tại {{chainName}}",
198
- "tokenSearch": "Tìm kiếm token",
222
+ "tokenSearch": "Tìm kiếm bằng tên token hoặc địa chỉ",
199
223
  "valueLoss": "Bạn sẽ mất",
200
224
  "walletAddressOrEns": "Địa chỉ hoặc tên miền ENS",
201
225
  "warning": {
@@ -229,6 +253,7 @@
229
253
  },
230
254
  "numberOfSteps": "Một số bước swap. Mỗi bước có thể chứa 1-2 giao dịch yêu cầu chữ ký.",
231
255
  "progressToNextUpdate": "Thông tin hiển thị sẽ tự động làm mới sau {{value}} giây. Bấm vào đây để cập nhật thủ công.",
256
+ "recommended": "Một tuyến đường giá rẻ cân bằng giữa sự phức tạp và dễ sử dụng.",
232
257
  "settingsModified": "Thiết lập (Đã điều chỉnh)"
233
258
  },
234
259
  "wallet": {
package/cjs/i18n/zh.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "button": {
3
3
  "auto": "自动",
4
+ "buy": "购买",
5
+ "buyNow": "立即购买",
4
6
  "cancel": "取消",
5
7
  "connectWallet": "关联钱包",
6
8
  "contactSupport": "联系技术支持",
@@ -23,6 +25,7 @@
23
25
  "resetSettings": "恢复默认设置",
24
26
  "restartSwap": "重新兑换",
25
27
  "reviewGasSwap": "查看燃气费兑换",
28
+ "reviewPurchase": "审查购买",
26
29
  "reviewSwap": "查看该兑换",
27
30
  "seeDetails": "查看详情",
28
31
  "showAll": "显示所有",
@@ -39,10 +42,14 @@
39
42
  },
40
43
  "header": {
41
44
  "activeSwaps": "正在进行的兑换",
45
+ "bridge": "跨链",
42
46
  "checkout": "支付",
43
47
  "from": "兑换自",
44
48
  "gas": "燃气费",
45
49
  "gasSwap": "燃气费兑换",
50
+ "payWith": "支付方式",
51
+ "purchase": "购买",
52
+ "purchaseDetails": "交易明细",
46
53
  "routes": "您获得",
47
54
  "selectChain": "选择网络",
48
55
  "selectWallet": "选择你的钱包",
@@ -75,6 +82,8 @@
75
82
  "currentAmount": "当前余额",
76
83
  "error": {
77
84
  "message": {
85
+ "allowanceRequired": "{{tokenSymbol}} 的转账金额超过了您设置的支出上限。请提高该代币的支出上限,然后重试。",
86
+ "insufficientFunds": "您没有足够的燃气费支付该交易。",
78
87
  "slippageThreshold": "滑点大于预设值,请选择其他路由并获取新的价格。",
79
88
  "transactionFailed": "请查看区块浏览器以了解更多信息。",
80
89
  "transactionNotSent": "交易未发送,不用担心,{{chainName}} 链上{{amount, number(maximumFractionDigits: 9)}} 个{{tokenSymbol}} 仍在您的钱包里。",
@@ -82,10 +91,12 @@
82
91
  "unknown": "请再试一次或者联系支持。"
83
92
  },
84
93
  "title": {
94
+ "allowanceRequired": "余额不足",
85
95
  "balanceIsTooLow": "余额太低",
86
96
  "chainSwitch": "请切换当前网络",
87
97
  "failed": "兑换失败",
88
98
  "gasLimitIsTooLow": "燃气费设置过低",
99
+ "insufficientFunds": "资金不足",
89
100
  "slippageNotMet": "滑点未满足",
90
101
  "transactionCanceled": "交易取消",
91
102
  "transactionFailed": "交易失败",
@@ -108,8 +119,8 @@
108
119
  "inProgress": "进行中",
109
120
  "insurance": {
110
121
  "bridgeExploits": "跨链桥故障、被黑或者被利用漏洞",
111
- "insure": "为跨链代币提供100%的保障",
112
- "insured": "您已经对100%的跨链代币投保:",
122
+ "insure": "在跨链期间为<strong>{{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}}</strong> 投保。",
123
+ "insured": "在跨链期间为<strong>{{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}}</strong> 投保。",
113
124
  "slippageError": "目标链代币的滑点错误"
114
125
  },
115
126
  "info": {
@@ -131,7 +142,6 @@
131
142
  "onChain": "在{{chainName}} 上",
132
143
  "otherTokens": "其他代币",
133
144
  "ownedBy": "属于",
134
- "payWith": "付款方式为",
135
145
  "process": {
136
146
  "crossChain": {
137
147
  "actionRequired": "请签署此交易",
@@ -139,6 +149,9 @@
139
149
  "pending": "跨链交易进行中",
140
150
  "started": "准备执行跨链交易"
141
151
  },
152
+ "nft": {
153
+ "done": "NFT 已购买"
154
+ },
142
155
  "receivingChain": {
143
156
  "done": "跨链完成",
144
157
  "partial": "跨链部分完成",
@@ -165,24 +178,27 @@
165
178
  "rateChange": "波动率",
166
179
  "receiving": "接收",
167
180
  "refuelStepDetails": "通过 {{tool}} 获取燃气费",
168
- "routes": "你会收到",
169
- "selectChain": "网络",
181
+ "selectChain": "选择网络",
170
182
  "selectChainAndToken": "选择链和代币",
171
- "selectToken": "代币",
183
+ "selectToken": "选择代币",
172
184
  "sendToAddress": "发送到{{address}}",
173
185
  "sendToWallet": "发送到另外的钱包",
174
186
  "sentToAddress": "发送到{{address}}",
175
187
  "stepBridge": "跨链",
188
+ "stepBridgeAndBuy": "跨链并购买",
176
189
  "stepDetails": "通过 LI.FI {{tool}}",
177
190
  "stepSwap": "兑换",
178
191
  "stepSwapAndBridge": "兑换和跨链",
192
+ "stepSwapAndBuy": "兑换并购买",
179
193
  "success": {
180
194
  "message": {
181
195
  "swapPartiallySuccessful": "我们试图完成兑换,但 {{tool}} 的 {{tokenSymbol}} 代币流动性不足。",
196
+ "purchaseSuccessful": "您的 {{walletAddress}} 钱包在 {{chainName}} 链上拥有该 {{assetName}} 财产",
182
197
  "swapSuccessful": "现在有 {{amount, number(maximumFractionDigits: 9)}} 个{{tokenSymbol}} 在{{chainName}} 链上的{{walletAddress}} 钱包里。"
183
198
  },
184
199
  "title": {
185
200
  "gasSwapSuccessful": "燃气费兑换成功",
201
+ "purchaseSuccessful": "购买成功",
186
202
  "refundIssued": "退款已受理",
187
203
  "swapPartiallySuccessful": "兑换部分完成",
188
204
  "swapSuccessful": "兑换成功"
@@ -194,16 +210,16 @@
194
210
  "tags": {
195
211
  "cheapest": "便宜的",
196
212
  "fastest": "快速的",
197
- "insurable": "可保性",
213
+ "insurable": "可投保",
198
214
  "insurance": "保险",
199
- "insured": "受保的",
215
+ "insured": "受保中",
200
216
  "recommended": "建议的",
201
217
  "safest": "最佳/安全"
202
218
  },
203
219
  "to": "到",
204
220
  "tokenOnChain": "{{chainName}}链上的{{tokenSymbol}}",
205
221
  "tokenOnChainAmount": "{{chainName}} 链上{{amount, number(maximumFractionDigits: 9)}} 个{{tokenSymbol}}",
206
- "tokenSearch": "搜索代币",
222
+ "tokenSearch": "按代币名称或者地址搜索",
207
223
  "valueLoss": "资金损失",
208
224
  "walletAddressOrEns": "钱包地址或ENS名称",
209
225
  "warning": {
@@ -237,6 +253,7 @@
237
253
  },
238
254
  "numberOfSteps": "一系列的兑换步骤,每个步骤可能包含1-2个需要签名的交易。",
239
255
  "progressToNextUpdate": "数据将在{{value}} 秒后自动刷新,点击这里可以手动更新。",
256
+ "recommended": "一个价格低廉但是兼顾复杂性和易用性的路由方案。",
240
257
  "settingsModified": "设置(已修改)"
241
258
  },
242
259
  "wallet": {
@@ -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;
@@ -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
  };
@@ -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;
@@ -24,7 +24,7 @@ const formatTokenAmount = (amount = '0', decimals = 0, decimalPlaces = 3) => {
24
24
  while (absAmount < 1 / 10 ** decimalPlaces) {
25
25
  decimalPlaces++;
26
26
  }
27
- return (0, big_js_1.default)(parsedAmount).toFixed(decimalPlaces + 1, 0);
27
+ return parsedAmount.toFixed(decimalPlaces + 1);
28
28
  };
29
29
  exports.formatTokenAmount = formatTokenAmount;
30
30
  const formatSlippage = (slippage = '', defaultValue = '', returnInitial = false) => {
@@ -50,7 +50,7 @@ const formatSlippage = (slippage = '', defaultValue = '', returnInitial = false)
50
50
  return parsedSlippage.toString();
51
51
  };
52
52
  exports.formatSlippage = formatSlippage;
53
- const formatInputAmount = (amount, returnInitial = false) => {
53
+ const formatInputAmount = (amount, decimals = null, returnInitial = false) => {
54
54
  if (!amount) {
55
55
  return amount;
56
56
  }
@@ -62,16 +62,19 @@ const formatInputAmount = (amount, returnInitial = false) => {
62
62
  if (isNaN(Number(formattedAmount)) && !isNaN(parsedAmount)) {
63
63
  return parsedAmount.toString();
64
64
  }
65
- try {
66
- const absFormattedAmount = (0, big_js_1.default)(formattedAmount).abs();
67
- if (returnInitial) {
68
- return formattedAmount;
69
- }
70
- return absFormattedAmount.toString();
71
- }
72
- catch {
65
+ if (isNaN(Math.abs(Number(formattedAmount)))) {
73
66
  return '';
74
67
  }
68
+ if (returnInitial) {
69
+ return formattedAmount;
70
+ }
71
+ let [integer, fraction = ''] = formattedAmount.split('.');
72
+ if (decimals !== null && fraction.length > decimals) {
73
+ fraction = fraction.slice(0, decimals);
74
+ }
75
+ integer = integer.replace(/^0+|-/, '');
76
+ fraction = fraction.replace(/(0+)$/, '');
77
+ return `${integer || (fraction ? '0' : '')}${fraction ? `.${fraction}` : ''}`;
75
78
  };
76
79
  exports.formatInputAmount = formatInputAmount;
77
80
  const formatTokenPrice = (amount, price) => {
@@ -1,3 +1,9 @@
1
1
  /// <reference types="react" />
2
+ import type { TokenAmount } from '@lifi/sdk';
2
3
  import type { SwapFormTypeProps } from '../../providers';
3
4
  export declare const FormPriceHelperText: React.FC<SwapFormTypeProps>;
5
+ export declare const FormPriceHelperTextBase: React.FC<SwapFormTypeProps & {
6
+ isLoading?: boolean;
7
+ tokenAddress?: string;
8
+ token?: TokenAmount;
9
+ }>;
@@ -6,15 +6,20 @@ import { useTokenAddressBalance } from '../../hooks';
6
6
  import { SwapFormKeyHelper } from '../../providers';
7
7
  import { formatTokenAmount, formatTokenPrice } from '../../utils';
8
8
  export const FormPriceHelperText = ({ formType, }) => {
9
- const { t } = useTranslation();
10
- const [amount, chainId, tokenAddress] = useWatch({
9
+ const [chainId, tokenAddress] = useWatch({
11
10
  name: [
12
- SwapFormKeyHelper.getAmountKey(formType),
13
11
  SwapFormKeyHelper.getChainKey(formType),
14
12
  SwapFormKeyHelper.getTokenKey(formType),
15
13
  ],
16
14
  });
17
15
  const { token, isLoading } = useTokenAddressBalance(chainId, tokenAddress);
16
+ return (_jsx(FormPriceHelperTextBase, { formType: formType, isLoading: isLoading, tokenAddress: tokenAddress, token: token }));
17
+ };
18
+ export const FormPriceHelperTextBase = ({ formType, isLoading, tokenAddress, token }) => {
19
+ const { t } = useTranslation();
20
+ const amount = useWatch({
21
+ name: SwapFormKeyHelper.getAmountKey(formType),
22
+ });
18
23
  const fromAmountTokenPrice = formatTokenPrice(amount, token?.priceUSD);
19
24
  return (_jsxs(FormHelperText, { component: "div", sx: { display: 'flex', justifyContent: 'space-between', margin: 0 }, children: [_jsx(Typography, { color: fromAmountTokenPrice ? 'text.secondary' : 'grey.600', fontWeight: 400, fontSize: 12, marginLeft: 8, lineHeight: 1.3334, flex: 1, sx: {
20
25
  wordBreak: 'break-word',
@@ -1,4 +1,12 @@
1
- /// <reference types="react" />
1
+ import type { Token } from '@lifi/sdk';
2
2
  import type { BoxProps } from '@mui/material';
3
+ import type { ReactNode } from 'react';
3
4
  import type { SwapFormTypeProps } from '../../providers';
4
5
  export declare const SwapInput: React.FC<SwapFormTypeProps & BoxProps>;
6
+ export declare const SwapInputBase: React.FC<SwapFormTypeProps & BoxProps & {
7
+ token?: Token;
8
+ startAdornment?: ReactNode;
9
+ endAdornment?: ReactNode;
10
+ bottomAdornment?: ReactNode;
11
+ disabled?: boolean;
12
+ }>;
@@ -1,37 +1,52 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useRef } from 'react';
3
- import { useController } from 'react-hook-form';
2
+ import { useLayoutEffect, useRef } from 'react';
3
+ import { useController, useWatch } from 'react-hook-form';
4
4
  import { useTranslation } from 'react-i18next';
5
+ import { useToken } from '../../hooks';
5
6
  import { SwapFormKeyHelper, useWidgetConfig } from '../../providers';
6
7
  import { DisabledUI } from '../../types';
7
- import { formatInputAmount } from '../../utils';
8
+ import { fitInputText, formatInputAmount } from '../../utils';
8
9
  import { Card, CardTitle } from '../Card';
9
- import { FitInputText } from './FitInputText';
10
10
  import { FormPriceHelperText } from './FormPriceHelperText';
11
- import { FormControl, Input } from './SwapInput.style';
11
+ import { FormControl, Input, maxInputFontSize, minInputFontSize, } from './SwapInput.style';
12
12
  import { SwapInputEndAdornment } from './SwapInputEndAdornment';
13
13
  import { SwapInputStartAdornment } from './SwapInputStartAdornment';
14
14
  export const SwapInput = ({ formType, ...props }) => {
15
+ const { disabledUI } = useWidgetConfig();
16
+ const [chainId, tokenAddress] = useWatch({
17
+ name: [
18
+ SwapFormKeyHelper.getChainKey(formType),
19
+ SwapFormKeyHelper.getTokenKey(formType),
20
+ ],
21
+ });
22
+ const { token } = useToken(chainId, tokenAddress);
23
+ const disabled = disabledUI?.includes(DisabledUI.FromAmount);
24
+ return (_jsx(SwapInputBase, { formType: formType, token: token, startAdornment: _jsx(SwapInputStartAdornment, { formType: formType }), endAdornment: !disabled ? _jsx(SwapInputEndAdornment, { formType: formType }) : undefined, bottomAdornment: _jsx(FormPriceHelperText, { formType: formType }), disabled: disabled, ...props }));
25
+ };
26
+ export const SwapInputBase = ({ formType, token, startAdornment, endAdornment, bottomAdornment, disabled, ...props }) => {
15
27
  const { t } = useTranslation();
16
28
  const amountKey = SwapFormKeyHelper.getAmountKey(formType);
17
29
  const { field: { onChange, onBlur, value }, } = useController({
18
30
  name: amountKey,
19
31
  });
20
- const { disabledUI } = useWidgetConfig();
21
32
  const ref = useRef(null);
22
33
  const handleChange = (event) => {
23
34
  const { value } = event.target;
24
- const formattedAmount = formatInputAmount(value, true);
35
+ const formattedAmount = formatInputAmount(value, token?.decimals, true);
25
36
  onChange(formattedAmount);
26
37
  };
27
38
  const handleBlur = (event) => {
28
39
  const { value } = event.target;
29
- const formattedAmount = formatInputAmount(value);
40
+ const formattedAmount = formatInputAmount(value, token?.decimals);
30
41
  onChange(formattedAmount);
31
42
  onBlur();
32
43
  };
33
- const disabled = disabledUI?.includes(DisabledUI.FromAmount);
34
- return (_jsxs(Card, { ...props, children: [_jsx(CardTitle, { children: t('swap.fromAmount') }), _jsxs(FormControl, { fullWidth: true, children: [_jsx(Input, { inputRef: ref, size: "small", autoComplete: "off", placeholder: "0", startAdornment: _jsx(SwapInputStartAdornment, { formType: formType }), endAdornment: !disabled ? (_jsx(SwapInputEndAdornment, { formType: formType })) : undefined, inputProps: {
44
+ useLayoutEffect(() => {
45
+ if (ref.current) {
46
+ fitInputText(maxInputFontSize, minInputFontSize, ref.current);
47
+ }
48
+ }, [value, ref]);
49
+ return (_jsxs(Card, { ...props, children: [_jsx(CardTitle, { children: t('swap.fromAmount') }), _jsxs(FormControl, { fullWidth: true, children: [_jsx(Input, { inputRef: ref, size: "small", autoComplete: "off", placeholder: "0", startAdornment: startAdornment, endAdornment: endAdornment, inputProps: {
35
50
  inputMode: 'decimal',
36
- }, onChange: handleChange, onBlur: handleBlur, value: value, name: amountKey, disabled: disabled, required: true }), _jsx(FormPriceHelperText, { formType: formType })] }), _jsx(FitInputText, { ref: ref, formType: formType })] }));
51
+ }, onChange: handleChange, onBlur: handleBlur, value: value, name: amountKey, disabled: disabled, required: true }), bottomAdornment] })] }));
37
52
  };
@@ -27,7 +27,7 @@ export const TokenListItemButton = ({ onClick, token, chain, showBalance, isBala
27
27
  setShowAddress(false);
28
28
  }
29
29
  };
30
- return (_jsxs(ListItemButton, { onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, dense: true, children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, { src: token.logoURI, alt: token.symbol, children: token.symbol[0] }) }), _jsx(ListItemText, { primary: token.symbol, secondaryTypographyProps: {
30
+ return (_jsxs(ListItemButton, { onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, dense: true, children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, { src: token.logoURI, alt: token.symbol, children: token.symbol?.[0] }) }), _jsx(ListItemText, { primary: token.symbol, secondaryTypographyProps: {
31
31
  component: 'div',
32
32
  sx: {
33
33
  overflow: 'auto',
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "2.0.0-beta.11";
2
+ export declare const version = "2.0.0-beta.13";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '2.0.0-beta.11';
2
+ export const version = '2.0.0-beta.13';
@@ -1,2 +1,2 @@
1
1
  import type { ChainId } from '@lifi/sdk';
2
- export declare const useGasRecommendation: (chainId: ChainId, fromChain?: ChainId, fromToken?: string) => import("@tanstack/react-query").UseQueryResult<import("@lifi/sdk").GasRecommendationResponse, unknown>;
2
+ export declare const useGasRecommendation: (chainId: ChainId, fromChain?: ChainId, fromToken?: string) => import("@tanstack/react-query").UseQueryResult<import("@lifi/sdk").GasRecommendationResponse | null, unknown>;
@@ -1,9 +1,14 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
2
  import { useLiFi } from '../providers';
3
+ import { useChains } from './useChains';
3
4
  const refetchInterval = 60000;
4
5
  export const useGasRecommendation = (chainId, fromChain, fromToken) => {
5
6
  const lifi = useLiFi();
7
+ const { chains } = useChains();
6
8
  return useQuery(['gas-recommendation', chainId, fromChain, fromToken], async ({ queryKey: [_, chainId, fromChain, fromToken] }) => {
9
+ if (!chains?.some((chain) => chain.id === chainId)) {
10
+ return null;
11
+ }
7
12
  const gasRecommendation = await lifi.getGasRecommendation({
8
13
  chainId: chainId,
9
14
  fromChain: fromChain,
@@ -5,7 +5,9 @@ import { useChains } from './useChains';
5
5
  import { useFeaturedTokens } from './useFeaturedTokens';
6
6
  export const useTokens = (selectedChainId) => {
7
7
  const lifi = useLiFi();
8
- const { data, isLoading, dataUpdatedAt } = useQuery(['tokens'], () => lifi.getTokens());
8
+ const { data, isLoading } = useQuery(['tokens'], () => lifi.getTokens(), {
9
+ refetchInterval: 3600000,
10
+ });
9
11
  const { getChainById, isLoading: isSupportedChainsLoading } = useChains();
10
12
  const featuredTokens = useFeaturedTokens(selectedChainId);
11
13
  const { tokens: configTokens, chains: configChains } = useWidgetConfig();
@@ -19,9 +21,18 @@ export const useTokens = (selectedChainId) => {
19
21
  if (!chainAllowed) {
20
22
  return [];
21
23
  }
22
- let filteredTokens = configTokens?.allow?.filter((token) => token.chainId === selectedChainId);
23
- if (!filteredTokens?.length) {
24
- filteredTokens = data?.tokens[selectedChainId];
24
+ let filteredTokens = data?.tokens[selectedChainId];
25
+ const includedTokens = configTokens?.include?.filter((token) => token.chainId === selectedChainId);
26
+ if (includedTokens?.length) {
27
+ filteredTokens = filteredTokens
28
+ ? [...includedTokens, ...filteredTokens]
29
+ : includedTokens;
30
+ }
31
+ const allowedTokens = configTokens?.allow
32
+ ?.filter((token) => token.chainId === selectedChainId)
33
+ .map((token) => token.address);
34
+ if (allowedTokens?.length) {
35
+ filteredTokens = filteredTokens?.filter((token) => allowedTokens.includes(token.address));
25
36
  }
26
37
  const deniedTokenAddresses = configTokens?.deny
27
38
  ?.filter((token) => token.chainId === selectedChainId)
@@ -40,15 +51,16 @@ export const useTokens = (selectedChainId) => {
40
51
  return tokens;
41
52
  // eslint-disable-next-line react-hooks/exhaustive-deps
42
53
  }, [
43
- isSupportedChainsLoading,
44
- selectedChainId,
45
- getChainById,
46
54
  configChains,
47
55
  configTokens?.allow,
48
56
  configTokens?.deny,
49
- featuredTokens,
57
+ configTokens?.include,
58
+ data?.tokens,
50
59
  data,
51
- dataUpdatedAt,
60
+ featuredTokens,
61
+ getChainById,
62
+ isSupportedChainsLoading,
63
+ selectedChainId,
52
64
  ]);
53
65
  return {
54
66
  tokens,