@openocean.finance/widget 1.0.25 → 1.0.26
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/components/AmountInput/AmountInput.js +2 -2
- package/dist/esm/components/AmountInput/AmountInput.js.map +1 -1
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/utils/format.d.ts +9 -0
- package/dist/esm/utils/format.js +17 -0
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/AmountInput/AmountInput.tsx +2 -2
- package/src/config/version.ts +1 -1
- package/src/utils/format.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openocean.finance/widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"description": "Openocean Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -12,7 +12,7 @@ import { FormKeyHelper, type FormTypeProps } from '../../stores/form/types.js'
|
|
|
12
12
|
import { useFieldController } from '../../stores/form/useFieldController.js'
|
|
13
13
|
import { useFieldValues } from '../../stores/form/useFieldValues.js'
|
|
14
14
|
import { DisabledUI } from '../../types/widget.js'
|
|
15
|
-
import { formatInputAmount, formatTokenAmount } from '../../utils/format.js'
|
|
15
|
+
import { formatInputAmount, formatTokenAmount, formatToTokenAmount } from '../../utils/format.js'
|
|
16
16
|
import { fitInputText } from '../../utils/input.js'
|
|
17
17
|
|
|
18
18
|
import {
|
|
@@ -101,7 +101,7 @@ export const AmountInputBase: React.FC<
|
|
|
101
101
|
router.toToken &&
|
|
102
102
|
typeof router.toToken.decimals === 'number'
|
|
103
103
|
) {
|
|
104
|
-
inputValue = String(
|
|
104
|
+
inputValue = String(formatToTokenAmount(BigInt(router.toAmount), router.toToken.decimals))
|
|
105
105
|
} else {
|
|
106
106
|
inputValue = ''
|
|
107
107
|
}
|
package/src/config/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@openocean.finance/widget'
|
|
2
|
-
export const version = '1.0.
|
|
2
|
+
export const version = '1.0.26'
|
package/src/utils/format.ts
CHANGED
|
@@ -18,6 +18,28 @@ export function formatTokenAmount(
|
|
|
18
18
|
return formattedAmount
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Format toToken amount with conditional decimal places for display only.
|
|
23
|
+
* When toToken value > 1000, keep 4 decimal places, otherwise keep 6 decimal places.
|
|
24
|
+
* This function only changes the display format, not the original value precision.
|
|
25
|
+
* @param amount amount to format.
|
|
26
|
+
* @param decimals token decimals.
|
|
27
|
+
* @returns formatted amount string for display.
|
|
28
|
+
*/
|
|
29
|
+
export function formatToTokenAmount(
|
|
30
|
+
amount: bigint | undefined,
|
|
31
|
+
decimals: number
|
|
32
|
+
) {
|
|
33
|
+
const formattedAmount = amount ? formatUnits(amount, decimals) : '0'
|
|
34
|
+
const parsedAmount = Number.parseFloat(formattedAmount)
|
|
35
|
+
if (!parsedAmount || Number.isNaN(Number(formattedAmount))) {
|
|
36
|
+
return '0'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const decimalPlaces = parsedAmount > 1000 ? 4 : 6
|
|
40
|
+
return parsedAmount.toFixed(decimalPlaces)
|
|
41
|
+
}
|
|
42
|
+
|
|
21
43
|
export function formatSlippage(
|
|
22
44
|
slippage = '',
|
|
23
45
|
defaultValue = '',
|