Skip to content

Commit bd8a4ef

Browse files
authored
chore: tracking txs usd amounts to amplitude (#2564)
1 parent 86a9f8a commit bd8a4ef

File tree

13 files changed

+63
-3
lines changed

13 files changed

+63
-3
lines changed

src/components/transactions/Borrow/BorrowActions.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
MAX_UINT_AMOUNT,
77
ProtocolAction,
88
} from '@aave/contract-helpers';
9+
import { valueToBigNumber } from '@aave/math-utils';
910
import { Trans } from '@lingui/macro';
1011
import { BoxProps } from '@mui/material';
1112
import { useQueryClient } from '@tanstack/react-query';
@@ -126,6 +127,9 @@ export const BorrowActions = React.memo(
126127
asset: poolAddress,
127128
amount: amountToBorrow,
128129
assetName: poolReserve.name,
130+
amountUsd: valueToBigNumber(amountToBorrow)
131+
.multipliedBy(poolReserve.priceInUSD)
132+
.toString(),
129133
});
130134

131135
queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });

src/components/transactions/DebtSwitch/DebtSwitchActions.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
gasLimitRecommendations,
44
ProtocolAction,
55
} from '@aave/contract-helpers';
6+
import { valueToBigNumber } from '@aave/math-utils';
67
import { SignatureLike } from '@ethersproject/bytes';
78
import { Trans } from '@lingui/macro';
89
import { BoxProps } from '@mui/material';
@@ -194,6 +195,14 @@ export const DebtSwitchActions = ({
194195
txState: 'success',
195196
previousState: `${route.outputAmount} variable ${poolReserve.symbol}`,
196197
newState: `${route.inputAmount} variable ${targetReserve.symbol}`,
198+
amountUsd: valueToBigNumber(parseUnits(amountToSwap, poolReserve.decimals).toString())
199+
.multipliedBy(poolReserve.priceInUSD)
200+
.toString(),
201+
outAmountUsd: valueToBigNumber(
202+
parseUnits(amountToReceive, targetReserve.decimals).toString()
203+
)
204+
.multipliedBy(targetReserve.priceInUSD)
205+
.toString(),
197206
});
198207

199208
queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });

src/components/transactions/Repay/RepayActions.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { gasLimitRecommendations, InterestRate, ProtocolAction } from '@aave/contract-helpers';
2+
import { valueToBigNumber } from '@aave/math-utils';
23
import { TransactionResponse } from '@ethersproject/providers';
34
import { Trans } from '@lingui/macro';
45
import { BoxProps } from '@mui/material';
@@ -29,6 +30,7 @@ export interface RepayActionProps extends BoxProps {
2930
repayWithATokens: boolean;
3031
blocked?: boolean;
3132
maxApproveNeeded: string;
33+
maxAmountToRepay: string;
3234
}
3335

