mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
cleanup
This commit is contained in:
parent
9911c458a7
commit
62d210f89f
@ -1,76 +0,0 @@
|
|||||||
import React, { useState, useEffect, ReactElement } from 'react'
|
|
||||||
import { useNavigate } from '@reach/router'
|
|
||||||
import { DDO } from '@oceanprotocol/lib'
|
|
||||||
import Button from '../atoms/Button'
|
|
||||||
import BaseDialog from '../atoms/BaseDialog'
|
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
|
||||||
|
|
||||||
const content = [
|
|
||||||
'You are about to delete your Data Set.',
|
|
||||||
'Your Data Set is being deleted...',
|
|
||||||
'You have deleted your Data Set ',
|
|
||||||
'Something happened... Your Data Set cannot be deleted'
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function DeleteAction({ ddo }: { ddo: DDO }): ReactElement {
|
|
||||||
const { ocean, accountId } = useOcean()
|
|
||||||
const navigate = useNavigate()
|
|
||||||
const isOwner = ddo.publicKey[0].owner === accountId
|
|
||||||
const [isModal, setIsModal] = useState(false)
|
|
||||||
const [status, setStatus] = useState(0) // 0-confirmation, 1-deleting, 2-success, 3-error
|
|
||||||
const { attributes } = ddo.findServiceByType('metadata')
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let tId: number
|
|
||||||
if (status === 2) {
|
|
||||||
tId = window.setTimeout(() => {
|
|
||||||
navigate(`/`)
|
|
||||||
}, 1000)
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
clearTimeout(tId)
|
|
||||||
}
|
|
||||||
}, [status])
|
|
||||||
if (!accountId || !ocean || !isOwner) return null
|
|
||||||
async function handleDeleteAction() {
|
|
||||||
if (!ocean) return
|
|
||||||
|
|
||||||
setStatus(1)
|
|
||||||
setIsModal(true)
|
|
||||||
try {
|
|
||||||
const consumerAddress = (await ocean.accounts.list())[0]
|
|
||||||
await ocean.assets.retire(ddo.id, consumerAddress)
|
|
||||||
|
|
||||||
setStatus(2)
|
|
||||||
} catch (error) {
|
|
||||||
// TODO: handle error
|
|
||||||
console.log(error)
|
|
||||||
setStatus(3)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
setIsModal(false)
|
|
||||||
setStatus(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleOpenConfirmation = () => setIsModal(true)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Button onClick={handleOpenConfirmation}>Delete</Button>
|
|
||||||
|
|
||||||
<BaseDialog
|
|
||||||
title={`Delete ${attributes.main.name}`}
|
|
||||||
open={isModal}
|
|
||||||
onClose={() => setIsModal(false)}
|
|
||||||
>
|
|
||||||
{content[status]}
|
|
||||||
<footer>
|
|
||||||
<Button onClick={handleDeleteAction}>Confirm</Button>
|
|
||||||
<Button onClick={handleCancel}>Cancel</Button>
|
|
||||||
</footer>
|
|
||||||
</BaseDialog>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
@ -50,7 +50,9 @@ export default function PoolTransactions(): ReactElement {
|
|||||||
async function getLogs() {
|
async function getLogs() {
|
||||||
if (!ocean || !accountId) return
|
if (!ocean || !accountId) return
|
||||||
|
|
||||||
const logs = await ocean.pool.getAllPoolLogs(accountId)
|
const logs = await ocean.pool.getAllPoolLogs(
|
||||||
|
'0xe08A1dAe983BC701D05E492DB80e0144f8f4b909'
|
||||||
|
)
|
||||||
// limit to 100 latest transactions for now
|
// limit to 100 latest transactions for now
|
||||||
setLogs(logs.slice(0, 99))
|
setLogs(logs.slice(0, 99))
|
||||||
}
|
}
|
||||||
@ -63,7 +65,8 @@ export default function PoolTransactions(): ReactElement {
|
|||||||
data={logs}
|
data={logs}
|
||||||
className={styles.table}
|
className={styles.table}
|
||||||
noHeader
|
noHeader
|
||||||
pagination
|
pagination={logs?.length >= 19}
|
||||||
|
paginationPerPage={20}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user