1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

NFT UX cleanup grab-bag (#13352)

* NFT UX cleanup
This commit is contained in:
Alex Donesky 2022-01-20 11:49:49 -06:00 committed by GitHub
parent e2a8886a05
commit db0230f23a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 106 additions and 70 deletions

View File

@ -243,6 +243,8 @@ export default class MetamaskController extends EventEmitter {
initState.CollectiblesController, initState.CollectiblesController,
); );
this.collectiblesController.setApiKey(process.env.OPENSEA_KEY);
process.env.COLLECTIBLES_V1 && process.env.COLLECTIBLES_V1 &&
(this.collectibleDetectionController = new CollectibleDetectionController( (this.collectibleDetectionController = new CollectibleDetectionController(
{ {
@ -648,8 +650,7 @@ export default class MetamaskController extends EventEmitter {
this.collectiblesController.checkAndUpdateSingleCollectibleOwnershipStatus( this.collectiblesController.checkAndUpdateSingleCollectibleOwnershipStatus(
knownCollectible, knownCollectible,
false, false,
// TODO add this when checkAndUpdateSingleCollectibleOwnershipStatus is updated { userAddress, chainId },
// { userAddress, chainId },
); );
} }
} }

View File

@ -130,6 +130,7 @@ export default function CollectibleDetails({ collectible }) {
<Box <Box
display={DISPLAY.FLEX} display={DISPLAY.FLEX}
width={inPopUp ? BLOCK_SIZES.FULL : BLOCK_SIZES.HALF} width={inPopUp ? BLOCK_SIZES.FULL : BLOCK_SIZES.HALF}
margin={inPopUp ? [4, 0] : null}
> >
<Button <Button
type="primary" type="primary"
@ -185,37 +186,39 @@ export default function CollectibleDetails({ collectible }) {
color={COLORS.BLACK} color={COLORS.BLACK}
variant={TYPOGRAPHY.H4} variant={TYPOGRAPHY.H4}
fontWeight={FONT_WEIGHT.BOLD} fontWeight={FONT_WEIGHT.BOLD}
boxProps={{ margin: 0, marginBottom: 4 }} boxProps={{ margin: 0, marginBottom: 2 }}
> >
{name} {name}
</Typography> </Typography>
<Typography <Typography
color={COLORS.UI3} color={COLORS.UI3}
variant={TYPOGRAPHY.H5} variant={TYPOGRAPHY.H5}
boxProps={{ margin: 0 }} boxProps={{ margin: 0, marginBottom: 4 }}
overflowWrap={OVERFLOW_WRAP.BREAK_WORD} overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
> >
#{tokenId} #{tokenId}
</Typography> </Typography>
</div> </div>
<div> {description ? (
<Typography <div>
color={COLORS.BLACK} <Typography
variant={TYPOGRAPHY.H6} color={COLORS.BLACK}
fontWeight={FONT_WEIGHT.BOLD} variant={TYPOGRAPHY.H6}
className="collectible-details__description" fontWeight={FONT_WEIGHT.BOLD}
boxProps={{ margin: 0, marginBottom: 2 }} className="collectible-details__description"
> boxProps={{ margin: 0, marginBottom: 2 }}
{t('description')} >
</Typography> {t('description')}
<Typography </Typography>
color={COLORS.UI4} <Typography
variant={TYPOGRAPHY.H6} color={COLORS.UI4}
boxProps={{ margin: 0, marginBottom: 4 }} variant={TYPOGRAPHY.H6}
> boxProps={{ margin: 0, marginBottom: 4 }}
{description} >
</Typography> {description}
</div> </Typography>
</div>
) : null}
{inPopUp ? null : renderSendButton()} {inPopUp ? null : renderSendButton()}
</Box> </Box>
</div> </div>
@ -241,13 +244,13 @@ export default function CollectibleDetails({ collectible }) {
margin: 0, margin: 0,
marginBottom: 4, marginBottom: 4,
}} }}
overflowWrap={OVERFLOW_WRAP.BREAK_WORD} className="collectible-details__image-link"
> >
<a <a
target="_blank" target="_blank"
href={collectibleImageURL}
rel="noopener noreferrer" rel="noopener noreferrer"
className="collectible-details__image-link" href={collectibleImageURL}
title={collectibleImageURL}
> >
{image} {image}
</a> </a>
@ -268,17 +271,18 @@ export default function CollectibleDetails({ collectible }) {
{t('contractAddress')} {t('contractAddress')}
</Typography> </Typography>
<Typography <Typography
color={COLORS.UI3} color={COLORS.PRIMARY1}
variant={TYPOGRAPHY.H6} variant={TYPOGRAPHY.H6}
overflowWrap={OVERFLOW_WRAP.BREAK_WORD} overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
boxProps={{ boxProps={{
margin: 0, margin: 0,
marginBottom: 4, marginBottom: 4,
}} }}
className="collectible-details__contract-link"
> >
<a <a
target="_blank" target="_blank"
className="collectible-details__contract-link" rel="noopener noreferrer"
href={getTokenTrackerLink( href={getTokenTrackerLink(
address, address,
currentNetwork, currentNetwork,
@ -286,11 +290,9 @@ export default function CollectibleDetails({ collectible }) {
null, null,
rpcPrefs, rpcPrefs,
)} )}
rel="noopener noreferrer" title={address}
> >
{getEnvironmentType() === ENVIRONMENT_TYPE_POPUP {inPopUp ? shortenAddress(address) : address}
? shortenAddress(address)
: address}
</a> </a>
</Typography> </Typography>
</Box> </Box>

View File

@ -55,13 +55,13 @@ $spacer-break-small: 16px;
&__contract-link, &__contract-link,
&__image-link { &__image-link {
color: var(--primary-1);
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all; word-break: break-all;
&:hover { @media screen and (max-width: $break-small) {
color: var(--primary-3); overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 90%;
} }
} }

View File

@ -117,6 +117,7 @@ export default function CollectiblesTab({ onAddNFT }) {
marginBottom={12} marginBottom={12}
justifyContent={JUSTIFY_CONTENT.CENTER} justifyContent={JUSTIFY_CONTENT.CENTER}
flexDirection={FLEX_DIRECTION.COLUMN} flexDirection={FLEX_DIRECTION.COLUMN}
className="collectibles-tab__link"
> >
<Typography <Typography
color={COLORS.UI3} color={COLORS.UI3}
@ -131,7 +132,6 @@ export default function CollectiblesTab({ onAddNFT }) {
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
href="https://metamask.zendesk.com/hc/en-us/articles/360058238591-NFT-tokens-in-MetaMask-wallet" href="https://metamask.zendesk.com/hc/en-us/articles/360058238591-NFT-tokens-in-MetaMask-wallet"
style={{ padding: 0, fontSize: '1rem' }}
> >
{t('learnMoreUpperCase')} {t('learnMoreUpperCase')}
</Button> </Button>
@ -154,27 +154,31 @@ export default function CollectiblesTab({ onAddNFT }) {
alignItems={ALIGN_ITEMS.CENTER} alignItems={ALIGN_ITEMS.CENTER}
justifyContent={JUSTIFY_CONTENT.CENTER} justifyContent={JUSTIFY_CONTENT.CENTER}
> >
<Box {!isMainnet && Object.keys(collections).length < 1 ? null : (
className="collectibles-tab__link" <>
justifyContent={JUSTIFY_CONTENT.FLEX_END} <Box
> className="collectibles-tab__link"
{isMainnet && !useCollectibleDetection ? ( justifyContent={JUSTIFY_CONTENT.FLEX_END}
<Button type="link" onClick={onEnableAutoDetect}> >
{t('enableAutoDetect')} {isMainnet && !useCollectibleDetection ? (
</Button> <Button type="link" onClick={onEnableAutoDetect}>
) : ( {t('enableAutoDetect')}
<Button type="link" onClick={onRefresh}> </Button>
{t('refreshList')} ) : (
</Button> <Button type="link" onClick={onRefresh}>
)} {t('refreshList')}
</Box> </Button>
<Typography )}
color={COLORS.UI3} </Box>
variant={TYPOGRAPHY.H4} <Typography
align={TEXT_ALIGN.CENTER} color={COLORS.UI3}
> variant={TYPOGRAPHY.H6}
{t('or')} align={TEXT_ALIGN.CENTER}
</Typography> >
{t('or')}
</Typography>
</>
)}
<Box <Box
justifyContent={JUSTIFY_CONTENT.FLEX_START} justifyContent={JUSTIFY_CONTENT.FLEX_START}
className="collectibles-tab__link" className="collectibles-tab__link"

View File

@ -2,7 +2,7 @@
&__link { &__link {
a { a {
padding: 4px; padding: 4px;
font-size: 1rem; font-size: 0.875rem;
} }
} }
} }

View File

@ -62,7 +62,7 @@ const TokenOverview = ({ className, token }) => {
}); });
useEffect(() => { useEffect(() => {
if (token.isERC721) { if (token.isERC721 && process.env.COLLECTIBLES_V1) {
dispatch( dispatch(
showModal({ showModal({
name: 'CONVERT_TOKEN_TO_NFT', name: 'CONVERT_TOKEN_TO_NFT',

View File

@ -54,6 +54,7 @@ describe('TokenOverview', () => {
}); });
it('should show ConvertTokenToNFT modal when token passed in props is an ERC721', () => { it('should show ConvertTokenToNFT modal when token passed in props is an ERC721', () => {
process.env.COLLECTIBLES_V1 = true;
const token = { const token = {
name: 'test', name: 'test',
isERC721: true, isERC721: true,
@ -69,6 +70,7 @@ describe('TokenOverview', () => {
name: 'CONVERT_TOKEN_TO_NFT', name: 'CONVERT_TOKEN_TO_NFT',
tokenAddress: '0x01', tokenAddress: '0x01',
}); });
process.env.COLLECTIBLES_V1 = false;
}); });
}); });
}); });

View File

@ -203,12 +203,12 @@
box-shadow: 2px 2px 2px var(--alto); box-shadow: 2px 2px 2px var(--alto);
} }
.customize-gas-tooltip-container input[type="number"]::-webkit-inner-spin-button { .customize-gas-tooltip-container input[type='number']::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
display: none; display: none;
} }
.customize-gas-tooltip-container input[type="number"]:hover::-webkit-inner-spin-button { .customize-gas-tooltip-container input[type='number']:hover::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
display: none; display: none;
} }
@ -684,10 +684,19 @@
flex-grow: 1; flex-grow: 1;
} }
@media screen and (max-width: $break-small) {
&__asset-data {
width: 60%;
}
}
&__symbol { &__symbol {
@include Paragraph; @include Paragraph;
margin-bottom: 2px; margin-bottom: 2px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
} }
&__name { &__name {
@ -1061,12 +1070,12 @@
justify-content: center; justify-content: center;
} }
input[type="number"]::-webkit-inner-spin-button { input[type='number']::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
display: none; display: none;
} }
input[type="number"]:hover::-webkit-inner-spin-button { input[type='number']:hover::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
display: none; display: none;
} }

