Skip to content

Commit

Permalink
analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepuppy committed Feb 16, 2024
1 parent 756a346 commit f397b91
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/views/dialogs/DepositDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ export const DepositDialog = ({ setIsOpen }: ElementProps) => {
const stringGetter = useStringGetter();
const { isMobile } = useBreakpoints();

const closeDialog = () => setIsOpen?.(false);

return (
<Dialog
isOpen
setIsOpen={setIsOpen}
title={stringGetter({ key: STRING_KEYS.DEPOSIT })}
placement={isMobile ? DialogPlacement.FullScreen : DialogPlacement.Default}
>
<DepositDialogContent onDeposit={closeDialog} />
<DepositDialogContent />
</Dialog>
);
};
16 changes: 14 additions & 2 deletions src/views/dialogs/DepositDialog/DepositDialogContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { useEffect, useState } from 'react';
import styled, { type AnyStyledComponent } from 'styled-components';

import { TransferInputField, TransferType } from '@/constants/abacus';
import { AnalyticsEvent } from '@/constants/analytics';
import { isMainnet } from '@/constants/networks';
import { layoutMixins } from '@/styles/layoutMixins';

import { DepositForm } from '@/views/forms/AccountManagementForms/DepositForm';
import { TestnetDepositForm } from '@/views/forms/AccountManagementForms/TestnetDepositForm';

import abacusStateManager from '@/lib/abacus';
import { track } from '@/lib/analytics';

type ElementProps = {
onDeposit?: () => void;
Expand All @@ -34,9 +36,19 @@ export const DepositDialogContent = ({ onDeposit }: ElementProps) => {
return (
<Styled.Content>
{isMainnet || !showFaucet ? (
<DepositForm onDeposit={onDeposit} />
<DepositForm
onDeposit={(event) => {
track(AnalyticsEvent.TransferDeposit, event);
onDeposit?.();
}}
/>
) : (
<TestnetDepositForm onDeposit={onDeposit} />
<TestnetDepositForm
onDeposit={() => {
track(AnalyticsEvent.TransferFaucet);
onDeposit?.();
}}
/>
)}
{!isMainnet && (
<Styled.TextToggle onClick={() => setShowFaucet(!showFaucet)}>
Expand Down
8 changes: 6 additions & 2 deletions src/views/forms/AccountManagementForms/DepositForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ export const DepositForm = ({ onDeposit, onError }: DepositFormProps) => {
};
const txHash = await signerWagmi.sendTransaction(tx);

onDeposit?.();

if (txHash) {
addTransferNotification({
txHash: txHash,
Expand All @@ -272,6 +270,12 @@ export const DepositForm = ({ onDeposit, onError }: DepositFormProps) => {
});
abacusStateManager.clearTransferInputValues();
setFromAmount('');

onDeposit?.({
chainId: chainIdStr || undefined,
tokenAddress: sourceToken?.address || undefined,
tokenSymbol: sourceToken?.symbol || undefined,
});
}
} catch (error) {
log('DepositForm/onSubmit', error);
Expand Down
25 changes: 19 additions & 6 deletions src/views/forms/AccountManagementForms/WithdrawForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import { getNobleChainId } from '@/lib/squid';
import { TokenSelectMenu } from './TokenSelectMenu';
import { WithdrawButtonAndReceipt } from './WithdrawForm/WithdrawButtonAndReceipt';
import { validateCosmosAddress } from '@/lib/addressUtils';
import { track } from '@/lib/analytics';
import { AnalyticsEvent } from '@/constants/analytics';

export const WithdrawForm = () => {
const stringGetter = useStringGetter();
Expand Down Expand Up @@ -183,18 +185,25 @@ export const WithdrawForm = () => {
);
if (txHash) {
const nobleChainId = getNobleChainId();
const toChainId = Boolean(exchange) ? nobleChainId : chainIdStr || undefined;
addTransferNotification({
txHash: txHash,
type: TransferNotificationTypes.Withdrawal,
fromChainId: !isCctp ? selectedDydxChainId : nobleChainId,
toChainId: Boolean(exchange) ? nobleChainId : chainIdStr || undefined,
toChainId,
toAmount: debouncedAmountBN.toNumber(),
triggeredAt: Date.now(),
isCctp,
isExchange: Boolean(exchange),
});
abacusStateManager.clearTransferInputValues();
setWithdrawAmount('');

track(AnalyticsEvent.TransferWithdraw, {
chainId: toChainId,
tokenAddress: toToken?.address || undefined,
tokenSymbol: toToken?.symbol || undefined,
});
}
}
} catch (error) {
Expand Down Expand Up @@ -222,10 +231,11 @@ export const WithdrawForm = () => {
debouncedAmountBN,
chainIdStr,
toAddress,
screenAddresses,
stringGetter,
selectedDydxChainId,
exchange,
toToken,
screenAddresses,
stringGetter,
]
);

Expand Down Expand Up @@ -380,16 +390,19 @@ export const WithdrawForm = () => {
summary,
]);

const isInvalidNobleAddress = Boolean(
exchange && toAddress && !validateCosmosAddress(toAddress, 'noble')
);

const isDisabled =
!!errorMessage ||
!toToken ||
(!chainIdStr && !exchange) ||
!toAddress ||
debouncedAmountBN.isNaN() ||
debouncedAmountBN.isZero() ||
isLoading;

const isInvalidNobleAddress = exchange && toAddress && !validateCosmosAddress(toAddress, 'noble');
isLoading ||
isInvalidNobleAddress;

return (
<Styled.Form onSubmit={onSubmit}>
Expand Down

0 comments on commit f397b91

Please sign in to comment.