From 9561edc83965c679b209539ef8828776468e5b04 Mon Sep 17 00:00:00 2001 From: jipstavenuiter Date: Tue, 3 Sep 2024 12:26:31 +0200 Subject: [PATCH] fix: automatically select first fraction owned by user and prefill form values --- components/marketplace/list-dialog.tsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/components/marketplace/list-dialog.tsx b/components/marketplace/list-dialog.tsx index 6d598d69..c977f3b5 100644 --- a/components/marketplace/list-dialog.tsx +++ b/components/marketplace/list-dialog.tsx @@ -77,25 +77,20 @@ function ListDialogInner({ const [state, setState] = useState(() => { const currency = Object.values(client.currencies)[0]; - const unitsForSale = fractionsOwnedByUser[0]?.units || "0"; + const defaultFraction = fractionsOwnedByUser[0]; + const unitsForSale = defaultFraction?.units || "0"; const minimumPrice = getMinimumPrice( unitsForSale, chainId, currency.address, ); return { - fractionId: - fractionsOwnedByUser.length === 1 - ? fractionsOwnedByUser[0].fraction_id || "" - : "", + fractionId: defaultFraction?.fraction_id || "", price: "", currency: currency.address, unitsForSale, unitsMinPerOrder: "1", - unitsMaxPerOrder: - fractionsOwnedByUser.length === 1 - ? fractionsOwnedByUser[0].units || "" - : "", + unitsMaxPerOrder: defaultFraction?.units || "", formIsValid: true, minimumPrice, startDateTime: new Date(Date.now()), @@ -335,8 +330,7 @@ function ListDialogInner({ {actualPriceForListing}{" "} {getCurrencyByAddress(chainId, state.currency)?.symbol} - . To prevent this, use a price that is a multiple - of{" "} + . To prevent this, use a price that is a multiple of{" "} {minimumPrice}{" "} {getCurrencyByAddress(chainId, state.currency)?.symbol}