2020-09-04 11:24:11 +02:00
|
|
|
import React, { useCallback } from 'react'
|
2020-07-13 11:57:27 +02:00
|
|
|
import { useOcean } from '@oceanprotocol/react'
|
2020-07-14 13:34:08 +02:00
|
|
|
import { useEffect } from 'react'
|
2020-07-13 11:57:27 +02:00
|
|
|
|
|
|
|
export function Wallet() {
|
2020-07-31 11:28:36 +02:00
|
|
|
const { ocean, connect, logout, accountId } = useOcean()
|
|
|
|
|
2020-07-13 11:57:27 +02:00
|
|
|
const conn = async () => {
|
2020-07-31 11:28:36 +02:00
|
|
|
await connect()
|
2020-07-13 11:57:27 +02:00
|
|
|
}
|
2020-07-31 11:28:36 +02:00
|
|
|
|
2020-09-04 11:24:11 +02:00
|
|
|
const init = useCallback(async () => {
|
2020-09-07 13:11:46 +02:00
|
|
|
if (ocean === undefined || accountId === undefined) return
|
|
|
|
await ocean.assets.ownerAssets(accountId)
|
2020-09-04 11:24:11 +02:00
|
|
|
}, [accountId, ocean])
|
2020-07-31 11:28:36 +02:00
|
|
|
|
2020-07-13 11:57:27 +02:00
|
|
|
useEffect(() => {
|
|
|
|
init()
|
2020-09-04 11:24:11 +02:00
|
|
|
}, [ocean, accountId, init])
|
2020-07-13 11:57:27 +02:00
|
|
|
|
|
|
|
const disc = async () => {
|
|
|
|
await logout()
|
|
|
|
await conn()
|
|
|
|
}
|
2020-07-31 11:28:36 +02:00
|
|
|
|
2020-07-13 11:57:27 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>wallet</div>
|
2020-07-14 13:34:08 +02:00
|
|
|
<div>
|
|
|
|
<button onClick={conn}>Connect</button>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button onClick={disc}>Disconnect</button>
|
|
|
|
</div>
|
2020-07-13 11:57:27 +02:00
|
|
|
<div>{accountId}</div>
|
|
|
|
</>
|
|
|
|
)
|
2020-07-14 13:34:08 +02:00
|
|
|
}
|