Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Oct 16, 2023
2 parents b4f9f37 + 0a4a592 commit 384701c
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 566 deletions.
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
# Changelog

## [1.48.0](https://github.com/cowprotocol/cowswap/compare/v1.47.1...v1.48.0) (2023-10-16)


### Features

* **permit:** allowance warning ([#3184](https://github.com/cowprotocol/cowswap/issues/3184)) ([f4700d9](https://github.com/cowprotocol/cowswap/commit/f4700d9ac34bf281f6efb9bcbc60bebacb8ac68f))
* **permit:** disable permit for SC wallets ([#3213](https://github.com/cowprotocol/cowswap/issues/3213)) ([29e5178](https://github.com/cowprotocol/cowswap/commit/29e5178a4c15eb56568f5da0d0a30990a47bc76f))
* **permit:** modals LIMIT ([#3164](https://github.com/cowprotocol/cowswap/issues/3164)) ([70e5653](https://github.com/cowprotocol/cowswap/commit/70e56534eaa17456e42e2ba30541537e44d76c78))
* **permit:** modals SWAP ([#3158](https://github.com/cowprotocol/cowswap/issues/3158)) ([ed53662](https://github.com/cowprotocol/cowswap/commit/ed53662eedec3fb4ce3d880c9303df701f5059c1))
* **permit:** refactor permit caching ([#3183](https://github.com/cowprotocol/cowswap/issues/3183)) ([e902e36](https://github.com/cowprotocol/cowswap/commit/e902e36d6d6320dfa1649a448a834df49f115ce4))
* remove walletConnect v1 and use v2 by default ([#3156](https://github.com/cowprotocol/cowswap/issues/3156)) ([4b3fbc0](https://github.com/cowprotocol/cowswap/commit/4b3fbc0f6de2f89235cc69fdc6e7eaefb9bd12b6))
* **tokens:** new UI component for token select modal ([#3166](https://github.com/cowprotocol/cowswap/issues/3166)) ([d5b69cd](https://github.com/cowprotocol/cowswap/commit/d5b69cd4716d1a77e94a4ecba808186e96ef4794))
* **tokens:** new UI for tokens management ([#3174](https://github.com/cowprotocol/cowswap/issues/3174)) ([6c2c253](https://github.com/cowprotocol/cowswap/commit/6c2c2535a11707ad1cc30aa17bd003863d832faa))


### Bug Fixes

* **eth-flow:** update refund info for expired orders ([#3222](https://github.com/cowprotocol/cowswap/issues/3222)) ([dede0d0](https://github.com/cowprotocol/cowswap/commit/dede0d0431511ad1b1ed0548f6d42f881b0f95e0))
* **permit:** improve permittable detection ([#3226](https://github.com/cowprotocol/cowswap/issues/3226)) ([79cb48a](https://github.com/cowprotocol/cowswap/commit/79cb48aa9cd21689d64e13fe57044c4f345c4118))
* **swap:** handle errors from order posting API ([#3224](https://github.com/cowprotocol/cowswap/issues/3224)) ([99df6d2](https://github.com/cowprotocol/cowswap/commit/99df6d2ca9fd5040624977f385e03b2442587c15))

## [1.47.1](https://github.com/cowprotocol/cowswap/compare/v1.47.0...v1.47.1) (2023-09-29)


### Features

* allow to change rpc nodes ([#3160](https://github.com/cowprotocol/cowswap/issues/3160)) ([b9b4be2](https://github.com/cowprotocol/cowswap/commit/b9b4be24ece99ddef83f351d47cc86a9ac3ff5da))
* **orders-table:** approve order token from allowance warn tooltip ([#3144](https://github.com/cowprotocol/cowswap/issues/3144)) ([aa943bf](https://github.com/cowprotocol/cowswap/commit/aa943bf06ab2ba3bb3040bae96106b4463f1283a))
* update approve button color ([#3169](https://github.com/cowprotocol/cowswap/issues/3169)) ([802f288](https://github.com/cowprotocol/cowswap/commit/802f288379329d6a526933be988e6669020bb872))


### Bug Fixes

* don't fetch tokens list ens hashes ([#3152](https://github.com/cowprotocol/cowswap/issues/3152)) ([49989f9](https://github.com/cowprotocol/cowswap/commit/49989f987e729749c17c64984ca3338f774198f9))
* fix bad import ([8546bbc](https://github.com/cowprotocol/cowswap/commit/8546bbc6e792cd913511c87ecfa3ab7453648ce6))
* **twap:** approve infinite amount ([#3141](https://github.com/cowprotocol/cowswap/issues/3141)) ([c5ab768](https://github.com/cowprotocol/cowswap/commit/c5ab768f85a0a463accaf436114fdcab7b538d80))


### Miscellaneous Chores

* **release:** hotfix 1.47.1 Merge pull request [#3171](https://github.com/cowprotocol/cowswap/issues/3171) from cowprotocol/hotfix/1.47.1 ([ce8671f](https://github.com/cowprotocol/cowswap/commit/ce8671fe3705f79a0bb73729855dfd59bbd48b52))

## [1.47.0](https://github.com/cowprotocol/cowswap/compare/v1.47.0-RC.0...v1.47.0) (2023-09-11)


Expand Down
14 changes: 4 additions & 10 deletions apps/cowswap-frontend/src/api/gnosisProtocol/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
CowEnv,
EnrichedOrder,
NativePriceResponse,
OrderBookApiError,
OrderKind,
OrderQuoteRequest,
OrderQuoteResponse,
Expand All @@ -25,9 +24,11 @@ import { LegacyFeeQuoteParams as FeeQuoteParams } from 'legacy/state/price/types

import { getAppData } from 'modules/appData'

import { ApiErrorCodes, ApiErrorObject } from 'api/gnosisProtocol/errors/OperatorError'
import { ApiErrorCodes } from 'api/gnosisProtocol/errors/OperatorError'
import GpQuoteError, { GpQuoteErrorDetails, mapOperatorErrorToQuoteError } from 'api/gnosisProtocol/errors/QuoteError'

import { getIsOrderBookTypedError } from './getIsOrderBookTypedError'

function getProfileUrl(): Partial<Record<ChainId, string>> {
if (isLocal || isDev || isPr || isBarn) {
return {
Expand Down Expand Up @@ -165,7 +166,7 @@ export async function getQuote(params: FeeQuoteParams): Promise<OrderQuoteRespon
}

return orderBookApi.getQuote(quoteParams, { chainId }).catch((error) => {
if (isOrderbookTypedError(error)) {
if (getIsOrderBookTypedError(error)) {
const errorObject = mapOperatorErrorToQuoteError(error.body)

return Promise.reject(errorObject ? new GpQuoteError(errorObject) : error)
Expand All @@ -175,13 +176,6 @@ export async function getQuote(params: FeeQuoteParams): Promise<OrderQuoteRespon
})
}

export type OrderbookTypedError = OrderBookApiError<ApiErrorObject>

function isOrderbookTypedError(e: any): e is OrderbookTypedError {
const error = e as OrderbookTypedError
return error.body.errorType !== undefined && error.body.description !== undefined
}

export async function getOrder(chainId: ChainId, orderId: string, env?: CowEnv): Promise<EnrichedOrder | null> {
const contextOverride = {
chainId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { OrderBookApiError } from '@cowprotocol/cow-sdk'

import { ApiErrorObject } from './errors/OperatorError'

export type OrderBookTypedError = OrderBookApiError<ApiErrorObject>

export function getIsOrderBookTypedError(e: any): e is OrderBookTypedError {
const error = e as OrderBookTypedError
return error.body.errorType !== undefined && error.body.description !== undefined
}
1 change: 1 addition & 0 deletions apps/cowswap-frontend/src/api/gnosisProtocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as realApi from './api'
import * as mockApi from './mock'

export type { UnsupportedToken, OrderID } from './api'
export { getIsOrderBookTypedError } from './getIsOrderBookTypedError'

const useMock = process.env.REACT_APP_MOCK === 'true'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useCallback, useRef } from 'react'

import { EXPIRED_ORDERS_PENDING_TIME } from '@cowprotocol/common-const'
import { NATIVE_CURRENCY_BUY_ADDRESS } from '@cowprotocol/common-const'
import { SupportedChainId as ChainId } from '@cowprotocol/cow-sdk'
import { useWalletInfo } from '@cowprotocol/wallet'

Expand All @@ -24,7 +24,6 @@ export function ExpiredOrdersUpdater(): null {
const updateOrders = useCallback(
async (chainId: ChainId, account: string) => {
const lowerCaseAccount = account.toLowerCase()
const now = Date.now()

if (isUpdating.current) {
return
Expand All @@ -33,26 +32,24 @@ export function ExpiredOrdersUpdater(): null {
try {
isUpdating.current = true

// Filter orders:
// Filter expired orders:
// - Only eth-flow orders
// - Owned by the current connected account
// - Created in the last 5 min, no further
// - Not yet refunded
const pending = expiredRef.current.filter(({ owner, creationTime: creationTimeString, refundHash }) => {
const creationTime = new Date(creationTimeString).getTime()
const orderWithoutRefund = expiredRef.current.filter(({ owner, refundHash, sellToken }) => {
const isEthFlowOrder = sellToken === NATIVE_CURRENCY_BUY_ADDRESS

return (
owner.toLowerCase() === lowerCaseAccount && now - creationTime < EXPIRED_ORDERS_PENDING_TIME && !refundHash
)
return isEthFlowOrder && owner.toLowerCase() === lowerCaseAccount && !refundHash
})

if (pending.length === 0) {
if (orderWithoutRefund.length === 0) {
// console.debug(`[CancelledOrdersUpdater] No orders are being expired`)
return
} else {
console.debug(`[ExpiredOrdersUpdater] Checking ${pending.length} recently expired orders...`)
console.debug(`[ExpiredOrdersUpdater] Checking ${orderWithoutRefund.length} recently expired orders...`)
}

const ordersPromises = pending.map(({ id }) => getOrder(chainId, id))
const ordersPromises = orderWithoutRefund.map(({ id }) => getOrder(chainId, id))

const resolvedPromises = await Promise.allSettled(ordersPromises)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ async function actuallyCheckTokenIsPermittable(params: CheckIsTokenPermittablePa
try {
nonce = await eip2612PermitUtils.getTokenNonce(tokenAddress, owner)
} catch (e) {
if (e === 'nonce not supported' || e.message === 'nonce is NaN') {
console.debug(`[checkTokenIsPermittable] Not a permittable token ${tokenAddress}`, e?.message || e)
// Here we know it's not supported, return false
// See https://github.com/1inch/permit-signed-approvals-utils/blob/b190197a45c3289867ee4e6da93f10dea51ef276/src/eip-2612-permit.utils.ts#L309
// and https://github.com/1inch/permit-signed-approvals-utils/blob/b190197a45c3289867ee4e6da93f10dea51ef276/src/eip-2612-permit.utils.ts#L325
return false
}
console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${tokenAddress}`, e)

return false
// Otherwise, it might have been a network issue or another temporary failure, return error
return { error: e.message || e.toString() }
}

const baseParams: BaseParams = {
Expand All @@ -81,10 +89,12 @@ async function actuallyCheckTokenIsPermittable(params: CheckIsTokenPermittablePa
return await estimateTokenPermit({ ...baseParams, type: 'eip-2612', provider })
} catch (e) {
// Not eip-2612, try dai-like
console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${tokenAddress}`, e)
try {
return await estimateTokenPermit({ ...baseParams, type: 'dai-like', provider })
} catch (e) {
// Not dai-like either, return error
console.debug(`[checkTokenIsPermittable] Failed to estimate dai-like permit for ${tokenAddress}`, e)
return { error: e.message || e.toString() }
}
}
Expand All @@ -105,7 +115,7 @@ type EstimateParams = BaseParams & {
provider: Web3Provider
}

async function estimateTokenPermit(params: EstimateParams) {
async function estimateTokenPermit(params: EstimateParams): Promise<EstimatePermitResult> {
const { provider, chainId, walletAddress, tokenAddress, type } = params

const getCallDataFn = type === 'eip-2612' ? getEip2612CallData : getDaiLikeCallData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CHAIN_UTILS_CACHE = new Map<number, Eip2612PermitUtils>()
/**
* Cache by provider. Here we cache per provider as each account should have its own instance
*/
const PROVIDER_UTILS_CACHE = new Map<Web3Provider, Eip2612PermitUtils>()
const PROVIDER_UTILS_CACHE = new Map<string, Eip2612PermitUtils>()

export function getPermitUtilsInstance(
chainId: SupportedChainId,
Expand All @@ -26,7 +26,8 @@ export function getPermitUtilsInstance(
if (!account && chainCache) {
return chainCache
}
const providerCache = PROVIDER_UTILS_CACHE.get(provider)
const providerCacheKey = `${chainId}-${account}`
const providerCache = PROVIDER_UTILS_CACHE.get(providerCacheKey)

if (providerCache) {
return providerCache
Expand All @@ -36,9 +37,14 @@ export function getPermitUtilsInstance(
const eip2612PermitUtils = new Eip2612PermitUtils(web3ProviderConnector)

if (!account) {
console.log(`[getPermitUtilsInstance] Set cached chain utils for chain ${chainId}`, eip2612PermitUtils)
CHAIN_UTILS_CACHE.set(chainId, eip2612PermitUtils)
} else {
PROVIDER_UTILS_CACHE.set(provider, eip2612PermitUtils)
console.log(
`[getPermitUtilsInstance] Set cached provider utils for chain ${chainId}-${account}`,
eip2612PermitUtils
)
PROVIDER_UTILS_CACHE.set(providerCacheKey, eip2612PermitUtils)
}

return eip2612PermitUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'inter-ui' // TODO: We need to do a cosmos wrapper with the global styles! Will reiterate to remove this line

import { useSelect } from 'react-cosmos/client'
import styled from 'styled-components/macro'

import { EthFlowStepper, EthFlowStepperProps, SmartOrderStatus } from '.'

Expand Down Expand Up @@ -376,20 +377,25 @@ const STEPS_BY_DESCRIPTION = STEPS.reduce<{ [description: string]: EthFlowSteppe
return acc
}, {})

const Wrapper = styled.div`
width: 80%;
margin: 20px auto;
`

function Fixture() {
const [stepDescription] = useSelect('steps', {
options: STEPS.map((step) => step.description),
})
const props = STEPS_BY_DESCRIPTION[stepDescription]

return (
<>
<Wrapper>
<EthFlowStepper {...props} />
<h3>Params</h3>
<div>
<pre>{JSON.stringify(props, null, 2)}</pre>
</div>
</>
</Wrapper>
)
}

Expand Down
12 changes: 10 additions & 2 deletions apps/cowswap-frontend/src/modules/trade/utils/swapErrorHelper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { getProviderErrorMessage, isRejectRequestProviderError } from '@cowprotocol/common-utils'
import { capitalizeFirstLetter, getProviderErrorMessage, isRejectRequestProviderError } from '@cowprotocol/common-utils'

import { getIsOrderBookTypedError } from 'api/gnosisProtocol'

export const USER_SWAP_REJECTED_ERROR = 'User rejected signing the order'

export function getSwapErrorMessage(error: Error): string {
if (isRejectRequestProviderError(error)) {
return USER_SWAP_REJECTED_ERROR
} else {
return getProviderErrorMessage(error)
const defaultErrorMessage = getProviderErrorMessage(error)

if (getIsOrderBookTypedError(error)) {
return capitalizeFirstLetter(error.body?.description) || defaultErrorMessage
}

return defaultErrorMessage
}
}
14 changes: 0 additions & 14 deletions apps/cowswap-frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { VitePWA } from 'vite-plugin-pwa'
import svgr from 'vite-plugin-svgr'
import viteTsConfigPaths from 'vite-tsconfig-paths'

import * as path from 'path'

import { getReactProcessEnv } from '../../tools/getReactProcessEnv'

// eslint-disable-next-line no-restricted-imports
Expand Down Expand Up @@ -102,18 +100,6 @@ export default defineConfig(({ mode }) => {
resolve: {
alias: {
'node-fetch': 'isomorphic-fetch',
/**
* Temporary fix for walletconnect
* https://github.com/Uniswap/web3-react/issues/861
*/
'@walletconnect/ethereum-provider': path.resolve(
__dirname,
'../../node_modules/@walletconnect/ethereum-provider/dist/umd/index.min.js'
),
'@walletconnect/universal-provider': path.resolve(
__dirname,
'../../node_modules/@walletconnect/universal-provider/dist/index.cjs.js'
),
},
},

Expand Down
1 change: 0 additions & 1 deletion libs/common-const/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const NATIVE_CURRENCY_BUY_TOKEN: { [chainId in ChainId | number]: Token }
export const INPUT_OUTPUT_EXPLANATION = 'Only executed swaps incur fees.'
export const PENDING_ORDERS_BUFFER = ms`60s` // 60s
export const CANCELLED_ORDERS_PENDING_TIME = ms`5min` // 5min
export const EXPIRED_ORDERS_PENDING_TIME = ms`15min` // 15min
export const PRICE_API_TIMEOUT_MS = ms`10s` // 10s
export const GP_ORDER_UPDATE_INTERVAL = ms`30s` // 30s
export const MINIMUM_ORDER_VALID_TO_TIME_SECONDS = 120
Expand Down
5 changes: 5 additions & 0 deletions libs/common-utils/src/capitalizeFirstLetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function capitalizeFirstLetter(str: string): string {
if (!str) return str

return str.charAt(0).toUpperCase() + str.slice(1)
}
1 change: 1 addition & 0 deletions libs/common-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export * from './getRandomInt'
export * from './isEnoughAmount'
export * from './tryParseFractionalAmount'
export * from './maxAmountSpend'
export * from './capitalizeFirstLetter'
export * from './jotai/atomWithPartialUpdate'
5 changes: 5 additions & 0 deletions libs/wallet/src/web3-react/connection/asyncConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ function initCustomProvider(self: AsyncConnector, connector: Connector, chainId:
}

self.events.emit(ASYNC_CUSTOM_PROVIDER_EVENT, self.customProvider)

// Update provider when network is changed on wallet side
connector.provider?.on('chainChanged', (chainIdHex: string) => {
initCustomProvider(self, connector, +chainIdHex)
})
}

/**
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cowswap",
"version": "1.47.0",
"version": "1.48.0",
"description": "CoW Swap",
"main": "index.js",
"author": "",
Expand Down Expand Up @@ -88,17 +88,16 @@
"@uniswap/sdk-core": "^3.0.1",
"@uniswap/token-lists": "^1.0.0-beta.30",
"@use-gesture/react": "^10.2.23",
"@web3-react/coinbase-wallet": "^8.2.0",
"@web3-react/core": "^8.2.0",
"@web3-react/eip1193": "^8.2.0",
"@web3-react/empty": "^8.2.0",
"@web3-react/gnosis-safe": "^8.2.0",
"@web3-react/metamask": "^8.2.1",
"@web3-react/network": "^8.2.0",
"@web3-react/types": "^8.2.0",
"@web3-react/url": "^8.2.0",
"@web3-react/walletconnect": "^8.2.0",
"@web3-react/walletconnect-v2": "^8.3.7",
"@walletconnect/ethereum-provider": "^2.10.2",
"@web3-react/coinbase-wallet": "^8.2.3",
"@web3-react/core": "^8.2.3",
"@web3-react/eip1193": "^8.2.3",
"@web3-react/empty": "^8.2.3",
"@web3-react/gnosis-safe": "^8.2.4",
"@web3-react/metamask": "^8.2.4",
"@web3-react/network": "^8.2.3",
"@web3-react/url": "^8.2.3",
"@web3-react/walletconnect-v2": "^8.5.1",
"bnc-sdk": "^4.6.0",
"buffer": "^6.0.3",
"cids": "^1.0.0",
Expand Down Expand Up @@ -214,6 +213,7 @@
"@vitejs/plugin-react-swc": "^3.3.2",
"@vitest/coverage-c8": "~0.32.0",
"@vitest/ui": "~0.32.0",
"@web3-react/types": "^8.2.3",
"babel-jest": "^29.6.2",
"babel-plugin-styled-components": "2.1.4",
"babel-plugin-transform-import-meta": "^2.2.0",
Expand Down
Loading

0 comments on commit 384701c

Please sign in to comment.