Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add HighValueLoss emitter event #86

Merged
merged 10 commits into from
May 16, 2023

Conversation

dennyscode
Copy link
Contributor

packages/widget/src/types/events.ts Outdated Show resolved Hide resolved
packages/widget/src/types/events.ts Outdated Show resolved Hide resolved
packages/widget/src/types/events.ts Outdated Show resolved Hide resolved
Comment on lines 49 to 59
emitter.emit(WidgetEvent.RouteHighValueLoss, {
fromAmountUsd: route.fromAmountUSD,
gasCostUSD: route.gasCostUSD,
toAmountUSD: route.toAmountUSD,
valueLoss: Big(route.toAmountUSD || 0)
.div(Big(route.fromAmountUSD || 0).plus(Big(route.gasCostUSD || 0)))
.minus(1)
.mul(100)
.round(2, Big.roundUp)
.toString(),
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just emit events in the middle of the render phase. This should be wrapped in useEffect. Also, later on, if we decide bottom sheet to stay mounted all the time this can cause issues of firing event even when we don't show the bottom sheet to the user.

I think the best place to fire this event is after we call it to open:

tokenValueBottomSheetRef.current?.open();

Wdyt? 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chybisov Thanks for wrapping your head around this and finding that bug! 👍
The approach you pointed out was a good idea on the issue which I was focussing on first: Triggering the Emit once the HighValueLoss-message pops up.
Now, as I continued to work on, I thought: The best would be to emit an event whenever a user actually continues: That will be useful for later tracking.

Having that message emit is not a bad thing, but what really matters is when the user continues.
What do you think of that approach? Sure, I will return to your solution if you prefer!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Continue is also a great place to emit this event. I thought about this too, but I also thought maybe we want to track precisely the event of showing the bottom sheet 😅

@chybisov chybisov merged commit 69d3918 into main May 16, 2023
@chybisov chybisov deleted the LF-2949-add-widget-event-for-high-value-loss branch May 16, 2023 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants