Skip to content

Commit

Permalink
Merge pull request #814 from Ekep-Obasi/feat/called-getprice-endpoint…
Browse files Browse the repository at this point in the history
…-on-cost-step

feat: called /getprice to retrive price on cost step
  • Loading branch information
Rassl authored Jan 25, 2024
2 parents 8284628 + 3f3c1d1 commit a7e947f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/components/AddContentModal/BudgetStep/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
import { Button } from '@mui/material'
import { FC } from 'react'
import { FC, useEffect, useState } from 'react'
import styled from 'styled-components'
import CheckIcon from '~/components/Icons/CheckIcon'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { getPriceData } from '~/network/fetchSourcesData'
import { useUserStore } from '~/stores/useUserStore'
import { colors, formatBudget } from '~/utils'
import { isSource } from '../utils'

type Props = {
onClick: () => void
loading: boolean
type: string
}

export const BudgetStep: FC<Props> = ({ onClick, loading }) => {
export const BudgetStep: FC<Props> = ({ onClick, loading, type }) => {
const budget = useUserStore((s) => s.budget)
const [price, setPrice] = useState<number>(10)
const endPoint = isSource(type) ? 'radar' : 'add_node'

useEffect(() => {
const run = async () => {
try {
const res = await getPriceData(endPoint)

setPrice(res.data.price)
} catch (err) {
console.error('cannot fetch', err)
}
}

run()
}, [endPoint])

return (
<Flex>
Expand All @@ -26,7 +45,7 @@ export const BudgetStep: FC<Props> = ({ onClick, loading }) => {
<Flex align="center" direction="row" justify="space-between" mb={20}>
<Cost>
<div className="title">COST</div>
<div className="value">10 sats</div>
<div className="value">{price} sats</div>
</Cost>
<Budget>
<div className="title">BUDGET</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/AddContentModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export const AddContentModal = () => {
)}
</>
)}
{currentStep === 2 && <BudgetStep loading={loading} onClick={() => null} />}
{currentStep === 2 && <BudgetStep loading={loading} onClick={() => null} type={type} />}
</form>
</FormProvider>
</BaseModal>
Expand Down
16 changes: 16 additions & 0 deletions src/network/fetchSourcesData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export type TStatParams = {
num_video: number
}

export type TPriceParams = {
success: string
message: string
data: {
price: number
endpoint: string
method: string
}
}

export type TMergeTopicsParams = {
from: string
to: string
Expand Down Expand Up @@ -136,3 +146,9 @@ export const deleteRadarData = async (id: string) => {

return response
}

export const getPriceData = async (endpoint: string) => {
const response = await api.get<TPriceParams>(`/getprice?endpoint=${endpoint}&method=post`)

return response
}

0 comments on commit a7e947f

Please sign in to comment.