Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
1 change: 1 addition & 0 deletions apps/cowswap-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@react-spring/web": "9.7.3",
"@reown/appkit": "1.8.19",
"@reown/appkit-adapter-wagmi": "1.8.19",
"@reown/appkit-controllers": "1.8.19",
"@reduxjs/toolkit": "1.9.5",
"@safe-global/api-kit": "4.0.1",
"@safe-global/types-kit": "3.0.0",
Expand Down
4 changes: 4 additions & 0 deletions apps/cowswap-frontend/src/locales/en-US.po
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,10 @@ msgstr "Cookie Policy"
msgid "Partner fee can not be more than {PARTNER_FEE_MAX_BPS} BPS!"
msgstr "Partner fee can not be more than {PARTNER_FEE_MAX_BPS} BPS!"

#: apps/cowswap-frontend/src/modules/tradeFormValidation/pure/TradeFormButtons/tradeButtonsMap.tsx
msgid "Restoring wallet"
msgstr "Restoring wallet"

#: apps/cowswap-frontend/src/modules/tokensList/pure/TokensContent/index.tsx
#~ msgid "Manage Token Lists"
#~ msgstr "Manage Token Lists"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import {
TokensListsUpdater,
UnsupportedTokensUpdater,
} from '@cowprotocol/tokens'
import { useWalletInfo, WalletUpdater } from '@cowprotocol/wallet'
import { useWalletInfo, WalletUpdater, WidgetStandaloneModeUpdater } from '@cowprotocol/wallet'

import { CowSdkUpdater } from 'cowSdk'
import { useBalancesContext } from 'entities/balancesContext/useBalancesContext'
import { BridgeOrdersCleanUpdater } from 'entities/bridgeOrders'
import { BridgeProvidersUpdater, useBridgeSupportedNetworks } from 'entities/bridgeProvider'
import { CorrelatedTokensUpdater } from 'entities/correlatedTokens'
import { useInjectedWidgetParams } from 'entities/injectedWidget'
import { ThemeConfigUpdater } from 'theme/ThemeConfigUpdater'
import { TradingSdkUpdater } from 'tradingSdk/TradingSdkUpdater'