3436
export const RepayActions = ({
@@ -41,6 +43,7 @@ export const RepayActions = ({
4143
repayWithATokens,
4244
blocked,
4345
maxApproveNeeded,
46+
maxAmountToRepay,
4447
...props
4548
}: RepayActionProps) => {
4649
const [
@@ -197,8 +200,11 @@ export const RepayActions = ({
197200
action,
198201
txState: 'success',
199202
asset: poolAddress,
200-
amount: amountToRepay,
203+
amount: amountToRepay === '-1' ? maxAmountToRepay : amountToRepay,
201204
assetName: symbol,
205+
amountUsd: valueToBigNumber(amountToRepay === '-1' ? maxAmountToRepay : amountToRepay)
206+
.multipliedBy(poolReserve.priceInUSD)
207+
.toString(),
202208
});
203209

204210
queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });

src/components/transactions/Repay/RepayModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export const RepayModalContent = ({
289289
isWrongNetwork={isWrongNetwork}
290290
symbol={modalSymbol}
291291
repayWithATokens={repayWithATokens}
292+
maxAmountToRepay={maxAmountToRepay.toString(10)}
292293
/>
293294
</>
294295
);

src/components/transactions/Supply/SupplyActions.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { gasLimitRecommendations, ProtocolAction } from '@aave/contract-helpers';
2+
import { valueToBigNumber } from '@aave/math-utils';
23
import { TransactionResponse } from '@ethersproject/providers';
34
import { Trans } from '@lingui/macro';
45
import { BoxProps } from '@mui/material';
56
import { useQueryClient } from '@tanstack/react-query';
67
import { parseUnits } from 'ethers/lib/utils';
78
import React, { useEffect, useState } from 'react';
9+
import { useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
810
import { SignedParams, useApprovalTx } from 'src/hooks/useApprovalTx';
911
import { usePoolApprovedAmount } from 'src/hooks/useApprovedAmount';
1012
import { useModalContext } from 'src/hooks/useModal';
@@ -60,6 +62,7 @@ export const SupplyActions = React.memo(
6062
state.currentMarketData,
6163
])
6264
);
65+
const { reserves } = useAppDataContext();
6366
const {
6467
approvalTxState,
6568
mainTxState,
@@ -181,6 +184,12 @@ export const SupplyActions = React.memo(
181184
asset: poolAddress,
182185
amount: amountToSupply,
183186
assetName: symbol,
187+
amountUsd: (() => {
188+
const reserve = reserves.find((r) => r.underlyingAsset === poolAddress);
189+
return reserve
190+
? valueToBigNumber(amountToSupply).multipliedBy(reserve.priceInUSD).toString()
191+
: undefined;
192+
})(),
184193
});
185194

186195
queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });

