fix insufficient funds bug
This commit is contained in:
parent
a027fcfbdf
commit
0e61ab1903
4 changed files with 18 additions and 22 deletions
|
|
@ -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}
|
||||
</div>
|
||||
{#if transferType === 'CASH'}
|
||||
<p class="text-muted-foreground text-xs">
|
||||
Minimum: $10.00 per transfer
|
||||
</p>
|
||||
<p class="text-muted-foreground text-xs">Minimum: $10.00 per transfer</p>
|
||||
{:else if transferType === 'COIN'}
|
||||
<p class="text-muted-foreground text-xs">
|
||||
Minimum estimated value: $10.00 per transfer
|
||||
</p>
|
||||
<p class="text-muted-foreground text-xs">Minimum estimated value: $10.00 per transfer</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
<br />Max sellable: {maxSellableAmount.toFixed(0)} {coin.symbol} (pool limit)
|
||||
{/if}
|
||||
</p>
|
||||
{:else if $PORTFOLIO_DATA}
|
||||
{:else if $PORTFOLIO_SUMMARY}
|
||||
<p class="text-muted-foreground text-xs">
|
||||
Balance: ${userBalance.toFixed(6)}
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
<SignInConfirmDialog bind:open={shouldSignIn} />
|
||||
|
||||
<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="text-center">
|
||||
<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 -->
|
||||
<div class="space-y-4">
|
||||
<!-- Cost Summary Card -->
|
||||
{#if $PORTFOLIO_DATA}
|
||||
{#if $PORTFOLIO_SUMMARY}
|
||||
<Card>
|
||||
<CardHeader class="pb-2">
|
||||
<div class="flex items-center justify-between">
|
||||
|
|
@ -272,7 +272,7 @@
|
|||
<div class="text-sm">
|
||||
<span class="text-muted-foreground">Balance: </span>
|
||||
<span class={hasEnoughFunds ? 'text-green-600' : 'text-destructive'}>
|
||||
${$PORTFOLIO_DATA.baseCurrencyBalance.toLocaleString()}
|
||||
${$PORTFOLIO_SUMMARY.baseCurrencyBalance.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@
|
|||
<Card.Content>
|
||||
<DataTable
|
||||
columns={holdingsColumns}
|
||||
data={portfolioData.coinHoldings}
|
||||
data={portfolioData?.coinHoldings || []}
|
||||
onRowClick={(holding) => goto(`/coin/${holding.symbol}`)}
|
||||
/>
|
||||
</Card.Content>
|
||||
|
|
|
|||
Reference in a new issue