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>
|
||||
|
|
|
|||
Reference in a new issue