Skip to content

Commit

Permalink
Wallet NFT section - WIP (MystenLabs#3738)
Browse files Browse the repository at this point in the history
* nft gallery

* gallery update


* added select nft state

* wallet-nft-section

* added package-lock file

* rm yarn lock file

* lint fix

* fixed formating

* show error text from backend

* nft update
  • Loading branch information
Jibz1 authored Aug 5, 2022
1 parent e352e3c commit e91604e
Show file tree
Hide file tree
Showing 49 changed files with 1,621 additions and 334 deletions.
Binary file modified wallet/font-icons/output/sui-icons.eot
Binary file not shown.
74 changes: 40 additions & 34 deletions wallet/font-icons/output/sui-icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,45 @@ url('./sui-icons.svg#sui-icons') format('svg');
-moz-osx-font-smoothing: grayscale;
}

.sui-icons-apps:before { content: "\ea01"; }
.sui-icons-arrow-left:before { content: "\ea02"; }
.sui-icons-arrow-right:before { content: "\ea03"; }
.sui-icons-clipboard:before { content: "\ea04"; }
.sui-icons-close:before { content: "\ea05"; }
.sui-icons-coins:before { content: "\ea06"; }
.sui-icons-globe:before { content: "\ea07"; }
.sui-icons-hand-coins:before { content: "\ea08"; }
.sui-icons-history:before { content: "\ea09"; }
.sui-icons-logout:before { content: "\ea0a"; }
.sui-icons-nfts:before { content: "\ea0b"; }
.sui-icons-percentage-polygon:before { content: "\ea0c"; }
.sui-icons-person:before { content: "\ea0d"; }
.sui-icons-sui-chevron-right:before { content: "\ea0e"; }
.sui-icons-sui-logo-icon:before { content: "\ea0f"; }
.sui-icons-sui-logo-txt:before { content: "\ea10"; }
.sui-icons-tokens:before { content: "\ea11"; }
.sui-icons-Info:before { content: "\ea01"; }
.sui-icons-Preview:before { content: "\ea02"; }
.sui-icons-apps:before { content: "\ea03"; }
.sui-icons-arrow-left:before { content: "\ea04"; }
.sui-icons-arrow-right:before { content: "\ea05"; }
.sui-icons-checkmark:before { content: "\ea06"; }
.sui-icons-clipboard:before { content: "\ea07"; }
.sui-icons-close:before { content: "\ea08"; }
.sui-icons-coins:before { content: "\ea09"; }
.sui-icons-globe:before { content: "\ea0a"; }
.sui-icons-hand-coins:before { content: "\ea0b"; }
.sui-icons-history:before { content: "\ea0c"; }
.sui-icons-logout:before { content: "\ea0d"; }
.sui-icons-nfts:before { content: "\ea0e"; }
.sui-icons-percentage-polygon:before { content: "\ea0f"; }
.sui-icons-person:before { content: "\ea10"; }
.sui-icons-sui-chevron-right:before { content: "\ea11"; }
.sui-icons-sui-logo-icon:before { content: "\ea12"; }
.sui-icons-sui-logo-txt:before { content: "\ea13"; }
.sui-icons-tokens:before { content: "\ea14"; }

$sui-icons-apps: "\ea01";
$sui-icons-arrow-left: "\ea02";
$sui-icons-arrow-right: "\ea03";
$sui-icons-clipboard: "\ea04";
$sui-icons-close: "\ea05";
$sui-icons-coins: "\ea06";
$sui-icons-globe: "\ea07";
$sui-icons-hand-coins: "\ea08";
$sui-icons-history: "\ea09";
$sui-icons-logout: "\ea0a";
$sui-icons-nfts: "\ea0b";
$sui-icons-percentage-polygon: "\ea0c";
$sui-icons-person: "\ea0d";
$sui-icons-sui-chevron-right: "\ea0e";
$sui-icons-sui-logo-icon: "\ea0f";
$sui-icons-sui-logo-txt: "\ea10";
$sui-icons-tokens: "\ea11";
$sui-icons-Info: "\ea01";
$sui-icons-Preview: "\ea02";
$sui-icons-apps: "\ea03";
$sui-icons-arrow-left: "\ea04";
$sui-icons-arrow-right: "\ea05";
$sui-icons-checkmark: "\ea06";
$sui-icons-clipboard: "\ea07";
$sui-icons-close: "\ea08";
$sui-icons-coins: "\ea09";
$sui-icons-globe: "\ea0a";
$sui-icons-hand-coins: "\ea0b";
$sui-icons-history: "\ea0c";
$sui-icons-logout: "\ea0d";
$sui-icons-nfts: "\ea0e";
$sui-icons-percentage-polygon: "\ea0f";
$sui-icons-person: "\ea10";
$sui-icons-sui-chevron-right: "\ea11";
$sui-icons-sui-logo-icon: "\ea12";
$sui-icons-sui-logo-txt: "\ea13";
$sui-icons-tokens: "\ea14";

