mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
pool transactions component splitup
This commit is contained in:
parent
209dd379dc
commit
3cecfb44a0
@ -0,0 +1,3 @@
|
|||||||
|
.titleText {
|
||||||
|
white-space: pre;
|
||||||
|
}
|
88
src/components/molecules/PoolTransactions/Title.tsx
Normal file
88
src/components/molecules/PoolTransactions/Title.tsx
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
import React, { useState, useEffect, ReactElement } from 'react'
|
||||||
|
import { Datatoken, PoolTransaction } from '.'
|
||||||
|
import { useUserPreferences } from '../../../providers/UserPreferences'
|
||||||
|
import ExplorerLink from '../../atoms/ExplorerLink'
|
||||||
|
import { formatPrice } from '../../atoms/Price/PriceUnit'
|
||||||
|
import styles from './Title.module.css'
|
||||||
|
|
||||||
|
function getSymbol(tokenId: Datatoken) {
|
||||||
|
const symbol = tokenId === null ? 'OCEAN' : tokenId.symbol
|
||||||
|
return symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getTitle(row: PoolTransaction, locale: string) {
|
||||||
|
let title = ''
|
||||||
|
switch (row.event) {
|
||||||
|
case 'swap': {
|
||||||
|
const inToken = row.tokens.filter((x) => x.type === 'in')[0]
|
||||||
|
const inTokenSymbol = getSymbol(inToken.poolToken.tokenId)
|
||||||
|
const outToken = row.tokens.filter((x) => x.type === 'out')[0]
|
||||||
|
const outTokenSymbol = getSymbol(outToken.poolToken.tokenId)
|
||||||
|
title += `Swap ${formatPrice(
|
||||||
|
Math.abs(inToken.value).toString(),
|
||||||
|
locale
|
||||||
|
)}${inTokenSymbol} for ${formatPrice(
|
||||||
|
Math.abs(outToken.value).toString(),
|
||||||
|
locale
|
||||||
|
)}${outTokenSymbol}`
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'setup': {
|
||||||
|
const firstToken = row.tokens.filter(
|
||||||
|
(x) =>
|
||||||
|
x.tokenAddress.toLowerCase() !==
|
||||||
|
row.poolAddress.datatokenAddress.toLowerCase()
|
||||||
|
)[0]
|
||||||
|
const firstTokenSymbol = await getSymbol(firstToken.poolToken.tokenId)
|
||||||
|
const secondToken = row.tokens.filter(
|
||||||
|
(x) =>
|
||||||
|
x.tokenAddress.toLowerCase() ===
|
||||||
|
row.poolAddress.datatokenAddress.toLowerCase()
|
||||||
|
)[0]
|
||||||
|
const secondTokenSymbol = await getSymbol(secondToken.poolToken.tokenId)
|
||||||
|
title += `Create pool with ${formatPrice(
|
||||||
|
Math.abs(firstToken.value).toString(),
|
||||||
|
locale
|
||||||
|
)}${firstTokenSymbol} and ${formatPrice(
|
||||||
|
Math.abs(secondToken.value).toString(),
|
||||||
|
locale
|
||||||
|
)}${secondTokenSymbol}`
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'join':
|
||||||
|
case 'exit': {
|
||||||
|
for (let i = 0; i < row.tokens.length; i++) {
|
||||||
|
const tokenSymbol = await getSymbol(row.tokens[i].poolToken.tokenId)
|
||||||
|
if (i > 0) title += '\n'
|
||||||
|
title += `${row.event === 'join' ? 'Add' : 'Remove'} ${formatPrice(
|
||||||
|
Math.abs(row.tokens[i].value).toString(),
|
||||||
|
locale
|
||||||
|
)}${tokenSymbol}`
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return title
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Title({ row }: { row: PoolTransaction }): ReactElement {
|
||||||
|
const [title, setTitle] = useState<string>()
|
||||||
|
const { locale } = useUserPreferences()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!locale || !row) return
|
||||||
|
async function init() {
|
||||||
|
const title = await getTitle(row, locale)
|
||||||
|
setTitle(title)
|
||||||
|
}
|
||||||
|
init()
|
||||||
|
}, [row, locale])
|
||||||
|
|
||||||
|
return title ? (
|
||||||
|
<ExplorerLink networkId={row.networkId} path={`/tx/${row.tx}`}>
|
||||||
|
<span className={styles.titleText}>{title}</span>
|
||||||
|
</ExplorerLink>
|
||||||
|
) : null
|
||||||
|
}
|
@ -1,7 +1,3 @@
|
|||||||
.time {
|
.time {
|
||||||
color: var(--color-secondary);
|
color: var(--color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.titleText {
|
|
||||||
white-space: pre;
|
|
||||||
}
|
|
@ -1,20 +1,19 @@
|
|||||||
import React, { ReactElement, useEffect, useState } from 'react'
|
import React, { ReactElement, useEffect, useState } from 'react'
|
||||||
import ExplorerLink from '../atoms/ExplorerLink'
|
import Time from '../../atoms/Time'
|
||||||
import Time from '../atoms/Time'
|
import Table from '../../atoms/Table'
|
||||||
import Table from '../atoms/Table'
|
import AssetTitle from '../AssetListTitle'
|
||||||
import AssetTitle from './AssetListTitle'
|
import { useUserPreferences } from '../../../providers/UserPreferences'
|
||||||
import styles from './PoolTransactions.module.css'
|
|
||||||
import { useUserPreferences } from '../../providers/UserPreferences'
|
|
||||||
import { formatPrice } from '../atoms/Price/PriceUnit'
|
|
||||||
import { gql } from 'urql'
|
import { gql } from 'urql'
|
||||||
import { TransactionHistory_poolTransactions as TransactionHistoryPoolTransactions } from '../../@types/apollo/TransactionHistory'
|
import { TransactionHistory_poolTransactions as TransactionHistoryPoolTransactions } from '../../../@types/apollo/TransactionHistory'
|
||||||
import web3 from 'web3'
|
import web3 from 'web3'
|
||||||
import { useWeb3 } from '../../providers/Web3'
|
import { useWeb3 } from '../../../providers/Web3'
|
||||||
import { fetchDataForMultipleChains } from '../../utils/subgraph'
|
import { fetchDataForMultipleChains } from '../../../utils/subgraph'
|
||||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
||||||
import NetworkName from '../atoms/NetworkName'
|
import NetworkName from '../../atoms/NetworkName'
|
||||||
import { retrieveDDO } from '../../utils/aquarius'
|
import { retrieveDDO } from '../../../utils/aquarius'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import Title from './Title'
|
||||||
|
import styles from './index.module.css'
|
||||||
|
|
||||||
const REFETCH_INTERVAL = 20000
|
const REFETCH_INTERVAL = 20000
|
||||||
|
|
||||||
@ -77,96 +76,14 @@ const txHistoryQuery = gql`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
interface Datatoken {
|
export interface Datatoken {
|
||||||
symbol: string
|
symbol: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PoolTransaction extends TransactionHistoryPoolTransactions {
|
export interface PoolTransaction extends TransactionHistoryPoolTransactions {
|
||||||
networkId: number
|
networkId: number
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSymbol(tokenId: Datatoken) {
|
|
||||||
const symbol = tokenId === null ? 'OCEAN' : tokenId.symbol
|
|
||||||
return symbol
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getTitle(row: PoolTransaction, locale: string) {
|
|
||||||
let title = ''
|
|
||||||
switch (row.event) {
|
|
||||||
case 'swap': {
|
|
||||||
const inToken = row.tokens.filter((x) => x.type === 'in')[0]
|
|
||||||
const inTokenSymbol = getSymbol(inToken.poolToken.tokenId)
|
|
||||||
const outToken = row.tokens.filter((x) => x.type === 'out')[0]
|
|
||||||
const outTokenSymbol = getSymbol(outToken.poolToken.tokenId)
|
|
||||||
title += `Swap ${formatPrice(
|
|
||||||
Math.abs(inToken.value).toString(),
|
|
||||||
locale
|
|
||||||
)}${inTokenSymbol} for ${formatPrice(
|
|
||||||
Math.abs(outToken.value).toString(),
|
|
||||||
locale
|
|
||||||
)}${outTokenSymbol}`
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'setup': {
|
|
||||||
const firstToken = row.tokens.filter(
|
|
||||||
(x) =>
|
|
||||||
x.tokenAddress.toLowerCase() !==
|
|
||||||
row.poolAddress.datatokenAddress.toLowerCase()
|
|
||||||
)[0]
|
|
||||||
const firstTokenSymbol = await getSymbol(firstToken.poolToken.tokenId)
|
|
||||||
const secondToken = row.tokens.filter(
|
|
||||||
(x) =>
|
|
||||||
x.tokenAddress.toLowerCase() ===
|
|
||||||
row.poolAddress.datatokenAddress.toLowerCase()
|
|
||||||
)[0]
|
|
||||||
const secondTokenSymbol = await getSymbol(secondToken.poolToken.tokenId)
|
|
||||||
title += `Create pool with ${formatPrice(
|
|
||||||
Math.abs(firstToken.value).toString(),
|
|
||||||
locale
|
|
||||||
)}${firstTokenSymbol} and ${formatPrice(
|
|
||||||
Math.abs(secondToken.value).toString(),
|
|
||||||
locale
|
|
||||||
)}${secondTokenSymbol}`
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'join':
|
|
||||||
case 'exit': {
|
|
||||||
for (let i = 0; i < row.tokens.length; i++) {
|
|
||||||
const tokenSymbol = await getSymbol(row.tokens[i].poolToken.tokenId)
|
|
||||||
if (i > 0) title += '\n'
|
|
||||||
title += `${row.event === 'join' ? 'Add' : 'Remove'} ${formatPrice(
|
|
||||||
Math.abs(row.tokens[i].value).toString(),
|
|
||||||
locale
|
|
||||||
)}${tokenSymbol}`
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return title
|
|
||||||
}
|
|
||||||
|
|
||||||
function Title({ row }: { row: PoolTransaction }) {
|
|
||||||
const [title, setTitle] = useState<string>()
|
|
||||||
const { locale } = useUserPreferences()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!locale || !row) return
|
|
||||||
async function init() {
|
|
||||||
const title = await getTitle(row, locale)
|
|
||||||
setTitle(title)
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
}, [row, locale])
|
|
||||||
|
|
||||||
return title ? (
|
|
||||||
<ExplorerLink networkId={row.networkId} path={`/tx/${row.tx}`}>
|
|
||||||
<span className={styles.titleText}>{title}</span>
|
|
||||||
</ExplorerLink>
|
|
||||||
) : null
|
|
||||||
}
|
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
name: 'Title',
|
name: 'Title',
|
||||||
@ -262,6 +179,7 @@ export default function PoolTransactions({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!appConfig.metadataCacheUri) return
|
if (!appConfig.metadataCacheUri) return
|
||||||
|
|
||||||
async function getTransactions() {
|
async function getTransactions() {
|
||||||
const poolTransactions: PoolTransaction[] = []
|
const poolTransactions: PoolTransaction[] = []
|
||||||
const source = axios.CancelToken.source()
|
const source = axios.CancelToken.source()
|
Loading…
Reference in New Issue
Block a user