Skip to content

Commit

Permalink
fix(space): work on space section rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenepix38 committed Oct 21, 2023
1 parent 90e2395 commit 9d48244
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 57 deletions.
6 changes: 6 additions & 0 deletions desktop-app/renderer/api/fleets/fleets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Fleet{
name: string
uuid: string
value: number
bot_count: number
}
37 changes: 32 additions & 5 deletions desktop-app/renderer/api/spaces/spaces.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
import { Fleet } from 'api/fleets/fleets'
import { request } from 'api/request'
import { Wallet } from 'api/wallets/wallets'
import { AxiosResponse } from 'axios'
import { useSearchParams } from 'next/navigation'

export interface NapseSpace {
export interface BaseNapseSpace{
name: string
description: string
exchange_account: string
}

export interface NapseSpace extends BaseNapseSpace{
uuid: string
value: number
fleet_count: number
}

interface Statistics {
[Key: string]: number
}

interface History{
// TODO: Improve this
[Key: string]: number
}

export interface RetrievedNapseSpace extends BaseNapseSpace {
uuid: string
exchange_account: string
delta?: number
created_at: string
statistics: Statistics
wallet: Wallet
// history:
fleets: Fleet[]
}




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

export async function getSpace(
export async function retrieveSpace(
searchParams: ReturnType<typeof useSearchParams>,
id: string
): Promise<AxiosResponse<NapseSpace>> {
): Promise<AxiosResponse<RetrievedNapseSpace>> {
const response = await request(searchParams, 'GET', `/api/space/${id}/`)
return response as AxiosResponse<NapseSpace>
return response as AxiosResponse<RetrievedNapseSpace>
}
20 changes: 20 additions & 0 deletions desktop-app/renderer/api/wallets/wallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export interface Currency{
ticker: string
mbp: number
amount: number
}

export interface Operation{
amount: number
ticker: string
operation_type: string
created_at: string
}

export interface Wallet{
title: string
value: string
created_at: string
currencies: Currency[]
operations: Operation[]
}
63 changes: 11 additions & 52 deletions desktop-app/renderer/pages/spaces/index.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,23 @@
import ValuePanelCard from '@/components/custom/panel/valuePanelCard'
import ContextHeader from '@/components/layout/contextHeader'

import { NapseSpace, listSpace } from '@/api/spaces/spaces'
import { standardUrlPartial } from '@/lib/queryParams'
import { AxiosResponse } from 'axios'
import DefaultPageLayout from '@/components/layout/defaultPageLayout'
import { useSearchParams } from 'next/navigation'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'

export default function Spaces(): JSX.Element {
const [spaces, setSpaces] = useState<NapseSpace[]>([])
const searchParams = useSearchParams()
useEffect(() => {
const fetchServers = async () => {
try {
const response: AxiosResponse<NapseSpace[]> =
await listSpace(searchParams)
setSpaces(response.data)
} catch (error) {
console.error(error)
setSpaces([])
}
}
if (searchParams.get('server')) {
fetchServers()
}
}, [searchParams])

const router = useRouter()
// const [Spaces, setSpaces] = useState<>

return (
<ContextHeader isBot>
<div className="mx-auto my-10 grid max-w-screen-xl gap-6 px-24 lg:grid-cols-3">
{spaces.map((space, index) => (
<ValuePanelCard
key={index}
title={space.name}
value={space.value}
delta={space.delta}
// tooltip={space.tooltip}
onClick={() => {
router
.push(
standardUrlPartial(
'/spaces/',
space.uuid,
{
exchangeAccount: space.exchange_account,
space: space.uuid
},
searchParams
)
)
.catch((err) => {
console.error(err)
})
}}
badge={String(space.fleet_count) + ' fleets'}
/>
))}
</div>
<DefaultPageLayout
header={'Your spaces'}
description={
'Here is an overview of all your spaces. A space make it easy to manage your money.'
}
>
<></>
</DefaultPageLayout>
</ContextHeader>
)
}
64 changes: 64 additions & 0 deletions desktop-app/renderer/pages/spaces/index_backup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import ValuePanelCard from '@/components/custom/panel/valuePanelCard'
import ContextHeader from '@/components/layout/contextHeader'

import { NapseSpace, listSpace } from '@/api/spaces/spaces'
import { standardUrlPartial } from '@/lib/queryParams'
import { AxiosResponse } from 'axios'
import { useSearchParams } from 'next/navigation'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'

export default function Spaces(): JSX.Element {
const [spaces, setSpaces] = useState<NapseSpace[]>([])
const searchParams = useSearchParams()
useEffect(() => {
const fetchServers = async () => {
try {
const response: AxiosResponse<NapseSpace[]> =
await listSpace(searchParams)
setSpaces(response.data)
} catch (error) {
console.error(error)
setSpaces([])
}
}
if (searchParams.get('server')) {
fetchServers()
}
}, [searchParams])

const router = useRouter()
return (
<ContextHeader isBot>
<div className="mx-auto my-10 grid max-w-screen-xl gap-6 px-24 lg:grid-cols-3">
{spaces.map((space, index) => (
<ValuePanelCard
key={index}
title={space.name}
value={space.value}
delta={space.delta}
// tooltip={space.tooltip}
onClick={() => {
router
.push(
standardUrlPartial(
'/spaces/',
space.uuid,
{
exchangeAccount: space.exchange_account,
space: space.uuid
},
searchParams
)
)
.catch((err) => {
console.error(err)
})
}}
badge={String(space.fleet_count) + ' fleets'}
/>
))}
</div>
</ContextHeader>
)
}

0 comments on commit 9d48244

Please sign in to comment.