45 changes: 27 additions & 18 deletions wallet/font-icons/output/sui-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions wallet/font-icons/output/sui-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

export enum SuiIcons {
Info = "sui-icons-Info",
Preview = "sui-icons-Preview",
Apps = "sui-icons-apps",
ArrowLeft = "sui-icons-arrow-left",
ArrowRight = "sui-icons-arrow-right",
Checkmark = "sui-icons-checkmark",
Clipboard = "sui-icons-clipboard",
Close = "sui-icons-close",
Coins = "sui-icons-coins",
Expand All @@ -21,6 +24,6 @@ export enum SuiIcons {
Tokens = "sui-icons-tokens"
}

export type SuiIconsClassname = "sui-icons-apps" | "sui-icons-arrow-left" | "sui-icons-arrow-right" | "sui-icons-clipboard" | "sui-icons-close" | "sui-icons-coins" | "sui-icons-globe" | "sui-icons-hand-coins" | "sui-icons-history" | "sui-icons-logout" | "sui-icons-nfts" | "sui-icons-percentage-polygon" | "sui-icons-person" | "sui-icons-sui-chevron-right" | "sui-icons-sui-logo-icon" | "sui-icons-sui-logo-txt" | "sui-icons-tokens"
export type SuiIconsIcon = "apps" | "arrow-left" | "arrow-right" | "clipboard" | "close" | "coins" | "globe" | "hand-coins" | "history" | "logout" | "nfts" | "percentage-polygon" | "person" | "sui-chevron-right" | "sui-logo-icon" | "sui-logo-txt" | "tokens"
export const SuiIconsPrefix = "sui-icons-"
export type SuiIconsClassname = "sui-icons-Info" | "sui-icons-Preview" | "sui-icons-apps" | "sui-icons-arrow-left" | "sui-icons-arrow-right" | "sui-icons-checkmark" | "sui-icons-clipboard" | "sui-icons-close" | "sui-icons-coins" | "sui-icons-globe" | "sui-icons-hand-coins" | "sui-icons-history" | "sui-icons-logout" | "sui-icons-nfts" | "sui-icons-percentage-polygon" | "sui-icons-person" | "sui-icons-sui-chevron-right" | "sui-icons-sui-logo-icon" | "sui-icons-sui-logo-txt" | "sui-icons-tokens"
export type SuiIconsIcon = "Info" | "Preview" | "apps" | "arrow-left" | "arrow-right" | "checkmark" | "clipboard" | "close" | "coins" | "globe" | "hand-coins" | "history" | "logout" | "nfts" | "percentage-polygon" | "person" | "sui-chevron-right" | "sui-logo-icon" | "sui-logo-txt" | "tokens"
export const SuiIconsPrefix = "sui-icons-"
Binary file modified wallet/font-icons/output/sui-icons.ttf
Binary file not shown.
Binary file modified wallet/font-icons/output/sui-icons.woff
Binary file not shown.
Binary file modified wallet/font-icons/output/sui-icons.woff2
Binary file not shown.
5 changes: 5 additions & 0 deletions wallet/font-icons/svgs/Info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions wallet/font-icons/svgs/Preview.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions wallet/font-icons/svgs/checkmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion wallet/src/ui/app/components/address-input/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const SUI_ADDRESS_VALIDATION = Yup.string()
.test(
'is-sui-address',
// eslint-disable-next-line no-template-curly-in-string
'${value} is not a valid Sui address',
'Invalid address. Please check again.',
(value) => isValidSuiAddress(value)
)
.label("Recipient's address");
11 changes: 8 additions & 3 deletions wallet/src/ui/app/components/explorer-link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export type ExplorerLinkProps = (
}
| { type: ExplorerLinkType.object; objectID: ObjectId }
| { type: ExplorerLinkType.transaction; transactionID: TransactionDigest }
) & { children?: ReactNode; className?: string; title?: string };
) & {
children?: ReactNode;
className?: string;
title?: string;
showIcon?: boolean;
};

