Skip to content

Commit

Permalink
Feat/dw transaction account (#2653)
Browse files Browse the repository at this point in the history
* fix(dx): tx list

* fix(dw): transactions
  • Loading branch information
javadkh2 authored Nov 8, 2024
1 parent dae4487 commit 75ae180
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 101 deletions.
154 changes: 88 additions & 66 deletions packages/apps/dev-wallet/src/pages/account/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ConfirmDeletion } from '@/Components/ConfirmDeletion/ConfirmDeletion';
import { FundOnTestnetButton } from '@/Components/FundOnTestnet/FundOnTestnet';
import { usePrompt } from '@/Components/PromptProvider/Prompt';
import { QRCode } from '@/Components/QRCode/QRCode';
import { SideBarBreadcrumbs } from '@/Components/SideBarBreadcrumbs/SideBarBreadcrumbs';
import {
accountRepository,
isWatchedAccount,
Expand All @@ -19,9 +20,10 @@ import {
MonoCreate,
MonoKey,
MonoRemoveRedEye,
MonoWallet,
} from '@kadena/kode-icons/system';
import { Button, Heading, Stack, TabItem, Tabs, Text } from '@kadena/kode-ui';
import { useLayout } from '@kadena/kode-ui/patterns';
import { SideBarBreadcrumbsItem, useLayout } from '@kadena/kode-ui/patterns';
import { useMemo, useState } from 'react';
import { Link, useNavigate, useParams } from 'react-router-dom';
import { noStyleLinkClass, panelClass } from '../home/style.css';
Expand Down Expand Up @@ -99,20 +101,16 @@ export function AccountPage() {

return (
<Stack flexDirection={'column'} gap={'lg'}>
<SideBarBreadcrumbs icon={<MonoWallet />}>
<SideBarBreadcrumbsItem href="/">Dashboard</SideBarBreadcrumbsItem>
<SideBarBreadcrumbsItem href={`/account/${accountId}`}>
Account ({account.alias || account.address})
</SideBarBreadcrumbsItem>
</SideBarBreadcrumbs>
<AliasForm show={isRightAsideExpanded} account={account} />
<Stack flexDirection={'column'} gap={'sm'}>
<Stack gap={'sm'} alignItems={'center'}>
<Heading variant="h3">{account.alias || '{ No Alias }'}</Heading>
{account.profileId === profile?.uuid && (
<Button
isCompact
variant="transparent"
startVisual={<MonoCreate />}
onPress={() => {
setIsRightAsideExpanded(!isRightAsideExpanded);
}}
/>
)}
</Stack>

<Stack justifyContent={'space-between'}>
Expand Down Expand Up @@ -249,62 +247,86 @@ export function AccountPage() {
)}
{activities.length > 0 && <ActivityTable activities={activities} />}
</TabItem>
{
(isOwnedAccount && (
<TabItem key="settings" title="Settings">
<Stack flexDirection={'column'} gap={'xxl'}>
<Stack
flexDirection={'column'}
gap={'md'}
className={panelClass}
alignItems={'flex-start'}
>
<Heading variant="h4">Migrate Account</Heading>
<Text>
You can use account migration to transfer all balances to a
newly created account with a new keyset, even though the
keyset guard for this account cannot be changed.
</Text>
<Button variant="outlined">Migrate</Button>
</Stack>
<Stack
flexDirection={'column'}
gap={'md'}
className={panelClass}
alignItems={'flex-start'}
>
<Heading variant="h4">Delete Account</Heading>
<Text>
You don't want to use this account anymore? You can delete
it from your wallet. This will be deleted locally not from
the blockchain.
</Text>
<Button
variant="negative"
onClick={async () => {
const confirm = await prompt((resolve) => {
return (
<ConfirmDeletion
onCancel={() => resolve(false)}
onDelete={() => resolve(true)}
title="Delete Account"
description=" Are you sure you want to delete this account? If you need to add it again you will need to use account creation process."
/>
);
});
if (confirm) {
await accountRepository.deleteAccount(account.uuid);
navigate('/');
}
}}

<TabItem key="settings" title="Settings">
<Stack flexDirection={'column'} gap={'xxl'}>
<Stack
flexDirection={'column'}
gap={'md'}
className={panelClass}
alignItems={'flex-start'}
>
<Heading variant="h4">Account Alias</Heading>
<Text>
You can set or change the alias for this account. This will help
you to identify this account easily.
</Text>
<Button
variant="outlined"
startVisual={<MonoCreate />}
onPress={() => {
setIsRightAsideExpanded(!isRightAsideExpanded);
}}
>
Edit Alias
</Button>
</Stack>
{
(isOwnedAccount && (
<>
<Stack
flexDirection={'column'}
gap={'md'}
className={panelClass}
alignItems={'flex-start'}
>
Delete
</Button>
</Stack>
</Stack>
</TabItem>
)) as any
}
<Heading variant="h4">Migrate Account</Heading>
<Text>
You can use account migration to transfer all balances to
a newly created account with a new keyset, even though the
keyset guard for this account cannot be changed.
</Text>
<Button variant="outlined">Migrate</Button>
</Stack>
<Stack
flexDirection={'column'}
gap={'md'}
className={panelClass}
alignItems={'flex-start'}
>
<Heading variant="h4">Delete Account</Heading>
<Text>
You don't want to use this account anymore? You can delete
it from your wallet. This will be deleted locally not from
the blockchain.
</Text>
<Button
variant="negative"
onClick={async () => {
const confirm = await prompt((resolve) => {
return (
<ConfirmDeletion
onCancel={() => resolve(false)}
onDelete={() => resolve(true)}
title="Delete Account"
description=" Are you sure you want to delete this account? If you need to add it again you will need to use account creation process."
/>
);
});
if (confirm) {
await accountRepository.deleteAccount(account.uuid);
navigate('/');
}
}}
>
Delete
</Button>
</Stack>
</>
)) as any
}
</Stack>
</TabItem>
</Tabs>
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { MonoDashboardCustomize } from '@kadena/kode-icons/system';
import { Box, Button, Heading, Stack, Text } from '@kadena/kode-ui';
import { SideBarBreadcrumbsItem } from '@kadena/kode-ui/patterns';
import { Link } from 'react-router-dom';
<SideBarBreadcrumbs icon={<MonoDashboardCustomize />}>
<SideBarBreadcrumbsItem href="/">Dashboard</SideBarBreadcrumbsItem>
<SideBarBreadcrumbsItem href="/terminal">Dev Console</SideBarBreadcrumbsItem>
</SideBarBreadcrumbs>;

export function BackupRecoveryPhrase() {
return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { CopyButton } from '@/Components/CopyButton/CopyButton';
import { ITransaction } from '@/modules/transaction/transaction.repository';
import { shortenPactCode } from '@/utils/parsedCodeToPact';
import { IPactCommand } from '@kadena/client';
import { Heading, Stack, Text } from '@kadena/kode-ui';
import { MonoTextSnippet } from '@kadena/kode-icons/system';
import { Button, Heading, Stack, Text } from '@kadena/kode-ui';
import classNames from 'classnames';
import { useMemo } from 'react';
import { useMemo, useState } from 'react';
import { Label, Value } from './helpers';
import { Signers } from './Signers';
import { cardClass, codeClass, textEllipsis } from './style.css';
Expand All @@ -19,6 +21,7 @@ export function CommandView({
() => JSON.parse(transaction.cmd),
[transaction.cmd],
);
const [showShortenCode, setShowShortenCode] = useState(true);
return (
<Stack flexDirection={'column'} gap={'xl'}>
<Stack gap={'sm'} flexDirection={'column'}>
Expand All @@ -29,8 +32,20 @@ export function CommandView({
{'exec' in command.payload && (
<>
<Stack gap={'sm'} flexDirection={'column'}>
<Heading variant="h4">Code</Heading>
<Value className={codeClass}>{command.payload.exec.code}</Value>
<Stack gap={'sm'} justifyContent={'space-between'}>
<Heading variant="h4">Code</Heading>
<Button
onPress={() => setShowShortenCode(!showShortenCode)}
variant={'transparent'}
isCompact
startVisual={<MonoTextSnippet />}
/>
</Stack>
<Value className={codeClass}>
{showShortenCode
? shortenPactCode(command.payload.exec.code)
: command.payload.exec.code}
</Value>
</Stack>
{Object.keys(command.payload.exec.data).length > 0 && (
<Stack gap={'sm'} flexDirection={'column'}>
Expand Down
4 changes: 4 additions & 0 deletions packages/apps/dev-wallet/src/pages/transactions/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ export const hashStyle = style({
whiteSpace: 'nowrap',
flex: 1,
});

export const codeClass = style({
whiteSpace: 'pre-wrap',
});
66 changes: 39 additions & 27 deletions packages/apps/dev-wallet/src/pages/transactions/transactions.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { SideBarBreadcrumbs } from '@/Components/SideBarBreadcrumbs/SideBarBreadcrumbs';
import { FormatCreationDateWrapper } from '@/Components/Table/FormatCreationDateWrapper';
import { FormatHash } from '@/Components/Table/FormatHash';
import {
ITransaction,
transactionRepository,
} from '@/modules/transaction/transaction.repository';
import { useWallet } from '@/modules/wallet/wallet.hook';
import { shorten } from '@/utils/helpers';
import { shortenPactCode } from '@/utils/parsedCodeToPact';
import { IPactCommand } from '@kadena/client';
import { MonoSwapHoriz } from '@kadena/kode-icons/system';
import { Heading, Stack } from '@kadena/kode-ui';
import {
CompactTable,
CompactTableFormatters,
SideBarBreadcrumbsItem,
} from '@kadena/kode-ui/patterns';
import { MonoArrowOutward, MonoSwapHoriz } from '@kadena/kode-icons/system';
import { Heading, Stack, Text } from '@kadena/kode-ui';
import { CompactTable, SideBarBreadcrumbsItem } from '@kadena/kode-ui/patterns';
import { useEffect, useMemo, useState } from 'react';
import { Link } from 'react-router-dom';
import { noStyleLinkClass } from '../home/style.css';
import { codeClass } from './style.css';

export function Transactions() {
const { profile, activeNetwork } = useWallet();
Expand Down Expand Up @@ -75,13 +74,13 @@ export const TransactionList = ({
return {
...tx,
type: 'exec',
code: cmd.payload.exec.code,
code: shortenPactCode(cmd.payload.exec.code, 4),
};
} else {
return {
...tx,
type: 'cont',
code: cmd.payload.cont.pactId,
code: `cont: ${cmd.payload.cont.pactId}`,
};
}
}),
Expand All @@ -91,34 +90,47 @@ export const TransactionList = ({
<CompactTable
fields={[
{
label: 'Status',
key: 'status',
variant: 'code',
width: '10%',
render: CompactTableFormatters.FormatStatus(),
label: 'Hash',
key: 'hash',
variant: 'body',
width: '15%',
render: ({ value }) => {
const tx = txs.find((tx) => tx.hash === value);
return (
<Link
to={`/transaction/${tx!.groupId}`}
className={noStyleLinkClass}
style={{ textDecoration: 'underline' }}
>
<Stack gap={'sm'} alignItems={'center'}>
{shorten(value)} <MonoArrowOutward fontSize={16} />
</Stack>
</Link>
);
},
},
{
label: 'GroupId',
key: 'groupId',
label: 'Status',
key: 'status',
variant: 'code',
width: '30%',
render: CompactTableFormatters.FormatLinkWrapper({
url: '/transaction/:value',
linkComponent: Link,
}),
width: '15%',
},
{
label: 'Hash',
key: 'hash',
label: 'Code',
key: 'code',
variant: 'code',
width: '20%',
render: FormatHash(),
width: 'auto',
render: ({ value }) => (
<Text variant="code" className={codeClass}>
{value}
</Text>
),
},
{
label: 'Date',
key: 'cmd',
variant: 'code',
width: '40%',
width: '20%',
render: FormatCreationDateWrapper(),
},
]}
Expand Down
Loading

0 comments on commit 75ae180

Please sign in to comment.