aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/LoadingSplash.svelte
blob: 2ab4c73913b0bd4c45ad2067f13e54eb9604c7f3 (plain) (blame)
1
2
3
4
5
6
7
<script>
	import { Icon } from '$comp';
</script>

<div class="flex justify-center items-center">
	<Icon icon="logo" style="mt-[calc(50vh-72px)]" />
</div>
Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
import { get } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
import * as Qr from "qrcode-base64";

export async function load({ cookies, depends, params, url, parent }) {
	depends("app:invoice");

	const token = cookies.get("token");
	let { subject, user } = await parent();
	const { id } = params;
	let invoice;

	if (id) {
		invoice = await get(`/invoice/${id}`);
		const options = !!url.searchParams.get("options");

		if (
			user &&
			invoice.uid !== user.id &&
			!(url.pathname.includes("tip") || url.pathname.includes("memo")) &&
			!options
		) {
			redirect(307, `/send/invoice/${id}`);
		}

		let { amount, pending, received } = invoice;
		amount = parseInt(amount);
		subject = invoice.user;

		const paid =
			(!amount && (pending || received)) ||
			(amount > 0 && (pending >= amount || received >= amount));
		if (paid && !url.pathname.endsWith("paid")) {
			redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : ""));
		}
	}

	const src = Qr.drawImg(invoice?.text || "", { size: 500 });
	const theme = cookies.get("theme") || "light";
	return { id, invoice, subject, src, user, token, theme };
}