From 413159818fc0e44315041dba2daf73a87d021d53 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 3 May 2024 16:27:46 +0500 Subject: [PATCH] fix(widget): log an error when partnerFee was discarded (#4403) --- .../updaters/InjectedWidgetUpdater.tsx | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/apps/cowswap-frontend/src/modules/injectedWidget/updaters/InjectedWidgetUpdater.tsx b/apps/cowswap-frontend/src/modules/injectedWidget/updaters/InjectedWidgetUpdater.tsx index 26990b7edf..02fbab08c1 100644 --- a/apps/cowswap-frontend/src/modules/injectedWidget/updaters/InjectedWidgetUpdater.tsx +++ b/apps/cowswap-frontend/src/modules/injectedWidget/updaters/InjectedWidgetUpdater.tsx @@ -1,10 +1,9 @@ import { useAtom, useSetAtom } from 'jotai' import { useEffect, useRef } from 'react' -import { useFeatureFlags } from '@cowprotocol/common-hooks' +import { usePrevious } from '@cowprotocol/common-hooks' import { deepEqual } from '@cowprotocol/common-utils' import { - CowSwapWidgetAppParams, listenToMessageFromWindow, postMessageToWindow, stopListeningWindowListener, @@ -13,6 +12,7 @@ import { WidgetMethodsListen, } from '@cowprotocol/widget-lib' +import * as Sentry from '@sentry/browser' import { useNavigate } from 'react-router-dom' import { IframeResizer } from './IframeResizer' @@ -36,12 +36,6 @@ const cacheMessages = (event: MessageEvent) => { messagesCache[method] = event.data } -const paramsWithoutPartnerFee = (params: CowSwapWidgetAppParams) => { - const { partnerFee: _, ...rest } = params - - return rest -} - /** * To avoid delays, immediately send an activation message and start listening messages */ @@ -56,10 +50,16 @@ const paramsWithoutPartnerFee = (params: CowSwapWidgetAppParams) => { })() export function InjectedWidgetUpdater() { - const { isPartnerFeeEnabled } = useFeatureFlags() - const [{ errors: validationErrors }, updateParams] = useAtom(injectedWidgetParamsAtom) + const [ + { + errors: validationErrors, + params: { partnerFee }, + }, + updateParams, + ] = useAtom(injectedWidgetParamsAtom) const updateMetaData = useSetAtom(injectedWidgetMetaDataAtom) + const prevPartnerFee = usePrevious(partnerFee) const navigate = useNavigate() const prevData = useRef(null) @@ -74,8 +74,7 @@ export function InjectedWidgetUpdater() { // Update params prevData.current = data - // Ignore partner fee value when feature flag is not enabled - const appParams = isPartnerFeeEnabled ? data.appParams : paramsWithoutPartnerFee(data.appParams) + const appParams = data.appParams const errors = validateWidgetParams(appParams) @@ -105,7 +104,25 @@ export function InjectedWidgetUpdater() { stopListeningWindowListener(window, updateParamsListener) stopListeningWindowListener(window, updateAppDataListener) } - }, [updateMetaData, navigate, updateParams, isPartnerFeeEnabled]) + }, [updateMetaData, navigate, updateParams]) + + // Log an error when partnerFee was set and then discarded + useEffect(() => { + if (prevPartnerFee || !partnerFee) { + const sentryError = Object.assign( + new Error(`BPS: ${prevPartnerFee?.bps}, recipient: ${prevPartnerFee?.recipient}`), + { + name: 'PartnerFeeDiscarded', + } + ) + + Sentry.captureException(sentryError, { + tags: { + errorType: 'PartnerFeeDiscarded', + }, + }) + } + }, [partnerFee, prevPartnerFee]) return ( <>