@openocean.finance/widget 1.0.24 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/widget",
3
- "version": "1.0.24",
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(formatTokenAmount(BigInt(router.toAmount), router.toToken.decimals))
104
+ inputValue = String(formatToTokenAmount(BigInt(router.toAmount), router.toToken.decimals))
105
105
  } else {
106
106
  inputValue = ''
107
107
  }
@@ -1,2 +1,2 @@
1
1
  export const name = '@openocean.finance/widget'
2
- export const version = '1.0.24'
2
+ export const version = '1.0.26'
@@ -33,6 +33,12 @@ export const useAvailableChains = (chainTypes?: ChainType[]) => {
33
33
  .filter((chainType) => isItemAllowed(chainType, chainTypesConfig))
34
34
 
35
35
  let availableChains = await getChains()
36
+ // reset solana chain id
37
+ const solanaChain = availableChains.find((chain) => chain.key === 'sol')
38
+ if (solanaChain) {
39
+ solanaChain.chainType = ChainType.SVM;
40
+ solanaChain.id = 1151111081099710;
41
+ }
36
42
  // allow chains "starknet","aptos","near","ont","sui",
37
43
  const allowedChainsIds = chains?.allow?.length ? chains.allow : DEFAULT_CHAIN_IDS;
38
44
  const allowedChains = availableChains.filter((chain) => {
@@ -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 = '',