Skip to content

Commit

Permalink
feat(wallet-dashboard): add send view and enhance asset transfer func…
Browse files Browse the repository at this point in the history
…tionality
  • Loading branch information
panteleymonchuk committed Nov 21, 2024
1 parent 093c3f4 commit b3291fb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
7 changes: 2 additions & 5 deletions apps/core/src/hooks/useNftDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { useGetNFTMeta, useOwnedNFT, useNFTBasicData, useGetKioskContents } from './';
import { formatAddress } from '@iota/iota-sdk/utils';
import { truncateString } from '../utils';
import { isAssetTransferable, truncateString } from '../utils';

type NftFields = {
metadata?: { fields?: { attributes?: { fields?: { keys: string[]; values: string[] } } } };
Expand All @@ -15,10 +15,7 @@ export function useNftDetails(nftId: string, accountAddress: string | null) {
const isContainedInKiosk = data?.lookup.get(nftId!);
const kioskItem = data?.list.find((k) => k.data?.objectId === nftId);

const isTransferable =
!!objectData &&
objectData.content?.dataType === 'moveObject' &&
objectData.content?.hasPublicTransfer;
const isTransferable = isAssetTransferable(objectData);

const { nftFields } = useNFTBasicData(objectData);

Expand Down
13 changes: 11 additions & 2 deletions apps/wallet-dashboard/components/Dialogs/Assets/AssetsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IotaObjectData } from '@iota/iota-sdk/client';

export enum AssetsDialogView {
Details,
Send,
}

interface AssetsDialogProps {
Expand All @@ -17,12 +18,20 @@ interface AssetsDialogProps {
}

export function AssetsDialog({ isOpen, handleClose, asset }: AssetsDialogProps): JSX.Element {
const [view] = React.useState<AssetsDialogView>(AssetsDialogView.Details);
const [view, setView] = React.useState<AssetsDialogView>(AssetsDialogView.Details);

function handleDetailsSend() {
setView(AssetsDialogView.Send);
}

return (
<Dialog open={isOpen} onOpenChange={() => handleClose()}>
{view === AssetsDialogView.Details && asset && (
<DetailsView asset={asset} handleClose={handleClose} />
<DetailsView
asset={asset}
handleClose={handleClose}
handleSend={handleDetailsSend}
/>
)}
</Dialog>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import { useCurrentAccount } from '@iota/dapp-kit';
interface DetailsViewProps {
asset: IotaObjectData;
handleClose: () => void;
handleSend: () => void;
}

export function DetailsView({ handleClose, asset }: DetailsViewProps) {
export function DetailsView({ handleClose, asset, handleSend }: DetailsViewProps) {
const account = useCurrentAccount();

const senderAddress = account?.address ?? '';
Expand Down Expand Up @@ -52,10 +53,6 @@ export function DetailsView({ handleClose, asset }: DetailsViewProps) {
window.open('https://wiki.iota.org/', '_blank');
}

function handleSend() {
console.log('send');
}

return (
<Layout>
<Header title="Asset" onClose={handleClose} />
Expand Down Expand Up @@ -146,9 +143,13 @@ export function DetailsView({ handleClose, asset }: DetailsViewProps) {
key={idx}
keyText={aKey}
value={
<Link key={aKey} href={valueLink || ''}>
{value}
</Link>
valueLink ? (
<Link key={aKey} href={valueLink || ''}>
{value}
</Link>
) : (
value
)
}
fullwidth
/>
Expand Down
17 changes: 17 additions & 0 deletions apps/wallet-dashboard/components/Dialogs/Assets/views/SendView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import React from 'react';
import { Layout, LayoutBody } from '../../Staking/views/Layout';

export function SendView() {
return (
<Layout>
<LayoutBody>
<div className="flex w-full flex-col items-center justify-center gap-xs">
Send view
</div>
</LayoutBody>
</Layout>
);
}
3 changes: 1 addition & 2 deletions apps/wallet/src/ui/app/pages/home/nft-transfer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import { useActiveAddress } from '_app/hooks/useActiveAddress';
import { Loading, NFTDisplayCard, Overlay } from '_components';
import { useOwnedNFT } from '_hooks';
import { useUnlockedGuard } from '_src/ui/app/hooks/useUnlockedGuard';
import { Navigate, useNavigate, useParams } from 'react-router-dom';
import { TransferNFTForm } from './TransferNFTForm';
import { isAssetTransferable } from '@iota/core';
import { isAssetTransferable, useOwnedNFT } from '@iota/core';

function NftTransferPage() {
const { nftId } = useParams();
Expand Down

0 comments on commit b3291fb

Please sign in to comment.