Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(wallet,dashboard): move TransactionReceipt to core #4280

Merged
merged 24 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2a7065f
refactor(wallet,dashboard): move `TransactionReceipt` to core
VmMad Nov 27, 2024
09139bf
fix: improve imports
VmMad Nov 27, 2024
54d75f9
Merge branch 'develop' into tooling-dashboard/add-activity-view
VmMad Nov 27, 2024
98838a6
fix: remove unused file
VmMad Nov 27, 2024
967e02c
fix: cleanup
VmMad Nov 27, 2024
93db22e
rever previous commit
VmMad Nov 27, 2024
917b02a
fix: types
VmMad Nov 27, 2024
012eb3b
fix: update tests
VmMad Nov 28, 2024
680ac9e
Merge branch 'develop' into tooling-dashboard/add-activity-view
VmMad Nov 29, 2024
82fcdd7
fix: format
VmMad Dec 3, 2024
af05acb
refactor: update interfaces to put required first
VmMad Dec 4, 2024
bf02a5d
fix: expandable list
VmMad Dec 4, 2024
f3c8da9
Merge branch 'develop' into tooling-dashboard/add-activity-view
VmMad Dec 4, 2024
60c1cef
fix: update imported dialog layouts
VmMad Dec 4, 2024
604cd24
fix: update missing import
VmMad Dec 4, 2024
585d94e
Merge branch 'develop' into tooling-dashboard/add-activity-view
VmMad Dec 5, 2024
05b240b
fix: update imports
VmMad Dec 5, 2024
a67b48f
refactor: rename file
VmMad Dec 5, 2024
cb2e953
Merge branch 'develop' into tooling-dashboard/add-activity-view
VmMad Dec 5, 2024
09534a0
fix(wallet): add core components to tailwind.config.ts
VmMad Dec 5, 2024
b3c66b7
chore: improve interface sorting
VmMad Dec 5, 2024
7acc956
Merge branch 'develop' into tooling-dashboard/add-activity-view
brancoder Dec 5, 2024
8467b96
fix: celanup types and imports
VmMad Dec 5, 2024
746134a
fix: wait for transaciton and refetch stakes
VmMad Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/core/src/components/buttons/ViewTxnOnExplorerButton.tsx
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 React, { JSX } from 'react';
import { Button, ButtonType, LoadingIndicator } from '@iota/apps-ui-kit';
import { ArrowTopRight } from '@iota/ui-icons';

interface ViewTxnOnExplorerButtonProps {
digest?: string;
}

export function ViewTxnOnExplorerButton({ digest }: ViewTxnOnExplorerButtonProps): JSX.Element {
return (
<Button
type={ButtonType.Outlined}
text="View on Explorer"
fullWidth
icon={digest ? <ArrowTopRight /> : <LoadingIndicator data-testid="loading-indicator" />}
iconAfterText
disabled={!digest}
/>
);
}
4 changes: 4 additions & 0 deletions apps/core/src/components/buttons/index.ts
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 './ViewTxnOnExplorerButton';
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,55 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import {
CoinItem,
getRecognizedUnRecognizedTokenChanges,
type BalanceChange,
type BalanceChangeSummary,
} from '@iota/core';
import { useMemo } from 'react';
import React, { useMemo } from 'react';
import { Divider, Header, KeyValueInfo, Panel } from '@iota/apps-ui-kit';
import { ExplorerLink, ExplorerLinkType } from '_src/ui/app/components';
import type { BalanceChangeSummary, RenderExplorerLink } from '../../types';
import { ExplorerLinkType } from '../../enums';
import { formatAddress } from '@iota/iota-sdk/utils';
import { CoinItem } from '../coin';
import { RecognizedBadge } from '@iota/ui-icons';
import { getRecognizedUnRecognizedTokenChanges } from '../../utils';
import { BalanceChange } from '../../interfaces';

interface BalanceChangesProps {
renderExplorerLink: RenderExplorerLink;
changes?: BalanceChangeSummary;
}

export function BalanceChanges({ changes, renderExplorerLink: ExplorerLink }: BalanceChangesProps) {
if (!changes) return null;

return (
<>
{Object.entries(changes).map(([owner, changes]) => {
return (
<Panel key={owner} hasBorder>
<div className="flex flex-col gap-y-sm overflow-hidden rounded-xl">
<Header title="Balance Changes" />
<BalanceChangeEntries changes={changes} />
<div className="flex flex-col gap-y-sm px-md pb-md">
<Divider />
<KeyValueInfo
keyText="Owner"
value={
<ExplorerLink
type={ExplorerLinkType.Address}
address={owner}
>
{formatAddress(owner)}
</ExplorerLink>
}
fullwidth
/>
</div>
</div>
</Panel>
);
})}
</>
);
}

