Skip to content

Commit

Permalink
feat: move postage stamp operations to bee debug api (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 committed Nov 24, 2021
1 parent b354ef7 commit 3bb0077
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/pages/stamps/CreatePostageStampModal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { ReactElement, useContext } from 'react'
import Button from '@material-ui/core/Button'
import CircularProgress from '@material-ui/core/CircularProgress'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import CircularProgress from '@material-ui/core/CircularProgress'
import DialogTitle from '@material-ui/core/DialogTitle'
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'
import BigNumber from 'bignumber.js'
import { FormikHelpers, Form, Field, Formik } from 'formik'
import { Field, Form, Formik, FormikHelpers } from 'formik'
import { TextField } from 'formik-material-ui'
import { useSnackbar } from 'notistack'
import React, { ReactElement, useContext } from 'react'
import { Context as SettingsContext } from '../../providers/Settings'
import { Context } from '../../providers/Stamps'
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'
import { useSnackbar } from 'notistack'

interface FormValues {
depth?: string
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function FormDialog({ label }: Props): ReactElement {
const classes = useStyles()
const [open, setOpen] = React.useState(false)
const { refresh } = useContext(Context)
const { beeApi } = useContext(SettingsContext)
const { beeDebugApi } = useContext(SettingsContext)
const handleClickOpen = () => setOpen(true)
const handleClose = () => setOpen(false)
const { enqueueSnackbar } = useSnackbar()
Expand All @@ -67,12 +67,12 @@ export default function FormDialog({ label }: Props): ReactElement {
// This is really just a typeguard, the validation pretty much guarantees these will have the right values
if (!values.depth || !values.amount) return

if (!beeApi) return
if (!beeDebugApi) return

const amount = BigInt(values.amount)
const depth = Number.parseInt(values.depth)
const options = values.label ? { label: values.label } : undefined
await beeApi.createPostageBatch(amount.toString(), depth, options)
await beeDebugApi.createPostageBatch(amount.toString(), depth, options)
actions.resetForm()
await refresh()
handleClose()
Expand Down
8 changes: 4 additions & 4 deletions src/providers/Stamps.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostageBatch } from '@ethersphere/bee-js'
import { createContext, ReactChild, ReactElement, useEffect, useState, useContext } from 'react'
import { createContext, ReactChild, ReactElement, useContext, useEffect, useState } from 'react'
import { Context as SettingsContext } from './Settings'

export interface EnrichedPostageBatch extends PostageBatch {
Expand Down Expand Up @@ -48,7 +48,7 @@ function enrichStamp(postageBatch: PostageBatch): EnrichedPostageBatch {
}

export function Provider({ children }: Props): ReactElement {
const { beeApi } = useContext(SettingsContext)
const { beeDebugApi } = useContext(SettingsContext)
const [stamps, setStamps] = useState<EnrichedPostageBatch[] | null>(initialValues.stamps)
const [error, setError] = useState<Error | null>(initialValues.error)
const [isLoading, setIsLoading] = useState<boolean>(initialValues.isLoading)
Expand All @@ -59,11 +59,11 @@ export function Provider({ children }: Props): ReactElement {
// Don't want to refresh when already refreshing
if (isLoading) return

if (!beeApi) return
if (!beeDebugApi) return

try {
setIsLoading(true)
const stamps = await beeApi.getAllPostageBatch()
const stamps = await beeDebugApi.getAllPostageBatch()

setStamps(stamps.map(enrichStamp))
setLastUpdate(Date.now())
Expand Down

0 comments on commit 3bb0077

Please sign in to comment.