-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet-dashboard): add styles for non visual assets (#3761)
* feat(wallet-dashboard): add protected layout * feat: add missing TopNav * fix: tests * fix: imports * feat(wallet-dashboard): add assets page * fix: add missing themes * feat: improve connect button size * revert: "feat: improve connect button size" * feat(wallet-dashboard): add grid for visual assets * feat(Wallet-dashboard): add styles for non visual assets * refactor: remove unnecessary useMemo * fix: remove commented lines * fix: improve type * fix: update IotaLogo * refactor: use explorer link and remove unnecessary code * fix: bring back more details for visual sset details * fix: update to make it as reviewed * refactor: move explorer link generation logic to core * fix: update imports * fix: copy comment --------- Co-authored-by: evavirseda <[email protected]> Co-authored-by: cpl121 <[email protected]>
- Loading branch information
1 parent
f59220d
commit 90fdcf7
Showing
37 changed files
with
293 additions
and
143 deletions.
There are no files selected for viewing
File renamed without changes.
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,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './ExplorerLinkType'; |
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
File renamed without changes.
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,58 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// Modifications Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getCustomNetwork } from '.'; | ||
import { getNetwork, Network, NetworkId } from '@iota/iota-sdk/client'; | ||
import { getAddressUrl, getObjectUrl, getTransactionUrl, getValidatorUrl } from '.'; | ||
import { ExplorerLinkType } from '../enums'; | ||
|
||
export type ExplorerLinkConfig = | ||
| { | ||
type: ExplorerLinkType.Address; | ||
address?: string; | ||
useActiveAddress?: false; | ||
} | ||
| { | ||
type: ExplorerLinkType.Address; | ||
useActiveAddress: true; | ||
} | ||
| { type: ExplorerLinkType.Object; objectID: string; moduleName?: string } | ||
| { type: ExplorerLinkType.Transaction; transactionID: string } | ||
| { type: ExplorerLinkType.Validator; validator: string }; | ||
|
||
function getAddress(linkConfig: ExplorerLinkConfig, activeAddress: string | null) { | ||
const { type } = linkConfig; | ||
const isAddress = type === ExplorerLinkType.Address; | ||
const isProvidedAddress = isAddress && !linkConfig.useActiveAddress; | ||
return isProvidedAddress ? linkConfig.address : activeAddress; | ||
} | ||
|
||
export function getExplorerLink( | ||
linkConfig: ExplorerLinkConfig, | ||
activeAddress: string | null, | ||
network: NetworkId, | ||
) { | ||
const { type } = linkConfig; | ||
const address = getAddress(linkConfig, activeAddress); | ||
const objectID = type === ExplorerLinkType.Object ? linkConfig.objectID : null; | ||
const transactionID = type === ExplorerLinkType.Transaction ? linkConfig.transactionID : null; | ||
const validator = type === ExplorerLinkType.Validator ? linkConfig.validator : null; | ||
const moduleName = type === ExplorerLinkType.Object ? linkConfig.moduleName : null; | ||
|
||
// fallback to localhost if customRPC is not set | ||
const customExplorer = | ||
network === Network.Custom ? getCustomNetwork().explorer : getNetwork(network).explorer; | ||
|
||
if (!address) return null; | ||
switch (type) { | ||
case ExplorerLinkType.Address: | ||
return address && getAddressUrl(address, network, customExplorer); | ||
case ExplorerLinkType.Object: | ||
return objectID && getObjectUrl(objectID, network, customExplorer, moduleName); | ||
case ExplorerLinkType.Transaction: | ||
return transactionID && getTransactionUrl(transactionID, network, customExplorer); | ||
case ExplorerLinkType.Validator: | ||
return validator && getValidatorUrl(validator, network, customExplorer); | ||
} | ||
} |
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,47 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// Modifications Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getNetwork, Network, NetworkId } from '@iota/iota-sdk/client'; | ||
|
||
function getExplorerUrl( | ||
path: string, | ||
network: NetworkId, | ||
customExplorer: string, | ||
getUrlWithDeviceId: (url: URL) => URL = (url) => url, | ||
) { | ||
const networkConfig = getNetwork(network); | ||
const explorer = network === Network.Custom ? customExplorer : networkConfig?.explorer; | ||
|
||
const url = getUrlWithDeviceId(new URL(path, explorer)); | ||
if (explorer) { | ||
url.searchParams.append('network', network); | ||
} | ||
|
||
return url.href; | ||
} | ||
|
||
export function getObjectUrl( | ||
objectID: string, | ||
network: NetworkId, | ||
customExplorer: string, | ||
moduleName?: string | null, | ||
) { | ||
return getExplorerUrl( | ||
`/object/${objectID}${moduleName ? `?module=${moduleName}` : ''}`, | ||
network, | ||
customExplorer, | ||
); | ||
} | ||
|
||
export function getTransactionUrl(txDigest: string, network: NetworkId, customExplorer: string) { | ||
return getExplorerUrl(`/txblock/${encodeURIComponent(txDigest)}`, network, customExplorer); | ||
} | ||
|
||
export function getAddressUrl(address: string, network: NetworkId, customExplorer: string) { | ||
return getExplorerUrl(`/address/${address}`, network, customExplorer); | ||
} | ||
|
||
export function getValidatorUrl(address: string, network: NetworkId, customExplorer: string) { | ||
return getExplorerUrl(`/validator/${address}`, network, customExplorer); | ||
} |
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
45 changes: 0 additions & 45 deletions
45
apps/wallet-dashboard/app/(protected)/assets/visual-assets/[objectId]/page.tsx
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AssetCategory } from '@/lib/enums'; | ||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { AssetTileLink } from '@/components'; | ||
|
||
interface AssetListProps { | ||
assets: IotaObjectData[]; | ||
selectedCategory: AssetCategory; | ||
} | ||
|
||
const ASSET_LAYOUT: Record<AssetCategory, string> = { | ||
[AssetCategory.Visual]: | ||
'grid-template-visual-assets grid max-h-[600px] gap-md overflow-auto py-sm', | ||
[AssetCategory.Other]: 'flex flex-col overflow-auto py-sm', | ||
}; | ||
|
||
export function AssetList({ assets, selectedCategory }: AssetListProps): React.JSX.Element { | ||
return ( | ||
<div className={ASSET_LAYOUT[selectedCategory]}> | ||
{assets.map((asset) => ( | ||
<AssetTileLink key={asset.digest} asset={asset} type={selectedCategory} /> | ||
))} | ||
</div> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
apps/wallet-dashboard/components/Cards/VisualAssetDetailsCard.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,23 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { VisualAssetTile } from '../tiles'; | ||
|
||
interface AssetDetailsCardProps { | ||
asset: IotaObjectData; | ||
} | ||
|
||
export function VisualAssetDetailsCard({ asset }: AssetDetailsCardProps): React.JSX.Element { | ||
return ( | ||
<div className="flex w-full gap-2"> | ||
<VisualAssetTile asset={asset} /> | ||
<div> | ||
<p>Digest: {asset.digest}</p> | ||
<p>Object ID: {asset.objectId}</p> | ||
{asset.type ? <p>Type: {asset.type}</p> : null} | ||
<p>Version: {asset.version}</p> | ||
</div> | ||
</div> | ||
); | ||
} |
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
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,52 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
'use client'; | ||
|
||
import { ASSETS_ROUTE } from '@/lib/constants/routes.constants'; | ||
import { AssetCategory } from '@/lib/enums'; | ||
import { VisibilityOff } from '@iota/ui-icons'; | ||
import { VisualAssetTile } from '.'; | ||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { NonVisualAssetCard } from './NonVisualAssetTile'; | ||
import { useExplorerLinkGetter } from '@/hooks'; | ||
import Link from 'next/link'; | ||
import { ExplorerLinkType } from '@iota/core'; | ||
|
||
interface AssetTileLinkProps { | ||
asset: IotaObjectData; | ||
type: AssetCategory; | ||
} | ||
|
||
export function AssetTileLink({ asset, type }: AssetTileLinkProps): React.JSX.Element { | ||
const getExplorerLink = useExplorerLinkGetter(); | ||
const linkProps = getAssetLinkProps(asset); | ||
|
||
function getAssetLinkProps(asset: IotaObjectData): React.ComponentProps<typeof Link> { | ||
if (type === AssetCategory.Visual) { | ||
return { href: ASSETS_ROUTE.path + `/${asset.objectId}` }; | ||
} else { | ||
const explorerLink = | ||
getExplorerLink({ | ||
type: ExplorerLinkType.Object, | ||
objectID: asset.objectId, | ||
}) ?? ''; | ||
|
||
return { | ||
href: explorerLink, | ||
target: '_blank', | ||
rel: 'noopener noreferrer', | ||
}; | ||
} | ||
} | ||
|
||
return ( | ||
<Link {...linkProps}> | ||
{type === AssetCategory.Visual ? ( | ||
<VisualAssetTile asset={asset} icon={<VisibilityOff />} /> | ||
) : ( | ||
<NonVisualAssetCard asset={asset} /> | ||
)} | ||
</Link> | ||
); | ||
} |
Oops, something went wrong.