From 5372ef002471d8e9d11be5ea67097456efef2e4e Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Sun, 11 Aug 2024 18:26:11 +0200 Subject: [PATCH] refactor: remove id and checked prop from type Utxo --- src/components/Send/ShowUtxos.tsx | 33 +++++++++++++++++-------- src/components/jar_details/UtxoList.tsx | 2 +- src/context/WalletContext.tsx | 4 +-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/components/Send/ShowUtxos.tsx b/src/components/Send/ShowUtxos.tsx index c15b4e30c..32c1bed73 100755 --- a/src/components/Send/ShowUtxos.tsx +++ b/src/components/Send/ShowUtxos.tsx @@ -27,8 +27,8 @@ interface ShowUtxosProps { } interface UtxoRowProps { - utxo: SelectableUtxo - onToggle: (utxo: SelectableUtxo) => void + utxo: SelectableUtxoTableRowData + onToggle: (utxo: SelectableUtxoTableRowData) => void settings: Settings showBackgroundColor: boolean walletInfo: WalletInfo @@ -161,6 +161,11 @@ const UtxoRow = ({ utxo, onToggle, showBackgroundColor, settings, walletInfo, t ) } +type SelectableUtxoTableRowData = SelectableUtxo & { + // TODO: add "tags" here and remove from "Utxo" type + // tags?: { tag: string; color: string }[] +} & Pick + const UtxoListDisplay = ({ utxos, onToggle, settings, showBackgroundColor = true }: UtxoListDisplayProps) => { const { t } = useTranslation() const walletInfo = useCurrentWalletInfo() @@ -179,18 +184,26 @@ const UtxoListDisplay = ({ utxos, onToggle, settings, showBackgroundColor = true } const tableTheme = useTheme(TABLE_THEME) + const tableData: TableTypes.Data = useMemo( + () => ({ + nodes: utxos.map( + (utxo: Utxo) => + ({ + ...utxo, + id: utxo.utxo, + }) as SelectableUtxoTableRowData, + ), + }), + [utxos], + ) + return (
- - {(utxosList: TableTypes.TableProps) => ( +
+ {(utxosList: TableTypes.TableProps) => ( {walletInfo && - utxosList.map((utxo: SelectableUtxo, index: number) => { + utxosList.map((utxo: SelectableUtxoTableRowData, index: number) => { return ( { return utxo as Utxo } -interface UtxoTableRow extends Utxo { +interface UtxoTableRow extends Utxo, TableTypes.TableNode { _icon: JSX.Element _tags: Tag[] _confs: JSX.Element diff --git a/src/context/WalletContext.tsx b/src/context/WalletContext.tsx index 5632f7975..080df1ae4 100644 --- a/src/context/WalletContext.tsx +++ b/src/context/WalletContext.tsx @@ -53,8 +53,7 @@ export type Utxo = { // `locktime` in format "yyyy-MM-dd 00:00:00" // NOTE: it is unparsable with safari Date constructor locktime?: string - id: string - checked?: boolean + // TODO: remove 'tags' prop tags?: { tag: string; color: string }[] } @@ -195,7 +194,6 @@ export const groupByJar = (utxos: Utxos): UtxosByJar => { return utxos.reduce((res, utxo) => { const { mixdepth } = utxo res[mixdepth] = res[mixdepth] || [] - utxo.id = utxo.utxo res[mixdepth].push(utxo) return res }, {} as UtxosByJar)