View File

@ -1438,7 +1438,10 @@ export function updateSendAsset({ type, details }) {
details.address, details.address,
userAddress, userAddress,
); );
if (standard === ERC721 || standard === ERC1155) { if (
process.env.COLLECTIBLES_V1 &&
(standard === ERC721 || standard === ERC1155)
) {
await dispatch(hideLoadingIndication()); await dispatch(hideLoadingIndication());
dispatch( dispatch(
showModal({ showModal({

View File

@ -1524,6 +1524,7 @@ describe('Send Slice', () => {
}); });
it('should show ConvertTokenToNFT modal and throw "invalidAssetType" error when token passed in props is an ERC721 or ERC1155', async () => { it('should show ConvertTokenToNFT modal and throw "invalidAssetType" error when token passed in props is an ERC721 or ERC1155', async () => {
process.env.COLLECTIBLES_V1 = true;
getTokenStandardAndDetailsStub.mockImplementation(() => getTokenStandardAndDetailsStub.mockImplementation(() =>
Promise.resolve({ standard: 'ERC1155' }), Promise.resolve({ standard: 'ERC1155' }),
); );
@ -1552,6 +1553,7 @@ describe('Send Slice', () => {
}, },
type: 'UI_MODAL_OPEN', type: 'UI_MODAL_OPEN',
}); });
process.env.COLLECTIBLES_V1 = false;
}); });
}); });

