Skip to content

Commit

Permalink
Feat/add fund test account + transactions (#2481)
Browse files Browse the repository at this point in the history
* feat(client-utils): add fund account on testnet function

* feat(dev-wallet): add transactions page

* fix(dev-wallet): side bar

* feat(dev-wallet): transaction stepper

* feat(dev-wallet): add tx icon

* fix(dev-wallet): clean up

* feat(client-utils): add faund existing/new accounts

* fix(dev-wallet): fund existing accounts

* fix(dev-wallet): transaction tabs

* feat(dev-wallet): keyset page

* feat(dev-wallet): your assets

* feat(client-utils): faucet helpers + dev-wallet account page

* feat(dev-wallet): bulk transfer

* fix(dev-wallet): evaluate transfers

* feat(dev-wallet): bulk transfer

* refactor(dev-wallet):  transfer page

* fix: build error

* chore: changeset
  • Loading branch information
javadkh2 authored Sep 16, 2024
1 parent 0e08d23 commit eb82843
Show file tree
Hide file tree
Showing 72 changed files with 4,052 additions and 542 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-cooks-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/dev-wallet': minor
---

Transfer page
6 changes: 6 additions & 0 deletions .changeset/large-pots-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@kadena/client-utils': minor
---

Added faucet helpers to call the contract on testnet + added transfer all to
transfer all available balance form one account to another one
5 changes: 5 additions & 0 deletions .changeset/tricky-rivers-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/kode-ui': minor
---

Added step to text filed; added inherit to color variants
4 changes: 3 additions & 1 deletion packages/apps/dev-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
},
"dependencies": {
"@hookform/resolvers": "^3.2.0",
"@kadena/chainweb-node-client": "workspace:*",
"@kadena/client": "workspace:*",
"@kadena/client-utils": "workspace:*",
"@kadena/chainweb-node-client": "workspace:*",
"@kadena/cryptography-utils": "workspace:*",
"@kadena/hd-wallet": "workspace:*",
"@kadena/kode-icons": "workspace:*",
Expand All @@ -35,6 +35,7 @@
"classnames": "^2.3.1",
"ed25519-keygen": "0.4.8",
"elliptic": "^6.5.5",
"js-yaml": "~4.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.45.4",
Expand All @@ -50,6 +51,7 @@
"@kadena/pactjs-cli": "workspace:*",
"@rollup/plugin-commonjs": "^25.0.7",
"@types/elliptic": "^6.4.18",
"@types/js-yaml": "4.0.9",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vanilla-extract/esbuild-plugin": "^2.3.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/dev-wallet/src/App/layout.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export const headerStyle = style({

export const mainColumnStyle = style([
atoms({
width: '100%',
overflow: 'auto',
color: 'text.base.default',
position: 'relative',
zIndex: 0,
flex: 1,
}),
]);

Expand Down
13 changes: 6 additions & 7 deletions packages/apps/dev-wallet/src/App/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
selectNetworkClass,
} from '@/App/layout.css.ts';
import { Sidebar } from '@/Components/Sidebar/Sidebar.tsx';
import { LayoutContext } from '@/modules/layout/layout.provider.tsx';
import { useNetwork } from '@/modules/network/network.hook';
import { useWallet } from '@/modules/wallet/wallet.hook.tsx';
import { pageClass } from '@/pages/home/style.css.ts';
Expand All @@ -24,7 +23,7 @@ import {
useTheme,
} from '@kadena/kode-ui';
import { atoms } from '@kadena/kode-ui/styles';
import { FC, useContext } from 'react';
import { FC } from 'react';
import { Link, Outlet } from 'react-router-dom';

export const Layout: FC = () => {
Expand All @@ -46,8 +45,6 @@ export const Layout: FC = () => {

const { isUnlocked, lockProfile } = useWallet();

const { layoutContext } = useContext(LayoutContext) ?? [];
const accentColor = layoutContext?.accentColor;
const handleLogOut = () => {
lockProfile();
};
Expand Down Expand Up @@ -111,9 +108,11 @@ export const Layout: FC = () => {
<main>
<Stack
className={pageClass}
style={{
backgroundImage: `radial-gradient(circle farthest-side at 50% 170%, ${accentColor}, transparent 75%)`,
}}
style={
{
// backgroundImage: `radial-gradient(circle farthest-side at 50% 170%, ${accentColor}, transparent 75%)`,
}
}
>
<Sidebar></Sidebar>
<Box padding="n10" className={mainColumnStyle}>
Expand Down
17 changes: 12 additions & 5 deletions packages/apps/dev-wallet/src/App/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ import {

import { CommunicationProvider } from '@/modules/communication/communication.provider';
import { AccountDiscovery } from '@/pages/account-discovery/account-dsicovery';
import { AccountPage } from '@/pages/account/account';
import { Connect } from '@/pages/connect/connect';
import { CreateAccount } from '@/pages/create-account/create-account';
import { FungiblePage } from '@/pages/fungible/fungible';
import { ImportWallet } from '@/pages/import-wallet/import-wallet';
import { KeySources } from '@/pages/key-sources/key-sources';
import { Keyset } from '@/pages/keyset/keyset';
import { CreateNetwork } from '@/pages/networks/create-network';
import { Networks } from '@/pages/networks/networks';
import { Ready } from '@/pages/ready/ready';
import { SignatureBuilder } from '@/pages/signature-builder/signature-builder';
import { Transaction } from '@/pages/transaction/Transaction';
import { TransactionPage } from '@/pages/transaction/Transaction';
import { Transactions } from '@/pages/transactions/transactions';
import { TransferV2 } from '@/pages/transfer-v2/transfer-v2';
import { Heading } from '@kadena/kode-ui';
import { useWallet } from '../modules/wallet/wallet.hook';
import { BackupRecoveryPhrase } from '../pages/backup-recovery-phrase/backup-recovery-phrase';
import { WriteDownRecoveryPhrase } from '../pages/backup-recovery-phrase/write-down/write-down-recovery-phrase';
import { CreateProfile } from '../pages/create-profile/create-profile';
import { HomePage } from '../pages/home/home-page';
import { SelectProfile } from '../pages/select-profile/select-profile';
import { Transfer } from '../pages/transfer/transfer';
import { UnlockProfile } from '../pages/unlock-profile/unlock-profile';
import { getScriptType } from '../utils/window';
import { Layout } from './layout';
Expand Down Expand Up @@ -99,15 +103,18 @@ export const Routes: FC = () => {
</Route>
<Route element={<Layout />}>
<Route path="/" element={<HomePage />} />
<Route path="/accounts/:account" element={<p>Account</p>} />
<Route path="/sig-builder" element={<SignatureBuilder />} />
<Route path="/networks" element={<Networks />} />
<Route path="/networks/create" element={<CreateNetwork />} />
<Route path="/connect/:requestId" element={<Connect />} />
<Route path="/key-sources" element={<KeySources />} />
<Route path="/create-account" element={<CreateAccount />} />
<Route path="/transfer" element={<Transfer />} />
<Route path="/transaction/:groupId" element={<Transaction />} />
<Route path="/transaction/:groupId" element={<TransactionPage />} />
<Route path="/transactions" element={<Transactions />} />
<Route path="/keyset/:keysetId" element={<Keyset />} />
<Route path="/fungible/:contract" element={<FungiblePage />} />
<Route path="/account/:accountId" element={<AccountPage />} />
<Route path="/transfer" element={<TransferV2 />} />
</Route>
</Route>
<Route path="/ready" element={<Ready />} />
Expand Down
103 changes: 103 additions & 0 deletions packages/apps/dev-wallet/src/Components/Accounts/Accounts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {
accountRepository,
Fungible,
IAccount,
IKeySet,
} from '@/modules/account/account.repository';
import { useWallet } from '@/modules/wallet/wallet.hook';
import { linkClass } from '@/pages/select-profile/select-profile.css';
import { getAccountName } from '@/utils/helpers';
import { Box, Heading, Stack, Text } from '@kadena/kode-ui';
import { Link, useNavigate } from 'react-router-dom';
import { ListItem } from '../ListItem/ListItem';
import {
listClass,
noStyleButtonClass,
noStyleLinkClass,
panelClass,
} from './style.css';

export function Accounts({
accounts,
keysets,
asset,
}: {
accounts: IAccount[];
keysets: IKeySet[];
asset?: Fungible;
}) {
const { profile, activeNetwork } = useWallet();
const navigate = useNavigate();
const notUsedKeysets = keysets.filter(
(ks) => !accounts.find((acc) => acc.keysetId === ks.uuid),
);
const totalAccounts = accounts.length + notUsedKeysets.length;
if (!profile || !activeNetwork) {
return null;
}
return (
<Box className={panelClass} marginBlockStart="xs">
<Heading as="h4">{totalAccounts} accounts</Heading>
<Link to="/create-account" className={linkClass}>
Create Account
</Link>
{totalAccounts ? (
<Box marginBlockStart="md">
<Text>Owned ({totalAccounts})</Text>
<ul className={listClass}>
{accounts.map(({ overallBalance, keyset, uuid }) => (
<li key={keyset?.principal}>
<Link to={`/account/${uuid}`} className={noStyleLinkClass}>
<ListItem>
<Stack flexDirection={'column'} gap={'sm'}>
<Text>
{keyset?.alias || getAccountName(keyset!.principal)}
</Text>
</Stack>
<Stack alignItems={'center'} gap={'sm'}>
<Text>{overallBalance} KDA</Text>
</Stack>
</ListItem>
</Link>
</li>
))}
{notUsedKeysets.map((keyset) => (
<li key={keyset?.principal}>
<button
className={noStyleButtonClass}
onClick={async (e) => {
e.preventDefault();
const account: IAccount = {
uuid: crypto.randomUUID(),
profileId: profile.uuid,
address: keyset?.principal,
keysetId: keyset.uuid,
networkId: activeNetwork.networkId,
contract: asset?.contract ?? 'coin',
chains: [],
overallBalance: '0',
};

await accountRepository.addAccount(account);
navigate(`/account/${account.uuid}`);
}}
>
<ListItem>
<Stack flexDirection={'column'} gap={'sm'}>
<Text>
{keyset?.alias || getAccountName(keyset!.principal)}
</Text>
</Stack>
<Stack alignItems={'center'} gap={'sm'}>
<Text>0 {asset?.symbol ?? 'KDA'}</Text>
</Stack>
</ListItem>
</button>
</li>
))}
</ul>
</Box>
) : null}
</Box>
);
}
68 changes: 68 additions & 0 deletions packages/apps/dev-wallet/src/Components/Accounts/style.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { cardColor, cardHoverColor } from '@/utils/color.ts';
import { atoms, vars } from '@kadena/kode-ui/styles';
import { style } from '@vanilla-extract/css';

export const pageClass = style({
minHeight: 'calc(100vh - 90px)',
});

export const panelClass = style([
atoms({
padding: 'md',
}),
{
background: cardColor,
},
]);

export const listClass = style([
atoms({
listStyleType: 'none',
marginBlockStart: 'md',
padding: 'n0',
}),
]);

export const chainListClass = style([
atoms({
listStyleType: 'none',
paddingBlock: 'n1',
}),
]);

export const listItemClass = style([
atoms({
padding: 'md',
marginBlockStart: 'xs',
}),
{
background: cardColor,
selectors: {
'&:hover': {
background: cardHoverColor,
},
},
},
]);

export const noStyleLinkClass = style({
textDecoration: 'none',
color: 'inherit',
});

export const chainClass = style([
{
background: vars.colors.$layoutSurfaceCard,
},
]);

export const noStyleButtonClass = style({
background: 'none',
color: 'inherit',
border: 'none',
padding: 0,
font: 'inherit',
outline: 'inherit',
cursor: 'pointer',
width: '100%',
});
Loading

0 comments on commit eb82843

Please sign in to comment.