diff options
| author | Adam Soltys <[email protected]> | 2024-09-23 20:26:50 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-09-23 20:26:50 -0700 |
| commit | 8c8c71d54d23960ffc4caa94619bae7c6a69514b (patch) | |
| tree | 53c09335935c00ce7db89a62e59c6b804c0ae1a7 | |
| parent | 12ad5c9abb74cbe35c5d07233fdd9a7b7f5c2b70 (diff) | |
| download | coinos-server-8c8c71d54d23960ffc4caa94619bae7c6a69514b.tar.gz coinos-server-8c8c71d54d23960ffc4caa94619bae7c6a69514b.zip | |
translations helper
| -rw-r--r-- | lib/locales/en.json | 1 | ||||
| -rw-r--r-- | lib/payments.ts | 11 | ||||
| -rw-r--r-- | lib/utils.ts | 3 | ||||
| -rw-r--r-- | routes/users.ts | 14 |
4 files changed, 19 insertions, 10 deletions
diff --git a/lib/locales/en.json b/lib/locales/en.json index 73cfbd3f..7d143c53 100644 --- a/lib/locales/en.json +++ b/lib/locales/en.json @@ -1,4 +1,5 @@ { + "balanceAdjustment": "Balance adjustment", "paymentReceived": "Payment received", "hello": "Hello", "youReceived": "You received a payment of", diff --git a/lib/payments.ts b/lib/payments.ts index 4bec9a93..6d83b28f 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -1,4 +1,3 @@ -import locales from "$lib/locales/index"; import config from "$config"; import { generate } from "$lib/invoices"; import { emit } from "$lib/sockets"; @@ -16,6 +15,7 @@ import { SATS, sats, formatReceipt, + t, } from "$lib/utils"; import { callWebhook } from "$lib/webhooks"; import got from "got"; @@ -289,10 +289,10 @@ export let completePayment = async (p, user) => { } } - let t = locales[user.language || "en"]; + let { paymentReceived } = t(user); if (user.verified && user.notify) { - mail(user, t.paymentReceived, templates.paymentReceived, { - ...t, + mail(user, paymentReceived, templates.paymentReceived, { + ...t(user), username, payment: { amount: fmt(p.amount), @@ -318,7 +318,8 @@ export let completePayment = async (p, user) => { } }; -let pay = async ({ aid, amount, to, user }) => { +let pay = async ({ aid = undefined, amount, to, user }) => { + if (!aid) aid = user.id; amount = parseInt(amount) || 0; let lnurl, pr; if (to.includes("@") && to.includes(".")) { diff --git a/lib/utils.ts b/lib/utils.ts index 388ee6c8..e0e1ace5 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -1,3 +1,4 @@ +import locales from "$lib/locales/index"; import { randomBytes, bytesToHex } from "@noble/hashes/utils"; import migrate from "$lib/migrate"; import { g, s } from "$lib/db"; @@ -159,3 +160,5 @@ export function formatReceipt(items, currency) { }) .join("\n"); } + + export let t = ({ language = "en" }) => locales[language]; diff --git a/routes/users.ts b/routes/users.ts index 06e437dd..44a87c95 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -1,7 +1,7 @@ import { appendFile } from "node:fs/promises"; import { g, s, db } from "$lib/db"; import config from "$config"; -import { SATS, pick, bail, fail, getUser } from "$lib/utils"; +import { SATS, pick, bail, fail, getUser, t } from "$lib/utils"; import jwt from "jsonwebtoken"; import { authenticator } from "otplib"; import whitelist from "$lib/whitelist"; @@ -16,7 +16,6 @@ import { mail, templates } from "$lib/mail"; import upload from "$lib/upload"; import rpc from "@coinos/rpc"; -let bc = rpc(config.bitcoin); let { encode, decode, fromWords, toWords } = bech32; export default { @@ -646,11 +645,12 @@ export default { await node.importDescriptors(descriptors); let { total_amount } = await node.scanTxOutSet("start", descriptors); let amount = Math.round(total_amount * SATS); + let { balanceAdjustment: memo } = t(user); if (amount) { let hash = v4(); let inv = { - memo: "On-chain balance reconciliation", + memo, type: types.reconcile, hash, amount, @@ -658,8 +658,12 @@ export default { aid: id, }; await s(`invoice:${hash}`, inv); - let { id: pid } = await credit({ hash, amount, type: types.reconcile }); - await db.lPush(`${id}:payments`, pid); + await credit({ + hash, + amount, + type: types.reconcile, + aid: id, + }); } await s(`account:${id}`, account); |
