add compound
parent
e06983ea61
commit
6a65883448
@ -0,0 +1,14 @@
|
|||||||
|
// nanoid code
|
||||||
|
const urlAlphabet =
|
||||||
|
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||||
|
export const nanoid = (size = 32) => {
|
||||||
|
let id = ''
|
||||||
|
let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
|
||||||
|
while (size--) {
|
||||||
|
// Using the bitwise AND operator to "cap" the value of
|
||||||
|
// the random byte from 255 to 63, in that way we can make sure
|
||||||
|
// that the value will be a valid index for the "chars" string.
|
||||||
|
id += urlAlphabet[bytes[size] & 63]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
import { db } from '$lib/db/index.js'
|
||||||
|
import { stacking_config } from '$lib/db/schema.js'
|
||||||
|
import { nanoid } from '$lib/nanoid.js'
|
||||||
|
import { eq } from 'drizzle-orm'
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
export const POST = async ({ request }) => {
|
||||||
|
const body = await request.json()
|
||||||
|
|
||||||
|
const data = z
|
||||||
|
.object({
|
||||||
|
threshhold: z.number().min(0),
|
||||||
|
stackRate: z.number().min(0),
|
||||||
|
})
|
||||||
|
.safeParse(body)
|
||||||
|
|
||||||
|
if (!data.success) {
|
||||||
|
return new Response()
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await db.query.stacking_config.findFirst()
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
await db.insert(stacking_config).values({
|
||||||
|
id: nanoid(),
|
||||||
|
stackRate: data.data.stackRate,
|
||||||
|
threshhold: data.data.threshhold,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await db
|
||||||
|
.update(stacking_config)
|
||||||
|
.set({
|
||||||
|
stackRate: data.data.stackRate,
|
||||||
|
threshhold: data.data.threshhold,
|
||||||
|
})
|
||||||
|
.where(eq(stacking_config.id, existing.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response()
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import { db } from '$lib/db'
|
||||||
|
|
||||||
|
export const load = async () => {
|
||||||
|
const config = await db.query.stacking_config.findFirst()
|
||||||
|
return {
|
||||||
|
config,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Button } from '$lib/components/ui/button'
|
||||||
|
import { Input } from '$lib/components/ui/input'
|
||||||
|
|
||||||
|
let { config } = $props()
|
||||||
|
|
||||||
|
let stackRate = $state(config?.stackRate || 0)
|
||||||
|
let threshhold = $state(config?.threshold || 0)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="p-4">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
|
<span>Threshold</span>
|
||||||
|
<Input bind:value={threshhold} type="number" class="flex-1" />
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
|
<span>Stack Rate (+%):</span>
|
||||||
|
<Input bind:value={stackRate} type="number" class="flex-1" />
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
onclick={() => {
|
||||||
|
fetch('/api/bybit/stacking', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
stackRate,
|
||||||
|
threshhold,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
}}>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Loading…
Reference in New Issue