2021-11-16 13:58:00 +01:00
|
|
|
<script>
|
|
|
|
import { onMount } from "svelte";
|
2021-11-16 21:11:59 +01:00
|
|
|
import { formatDataVolume, formatDate } from "../util/Formatting.svelte";
|
2021-11-16 13:58:00 +01:00
|
|
|
import Spinner from "../util/Spinner.svelte";
|
2021-11-16 21:11:59 +01:00
|
|
|
import Euro from "../util/Euro.svelte"
|
2021-11-16 13:58:00 +01:00
|
|
|
|
|
|
|
let loading = false
|
|
|
|
let months = []
|
|
|
|
|
|
|
|
const load_transactions = async () => {
|
|
|
|
loading = true
|
|
|
|
try {
|
2022-02-01 18:43:52 +01:00
|
|
|
// We keep fetching history until we have fetched three months without
|
|
|
|
// any transactions
|
|
|
|
let empty_months = 0
|
2021-11-16 13:58:00 +01:00
|
|
|
let now = new Date()
|
2022-02-01 18:43:52 +01:00
|
|
|
while (empty_months < 3) {
|
2021-11-16 13:58:00 +01:00
|
|
|
const resp = await fetch(
|
|
|
|
window.api_endpoint+"/user/transactions/" +
|
|
|
|
now.getFullYear()+"-"+("00"+(now.getMonth()+1)).slice(-2),
|
|
|
|
)
|
|
|
|
if(resp.status >= 400) {
|
|
|
|
let json = await resp.json()
|
|
|
|
if (json.value === "authentication_failed") {
|
|
|
|
window.location = "/login"
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
throw new Error(json.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let month = {
|
|
|
|
rows: await resp.json(),
|
|
|
|
month: now.getFullYear()+"-"+("00"+(now.getMonth()+1)).slice(-2),
|
|
|
|
total_subscription_charge: 0,
|
|
|
|
total_storage_charge: 0,
|
|
|
|
total_bandwidth_charge: 0,
|
2022-01-25 20:37:21 +01:00
|
|
|
total_kickback_fee: 0,
|
2021-11-16 13:58:00 +01:00
|
|
|
total_deposited: 0,
|
|
|
|
total_deducted: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
if (month.rows.length === 0) {
|
2022-02-01 18:43:52 +01:00
|
|
|
empty_months++
|
|
|
|
continue
|
2021-11-16 13:58:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
month.rows.forEach(row => {
|
|
|
|
row.time = new Date(row.time)
|
|
|
|
month.total_deposited += row.deposit_amount
|
|
|
|
month.total_subscription_charge += row.subscription_charge
|
|
|
|
month.total_storage_charge += row.storage_charge
|
|
|
|
month.total_bandwidth_charge += row.bandwidth_charge
|
2022-01-25 20:37:21 +01:00
|
|
|
month.total_kickback_fee += row.kickback_fee
|
2021-11-16 13:58:00 +01:00
|
|
|
month.total_deducted += row.subscription_charge + row.storage_charge + row.bandwidth_charge
|
|
|
|
})
|
|
|
|
months.push(month)
|
|
|
|
months = months
|
|
|
|
|
|
|
|
// Fetch the previous month
|
|
|
|
now.setMonth(now.getMonth()-1)
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
alert(err)
|
|
|
|
} finally {
|
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-30 16:33:57 +01:00
|
|
|
let credit_amount = 10
|
2021-11-16 13:58:00 +01:00
|
|
|
|
2021-12-02 18:29:11 +01:00
|
|
|
const checkout = async (network) => {
|
2021-11-16 13:58:00 +01:00
|
|
|
loading = true
|
|
|
|
const form = new FormData()
|
2021-11-30 16:33:57 +01:00
|
|
|
form.set("amount", credit_amount*1e6)
|
2021-12-02 18:29:11 +01:00
|
|
|
form.set("network", network)
|
2021-11-30 16:33:57 +01:00
|
|
|
|
2021-11-16 13:58:00 +01:00
|
|
|
try {
|
|
|
|
const resp = await fetch(
|
2021-11-30 16:33:57 +01:00
|
|
|
window.api_endpoint+"/btcpay/deposit",
|
|
|
|
{ method: "POST", body: form },
|
2021-11-16 13:58:00 +01:00
|
|
|
)
|
|
|
|
if(resp.status >= 400) {
|
|
|
|
let json = await resp.json()
|
|
|
|
throw json.message
|
|
|
|
}
|
|
|
|
|
2021-11-30 16:33:57 +01:00
|
|
|
window.location = (await resp.json()).checkout_url
|
2021-11-16 13:58:00 +01:00
|
|
|
} catch (err) {
|
2021-11-30 16:33:57 +01:00
|
|
|
alert(err)
|
|
|
|
} finally {
|
2021-11-16 13:58:00 +01:00
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 16:33:57 +01:00
|
|
|
let show_expired = false
|
|
|
|
let invoices = []
|
|
|
|
const load_invoices = async () => {
|
|
|
|
loading = true
|
|
|
|
try {
|
|
|
|
const resp = await fetch(window.api_endpoint+"/btcpay/invoice")
|
|
|
|
if(resp.status >= 400) {
|
|
|
|
throw new Error((await resp.json()).message)
|
|
|
|
}
|
|
|
|
|
|
|
|
let invoices_tmp = await resp.json()
|
|
|
|
invoices_tmp.forEach(row => {
|
|
|
|
row.time = new Date(row.time)
|
|
|
|
})
|
|
|
|
invoices_tmp.sort((a, b) => {
|
|
|
|
return b.time - a.time
|
|
|
|
})
|
|
|
|
invoices = invoices_tmp
|
|
|
|
} catch (err) {
|
2021-12-03 17:47:11 +01:00
|
|
|
console.error(err)
|
2021-11-30 16:33:57 +01:00
|
|
|
alert(err)
|
|
|
|
} finally {
|
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-16 13:58:00 +01:00
|
|
|
onMount(() => {
|
|
|
|
load_transactions()
|
2021-11-30 16:33:57 +01:00
|
|
|
load_invoices()
|
2021-11-16 13:58:00 +01:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2022-01-11 13:28:22 +01:00
|
|
|
{#if loading}
|
|
|
|
<div class="spinner_container">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<h2>Deposit credits</h2>
|
|
|
|
<p>
|
|
|
|
You can deposit credit on your pixeldrain account with Bitcoin,
|
|
|
|
Lightning network (<a
|
|
|
|
href="https://btcpay.pixeldrain.com/embed/uS2mbWjXUuaAqMh8XLjkjwi8oehFuxeBZxekMxv68LN/BTC/ln"
|
|
|
|
target="_blank">node info</a>) and Dogecoin. You must pay the full
|
|
|
|
amount as stated on the invoice, else your payment will fail.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Do note that it is not possible to withdraw coins from your
|
|
|
|
pixeldrain account. It's not a wallet. Any amount of money you
|
|
|
|
deposit has to be used up.
|
|
|
|
</p>
|
|
|
|
<div style="text-align: center;">
|
|
|
|
Deposit amount €
|
|
|
|
<input type="number" bind:value={credit_amount} min="1"/>
|
|
|
|
<br/>
|
|
|
|
Pay with:<br/>
|
|
|
|
<button on:click={() => {checkout("btc")}}>
|
|
|
|
<span class="icon_unicode">₿</span> Bitcoin
|
|
|
|
</button>
|
|
|
|
<button on:click={() => {checkout("btc_lightning")}}>
|
|
|
|
<i class="icon">bolt</i> Lightning network
|
|
|
|
</button>
|
|
|
|
<button on:click={() => {checkout("doge")}}>
|
|
|
|
<span class="icon_unicode">Ð</span> Dogecoin
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h3>Open invoices</h3>
|
|
|
|
<div class="table_scroll">
|
|
|
|
<table style="text-align: left;">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<td>Created</td>
|
|
|
|
<td>Amount</td>
|
|
|
|
<td>Status</td>
|
|
|
|
<td></td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{#each invoices as row (row.id)}
|
|
|
|
{#if row.status === "New" ||
|
|
|
|
row.status === "InvoiceCreated" ||
|
|
|
|
row.status === "InvoiceProcessing" ||
|
|
|
|
show_expired
|
|
|
|
}
|
|
|
|
<tr>
|
|
|
|
<td>{formatDate(row.time, true, true, false)}</td>
|
|
|
|
<td><Euro amount={row.amount}></Euro></td>
|
|
|
|
<td>
|
|
|
|
{#if row.status === "InvoiceCreated"}
|
|
|
|
New (waiting for payment)
|
|
|
|
{:else if row.status === "InvoiceProcessing"}
|
|
|
|
Payment received, waiting for confirmations
|
|
|
|
{:else if row.status === "InvoiceSettled"}
|
|
|
|
Paid
|
|
|
|
{:else if row.status === "InvoiceExpired"}
|
|
|
|
Expired
|
|
|
|
{:else}
|
|
|
|
{row.status}
|
|
|
|
{/if}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
{#if row.status === "New" || row.status === "InvoiceCreated"}
|
|
|
|
<a href={row.checkout_url} class="button button_highlight">
|
|
|
|
<i class="icon">paid</i> Pay
|
|
|
|
</a>
|
|
|
|
{/if}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{/if}
|
|
|
|
{/each}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2022-01-04 16:21:58 +01:00
|
|
|
<div style="text-align: center;">
|
2022-01-11 13:28:22 +01:00
|
|
|
<button on:click={() => {show_expired = !show_expired}}>
|
|
|
|
{#if show_expired}
|
|
|
|
Hide
|
|
|
|
{:else}
|
|
|
|
Show
|
|
|
|
{/if}
|
|
|
|
expired and settled invoices
|
2021-12-09 22:16:52 +01:00
|
|
|
</button>
|
2021-11-30 16:33:57 +01:00
|
|
|
</div>
|
2022-01-11 13:28:22 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<h2>Transaction log</h2>
|
|
|
|
<p>
|
|
|
|
Here is a log of all transactions on your account balance.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
{#each months as month}
|
|
|
|
<h3>{month.month}</h3>
|
|
|
|
<ul>
|
|
|
|
<li>Subscription charge: <Euro amount={month.total_subscription_charge}></Euro></li>
|
|
|
|
<li>Storage charge: <Euro amount={month.total_storage_charge}></Euro></li>
|
|
|
|
<li>Bandwidth charge: <Euro amount={month.total_bandwidth_charge}></Euro></li>
|
|
|
|
<li>Total charge: <Euro amount={month.total_deducted}></Euro></li>
|
2022-01-25 20:37:21 +01:00
|
|
|
<li>Earned: <Euro amount={month.total_kickback_fee}></Euro></li>
|
2022-01-11 13:28:22 +01:00
|
|
|
<li>Deposited: <Euro amount={month.total_deposited}></Euro></li>
|
|
|
|
</ul>
|
2021-11-30 16:33:57 +01:00
|
|
|
|
|
|
|
<div class="table_scroll">
|
|
|
|
<table style="text-align: left;">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2022-01-11 13:28:22 +01:00
|
|
|
<td>Time</td>
|
|
|
|
<td>Balance</td>
|
|
|
|
<td>Subscription</td>
|
|
|
|
<td colspan="2">Storage</td>
|
|
|
|
<td colspan="2">Bandwidth</td>
|
2022-01-25 20:37:21 +01:00
|
|
|
<td colspan="2">Kickback</td>
|
|
|
|
<td>Deposit</td>
|
2022-01-11 13:28:22 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
2022-01-25 20:37:21 +01:00
|
|
|
<td>Charge</td>
|
|
|
|
<td>Charge</td>
|
|
|
|
<td>Usage</td>
|
|
|
|
<td>Charge</td>
|
|
|
|
<td>Usage</td>
|
|
|
|
<td>Fee</td>
|
|
|
|
<td>Amount</td>
|
2021-11-30 16:33:57 +01:00
|
|
|
<td></td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2022-01-11 13:28:22 +01:00
|
|
|
{#each month.rows as row}
|
|
|
|
<tr>
|
|
|
|
<td>{formatDate(row.time, true, true, false)}</td>
|
|
|
|
<td><Euro amount={row.new_balance}></Euro></td>
|
|
|
|
<td><Euro amount={row.subscription_charge} precision="4"></Euro></td>
|
|
|
|
<td><Euro amount={row.storage_charge} precision="4"></Euro></td>
|
|
|
|
<td>{formatDataVolume(row.storage_used, 3)}</td>
|
|
|
|
<td><Euro amount={row.bandwidth_charge} precision="4"></Euro></td>
|
|
|
|
<td>{formatDataVolume(row.bandwidth_used, 3)}</td>
|
2022-01-25 20:37:21 +01:00
|
|
|
<td><Euro amount={row.kickback_fee} precision="4"></Euro></td>
|
|
|
|
<td>{formatDataVolume(row.kickback_amount, 3)}</td>
|
2022-01-11 13:28:22 +01:00
|
|
|
<td><Euro amount={row.deposit_amount}></Euro></td>
|
|
|
|
</tr>
|
2021-11-30 16:33:57 +01:00
|
|
|
{/each}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2022-01-11 13:28:22 +01:00
|
|
|
{/each}
|
|
|
|
</section>
|
2021-11-16 13:58:00 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.spinner_container {
|
|
|
|
position: absolute;
|
|
|
|
top: 10px;
|
|
|
|
left: 10px;
|
|
|
|
height: 100px;
|
|
|
|
width: 100px;
|
|
|
|
z-index: 1000;
|
|
|
|
}
|
|
|
|
</style>
|