From b673487cd04156fa630790abf16ed32b20097ba1 Mon Sep 17 00:00:00 2001 From: Albert G <516972+alber70g@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:12:57 +0100 Subject: [PATCH] feat(cw3): adds bulk sigdata --- packages/apps/dev-wallet/src/App/routes.tsx | 5 + .../Components/UnlockPrompt/UnlockPrompt.tsx | 1 + .../signature-builder/signature-builder.tsx | 193 +++++++- .../transaction-group/TransactionGroup.tsx | 80 ++++ .../components/CommandView.tsx | 233 ++++++++++ .../components/ExpandedTransaction.tsx | 309 +++++++++++++ .../transaction-group/components/Signer.tsx | 221 +++++++++ .../components/SubmittedStatus.tsx | 93 ++++ .../components/TxContainer.tsx | 203 +++++++++ .../transaction-group/components/TxList.tsx | 228 ++++++++++ .../components/TxMinimized.tsx | 58 +++ .../components/TxPipeLine.tsx | 426 ++++++++++++++++++ .../transaction-group/components/TxTile.tsx | 195 ++++++++ .../components/TxTileGeneric.tsx | 129 ++++++ .../transaction-group/components/helpers.tsx | 23 + .../transaction-group/components/style.css.ts | 139 ++++++ .../src/pages/transaction-group/style.css.ts | 18 + .../pages/unlock-profile/unlock-profile.tsx | 1 + .../src/utils/transaction-scheme.ts | 3 +- 19 files changed, 2541 insertions(+), 17 deletions(-) create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/TransactionGroup.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/CommandView.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/ExpandedTransaction.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/Signer.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/SubmittedStatus.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/TxContainer.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/TxList.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/TxMinimized.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/TxPipeLine.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/TxTile.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/TxTileGeneric.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/helpers.tsx create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/components/style.css.ts create mode 100644 packages/apps/dev-wallet/src/pages/transaction-group/style.css.ts diff --git a/packages/apps/dev-wallet/src/App/routes.tsx b/packages/apps/dev-wallet/src/App/routes.tsx index 529b002d1b..93a22926c3 100644 --- a/packages/apps/dev-wallet/src/App/routes.tsx +++ b/packages/apps/dev-wallet/src/App/routes.tsx @@ -29,6 +29,7 @@ import { ImportData } from '@/pages/settings/import-data/import-data'; import { RevealPhrase } from '@/pages/settings/reveal-phrase/reveal-phrase'; import { Settings } from '@/pages/settings/settings'; import { SignatureBuilder } from '@/pages/signature-builder/signature-builder'; +import { TransactionGroupPage } from '@/pages/transaction-group/TransactionGroup'; import { TransactionPage } from '@/pages/transaction/Transaction'; import { Transactions } from '@/pages/transactions/transactions'; import { Transfer } from '@/pages/transfer/transfer'; @@ -120,6 +121,10 @@ export const Routes: FC = () => { } /> } /> } /> + } + /> } /> } /> } /> diff --git a/packages/apps/dev-wallet/src/Components/UnlockPrompt/UnlockPrompt.tsx b/packages/apps/dev-wallet/src/Components/UnlockPrompt/UnlockPrompt.tsx index 8de06df638..744af6cf8e 100644 --- a/packages/apps/dev-wallet/src/Components/UnlockPrompt/UnlockPrompt.tsx +++ b/packages/apps/dev-wallet/src/Components/UnlockPrompt/UnlockPrompt.tsx @@ -74,6 +74,7 @@ export const UnlockPrompt: React.FC<{ type="password" {...register('password')} label="Password" + autoFocus /> )} {storePassword && ( diff --git a/packages/apps/dev-wallet/src/pages/signature-builder/signature-builder.tsx b/packages/apps/dev-wallet/src/pages/signature-builder/signature-builder.tsx index a2c0c0958b..4211ac7404 100644 --- a/packages/apps/dev-wallet/src/pages/signature-builder/signature-builder.tsx +++ b/packages/apps/dev-wallet/src/pages/signature-builder/signature-builder.tsx @@ -8,10 +8,14 @@ import { } from '@kadena/client'; import { SideBarBreadcrumbs } from '@/Components/SideBarBreadcrumbs/SideBarBreadcrumbs'; -import { transactionRepository } from '@/modules/transaction/transaction.repository'; +import { + ITransaction, + transactionRepository, +} from '@/modules/transaction/transaction.repository'; import * as transactionService from '@/modules/transaction/transaction.service'; import { useWallet } from '@/modules/wallet/wallet.hook'; import { normalizeTx } from '@/utils/normalizeSigs'; +import { browse, readContent } from '@/utils/select-file'; import { determineSchema, RequestScheme, @@ -19,7 +23,13 @@ import { } from '@/utils/transaction-scheme'; import { usePatchedNavigate } from '@/utils/usePatchedNavigate'; import { base64UrlDecodeArr } from '@kadena/cryptography-utils'; -import { MonoDashboardCustomize } from '@kadena/kode-icons/system'; +import { + MonoDashboardCustomize, + MonoRemove, + MonoRemoveCircleOutline, + MonoRestoreFromTrash, + MonoSignature, +} from '@kadena/kode-icons/system'; import { Box, Button, @@ -32,8 +42,9 @@ import { SideBarBreadcrumbsItem } from '@kadena/kode-ui/patterns'; import { execCodeParser } from '@kadena/pactjs-generator'; import classNames from 'classnames'; import yaml from 'js-yaml'; -import { useEffect, useMemo, useState } from 'react'; +import { FC, useEffect, useMemo, useState } from 'react'; import { useSearchParams } from 'react-router-dom'; +import { TxTileGeneric } from '../transaction-group/components/TxTileGeneric'; import { codeArea } from './style.css'; const getTxFromUrlHash = () => @@ -45,12 +56,18 @@ export function SignatureBuilder() { const [error, setError] = useState(); const [schema, setSchema] = useState(); const [input, setInput] = useState(''); + const [fileContent, setFileContent] = useState(); const [pactCommand, setPactCommand] = useState(); const [unsignedTx, setUnsignedTx] = useState(); const [signed, setSignedTx] = useState(); const [capsWithoutSigners, setCapsWithoutSigners] = useState< ISigningRequest['caps'] >([]); + const [groupId] = useState(crypto.randomUUID()); + const [transactions, setTransactions] = useState([]); + const [existingTransactions, setExistingTransactions] = useState< + ITransaction[] + >([]); const { profile, activeNetwork, networks, setActiveNetwork } = useWallet(); const navigate = usePatchedNavigate(); @@ -75,11 +92,27 @@ export function SignatureBuilder() { if (urlTransaction) { const data = new TextDecoder().decode(base64UrlDecodeArr(urlTransaction)); setInput(data); - processSig(data); + processSigData(data); + addTransactionToGroup(groupId); } }, [urlTransaction]); - function processSig(inputData: string) { + useEffect(() => { + async function addTransaction() { + if (unsignedTx && profile) { + await addTransactionToGroup(groupId); + setTransactions( + await transactionRepository.getTransactionsByGroup( + groupId, + profile.uuid, + ), + ); + } + } + addTransaction(); + }, [unsignedTx]); + + function processSigData(inputData: string) { setInput(inputData); let schema = determineSchema(inputData); if (schema === 'base64') { @@ -121,10 +154,36 @@ export function SignatureBuilder() { setSchema(schema); } - const reviewTransaction = async () => { + const removeTransactionToAdd = async (tx: ITransaction) => { + if (!profile) return; + + // remove transaction from existingTransactions + if ( + existingTransactions.find((item) => item.uuid === tx.uuid) !== undefined + ) { + setExistingTransactions((prev) => + prev.filter((item) => item.uuid !== tx.uuid), + ); + } + + // remove transaction from group + if (transactions.find((item) => item.uuid === tx.uuid) !== undefined) { + await transactionRepository.deleteTransaction(tx.uuid); + setTransactions( + await transactionRepository.getTransactionsByGroup( + groupId, + profile.uuid, + ), + ); + } + }; + + const addTransactionToGroup = async (groupId: string) => { if (!unsignedTx || !profile || !activeNetwork) return; + const command: IPactCommand = JSON.parse(unsignedTx.cmd); let networkUUID = activeNetwork.uuid; + if (command.networkId && activeNetwork.networkId !== command.networkId) { const network = networks.filter( ({ networkId }) => networkId === command.networkId, @@ -132,7 +191,7 @@ export function SignatureBuilder() { if (network.length === 0) { setError( command.networkId === 'mainnet01' - ? 'MANNET_IS_DISABLED: Mainnet is disabled since the wallet is not fully tested; you can try other networks' + ? 'MAINNET_IS_DISABLED: Mainnet is disabled since the wallet is not fully tested; you can try other networks' : 'NETWORK_NOT_FOUND: This network is not found', ); throw new Error('Network not found'); @@ -144,7 +203,6 @@ export function SignatureBuilder() { // switch network setActiveNetwork(network[0]); } - const groupId = crypto.randomUUID(); // check if transaction already exists const tx = await transactionRepository.getTransactionByHashNetworkProfile( @@ -162,12 +220,23 @@ export function SignatureBuilder() { pubKey?: string; }>), ); + await transactionRepository.updateTransaction({ ...tx, sigs: updatedTx.sigs, }); + + if ( + existingTransactions.find((item) => item.uuid === tx.uuid) === + undefined + ) { + setExistingTransactions((prev) => [...prev, tx]); + } } - navigate(`/transaction/${tx.groupId}`); + setPactCommand(undefined); + setUnsignedTx(undefined); + setCapsWithoutSigners([]); + setInput(''); return; } @@ -177,7 +246,15 @@ export function SignatureBuilder() { networkUUID: networkUUID, groupId, }); - navigate(`/transaction/${groupId}`); + + setPactCommand(undefined); + setUnsignedTx(undefined); + setCapsWithoutSigners([]); + setInput(''); + }; + + const reviewTransaction = () => { + navigate(`/transaction-group/${groupId}`); }; return ( @@ -189,17 +266,20 @@ export function SignatureBuilder() { - Paste SigData, CommandSigData, or Payload + + Paste or Upload SigData, CommandSigData, or Payload +