-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix: dedicated convert mUSD details cp-13.41.0 #44586
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
Changes from 2 commits
99b9aa4
d1ac92e
48536be
ba39d23
a82b3d1
df03a38
7e9c5b2
655a1a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { useSelector } from 'react-redux'; | ||
| import { selectLocalTransactionsByHash } from '../../selectors/activity'; | ||
|
|
||
| /** | ||
| * Used for enriching activity items with local-only data. | ||
| * This is where `metamaskPay` and other per-transaction metadata live. | ||
| * | ||
| * @param hash - The activity item hash | ||
| */ | ||
| export function useTransactionMeta(hash: string | undefined) { | ||
| const localTransactionsByHash = useSelector(selectLocalTransactionsByHash); | ||
| return localTransactionsByHash.get((hash ?? '').toLowerCase()) | ||
| ?.initialTransaction; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import React, { useMemo } from 'react'; | ||
| import { toEvmCaipChainId } from '@metamask/multichain-network-controller'; | ||
| import type { | ||
| ActivityListItem, | ||
| TokenAmount, | ||
| } from '../../../../shared/lib/activity/types'; | ||
| import { useI18nContext } from '../../../hooks/useI18nContext'; | ||
| import { useFormatters } from '../../../hooks/useFormatters'; | ||
| import { useTransactionMeta } from '../../../hooks/activity/useTransactionMeta'; | ||
| import { useTransactionQuery } from '../../../hooks/activity/useTransactionQuery'; | ||
| import { Footer, PAY_FIAT_CURRENCY, Row, Section } from '../components/shared'; | ||
| import { ConvertAgainButton } from '../components/convert-again-button'; | ||
| import { MetadataSection, TokensSection } from '../components/sections'; | ||
| // eslint-disable-next-line import-x/no-restricted-paths | ||
| import { TransactionDetailsProvider } from '../../confirmations/components/activity/transaction-details-context'; | ||
| // eslint-disable-next-line import-x/no-restricted-paths | ||
| import { TransactionDetailsSummary } from '../../confirmations/components/activity/transaction-details-summary'; | ||
|
|
||
| function useSentToken( | ||
| baseToken: TokenAmount | undefined, | ||
| transactionMeta: ReturnType<typeof useTransactionMeta>, | ||
| ): TokenAmount | undefined { | ||
| const { sourceHash, tokenAddress, chainId } = | ||
| transactionMeta?.metamaskPay ?? {}; | ||
| const sourceChainId = chainId ? toEvmCaipChainId(chainId) : undefined; | ||
| const userAddress = transactionMeta?.txParams?.from?.toLowerCase(); | ||
|
|
||
| const { data: sourceTransaction } = useTransactionQuery({ | ||
| chainId: sourceChainId, | ||
| txHash: sourceHash, | ||
| enabled: Boolean(sourceHash && sourceChainId), | ||
| }); | ||
|
|
||
| return useMemo(() => { | ||
| if (!baseToken) { | ||
| return baseToken; | ||
| } | ||
| const transfers = sourceTransaction?.valueTransfers ?? []; | ||
| const payToken = tokenAddress?.toLowerCase(); | ||
| const sentTransfer = | ||
| transfers.find( | ||
| (transfer) => | ||
| transfer.contractAddress.toLowerCase() === payToken && | ||
| transfer.from.toLowerCase() === userAddress, | ||
| ) ?? | ||
| transfers.find( | ||
| (transfer) => transfer.contractAddress.toLowerCase() === payToken, | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| ); | ||
| return sentTransfer?.amount | ||
| ? { ...baseToken, amount: sentTransfer.amount } | ||
| : baseToken; | ||
| }, [baseToken, sourceTransaction, tokenAddress, userAddress]); | ||
| } | ||
|
|
||
| type Props = { | ||
| item: Extract< | ||
| ActivityListItem, | ||
| { | ||
| type: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. convert is currently shared in this union type |
||
| | 'swap' | ||
| | 'bridge' | ||
| | 'convert' | ||
| | 'lendingDeposit' | ||
| | 'lendingWithdrawal' | ||
| | 'wrap' | ||
| | 'unwrap'; | ||
| } | ||
| >; | ||
| }; | ||
|
|
||
| export function ConvertDetails({ item }: Props) { | ||
|
Check warning on line 71 in ui/pages/details/templates/convert-details.tsx
|
||
| const t = useI18nContext(); | ||
| const { formatCurrencyWithMinThreshold } = useFormatters(); | ||
| const transactionMeta = useTransactionMeta(item.hash); | ||
| const { networkFeeFiat, totalFiat } = transactionMeta?.metamaskPay ?? {}; | ||
| const sentToken = useSentToken(item.data.sourceToken, transactionMeta); | ||
|
|
||
| const formatFiat = (value?: string) => | ||
| value | ||
| ? formatCurrencyWithMinThreshold(Number(value), PAY_FIAT_CURRENCY) | ||
| : null; | ||
|
|
||
| if (!transactionMeta) { | ||
| return null; | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| return ( | ||
| <div className="flex grow flex-col"> | ||
| <div className="divide-y divide-border-muted"> | ||
| <TokensSection | ||
| tokens={[ | ||
| { label: t('youSent'), token: sentToken }, | ||
| { label: t('youReceived'), token: item.data.destinationToken }, | ||
| ]} | ||
| /> | ||
|
|
||
| <MetadataSection item={item} /> | ||
|
|
||
| <Section> | ||
| <Row | ||
| label={t('networkFee')} | ||
| testId="transaction-base-fee" | ||
| value={formatFiat(networkFeeFiat)} | ||
| /> | ||
| <Row | ||
| label={t('total')} | ||
| testId="transaction-breakdown-value-amount" | ||
| value={formatFiat(totalFiat)} | ||
| /> | ||
| </Section> | ||
|
|
||
| <Section> | ||
| <TransactionDetailsProvider transactionMeta={transactionMeta}> | ||
| <TransactionDetailsSummary /> | ||
| </TransactionDetailsProvider> | ||
| </Section> | ||
| </div> | ||
|
|
||
| <Footer> | ||
| <ConvertAgainButton sourceToken={item.data.sourceToken} /> | ||
| </Footer> | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import React from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { toEvmCaipChainId } from '@metamask/multichain-network-controller'; | ||
| import { | ||
| Button, | ||
|
|
@@ -12,7 +11,7 @@ import type { ActivityListItem } from '../../../../shared/lib/activity/types'; | |
| import { CHAIN_IDS } from '../../../../shared/constants/network'; | ||
| import { ActivityAvatar } from '../../../components/app/activity-list-item-avatar'; | ||
| import { usePerpsDepositConfirmation } from '../../../components/app/perps/hooks/usePerpsDepositConfirmation'; | ||
| import { selectLocalTransactionsByHash } from '../../../selectors/activity'; | ||
| import { useTransactionMeta } from '../../../hooks/activity/useTransactionMeta'; | ||
| // eslint-disable-next-line import-x/no-restricted-paths | ||
| import { TransactionDetailsProvider } from '../../confirmations/components/activity/transaction-details-context'; | ||
| // eslint-disable-next-line import-x/no-restricted-paths | ||
|
|
@@ -36,11 +35,6 @@ type Props = { | |
| >; | ||
| }; | ||
|
|
||
| function useTransactionMeta(hash: string | undefined) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extracted into useLocalTransactionMeta |
||
| const localTransactions = useSelector(selectLocalTransactionsByHash); | ||
| return localTransactions.get(hash || '')?.initialTransaction; | ||
| } | ||
|
|
||
| export function PerpsDepositDetails({ item }: Readonly<Props>) { | ||
| const t = useI18nContext(); | ||
| const { trigger: triggerDeposit } = usePerpsDepositConfirmation(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import React, { useMemo } from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { toEvmCaipChainId } from '@metamask/multichain-network-controller'; | ||
| import type { | ||
| ActivityListItem, | ||
|
|
@@ -9,7 +8,7 @@ import { toAssetId } from '../../../../shared/lib/asset-utils'; | |
| import { AccountName } from '../../../components/app/transaction/account-name'; | ||
| import { NetworkName } from '../../../components/app/transaction/network-name'; | ||
| import { TransactionStatus } from '../../../components/app/transaction/transaction-status'; | ||
| import { selectLocalTransactionsByHash } from '../../../selectors/activity'; | ||
| import { useTransactionMeta } from '../../../hooks/activity/useTransactionMeta'; | ||
| import { | ||
| ARBITRUM_USDC, | ||
| PERPS_CURRENCY, | ||
|
|
@@ -27,11 +26,6 @@ const ARBITRUM_USDC_ASSET_ID = toAssetId( | |
| toEvmCaipChainId(ARBITRUM_USDC.chainId), | ||
| ); | ||
|
|
||
| function useTransactionMeta(hash: string | undefined) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extracted into useLocalTransactionMeta |
||
| const localTransactions = useSelector(selectLocalTransactionsByHash); | ||
| return localTransactions.get(hash || '')?.initialTransaction; | ||
| } | ||
|
|
||
| export function PerpsDetails({ | ||
| item, | ||
| }: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import React from 'react'; | |
| import type { ActivityListItem } from '../../../../shared/lib/activity/types'; | ||
| import { ApprovalDetails } from './approval-details'; | ||
| import { BridgeDetails } from './bridge-details/bridge-details'; | ||
| import { ConvertDetails } from './convert-details'; | ||
| import { DefaultDetails } from './default-details'; | ||
| import { NftDetails } from './nft-details'; | ||
| import { PerpsDepositDetails } from './perps-deposit-details'; | ||
|
|
@@ -29,8 +30,9 @@ export function TemplateLoader({ item }: Props) { | |
| return <SendDetails item={item} />; | ||
| case 'bridge': | ||
| return <BridgeDetails item={item} />; | ||
| case 'swap': | ||
| case 'convert': | ||
| return <ConvertDetails item={item} />; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point of interest |
||
| case 'swap': | ||
| case 'lendingDeposit': | ||
| case 'lendingWithdrawal': | ||
| case 'wrap': | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted from other locally-enriched detail pages