Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
6f34021
feat: installs packages
bsvalverde Dec 16, 2025
dedfc39
feat: adds wagmi provider and config
bsvalverde Dec 16, 2025
ad60313
feat: adds feature flag and gets some wallet info from wagmi
bsvalverde Dec 16, 2025
d91df2b
chore: updates safe packages
bsvalverde Jan 13, 2026
402f4e3
chore: updates wallet hooks
bsvalverde Jan 13, 2026
710e45f
Merge remote-tracking branch 'origin/develop' into bernardo/cow-567-i…
bsvalverde Jan 13, 2026
bcb0b7c
chore: removes unused variables
bsvalverde Jan 13, 2026
94b0315
chore: updates cow sdk adapter
bsvalverde Jan 15, 2026
23c79e5
fix: fixes feature flag
bsvalverde Jan 15, 2026
f0b8de1
chore: adds new components to test files
bsvalverde Jan 16, 2026
934055b
chore: adds status icon to new connection
bsvalverde Jan 16, 2026
e8a69c8
chore: updates gas estimation hook
bsvalverde Jan 16, 2026
089d755
chore: updates chain id hook
bsvalverde Jan 16, 2026
52e946f
chore: updates wallet capabilities
bsvalverde Jan 17, 2026
b38b58c
chore: updates safe info hook with todos
bsvalverde Jan 17, 2026
c3f8b40
chore: fixes wallet id
bsvalverde Jan 17, 2026
2a91034
chore: updates wallet metadata function
bsvalverde Jan 17, 2026
297f37e
chore: updates is wallet connect hook and wallet lib exports
bsvalverde Jan 18, 2026
8997067
chore: identifies places that need to be updated in future tasks
bsvalverde Jan 18, 2026
43d4099
chore: updates comments
bsvalverde Jan 18, 2026
67add44
Merge remote-tracking branch 'origin/develop' into bernardo/cow-567-i…
bsvalverde Jan 19, 2026
a21f65d
chore: fixes safe types
bsvalverde Jan 19, 2026
53a64c3
fix: type issues
bsvalverde Jan 19, 2026
bced543
fix: type & complexity issue
bsvalverde Jan 19, 2026
ba62e2f
fix: fixes tests
bsvalverde Jan 19, 2026
2f96fde
fix: adjustments based on PR comments
bsvalverde Jan 20, 2026
890a01a
Merge remote-tracking branch 'origin/develop' into bernardo/cow-567-i…
bsvalverde Jan 20, 2026
d9758de
fix: failing builds
bsvalverde Jan 20, 2026
7cc606f
feat: adds reown and updates disconnect hook
bsvalverde Jan 21, 2026
db9ee71
chore: updates config
bsvalverde Jan 21, 2026
0427ba4
refactor: uses wagmi hooks
bsvalverde Jan 21, 2026
d558250
fix: updates flag to use local storage
bsvalverde Jan 22, 2026
3290e51
chore: reorders connection options
bsvalverde Jan 23, 2026
92cdb05
Merge remote-tracking branch 'origin/develop' into bernardo/cow-567-i…
bsvalverde Jan 23, 2026
d1f4db5
fix: fixes build error
bsvalverde Jan 23, 2026
e41f908
fix: adds return types to version resolver
bsvalverde Jan 23, 2026
4a43a83
fix: coderabbit reviews
bsvalverde Jan 23, 2026
9369c63
feat: adds switch network hook
bsvalverde Jan 23, 2026
ed43ef7
fix: fixes SafeApiKit txServiceUrl
bsvalverde Jan 23, 2026
fcffca2
Merge remote-tracking branch 'origin/develop' into bernardo/cow-567-i…
bsvalverde Jan 26, 2026
25fc3ca
feat: adds wallet connect peer information
bsvalverde Jan 26, 2026
937faff
chore: removes TODO from hook that will no longer be used
bsvalverde Jan 26, 2026
301e2de
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Jan 27, 2026
fed4cf6
chore: merge develop
shoom3301 Jan 27, 2026
c3c05e4
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Jan 27, 2026
4ae9c38
chore: merge develop
shoom3301 Jan 27, 2026
755901c
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Jan 27, 2026
9f7c19f
chore: merge develop
shoom3301 Jan 27, 2026
6d8ac96
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Jan 27, 2026
a38597e
chore: merge develop
shoom3301 Jan 27, 2026
ed6d34b
Merge remote-tracking branch 'upstream/develop' into bernardo/cow-567…
bsvalverde Jan 27, 2026
c1d4c46
chore: fix libs build
shoom3301 Jan 27, 2026
aa51eb1
chore: fix libs build
shoom3301 Jan 27, 2026
07b506e
chore: fix tests
shoom3301 Jan 27, 2026
d24dac5
chore: fix libs build
shoom3301 Jan 27, 2026
a010563
chore: fix libs build
shoom3301 Jan 27, 2026
bb4ed75
chore: fix tests
shoom3301 Jan 27, 2026
5477802
Merge branch 'bernardo/cow-567-initial-viem-wagmi-setup' into bernard…
bsvalverde Jan 27, 2026
c00e977
fix: package dependencies
bsvalverde Jan 27, 2026
003b223
Merge remote-tracking branch 'upstream/bernardo/cow-567-merge-develop…
bsvalverde Jan 27, 2026
06579fe
Merge remote-tracking branch 'origin/bernardo/cow-567-initial-viem-wa…
bsvalverde Jan 28, 2026
1e9ff5e
Merge remote-tracking branch 'origin/develop' into bernardo/cow-568-m…
bsvalverde Jan 29, 2026
111043c
fix: post merge fixes
bsvalverde Jan 29, 2026
0f9baca
fix: moves wagmi to dependencies
bsvalverde Jan 29, 2026
4cd995d
fix: fixes tests broken by reown
bsvalverde Jan 29, 2026
ee26bc8
fix: updates wagmi and wagmi core versions
bsvalverde Jan 29, 2026
0b874db
chore: adds wagmi connector to resolutions
bsvalverde Jan 29, 2026
58bc37b
Revert "chore: adds wagmi connector to resolutions"
bsvalverde Jan 29, 2026
3a44b39
fix: dedupes wagmi
bsvalverde Feb 2, 2026
b8e73ca
fix: dedupes reown
bsvalverde Feb 2, 2026
f296e7f
Merge remote-tracking branch 'origin/develop' into bernardo/cow-568-m…
bsvalverde Feb 2, 2026
07d55cc
fix: updates pnpm lock
bsvalverde Feb 2, 2026
44186bb
Merge remote-tracking branch 'origin/develop' into bernardo/cow-568-m…
bsvalverde Feb 2, 2026
9b52f23
fix: fixes wagmi multiple instances for tests
bsvalverde Feb 2, 2026
d036bc5
fix: attemps to fix test issue
bsvalverde Feb 2, 2026
b553547
fix: attemps to fix ci tests
bsvalverde Feb 2, 2026
1a8c787
fix: uses global chain id for wallet updater
bsvalverde Feb 2, 2026
a18e9bd
fix: fixes wallet name
bsvalverde Feb 2, 2026
700b6bc
refactor: refactors wallet name fallback
bsvalverde Feb 2, 2026
c0ab938
chore: undoes update to tools files
bsvalverde Feb 2, 2026
1213c19
fix: adjustments based on PR comments
bsvalverde Feb 3, 2026
4c15cf4
fix: fixes return error
bsvalverde Feb 3, 2026
253bddf
fix: adds dark and light modes to reown modal
bsvalverde Feb 4, 2026
42e0a70
fix: attemps to remove reown if flag is not on
bsvalverde Feb 5, 2026
320c7b2
Merge remote-tracking branch 'origin/develop' into bernardo/cow-568-m…
bsvalverde Feb 5, 2026
8d88cf0
Merge remote-tracking branch 'origin/develop' into bernardo/cow-568-m…
bsvalverde Feb 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/cow-fi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@visx/group": "^3.3.0",
"@visx/responsive": "^3.10.2",
"@visx/shape": "^3.5.0",
"@wagmi/core": "^3.1.0",
"@wagmi/core": "^3.3.1",
"@web3-react/core": "^8.2.3",
"color2k": "^2.0.2",
"csstype": "^3.1.3",
Expand All @@ -81,8 +81,8 @@
"remark-gfm": "^4.0.1",
"styled-components": "5.3.11",
"swiper": "^11.1.1",
"viem": "^2.42.1",
"wagmi": "^3.1.0",
"viem": "^2.45.0",
"wagmi": "3.4.1",
"workbox-core": "^6.6.1",
"workbox-expiration": "^6.6.1",
"workbox-precaching": "^6.6.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// this is not used for now. we use "craco test", but eventually we will

