various safeguards, minor fixes/improvements

This commit is contained in:
stjet
2025-01-22 05:48:11 +00:00
parent b76e9c09fd
commit 1bdd6c11f6
3 changed files with 24 additions and 12 deletions

View File

@@ -49,16 +49,17 @@ export async function find_payment(db: MongoClient, domain: string, send_to: str
}
//todo: technically possible for there to be race condition with payment_already_pending
export async function create_payment(db: MongoClient, domain: string, send_to: string, receive_seed: string) {
export async function create_payment(db: MongoClient, domain: string, send_to: string, receive_seed: string): bool {
const price = get_price(domain.length);
const payments = db.db("bns_backend").collection("payments");
await payments.insertOne({
const result = await payments.insertOne({
domain,
receive_seed, //seed to receive payment from
send_to, //Domain Address (banano address) to send domain to after payment received
price,
timestamp: Date.now(),
});
return result.acknowledged;
}
//

View File

@@ -7,32 +7,40 @@
let error: String = $state("");
let price: String = $state("");
let address_register_safeguard: bool = true;
function domain_keydown(event: KeyboardEvent) {
let key = event.key.toLowerCase();
if (!ALLOWED.includes(key)) {
event.preventDefault();
} else {
price = "";
if (domain_content.length > 3) {
price = `Price: ${get_price(domain_content.length)} BAN`;
}
}
}
function domain_keyup() {
function domain_keyup(event: KeyboardEvent) {
if (domain_content.length > 3) {
price = `Price: ${get_price(domain_content.length)} BAN`;
} else {
price = "";
}
domain_content = domain_content.toLowerCase();
}
async function domain_next() {
error = "";
domain_content = domain_content.toLowerCase();
if (domain_content.length < 4) {
error = "Domain name must be more than 3 characters";
} else {
//safeguard to make people don't accidentally paste in their banano address and register that
if (domain_content.startsWith("ban_") && domain_content.length === 32 && address_register_safeguard) {
alert("It seems like you entered a Banano address instead of the .ban domain name you want to register. Are you sure you want to do this? Try again if so.");
address_register_safeguard = false;
return;
}
const resp = await (await fetch("/api/domain_issued?domain=" + domain_content)).json();
if (resp.issued) {
error = "Domain name already issued, choose another one";
error = `Domain name <a href="https://creeper.banano.cc/account/${domain_content}.ban">already issued</a>, choose another one`;
} else {
error = "";
goto("/register?domain=" + domain_content);
}
}
@@ -97,7 +105,7 @@
<input placeholder="Get your .ban on" maxlength="32" onkeydown={domain_keydown} onkeyup={domain_keyup} bind:value={domain_content} type="text"/><span>.ban</span><input onclick={domain_next} type="button" value="-->"/>
</div>
<span id="price">{price}</span>
<span class="error">{error}</span>
<span class="error">{@html error}</span>
<div>
<h2>Supported by:</h2>
<div>

View File

@@ -23,7 +23,10 @@ export const POST: RequestHandler = async ({ request }) => {
return error(500, "Payment for domain already pending, wait 5 minutes or so");
}
const payment_wallet = Wallet.gen_random_wallet();
await create_payment(db, domain, get_address_from_public_key(send_to_pub_key), payment_wallet.seed);
const success = await create_payment(db, domain, get_address_from_public_key(send_to_pub_key), payment_wallet.seed);
if (!success) {
return error(500, "Server error, try again");
}
return json({
payment_address: payment_wallet.address,
});