Skip to content

Commit b78da16

Browse files
authored
Merge branch 'main' into fix/safari-csp
2 parents 95058d2 + 4366718 commit b78da16

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

e2e/specs/stateless/wrapName.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,16 @@ test('should calculate needed steps without localstorage', async ({
265265

266266
await page.waitForTimeout(10000)
267267

268-
await page.evaluate(() => localStorage.clear())
268+
await page.evaluate(() => window.localStorage.clear())
269+
await page.evaluate(() => window.sessionStorage.clear())
269270
await page.reload()
270271
await login.reconnect()
271272

272273
await morePage.wrapButton.click()
273274

274-
await expect(page.getByTestId('display-item-Step 1-normal')).toContainText('Migrate profile')
275+
await expect(page.getByTestId('display-item-Step 1-normal')).toContainText('Migrate profile', {
276+
timeout: 10000,
277+
})
275278
await expect(page.getByTestId('display-item-Step 2-normal')).toContainText('Wrap name')
276279

277280
await transactionModal.introButton.click()

src/components/@molecules/TransactionDialogManager/stage/query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { getReadableError } from '@app/utils/errors'
2727
import { createAccessList } from '@app/utils/query/createAccessList'
2828
import { wagmiConfig } from '@app/utils/query/wagmi'
29-
import { hasParaConnection } from '@app/utils/utils'
29+
import { connectorIsMetaMask, hasParaConnection } from '@app/utils/utils'
3030

3131
export const getUniqueTransaction = ({
3232
txKey,
@@ -211,6 +211,10 @@ export const createTransactionRequestUnsafe = async ({
211211
...(isParaConnected ? { maxPriorityFeePerGas: largestMedianGasFee } : {}),
212212
})
213213

214+
if (connectorIsMetaMask(connections, connectorClient)) {
215+
;(request as any).__is_metamask = true
216+
}
217+
214218
return {
215219
...request,
216220
chain: request.chain!,

src/constants/chains.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const getChainsFromUrl = () => {
6464
const chain = process.env.NEXT_PUBLIC_CHAIN_NAME
6565
if (chain === 'holesky') return [holeskyWithEns]
6666
if (chain === 'sepolia') return [sepoliaWithEns]
67+
if (chain === 'mainnet') return [mainnetWithEns]
6768

6869
// Previews
6970
if (segments.length === 4) {

src/utils/query/wagmi.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { createClient, type FallbackTransport, type HttpTransport, type Transport } from 'viem'
1+
import {
2+
createClient,
3+
formatTransactionRequest,
4+
type ExactPartial,
5+
type FallbackTransport,
6+
type HttpTransport,
7+
type TransactionRequest,
8+
type TransactionType,
9+
type Transport,
10+
} from 'viem'
211
import { createConfig, createStorage, fallback, http } from 'wagmi'
312
import { holesky, localhost, mainnet, sepolia } from 'wagmi/chains'
413

@@ -87,7 +96,51 @@ export const transports = {
8796
[holesky.id]: initialiseTransports('holesky', [drpcUrl, tenderlyUrl]),
8897
} as const
8998

90-
const chains = getChainsFromUrl() as unknown as readonly [SupportedChain, ...SupportedChain[]]
99+
// This is a workaround to fix MetaMask defaulting to the wrong transaction type
100+
// when no type is specified, but an access list is provided.
101+
// See: https://github.com/MetaMask/core/issues/5720
102+
// Viem by default doesn't include the type in a TransactionRequest, because it's generally not required.
103+
// To fix the MetaMask issue, we need to include it. However, we don't want to break other wallets, so we only add it
104+
// for MetaMask.
105+
// Viem will use a chain specific transactionRequest formatter if provided, so we can utilise this to
106+
// add `type`.
107+
// References to the formatter are:
108+
// 1. Call to `extract` with all extra parameters (i.e. unused by call by default), and the chain specific formatter
109+
// a. If a formatter is not provided, the function returns `{}` (existing behaviour)
110+
// b. If a formatter is provided, returns the formatted extra parameters
111+
// 2. Call to chain specific formatter if provided, otherwise `formatTransactionRequest`, with the request and the formatted extra parameters
112+
//
113+
// We want to capture only the first call, so `type` is added to the final request object without
114+
// modifying existing behaviour.
115+
const formatExtraTransactionRequestParameters = (
116+
request:
117+
| { type: TransactionType }
118+
// eslint-disable-next-line @typescript-eslint/naming-convention
119+
| { type: TransactionType; __is_metamask: boolean }
120+
| ExactPartial<TransactionRequest>,
121+
) => {
122+
// 1: Call will never have `from`
123+
if (!('from' in request)) {
124+
// 1a: Default behaviour when not MetaMask
125+
if (!('__is_metamask' in request) || !request.__is_metamask) return {}
126+
// 1b: Add `type` to the request
127+
return {
128+
type: request.type,
129+
}
130+
}
131+
// 2: Standard call to formatter
132+
return formatTransactionRequest(request)
133+
}
134+
135+
const chains = getChainsFromUrl().map((c) => ({
136+
...c,
137+
formatters: {
138+
...(c.formatters || {}),
139+
transactionRequest: {
140+
format: formatExtraTransactionRequestParameters,
141+
},
142+
},
143+
})) as unknown as readonly [SupportedChain, ...SupportedChain[]]
91144

92145
const wagmiConfig_ = createConfig({
93146
syncConnectedChain: false,

src/utils/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GetPriceReturnType } from '@ensdomains/ensjs/public'
77
import { DecodedFuses } from '@ensdomains/ensjs/utils'
88

99
import { KNOWN_RESOLVER_DATA } from '@app/constants/resolverAddressData'
10+
import type { ConnectorClientWithEns } from '@app/types'
1011

1112
import { CURRENCY_FLUCTUATION_BUFFER_PERCENTAGE } from './constants'
1213
import { calculateDatesDiff } from './date'
@@ -231,3 +232,14 @@ export const hslToHex = (hsl: string) => {
231232
export const hasParaConnection = (connections: Connection[]) => {
232233
return connections?.some((connection) => connection?.connector?.id === 'para-integrated')
233234
}
235+
236+
export const connectorIsMetaMask = (
237+
connections: Connection[],
238+
connectorClient: ConnectorClientWithEns,
239+
) => {
240+
return connections?.some(
241+
(connection) =>
242+
connection?.connector?.id === 'io.metamask' &&
243+
connection.accounts.some((a) => a === connectorClient.account.address),
244+
)
245+
}

0 commit comments

Comments
 (0)