From e286905f5e270978c7dc47cced05617d03549683 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Aste Kompen Date: Mon, 26 Feb 2024 12:28:52 -0300 Subject: [PATCH] feat(ramp): add quotes expanded event --- .../UI/Ramp/Views/Quotes/Quotes.test.tsx | 12 +++++++ .../UI/Ramp/Views/Quotes/Quotes.tsx | 31 ++++++++++++++++++- .../Quotes/__snapshots__/Quotes.test.tsx.snap | 2 +- app/components/UI/Ramp/types/analytics.ts | 20 ++++++++++-- app/core/Analytics/MetaMetrics.events.ts | 4 +++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx b/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx index 4d82d4c8d25a..86d8f9b5a930 100644 --- a/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx +++ b/app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx @@ -251,6 +251,18 @@ describe('Quotes', () => { jest.advanceTimersByTime(3000); jest.clearAllTimers(); }); + expect(mockTrackEvent.mock.lastCall).toMatchInlineSnapshot(` + Array [ + "ONRAMP_QUOTES_EXPANDED", + Object { + "amount": 50, + "chain_id_destination": "1", + "currency_destination": "ETH", + "currency_source": "USD", + "payment_method_id": "/payment-methods/test-payment-method", + }, + ] + `); expect(screen.toJSON()).toMatchSnapshot(); act(() => { jest.useRealTimers(); diff --git a/app/components/UI/Ramp/Views/Quotes/Quotes.tsx b/app/components/UI/Ramp/Views/Quotes/Quotes.tsx index 90453d7e0084..da931aea184e 100644 --- a/app/components/UI/Ramp/Views/Quotes/Quotes.tsx +++ b/app/components/UI/Ramp/Views/Quotes/Quotes.tsx @@ -230,6 +230,35 @@ function Quotes() { trackEvent, ]); + const handleExpandQuotes = useCallback(() => { + setIsExpanded(true); + const payload = { + payment_method_id: selectedPaymentMethodId as string, + currency_source: params.fiatCurrency?.symbol, + currency_destination: params.asset?.symbol, + amount: params.amount, + }; + if (isBuy) { + trackEvent('ONRAMP_QUOTES_EXPANDED', { + ...payload, + chain_id_destination: selectedChainId, + }); + } else { + trackEvent('OFFRAMP_QUOTES_EXPANDED', { + ...payload, + chain_id_source: selectedChainId, + }); + } + }, [ + isBuy, + params.amount, + params.asset?.symbol, + params.fiatCurrency?.symbol, + selectedChainId, + selectedPaymentMethodId, + trackEvent, + ]); + const handleOnQuotePress = useCallback( (quote: QuoteResponse | SellQuoteResponse) => { setProviderId(quote.provider.id); @@ -739,7 +768,7 @@ function Quotes() { label: strings( 'fiat_on_ramp_aggregator.explore_more_options', ), - onPress: () => setIsExpanded(true), + onPress: handleExpandQuotes, }, ] : [] diff --git a/app/components/UI/Ramp/Views/Quotes/__snapshots__/Quotes.test.tsx.snap b/app/components/UI/Ramp/Views/Quotes/__snapshots__/Quotes.test.tsx.snap index 5cadbcbb8380..7ac2cbd1ac0f 100644 --- a/app/components/UI/Ramp/Views/Quotes/__snapshots__/Quotes.test.tsx.snap +++ b/app/components/UI/Ramp/Views/Quotes/__snapshots__/Quotes.test.tsx.snap @@ -2843,7 +2843,7 @@ exports[`Quotes renders correctly after animation with quotes 1`] = ` `; -exports[`Quotes renders correctly after animation with quotes and expanded 1`] = ` +exports[`Quotes renders correctly after animation with quotes and expanded 2`] = `