aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-07-16 00:05:35 -0700
committerAdam Soltys <[email protected]>2025-07-16 00:05:35 -0700
commit25ac9d65b346dafb3b1c733cce44feb1c3564aa8 (patch)
treee7ce923d19eb8f4527c2e66eaa55d36e3181950c /src
parent1d202c7d73aa0d84fa7c2bbc1749b9111054e3b1 (diff)
downloadcoinos-ui-25ac9d65b346dafb3b1c733cce44feb1c3564aa8.tar.gz
coinos-ui-25ac9d65b346dafb3b1c733cce44feb1c3564aa8.zip
fix pin issue
Diffstat (limited to 'src')
-rw-r--r--src/locales/en.json1
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.server.ts18
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.svelte12
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.server.ts24
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.svelte12
5 files changed, 46 insertions, 21 deletions
diff --git a/src/locales/en.json b/src/locales/en.json
index 72c3cd41..77b2cb20 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -407,6 +407,7 @@
}
},
"payments": {
+ "custom": "Custom",
"trustUser": "Send and enable auto-pay",
"gift": "Gift all funds",
"giftLink": "Gift link",
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
index 286d7c35..988b6da5 100644
--- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts
+++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
@@ -1,18 +1,19 @@
import invoice from "$lib/invoice";
import getRates from "$lib/rates";
import { auth, get, post } from "$lib/utils";
-import { redirect } from "@sveltejs/kit";
+import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, parent }) {
const rates = await getRates();
let { invoice, subject, user } = await parent();
if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`);
+ const pin = cookies.get("pin");
if (user) {
const trust = await get("/trust", auth(cookies));
const trusted = trust.includes(invoice.uid);
- if (trusted) {
- if (invoice.prompt && invoice.tip === null && user.tip > 0) {
+ if (trusted && (pin || !user.haspin)) {
+ if (!invoice.prompt && invoice.user.prompt && user.tip > 0) {
invoice.tip = Math.round(invoice.amount * (user.tip / 100));
invoice = await post(
"/invoice",
@@ -21,8 +22,15 @@ export async function load({ cookies, parent }) {
);
}
- const p = await post("/payments", invoice, auth(cookies));
- redirect(307, `/sent/${p.id}`);
+ let p;
+ try {
+ p = await post("/payments", { ...invoice, pin }, auth(cookies));
+ } catch (e) {
+ const { message } = e as Error;
+ fail(400, { message });
+ }
+
+ if (p) redirect(307, `/sent/${p.id}`);
}
}
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte
index d609d86a..97d87bb0 100644
--- a/src/routes/(app)/invoice/[id]/tip/+page.svelte
+++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte
@@ -127,7 +127,10 @@
<div class="ml-auto text-lg flex gap-2">
<div class="flex items-center">
- <iconify-icon noobserver icon="ph:lightning-fill" class="text-yellow-300"
+ <iconify-icon
+ noobserver
+ icon="ph:lightning-fill"
+ class="text-yellow-300"
></iconify-icon>
<div>{s(amount, locale)}</div>
</div>
@@ -170,12 +173,15 @@
{/if}
</div>
- <div>
+ <div class="space-y-2">
<button
type="button"
class="btn"
- onclick={() => (showCustomAmount = true)}>Custom</button
+ onclick={() => (showCustomAmount = true)}
+ >{$t("payments.custom")}</button
>
+
+ <a href={`/invoice/${id}`} class="btn">{$t("payments.cancel")}</a>
</div>
{/if}
diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts
index 18379943..ac3c910e 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.server.ts
+++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts
@@ -1,24 +1,32 @@
import getRates from "$lib/rates";
import { auth, fd, get, post, types } from "$lib/utils";
-import { error, redirect } from "@sveltejs/kit";
+import { error, fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, depends, params: { id }, parent }) {
depends("app:trust");
- const { user } = await parent();
+ const { subject, user } = await parent();
const aid = cookies.get("aid") || user.id;
+ const pin = cookies.get("pin");
- const invoice = await get(`/invoice/${id}`);
+ let invoice = await get(`/invoice/${id}`);
const trust = await get("/trust", auth(cookies));
const trusted = trust.includes(invoice.uid);
- if (trusted) {
+ if (trusted && (pin || !user.haspin)) {
let p;
try {
- p = await post("/payments", invoice, auth(cookies));
+ if (!invoice.tip && invoice.user.prompt && user.tip > 0) {
+ invoice.tip = Math.round(invoice.amount * (user.tip / 100));
+ invoice = await post(
+ "/invoice",
+ { invoice, user: subject },
+ auth(cookies),
+ );
+ }
+ p = await post("/payments", { ...invoice, pin }, auth(cookies));
} catch (e) {
const { message } = e as Error;
- console.log("payment failed", id, e);
- error(500, message);
+ fail(400, { message });
}
if (p) redirect(307, `/sent/${p.id}`);
}
@@ -60,7 +68,7 @@ export const actions = {
} catch (e) {
const { message } = e as Error;
console.log("payment failed", id, e);
- error(500, message);
+ error(500, { message });
}
redirect(307, `/sent/${p.id}`);
diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte
index 9aac5c8d..d5fd00a8 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.svelte
+++ b/src/routes/(app)/send/invoice/[id]/+page.svelte
@@ -207,10 +207,12 @@
<button type="button" class="btn" onclick={external}
>{$t("payments.moreOptions")}</button
>
- <button type="button" class="btn" onclick={toggleTrust}>
- <iconify-icon icon={trusted ? "ph:star-fill" : "ph:star-bold"} width={32}
- ></iconify-icon>
- {$t("payments.trustUser")}</button
- >
+
+ {#if !trusted}
+ <button type="button" class="btn" onclick={toggleTrust}>
+ <iconify-icon icon="ph:star-fill" width={32}></iconify-icon>
+ {$t("payments.trustUser")}</button
+ >
+ {/if}
</form>
</div>