mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
purgatory account fix
Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
parent
6f33f953df
commit
6ffb9fc783
@ -15,10 +15,9 @@ import {
|
|||||||
MetadataCache
|
MetadataCache
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { PurgatoryData } from '@oceanprotocol/lib/dist/node/ddo/interfaces/PurgatoryData'
|
import { PurgatoryData } from '@oceanprotocol/lib/dist/node/ddo/interfaces/PurgatoryData'
|
||||||
import { useOcean } from '../index'
|
import { useOcean } from '../OceanProvider'
|
||||||
import { isDDO, getDataTokenPrice } from 'utils'
|
import { isDDO, getDataTokenPrice } from 'utils'
|
||||||
import { getAssetPurgatoryData } from '../../utils/getPurgatoryData'
|
import { getAssetPurgatoryData } from '../../utils/getPurgatoryData'
|
||||||
import ProviderStatus from '../OceanProvider/ProviderStatus'
|
|
||||||
import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
|
import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper'
|
||||||
|
|
||||||
interface AssetProviderValue {
|
interface AssetProviderValue {
|
||||||
@ -98,7 +97,7 @@ function AssetProvider({
|
|||||||
try {
|
try {
|
||||||
const result = await getAssetPurgatoryData(did)
|
const result = await getAssetPurgatoryData(did)
|
||||||
|
|
||||||
if (result.did !== undefined) {
|
if (result?.did !== undefined) {
|
||||||
setIsInPurgatory(true)
|
setIsInPurgatory(true)
|
||||||
setPurgatoryData(result)
|
setPurgatoryData(result)
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,12 +79,12 @@ function OceanProvider({
|
|||||||
ProviderStatus.NOT_AVAILABLE
|
ProviderStatus.NOT_AVAILABLE
|
||||||
)
|
)
|
||||||
|
|
||||||
const setPurgatory = useCallback(async (accountId: string): Promise<void> => {
|
const setPurgatory = useCallback(async (address: string): Promise<void> => {
|
||||||
if (!accountId) return
|
if (!address) return
|
||||||
try {
|
try {
|
||||||
const result = await getAccountPurgatoryData(accountId)
|
const result = await getAccountPurgatoryData(address)
|
||||||
|
|
||||||
if (result.address !== undefined) {
|
if (result?.address !== undefined) {
|
||||||
setIsInPurgatory(true)
|
setIsInPurgatory(true)
|
||||||
setPurgatoryData(result)
|
setPurgatoryData(result)
|
||||||
} else {
|
} else {
|
||||||
@ -147,8 +147,6 @@ function OceanProvider({
|
|||||||
const balance = await getBalance(account)
|
const balance = await getBalance(account)
|
||||||
setBalance(balance)
|
setBalance(balance)
|
||||||
Logger.log('balance', JSON.stringify(balance))
|
Logger.log('balance', JSON.stringify(balance))
|
||||||
|
|
||||||
await setPurgatory(accountId)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error)
|
Logger.error(error)
|
||||||
}
|
}
|
||||||
@ -178,6 +176,12 @@ function OceanProvider({
|
|||||||
|
|
||||||
// TODO: #68 Refetch balance periodically, or figure out some event to subscribe to
|
// 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(() => {
|
useEffect(() => {
|
||||||
const handleAccountsChanged = async (accounts: string[]) => {
|
const handleAccountsChanged = async (accounts: string[]) => {
|
||||||
Logger.debug("Handling 'accountsChanged' event with payload", accounts)
|
Logger.debug("Handling 'accountsChanged' event with payload", accounts)
|
||||||
|
@ -12,7 +12,7 @@ export async function getAssetPurgatoryData(
|
|||||||
): Promise<PurgatoryData> {
|
): Promise<PurgatoryData> {
|
||||||
const response = await axios(`${purgatoryUrl}asset?did=${did}`)
|
const response = await axios(`${purgatoryUrl}asset?did=${did}`)
|
||||||
const responseJson = await response.data[0]
|
const responseJson = await response.data[0]
|
||||||
return { did: responseJson.did, reason: responseJson.reason }
|
return { did: responseJson?.did, reason: responseJson?.reason }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAccountPurgatoryData(
|
export async function getAccountPurgatoryData(
|
||||||
@ -20,5 +20,5 @@ export async function getAccountPurgatoryData(
|
|||||||
): Promise<AccountPurgatoryData> {
|
): Promise<AccountPurgatoryData> {
|
||||||
const response = await axios(`${purgatoryUrl}account?address=${address}`)
|
const response = await axios(`${purgatoryUrl}account?address=${address}`)
|
||||||
const responseJson = await response.data[0]
|
const responseJson = await response.data[0]
|
||||||
return { address: responseJson.address, reason: responseJson.reason }
|
return { address: responseJson?.address, reason: responseJson?.reason }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user