Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
gandlafbtc committed Apr 18, 2023
1 parent 39f5653 commit 9638a49
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 77 deletions.
58 changes: 25 additions & 33 deletions src/comp/elements/CoinSelection.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<script lang="ts">
import type { Mint } from "../../model/mint";
import type { Token } from "../../model/token";
import AvailableTokensTable from "../tokens/AvailableTokensTable.svelte";
import { getAmountForTokenSet } from "../util/walletUtils";
export let mint: Mint
export let amount: number = 0
export let selectedTokens: Token[] = []
import type { Mint } from '../../model/mint';
import type { Token } from '../../model/token';
import AvailableTokensTable from '../tokens/AvailableTokensTable.svelte';
import { getAmountForTokenSet } from '../util/walletUtils';
export let isCoinSelection = false;
export let mint: Mint;
export let amount: number = 0;
export let selectedTokens: Token[] = [];
export let isCoinSelection = false;
</script>

<div class="flex flex-col gap-2 ">
Expand All @@ -20,27 +18,21 @@
<input type="checkbox" bind:checked={isCoinSelection} class="checkbox checkbox-primary" />
</div>
</label>
{#if isCoinSelection}
<AvailableTokensTable {mint} bind:selectedTokens></AvailableTokensTable>
<div class="flex gap-2 items-center">
<div class="grid grid-cols-3 w-full">
<span class="font-bold">
Amount selected:
</span>
<span class="col-span-2">
{getAmountForTokenSet(selectedTokens)} / {amount??0} sats
</span>
{#if getAmountForTokenSet(selectedTokens)- amount > 0}
<span class="font-bold">
Change:
</span>
<span class="col-span-2">
{getAmountForTokenSet(selectedTokens)- amount} sats
</span>
{/if}
</div>

</div>

{/if}
{#if isCoinSelection}
<AvailableTokensTable {mint} bind:selectedTokens />
<div class="flex gap-2 items-center">
<div class="grid grid-cols-3 w-full">
<span class="font-bold"> Amount selected: </span>
<span class="col-span-2">
{getAmountForTokenSet(selectedTokens)} / {amount ?? 0} sats
</span>
{#if getAmountForTokenSet(selectedTokens) - amount > 0}
<span class="font-bold"> Change: </span>
<span class="col-span-2">
{getAmountForTokenSet(selectedTokens) - amount} sats
</span>
{/if}
</div>
</div>
{/if}
</div>
33 changes: 19 additions & 14 deletions src/comp/tokens/AvailableTokensTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
import TokenRow from './TokenRow.svelte';
import type { Token } from '../../model/token';
export let mint: Mint | undefined = undefined
export let selectedTokens: Token[] = []
$: selectedTokensBool = []
$: isPending = mint?false:true;
export let mint: Mint | undefined = undefined;
export let selectedTokens: Token[] = [];
$: selectedTokensBool = [];
$: isPending = mint ? false : true;
$: page = 20;
$: tokenSelection = isPending ? $pendingTokens : $token;
$: tokenFromMint = mint?tokenSelection.filter((t:Token)=> mint?.keysets.includes(t.id)):tokenSelection
$: tokenSub = tokenFromMint.slice(0, page)
$: selectedTokens = tokenSub.filter((t,i) => selectedTokensBool[i])
$: tokenFromMint = mint
? tokenSelection.filter((t: Token) => mint?.keysets.includes(t.id))
: tokenSelection;
$: tokenSub = tokenFromMint.slice(0, page);
$: selectedTokens = tokenSub.filter((t, i) => selectedTokensBool[i]);
const loadMore = () => {
page += 20;
};
</script>

<div class="overflow-x-scroll overflow-y-scroll max-h-40 scrollbar-hide">
Expand All @@ -31,9 +32,13 @@
<th>
<div class="flex justify-start items-center gap-1">
{#if !mint}
<p class="hidden lg:flex">Pending</p>
<p class="flex lg:hidden">Pnd</p>
<input type="checkbox" bind:checked={isPending} class="{mint?'disabled hidden':''} checkbox checkbox-primary " />
<p class="hidden lg:flex">Pending</p>
<p class="flex lg:hidden">Pnd</p>
<input
type="checkbox"
bind:checked={isPending}
class="{mint ? 'disabled hidden' : ''} checkbox checkbox-primary "
/>
{/if}
</div>
</th>
Expand Down
8 changes: 4 additions & 4 deletions src/comp/tokens/TokenRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import { browser } from '$app/environment';
import type { Mint } from '../../model/mint';
export let mint: Mint | undefined
export let isSelected =false
export let mint: Mint | undefined;
export let isSelected = false;
export let token: Token;
export let i: number;
let isLoading = false;
Expand Down Expand Up @@ -112,7 +112,7 @@
<td>
<div class="flex gap-1 items-center">
{#if mint}
<input type="checkbox" bind:checked={isSelected} class="checkbox checkbox-primary" />
<input type="checkbox" bind:checked={isSelected} class="checkbox checkbox-primary" />
{/if}

<TokenIcon />
Expand Down
40 changes: 19 additions & 21 deletions src/comp/wallet/Melting.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
$: mint = $mints[0];
$: amountAvailable = getAmountForTokenSet(getTokensForMint(mint, $token));
$: selectedTokens = []
$: isCoinSelection = false
$: selectedTokens = [];
$: isCoinSelection = false;
onMount(() => {
decodeInvoice();
});
Expand Down Expand Up @@ -80,27 +80,19 @@
const cashuWallet: CashuWallet = new CashuWallet(mint.keys, cashuMint);
let tokensToSend: Array<Token> = [];
let tokensToSend: Array<Token>= []
if (isCoinSelection) {
tokensToSend = selectedTokens
}
else
{
getTokensToSend(amount + fees, getTokensForMint(mint, $token));
}
if (
amount + fees >
getAmountForTokenSet(tokensToSend)
) {
if (isCoinSelection) {
tokensToSend = selectedTokens;
} else {
getTokensToSend(amount + fees, getTokensForMint(mint, $token));
}
if (amount + fees > getAmountForTokenSet(tokensToSend)) {
toast('warning', 'not enough funds', 'Could not Send');
isLoading = false;
return;
}
const { returnChange, send } = await cashuWallet.send(amount + fees, tokensToSend);
console.log(send);
Expand Down Expand Up @@ -284,11 +276,17 @@
</div>
</div>

<CoinSelection amount={amount+fees} {mint} bind:selectedTokens bind:isCoinSelection></CoinSelection>
<CoinSelection amount={amount + fees} {mint} bind:selectedTokens bind:isCoinSelection />

<div class="flex items-center gap-2">
<button class="btn btn-outline" on:click={resetState}>cancel</button>
<button class="btn {isPayable&&!(isCoinSelection&&getAmountForTokenSet(selectedTokens)<amount+fees ) ? 'btn-warning' : 'btn-disabled'}" on:click={() => payInvoice()}>
<button
class="btn {isPayable &&
!(isCoinSelection && getAmountForTokenSet(selectedTokens) < amount + fees)
? 'btn-warning'
: 'btn-disabled'}"
on:click={() => payInvoice()}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
Expand Down
12 changes: 7 additions & 5 deletions src/comp/wallet/Sending.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
toast('warning', 'amount must be larger than 0', 'Could not send');
return;
}
if (
amountToSend >
getAmountForTokenSet(tokensToSend)
) {
if (amountToSend > getAmountForTokenSet(tokensToSend)) {
toast('warning', 'not enough funds', 'Could not Send');
isLoading = false;
return;
Expand Down Expand Up @@ -366,7 +363,12 @@
</div>
<div class="flex gap-2">
<button class="btn" on:click={() => resetState()}>cancel</button>
<button class="btn {isCoinSelection&&getAmountForTokenSet(selectedTokens)<amountToSend?'btn-disabled':'btn-success'}" on:click={send}>send</button>
<button
class="btn {isCoinSelection && getAmountForTokenSet(selectedTokens) < amountToSend
? 'btn-disabled'
: 'btn-success'}"
on:click={send}>send</button
>
</div>
</div>
{/if}
Expand Down

0 comments on commit 9638a49

Please sign in to comment.