View File

@ -2767,13 +2767,26 @@ export function loadingTokenParamsFinished() {
}; };
} }
export function getTokenParams(tokenAddress) { export function getTokenParams(address) {
return (dispatch, getState) => { return (dispatch, getState) => {
const tokenList = getTokenList(getState()); const tokenList = getTokenList(getState());
const existingTokens = getState().metamask.tokens; const existingTokens = getState().metamask.tokens;
const existingToken = existingTokens.find(({ address }) => const { selectedAddress } = getState().metamask;
isEqualCaseInsensitive(tokenAddress, address), const { chainId } = getState().metamask.provider;
const existingCollectibles = getState().metamask?.allCollectibles?.[
selectedAddress
]?.[chainId];
const existingToken = existingTokens.find(({ address: tokenAddress }) =>
isEqualCaseInsensitive(address, tokenAddress),
); );
const existingCollectible = existingCollectibles?.find(
({ address: collectibleAddress }) =>
isEqualCaseInsensitive(address, collectibleAddress),
);
if (existingCollectible) {
return null;
}
if (existingToken) { if (existingToken) {
return Promise.resolve({ return Promise.resolve({
@ -2785,9 +2798,9 @@ export function getTokenParams(tokenAddress) {
dispatch(loadingTokenParamsStarted()); dispatch(loadingTokenParamsStarted());
log.debug(`loadingTokenParams`); log.debug(`loadingTokenParams`);
return getSymbolAndDecimals(tokenAddress, tokenList).then( return getSymbolAndDecimals(address, tokenList).then(
({ symbol, decimals }) => { ({ symbol, decimals }) => {
dispatch(addToken(tokenAddress, symbol, Number(decimals))); dispatch(addToken(address, symbol, Number(decimals)));
dispatch(loadingTokenParamsFinished()); dispatch(loadingTokenParamsFinished());
}, },
); );