-
Notifications
You must be signed in to change notification settings - Fork 13
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): style selected visual Assets (#4085)
* feat(wallet-dashboard): style selected visual Assets. * refactor(core): destructure metaKeys and metaValues from attributes * refactor(wallet): move Collapsible component to core. * feat(dashboard): integrate useAssetsDialog for asset details view * fix(assets): update import path and enhance text styling in DetailsView * refactor(wallet-dashboard): move state to page * refactor(wallet-dashboard): rename handler functions for consistency and clarity * refactor(dashboard): update state for asset view, improve code * fix(wallet-dashboard): unify asset transfer success and error handling in AssetDialog * refactor(dashboard): adjust z-index for dialog and notifications; * feat(dashboard): add refetch functionality after asset transfered * refactor(dashboard): rename callbacks for clarity in AssetDialog * refactor(dashboard, cove): rename hooks, remove duplication. * refactor(dashboard): remove unused asset details page --------- Co-authored-by: Bran <[email protected]> Co-authored-by: Marc Espin <[email protected]>
- Loading branch information
1 parent
d796edd
commit c7aa8e5
Showing
43 changed files
with
587 additions
and
230 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 './Collapsible'; |
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
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
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
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,98 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
useGetNFTDisplay, | ||
useOwnedNFT, | ||
useNFTBasicData, | ||
useGetKioskContents, | ||
useIsAssetTransferable, | ||
} from './'; | ||
import { formatAddress } from '@iota/iota-sdk/utils'; | ||
import { truncateString } from '../utils'; | ||
|
||
type NftField = { keys: string[]; values: string[] }; | ||
|
||
type NftFields = { | ||
metadata?: { fields?: { attributes?: { fields?: NftField } } }; | ||
}; | ||
|
||
export function useNftDetails(nftId: string, accountAddress: string | null) { | ||
const { data: objectData, isPending: isNftLoading } = useOwnedNFT(nftId || '', accountAddress); | ||
const { data } = useGetKioskContents(accountAddress); | ||
|
||
const isContainedInKiosk = data?.lookup.get(nftId!); | ||
const kioskItem = data?.list.find((k) => k.data?.objectId === nftId); | ||
|
||
const { data: isAssetTransferable, isLoading: isCheckingAssetTransferability } = | ||
useIsAssetTransferable(objectData); | ||
|
||
const { nftFields } = useNFTBasicData(objectData); | ||
|
||
const { data: nftDisplayData, isPending: isPendingNftDislpay } = useGetNFTDisplay(nftId); | ||
|
||
const nftName = nftDisplayData?.name || formatAddress(nftId); | ||
const nftImageUrl = nftDisplayData?.imageUrl || ''; | ||
|
||
// Extract either the attributes, or use the top-level NFT fields: | ||
const { keys: metaKeys, values: metaValues } = | ||
(nftFields as NftFields)?.metadata?.fields?.attributes?.fields || | ||
Object.entries(nftFields ?? {}) | ||
.filter(([key]) => key !== 'id') | ||
.reduce<NftField>( | ||
(acc, [key, value]) => { | ||
acc.keys.push(key); | ||
acc.values.push(value as string); | ||
return acc; | ||
}, | ||
{ keys: [], values: [] }, | ||
); | ||
|
||
const ownerAddress = | ||
(objectData?.owner && | ||
typeof objectData?.owner === 'object' && | ||
'AddressOwner' in objectData.owner && | ||
objectData.owner.AddressOwner) || | ||
''; | ||
|
||
function formatMetaValue(value: string | object) { | ||
if (typeof value === 'object') { | ||
return { | ||
value: JSON.stringify(value), | ||
valueLink: undefined, | ||
}; | ||
} else { | ||
if (value.includes('http')) { | ||
return { | ||
value: value.startsWith('http') | ||
? truncateString(value, 20, 8) | ||
: formatAddress(value), | ||
valueLink: value, | ||
}; | ||
} | ||
return { | ||
value: value, | ||
valueLink: undefined, | ||
}; | ||
} | ||
} | ||
|
||
const isLoading = isNftLoading || isCheckingAssetTransferability || isPendingNftDislpay; | ||
|
||
return { | ||
isLoading, | ||
objectData, | ||
isNftLoading, | ||
nftName, | ||
nftImageUrl, | ||
ownerAddress, | ||
isCheckingAssetTransferability, | ||
isAssetTransferable, | ||
metaKeys, | ||
metaValues, | ||
formatMetaValue, | ||
isContainedInKiosk, | ||
kioskItem, | ||
nftDisplayData, | ||
isPendingNftDislpay, | ||
}; | ||
} |
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
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
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
44 changes: 0 additions & 44 deletions
44
apps/wallet-dashboard/app/(protected)/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
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
81 changes: 81 additions & 0 deletions
81
apps/wallet-dashboard/components/Dialogs/Assets/AssetDialog.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,81 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React, { useState } from 'react'; | ||
import { Dialog } from '@iota/apps-ui-kit'; | ||
import { FormikProvider, useFormik } from 'formik'; | ||
import { useCurrentAccount } from '@iota/dapp-kit'; | ||
import { createNftSendValidationSchema } from '@iota/core'; | ||
import { DetailsView, SendView } from './views'; | ||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { AssetsDialogView } from './constants'; | ||
import { useCreateSendAssetTransaction, useNotifications } from '@/hooks'; | ||
import { NotificationType } from '@/stores/notificationStore'; | ||
|
||
interface AssetsDialogProps { | ||
onClose: () => void; | ||
asset: IotaObjectData; | ||
} | ||
|
||
interface FormValues { | ||
to: string; | ||
} | ||
|
||
const INITIAL_VALUES: FormValues = { | ||
to: '', | ||
}; | ||
|
||
export function AssetDialog({ onClose, asset }: AssetsDialogProps): JSX.Element { | ||
const [view, setView] = useState<AssetsDialogView>(AssetsDialogView.Details); | ||
const account = useCurrentAccount(); | ||
const activeAddress = account?.address ?? ''; | ||
const objectId = asset?.objectId ?? ''; | ||
const { addNotification } = useNotifications(); | ||
const validationSchema = createNftSendValidationSchema(activeAddress, objectId); | ||
|
||
const { mutation: sendAsset } = useCreateSendAssetTransaction(objectId); | ||
|
||
const formik = useFormik<FormValues>({ | ||
initialValues: INITIAL_VALUES, | ||
validationSchema: validationSchema, | ||
onSubmit: onSubmit, | ||
validateOnChange: true, | ||
}); | ||
|
||
async function onSubmit(values: FormValues) { | ||
try { | ||
await sendAsset.mutateAsync(values.to); | ||
addNotification('Transfer transaction successful', NotificationType.Success); | ||
onClose(); | ||
setView(AssetsDialogView.Details); | ||
} catch { | ||
addNotification('Transfer transaction failed', NotificationType.Error); | ||
} | ||
} | ||
|
||
function onDetailsSend() { | ||
setView(AssetsDialogView.Send); | ||
} | ||
|
||
function onSendViewBack() { | ||
setView(AssetsDialogView.Details); | ||
} | ||
function onOpenChange() { | ||
setView(AssetsDialogView.Details); | ||
onClose(); | ||
} | ||
return ( | ||
<Dialog open onOpenChange={onOpenChange}> | ||
<FormikProvider value={formik}> | ||
<> | ||
{view === AssetsDialogView.Details && ( | ||
<DetailsView asset={asset} onClose={onOpenChange} onSend={onDetailsSend} /> | ||
)} | ||
{view === AssetsDialogView.Send && ( | ||
<SendView asset={asset} onClose={onOpenChange} onBack={onSendViewBack} /> | ||
)} | ||
</> | ||
</FormikProvider> | ||
</Dialog> | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/wallet-dashboard/components/Dialogs/Assets/constants/AssetsDialogView.ts
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,7 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export enum AssetsDialogView { | ||
Details = 'Details', | ||
Send = 'Send', | ||
} |
Oops, something went wrong.