Skip to content

Commit

Permalink
Merge pull request #172 from napse-invest/feature/bot
Browse files Browse the repository at this point in the history
Feature/bot
  • Loading branch information
Xenepix authored Jan 7, 2024
2 parents b4cd132 + 2850aa0 commit d08509e
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 69 deletions.
3 changes: 3 additions & 0 deletions desktop-app/renderer/api/bots/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export interface Bot {
uuid: string
value: number
delta: number
fleet: string
space?: string
exchangeAccount: string
}

export async function listBot(
Expand Down
2 changes: 1 addition & 1 deletion desktop-app/renderer/api/fleets/fleets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Fleet extends BaseFleet {
value: number
bot_count: number
delta: number
exchange_account: string
exchangeAccount: string
}

export interface RetrievedFleet extends BaseFleet {
Expand Down
4 changes: 2 additions & 2 deletions desktop-app/renderer/api/spaces/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface History {
export interface BaseNapseSpace {
name: string
description: string
exchange_account: string
exchangeAccount: string
}

export interface NapseSpace extends BaseNapseSpace {
Expand All @@ -26,7 +26,7 @@ export interface NapseSpace extends BaseNapseSpace {

export interface RetrievedNapseSpace extends BaseNapseSpace {
uuid: string
exchange_account: string
exchangeAccount: string
created_at: string
statistics: Statistics
wallet: Wallet
Expand Down
19 changes: 16 additions & 3 deletions desktop-app/renderer/pages/bots/[slug]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
export default function Todo(): JSX.Element {
// TODO: implement or move this file
return <></>
import ContextHeader from '@/components/layout/contextHeader'
import DefaultPageLayout from '@/components/layout/defaultPageLayout'

export default function Bot(): JSX.Element {
return (
<ContextHeader isBot>
<DefaultPageLayout
header={'Your Bots'}
description={
'Bots look to make your money grow while you do something else.'
}
>
<></>
</DefaultPageLayout>
</ContextHeader>
)
}
124 changes: 68 additions & 56 deletions desktop-app/renderer/pages/bots/index.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,77 @@
import { Bot, listBot } from '@/api/bots/bots'
import { Key, getCurrentKey } from '@/api/key/key'
import ValuePanelCard from '@/components/custom/panel/valuePanelCard'
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'

import { Card, Metric, Text, Flex, BadgeDelta, Grid } from '@tremor/react'
import type { DeltaType } from '@tremor/react'
export default function Bots(): JSX.Element {
const searchParams = useSearchParams()
const router = useRouter()
const [bots, setBots] = useState<Bot[]>([])
const [currentKey, setCurrentKey] = useState<Key>()

interface Category {
title: string
metric: string
metricPrev: string
delta: string
deltaType: DeltaType
}
useEffect(() => {
async function fetchBots() {
try {
const response = await listBot(searchParams)
setBots(response.data)
} catch (error) {
console.error(error)
setBots([])
}
}
const fetchCurrentKey = async () => {
try {
const response = await getCurrentKey(searchParams)
setCurrentKey(response)
} catch (error) {
console.error(error)
setCurrentKey(undefined)
}
}
if (searchParams.get('server')) {
fetchBots()
fetchCurrentKey()
}
}, [searchParams])

const categories: Category[] = [
{
title: 'Sales',
metric: '$ 12,699',
metricPrev: '$ 9,456',
delta: '34.3%',
deltaType: 'moderateIncrease'
},
{
title: 'Profit',
metric: '$ 40,598',
metricPrev: '$ 45,564',
delta: '10.9%',
deltaType: 'moderateDecrease'
},
{
title: 'Customers',
metric: '1,072',
metricPrev: '856',
delta: '25.3%',
deltaType: 'moderateIncrease'
}
]
export default function Bots(): JSX.Element {
return (
<ContextHeader isBot>
<Grid numItemsSm={2} numItemsLg={3} className="gap-6">
{categories.map((item) => (
<Card key={item.title}>
<Flex alignItems="start">
<Text>{item.title}</Text>
<BadgeDelta
className=" rounded-tremor-small"
deltaType={item.deltaType}
>
{item.delta}
</BadgeDelta>
</Flex>
<Flex
justifyContent="start"
alignItems="baseline"
className="space-x-3 truncate"
>
<Metric>{item.metric}</Metric>
<Text className="truncate">from {item.metricPrev}</Text>
</Flex>
</Card>
))}
</Grid>
<DefaultPageLayout
header={'Your Bots'}
description={
'Bots look to make your money grow while you do something else.'
}
>
<div className="my-10 grid max-w-screen-xl grid-cols-3 gap-6">
{bots.map((bot, index) => (
<ValuePanelCard
key={index}
title={bot.name}
value={bot.value}
delta={bot.delta}
onClick={() => {
router.push(
standardUrlPartial(
'/bots/',
bot.uuid,
{
exchangeAccount: bot.exchangeAccount,
space: bot.space,
fleet: bot.fleet,
bot: bot.uuid
},
searchParams
)
)
}}
/>
))}
</div>
</DefaultPageLayout>
</ContextHeader>
)
}
5 changes: 2 additions & 3 deletions desktop-app/renderer/pages/fleets/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ export default function Fleet(): JSX.Element {
onClick={() => {
router.push(
standardUrlPartial(
'/fleets/',
'/bots/',
bot.uuid,
{
fleet: bot.uuid,
bot: ''
bot: bot.uuid
},
searchParams
)
Expand Down
1 change: 1 addition & 0 deletions desktop-app/renderer/pages/fleets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default function Fleets(): JSX.Element {
'/fleets/',
fleet.uuid,
{
exchangeAccount: fleet.exchangeAccount,
space: fleet.space,
fleet: fleet.uuid,
bot: ''
Expand Down
6 changes: 3 additions & 3 deletions desktop-app/renderer/pages/spaces/createSpaceDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as z from 'zod'
const defaultSpace: BaseNapseSpace = {
name: 'My Space',
description: 'My Space Description',
exchange_account: '7bdd866e-f2a2-4ea9-a01e-02ddb77a80fe'
exchangeAccount: '7bdd866e-f2a2-4ea9-a01e-02ddb77a80fe'
}

export default function CreateSpaceDialog({
Expand Down Expand Up @@ -95,12 +95,12 @@ export default function CreateSpaceDialog({
},
{
label: 'Exchange',
key: 'exchange_account',
key: 'exchangeAccount',
// type: 'select',
// possibilities: possibleExchangeAccounts,
type: 'input',
zod: z.string(),
default: defaultSpace.exchange_account
default: defaultSpace.exchangeAccount
}
]}
onSubmit={async (values) => {
Expand Down
2 changes: 1 addition & 1 deletion desktop-app/renderer/pages/spaces/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function Spaces(): JSX.Element {
'/spaces/',
space.uuid,
{
exchangeAccount: space.exchange_account,
exchangeAccount: space.exchangeAccount,
space: space.uuid,
fleet: '',
bot: ''
Expand Down

0 comments on commit d08509e

Please sign in to comment.