Skip to content

Commit

Permalink
feat(ramp): add quotes expanded event
Browse files Browse the repository at this point in the history
  • Loading branch information
wachunei committed Feb 26, 2024
1 parent dfb5895 commit e286905
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
12 changes: 12 additions & 0 deletions app/components/UI/Ramp/Views/Quotes/Quotes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 30 additions & 1 deletion app/components/UI/Ramp/Views/Quotes/Quotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -739,7 +768,7 @@ function Quotes() {
label: strings(
'fiat_on_ramp_aggregator.explore_more_options',
),
onPress: () => setIsExpanded(true),
onPress: handleExpandQuotes,
},
]
: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2843,7 +2843,7 @@ exports[`Quotes renders correctly after animation with quotes 1`] = `
</View>
`;

exports[`Quotes renders correctly after animation with quotes and expanded 1`] = `
exports[`Quotes renders correctly after animation with quotes and expanded 2`] = `
<View
style={
Object {
Expand Down
20 changes: 18 additions & 2 deletions app/components/UI/Ramp/types/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,21 @@ interface RampTransaction {
order_id?: string;
}

interface RampQuotesExpanded {
payment_method_id: string;
currency_source: string;
currency_destination: string;
amount: number | string;
}

interface OnRampQuotesExpanded extends RampQuotesExpanded {
chain_id_destination: string;
}

interface OffRampQuotesExpanded extends RampQuotesExpanded {
chain_id_source: string;
}

export interface AnalyticsEvents {
BUY_BUTTON_CLICKED: BuyButtonClicked;
SELL_BUTTON_CLICKED: SellButtonClicked;
Expand All @@ -305,6 +320,9 @@ export interface AnalyticsEvents {
ONRAMP_QUOTES_RECEIVED: OnRampQuotesReceived;
OFFRAMP_QUOTES_RECEIVED: OffRampQuotesReceived;

ONRAMP_QUOTES_EXPANDED: OnRampQuotesExpanded;
OFFRAMP_QUOTES_EXPANDED: OffRampQuotesExpanded;

ONRAMP_PROVIDER_SELECTED: OnRampProviderSelected;
OFFRAMP_PROVIDER_SELECTED: OffRampProviderSelected;

Expand Down Expand Up @@ -341,6 +359,4 @@ export interface AnalyticsEvents {
OFFRAMP_SEND_TRANSACTION_INVOKED: RampTransaction;
OFFRAMP_SEND_TRANSACTION_CONFIRMED: RampTransaction;
OFFRAMP_SEND_TRANSACTION_REJECTED: RampTransaction;

// after redirection events will go here
}
4 changes: 4 additions & 0 deletions app/core/Analytics/MetaMetrics.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ enum EVENT_NAME {
ONRAMP_QUOTES_REQUESTED = 'On-ramp Quotes Requested',
ONRAMP_CANCELED = 'On-ramp Canceled',
ONRAMP_QUOTES_RECEIVED = 'On-ramp Quotes Received',
ONRAMP_QUOTES_EXPANDED = 'On-ramp Quotes Expanded',
ONRAMP_PROVIDER_SELECTED = 'On-ramp Provider Selected',
ONRAMP_PROVIDER_DETAILS_VIEWED = 'On-ramp Provider Details Viewed',
ONRAMP_DIRECT_PROVIDER_CLICKED = 'On-ramp Provider Custom Action Clicked',
Expand All @@ -227,6 +228,7 @@ enum EVENT_NAME {
OFFRAMP_QUOTES_REQUESTED = 'Off-ramp Quotes Requested',
OFFRAMP_CANCELED = 'Off-ramp Canceled',
OFFRAMP_QUOTES_RECEIVED = 'Off-ramp Quotes Received',
OFFRAMP_QUOTES_EXPANDED = 'Off-ramp Quotes Expanded',
OFFRAMP_PROVIDER_SELECTED = 'Off-ramp Provider Selected',
OFFRAMP_PROVIDER_DETAILS_VIEWED = 'Off-ramp Provider Details Viewed',
OFFRAMP_DIRECT_PROVIDER_CLICKED = 'Off-ramp Provider Custom Action Clicked',
Expand Down Expand Up @@ -592,6 +594,7 @@ const events = {
ONRAMP_QUOTES_REQUESTED: generateOpt(EVENT_NAME.ONRAMP_QUOTES_REQUESTED),
ONRAMP_CANCELED: generateOpt(EVENT_NAME.ONRAMP_CANCELED),
ONRAMP_QUOTES_RECEIVED: generateOpt(EVENT_NAME.ONRAMP_QUOTES_RECEIVED),
ONRAMP_QUOTES_EXPANDED: generateOpt(EVENT_NAME.ONRAMP_QUOTES_EXPANDED),
ONRAMP_PROVIDER_SELECTED: generateOpt(EVENT_NAME.ONRAMP_PROVIDER_SELECTED),
ONRAMP_PROVIDER_DETAILS_VIEWED: generateOpt(
EVENT_NAME.ONRAMP_PROVIDER_DETAILS_VIEWED,
Expand Down Expand Up @@ -628,6 +631,7 @@ const events = {
OFFRAMP_QUOTES_REQUESTED: generateOpt(EVENT_NAME.OFFRAMP_QUOTES_REQUESTED),
OFFRAMP_CANCELED: generateOpt(EVENT_NAME.OFFRAMP_CANCELED),
OFFRAMP_QUOTES_RECEIVED: generateOpt(EVENT_NAME.OFFRAMP_QUOTES_RECEIVED),
OFFRAMP_QUOTES_EXPANDED: generateOpt(EVENT_NAME.OFFRAMP_QUOTES_EXPANDED),
OFFRAMP_PROVIDER_SELECTED: generateOpt(EVENT_NAME.OFFRAMP_PROVIDER_SELECTED),
OFFRAMP_PROVIDER_DETAILS_VIEWED: generateOpt(
EVENT_NAME.OFFRAMP_PROVIDER_DETAILS_VIEWED,
Expand Down

0 comments on commit e286905

Please sign in to comment.