refactor: debug api chequebook - cheques methods

This commit is contained in:
Vojtech Simetka
2021-04-02 11:21:04 +02:00
parent d2708738ce
commit d9941038df
4 changed files with 17 additions and 26 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ export default function DepositModal() {
<EthereumAddress <EthereumAddress
hideBlockie hideBlockie
transaction transaction
address={res.data.transactionHash} address={res.transactionHash}
network={'goerli'} network={'goerli'}
/> />
</span>) </span>)
+8 -17
View File
@@ -1,7 +1,7 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import type { NodeAddresses, ChequebookAddressResponse, ChequebookBalanceResponse, BalanceResponse, import { NodeAddresses, ChequebookAddressResponse, ChequebookBalanceResponse, BalanceResponse,
LastChequesResponse, AllSettlements, LastCashoutActionResponse, Health, Peer, Topology, PingResponse } from '@ethersphere/bee-js' LastChequesResponse, AllSettlements, LastCashoutActionResponse, Health, Peer, Topology, PingResponse, LastChequesForPeerResponse } from '@ethersphere/bee-js'
import { beeDebugApi, beeApi } from '../services/bee'; import { beeDebugApi, beeApi } from '../services/bee';
@@ -102,7 +102,7 @@ export const useApiChequebookAddress = () => {
setLoading(true) setLoading(true)
beeDebugApi.chequebook.address() beeDebugApi.chequebook.address()
.then(res => { .then(res => {
setChequebookAddress(res.data) setChequebookAddress(res)
}) })
.catch(error => { .catch(error => {
setError(error) setError(error)
@@ -146,7 +146,7 @@ export const useApiChequebookBalance = () => {
setLoading(true) setLoading(true)
beeDebugApi.chequebook.balance() beeDebugApi.chequebook.balance()
.then(res => { .then(res => {
setChequebookBalance(res.data) setChequebookBalance(res)
}) })
.catch(error => { .catch(error => {
setError(error) setError(error)
@@ -190,7 +190,7 @@ export const useApiPeerCheques = () => {
setLoading(true) setLoading(true)
beeDebugApi.chequebook.getLastCheques() beeDebugApi.chequebook.getLastCheques()
.then(res => { .then(res => {
setPeerCheques(res.data) setPeerCheques(res)
}) })
.catch(error => { .catch(error => {
setError(error) setError(error)
@@ -204,16 +204,7 @@ export const useApiPeerCheques = () => {
} }
export const useApiPeerLastCheque = (peerId: string) => { export const useApiPeerLastCheque = (peerId: string) => {
const [peerCheque, setPeerCheque] = useState({ peer: '-', chequebook: "", const [peerCheque, setPeerCheque] = useState<LastChequesForPeerResponse | null>(null)
cumulativePayout: 0,
beneficiary: "",
transactionHash: "",
result: {
recipient: "",
lastPayout: 0,
bounced: false
}}
)
const [isLoadingPeerCheque, setLoading] = useState<boolean>(false) const [isLoadingPeerCheque, setLoading] = useState<boolean>(false)
const [error, setError] = useState<Error | null>(null) const [error, setError] = useState<Error | null>(null)
@@ -221,7 +212,7 @@ export const useApiPeerLastCheque = (peerId: string) => {
setLoading(true) setLoading(true)
beeDebugApi.chequebook.getPeerLastCheques(peerId) beeDebugApi.chequebook.getPeerLastCheques(peerId)
.then(res => { .then(res => {
setPeerCheque(res.data) setPeerCheque(res)
}) })
.catch(error => { .catch(error => {
setError(error) setError(error)
@@ -288,7 +279,7 @@ export const useApiPeerLastCashout = (peerId: string) => {
setLoading(true) setLoading(true)
beeDebugApi.chequebook.getPeerLastCashout(peerId) beeDebugApi.chequebook.getPeerLastCashout(peerId)
.then(res => { .then(res => {
setPeerCashout(res.data) setPeerCashout(res)
}) })
.catch(error => { .catch(error => {
setError(error) setError(error)
+2 -2
View File
@@ -40,7 +40,7 @@ export default function Index(props: any) {
setIsLoadingPeerCashout(true) setIsLoadingPeerCashout(true)
beeDebugApi.chequebook.getPeerLastCashout(peerId) beeDebugApi.chequebook.getPeerLastCashout(peerId)
.then(res => { .then(res => {
setPeerCashout(res.data) setPeerCashout(res)
}) })
.catch(error => { .catch(error => {
}) })
@@ -51,7 +51,7 @@ export default function Index(props: any) {
setIsLoadingPeerCheque(true) setIsLoadingPeerCheque(true)
beeDebugApi.chequebook.getPeerLastCheques(peerId) beeDebugApi.chequebook.getPeerLastCheques(peerId)
.then(res => { .then(res => {
setPeerCheque(res.data) setPeerCheque(res)
}) })
.catch(error => { .catch(error => {
}) })
+6 -6
View File
@@ -76,22 +76,22 @@ export const beeDebugApi = {
}, },
chequebook: { chequebook: {
address() { address() {
return beeDebugApiClient().get(`/chequebook/address`) return beeJSDebugClient().getChequebookAddress()
}, },
balance() { balance() {
return beeDebugApiClient().get(`/chequebook/balance`) return beeJSDebugClient().getChequebookBalance()
}, },
getLastCheques() { getLastCheques() {
return beeDebugApiClient().get(`/chequebook/cheque`) return beeJSDebugClient().getLastCheques()
}, },
peerCashout(peerId: string) { peerCashout(peerId: string) {
return beeDebugApiClient().post(`/chequebook/cashout/${peerId}`) return beeJSDebugClient().cashoutLastCheque(peerId)
}, },
getPeerLastCashout(peerId: string) { getPeerLastCashout(peerId: string) {
return beeDebugApiClient().get(`/chequebook/cashout/${peerId}`) return beeJSDebugClient().getLastCashoutAction(peerId)
}, },
getPeerLastCheques(peerId: string) { getPeerLastCheques(peerId: string) {
return beeDebugApiClient().get(`/chequebook/cheque/${peerId}`) return beeJSDebugClient().getLastChequesForPeer(peerId)
}, },
withdraw(amount: bigint) { withdraw(amount: bigint) {
return beeDebugApiClient().post(`/chequebook/withdraw?amount=${amount}`) return beeDebugApiClient().post(`/chequebook/withdraw?amount=${amount}`)