diff options
| author | Adam Soltys <[email protected]> | 2025-07-16 00:05:35 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-07-16 00:05:35 -0700 |
| commit | 25ac9d65b346dafb3b1c733cce44feb1c3564aa8 (patch) | |
| tree | e7ce923d19eb8f4527c2e66eaa55d36e3181950c /src/routes/(app)/send | |
| parent | 1d202c7d73aa0d84fa7c2bbc1749b9111054e3b1 (diff) | |
| download | coinos-ui-25ac9d65b346dafb3b1c733cce44feb1c3564aa8.tar.gz coinos-ui-25ac9d65b346dafb3b1c733cce44feb1c3564aa8.zip | |
fix pin issue
Diffstat (limited to 'src/routes/(app)/send')
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.ts | 24 | ||||
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.svelte | 12 |
2 files changed, 23 insertions, 13 deletions
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> |
