Skip to content

Commit

Permalink
feat(bot): add retrieve bot to bot/slug page
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenepix committed Jan 18, 2024
1 parent d08509e commit 0daa84f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
16 changes: 15 additions & 1 deletion desktop-app/renderer/api/bots/bots.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Order } from '@/api/orders/orders'
import { Wallet } from '@/api/wallets/wallets'
import { request } from 'api/request'
import { AxiosResponse } from 'axios'
import { useSearchParams } from 'next/navigation'

export interface Bot {
name: string
uuid: string
Expand All @@ -12,9 +13,22 @@ export interface Bot {
exchangeAccount: string
}

export interface RetrievedBot extends Bot {
wallet: Wallet
orders: Order[]
}

export async function listBot(
searchParams: ReturnType<typeof useSearchParams>
): Promise<AxiosResponse<Bot[]>> {
const response = await request(searchParams, 'GET', `/api/bot/`)
return response as AxiosResponse<Bot[]>
}

export async function retrieveBot(
searchParams: ReturnType<typeof useSearchParams>,
uuid: string
): Promise<AxiosResponse<RetrievedBot>> {
const response = await request(searchParams, 'GET', `/api/bot/${uuid}/`)
return response as AxiosResponse<RetrievedBot>
}
23 changes: 23 additions & 0 deletions desktop-app/renderer/api/orders/orders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export interface Order {
side: string
completed: boolean
spent: {
ticker: string
amount: number
price: number
value: number
}
received: {
ticker: string
amount: number
price: number
value: number
}
fees: {
ticker: string
amount: number
price: number
value: number
}
created_at: string
}
34 changes: 34 additions & 0 deletions desktop-app/renderer/pages/bots/[slug]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
import { RetrievedBot, retrieveBot } from '@/api/bots/bots'
import ContextHeader from '@/components/layout/contextHeader'
import DefaultPageLayout from '@/components/layout/defaultPageLayout'
import { standardUrlPartial } from '@/lib/queryParams'
import { useRouter, useSearchParams } from 'next/navigation'
import { useEffect, useState } from 'react'

export default function Bot(): JSX.Element {
const searchParams = useSearchParams()
const router = useRouter()

const botID: string = searchParams.get('bot') || ''
const [bot, setBot] = useState<RetrievedBot>()

useEffect(() => {
async function fetchBot() {
try {
const response = await retrieveBot(searchParams, botID)
setBot(response.data)
} catch (error) {
console.error(error)
// go to the previous page
router.push(
standardUrlPartial(
'/bots/',
null,
{ space: '', fleet: '', bot: '' },
searchParams
)
)
}
}

if (searchParams.get('server')) {
fetchBot()
}
}, [botID, searchParams, router])
console.log(bot)
return (
<ContextHeader isBot>
<DefaultPageLayout
Expand Down

0 comments on commit 0daa84f

Please sign in to comment.