function useAddress(props: ExplorerLinkProps) {
const { type } = props;
Expand All @@ -36,7 +41,7 @@ function useAddress(props: ExplorerLinkProps) {
}

function ExplorerLink(props: ExplorerLinkProps) {
const { type, children, className, title } = props;
const { type, children, className, title, showIcon = true } = props;
const address = useAddress(props);
const selectedApiEnv = useAppSelector(({ app }) => app.apiEnv);
const objectID = type === ExplorerLinkType.object ? props.objectID : null;
Expand Down Expand Up @@ -70,7 +75,7 @@ function ExplorerLink(props: ExplorerLinkProps) {
showIcon={false}
>
<>
{children} <Icon icon="box-arrow-up-right" />
{children} {showIcon && <Icon icon="box-arrow-up-right" />}
</>
</ExternalLink>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use '_variables' as v;
@use '_values' as values;
@use '_values/colors';

.container {
display: flex;
Expand Down Expand Up @@ -39,6 +40,7 @@
.icon {
font-size: 32px;
margin-bottom: 2px;
color: colors.$sui-steel-blue;

.active > & {
color: v.use(v.$colors-nav-item-icon-highlighted-color);
Expand Down
106 changes: 106 additions & 0 deletions wallet/src/ui/app/components/nft-display/NFTDisplay.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@use '_utils';
@use '_values/colors';

.nftimage {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;

img {
width: 100%;
object-fit: cover;
border-radius: 6px;
height: 100%;
}

.small {
height: 98px;
width: 98px;
}

.medium {
height: 150px;
width: 150px;
}

.large {
height: 180px;
width: 180px;
}

.nftfields {
line-height: 12px;
text-decoration: none;
font-weight: 500;
font-size: 13px;
padding-top: 10px;
color: colors.$gray-100;
width: 100%;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

.expandable {
@include utils.typography('table/title-sm');

margin-top: 10px;

a {
text-decoration: none;
color: colors.$gray-80;
display: flex;
align-items: center;
justify-content: center;
}

i {
color: colors.$gray-65;
font-size: 14px;
margin-left: 5px;
font-weight: 300;
line-height: 100%;
}
}

&.wideview {
background-color: colors.$gray-40;
padding: 10px;
border-radius: 10px;
width: 100%;
justify-content: space-between;
flex-flow: row-reverse;
gap: 10px;

.img {
width: 50px;
height: 50px;
}

.nftfields {
padding-top: 0;
height: 49px;
display: flex;
flex-flow: column;
justify-content: center;
}

.nft-name {
text-transform: capitalize;
color: colors.$gray-100;
margin-bottom: 4px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;

@include utils.typography('nft-title');
}

.nft-type {
color: colors.$gray-75;

@include utils.typography('table/text-lg');
}
}
}
70 changes: 70 additions & 0 deletions wallet/src/ui/app/components/nft-display/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { isSuiMoveObject } from '@mysten/sui.js';
import cl from 'classnames';

import ExplorerLink from '_components/explorer-link';
import { ExplorerLinkType } from '_components/explorer-link/ExplorerLinkType';
import Icon, { SuiIcons } from '_components/icon';
import { useFileExtentionType, useMediaUrl } from '_hooks';

import type { SuiObject as SuiObjectType } from '@mysten/sui.js';

import st from './NFTDisplay.module.scss';

export type NFTsProps = {
nftobj: SuiObjectType;
showlabel?: boolean;
size?: 'small' | 'medium' | 'large';
expandable?: boolean;
wideview?: boolean;
};

function NFTDisplayCard({
nftobj,
showlabel,
size = 'medium',
expandable,
wideview,
}: NFTsProps) {
const imgUrl = useMediaUrl(nftobj.data);
const nftFields = isSuiMoveObject(nftobj.data) ? nftobj.data.fields : null;
const fileExtentionType = useFileExtentionType(nftFields?.url || '');

const wideviewSection = (
<div className={st.nftfields}>
<div className={st.nftName}>{nftFields?.name}</div>
<div className={st.nftType}>{fileExtentionType}</div>
</div>
);
const defaultSection = (
<>
{expandable && nftFields?.info.id ? (
<div className={st.expandable}>
<ExplorerLink
type={ExplorerLinkType.object}
objectID={nftFields?.info.id}
showIcon={false}
className={st['explorer-link']}
>
View Image <Icon icon={SuiIcons.Preview} />
</ExplorerLink>
</div>
) : null}
{showlabel && nftFields?.name ? (
<div className={st.nftfields}>{nftFields.name}</div>
) : null}
</>
);

return (
<div className={cl(st.nftimage, wideview && st.wideview)}>
{imgUrl && (
<img className={cl(st.img, st[size])} src={imgUrl} alt="NFT" />
)}
{wideview ? wideviewSection : defaultSection}
</div>
);
}

export default NFTDisplayCard;
Loading

0 comments on commit e91604e

Please sign in to comment.