@openocean.finance/widget 1.0.13 → 1.0.15

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,10 +1,10 @@
1
1
  {
2
2
  "name": "@openocean.finance/widget",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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
- "main": "./src/index.ts",
7
- "types": "./src/index.d.ts",
6
+ "main": "./dist/esm/index.js",
7
+ "types": "./dist/esm/index.d.ts",
8
8
  "sideEffects": false,
9
9
  "scripts": {
10
10
  "watch": "tsc -w -p ./tsconfig.json",
@@ -261,7 +261,7 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
261
261
  quoteResult.isDebridgeRoute = false
262
262
  }
263
263
  }
264
- const data = quoteResult || {}
264
+ const data = quoteResult && quoteResult.data || {}
265
265
  // minOutAmount calculation is now handled within DebridgeService or OpenOceanService
266
266
  const isDebridge = data.isDebridgeRoute === true
267
267
 
@@ -277,7 +277,6 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
277
277
  toAmountMin = minAmount.toFixed(20).replace(/\.?0+$/, '');
278
278
  // 如果还是科学计数法,再强制转字符串
279
279
  if (toAmountMin.includes('e') || toAmountMin.includes('E')) {
280
- debugger;
281
280
  toAmountMin = minAmount.toLocaleString('fullwide', { useGrouping: false, maximumSignificantDigits: 21 });
282
281
  toAmountMin = toAmountMin.replace(/\.?0+$/, '');
283
282
  }
@@ -9,9 +9,10 @@ interface OpenOceanToken {
9
9
  }
10
10
 