function BalanceChangeEntry({ change }: { change: BalanceChange }) {
const { amount, coinType, unRecognizedToken } = change;
return (
Expand Down Expand Up @@ -54,37 +87,3 @@ function BalanceChangeEntries({ changes }: { changes: BalanceChange[] }) {
</>
);
}

export function BalanceChanges({ changes }: BalanceChangesProps) {
if (!changes) return null;

return (
<>
{Object.entries(changes).map(([owner, changes]) => {
return (
<Panel key={owner} hasBorder>
<div className="flex flex-col gap-y-sm overflow-hidden rounded-xl">
<Header title="Balance Changes" />
<BalanceChangeEntries changes={changes} />
<div className="flex flex-col gap-y-sm px-md pb-md">
<Divider />
<KeyValueInfo
keyText="Owner"
value={
<ExplorerLink
type={ExplorerLinkType.Address}
address={owner}
>
{formatAddress(owner)}
</ExplorerLink>
}
fullwidth
/>
</div>
</div>
</Panel>
);
})}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { ExplorerLink, ExplorerLinkType } from '_components';
import { type IotaObjectChangeWithDisplay, ImageIcon } from '@iota/core';

import React from 'react';
import { type IotaObjectChangeWithDisplay, ExplorerLinkType, ImageIcon } from '../../';
import { Card, CardAction, CardActionType, CardBody, CardImage, CardType } from '@iota/apps-ui-kit';
import { ArrowTopRight } from '@iota/ui-icons';
import { RenderExplorerLink } from '../../types';

export function ObjectChangeDisplay({ change }: { change: IotaObjectChangeWithDisplay }) {
interface ObjectChangeDisplayProps {
renderExplorerLink: RenderExplorerLink;
change?: IotaObjectChangeWithDisplay;
}
export function ObjectChangeDisplay({
change,
renderExplorerLink: ExplorerLink,
}: ObjectChangeDisplayProps) {
const display = change?.display?.data;
const name = display?.name ?? '';
const objectId = 'objectId' in change && change?.objectId;
const objectId = change && 'objectId' in change && change?.objectId;

if (!display) return null;

return (
<ExplorerLink
className="text-hero-dark no-underline"
objectID={objectId?.toString() ?? ''}
type={ExplorerLinkType.Object}
>
<ExplorerLink objectID={objectId?.toString() ?? ''} type={ExplorerLinkType.Object}>
<Card type={CardType.Default} isHoverable>
<CardImage>
<ImageIcon src={display.image_url ?? ''} label={name} fallback="NFT" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// Copyright (c) Mysten Labs, Inc.
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import { ExplorerLink, ExplorerLinkType } from '_components';
import React, { useState } from 'react';
import {
getObjectChangeLabel,
type ObjectChangesByOwner,
type ObjectChangeSummary,
type IotaObjectChangeTypes,
type IotaObjectChangeWithDisplay,
Collapsible,
} from '@iota/core';
ExplorerLinkType,
} from '../../';
import { formatAddress } from '@iota/iota-sdk/utils';
import cx from 'clsx';
import { ExpandableList } from '../../ExpandableList';
import { ObjectChangeDisplay } from './objectSummary/ObjectChangeDisplay';
import { ExpandableList } from '../lists';
import { Collapsible } from '../collapsible';
import { ObjectChangeDisplay } from './ObjectChangeDisplay';
import {
Badge,
BadgeType,
Expand All @@ -23,16 +24,17 @@ import {
Title,
TitleSize,
} from '@iota/apps-ui-kit';
import { useState } from 'react';
import { TriangleDown } from '@iota/ui-icons';
import { RenderExplorerLink } from '../../types';

interface ObjectDetailProps {
change: IotaObjectChangeWithDisplay;
ownerKey: string;
renderExplorerLink: RenderExplorerLink;
display?: boolean;
}

export function ObjectDetail({ change, display }: ObjectDetailProps) {
export function ObjectDetail({ change, renderExplorerLink: ExplorerLink }: ObjectDetailProps) {
if (change.type === 'transferred' || change.type === 'published') {
return null;
}
Expand Down Expand Up @@ -127,9 +129,14 @@ export function ObjectDetail({ change, display }: ObjectDetailProps) {
interface ObjectChangeEntryProps {
type: IotaObjectChangeTypes;
changes: ObjectChangesByOwner;
renderExplorerLink: RenderExplorerLink;
}

export function ObjectChangeEntry({ changes, type }: ObjectChangeEntryProps) {
export function ObjectChangeEntry({
changes,
type,
renderExplorerLink: ExplorerLink,
}: ObjectChangeEntryProps) {
const [open, setOpen] = useState(new Set());
return (
<>
Expand Down Expand Up @@ -169,35 +176,29 @@ export function ObjectChangeEntry({ changes, type }: ObjectChangeEntryProps) {
{!!changes.changesWithDisplay.length && (
<div className="flex flex-1 flex-col gap-2 overflow-y-auto">
<ExpandableList
initialShowAll={isOpen}
defaultItemsToShow={5}
items={
isOpen
? changes.changesWithDisplay.map(
(change) => (
<ObjectChangeDisplay
change={change}
/>
),
)
: []
}
items={changes.changesWithDisplay.map((change) => (
<ObjectChangeDisplay
change={change}
renderExplorerLink={ExplorerLink}
/>
))}
/>
</div>
)}

<div className="flex w-full flex-col gap-2">
<ExpandableList
defaultItemsToShow={5}
items={
open
? changes.changes.map((change) => (
<ObjectDetail
ownerKey={owner}
change={change}
/>
))
: []
}
initialShowAll={isOpen}
items={changes.changes.map((change) => (
<ObjectDetail
renderExplorerLink={ExplorerLink}
ownerKey={owner}
change={change}
/>
))}
/>
</div>
</>
Expand Down Expand Up @@ -227,9 +228,10 @@ export function ObjectChangeEntry({ changes, type }: ObjectChangeEntryProps) {

interface ObjectChangesProps {
changes?: ObjectChangeSummary | null;
renderExplorerLink: RenderExplorerLink;
}

export function ObjectChanges({ changes }: ObjectChangesProps) {
export function ObjectChanges({ changes, renderExplorerLink }: ObjectChangesProps) {
if (!changes) return null;

return (
Expand All @@ -240,6 +242,7 @@ export function ObjectChanges({ changes }: ObjectChangesProps) {
key={type}
type={type as keyof ObjectChangeSummary}
changes={changes}
renderExplorerLink={renderExplorerLink}
/>
);
})}
Expand Down
5 changes: 5 additions & 0 deletions apps/core/src/components/cards/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export * from './BalanceChanges';
export * from './ObjectChanges';
5 changes: 2 additions & 3 deletions apps/core/src/components/collapsible/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import React, { useState, type ReactNode } from 'react';
import { Accordion, AccordionContent, AccordionHeader, Title, TitleSize } from '@iota/apps-ui-kit';
import { useState, type ReactNode } from 'react';

interface CollapsibleProps {
interface CollapsibleProps extends React.PropsWithChildren {
title?: string;
defaultOpen?: boolean;
children: ReactNode | ReactNode[];
isOpen?: boolean;
onOpenChange?: (isOpen: boolean) => void;
titleSize?: TitleSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import React from 'react';
import { TitleSize, Badge, BadgeType, Title, Panel } from '@iota/apps-ui-kit';
import { GasSummary } from '_src/ui/app/shared/transaction-summary/cards/GasSummary';
import { type GasSummaryType, Collapsible } from '@iota/core';
import { Collapsible, GasSummary, type RenderExplorerLink, type GasSummaryType } from '../../';

interface GasFeesProps {
activeAddress: string | null | undefined;
renderExplorerLink: RenderExplorerLink;
sender?: string;
gasSummary?: GasSummaryType;
isEstimate?: boolean;
Expand All @@ -15,7 +17,15 @@ interface GasFeesProps {
}
const DEFAULT_TITLE = 'Gas Fees';

export function GasFees({ sender, gasSummary, isEstimate, isPending, isError }: GasFeesProps) {
export function GasFees({
sender,
activeAddress,
gasSummary,
isEstimate,
isPending,
isError,
renderExplorerLink,
}: GasFeesProps) {
const title = isEstimate ? `Est. ${DEFAULT_TITLE}` : DEFAULT_TITLE;
const trailingElement =
gasSummary?.isSponsored && gasSummary.owner ? (
Expand Down Expand Up @@ -43,6 +53,8 @@ export function GasFees({ sender, gasSummary, isEstimate, isPending, isError }:
gasSummary={gasSummary}
isPending={isPending}
isError={isError}
renderExplorerLink={renderExplorerLink}
activeAddress={activeAddress}
/>
</div>
</Collapsible>
Expand Down
Loading
Loading