Skip to content

Commit

Permalink
Disable WC notifications for cross-VM sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Mar 10, 2025
1 parent c4e49fe commit 2371ec7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/fcl-ethereum-provider/src/wc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const BASE_WC_SERVICE = (
},
params: {
externalProvider,
disableNotifications: true,
},
}) as unknown as Service

Expand Down Expand Up @@ -84,7 +85,10 @@ export class WalletConnectEthereumProvider extends EthereumProvider {
(externalProviderTopic == null ||
externalProviderTopic === provider.signer.session.topic)
) {
await fclUser.authenticate({service: wcService, forceReauth: true})
await fclUser.authenticate({
service: wcService,
forceReauth: true,
})
} else if (!provider.signer.session) {
// If no session is set but FCL is still authenticated, unauthenticate the user
await fclUser.unauthenticate()
Expand Down
8 changes: 6 additions & 2 deletions packages/fcl-wc/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ const makeExec = (
const {
wcRequestHook,
pairingModalOverride,
disableNotifications: appDisabledNotifications,
disableNotifications: _appDisabledNotifications,
} = config

const appDisabledNotifications =
service.params?.disableNotifications ?? _appDisabledNotifications

const resolvedProvider = await resolveProvider({
provider: signerPromise,
externalProviderOrTopic: service.params?.externalProvider,
Expand Down Expand Up @@ -155,6 +158,7 @@ const makeExec = (
provider,
abortSignal,
isExternal,
disableNotifications: service.params?.disableNotifications,
}).finally(() => notification?.dismiss())

function validateAppLink({uid}: {uid: string}) {
Expand Down Expand Up @@ -282,7 +286,7 @@ function connectWc(
onClose()
throw error
} finally {
// walletConnectModal?.closeModal()
walletConnectModal?.closeModal()
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/fcl-wc/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ export const request = async ({
provider,
isExternal,
abortSignal,
disableNotifications,
}: {
method: any
body: any
session: SessionTypes.Struct
provider: InstanceType<typeof UniversalProvider>
isExternal?: boolean
abortSignal?: AbortSignal
disableNotifications?: boolean
}) => {
const [chainId, addr, address] = makeSessionData(session)
const data = JSON.stringify({...body, addr, address})
Expand Down Expand Up @@ -95,21 +97,22 @@ export const request = async ({

switch (result.status) {
case "APPROVED":
function normalizeService(service: Service) {
function addSessionInfo(service: Service) {
if (service.method === "WC/RPC") {
return {
...service,
params: {
...service.params,
...(isExternal ? {externalProvider: session.topic} : {}),
...(disableNotifications ? {disableNotifications} : {}),
},
}
}
return service
}

if (method === FLOW_METHODS.FLOW_AUTHN) {
const services = (result?.data?.services ?? []).map(normalizeService)
const services = (result?.data?.services ?? []).map(addSessionInfo)

return {
...(result.data ? result.data : {}),
Expand All @@ -121,10 +124,10 @@ export const request = async ({
return {
...result.data,
...(result.data?.proposer
? {proposer: normalizeService(result.data.proposer)}
? {proposer: addSessionInfo(result.data.proposer)}
: {}),
payer: [...result.data?.payer?.map(normalizeService)],
authorization: [...result.data?.authorization?.map(normalizeService)],
payer: [...result.data?.payer?.map(addSessionInfo)],
authorization: [...result.data?.authorization?.map(addSessionInfo)],
}
}

Expand Down

0 comments on commit 2371ec7

Please sign in to comment.