src/components/transactions/Supply/SupplyModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ export const SupplyWrappedTokenModalContent = ({
475475
decimals={18}
476476
symbol={wrappedTokenConfig.tokenIn.symbol}
477477
isWrongNetwork={isWrongNetwork}
478+
reserve={poolReserve}
478479
/>
479480
) : (
480481
<SupplyActions

src/components/transactions/Supply/SupplyWrappedTokenActions.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { gasLimitRecommendations, ProtocolAction } from '@aave/contract-helpers';
2+
import { valueToBigNumber } from '@aave/math-utils';
23
import { SignatureLike } from '@ethersproject/bytes';
34
import { TransactionResponse } from '@ethersproject/providers';
45
import { Trans } from '@lingui/macro';
56
import { BoxProps } from '@mui/material';
67
import { useQueryClient } from '@tanstack/react-query';
78
import { parseUnits } from 'ethers/lib/utils';
89
import { useState } from 'react';
10+
import { ComputedReserveData } from 'src/hooks/app-data-provider/useAppDataProvider';
911
import { useApprovalTx } from 'src/hooks/useApprovalTx';
1012
import { useApprovedAmount } from 'src/hooks/useApprovedAmount';
1113
import { useModalContext } from 'src/hooks/useModal';
@@ -32,6 +34,7 @@ interface SupplyWrappedTokenActionProps extends BoxProps {
3234
symbol: string;
3335
tokenWrapperAddress: string;
3436
isWrongNetwork: boolean;
37+
reserve: ComputedReserveData;
3538
}
3639
export const SupplyWrappedTokenActions = ({
3740
tokenIn,
@@ -41,7 +44,8 @@ export const SupplyWrappedTokenActions = ({
4144
tokenWrapperAddress,
4245
isWrongNetwork,
4346
sx,
44-
...props
47+
reserve,
48+
...propsx
4549
}: SupplyWrappedTokenActionProps) => {
4650
const [user, estimateGasLimit, addTransaction, marketData] = useRootStore(
4751
useShallow((state) => [
@@ -174,6 +178,7 @@ export const SupplyWrappedTokenActions = ({
174178
asset: tokenIn,
175179
amount: amountToSupply,
176180
assetName: symbol,
181+
amountUsd: valueToBigNumber(amountToSupply).multipliedBy(reserve.priceInUSD).toString(),
177182
});
178183

179184
queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });
@@ -212,7 +217,7 @@ export const SupplyWrappedTokenActions = ({
212217
requiresApproval={requiresApproval}
213218
tryPermit={usePermit}
214219
sx={sx}
215-
{...props}
220+
{...propsx}
216221
/>
217222
);
218223
};

src/components/transactions/Withdraw/WithdrawActions.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ProtocolAction } from '@aave/contract-helpers';
2+
import { valueToBigNumber } from '@aave/math-utils';
23
import { Trans } from '@lingui/macro';
34
import { BoxProps } from '@mui/material';
45
import { useTransactionHandler } from 'src/helpers/useTransactionHandler';
@@ -42,6 +43,9 @@ export const WithdrawActions = ({
4243
amount: amountToWithdraw,
4344
assetName: poolReserve.name,
4445
asset: poolReserve.underlyingAsset,
46+
amountUsd: valueToBigNumber(amountToWithdraw)
47+
.multipliedBy(poolReserve.priceInUSD)
48+
.toString(),
4549
},
4650
protocolAction: ProtocolAction.withdraw,
4751
});

src/components/transactions/Withdraw/WithdrawAndSwitchActions.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ERC20Service, gasLimitRecommendations, ProtocolAction } from '@aave/contract-helpers';
2+
import { valueToBigNumber } from '@aave/math-utils';
23
import { SignatureLike } from '@ethersproject/bytes';
34
import { Trans } from '@lingui/macro';
45
import { BoxProps } from '@mui/material';
@@ -148,6 +149,14 @@ export const WithdrawAndSwitchActions = ({
148149
outAsset: targetReserve.underlyingAsset,
149150
outAssetName: targetReserve.name,
150151
outAmount: parseUnits(route.outputAmount, targetReserve.decimals).toString(),
152+
amountUsd: valueToBigNumber(parseUnits(route.inputAmount, poolReserve.decimals).toString())
153+
.multipliedBy(poolReserve.priceInUSD)
154+
.toString(),
155+
outAmountUsd: valueToBigNumber(
156+
parseUnits(route.outputAmount, targetReserve.decimals).toString()
157+
)
158+
.multipliedBy(targetReserve.priceInUSD)
159+
.toString(),
151160
});
152161
} catch (error) {
153162
const parsedError = getErrorTextFromError(error, TxAction.GAS_ESTIMATION, false);

src/modules/umbrella/UmbrellaActions.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
StakeTokenService,
66
UmbrellaBatchHelperService,
77
} from '@aave/contract-helpers';
8+
import { valueToBigNumber } from '@aave/math-utils';
89
import { Trans } from '@lingui/macro';
910
import { BoxProps } from '@mui/material';
1011
import { useQueryClient } from '@tanstack/react-query';
@@ -13,6 +14,7 @@ import { parseUnits } from 'ethers/lib/utils';
1314
import { useEffect, useState } from 'react';
1415
import { TxActionsWrapper } from 'src/components/transactions/TxActionsWrapper';
1516
import { APPROVAL_GAS_LIMIT, checkRequiresApproval } from 'src/components/transactions/utils';
17+
import { ComputedReserveData } from 'src/hooks/app-data-provider/useAppDataProvider';
1618
import { MergedStakeData } from 'src/hooks/stake/useUmbrellaSummary';
1719
import { SignedParams, useApprovalTx } from 'src/hooks/useApprovalTx';
1820
import { useApprovedAmount } from 'src/hooks/useApprovedAmount';
@@ -37,6 +39,7 @@ export interface StakeActionProps extends BoxProps {
3739
selectedToken: StakeInputAsset;
3840
event: string;
3941
isMaxSelected: boolean;
42+
reserve: ComputedReserveData;
4043
}
4144

4245
export const UmbrellaActions = ({
@@ -49,6 +52,7 @@ export const UmbrellaActions = ({
4952
event,
5053
stakeData,
5154
isMaxSelected,
55+
reserve,
5256
...props
5357
}: StakeActionProps) => {
5458
const queryClient = useQueryClient();
@@ -193,6 +197,7 @@ export const UmbrellaActions = ({
193197
action: ProtocolAction.umbrellaStake,
194198
amount: amountToStake,
195199
assetName: selectedToken.symbol,
200+
amountUsd: valueToBigNumber(amountToStake).multipliedBy(reserve.priceInUSD).toString(),
196201
});
197202

198203
queryClient.invalidateQueries({ queryKey: queryKeysFactory.umbrella });

0 commit comments

Comments
 (0)