From a0011aa35f907054d506df4d6702ca09d5a1dacd Mon Sep 17 00:00:00 2001 From: VGabriel45 Date: Wed, 2 Apr 2025 13:45:13 +0300 Subject: [PATCH 1/5] feat: getSwapQuoteV2 --- packages/checkout/package.json | 2 +- packages/connect/package.json | 2 +- packages/hooks/package.json | 4 ++-- .../src/hooks/Combination/useGetSwapQuote.ts | 14 ++++++------- packages/wallet-widget/package.json | 2 +- pnpm-lock.yaml | 21 ++++++++++++------- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/checkout/package.json b/packages/checkout/package.json index 19af91e73..45b4b02b3 100644 --- a/packages/checkout/package.json +++ b/packages/checkout/package.json @@ -41,7 +41,7 @@ }, "peerDependencies": { "0xsequence": ">= 2.2.13", - "@0xsequence/api": ">= 2.2.13", + "@0xsequence/api": "^2.3.4", "@0xsequence/indexer": ">= 2.2.13", "@0xsequence/metadata": ">= 2.2.13", "@0xsequence/network": ">= 2.2.13", diff --git a/packages/connect/package.json b/packages/connect/package.json index 5c4af5c0f..c053a82d4 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -37,7 +37,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@0xsequence/api": ">= 2.2.13", + "@0xsequence/api": "^2.3.4", "@0xsequence/auth": ">= 2.2.13", "@0xsequence/core": ">= 2.2.13", "@0xsequence/design-system": "^2.0.11", diff --git a/packages/hooks/package.json b/packages/hooks/package.json index f0ad01e26..5eeaa897a 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -30,7 +30,7 @@ "test:watch": "vitest" }, "peerDependencies": { - "@0xsequence/api": ">=2.2.13", + "@0xsequence/api": "^2.3.4", "@0xsequence/indexer": ">=2.2.13", "@0xsequence/metadata": ">=2.2.13", "@0xsequence/network": ">=2.2.13", @@ -39,7 +39,7 @@ "react-dom": ">= 17" }, "devDependencies": { - "@0xsequence/api": "^2.2.13", + "@0xsequence/api": "^2.3.4", "@0xsequence/indexer": "^2.2.13", "@0xsequence/metadata": "^2.2.13", "@0xsequence/network": "^2.2.13", diff --git a/packages/hooks/src/hooks/Combination/useGetSwapQuote.ts b/packages/hooks/src/hooks/Combination/useGetSwapQuote.ts index df091111f..9e0b1fc4a 100644 --- a/packages/hooks/src/hooks/Combination/useGetSwapQuote.ts +++ b/packages/hooks/src/hooks/Combination/useGetSwapQuote.ts @@ -1,7 +1,7 @@ -import { GetSwapQuoteArgs } from '@0xsequence/api' +import { GetSwapQuoteV2Args } from '@0xsequence/api' import { useQuery } from '@tanstack/react-query' -import { NATIVE_TOKEN_ADDRESS_0X_SWAP, QUERY_KEYS, ZERO_ADDRESS, time } from '../../constants' +import { QUERY_KEYS, ZERO_ADDRESS, time } from '../../constants' import { HooksOptions } from '../../types' import { compareAddress } from '../../utils/helpers' import { useAPIClient } from '../API/useAPIClient' @@ -9,25 +9,25 @@ import { useAPIClient } from '../API/useAPIClient' /** * @description Gets the swap quote for a given currency pair */ -export const useGetSwapQuote = (getSwapQuoteArgs: GetSwapQuoteArgs, options?: HooksOptions) => { +export const useGetSwapQuote = (getSwapQuoteArgs: GetSwapQuoteV2Args, options?: HooksOptions) => { const apiClient = useAPIClient() return useQuery({ queryKey: [QUERY_KEYS.useGetSwapQuote, getSwapQuoteArgs, options], queryFn: async () => { - const res = await apiClient.getSwapQuote({ + const res = await apiClient.getSwapQuoteV2({ ...getSwapQuoteArgs, buyCurrencyAddress: compareAddress(getSwapQuoteArgs.buyCurrencyAddress, ZERO_ADDRESS) - ? NATIVE_TOKEN_ADDRESS_0X_SWAP + ? ZERO_ADDRESS : getSwapQuoteArgs.buyCurrencyAddress, sellCurrencyAddress: compareAddress(getSwapQuoteArgs.sellCurrencyAddress, ZERO_ADDRESS) - ? NATIVE_TOKEN_ADDRESS_0X_SWAP + ? ZERO_ADDRESS : getSwapQuoteArgs.sellCurrencyAddress }) return { ...res.swapQuote, - currencyAddress: compareAddress(res.swapQuote.currencyAddress, NATIVE_TOKEN_ADDRESS_0X_SWAP) + currencyAddress: compareAddress(res.swapQuote.currencyAddress, ZERO_ADDRESS) ? ZERO_ADDRESS : res.swapQuote.currencyAddress } diff --git a/packages/wallet-widget/package.json b/packages/wallet-widget/package.json index 8a673a1a4..0d62410a5 100644 --- a/packages/wallet-widget/package.json +++ b/packages/wallet-widget/package.json @@ -40,7 +40,7 @@ "motion": "^12.3.1" }, "peerDependencies": { - "@0xsequence/api": ">= 2.2.13", + "@0xsequence/api": "^2.3.4", "@0xsequence/indexer": ">= 2.2.13", "@0xsequence/metadata": ">= 2.2.13", "@0xsequence/network": ">= 2.2.13", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6c81129eb..79c90b717 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -254,8 +254,8 @@ importers: specifier: '>= 2.2.13' version: 2.2.13(ethers@6.13.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)) '@0xsequence/api': - specifier: '>= 2.2.13' - version: 2.2.13 + specifier: ^2.3.4 + version: 2.3.4 '@0xsequence/design-system': specifier: ^2.0.11 version: 2.0.11(@types/react-dom@19.0.4(@types/react@19.0.10))(@types/react@19.0.10)(motion@12.4.10(@emotion/is-prop-valid@0.8.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -327,8 +327,8 @@ importers: packages/connect: dependencies: '@0xsequence/api': - specifier: '>= 2.2.13' - version: 2.2.13 + specifier: ^2.3.4 + version: 2.3.4 '@0xsequence/auth': specifier: '>= 2.2.13' version: 2.2.13(ethers@6.13.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)) @@ -418,8 +418,8 @@ importers: packages/hooks: devDependencies: '@0xsequence/api': - specifier: ^2.2.13 - version: 2.2.13 + specifier: ^2.3.4 + version: 2.3.4 '@0xsequence/indexer': specifier: ^2.2.13 version: 2.2.13 @@ -469,8 +469,8 @@ importers: packages/wallet-widget: dependencies: '@0xsequence/api': - specifier: '>= 2.2.13' - version: 2.2.13 + specifier: ^2.3.4 + version: 2.3.4 '@0xsequence/design-system': specifier: ^2.0.11 version: 2.0.11(@types/react-dom@19.0.4(@types/react@19.0.10))(@types/react@19.0.10)(motion@12.4.10(@emotion/is-prop-valid@0.8.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -548,6 +548,9 @@ packages: '@0xsequence/api@2.2.13': resolution: {integrity: sha512-UmFMdLRCOfUGT2WqXzHE91sm+XU7eossdoKZ74W/F1ZTBU8XRa4DldQ0alKjff5x4Hxe/wIjppBPE9pQUzGYxA==} + '@0xsequence/api@2.3.4': + resolution: {integrity: sha512-C1qS+6YhKopoE54QonmfOqPUAi8djeoq4isAgPg0wVFb+qlMLCous63m0KqQjj7o4eCa9qOqn9+86lhTsLtaFw==} + '@0xsequence/auth@2.2.13': resolution: {integrity: sha512-3UQ6/zDhrNO5BVsgiLwCfQq4Nmbd1W0Ync/FNug8Yum1i9r2il54bUZRtauct6uMUaotAqNG4l/nzy105v93QQ==} peerDependencies: @@ -6535,6 +6538,8 @@ snapshots: '@0xsequence/api@2.2.13': {} + '@0xsequence/api@2.3.4': {} + '@0xsequence/auth@2.2.13(ethers@6.13.0(bufferutil@4.0.9)(utf-8-validate@5.0.10))': dependencies: '@0xsequence/abi': 2.2.13 From a73cad249f6e955d79fbf0f5ccaf3f07c1eb8b65 Mon Sep 17 00:00:00 2001 From: VGabriel45 Date: Wed, 2 Apr 2025 13:46:39 +0300 Subject: [PATCH 2/5] chore: fix formatting --- packages/connect/src/connectors/ecosystem/provider.ts | 1 - .../src/connectors/ecosystem/providerTransport.ts | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/connect/src/connectors/ecosystem/provider.ts b/packages/connect/src/connectors/ecosystem/provider.ts index d67ba6ad9..2df1170e4 100644 --- a/packages/connect/src/connectors/ecosystem/provider.ts +++ b/packages/connect/src/connectors/ecosystem/provider.ts @@ -27,7 +27,6 @@ export class EcosystemWalletTransportProvider extends ethers.AbstractProvider im this.currentNetwork = ethers.Network.from(initialChainId) } - // eslint-disable-next-line @typescript-eslint/no-explicit-any async request({ method, params }: { method: string; params?: any[] }) { if (method === 'wallet_switchEthereumChain') { const chainId = normalizeChainId(params?.[0].chainId) diff --git a/packages/connect/src/connectors/ecosystem/providerTransport.ts b/packages/connect/src/connectors/ecosystem/providerTransport.ts index 247bdce6a..1ac43f657 100644 --- a/packages/connect/src/connectors/ecosystem/providerTransport.ts +++ b/packages/connect/src/connectors/ecosystem/providerTransport.ts @@ -10,7 +10,7 @@ const isBrowser = typeof window !== 'undefined' export class ProviderTransport { private walletOrigin: string private walletWindow: Window | null = null - // eslint-disable-next-line @typescript-eslint/no-explicit-any + private callbacks: Map void> = new Map() private connectionState: ConnectionState = 'disconnected' private session: SessionData | undefined @@ -134,7 +134,6 @@ export class ProviderTransport { }) } - // eslint-disable-next-line @typescript-eslint/no-explicit-any async sendRequest(method: string, params: any[], chainId: number): Promise { if (!isBrowser) { throw new Error('ProviderTransport is only available in browser environment') @@ -180,7 +179,6 @@ export class ProviderTransport { }) } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private openWalletAndPostMessage(message: any): Promise { if (!isBrowser) { return Promise.reject(new Error('ProviderTransport is only available in browser environment')) @@ -211,7 +209,6 @@ export class ProviderTransport { }) } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private postMessageToWallet(message: any) { console.log('Posting message to wallet:', message) this.walletWindow!.postMessage(message, { @@ -232,7 +229,9 @@ export class ProviderTransport { } private handleMessage = (event: MessageEvent) => { - if (event.origin !== this.walletOrigin) return + if (event.origin !== this.walletOrigin) { + return + } const response = event.data const callback = this.callbacks.get(response.id) From 2a6c2809254b1b9540ec672d4a1b3be7a01959f8 Mon Sep 17 00:00:00 2001 From: VGabriel45 Date: Wed, 2 Apr 2025 14:25:32 +0300 Subject: [PATCH 3/5] chore: added test for api --- .../tests/Combination/useGetSwapQuote.test.ts | 30 ++++++++++++++++--- packages/hooks/src/tests/handlers.ts | 18 +++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts b/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts index 25dece06e..b3ed6e1a8 100644 --- a/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts +++ b/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts @@ -2,22 +2,23 @@ import { renderHook, waitFor } from '@testing-library/react' import { HttpResponse, http } from 'msw' import { describe, expect, it } from 'vitest' -import { ACCOUNT_ADDRESS, NATIVE_TOKEN_ADDRESS_0X_SWAP } from '../../constants' +import { ACCOUNT_ADDRESS, ZERO_ADDRESS } from '../../constants' import { useGetSwapQuote } from '../../hooks/Combination/useGetSwapQuote' import { createWrapper } from '../createWrapper' import { server } from '../setup' const getSwapQuoteArgs = { userAddress: ACCOUNT_ADDRESS, - buyCurrencyAddress: NATIVE_TOKEN_ADDRESS_0X_SWAP, - sellCurrencyAddress: NATIVE_TOKEN_ADDRESS_0X_SWAP, + buyCurrencyAddress: ZERO_ADDRESS, + sellCurrencyAddress: ZERO_ADDRESS, buyAmount: '20000', chainId: 1, includeApprove: true } -describe('useGetSwapQuote', () => { +describe('useGetSwapQuoteV2', () => { it('should return data with a balance', async () => { + const { result } = renderHook(() => useGetSwapQuote(getSwapQuoteArgs), { wrapper: createWrapper() }) @@ -44,4 +45,25 @@ describe('useGetSwapQuote', () => { await waitFor(() => expect(result.current.isError).toBe(true)) }) + + it('should return correct data from dev api', async () => { + const response = await fetch('https://dev-api.sequence.app/rpc/API/GetSwapQuoteV2', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-Access-Key': 'AQAAAAAAAAK2JvvZhWqZ51riasWBftkrVXE' + }, + body: JSON.stringify({ + userAddress: ACCOUNT_ADDRESS, + buyCurrencyAddress: ZERO_ADDRESS, + sellCurrencyAddress: ZERO_ADDRESS, + buyAmount: '20000', + chainId: 1, + includeApprove: true + }) + }) + + const data = await response.json() + console.log('Real API Response Structure:', JSON.stringify(data, null, 2)) + }) }) diff --git a/packages/hooks/src/tests/handlers.ts b/packages/hooks/src/tests/handlers.ts index 73d900fec..ec29ec434 100644 --- a/packages/hooks/src/tests/handlers.ts +++ b/packages/hooks/src/tests/handlers.ts @@ -316,5 +316,23 @@ export const handlers = [ }, { status: 200 } ) + }), + + http.post('*/GetSwapQuoteV2', async () => { + return HttpResponse.json( + { + swapQuote: { + currencyAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + currencyBalance: '180000000000000', + price: '7351402238115', + maxPrice: '7718972350021', + to: '0x0000000000000000000000000000000000000000', + transactionData: '0x0000000000000000000000000000000000000000000000000000000000000000', + transactionValue: '0', + approveData: '0x0000000000000000000000000000000000000000000000000000000000000000' + } + }, + { status: 200 } + ) }) ] From eb04c9a92c8d4f1c5a711f2e2f38515119e154ba Mon Sep 17 00:00:00 2001 From: VGabriel45 Date: Wed, 2 Apr 2025 14:25:50 +0300 Subject: [PATCH 4/5] chore: linting --- packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts b/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts index b3ed6e1a8..dbfab29dc 100644 --- a/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts +++ b/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts @@ -18,7 +18,6 @@ const getSwapQuoteArgs = { describe('useGetSwapQuoteV2', () => { it('should return data with a balance', async () => { - const { result } = renderHook(() => useGetSwapQuote(getSwapQuoteArgs), { wrapper: createWrapper() }) From 52a8280ac5d7806acbc88c291777c48b3fcef546 Mon Sep 17 00:00:00 2001 From: VGabriel45 Date: Wed, 2 Apr 2025 16:23:25 +0300 Subject: [PATCH 5/5] refactor: remove integration test --- .../tests/Combination/useGetSwapQuote.test.ts | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts b/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts index dbfab29dc..d67ab1f42 100644 --- a/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts +++ b/packages/hooks/src/tests/Combination/useGetSwapQuote.test.ts @@ -44,25 +44,4 @@ describe('useGetSwapQuoteV2', () => { await waitFor(() => expect(result.current.isError).toBe(true)) }) - - it('should return correct data from dev api', async () => { - const response = await fetch('https://dev-api.sequence.app/rpc/API/GetSwapQuoteV2', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-Access-Key': 'AQAAAAAAAAK2JvvZhWqZ51riasWBftkrVXE' - }, - body: JSON.stringify({ - userAddress: ACCOUNT_ADDRESS, - buyCurrencyAddress: ZERO_ADDRESS, - sellCurrencyAddress: ZERO_ADDRESS, - buyAmount: '20000', - chainId: 1, - includeApprove: true - }) - }) - - const data = await response.json() - console.log('Real API Response Structure:', JSON.stringify(data, null, 2)) - }) })