forked from solana-foundation/explorer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMetaplexNFTHeader.tsx
More file actions
190 lines (171 loc) · 7.92 KB
/
MetaplexNFTHeader.tsx
File metadata and controls
190 lines (171 loc) · 7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { InfoTooltip } from '@components/common/InfoTooltip';
import { ArtContent } from '@components/common/NFTArt';
import { Creator } from '@metaplex-foundation/mpl-token-metadata';
import { isSome } from '@metaplex-foundation/umi';
import * as Umi from '@metaplex-foundation/umi';
import { NFTData, useFetchAccountInfo, useMintAccountInfo } from '@providers/accounts';
import { EditionInfo } from '@providers/accounts/utils/getEditionInfo';
import { PublicKey } from '@solana/web3.js';
import { useClusterPath } from '@utils/url';
import Link from 'next/link';
import React, { createRef } from 'react';
import { AlertOctagon, Check, ChevronDown } from 'react-feather';
import useAsyncEffect from 'use-async-effect';
export function MetaplexNFTHeader({ nftData, address }: { nftData: NFTData; address: string }) {
const collection = nftData.metadata.collection;
let collectionAddress: Umi.PublicKey | null = null;
let verified = false;
if (collection && isSome(collection)) {
collectionAddress = collection.value.key;
verified = collection.value.verified;
}
const collectionMintInfo = useMintAccountInfo(collectionAddress?.toString());
const fetchAccountInfo = useFetchAccountInfo();
React.useEffect(() => {
if (collectionAddress && !collectionMintInfo) {
fetchAccountInfo(new PublicKey(collectionAddress), 'parsed');
}
}, [fetchAccountInfo, collectionAddress]); // eslint-disable-line react-hooks/exhaustive-deps
const metadata = nftData.metadata;
const data = nftData.json;
const isVerifiedCollection = collection != null && verified && collectionMintInfo !== undefined;
const dropdownRef = createRef<HTMLButtonElement>();
useAsyncEffect(
async isMounted => {
if (!dropdownRef.current) {
return;
}
const Dropdown = (await import('bootstrap/js/dist/dropdown')).default;
if (!isMounted || !dropdownRef.current) {
return;
}
return new Dropdown(dropdownRef.current);
},
dropdown => {
if (dropdown) {
dropdown.dispose();
}
},
[dropdownRef]
);
return (
<div className="row">
<div className="col-auto ms-2 d-flex align-items-center">
<ArtContent pubkey={address} data={data} />
</div>
<div className="col mb-3 ms-0.5 mt-3">
{<h6 className="header-pretitle ms-1">Metaplex NFT</h6>}
<div className="d-flex align-items-center">
<h2 className="header-title ms-1 align-items-center no-overflow-with-ellipsis">
{metadata.name !== '' ? metadata.name : 'No NFT name was found'}
</h2>
{getEditionPill(nftData.editionInfo)}
{isVerifiedCollection ? getVerifiedCollectionPill() : null}
</div>
<h4 className="header-pretitle ms-1 mt-1 no-overflow-with-ellipsis">
{metadata.symbol !== '' ? metadata.symbol : 'No Symbol was found'}
</h4>
<div className="mb-2 mt-2">{getSaleTypePill(metadata.primarySaleHappened)}</div>
<div className="mb-3 mt-2">{getIsMutablePill(metadata.isMutable)}</div>
<div className="btn-group">
<button
className="btn btn-dark btn-sm creators-dropdown-button-width"
type="button"
aria-haspopup="true"
aria-expanded="false"
data-bs-toggle="dropdown"
ref={dropdownRef}
>
Creators <ChevronDown size={15} className="align-text-top" />
</button>
<div className="dropdown-menu mt-2">{getCreatorDropdownItems(isSome(metadata.creators) ? metadata.creators.value : [])}</div>
</div>
</div>
</div>
);
}
export function getCreatorDropdownItems(creators: Creator[] | null) {
const CreatorHeader = () => {
const creatorTooltip = 'Verified creators signed the metadata associated with this NFT when it was created.';
const shareTooltip = 'The percentage of the proceeds a creator receives when this NFT is sold.';
return (
<div className={'d-flex align-items-center dropdown-header creator-dropdown-entry'}>
<div className="d-flex font-monospace creator-dropdown-header">
<span>Creator Address</span>
<InfoTooltip bottom text={creatorTooltip} />
</div>
<div className="d-flex font-monospace">
<span className="font-monospace">Royalty</span>
<InfoTooltip bottom text={shareTooltip} />
</div>
</div>
);
};
const getVerifiedIcon = (isVerified: boolean) => {
return isVerified ? <Check className="ms-3" size={15} /> : <AlertOctagon className="me-3" size={15} />;
};
const CreatorEntry = (creator: Creator) => {
const creatorPath = useClusterPath({ pathname: `/address/${creator.address}` });
return (
<div className={'d-flex align-items-center font-monospace creator-dropdown-entry ms-3 me-3'}>
{getVerifiedIcon(creator.verified)}
<Link className="dropdown-item font-monospace creator-dropdown-entry-address" href={creatorPath}>
{creator.address}
</Link>
<div className="me-3"> {`${creator.share}%`}</div>
</div>
);
};
if (creators && creators.length > 0) {
const listOfCreators: JSX.Element[] = [];
listOfCreators.push(<CreatorHeader key={'header'} />);
creators.forEach(creator => {
listOfCreators.push(<CreatorEntry key={creator.address} {...creator} />);
});
return listOfCreators;
}
return (
<div className={'dropdown-item font-monospace'}>
<div className="me-3">No creators are associated with this NFT.</div>
</div>
);
}
function getEditionPill(editionInfo: EditionInfo) {
const masterEdition = editionInfo.masterEdition;
const edition = editionInfo.edition;
return (
<div className={'d-inline-flex ms-2'}>
<span className="badge badge-pill bg-dark">{`${edition && masterEdition
? `Edition ${Number(edition.edition)} / ${Number(masterEdition.supply)}`
: masterEdition
? 'Master Edition'
: 'No Master Edition Information'
}`}</span>
</div>
);
}
function getSaleTypePill(hasPrimarySaleHappened: boolean) {
const primaryMarketTooltip = 'Creator(s) split 100% of the proceeds when this NFT is sold.';
const secondaryMarketTooltip =
'Creator(s) split the Seller Fee when this NFT is sold. The owner receives the remaining proceeds.';
return (
<div className={'d-inline-flex align-items-center'}>
<span className="badge badge-pill bg-dark">{`${hasPrimarySaleHappened ? 'Secondary Market' : 'Primary Market'
}`}</span>
<InfoTooltip bottom text={hasPrimarySaleHappened ? secondaryMarketTooltip : primaryMarketTooltip} />
</div>
);
}
export function getIsMutablePill(isMutable: boolean) {
return <span className="badge badge-pill bg-dark">{`${isMutable ? 'Mutable' : 'Immutable'}`}</span>;
}
export function getVerifiedCollectionPill() {
const onchainVerifiedToolTip =
'This NFT has been verified as a member of an on-chain collection. This tag guarantees authenticity.';
return (
<div className={'d-inline-flex align-items-center ms-2'}>
<span className="badge badge-pill bg-dark">{'Verified Collection'}</span>
<InfoTooltip bottom text={onchainVerifiedToolTip} />
</div>
);
}