fix insufficient funds bug

This commit is contained in:
Face 2025-06-11 12:06:20 +03:00
parent a027fcfbdf
commit 0e61ab1903
4 changed files with 18 additions and 22 deletions

View file

@ -53,13 +53,9 @@
: false : false
); );
let isWithinCashLimit = $derived( let isWithinCashLimit = $derived(transferType === 'CASH' ? numericAmount >= 10 : true);
transferType === 'CASH' ? numericAmount >= 10 : true
);
let isWithinCoinValueLimit = $derived( let isWithinCoinValueLimit = $derived(transferType === 'COIN' ? estimatedValue >= 10 : true);
transferType === 'COIN' ? estimatedValue >= 10 : true
);
let canSend = $derived( let canSend = $derived(
hasValidAmount && hasValidAmount &&
@ -125,6 +121,10 @@
const result = await response.json(); const result = await response.json();
if (!response.ok) { if (!response.ok) {
if (result.message) {
throw new Error(result.message);
}
throw new Error(result.error || 'Transfer failed'); throw new Error(result.error || 'Transfer failed');
} }
@ -282,13 +282,9 @@
{/if} {/if}
</div> </div>
{#if transferType === 'CASH'} {#if transferType === 'CASH'}
<p class="text-muted-foreground text-xs"> <p class="text-muted-foreground text-xs">Minimum: $10.00 per transfer</p>
Minimum: $10.00 per transfer
</p>
{:else if transferType === 'COIN'} {:else if transferType === 'COIN'}
<p class="text-muted-foreground text-xs"> <p class="text-muted-foreground text-xs">Minimum estimated value: $10.00 per transfer</p>
Minimum estimated value: $10.00 per transfer
</p>
{/if} {/if}
</div> </div>

View file

@ -5,7 +5,7 @@
import { Label } from '$lib/components/ui/label'; import { Label } from '$lib/components/ui/label';
import { Badge } from '$lib/components/ui/badge'; import { Badge } from '$lib/components/ui/badge';
import { TrendingUp, TrendingDown, Loader2 } from 'lucide-svelte'; 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'; import { toast } from 'svelte-sonner';
let { let {
@ -35,7 +35,7 @@
); );
let estimatedResult = $derived(calculateEstimate(numericAmount, type, currentPrice)); let estimatedResult = $derived(calculateEstimate(numericAmount, type, currentPrice));
let hasValidAmount = $derived(numericAmount > 0); 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( let hasEnoughFunds = $derived(
type === 'BUY' ? numericAmount <= userBalance : numericAmount <= userHolding type === 'BUY' ? numericAmount <= userBalance : numericAmount <= userHolding
); );
@ -113,7 +113,7 @@
function setMaxAmount() { function setMaxAmount() {
if (type === 'SELL') { if (type === 'SELL') {
amount = maxSellableAmount.toString(); amount = maxSellableAmount.toString();
} else if ($PORTFOLIO_DATA) { } else if ($PORTFOLIO_SUMMARY) {
// For BUY, max is user's balance // For BUY, max is user's balance
amount = userBalance.toString(); amount = userBalance.toString();
} }
@ -163,7 +163,7 @@
<br />Max sellable: {maxSellableAmount.toFixed(0)} {coin.symbol} (pool limit) <br />Max sellable: {maxSellableAmount.toFixed(0)} {coin.symbol} (pool limit)
{/if} {/if}
</p> </p>
{:else if $PORTFOLIO_DATA} {:else if $PORTFOLIO_SUMMARY}
<p class="text-muted-foreground text-xs"> <p class="text-muted-foreground text-xs">
Balance: ${userBalance.toFixed(6)} Balance: ${userBalance.toFixed(6)}
</p> </p>

View file

@ -7,7 +7,7 @@
import { Alert, AlertDescription } from '$lib/components/ui/alert'; import { Alert, AlertDescription } from '$lib/components/ui/alert';
import { Separator } from '$lib/components/ui/separator'; import { Separator } from '$lib/components/ui/separator';
import { Info, Loader2, Coins, ImagePlus } from 'lucide-svelte'; 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 { onMount } from 'svelte';
import { CREATION_FEE, INITIAL_LIQUIDITY, TOTAL_COST } from '$lib/data/constants'; import { CREATION_FEE, INITIAL_LIQUIDITY, TOTAL_COST } from '$lib/data/constants';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
@ -46,7 +46,7 @@
); );
let hasEnoughFunds = $derived( 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); let canSubmit = $derived(isFormValid && hasEnoughFunds && !isSubmitting);
@ -126,7 +126,7 @@
<SignInConfirmDialog bind:open={shouldSignIn} /> <SignInConfirmDialog bind:open={shouldSignIn} />
<div class="container mx-auto max-w-5xl px-4 py-6"> <div class="container mx-auto max-w-5xl px-4 py-6">
{#if !$PORTFOLIO_DATA} {#if !$PORTFOLIO_SUMMARY}
<div class="flex h-96 items-center justify-center"> <div class="flex h-96 items-center justify-center">
<div class="text-center"> <div class="text-center">
<div class="text-muted-foreground mb-4 text-xl">Sign in to create your own coin</div> <div class="text-muted-foreground mb-4 text-xl">Sign in to create your own coin</div>
@ -264,7 +264,7 @@
<!-- Right Column - Preview and Info --> <!-- Right Column - Preview and Info -->
<div class="space-y-4"> <div class="space-y-4">
<!-- Cost Summary Card --> <!-- Cost Summary Card -->
{#if $PORTFOLIO_DATA} {#if $PORTFOLIO_SUMMARY}
<Card> <Card>
<CardHeader class="pb-2"> <CardHeader class="pb-2">
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
@ -272,7 +272,7 @@
<div class="text-sm"> <div class="text-sm">
<span class="text-muted-foreground">Balance: </span> <span class="text-muted-foreground">Balance: </span>
<span class={hasEnoughFunds ? 'text-green-600' : 'text-destructive'}> <span class={hasEnoughFunds ? 'text-green-600' : 'text-destructive'}>
${$PORTFOLIO_DATA.baseCurrencyBalance.toLocaleString()} ${$PORTFOLIO_SUMMARY.baseCurrencyBalance.toLocaleString()}
</span> </span>
</div> </div>
</div> </div>

View file

@ -366,7 +366,7 @@
<Card.Content> <Card.Content>
<DataTable <DataTable
columns={holdingsColumns} columns={holdingsColumns}
data={portfolioData.coinHoldings} data={portfolioData?.coinHoldings || []}
onRowClick={(holding) => goto(`/coin/${holding.symbol}`)} onRowClick={(holding) => goto(`/coin/${holding.symbol}`)}
/> />
</Card.Content> </Card.Content>