Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #506 from cowprotocol/release/2.22.0
Browse files Browse the repository at this point in the history
Release: 2.22.0
  • Loading branch information
tukantje authored Jun 2, 2023
2 parents d4967f2 + 4bf8444 commit 63b5728
Show file tree
Hide file tree
Showing 12 changed files with 691 additions and 499 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/explorer",
"version": "2.21.1",
"version": "2.22.0",
"description": "",
"main": "src/index.js",
"sideEffects": false,
Expand Down Expand Up @@ -48,7 +48,7 @@
"@apollo/client": "^3.1.5",
"@cowprotocol/app-data": "v0.1.0",
"@cowprotocol/contracts": "1.3.1",
"@cowprotocol/cow-sdk": "^2.0.0",
"@cowprotocol/cow-sdk": "^2.0.6",
"@fortawesome/fontawesome-svg-core": "^6.1.2",
"@fortawesome/free-regular-svg-icons": "^6.1.2",
"@fortawesome/free-solid-svg-icons": "^6.1.2",
Expand Down
8 changes: 4 additions & 4 deletions src/api/operator/operatorApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ export async function getTrades(
orderId?: UID
} & WithNetworkId,
): Promise<RawTrade[]> {
const { networkId, owner, orderId } = params
console.log(`[getTrades] Fetching trades on network ${networkId} with filters`, { owner, orderId })
const { networkId, owner, orderId: orderUid } = params
console.log(`[getTrades] Fetching trades on network ${networkId} with filters`, { owner, orderUid })

const tradesPromise = orderBookSDK.getTrades({ owner, orderId }, { chainId: networkId })
const tradesPromise = orderBookSDK.getTrades({ owner, orderUid }, { chainId: networkId })
const tradesPromiseBarn = orderBookSDK
.getTrades({ owner, orderId }, { chainId: networkId, env: 'staging' })
.getTrades({ owner, orderUid }, { chainId: networkId, env: 'staging' })
.catch((error) => {
console.error('[getTrades] Error getting the trades for Barn', params, error)
return []
Expand Down
40 changes: 26 additions & 14 deletions src/api/tenderly/tenderlyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ export function traceToTransfersTrades(trace: Trace): TxTradesAndTransfers {
try {
trace.logs.forEach((log) => {
if (log.name === TypeOfTrace.TRANSFER) {
const from = log.inputs[IndexTransferInput.from].value
const to = log.inputs[IndexTransferInput.to].value
transfers.push({
token: log.raw.address,
from: log.inputs[IndexTransferInput.from].value,
to: log.inputs[IndexTransferInput.to].value,
from,
to,
value: log.inputs[IndexTransferInput.value].value,
isInternal: from === to,
})
} else if (log.name === TypeOfTrace.TRADE) {
const trade = {
Expand All @@ -93,6 +96,7 @@ export function traceToTransfersTrades(trace: Trace): TxTradesAndTransfers {
from: log.raw.address,
to: trade.owner,
value: trade.buyAmount,
isInternal: log.raw.address === trade.owner,
})
}
trades.push(trade)
Expand Down Expand Up @@ -128,23 +132,31 @@ export function accountAddressesInvolved(
): Map<string, Account> {
const result = new Map()

// Create a set with transfer (to & from) addresses for quicker access
const transferAddresses = new Set()

transfers.forEach((transfer) => {
transferAddresses.add(transfer.from)
transferAddresses.add(transfer.to)
})

try {
contracts
.filter((contract: Contract) => {
// Only usecontracts which are involved in a transfer
return transfers.find((transfer) => {
return transfer.from === contract.address || transfer.to === contract.address
})
})
.forEach((contract: Contract) => {
contracts.forEach((contract: Contract) => {
// Only use contracts which are involved in a transfer
if (transferAddresses.has(contract.address))
result.set(contract.address, {
alias: _contractName(contract.contract_name),
})
})
})
trades.forEach((trade) => {
result.set(trade.owner, {
alias: ALIAS_TRADER_NAME,
})
// Don't overwrite existing contract alias
// This addresses an edge case where the settlement contract is also a trader
// See https://github.com/cowprotocol/explorer/issues/491
if (!result.has(trade.owner)) {
result.set(trade.owner, {
alias: ALIAS_TRADER_NAME,
})
}
})
// Track any missing from/to contract as unknown
transfers
Expand Down
1 change: 1 addition & 0 deletions src/api/tenderly/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface Transfer {
to: string
value: string
token: string
isInternal: boolean
}

export interface Account {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BlockExplorerLink } from 'components/common/BlockExplorerLink'
import { ConnectionStatus } from 'components/ConnectionStatus'
import { Notification } from 'components/Notification'
import { useTxBatchTrades, GetTxBatchTradesResult } from 'hooks/useTxBatchTrades'
import TransactionBatchGraph from 'apps/explorer/components/TransanctionBatchGraph'
import { TransactionBatchGraph } from 'apps/explorer/components/TransanctionBatchGraph'
import CowLoading from 'components/common/CowLoading'

interface Props {
Expand Down
116 changes: 116 additions & 0 deletions src/apps/explorer/components/TransanctionBatchGraph/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useCallback, useEffect, useRef, useState } from 'react'
import Cytoscape, { EdgeDataDefinition, ElementDefinition, NodeDataDefinition } from 'cytoscape'
import { CustomLayoutOptions, layouts } from 'apps/explorer/components/TransanctionBatchGraph/layouts'
import useWindowSizes from 'hooks/useWindowSizes'
import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const'
import {
bindPopper,
getNodes,
PopperInstance,
removePopper,
updateLayout,
} from 'apps/explorer/components/TransanctionBatchGraph/utils'
import { GetTxBatchTradesResult as TxBatchData } from 'hooks/useTxBatchTrades'
import { Network } from 'types'

export type UseCytoscapeParams = {
txBatchData: TxBatchData
networkId: Network | undefined
}

export type UseCytoscapeReturn = {
elements: ElementDefinition[]
failedToLoadGraph: boolean
heightSize: number | undefined
resetZoom: boolean | null
setResetZoom: (resetZoom: boolean | null) => void
setCytoscape: (ref: Cytoscape.Core | null) => void
layout: CustomLayoutOptions
setLayout: (layout: CustomLayoutOptions) => void
cyPopperRef: React.MutableRefObject<PopperInstance | null>
}

export function useCytoscape(params: UseCytoscapeParams): UseCytoscapeReturn {
const {
txBatchData: { error, isLoading, txSettlement },
networkId,
} = params

const [elements, setElements] = useState<ElementDefinition[]>([])
const cytoscapeRef = useRef<Cytoscape.Core | null>(null)
const cyPopperRef = useRef<PopperInstance | null>(null)
const [resetZoom, setResetZoom] = useState<boolean | null>(null)
const [layout, setLayout] = useState(layouts.grid)
const { innerHeight } = useWindowSizes()
const heightSize = innerHeight && innerHeight - HEIGHT_HEADER_FOOTER
const [failedToLoadGraph, setFailedToLoadGraph] = useState(false)

const setCytoscape = useCallback(
(ref: Cytoscape.Core) => {
cytoscapeRef.current = ref
ref.removeListener('resize')
ref.on('resize', () => {
updateLayout(ref, layout.name, true)
})
},
[layout.name],
)

const stableTxSettlement = JSON.stringify(txSettlement)

useEffect(() => {
try {
setFailedToLoadGraph(false)
const cy = cytoscapeRef.current
setElements([])
if (error || isLoading || !networkId || !heightSize || !cy) return

setElements(getNodes(txSettlement, networkId, heightSize, layout.name))
if (resetZoom) {
updateLayout(cy, layout.name)
}
removePopper(cyPopperRef)
setResetZoom(null)
} catch (e) {
console.error(`Failed to build graph`, e)
setFailedToLoadGraph(true)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [error, isLoading, stableTxSettlement, networkId, heightSize, resetZoom, layout.name])

useEffect(() => {
const cy = cytoscapeRef.current
if (!cy || !elements.length) return

cy.on('mouseover touchstart', 'edge', (event): void => {
const target = event.target
const targetData: NodeDataDefinition | EdgeDataDefinition = target.data()

bindPopper(event, targetData, cyPopperRef)
})
cy.on('mouseover', 'edge', (event): void => {
event.target.addClass('hover')
})
cy.on('mouseout', 'edge', (event): void => {
event.target.removeClass('hover')
})
cy.nodes().noOverlap({ padding: 5 })

return (): void => {
cy.removeAllListeners()
removePopper(cyPopperRef)
}
}, [cytoscapeRef, elements.length])

return {
failedToLoadGraph,
heightSize,
resetZoom,
setResetZoom,
setCytoscape,
layout,
setLayout,
cyPopperRef,
elements,
}
}
Loading

0 comments on commit 63b5728

Please sign in to comment.