Skip to content

Commit

Permalink
Swap actions analytics (#581)
Browse files Browse the repository at this point in the history
* Added event for click on swap from explore

* added analytics event for swap submit on form

* review fixes
  • Loading branch information
letier3110 authored Feb 22, 2022
1 parent a8e8fdd commit de38b35
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/app/pages/Explore.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum ExploreSelectors {
ReceiveButton = 'Explore/ReceiveButton',
SendButton = 'Explore/SendButton',
SwapButton = 'Explore/SwapButton',
AssetsTab = 'Explore/AssetsTab',
DelegationTab = 'Explore/DelegationTab',
ActivityTab = 'Explore/ActivityTab',
Expand Down
22 changes: 18 additions & 4 deletions src/app/pages/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ReactComponent as SwapIcon } from 'app/icons/swap.svg';
import PageLayout from 'app/layouts/PageLayout';
import Activity from 'app/templates/activity/Activity';
import AssetInfo from 'app/templates/AssetInfo';
import { TestIDProps } from 'lib/analytics';
import { T, t } from 'lib/i18n/react';
import {
getAssetSymbol,
Expand Down Expand Up @@ -113,6 +114,7 @@ const Explore: FC<ExploreProps> = ({ assetSlug }) => {
}}
disabled={!canSend}
tippyProps={tippyPropsMock}
testID={ExploreSelectors.SwapButton}
/>
<ActionButton
label={<T id="send" />}
Expand All @@ -133,15 +135,23 @@ const Explore: FC<ExploreProps> = ({ assetSlug }) => {

export default Explore;

type ActionButtonProps = {
interface ActionButtonProps extends TestIDProps {
label: React.ReactNode;
Icon: FunctionComponent<SVGProps<SVGSVGElement>>;
to: To;
disabled?: boolean;
tippyProps?: Partial<TippyProps>;
};
}

const ActionButton: FC<ActionButtonProps> = ({ label, Icon, to, disabled, tippyProps = {} }) => {
const ActionButton: FC<ActionButtonProps> = ({
label,
Icon,
to,
disabled,
tippyProps = {},
testID,
testIDProperties
}) => {
const buttonRef = useTippy<HTMLButtonElement>(tippyProps);
const commonButtonProps = useMemo(
() => ({
Expand All @@ -166,7 +176,11 @@ const ActionButton: FC<ActionButtonProps> = ({ label, Icon, to, disabled, tippyP
}),
[disabled, Icon, label]
);
return disabled ? <button ref={buttonRef} {...commonButtonProps} /> : <Link to={to} {...commonButtonProps} />;
return disabled ? (
<button ref={buttonRef} {...commonButtonProps} />
) : (
<Link testID={testID} testIDProperties={testIDProperties} to={to} {...commonButtonProps} />
);
};

const Delegation: FC = () => (
Expand Down
3 changes: 3 additions & 0 deletions src/app/templates/SwapForm/SwapForm.selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum SwapFormSelectors {
SwapSubmit = 'SwapForm/SwapSubmit'
}
2 changes: 2 additions & 0 deletions src/app/templates/SwapForm/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { HistoryAction, navigate } from 'lib/woozie';
import { SwapExchangeRate } from './SwapExchangeRate/SwapExchangeRate';
import { SwapFormValue, SwapInputValue, useSwapFormDefaultValue } from './SwapForm.form';
import styles from './SwapForm.module.css';
import { SwapFormSelectors } from './SwapForm.selectors';
import { feeInfoTippyProps } from './SwapForm.tippy';
import { SlippageToleranceInput } from './SwapFormInput/SlippageToleranceInput/SlippageToleranceInput';
import { slippageToleranceInputValidationFn } from './SwapFormInput/SlippageToleranceInput/SlippageToleranceInput.validation';
Expand Down Expand Up @@ -346,6 +347,7 @@ export const SwapForm: FC = () => {
}}
loading={isSubmitting}
onClick={handleSubmitButtonClick}
testID={SwapFormSelectors.SwapSubmit}
>
<T id="swap" />
</FormSubmitButton>
Expand Down
6 changes: 4 additions & 2 deletions src/lib/woozie/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement>, Test
replace?: boolean;
}

const Link: FC<LinkProps> = ({ to, replace, ...rest }) => {
const Link: FC<LinkProps> = ({ to, replace, testID, testIDProperties, ...rest }) => {
const lctn = useLocation();
const { trackEvent } = useAnalytics();

const { pathname, search, hash, state } = useMemo(() => createLocationUpdates(to, lctn), [to, lctn]);

Expand All @@ -20,10 +21,11 @@ const Link: FC<LinkProps> = ({ to, replace, ...rest }) => {
const href = useMemo(() => (USE_LOCATION_HASH_AS_URL ? `${window.location.pathname}#${url}` : url), [url]);

const handleNavigate = useCallback(() => {
testID !== undefined && trackEvent(testID, AnalyticsEventCategory.PageOpened, testIDProperties);
const action =
replace || url === createUrl(lctn.pathname, lctn.search, lctn.hash) ? HistoryAction.Replace : HistoryAction.Push;
changeState(action, state, url);
}, [replace, state, url, lctn]);
}, [replace, state, url, lctn, testID, testIDProperties, trackEvent]);

return <LinkAnchor {...rest} href={href} onNavigate={handleNavigate} />;
};
Expand Down

0 comments on commit de38b35

Please sign in to comment.