-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98a1064
commit 8f29230
Showing
10 changed files
with
237 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 6 additions & 14 deletions
20
ui/pages/confirmations/components/confirm/info/shared/send-heading/send-heading.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
ui/pages/confirmations/components/confirm/info/token-transfer/name.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { NameType } from '@metamask/name-controller'; | ||
import React, { useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useFallbackDisplayName } from '../../../../../../components/app/confirm/info/row/hook'; | ||
import NicknamePopovers from '../../../../../../components/app/modals/nickname-popovers'; | ||
import Name from '../../../../../../components/app/name'; | ||
import { | ||
AvatarAccount, | ||
AvatarAccountSize, | ||
Box, | ||
Text, | ||
} from '../../../../../../components/component-library'; | ||
import { | ||
AlignItems, | ||
BorderColor, | ||
Display, | ||
FlexDirection, | ||
TextColor, | ||
} from '../../../../../../helpers/constants/design-system'; | ||
import { getPetnamesEnabled } from '../../../../../../selectors'; | ||
|
||
export const NameOrAddressDisplay = ({ address }: { address: string }) => { | ||
const isPetNamesEnabled = useSelector(getPetnamesEnabled); | ||
const { displayName, hexAddress } = useFallbackDisplayName(address); | ||
const [isNicknamePopoverShown, setIsNicknamePopoverShown] = useState(false); | ||
const handleDisplayNameClick = () => setIsNicknamePopoverShown(true); | ||
const onCloseHandler = () => setIsNicknamePopoverShown(false); | ||
|
||
if (isPetNamesEnabled) { | ||
return <Name value={hexAddress} type={NameType.ETHEREUM_ADDRESS} />; | ||
} | ||
|
||
return ( | ||
<> | ||
<Box | ||
display={Display.Flex} | ||
flexDirection={FlexDirection.Row} | ||
alignItems={AlignItems.center} | ||
onClick={handleDisplayNameClick} | ||
> | ||
<AvatarAccount | ||
address={address} | ||
size={AvatarAccountSize.Xs} | ||
borderColor={BorderColor.transparent} | ||
/> | ||
<Text | ||
marginLeft={2} | ||
color={TextColor.inherit} | ||
data-testid="confirm-info-row-display-name" | ||
> | ||
{displayName} | ||
</Text> | ||
</Box> | ||
{isNicknamePopoverShown ? ( | ||
<NicknamePopovers onClose={onCloseHandler} address={hexAddress} /> | ||
) : null} | ||
</> | ||
); | ||
}; |
79 changes: 79 additions & 0 deletions
79
ui/pages/confirmations/components/confirm/info/token-transfer/token-details-section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { TransactionMeta } from '@metamask/transaction-controller'; | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP } from '../../../../../../../shared/constants/network'; | ||
import { | ||
ConfirmInfoRow, | ||
ConfirmInfoRowAddress, | ||
} from '../../../../../../components/app/confirm/info/row'; | ||
import { ConfirmInfoSection } from '../../../../../../components/app/confirm/info/row/section'; | ||
import { | ||
AvatarNetwork, | ||
AvatarNetworkSize, | ||
Box, | ||
Text, | ||
} from '../../../../../../components/component-library'; | ||
import { | ||
AlignItems, | ||
BlockSize, | ||
BorderColor, | ||
Display, | ||
FlexWrap, | ||
TextColor, | ||
TextVariant, | ||
} from '../../../../../../helpers/constants/design-system'; | ||
import { useI18nContext } from '../../../../../../hooks/useI18nContext'; | ||
import { | ||
getCurrentChainId, | ||
getNetworkConfigurationsByChainId, | ||
} from '../../../../../../selectors'; | ||
import { useConfirmContext } from '../../../../context/confirm'; | ||
|
||
export const TokenDetailsSection = () => { | ||
const t = useI18nContext(); | ||
const { currentConfirmation: transactionMeta } = | ||
useConfirmContext<TransactionMeta>(); | ||
|
||
const chainId = useSelector(getCurrentChainId); | ||
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId); | ||
const networkName = networkConfigurations[chainId].name; | ||
|
||
const networkRow = ( | ||
<ConfirmInfoRow label={t('transactionFlowNetwork')}> | ||
<Box | ||
display={Display.Flex} | ||
alignItems={AlignItems.center} | ||
flexWrap={FlexWrap.Wrap} | ||
gap={2} | ||
minWidth={BlockSize.Zero} | ||
> | ||
<AvatarNetwork | ||
borderColor={BorderColor.backgroundDefault} | ||
size={AvatarNetworkSize.Sm} | ||
src={ | ||
CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[ | ||
chainId as keyof typeof CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP | ||
] | ||
} | ||
name={networkName} | ||
/> | ||
<Text variant={TextVariant.bodyMd} color={TextColor.textDefault}> | ||
{networkName} | ||
</Text> | ||
</Box> | ||
</ConfirmInfoRow> | ||
); | ||
|
||
const tokenRow = ( | ||
<ConfirmInfoRow label={t('interactingWith')}> | ||
<ConfirmInfoRowAddress address={transactionMeta.txParams.to as string} /> | ||
</ConfirmInfoRow> | ||
); | ||
|
||
return ( | ||
<ConfirmInfoSection data-testid="confirmation__transaction-flow"> | ||
{networkRow} | ||
{tokenRow} | ||
</ConfirmInfoSection> | ||
); | ||
}; |
20 changes: 19 additions & 1 deletion
20
ui/pages/confirmations/components/confirm/info/token-transfer/token-transfer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectConfirmationAdvancedDetailsOpen } from '../../../../selectors/preferences'; | ||
import { AdvancedDetails } from '../shared/advanced-details/advanced-details'; | ||
import { GasFeesSection } from '../shared/gas-fees-section/gas-fees-section'; | ||
import SendHeading from '../shared/send-heading/send-heading'; | ||
import { TokenDetailsSection } from './token-details-section'; | ||
import { TransactionFlowSection } from './transaction-flow-section'; | ||
|
||
const TokenTransferInfo = () => { | ||
return <SendHeading />; | ||
const showAdvancedDetails = useSelector( | ||
selectConfirmationAdvancedDetailsOpen, | ||
); | ||
|
||
return ( | ||
<> | ||
<SendHeading /> | ||
<TransactionFlowSection /> | ||
<TokenDetailsSection /> | ||
<GasFeesSection /> | ||
{showAdvancedDetails && <AdvancedDetails />} | ||
</> | ||
); | ||
}; | ||
|
||
export default TokenTransferInfo; |
55 changes: 55 additions & 0 deletions
55
ui/pages/confirmations/components/confirm/info/token-transfer/transaction-flow-section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { TransactionMeta } from '@metamask/transaction-controller'; | ||
import React from 'react'; | ||
import { ConfirmInfoSection } from '../../../../../../components/app/confirm/info/row/section'; | ||
import { | ||
Box, | ||
Icon, | ||
IconName, | ||
IconSize, | ||
} from '../../../../../../components/component-library'; | ||
import { | ||
AlignItems, | ||
Display, | ||
FlexDirection, | ||
IconColor, | ||
JustifyContent, | ||
} from '../../../../../../helpers/constants/design-system'; | ||
import { useConfirmContext } from '../../../../context/confirm'; | ||
import { useDecodedTransactionData } from '../hooks/useDecodedTransactionData'; | ||
import { NameOrAddressDisplay } from './name'; | ||
|
||
export const TransactionFlowSection = () => { | ||
const { currentConfirmation: transactionMeta } = | ||
useConfirmContext<TransactionMeta>(); | ||
|
||
const { value, pending } = useDecodedTransactionData(); | ||
|
||
const recipientAddress = | ||
value?.data[0].params.find((param) => param.type === 'address')?.value || | ||
'0x0000000000000000000000000000000000000000'; | ||
|
||
if (pending) { | ||
// TODO: ConfirmPendingLoader when papercuts PR is merged | ||
return null; | ||
} | ||
|
||
return ( | ||
<ConfirmInfoSection data-testid="confirmation__transaction-flow"> | ||
<Box | ||
display={Display.Flex} | ||
flexDirection={FlexDirection.Row} | ||
justifyContent={JustifyContent.spaceBetween} | ||
alignItems={AlignItems.center} | ||
padding={3} | ||
> | ||
<NameOrAddressDisplay address={transactionMeta.txParams.from} /> | ||
<Icon | ||
name={IconName.ArrowRight} | ||
size={IconSize.Md} | ||
color={IconColor.iconMuted} | ||
/> | ||
<NameOrAddressDisplay address={recipientAddress} /> | ||
</Box> | ||
</ConfirmInfoSection> | ||
); | ||
}; |