import { BalancesDevtools, CommonPriorityBalancesAndAllowancesUpdater } from 'modules/balancesAndAllowances'
import { PendingBridgeOrdersUpdater, BridgingEnabledUpdater } from 'modules/bridge'
import { BalancesCombinedUpdater } from 'modules/combinedBalances'
import { InFlightOrderFinalizeUpdater } from 'modules/ethFlow'
import { CowEventsUpdater, InjectedWidgetUpdater, WidgetStandaloneModeUpdater } from 'modules/injectedWidget'
import { CowEventsUpdater, InjectedWidgetUpdater } from 'modules/injectedWidget'
import { FinalizeTxUpdater } from 'modules/onchainTransactions'
import {
OrderProgressEventsUpdater,
Expand Down Expand Up @@ -77,6 +78,7 @@ export function Updaters(): ReactNode {
const { chainId: sourceChainId } = useSourceChainId()
const bridgeNetworkInfo = useBridgeSupportedNetworks()
const balancesContext = useBalancesContext()
const { standaloneMode } = useInjectedWidgetParams()
const balancesAccount = balancesContext.account || account

return (
Expand All @@ -102,7 +104,7 @@ export function Updaters(): ReactNode {
<InFlightOrderFinalizeUpdater />
<SpotPricesUpdater />
<InjectedWidgetUpdater />
<WidgetStandaloneModeUpdater />
<WidgetStandaloneModeUpdater standaloneMode={standaloneMode} />
<CowEventsUpdater />
<UsdPricesUpdater />
<OrdersNotificationsUpdater />
Expand Down
1 change: 0 additions & 1 deletion apps/cowswap-frontend/src/modules/injectedWidget/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export { InjectedWidgetUpdater } from './updaters/InjectedWidgetUpdater'
export { CowEventsUpdater } from './updaters/CowEventsUpdater'
export { WidgetStandaloneModeUpdater } from './updaters/WidgetStandaloneMode.updater'
export { useIsInfiniteApproveDisabledInWidget } from './hooks/useIsInfiniteApproveDisabledInWidget'
export { useInjectedWidgetDeadline } from './hooks/useInjectedWidgetDeadline'
export { useInjectedWidgetMetaData } from './hooks/useInjectedWidgetMetaData'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ export function useSetupTradeState(): void {
* 4. Otherwise, navigate to the new chainId with default tokens
*/
useEffect(() => {
// Take urlChainId directly from window.location to avoid race conditions
const urlChainId = getRawCurrentChainIdFromUrl()

// When we came back to the tab and there is a new chainId in provider
const providerChangedNetworkWhenWindowInactive =
isWindowVisible && prevIsWindowVisible !== isWindowVisible && providerChainId !== urlChainId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { Nullish } from '@cowprotocol/cow-sdk'
import { Currency, Token } from '@cowprotocol/currency'
import { useENSAddress } from '@cowprotocol/ens'
import { useIsTradeUnsupported, useIsXstockToken, useTryFindToken } from '@cowprotocol/tokens'
import { useGnosisSafeInfo, useIsTxBundlingSupported, useWalletDetails, useWalletInfo } from '@cowprotocol/wallet'
import {
useGnosisSafeInfo,
useIsRestoringConnection,
useIsTxBundlingSupported,
useWalletDetails,
useWalletInfo,
} from '@cowprotocol/wallet'

import { useHasHookBridgeProvidersEnabled } from 'entities/bridgeProvider'
import { useInjectedWidgetParams } from 'entities/injectedWidget'
Expand Down Expand Up @@ -44,6 +50,7 @@ export function useTradeFormValidationContext(): TradeFormValidationCommonContex
const isProviderNetworkDeprecated = useIsProviderNetworkDeprecated()
const isOnline = useIsOnline()
const { isLoading: isBalancesLoading, hasFirstLoad, error: balancesError } = useTokensBalancesCombined()
const isRestoringConnection = useIsRestoringConnection()

const { inputCurrency, outputCurrency, recipient, tradeType } = derivedTradeState || {}
const customTokenError = useTokenCustomTradeError(inputCurrency, outputCurrency, tradeQuote.error)
Expand Down Expand Up @@ -115,6 +122,7 @@ export function useTradeFormValidationContext(): TradeFormValidationCommonContex
isInputCurrencyXstock,
isOutputCurrencyXstock,
isNonEvmReceiverConfirmed,
isRestoringConnection,
}
}, [
hasFirstLoad,
Expand Down Expand Up @@ -146,6 +154,7 @@ export function useTradeFormValidationContext(): TradeFormValidationCommonContex
injectedWidgetParams,
tradePriceImpact,
isNonEvmReceiverConfirmed,
isRestoringConnection,
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,7 @@ export const tradeButtonsMap: Record<TradeFormValidation, ButtonErrorConfig | Bu
[TradeFormValidation.WidgetConstrainedTokenPair]: {
text: <Trans>The token pair is constrained</Trans>,
},
[TradeFormValidation.RestoringWallet]: {
text: <Trans>Restoring wallet</Trans>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! Maybe we can also change the copy in connect button match in apps/cowswap-frontend/src/modules/wallet/containers/WalletStatusButton/WalletStatusButton.container.tsx#L85

Image

},
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function validateTradeForm(context: TradeFormValidationContext): TradeFor
injectedWidgetParams,
tradePriceImpact,
isNonEvmReceiverConfirmed,
isRestoringConnection,
} = context

const {
Expand Down Expand Up @@ -117,7 +118,9 @@ export function validateTradeForm(context: TradeFormValidationContext): TradeFor
}

if (!isSwapUnsupported && !account) {
validations.push(TradeFormValidation.WalletNotConnected)
validations.push(
isRestoringConnection ? TradeFormValidation.RestoringWallet : TradeFormValidation.WalletNotConnected,
)
}

if (!isSupportedWallet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface TradeFormValidationCommonContext {
injectedWidgetParams: Partial<CowSwapWidgetAppParams>
tradePriceImpact: PriceImpact
isNonEvmReceiverConfirmed: boolean
isRestoringConnection: boolean
}

export interface TradeFormValidationContext extends TradeFormValidationCommonContext {}
Expand All @@ -75,6 +76,7 @@ export enum TradeFormValidation {
WalletNotSupported,
SafeReadonlyUser,
WalletCapabilitiesLoading,
RestoringWallet,

// Quote request params
CurrencyNotSet,
Expand Down
20 changes: 20 additions & 0 deletions apps/cowswap-frontend/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import svgr from 'vite-plugin-svgr'
import viteTsConfigPaths from 'vite-tsconfig-paths'

import { execSync } from 'child_process'
import { readFile } from 'node:fs/promises'
import * as path from 'path'

import pkg from './package.json'
Expand Down Expand Up @@ -195,6 +196,25 @@ export default defineConfig(({ mode, isPreview }) => {
})
},
},
{

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixes @reown/appkit source maps, now you can debug it locally

// @reown/appkit ships .js.map files whose `sources` point at the original
// TypeScript (exports/react.ts, src/**/*.ts) without inlining `sourcesContent`,
// and the published tarball doesn't include those .ts files. esbuild follows the
// sourceMappingURL pragma during prebundling and propagates the null sources into
// the optimized dep map, so devtools 404s on every reown source ("DevTools failed
// to load source map"). Drop the pragma for @reown files so esbuild treats the
// shipped compiled .js as the source and embeds real `sourcesContent` instead.
name: 'cow-reown-strip-sourcemap',
setup(build) {
build.onLoad({ filter: /[\\/]@reown[\\/].*\.js$/ }, async (args) => {
const contents = await readFile(args.path, 'utf8')
return {
contents: contents.replace(/\n?\/\/# sourceMappingURL=.*$/gm, ''),
loader: 'js',
}
})
},
},
],
},
// Only include packages that are direct or resolvable from the app; transitive
Expand Down
4 changes: 3 additions & 1 deletion libs/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@cowprotocol/cow-sdk": "9.1.2",
"@reown/appkit": "1.8.19",
"@reown/appkit-adapter-wagmi": "1.8.19",
"@reown/appkit-controllers": "1.8.19",
"@cowprotocol/assets": "workspace:*",
"@cowprotocol/common-const": "workspace:*",
"@cowprotocol/common-utils": "workspace:*",
Expand Down Expand Up @@ -62,6 +63,7 @@
"devDependencies": {
"@types/ms.macro": "2.0.0",
"@types/react": "19.1.3",
"@types/styled-components": "5.1.34"
"@types/styled-components": "5.1.34",
"@testing-library/react": "16.3.0"
}
}
2 changes: 1 addition & 1 deletion libs/wallet/src/api/container/WalletProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode, useEffect } from 'react'

import { useTheme } from '@cowprotocol/common-hooks'

import { reownAppKit } from '../../../reown/init'
import { reownAppKit } from '../../../wagmi/config'

interface WalletProviderProps {
children: ReactNode
Expand Down
3 changes: 0 additions & 3 deletions libs/wallet/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import type { CaipNetworkId } from '@reown/appkit'
/** Custom event name for "open wallet modal". Dispatched by the app; handled in Web3Provider to open Reown (AppKit). */
export const OPEN_WALLET_MODAL_EVENT = 'cowswap-open-wallet-modal'

/** SessionStorage key: set on user disconnect so InjectedBrowserAutoConnect does not reopen the wallet (e.g. Rabby). */
export const USER_DISCONNECTED_SESSION_KEY = 'cowswap:userDisconnected:v0'

export const WC_DISABLED_TEXT =
'Wallet-connect based wallet is already in use. Please disconnect it to connect to this wallet.'

Expand Down
5 changes: 5 additions & 0 deletions libs/wallet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export * from './wagmi/hooks/useDisconnectWallet'
export * from './wagmi/hooks/useSwitchNetwork'
export * from './wagmi/hooks/useConnectionType'
export * from './wagmi/hooks/useIsRestoringConnection'
export { WidgetStandaloneModeUpdater } from './updaters/WidgetStandaloneMode.updater'
export { reownAppKit, wagmiAdapter, wagmiStorage } from './wagmi/config'

// Updater
export { WalletUpdater } from './wagmi/updater'
Expand All @@ -40,3 +42,6 @@ export { Web3Provider } from './wagmi/Web3Provider'
// TODO: this export is discussable, however it's already used outside
export * from './api/state'
export * from './api/state'
Comment thread
shoom3301 marked this conversation as resolved.

export * from './utils/getIsSafeAppIframe'
export * from './utils/connectWalletById'
1 change: 1 addition & 0 deletions libs/wallet/src/reown/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const SUPPORTED_REOWN_NETWORKS = ALL_SUPPORTED_CHAIN_IDS.flatMap((chainId
) as [Chain, ...Chain[]]

export const COW_WIDGET_CONNECTOR_ID = 'cow-widget'
export const SAFE_CONNECTOR_ID = 'safe'
6 changes: 0 additions & 6 deletions libs/wallet/src/reown/init.ts

This file was deleted.

7 changes: 7 additions & 0 deletions libs/wallet/src/state/appWalletContext.atom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { atom } from 'jotai'

export interface AppWalletContext {
standaloneMode: boolean | undefined
}

export const appWalletContextAtom = atom<AppWalletContext | null>(null)
Loading
Loading