From 0e61ab1903835cdd3809bec5956c3f2d1759d465 Mon Sep 17 00:00:00 2001 From: Face <69168154+face-hh@users.noreply.github.com> Date: Wed, 11 Jun 2025 12:06:20 +0300 Subject: [PATCH] fix insufficient funds bug --- .../lib/components/self/SendMoneyModal.svelte | 20 ++++++++----------- .../src/lib/components/self/TradeModal.svelte | 8 ++++---- website/src/routes/coin/create/+page.svelte | 10 +++++----- website/src/routes/portfolio/+page.svelte | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/website/src/lib/components/self/SendMoneyModal.svelte b/website/src/lib/components/self/SendMoneyModal.svelte index 26f0b4a..6559edf 100644 --- a/website/src/lib/components/self/SendMoneyModal.svelte +++ b/website/src/lib/components/self/SendMoneyModal.svelte @@ -53,13 +53,9 @@ : false ); - let isWithinCashLimit = $derived( - transferType === 'CASH' ? numericAmount >= 10 : true - ); + let isWithinCashLimit = $derived(transferType === 'CASH' ? numericAmount >= 10 : true); - let isWithinCoinValueLimit = $derived( - transferType === 'COIN' ? estimatedValue >= 10 : true - ); + let isWithinCoinValueLimit = $derived(transferType === 'COIN' ? estimatedValue >= 10 : true); let canSend = $derived( hasValidAmount && @@ -125,6 +121,10 @@ const result = await response.json(); if (!response.ok) { + if (result.message) { + throw new Error(result.message); + } + throw new Error(result.error || 'Transfer failed'); } @@ -282,13 +282,9 @@ {/if} {#if transferType === 'CASH'} -
- Minimum: $10.00 per transfer -
+Minimum: $10.00 per transfer
{:else if transferType === 'COIN'} -- Minimum estimated value: $10.00 per transfer -
+Minimum estimated value: $10.00 per transfer
{/if} diff --git a/website/src/lib/components/self/TradeModal.svelte b/website/src/lib/components/self/TradeModal.svelte index 417d6e7..9c323dd 100644 --- a/website/src/lib/components/self/TradeModal.svelte +++ b/website/src/lib/components/self/TradeModal.svelte @@ -5,7 +5,7 @@ import { Label } from '$lib/components/ui/label'; import { Badge } from '$lib/components/ui/badge'; import { TrendingUp, TrendingDown, Loader2 } from 'lucide-svelte'; - import { PORTFOLIO_DATA } from '$lib/stores/portfolio-data'; + import { PORTFOLIO_SUMMARY } from '$lib/stores/portfolio-data'; import { toast } from 'svelte-sonner'; let { @@ -35,7 +35,7 @@ ); let estimatedResult = $derived(calculateEstimate(numericAmount, type, currentPrice)); let hasValidAmount = $derived(numericAmount > 0); - let userBalance = $derived($PORTFOLIO_DATA ? $PORTFOLIO_DATA.baseCurrencyBalance : 0); + let userBalance = $derived($PORTFOLIO_SUMMARY ? $PORTFOLIO_SUMMARY.baseCurrencyBalance : 0); let hasEnoughFunds = $derived( type === 'BUY' ? numericAmount <= userBalance : numericAmount <= userHolding ); @@ -113,7 +113,7 @@ function setMaxAmount() { if (type === 'SELL') { amount = maxSellableAmount.toString(); - } else if ($PORTFOLIO_DATA) { + } else if ($PORTFOLIO_SUMMARY) { // For BUY, max is user's balance amount = userBalance.toString(); } @@ -163,7 +163,7 @@Balance: ${userBalance.toFixed(6)}
diff --git a/website/src/routes/coin/create/+page.svelte b/website/src/routes/coin/create/+page.svelte index e6b5dc7..f8c463f 100644 --- a/website/src/routes/coin/create/+page.svelte +++ b/website/src/routes/coin/create/+page.svelte @@ -7,7 +7,7 @@ import { Alert, AlertDescription } from '$lib/components/ui/alert'; import { Separator } from '$lib/components/ui/separator'; import { Info, Loader2, Coins, ImagePlus } from 'lucide-svelte'; - import { PORTFOLIO_DATA, fetchPortfolioData } from '$lib/stores/portfolio-data'; + import { PORTFOLIO_SUMMARY, fetchPortfolioData } from '$lib/stores/portfolio-data'; import { onMount } from 'svelte'; import { CREATION_FEE, INITIAL_LIQUIDITY, TOTAL_COST } from '$lib/data/constants'; import { toast } from 'svelte-sonner'; @@ -46,7 +46,7 @@ ); let hasEnoughFunds = $derived( - $PORTFOLIO_DATA ? $PORTFOLIO_DATA.baseCurrencyBalance >= TOTAL_COST : false + $PORTFOLIO_SUMMARY ? $PORTFOLIO_SUMMARY.baseCurrencyBalance >= TOTAL_COST : false ); let canSubmit = $derived(isFormValid && hasEnoughFunds && !isSubmitting); @@ -126,7 +126,7 @@