import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

export default {
displayName: 'cowswap',
preset: '../../jest.preset.js',
Expand All @@ -12,7 +16,11 @@ export default {
setupFilesAfterEnv: ['./jest.setup.ts'],
setupFiles: ['dotenv/config'],
transformIgnorePatterns: [
'/node_modules/.pnpm/(?!.*(react-dnd|dnd-core|@react-dnd|wagmi|@wagmi|viem))',
'/node_modules/(?!(\\.pnpm|react-dnd|dnd-core|@react-dnd|wagmi|@wagmi|viem))',
'/node_modules/.pnpm/(?!.*(react-dnd|dnd-core|@react-dnd|wagmi|@wagmi|viem|@reown))',
'/node_modules/(?!(\\.pnpm|react-dnd|dnd-core|@react-dnd|wagmi|@wagmi|viem|@reown))',
],
moduleNameMapper: {
'^wagmi$': require.resolve('wagmi'),
'^@reown/appkit/react$': '<rootDir>/../../testing/reownMock.ts',
},
}
5 changes: 3 additions & 2 deletions apps/cowswap-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@reach/menu-button": "^0.18.0",
"@react-spring/web": "^9.6.1",
"@reduxjs/toolkit": "^1.8.0",
"@reown/appkit": "^1.8.17",
"@safe-global/api-kit": "^4.0.1",
"@safe-global/types-kit": "^3.0.0",
"@sentry/browser": "^7.80.0",
Expand Down Expand Up @@ -136,8 +137,8 @@
"tiny-invariant": "^1.2.0",
"use-async-memo": "^1.2.4",
"uuid": "^13.0.0",
"viem": "^2.42.1",
"wagmi": "^3.1.0",
"viem": "^2.45.0",
"wagmi": "3.4.1",
"workbox-core": "^6.6.1",
"workbox-expiration": "^6.6.1",
"workbox-precaching": "^6.6.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/cowswap-frontend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"executor": "@nx/jest:jest",
"options": {
"passWithNoTests": true,
"jestConfig": "apps/cowswap-frontend/jest.config.ts"
"jestConfig": "apps/cowswap-frontend/jest.config.mjs"
}
},
"ipfs": {
Expand Down
11 changes: 10 additions & 1 deletion apps/cowswap-frontend/src/legacy/state/application/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ export function useCloseModal(_modal: ApplicationModal): Command {
}

export function useToggleWalletModal(): Command {
return useToggleModal(ApplicationModal.WALLET)
// TODO M-7 COW-572
// Readd this
// const { open } = useAppKit()
const toggleModal = useToggleModal(ApplicationModal.WALLET)

// if (LAUNCH_DARKLY_VIEM_MIGRATION) {
// return () => open()
// }

return toggleModal
Comment on lines 30 to 40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Check the package.json to confirm the `@reown/appkit` version
grep -r "@reown/appkit" --include="package.json" | head -5

Repository: cowprotocol/cowswap

Length of output: 257


🏁 Script executed:

# Search for useToggleModal implementation to understand toggle semantics
fd -e ts -e tsx | xargs grep -l "useToggleModal" | head -10

Repository: cowprotocol/cowswap

Length of output: 268


🏁 Script executed:

# Check how useToggleWalletModal is being used in the codebase
rg "useToggleWalletModal" -A 3 -B 1

Repository: cowprotocol/cowswap

Length of output: 5412


🌐 Web query:

@reown/appkit/react v1.8.17 useAppKit hook open() method behavior toggle or open only

💡 Result:

In @reown/appkit/react v1.8.17, useAppKit().open() is open-only (idempotent), not a toggle—you close the modal with useAppKit().close(). The modal’s current visibility is exposed via useAppKitState() (open: boolean). [1] [2]

If you want toggle behavior, implement it yourself:

const { open, close } = useAppKit()
const { open: isOpen } = useAppKitState()

const toggle = () => (isOpen ? close() : open({ view: 'Connect' }))

Sources: [useAppKit / open+close] [1], [useAppKitState / open boolean] [2].

[1] (docs.reown.com)
[2] (docs.reown.com)

Citations:


🏁 Script executed:

# Check useToggleModal implementation to understand what it does
rg "function useToggleModal|const useToggleModal" -A 10

Repository: cowprotocol/cowswap

Length of output: 1143


🏁 Script executed:

# Examine a usage site to see how the toggle is actually called
sed -n '1,50p' apps/cowswap-frontend/src/modules/wallet/containers/Web3Status/index.tsx

Repository: cowprotocol/cowswap

Length of output: 1630


Fix toggle semantics and stabilize the callback.

When the flag is on, the hook returns a new inline function that only calls open(). Since @reown/appkit/react@1.8.17 treats open() as open-only (not a toggle), callers expecting close-on-second-click lose that behavior. Additionally, creating a new function each render creates referential instability for memoized children.

Use useAppKitState() and close() to properly implement toggle semantics, wrapped in useCallback for stability:

♻️ Suggested refactor
 export function useToggleWalletModal(): Command {
-  const { open } = useAppKit()
+  const { open, close } = useAppKit()
+  const { open: isOpen } = useAppKitState()
   const toggleModal = useToggleModal(ApplicationModal.WALLET)
 
-  if (LAUNCH_DARKLY_VIEM_MIGRATION) {
-    return () => open()
-  }
-
-  return toggleModal
+  return useCallback(() => {
+    if (LAUNCH_DARKLY_VIEM_MIGRATION) {
+      isOpen ? close() : open()
+      return
+    }
+    toggleModal()
+  }, [open, close, isOpen, toggleModal])
 }
🤖 Prompt for AI Agents
In `@apps/cowswap-frontend/src/legacy/state/application/hooks.ts` around lines 32
- 40, The hook useToggleWalletModal currently returns a new inline function that
only calls open() when LAUNCH_DARKLY_VIEM_MIGRATION is true, breaking toggle
semantics and causing referential instability; replace that branch to derive
current open state via useAppKitState() and call open() or close() appropriately
to implement true toggle behavior, and wrap the returned callback in useCallback
for stable identity; keep the original fallback of returning
useToggleModal(ApplicationModal.WALLET) when the flag is false, and reference
the functions useAppKit(), useAppKitState(), open, close, useCallback,
useToggleModal, ApplicationModal.WALLET, and the feature flag
LAUNCH_DARKLY_VIEM_MIGRATION when editing the hook.

}

// TODO: These two seem to be gone from original. Check whether they have been replaced
Expand Down
7 changes: 7 additions & 0 deletions apps/cowswap-frontend/src/legacy/state/user/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ export function useIsDarkMode(): boolean {

export function useDarkModeManager(): [boolean, Command] {
const dispatch = useAppDispatch()
// TODO M-7 COW-572
// Readd this
// const { setThemeMode } = useAppKitTheme()
const darkMode = useIsDarkMode()

// useEffect(() => {
// setThemeMode(darkMode ? 'dark' : 'light')
// }, [darkMode, setThemeMode])

const toggleSetDarkMode = useCallback(() => {
dispatch(updateUserDarkMode({ userDarkMode: !darkMode }))
}, [darkMode, dispatch])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export function AccountDetails({
// When name is not set, it defaults to WalletConnect already
const walletConnectSuffix = isWalletConnect && walletDetails?.walletName ? ` ` + t`(via WalletConnect)` : ''

const handleDisconnectClick = (): void => {
disconnectWallet()
const handleDisconnectClick = async (): Promise<void> => {
await disconnectWallet()
handleCloseOrdersPanel()
dispatch(updateSelectedWallet({ wallet: undefined }))
}
Expand Down
4 changes: 4 additions & 0 deletions apps/cowswap-frontend/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export default defineConfig(({ mode }) => {
},
// force esm usage for misconfigured deps' "exports" field (e.g. @use-gesture/core)
conditions: ['module', 'import', 'browser', 'default'],
// Dedupe packages that rely on shared React context across workspace libs.
// Without this, pnpm creates separate copies per workspace package (different peer dep sets),
// causing context mismatches (e.g. WagmiProvider in libs/wallet vs useConnection in libs/wallet-provider).
dedupe: ['@reown/appkit', 'wagmi'],
},

build: {
Expand Down
8 changes: 4 additions & 4 deletions libs/common-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"@cowprotocol/common-utils": "workspace:*",
"@cowprotocol/types": "workspace:*",
"@ethersproject/abstract-provider": "5.7.0",
"@ethersproject/bignumber": "5.7.0",
"@ethersproject/properties": "5.7.0",
"@ethersproject/providers": "5.7.0",
"@ethersproject/bignumber": "5.7.0",
"@lingui/react": "^5.4.1",
"@wagmi/core": "^3.3.1",
"@web3-react/core": "^8.2.3",
"copy-to-clipboard": "^3.2.0",
"ethers": "5.7.2",
Expand All @@ -45,9 +46,8 @@
"styled-components": "5.3.11",
"swr": "^2.3.3",
"timeago.js": "^4.0.2",
"viem": "^2.42.1",
"@wagmi/core": "^3.1.0",
"wagmi": "^3.1.0"
"viem": "^2.45.0",
"wagmi": "3.4.1"
},
"devDependencies": {
"@testing-library/react": "16.3.0",
Expand Down
2 changes: 1 addition & 1 deletion libs/permit-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@ethersproject/wallet": "5.7.0",
"ethers": "5.7.2",
"ms.macro": "^2.0.0",
"viem": "^2.42.1"
"viem": "^2.45.0"
},
"module": "./index.js",
"main": "./src/index.ts",
Expand Down
4 changes: 2 additions & 2 deletions libs/wallet-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@ethersproject/providers": "5.7.0",
"@web3-react/core": "^8.2.3",
"ethers": "5.7.2",
"viem": "^2.42.1",
"wagmi": "^3.1.0"
"viem": "^2.45.0",
"wagmi": "3.4.1"
}
}
14 changes: 8 additions & 6 deletions libs/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,23 @@
"@ethersproject/transactions": "5.7.0",
"@metamask/jazzicon": "^2.0.0",
"@metamask/sdk": "^0.31.4",
"@reown/appkit": "^1.8.17",
"@reown/appkit-adapter-wagmi": "^1.8.17",
"@safe-global/api-kit": "^4.0.1",
"@safe-global/safe-apps-react-sdk": "^4.7.2",
"@safe-global/safe-apps-sdk": "^9.1.0",
"@safe-global/types-kit": "^3.0.0",
"@safe-global/safe-apps-react-sdk": "^4.7.2",
"@tanstack/react-query": "^5.90.20",
"@trezor/connect": "^9.0.11",
"@trezor/connect-plugin-ethereum": "^9.0.1",
"@trezor/connect-web": "^9.0.11",
"@uniswap/sdk-core": "^3.0.1",
"@wagmi/connectors": "^7.1.5",
"@web3-react/coinbase-wallet": "^8.2.3",
"@web3-react/core": "^8.2.3",
"@web3-react/gnosis-safe": "^8.2.4",
"@web3-react/network": "^8.2.3",
"@web3-react/walletconnect-v2": "^8.5.1",
"@tanstack/react-query": "^5.90.12",
"ethereumjs-util": "^7.1.5",
"ethers": "5.7.2",
"eventemitter3": "^4.0.0",
Expand All @@ -62,10 +65,9 @@
"ms.macro": "^2.0.0",
"react": "19.1.2",
"styled-components": "5.3.11",
"viem": "^2.42.1",
"wagmi": "^3.1.0",
"@wagmi/connectors": "^7.0.2",
"swr": "^2.3.3"
"swr": "^2.3.3",
"viem": "^2.45.0",
"wagmi": "3.4.1"
},
"devDependencies": {
"@types/ms.macro": "^2.0.0",
Expand Down
17 changes: 15 additions & 2 deletions libs/wallet/src/versionResolver.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { LAUNCH_DARKLY_VIEM_MIGRATION } from '@cowprotocol/common-const'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { AccountType } from '@cowprotocol/types'
import { Connector as LegacyConnector } from '@web3-react/types'

import * as newUseDisconnect from './wagmi/hooks/useDisconnectWallet'
import * as newUseIsSmartContract from './wagmi/hooks/useIsSmartContractWallet'
import * as newUseIsWalletConnect from './wagmi/hooks/useIsWalletConnect'
import * as newUseSwitchChain from './wagmi/hooks/useSwitchNetwork'
import * as newUseWalletMetadata from './wagmi/hooks/useWalletMetadata'
import * as legacyUseDisconnect from './web3-react/hooks/useDisconnectWallet'
import * as legacyUseIsSmartContractWallet from './web3-react/hooks/useIsSmartContractWallet'
import * as legacyUseIsWalletConnect from './web3-react/hooks/useIsWalletConnect'
import * as legacyUseSwitchChain from './web3-react/hooks/useSwitchNetwork'
import * as legacyUseWalletMetadata from './web3-react/hooks/useWalletMetadata'

export * from './web3-react/hooks/useActivateConnector'

export * from './web3-react/hooks/useConnectionType'

export * from './web3-react/hooks/useDisconnectWallet'
export function useDisconnectWallet(): () => Promise<void> {
const newUseDisconnectWallet = newUseDisconnect.useDisconnectWallet()
const legacyUseDisconnectWallet = legacyUseDisconnect.useDisconnectWallet()
return LAUNCH_DARKLY_VIEM_MIGRATION ? newUseDisconnectWallet : legacyUseDisconnectWallet
}

export function useAccountType(): AccountType | undefined {
const newUseAccountType = newUseIsSmartContract.useAccountType()
Expand All @@ -39,7 +48,11 @@ export function useIsWalletConnect(): boolean {

export * from './web3-react/hooks/useSafeAppsSdk'

export * from './web3-react/hooks/useSwitchNetwork'
export function useSwitchNetwork(): (chainId: SupportedChainId) => Promise<void> {
const newUseSwitchNetwork = newUseSwitchChain.useSwitchNetwork()
const legacyUseSwitchNetwork = legacyUseSwitchChain.useSwitchNetwork()
return LAUNCH_DARKLY_VIEM_MIGRATION ? newUseSwitchNetwork : legacyUseSwitchNetwork
}

export function useIsSafeApp(): boolean {
const newIsSafeApp = newUseWalletMetadata.useIsSafeApp()
Expand Down
21 changes: 18 additions & 3 deletions libs/wallet/src/wagmi/Web3Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ReactNode } from 'react'
import { ReactNode, useEffect } from 'react'

import { LAUNCH_DARKLY_VIEM_MIGRATION } from '@cowprotocol/common-const'
import { SafeProvider } from '@safe-global/safe-apps-react-sdk'

import { createAppKit } from '@reown/appkit/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { WagmiProvider } from 'wagmi'

import { config } from './config'
import { appKitParams, wagmiAdapter } from './config'

const queryClient = new QueryClient()

Expand All @@ -14,8 +16,21 @@ interface Web3ProviderProps {
}

export function Web3Provider({ children }: Web3ProviderProps): React.ReactNode {
useEffect(() => {
if (LAUNCH_DARKLY_VIEM_MIGRATION) {
// TODO M-7 COW-572
// This will be moved back to config file on cleanup
const appKit = createAppKit(appKitParams)

appKit.updateFeatures({
connectorTypeOrder: ['recent', 'injected', 'featured', 'custom', 'external', 'recommended', 'walletConnect'],
})
appKit.close
}
}, [])

return (
<WagmiProvider config={config}>
<WagmiProvider config={wagmiAdapter.wagmiConfig}>
<QueryClientProvider client={queryClient}>
<SafeProvider>{children}</SafeProvider>
</QueryClientProvider>
Expand Down
51 changes: 45 additions & 6 deletions libs/wallet/src/wagmi/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { RPC_URLS } from '@cowprotocol/common-const'
import { LAUNCH_DARKLY_VIEM_MIGRATION, RPC_URLS } from '@cowprotocol/common-const'
import { SupportedChainId } from '@cowprotocol/cow-sdk'

import { safe, injected } from '@wagmi/connectors'
import { CreateAppKit } from '@reown/appkit/react'
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi'
import { Chain, http } from 'viem'
import {
arbitrum,
Expand All @@ -17,7 +18,10 @@ import {
polygon,
sepolia,
} from 'viem/chains'
import { createConfig, Transport } from 'wagmi'
import { Transport } from 'wagmi'

// TODO change
const projectId = 'be9f19dedc14dc05c554d97f92aed71d'

Comment on lines +23 to 25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n libs/wallet/src/wagmi/config.ts

Repository: cowprotocol/cowswap

Length of output: 3557


🏁 Script executed:

rg "REOWN|projectId" -i --type ts --type tsx -A 2 -B 2 | head -100

Repository: cowprotocol/cowswap

Length of output: 90


🏁 Script executed:

fd "\.env" -o "env.example" | head -20

Repository: cowprotocol/cowswap

Length of output: 204


🏁 Script executed:

rg "be9f19dedc14dc05c554d97f92aed71d"

Repository: cowprotocol/cowswap

Length of output: 147


🏁 Script executed:

find . -name ".env*" -o -name "vite.config*" | head -20

Repository: cowprotocol/cowswap

Length of output: 636


🏁 Script executed:

rg "VITE_|process.env" --type ts -l | head -10

Repository: cowprotocol/cowswap

Length of output: 435


🏁 Script executed:

rg "reown|appkit" -i --type ts -B 3 -A 3 | grep -i "env\|const\|config" | head -30

Repository: cowprotocol/cowswap

Length of output: 2551


🏁 Script executed:

cat .env

Repository: cowprotocol/cowswap

Length of output: 45


🏁 Script executed:

cat .env.local.example

Repository: cowprotocol/cowswap

Length of output: 557


🏁 Script executed:

grep -r "REOWN\|PROJECT_ID" .env* 2>/dev/null | head -20

Repository: cowprotocol/cowswap

Length of output: 45


🏁 Script executed:

cat apps/cowswap-frontend/vite.config.mts

Repository: cowprotocol/cowswap

Length of output: 7102


🏁 Script executed:

cat tools/getReactProcessEnv.ts

Repository: cowprotocol/cowswap

Length of output: 479


🏁 Script executed:

rg "projectId" --type ts -B 5 -A 5 | head -50

Repository: cowprotocol/cowswap

Length of output: 3027


🏁 Script executed:

find . -path "*/libs/wallet*" -name "*.ts" -o -name "*.tsx" | head -20

Repository: cowprotocol/cowswap

Length of output: 1038


Remove the TODO and load projectId from environment variable before shipping.

The // TODO change comment and hardcoded projectId (be9f19dedc14dc05c554d97f92aed71d) are scaffolding that must be resolved. Load it from import.meta.env.VITE_REOWN_PROJECT_ID (or equivalent based on your env setup) and validate it exists.

Example
-// TODO change
-const projectId = 'be9f19dedc14dc05c554d97f92aed71d'
+const projectId = import.meta.env.VITE_REOWN_PROJECT_ID
+if (!projectId) {
+  throw new Error('Missing VITE_REOWN_PROJECT_ID')
+}

Per coding guidelines: Remove linter scaffolding (// TODO, eslint-disable) by supplying the correct types before shipping.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO change
const projectId = 'be9f19dedc14dc05c554d97f92aed71d'
const projectId = import.meta.env.VITE_REOWN_PROJECT_ID
if (!projectId) {
throw new Error('Missing VITE_REOWN_PROJECT_ID')
}
🤖 Prompt for AI Agents
In `@libs/wallet/src/wagmi/config.ts` around lines 23 - 25, Replace the hardcoded
projectId constant and remove the "// TODO change" comment: read the value from
import.meta.env.VITE_REOWN_PROJECT_ID (or your env accessor) into a typed const
projectId: string, validate that it exists (throw an error or log and exit if
falsy) so the app fails fast when not provided, and ensure no eslint scaffolding
remains; update any places that reference projectId to use this new constant.

const SUPPORTED_CHAIN_IDS = Object.values(SupportedChainId).filter((v) => typeof v === 'number')

Expand All @@ -36,14 +40,49 @@ const SUPPORTED_CHAINS: Record<SupportedChainId, Chain> = {
[SupportedChainId.SEPOLIA]: sepolia,
}

export const config = createConfig({
chains: SUPPORTED_CHAIN_IDS.map((chainId) => SUPPORTED_CHAINS[chainId]) as [Chain, ...Chain[]],
const metadata = {
name: 'CoW Swap',
description:
'CoW Swap finds the lowest prices from all decentralized exchanges and DEX aggregators & saves you more with p2p trading and protection from MEV',
url: 'https://swap.cow.fi',
icons: ['https://swap.cow.fi/favicon-light-mode.png'],
}

const networks = Object.values(SUPPORTED_CHAINS) as [Chain, ...Chain[]]

export const wagmiAdapter = new WagmiAdapter({
networks,
transports: SUPPORTED_CHAIN_IDS.reduce(
(acc, chainId) => {
acc[chainId] = http(RPC_URLS[chainId])
return acc
},
{} as Record<SupportedChainId, Transport>,
),
connectors: [safe(), injected()],
projectId,
})

export const appKitParams: CreateAppKit = {
adapters: [wagmiAdapter],
// TODO M-7 COW-572
// this will become false once the feature flag is removed
allowUnsupportedChain: !LAUNCH_DARKLY_VIEM_MIGRATION,
defaultNetwork: networks[0],
enableEIP6963: true,
enableWalletGuide: false,
featuredWalletIds: [
'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', // metamask
'18388be9ac2d02726dbac9777c96efaac06d744b2f6d580fccdd4127a6d01fd1', // rabby
'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // coinbase
],
features: {
analytics: false,
email: false,
socials: false,
},
metadata,
networks,
projectId,
termsConditionsUrl:
'https://cow.fi/legal/cowswap-terms?utm_source=swap.cow.fi&utm_medium=web&utm_content=wallet-modal-terms-link',
}
15 changes: 15 additions & 0 deletions libs/wallet/src/wagmi/hooks/useDisconnectWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useCallback } from 'react'

import { Command } from '@cowprotocol/types'

import { useDisconnect } from 'wagmi'

export function useDisconnectWallet(onDisconnect?: Command): () => Promise<void> {
const { mutateAsync: disconnect } = useDisconnect()

return useCallback(async () => {
await disconnect()

onDisconnect?.()
}, [disconnect, onDisconnect])
}
Loading
Loading