Skip to content

Conversation

@vyorkin
Copy link
Contributor

@vyorkin vyorkin commented Apr 23, 2025

No description provided.

@vyorkin vyorkin self-assigned this Apr 23, 2025
@github-actions
Copy link

github-actions bot commented Apr 23, 2025

📦 build.zip [updated at Apr 25, 4:28:02 PM UTC]

@vyorkin vyorkin marked this pull request as ready for review April 23, 2025 14:37
emitter.on('finalQuoteReceived', ({ quote, formView, scope }) => {
const params = createParams({
request_name: 'swap_form_filled_out',
screen_name: scope === 'Swap' ? 'Swap' : 'Bridge',
Copy link
Collaborator

@zerts zerts Apr 23, 2025

Choose a reason for hiding this comment

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

I think, we can do

invariant(scope === 'Swap' || scope === 'Bridge')

And then

screen_name: scope,
client_scope: scope,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, yes, makes sense :) updated ✅


export interface FinalQuoteReceivedParams {
quote: Quote;
formView: FormViewForAnalytics;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because we went away from formView concept, we can rename this to formState?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated ✅

quantity: string | null;
}

function assetQuantityToValue(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can reuse the same function from src/shared/analytics/shared/addressActionToAnalytics.ts

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see. It is slightly different. Well, then it is on you to decide what to so with it. May be it is ok to keep it this way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated ✅

isHighValueLoss,
} from 'src/ui/pages/SwapForm/shared/price-impact';

function toMaybeArr<T>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one can be reused from src/shared/analytics/shared/addressActionToAnalytics.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated ✅

formView: FormViewForAnalytics;
quote: Quote;
}) {
const zerion_fee_percentage = quote.protocol_fee;
Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like we can extract all parts of the formView here and don't use it below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated ✅

}) {
const zerion_fee_percentage = quote.protocol_fee;
const feeAmount = quote.protocol_fee_amount;
const spendAsset = formView.spendAsset;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated ✅

usd_amount_received: toMaybeArr([usdAmountReceived]),
asset_amount_sent: toMaybeArr([quote.input_amount_estimation]),
asset_amount_received: toMaybeArr([quote.output_amount_estimation]),
asset_name_sent: toMaybeArr([formView.spendAsset?.name]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated ✅

enough_balance,
enough_allowance: Boolean(quote.transaction),
warning_was_shown: isHighLoss,
// TODO add fdv_asset_sent
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add this in this PR?
Endpoint is ready to be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added missing fields ✅

@vyorkin vyorkin mentioned this pull request Apr 24, 2025
request_name: 'swap_form_filled_out',
screen_name: scope,
client_scope: scope,
action_type: scope,
Copy link
Collaborator

Choose a reason for hiding this comment

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

action_type can be Trade or Send 🫠🫠🫠

Copy link
Contributor Author

@vyorkin vyorkin Apr 25, 2025

Choose a reason for hiding this comment

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

in general it can, but not in formFilledOut event handler
so the scope should be of type scope: "Swap" | "Bridge" in FormFilledOutParams (if I'm not missing smth)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update this part in a minute

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated ✅

fdv_asset_sent: fdvAssetSent,
fdv_asset_received: fdvAssetReceived,
bridge_fee_usd_amount: bridgeFeeAmountInUsd,
outputAmountColor,
Copy link
Collaborator

Choose a reason for hiding this comment

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

output_amount_color: outputAmountColor

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also something is not right with these conditions
Zerts Screenshot 2025-04-24 at 17 54 04@2x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, thanks! it should be

  const outputAmountColor =
    priceImpact && isSignificantValueLoss(priceImpact) ? 'red' : 'grey';

updated ✅

contract_type: quote.contract_metadata?.name,
enough_balance,
enough_allowance: Boolean(quote.transaction),
warning_was_shown: isHighPriceImpact,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something is not right here
Zerts Screenshot 2025-04-24 at 17 56 38@2x
But I can't understand what exactly

Copy link
Contributor Author

@vyorkin vyorkin Apr 25, 2025

Choose a reason for hiding this comment

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

should be fixed, just checked locally ✅

return {
usd_amount_sent: toMaybeArr([usdAmountSend]),
usd_amount_received: toMaybeArr([usdAmountReceived]),
asset_amount_sent: toMaybeArr([quote.input_amount_estimation]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to convert these values? Need to be checked

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right now it shows value in gwei, not in the token itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we convert values like these in addressActionToAnalytics so probably I should do the same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, updated ✅

@vyorkin vyorkin requested a review from zerts April 25, 2025 14:02
enabled?: boolean;
mapResponse?: (response: unknown) => T;
mergeResponse?(currentValue: T | null, nextValue: T | null): T | null;
onEnd?: (value: null | T) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about onDone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That way my first though as well, but ended up naming it onEnd to match the existing event name and the corresponding event handler

return updatedItem || item;
});
},
onEnd: (quotes) => emitter.emit('quotesReceived', quotes),
Copy link
Collaborator

@zerts zerts Apr 25, 2025

Choose a reason for hiding this comment

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

Can we add a param to useQuotes({ onEnd })?
To avoid event emitter here. Not sure is it important or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great idead, updated ✅

`${url ?? 'no-url'}-${refetchHash}`,
url ?? null,
{
mergeResponse: (currentValue, nextValue) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove this param completely from useEventSource

@zerts zerts closed this Nov 3, 2025
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.

3 participants