11
11
  export class OpenOceanService {
12
- private static readonly API_V1_URL = 'https://ethapi.openocean.finance/v1'
13
- private static readonly API_V2_URL = 'https://ethapi.openocean.finance/v2'
12
+ // private static readonly API_V1_URL = 'https://ethapi.openocean.finance/v1'
13
+ //private static readonly API_V2_URL = 'https://ethapi.openocean.finance/v2'
14
14
  private static readonly API_V3_URL = 'https://open-api.openocean.finance/v3'
15
+ private static readonly API_V4_URL = 'https://open-api.openocean.finance/v4'
15
16
 
16
17
  // Chain ID to OpenOcean chain name mapping
17
18
  private static readonly CHAIN_ID_MAP: Record<string | number, string> = {
@@ -28,8 +29,8 @@ export class OpenOceanService {
28
29
  // If chainId exists in CHAIN_ID_MAP, use V1 API
29
30
  const chainName = this.getChainName(chainId)
30
31
  return Object.keys(this.CHAIN_ID_MAP).includes(chainId.toString())
31
- ? `${this.API_V1_URL}/${chainName}`
32
- : `${this.API_V2_URL}/${chainId}`
32
+ ? `${this.API_V4_URL}/${chainName}`
33
+ : `${this.API_V4_URL}/${chainId}`
33
34
  }
34
35
 
35
36
  static async getQuote(params: {
@@ -46,16 +47,16 @@ export class OpenOceanService {
46
47
  referrer?: string
47
48
  }) {
48
49
  const apiUrl = this.getApiUrl(params.chain)
49
- const slippage = (Number(params.slippage || '1') * 10000).toString()
50
+ const slippage = (Number(params.slippage || 0.01)).toString();
50
51
  const queryParams = new URLSearchParams({
51
52
  quoteType: 'quote',
52
53
  inTokenSymbol: params.inTokenSymbol,
53
54
  inTokenAddress: params.inTokenAddress,
54
55
  outTokenSymbol: params.outTokenSymbol,
55
56
  outTokenAddress: params.outTokenAddress,
56
- amount: params.amount,
57
+ amountDecimals: params.amount,
57
58
  slippage,
58
- gasPrice: params.gasPrice || '',
59
+ gasPriceDecimals: params.gasPrice || '',
59
60
  disabledDexIds: params.disabledDexIds || '',
60
61
  enabledDexIds: params.enabledDexIds || '',
61
62
  referrer: params.referrer || '0x3487ef9f9b36547e43268b8f0e2349a226c70b53',
@@ -82,22 +83,27 @@ export class OpenOceanService {
82
83
  referrerFeeShare?: string
83
84
  }) {
84
85
  const apiUrl = this.getApiUrl(params.chain)
85
- const slippage = (Number(params.slippage || '1') * 10000).toString()
86
+ const slippage = (Number(params.slippage || 0.01)).toString();
87
+ const referrer: any = {
88
+ referrer: params.referrer || '0x3487ef9f9b36547e43268b8f0e2349a226c70b53',
89
+ }
90
+ if (params.referrerFee) {
91
+ referrer.referrerFee = (Number(params.referrerFee) * 100).toString();
92
+ referrer.referrerFeeShare = params.referrerFeeShare || '1500';
93
+ }
86
94
  const queryParams = new URLSearchParams({
87
95
  quoteType: 'swap',
88
96
  inTokenSymbol: params.inTokenSymbol,
89
97
  inTokenAddress: params.inTokenAddress,
90
98
  outTokenSymbol: params.outTokenSymbol,
91
99
  outTokenAddress: params.outTokenAddress,
92
- amount: params.amount,
100
+ amountDecimals: params.amount,
93
101
  account: params.account,
94
102
  slippage,
95
- gasPrice: params.gasPrice || '',
103
+ gasPriceDecimals: params.gasPrice || '',
96
104
  disabledDexIds: params.disabledDexIds || '',
97
105
  enabledDexIds: params.enabledDexIds || '',
98
- referrer: params.referrer || '0x3487ef9f9b36547e43268b8f0e2349a226c70b53',
99
- referrerFee: (Number(params.referrerFee || '0') * 100).toString(),
100
- referrerFeeShare: params.referrerFeeShare || '1500',
106
+ ...referrer,
101
107
  })
102
108
  const isV1Api = Object.keys(this.CHAIN_ID_MAP).includes(params.chain.toString())
103
109
  const swapEndpoint = isV1Api ? 'swap-quote' : 'swap'
@@ -107,7 +113,7 @@ export class OpenOceanService {
107
113
 
108
114
  static async getTokenList(chain: string) {
109
115
  const chainName = this.getChainName(chain)
110
- const response = await fetch(`${this.API_V3_URL}/${chainName}/tokenList`)
116
+ const response = await fetch(`${this.API_V4_URL}/${chainName}/tokenList`)
111
117
  const data = await response.json()
112
118
  if (data.code !== 200) {
113
119
  throw new Error('Failed to fetch token list')
@@ -152,8 +158,8 @@ export class OpenOceanService {
152
158
  }
153
159
  }
154
160
  // const apiUrl = this.getApiUrl(chain)
155
- const response = await fetch(`${this.API_V2_URL}/${chain}/gas-price`)
156
- const data = await response.json()
161
+ const response = await fetch(`${this.API_V4_URL}/${chain}/gasPrice`)
162
+ const { data } = await response.json()
157
163
  return data
158
164
  }
159
165
 
@@ -162,8 +168,8 @@ export class OpenOceanService {
162
168
  // Check if the address is valid
163
169
  if (!tokenAddress || (!/^0x[a-fA-F0-9]{40}$/.test(tokenAddress) && !/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(tokenAddress))) {
164
170
  throw new Error('Invalid token address')
165
- }
166
- const response = await fetch(`${this.API_V3_URL}/${chainName}/getTokenInfo?tokenAddress=${tokenAddress}`)
171
+ }
172
+ const response = await fetch(`${this.API_V4_URL}/${chainName}/getTokenInfo?tokenAddress=${tokenAddress}`)
167
173
  const data = await response.json()
168
174
  if (!data || !data.address || !data.symbol || !data.decimals) {
169
175
  throw new Error('Failed to fetch token info')