1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-11-22 09:47:06 +01:00

purgatory account fix

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2020-11-13 19:26:48 +02:00
parent 6f33f953df
commit 6ffb9fc783
No known key found for this signature in database
GPG Key ID: 4FB0C2329B4C6E29
3 changed files with 14 additions and 11 deletions

View File

@ -15,10 +15,9 @@ import {
MetadataCache
} from '@oceanprotocol/lib'
import { PurgatoryData } from '@oceanprotocol/lib/dist/node/ddo/interfaces/PurgatoryData'
import { useOcean } from '../index'
import { useOcean } from '../OceanProvider'
import { isDDO, getDataTokenPrice } from 'utils'
import { getAssetPurgatoryData } from '../../utils/getPurgatoryData'
import ProviderStatus from '../OceanProvider/ProviderStatus'
import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
interface AssetProviderValue {
@ -98,7 +97,7 @@ function AssetProvider({
try {
const result = await getAssetPurgatoryData(did)
if (result.did !== undefined) {
if (result?.did !== undefined) {
setIsInPurgatory(true)
setPurgatoryData(result)
} else {

View File

@ -79,12 +79,12 @@ function OceanProvider({
ProviderStatus.NOT_AVAILABLE
)
const setPurgatory = useCallback(async (accountId: string): Promise<void> => {
if (!accountId) return
const setPurgatory = useCallback(async (address: string): Promise<void> => {
if (!address) return
try {
const result = await getAccountPurgatoryData(accountId)
const result = await getAccountPurgatoryData(address)
if (result.address !== undefined) {
if (result?.address !== undefined) {
setIsInPurgatory(true)
setPurgatoryData(result)
} else {
@ -147,8 +147,6 @@ function OceanProvider({
const balance = await getBalance(account)
setBalance(balance)
Logger.log('balance', JSON.stringify(balance))
await setPurgatory(accountId)
} catch (error) {
Logger.error(error)
}
@ -178,6 +176,12 @@ function OceanProvider({
// TODO: #68 Refetch balance periodically, or figure out some event to subscribe to
useEffect(() => {
if (!accountId) return
console.log('balanc ref', accountId)
setPurgatory(accountId)
}, [accountId])
useEffect(() => {
const handleAccountsChanged = async (accounts: string[]) => {
Logger.debug("Handling 'accountsChanged' event with payload", accounts)

View File

@ -12,7 +12,7 @@ export async function getAssetPurgatoryData(
): Promise<PurgatoryData> {
const response = await axios(`${purgatoryUrl}asset?did=${did}`)
const responseJson = await response.data[0]
return { did: responseJson.did, reason: responseJson.reason }
return { did: responseJson?.did, reason: responseJson?.reason }
}
export async function getAccountPurgatoryData(
@ -20,5 +20,5 @@ export async function getAccountPurgatoryData(
): Promise<AccountPurgatoryData> {
const response = await axios(`${purgatoryUrl}account?address=${address}`)
const responseJson = await response.data[0]
return { address: responseJson.address, reason: responseJson.reason }
return { address: responseJson?.address, reason: responseJson?.reason }
}