From b9b81b79743449a6cde02e16403bc61ac25219db Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Fri, 18 Mar 2022 09:53:17 -0300 Subject: [PATCH 01/31] Solve merge conflicts PR1057 --- package.json | 4 + .../TransactionsTableWidget/index.tsx | 33 ++-- .../elementsBuilder.tsx | 116 ++++++++++++++ .../TransanctionBatchGraph/index.tsx | 142 ++++++++++++++++++ .../TransanctionBatchGraph/styled.ts | 69 +++++++++ .../TransanctionBatchGraph/types.ts | 15 ++ src/apps/explorer/const.ts | 3 + src/apps/explorer/layout/Header.tsx | 3 +- src/apps/explorer/pages/UserDetails.tsx | 8 +- src/apps/explorer/pages/styled.tsx | 53 ++++++- src/assets/img/CoW.svg | 16 ++ src/assets/img/Dex.svg | 10 ++ src/assets/img/TraderMe.svg | 5 + src/assets/img/TraderOther.svg | 5 + src/hooks/useTxBatchTrades.tsx | 2 +- yarn.lock | 52 +++++++ 16 files changed, 513 insertions(+), 23 deletions(-) create mode 100644 src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx create mode 100644 src/apps/explorer/components/TransanctionBatchGraph/index.tsx create mode 100644 src/apps/explorer/components/TransanctionBatchGraph/styled.ts create mode 100644 src/apps/explorer/components/TransanctionBatchGraph/types.ts create mode 100644 src/assets/img/CoW.svg create mode 100644 src/assets/img/Dex.svg create mode 100644 src/assets/img/TraderMe.svg create mode 100644 src/assets/img/TraderOther.svg diff --git a/package.json b/package.json index f399676c7..f2c28d67e 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "bignumber.js": "^9.0.0", "bn.js": "^4.11.9", "combine-reducers": "^1.0.0", + "cytoscape": "^3.21.0", "date-fns": "^2.9.0", "detect-browser": "^5.1.0", "eth-json-rpc-middleware": "^4.4.1", @@ -90,6 +91,7 @@ "qrcode.react": "^1.0.0", "react": "^16.12.0", "react-copy-to-clipboard": "^5.0.2", + "react-cytoscapejs": "^1.2.1", "react-device-detect": "^1.15.0", "react-dom": "^16.12.0", "react-ga": "^3.3.0", @@ -124,6 +126,7 @@ "@truffle/hdwallet-provider": "^1.2.0", "@types/bn.js": "^4.11.6", "@types/combine-reducers": "^1.0.0", + "@types/cytoscape": "^3.19.4", "@types/enzyme": "^3.10.4", "@types/enzyme-adapter-react-16": "^1.0.5", "@types/hapi__joi": "^16.0.12", @@ -131,6 +134,7 @@ "@types/node": "^14.0.14", "@types/qrcode.react": "^1.0.0", "@types/react-copy-to-clipboard": "^4.3.0", + "@types/react-cytoscapejs": "^1.2.2", "@types/react-dom": "^16.9.5", "@types/react-router": "^5.1.4", "@types/react-router-dom": "^5.1.3", diff --git a/src/apps/explorer/components/TransactionsTableWidget/index.tsx b/src/apps/explorer/components/TransactionsTableWidget/index.tsx index bc79ba21c..65272c90c 100644 --- a/src/apps/explorer/components/TransactionsTableWidget/index.tsx +++ b/src/apps/explorer/components/TransactionsTableWidget/index.tsx @@ -1,19 +1,20 @@ import React, { useState, useEffect } from 'react' import { BlockchainNetwork, TransactionsTableContext } from './context/TransactionsTableContext' -import { useGetTxOrders } from 'hooks/useGetOrders' +import { useGetTxOrders, useTxOrderExplorerLink } from 'hooks/useGetOrders' import RedirectToSearch from 'components/RedirectToSearch' import Spinner from 'components/common/Spinner' import { RedirectToNetwork, useNetworkId } from 'state/network' import { Order } from 'api/operator' -import { useTxOrderExplorerLink } from 'hooks/useGetOrders' import { TransactionsTableWithData } from 'apps/explorer/components/TransactionsTableWidget/TransactionsTableWithData' import { TabItemInterface } from 'components/common/Tabs/Tabs' import ExplorerTabs from '../common/ExplorerTabs/ExplorerTab' -import styled from 'styled-components' -import { TitleAddress } from 'apps/explorer/pages/styled' +import { TitleAddress, FlexContainer, StyledTabLoader, BVButton, Title } from 'apps/explorer/pages/styled' import { BlockExplorerLink } from 'components/common/BlockExplorerLink' import { useTxBatchTrades } from 'hooks/useTxBatchTrades' +import { faListUl, faProjectDiagram } from '@fortawesome/free-solid-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import TransactionBatchGraph from 'apps/explorer/components/TransanctionBatchGraph' interface Props { txHash: string @@ -21,10 +22,6 @@ interface Props { transactions?: Order[] } -const StyledTabLoader = styled.span` - padding-left: 4px; -` - const tabItems = (isLoadingOrders: boolean): TabItemInterface[] => { return [ { @@ -44,6 +41,7 @@ export const TransactionsTableWidget: React.FC = ({ txHash }) => { const { orders, isLoading: isTxLoading, errorTxPresentInNetworkId, error } = useGetTxOrders(txHash) const networkId = useNetworkId() || undefined const [redirectTo, setRedirectTo] = useState(false) + const [batchViewer, setBatchViewer] = useState(false) const txHashParams = { networkId, txHash } const isZeroOrders = !!(orders && orders.length === 0) const notGpv2ExplorerData = useTxOrderExplorerLink(txHash, isZeroOrders) @@ -73,15 +71,22 @@ export const TransactionsTableWidget: React.FC = ({ txHash }) => { return } + const batchViewerButtonName = batchViewer ? 'Show Transactions list' : 'Show Batch Viewer' + const batchViewerButtonIcon = batchViewer ? faListUl : faProjectDiagram + return ( <> -

- Transaction details + + Transaction details } /> -

+ setBatchViewer(!batchViewer)}> + + {batchViewerButtonName} + + = ({ txHash }) => { isTxLoading, }} > - + {batchViewer ? ( + + ) : ( + + )} ) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx new file mode 100644 index 000000000..3dc2bcb29 --- /dev/null +++ b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx @@ -0,0 +1,116 @@ +import { ElementDefinition } from 'cytoscape' +import { Node, TypeNodeOnTx } from './types' + +export default class ElementsBuilder { + _center: ElementDefinition | null = null + _nodes: ElementDefinition[] = [] + _edges: ElementDefinition[] = [] + _SIZE: number + _countTypes: Map + + constructor(heighSize?: number) { + this._SIZE = heighSize || 600 + this._countTypes = new Map() + } + + _increaseCounType = (_type: string): void => { + const count = this._countTypes.get(_type) || 0 + this._countTypes.set(_type, count + 1) + } + _createNodeElement = (node: Node, parent?: string): ElementDefinition => { + this._increaseCounType(node.type) + return { + group: 'nodes', + data: { + id: `${node.type}:${node.id}`, + label: node.entity.alias, + type: node.type, + parent: parent ? `${TypeNodeOnTx.NetworkNode}:${parent}` : undefined, + }, + } + } + + center(node: Node, parent?: string): this { + this._center = this._createNodeElement(node, parent) + return this + } + + node(node: Node, parent?: string): this { + this._nodes.push(this._createNodeElement(node, parent)) + return this + } + + edge(source: Pick, target: Pick, label: string): this { + this._edges.push({ + group: 'edges', + data: { + id: `${source.type}:${source.id}->${target.type}:${target.id}`, + source: `${source.type}:${source.id}`, + target: `${target.type}:${target.id}`, + label, + }, + }) + return this + } + + build(): ElementDefinition[] { + if (!this._center) { + throw new Error('Center node is required') + } + + const thirdOfTotalRows = Math.max(...this._countTypes.values()) / 3 + const center = { + ...this._center, + position: { x: 100, y: 0 }, + } + center['data']['rowValue'] = Math.floor(thirdOfTotalRows) + + const r = this._SIZE / 2 - 100 + + const nodes = this._nodes.map((node, index) => { + return { + ...node, + position: { + x: r * Math.cos((2 * Math.PI * index) / this._nodes.length), + y: r * Math.sin((2 * Math.PI * index) / this._nodes.length), + }, + } + }) + + return [center, ...nodes, ...this._edges] + } + + getById(id: string): ElementDefinition | undefined { + // split type:id and find by id + if (this._center) { + return [this._center, ...this._nodes].find((node) => node.data.id?.split(':')[1] === id) + } + + return this._nodes.find((node) => node.data.id?.split(':')[1] === id) + } +} + +const columnTypeMap = new Map([ + [TypeNodeOnTx.Trader, 0], + [TypeNodeOnTx.CowProtocol, 1], + [TypeNodeOnTx.Dex, 2], +]) + +interface GridPosition { + x: number + y: number +} +export function getGridPosition(type: TypeNodeOnTx, index: number): undefined | GridPosition { + if (!columnTypeMap.has(type)) return + + let col + const row = index + if (type === TypeNodeOnTx.Trader) { + col = 0 + } else if (type === TypeNodeOnTx.CowProtocol) { + col = 1 + } else { + col = 2 + } + return { y: row, x: col } +} diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx new file mode 100644 index 000000000..69a8b17bb --- /dev/null +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -0,0 +1,142 @@ +import Cytoscape, { ElementDefinition, NodeSingular } from 'cytoscape' +import React, { useState, useEffect, useRef, useCallback } from 'react' +import CytoscapeComponent from 'react-cytoscapejs' +import styled from 'styled-components' + +import Spinner from 'components/common/Spinner' +import { GetTxBatchTradesResult as TxBatchData, Settlement as TxSettlement } from 'hooks/useTxBatchTrades' +import { networkOptions } from 'components/NetworkSelector' +import { Network } from 'types' +import { Account, ALIAS_TRADER_NAME } from 'api/tenderly' +import ElementsBuilder from 'apps/explorer/components/TransanctionBatchGraph/elementsBuilder' +import { TypeNodeOnTx } from './types' +import { APP_NAME } from 'const' +import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' +import { STYLESHEET } from './styled' + +const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER +const PROTOCOL_NAME = APP_NAME +const WrapperCytoscape = styled(CytoscapeComponent)` + background-color: ${({ theme }): string => theme.bg1}; + font-weight: ${({ theme }): string => theme.fontMedium}; + border: 0.1rem solid ${({ theme }): string => theme.borderPrimary}; + border-radius: 0.4rem; +` + +function getTypeNode(element: Account): TypeNodeOnTx { + let type = TypeNodeOnTx.Dex + if (element.alias === ALIAS_TRADER_NAME) { + type = TypeNodeOnTx.Trader + } else if (element.alias === PROTOCOL_NAME) { + type = TypeNodeOnTx.CowProtocol + } + + return type +} + +function getNetworkParentNode(account: Account, networkName: string): string | undefined { + return account.alias !== ALIAS_TRADER_NAME ? networkName : undefined +} + +function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefinition[] { + if (!txSettlement.accounts) return [] + + const networkName = networkOptions.find((network) => network.id === networkId)?.name.toLowerCase() + const networkNode = { alias: networkName || '' } + const builder = new ElementsBuilder(HEIGHT_SIZE) + builder.node({ type: TypeNodeOnTx.NetworkNode, entity: networkNode, id: networkNode.alias }) + + for (const key in txSettlement.accounts) { + const account = txSettlement.accounts[key] + const parentNodeName = getNetworkParentNode(account, networkNode.alias) + + if (getTypeNode(account) === TypeNodeOnTx.CowProtocol) { + builder.center({ type: TypeNodeOnTx.CowProtocol, entity: account, id: key }, parentNodeName) + } else { + builder.node( + { + id: key, + type: getTypeNode(account), + entity: account, + }, + parentNodeName, + ) + } + } + + txSettlement.transfers.forEach((transfer) => { + const token = txSettlement.tokens[transfer.token] || { decimals: 1, symbol: 'UNKNOW' } + + const source = builder.getById(transfer.from) + const target = builder.getById(transfer.to) + builder.edge( + { type: source?.data.type, id: transfer.from }, + { type: target?.data.type, id: transfer.to }, + `${token.symbol}`, + ) + }) + + return builder.build() +} + +interface GraphBatchTxParams { + txBatchData: TxBatchData + networkId: Network | undefined +} + +function TransanctionBatchGraph({ + txBatchData: { error, isLoading, txSettlement }, + networkId, +}: GraphBatchTxParams): JSX.Element { + const [elements, setElements] = useState([]) + const cytoscapeRef = useRef(null) + const setCytoscape = useCallback( + (ref: Cytoscape.Core) => { + cytoscapeRef.current = ref + }, + [cytoscapeRef], + ) + + useEffect(() => { + if (error || isLoading || !networkId) return + + setElements(getNodes(txSettlement, networkId)) + }, [error, isLoading, networkId, txSettlement]) + + if (isLoading) return + + const layout = { + name: 'grid', + position: function (node: NodeSingular): { row: undefined | number; col: number } { + let col + let row = undefined + if (node.data('type') === TypeNodeOnTx.Trader) { + col = 0 + } else if (node.data('type') === TypeNodeOnTx.CowProtocol) { + col = 1 + row = node.data('rowValue') + } else { + col = 2 + } + return { row, col } + }, + fit: true, // whether to fit the viewport to the graph + padding: 20, // padding used on fit + avoidOverlap: true, // prevents node overlap, may overflow boundingBox if not enough space + avoidOverlapPadding: 10, // extra spacing around nodes when avoidOverlap: true + nodeDimensionsIncludeLabels: false, + } + + return ( + + ) +} + +export default TransanctionBatchGraph diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts new file mode 100644 index 000000000..41b40c252 --- /dev/null +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -0,0 +1,69 @@ +import { Stylesheet } from 'cytoscape' + +import TraderOtherIcon from 'assets/img/TraderOther.svg' +import CowProtocolIcon from 'assets/img/CoW.svg' +import DexIcon from 'assets/img/Dex.svg' + +export const STYLESHEET: Stylesheet[] = [ + { + selector: 'node[label]', + style: { + label: 'data(label)', + color: '#cfcfcf', + height: 50, + width: 50, + 'background-color': '#22232d', + }, + }, + + { + selector: 'edge[label]', + style: { + label: 'data(label)', + width: 3, + 'target-arrow-shape': 'triangle', + 'curve-style': 'unbundled-bezier', + color: 'black', + 'line-color': '#747a9e', + 'line-opacity': 0.8, + 'text-margin-y': 10, + + 'text-background-color': 'white', + 'text-background-opacity': 1, + 'text-background-padding': '2px', + 'text-background-shape': 'roundrectangle', + }, + }, + { + selector: 'node[type="trader"]', + style: { + 'background-image': `url(${TraderOtherIcon})`, + 'text-valign': 'bottom', + 'text-margin-y': 8, + }, + }, + { + selector: 'node[type="dex"]', + style: { + 'background-image': `url(${DexIcon})`, + 'text-max-width': '5rem', + 'text-valign': 'bottom', + 'text-margin-y': 8, + }, + }, + { + selector: 'node[type="cowProtocol"]', + style: { + 'background-image': `url(${CowProtocolIcon})`, + 'text-valign': 'bottom', + 'text-margin-y': 8, + }, + }, + { + selector: 'node[type="networkNode"]', + style: { + 'border-style': 'dashed', + 'border-opacity': 0.8, + }, + }, +] diff --git a/src/apps/explorer/components/TransanctionBatchGraph/types.ts b/src/apps/explorer/components/TransanctionBatchGraph/types.ts new file mode 100644 index 000000000..bd1562806 --- /dev/null +++ b/src/apps/explorer/components/TransanctionBatchGraph/types.ts @@ -0,0 +1,15 @@ +import { Account } from 'api/tenderly' + +export enum TypeNodeOnTx { + NetworkNode = 'networkNode', + CowProtocol = 'cowProtocol', + Trader = 'trader', + Dex = 'dex', +} + +export type NodeType = { type: T; entity: E; id: string } +export type Node = + | NodeType + | NodeType + | NodeType + | NodeType diff --git a/src/apps/explorer/const.ts b/src/apps/explorer/const.ts index 68d78c918..606846fe3 100644 --- a/src/apps/explorer/const.ts +++ b/src/apps/explorer/const.ts @@ -23,3 +23,6 @@ export const DIMENSION_NAMES = { } export const NETWORK_ID_SEARCH_LIST = [Network.Mainnet, Network.xDAI, Network.Rinkeby] + +// Estimation heigh of the header + footer space +export const HEIGHT_HEADER_FOOTER = 257 diff --git a/src/apps/explorer/layout/Header.tsx b/src/apps/explorer/layout/Header.tsx index 269404e71..169c28c3a 100644 --- a/src/apps/explorer/layout/Header.tsx +++ b/src/apps/explorer/layout/Header.tsx @@ -10,6 +10,7 @@ import { FlexWrap } from 'apps/explorer/pages/styled' import { ExternalLink } from 'components/analytics/ExternalLink' import { useHistory } from 'react-router' import useOnClickOutside from 'hooks/useOnClickOutside' +import { APP_NAME } from 'const' export const Header: React.FC = () => { const history = useHistory() @@ -43,7 +44,7 @@ export const Header: React.FC = () => {
  • - CoW Protocol + {APP_NAME}
  • diff --git a/src/apps/explorer/pages/UserDetails.tsx b/src/apps/explorer/pages/UserDetails.tsx index bafccefcd..d2b55a71e 100644 --- a/src/apps/explorer/pages/UserDetails.tsx +++ b/src/apps/explorer/pages/UserDetails.tsx @@ -7,7 +7,7 @@ import { BlockExplorerLink } from 'components/common/BlockExplorerLink' import RedirectToSearch from 'components/RedirectToSearch' import { useResolveEns } from 'hooks/useResolveEns' import Spinner from 'components/common/Spinner' -import { TitleAddress, Wrapper } from 'apps/explorer/pages/styled' +import { TitleAddress, Wrapper, FlexContainerVar } from 'apps/explorer/pages/styled' const UserDetails: React.FC = () => { const { address } = useParams<{ address: string }>() @@ -22,8 +22,8 @@ const UserDetails: React.FC = () => { {addressAccount ? ( <> -

    - User details + +

    User details

    { /> } /> -

    + ) : ( diff --git a/src/apps/explorer/pages/styled.tsx b/src/apps/explorer/pages/styled.tsx index a859e17cc..5ac986d1b 100644 --- a/src/apps/explorer/pages/styled.tsx +++ b/src/apps/explorer/pages/styled.tsx @@ -20,21 +20,51 @@ export const Wrapper = styled.div` > h1 { display: flex; - padding: 2.4rem 0 2.35rem; + padding: 2.4rem 0; align-items: center; font-weight: ${({ theme }): string => theme.fontBold}; margin: 0; } ` +export const StyledTabLoader = styled.span` + padding-left: 4px; +` + +export const FlexContainer = styled.div` + display: flex; + align-items: center; + ${media.mobile} { + flex-direction: column; + align-items: flex-start; + } +` + +export const FlexContainerVar = styled.div` + display: flex; + flex-direction: row; + align-items: baseline; + margin: 2.4rem 0; + + ${media.mobile} { + /* margin: 0 0 0 1.5rem; */ + span:nth-child(1) { + margin: 0 0 0 1.5rem; + } + } +` + export const TitleAddress = styled(RowWithCopyButton)` font-size: ${({ theme }): string => theme.fontSizeDefault}; font-weight: ${({ theme }): string => theme.fontNormal}; margin: 0 0 0 1.5rem; - display: flex; - align-items: center; - ${media.tinyDown} { + ${media.mobile} { font-size: 1.2rem; + margin: 0 0 1.5rem 0; + } + a { + display: flex; + align-items: center; } ` @@ -52,6 +82,7 @@ export const StyledLink = styled(Link)` display: flex; align-items: center; justify-content: center; + flex: 0 1 auto; cursor: pointer; color: ${({ theme }): string => theme.white} !important; @@ -62,10 +93,22 @@ export const StyledLink = styled(Link)` ` export const Title = styled.h1` - margin: 3rem 0 2.95rem; + margin: 2.4rem 0; font-weight: ${({ theme }): string => theme.fontBold}; ` +export const BVButton = styled.a` + color: ${({ theme }): string => theme.orange}; + font-size: 1.3rem; + margin-left: auto; + svg { + margin: 0 0.75rem 0 0; + } + ${media.mobile} { + margin: -3rem 0 1.5rem auto; + } +` + export const ContentCard = styled.div` font-size: 1.6rem; border: 0.1rem solid ${({ theme }): string => theme.borderPrimary}; diff --git a/src/assets/img/CoW.svg b/src/assets/img/CoW.svg new file mode 100644 index 000000000..1df19b7a7 --- /dev/null +++ b/src/assets/img/CoW.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/assets/img/Dex.svg b/src/assets/img/Dex.svg new file mode 100644 index 000000000..4b3f5d552 --- /dev/null +++ b/src/assets/img/Dex.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/assets/img/TraderMe.svg b/src/assets/img/TraderMe.svg new file mode 100644 index 000000000..b36a98759 --- /dev/null +++ b/src/assets/img/TraderMe.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/assets/img/TraderOther.svg b/src/assets/img/TraderOther.svg new file mode 100644 index 000000000..4345ba7f1 --- /dev/null +++ b/src/assets/img/TraderOther.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/hooks/useTxBatchTrades.tsx b/src/hooks/useTxBatchTrades.tsx index 94e67b390..2569c4e45 100644 --- a/src/hooks/useTxBatchTrades.tsx +++ b/src/hooks/useTxBatchTrades.tsx @@ -21,7 +21,7 @@ export interface Settlement { trades: Array } -type GetTxBatchTradesResult = { +export type GetTxBatchTradesResult = { txSettlement: Settlement error: string isLoading: boolean diff --git a/yarn.lock b/yarn.lock index fd52ed3e3..114cd770e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3800,6 +3800,11 @@ resolved "https://registry.yarnpkg.com/@types/combine-reducers/-/combine-reducers-1.0.1.tgz#8fb474ac08c211349edf5cbfa58e9f6370bd326a" integrity sha512-T7bMnCsLZ0djOJhQf92w4slUTLfHQVKNtyXR8eO6pBy/QYNSzeuxaTYnjcVju+VKqaXV5zNbSnb0qKTIVpk+NA== +"@types/cytoscape@*", "@types/cytoscape@^3.19.4": + version "3.19.4" + resolved "https://registry.yarnpkg.com/@types/cytoscape/-/cytoscape-3.19.4.tgz#f41214103b80ff3d7d8741bacc32265ed90e45b5" + integrity sha512-0IozTg1vdZrA3nuAK5o9Pa8nl2INUnTaXwcGwoiALDcsD8/TiVnp0Zi+R1IiPRG6edoy0Ya61/3osFLtfkhhmw== + "@types/enzyme-adapter-react-16@^1.0.5": version "1.0.6" resolved "https://registry.yarnpkg.com/@types/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.0.6.tgz#8aca7ae2fd6c7137d869b6616e696d21bb8b0cec" @@ -4064,6 +4069,14 @@ dependencies: "@types/react" "*" +"@types/react-cytoscapejs@^1.2.2": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@types/react-cytoscapejs/-/react-cytoscapejs-1.2.2.tgz#e2d27dc11b2bac61fd3e64efe2004ab65958344f" + integrity sha512-Z+CeQLw4XyQOrS/SdbcUCdYfWqYmaPS/WT+gNy33KYR09BtVzekx1jeNU5kNDvXCv8/8jGlhSrSk0uO7ocGuFg== + dependencies: + "@types/cytoscape" "*" + "@types/react" "*" + "@types/react-dom@*", "@types/react-dom@>=16.9.0": version "17.0.9" resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.9.tgz#441a981da9d7be117042e1a6fd3dac4b30f55add" @@ -7442,6 +7455,17 @@ cyclist@^1.0.1: resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= +cytoscape@^3.2.19, cytoscape@^3.21.0: + version "3.21.0" + resolved "https://registry.yarnpkg.com/cytoscape/-/cytoscape-3.21.0.tgz#8a73f6f0f3a44f948e266ac7df9b2eff65e8bd3c" + integrity sha512-xPINMzQNGN4WIog93gYRScT4y/CyZMmqunnhU59/8LynhWwzepJtUydMfvIPuz5TmJ9rSCMdw6rmxhfbb1eofw== + dependencies: + heap "^0.2.6" + lodash.debounce "^4.0.8" + lodash.get "^4.4.2" + lodash.set "^4.3.2" + lodash.topath "^4.5.2" + "d3-array@1 - 2", d3-array@^2.5.0: version "2.12.1" resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.12.1.tgz#e20b41aafcdffdf5d50928004ececf815a465e81" @@ -10906,6 +10930,11 @@ he@^1.2.0: resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +heap@^0.2.6: + version "0.2.7" + resolved "https://registry.yarnpkg.com/heap/-/heap-0.2.7.tgz#1e6adf711d3f27ce35a81fe3b7bd576c2260a8fc" + integrity sha512-2bsegYkkHO+h/9MGbn6KWcE45cHZgPANo5LXF7EvWdT0yT2EguSVO1nDgU5c8+ZOPwp2vMNa7YFsJhVcDR9Sdg== + highlight.js@^10.1.1, highlight.js@^10.1.2, highlight.js@~10.7.0: version "10.7.3" resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.7.3.tgz#697272e3991356e40c3cac566a74eef681756531" @@ -13384,6 +13413,11 @@ lodash.flattendeep@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2" integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= +lodash.get@^4.4.2: + version "4.4.2" + resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" + integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -13426,11 +13460,21 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== +lodash.set@^4.3.2: + version "4.3.2" + resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23" + integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM= + lodash.sortby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= +lodash.topath@^4.5.2: + version "4.5.2" + resolved "https://registry.yarnpkg.com/lodash.topath/-/lodash.topath-4.5.2.tgz#3616351f3bba61994a0931989660bd03254fd009" + integrity sha1-NhY1Hzu6YZlKCTGYlmC9AyVP0Ak= + lodash.truncate@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193" @@ -16257,6 +16301,14 @@ react-copy-to-clipboard@^5.0.2: copy-to-clipboard "^3" prop-types "^15.5.8" +react-cytoscapejs@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/react-cytoscapejs/-/react-cytoscapejs-1.2.1.tgz#ccce46acabf4f0c41dce9070743854f92b0dc050" + integrity sha512-8exVCetpzyGCAKuRjXPWGjFCnb22boZ3SXUPpPB/+wQI8Q8BwkT1URN3A7J1Czvj1qAbShh5QQ514mBUp7i7kw== + dependencies: + cytoscape "^3.2.19" + prop-types "^15.6.2" + react-dev-utils@^11.0.3, react-dev-utils@^11.0.4: version "11.0.4" resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-11.0.4.tgz#a7ccb60257a1ca2e0efe7a83e38e6700d17aa37a" From 82e610743cf30029b7e6382ac44b9ca710a915e0 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Fri, 18 Mar 2022 09:56:49 -0300 Subject: [PATCH 02/31] Show Trader address --- .../components/TransanctionBatchGraph/index.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 69a8b17bb..89da17728 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -13,6 +13,7 @@ import { TypeNodeOnTx } from './types' import { APP_NAME } from 'const' import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' import { STYLESHEET } from './styled' +import { abbreviateString } from 'utils' const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER const PROTOCOL_NAME = APP_NAME @@ -23,17 +24,24 @@ const WrapperCytoscape = styled(CytoscapeComponent)` border-radius: 0.4rem; ` -function getTypeNode(element: Account): TypeNodeOnTx { +function getTypeNode(account: Account): TypeNodeOnTx { let type = TypeNodeOnTx.Dex - if (element.alias === ALIAS_TRADER_NAME) { + if (account.alias === ALIAS_TRADER_NAME) { type = TypeNodeOnTx.Trader - } else if (element.alias === PROTOCOL_NAME) { + } else if (account.alias === PROTOCOL_NAME) { type = TypeNodeOnTx.CowProtocol } return type } +function showTraderAddress(account: Account, address: string): Account { + if (account.alias === ALIAS_TRADER_NAME) { + account.alias = abbreviateString(address, 4, 4) + } + return account +} + function getNetworkParentNode(account: Account, networkName: string): string | undefined { return account.alias !== ALIAS_TRADER_NAME ? networkName : undefined } @@ -57,7 +65,7 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini { id: key, type: getTypeNode(account), - entity: account, + entity: showTraderAddress(account, key), }, parentNodeName, ) From d260f14015cbff82e654cf02ad6251076e04d411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Fri, 18 Mar 2022 16:25:24 -0300 Subject: [PATCH 03/31] label styles --- src/apps/explorer/components/TransanctionBatchGraph/styled.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index 41b40c252..e2ee0f8d2 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -26,12 +26,11 @@ export const STYLESHEET: Stylesheet[] = [ color: 'black', 'line-color': '#747a9e', 'line-opacity': 0.8, - 'text-margin-y': 10, - 'text-background-color': 'white', 'text-background-opacity': 1, 'text-background-padding': '2px', 'text-background-shape': 'roundrectangle', + 'font-size': '11px', }, }, { From 01d0681421a75705eeeac67902ceb73a8783fadc Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Mon, 21 Mar 2022 12:35:10 -0300 Subject: [PATCH 04/31] Adding custom position layout --- .../TransactionsTableWidget/index.tsx | 2 - .../elementsBuilder.tsx | 96 ++++++++++++++----- .../TransanctionBatchGraph/index.tsx | 24 ++--- 3 files changed, 79 insertions(+), 43 deletions(-) diff --git a/src/apps/explorer/components/TransactionsTableWidget/index.tsx b/src/apps/explorer/components/TransactionsTableWidget/index.tsx index 65272c90c..edf1bcfc4 100644 --- a/src/apps/explorer/components/TransactionsTableWidget/index.tsx +++ b/src/apps/explorer/components/TransactionsTableWidget/index.tsx @@ -45,9 +45,7 @@ export const TransactionsTableWidget: React.FC = ({ txHash }) => { const txHashParams = { networkId, txHash } const isZeroOrders = !!(orders && orders.length === 0) const notGpv2ExplorerData = useTxOrderExplorerLink(txHash, isZeroOrders) - // TODO use on draw tx view const txBatchTrades = useTxBatchTrades(networkId, txHash, orders && orders.length) - console.log('txBatchTrades', txBatchTrades) // Avoid redirecting until another network is searched again useEffect(() => { diff --git a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx index 3dc2bcb29..cd63afa17 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx @@ -53,26 +53,33 @@ export default class ElementsBuilder { return this } - build(): ElementDefinition[] { + build(customLayoutNodes?: CustomLayoutNodes): ElementDefinition[] { + if (!customLayoutNodes) { + return this._buildCoseLayout() + } else { + const { center, nodes } = customLayoutNodes + return [center, ...nodes, ...this._edges] + } + } + + _buildCoseLayout(): ElementDefinition[] { if (!this._center) { throw new Error('Center node is required') } - - const thirdOfTotalRows = Math.max(...this._countTypes.values()) / 3 const center = { ...this._center, - position: { x: 100, y: 0 }, + position: { x: 0, y: 0 }, } - center['data']['rowValue'] = Math.floor(thirdOfTotalRows) + const nTypes = this._countTypes.size - const r = this._SIZE / 2 - 100 + const r = this._SIZE / nTypes - 100 // get radio - const nodes = this._nodes.map((node, index) => { + const nodes = this._nodes.map((node: ElementDefinition, index: number) => { return { ...node, position: { - x: r * Math.cos((2 * Math.PI * index) / this._nodes.length), - y: r * Math.sin((2 * Math.PI * index) / this._nodes.length), + x: r * Math.cos((nTypes * Math.PI * index) / this._nodes.length), + y: r * Math.sin((nTypes * Math.PI * index) / this._nodes.length), }, } }) @@ -81,7 +88,7 @@ export default class ElementsBuilder { } getById(id: string): ElementDefinition | undefined { - // split type:id and find by id + // split : and find by if (this._center) { return [this._center, ...this._nodes].find((node) => node.data.id?.split(':')[1] === id) } @@ -90,27 +97,66 @@ export default class ElementsBuilder { } } -const columnTypeMap = new Map([ - [TypeNodeOnTx.Trader, 0], - [TypeNodeOnTx.CowProtocol, 1], - [TypeNodeOnTx.Dex, 2], -]) - -interface GridPosition { - x: number - y: number +interface CustomLayoutNodes { + center: ElementDefinition + nodes: ElementDefinition[] } -export function getGridPosition(type: TypeNodeOnTx, index: number): undefined | GridPosition { - if (!columnTypeMap.has(type)) return +export function getGridPosition(type: TypeNodeOnTx): number { let col - const row = index if (type === TypeNodeOnTx.Trader) { col = 0 } else if (type === TypeNodeOnTx.CowProtocol) { - col = 1 + col = 4 } else { - col = 2 + col = 8 + } + return col +} + +export function buildGridLayout( + countTypes: Map, + center: ElementDefinition | null, + nodes: ElementDefinition[], +): { center: ElementDefinition; nodes: ElementDefinition[] } { + if (!center) { + throw new Error('Center node is required') + } + const maxRows = Math.max(...countTypes.values()) + const middleOfTotalRows = Math.floor(maxRows / 2) + const _center = { + ...center, + position: { y: middleOfTotalRows, x: getGridPosition(center.data.type) }, } - return { y: row, x: col } + + const traders = countTypes.get(TypeNodeOnTx.Trader) || 0 + const dexes = countTypes.get(TypeNodeOnTx.Dex) || 0 + let counterRows = { [TypeNodeOnTx.Trader]: 0, [TypeNodeOnTx.Dex]: 0 } + if (traders > dexes) { + const difference = (traders - dexes) / 2 + counterRows[TypeNodeOnTx.Dex] = Math.floor(difference) + } else if (traders < dexes) { + const difference = (dexes - traders) / 2 + counterRows[TypeNodeOnTx.Trader] = Math.floor(difference) + } + + const _nodes = nodes.map((node) => { + const _node = { + ...node, + position: { + y: counterRows[node.data.type], + x: getGridPosition(node.data.type), + }, + } + + if (node.data.type === TypeNodeOnTx.Trader) { + counterRows = { ...counterRows, [TypeNodeOnTx.Trader]: counterRows[TypeNodeOnTx.Trader] + 1 } + } else if (node.data.type === TypeNodeOnTx.Dex) { + counterRows = { ...counterRows, [TypeNodeOnTx.Dex]: counterRows[TypeNodeOnTx.Dex] + 1 } + } + + return _node + }) + + return { center: _center, nodes: _nodes } } diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 89da17728..1a91bc57b 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -8,7 +8,7 @@ import { GetTxBatchTradesResult as TxBatchData, Settlement as TxSettlement } fro import { networkOptions } from 'components/NetworkSelector' import { Network } from 'types' import { Account, ALIAS_TRADER_NAME } from 'api/tenderly' -import ElementsBuilder from 'apps/explorer/components/TransanctionBatchGraph/elementsBuilder' +import ElementsBuilder, { buildGridLayout } from 'apps/explorer/components/TransanctionBatchGraph/elementsBuilder' import { TypeNodeOnTx } from './types' import { APP_NAME } from 'const' import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' @@ -84,7 +84,9 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini ) }) - return builder.build() + return builder.build( + buildGridLayout(builder._countTypes as Map, builder._center, builder._nodes), + ) } interface GraphBatchTxParams { @@ -115,23 +117,13 @@ function TransanctionBatchGraph({ const layout = { name: 'grid', - position: function (node: NodeSingular): { row: undefined | number; col: number } { - let col - let row = undefined - if (node.data('type') === TypeNodeOnTx.Trader) { - col = 0 - } else if (node.data('type') === TypeNodeOnTx.CowProtocol) { - col = 1 - row = node.data('rowValue') - } else { - col = 2 - } - return { row, col } + position: function (node: NodeSingular): { row: number; col: number } { + return { row: node.position('y'), col: node.position('x') } }, fit: true, // whether to fit the viewport to the graph - padding: 20, // padding used on fit + padding: 10, // padding used on fit avoidOverlap: true, // prevents node overlap, may overflow boundingBox if not enough space - avoidOverlapPadding: 10, // extra spacing around nodes when avoidOverlap: true + avoidOverlapPadding: 100, // extra spacing around nodes when avoidOverlap: true nodeDimensionsIncludeLabels: false, } From 581327544114391b6a448375a583aea7fa2e2679 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Mon, 21 Mar 2022 15:00:19 -0300 Subject: [PATCH 05/31] Adapt grid by batch of rows --- .../elementsBuilder.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx index cd63afa17..7e3bce229 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx @@ -102,14 +102,19 @@ interface CustomLayoutNodes { nodes: ElementDefinition[] } -export function getGridPosition(type: TypeNodeOnTx): number { +export function getGridPosition(type: TypeNodeOnTx, traderRowsLength: number, dexRowsLenght: number): number { let col + const batchOf = 5 + // Add a column for each batch of n + const leftPaddingCol = 1 + Math.round(traderRowsLength / batchOf) + const rightPaddingCol = leftPaddingCol + 1 + Math.round(dexRowsLenght / batchOf) + if (type === TypeNodeOnTx.Trader) { - col = 0 + col = 0 // first Column } else if (type === TypeNodeOnTx.CowProtocol) { - col = 4 + col = leftPaddingCol } else { - col = 8 + col = rightPaddingCol } return col } @@ -122,15 +127,16 @@ export function buildGridLayout( if (!center) { throw new Error('Center node is required') } + const maxRows = Math.max(...countTypes.values()) const middleOfTotalRows = Math.floor(maxRows / 2) + const traders = countTypes.get(TypeNodeOnTx.Trader) || 0 + const dexes = countTypes.get(TypeNodeOnTx.Dex) || 0 const _center = { ...center, - position: { y: middleOfTotalRows, x: getGridPosition(center.data.type) }, + position: { y: middleOfTotalRows, x: getGridPosition(center.data.type, traders, dexes) }, } - const traders = countTypes.get(TypeNodeOnTx.Trader) || 0 - const dexes = countTypes.get(TypeNodeOnTx.Dex) || 0 let counterRows = { [TypeNodeOnTx.Trader]: 0, [TypeNodeOnTx.Dex]: 0 } if (traders > dexes) { const difference = (traders - dexes) / 2 @@ -145,7 +151,7 @@ export function buildGridLayout( ...node, position: { y: counterRows[node.data.type], - x: getGridPosition(node.data.type), + x: getGridPosition(node.data.type, traders, dexes), }, } From f19e086b5fbe60d6b23a1c6ecca1791fdfe563f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Mon, 21 Mar 2022 20:25:11 -0300 Subject: [PATCH 06/31] add basic tooltip --- package.json | 1 + .../TransanctionBatchGraph/index.tsx | 26 +++++++++++++++++++ src/env.d.ts | 1 + yarn.lock | 12 +++++++++ 4 files changed, 40 insertions(+) create mode 100644 src/env.d.ts diff --git a/package.json b/package.json index f2c28d67e..71cb941db 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "bn.js": "^4.11.9", "combine-reducers": "^1.0.0", "cytoscape": "^3.21.0", + "cytoscape-popper": "^2.0.0", "date-fns": "^2.9.0", "detect-browser": "^5.1.0", "eth-json-rpc-middleware": "^4.4.1", diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 1a91bc57b..d8bd0913f 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -1,4 +1,5 @@ import Cytoscape, { ElementDefinition, NodeSingular } from 'cytoscape' +import popper from 'cytoscape-popper' import React, { useState, useEffect, useRef, useCallback } from 'react' import CytoscapeComponent from 'react-cytoscapejs' import styled from 'styled-components' @@ -15,6 +16,7 @@ import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' import { STYLESHEET } from './styled' import { abbreviateString } from 'utils' +Cytoscape.use(popper) const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER const PROTOCOL_NAME = APP_NAME const WrapperCytoscape = styled(CytoscapeComponent)` @@ -111,6 +113,30 @@ function TransanctionBatchGraph({ if (error || isLoading || !networkId) return setElements(getNodes(txSettlement, networkId)) + const cy = cytoscapeRef.current + if (cy) { + cy.on('click', 'node', (_event): void => { + const node = _event.target + const popper = node.popper({ + content: () => { + const div = document.createElement('div') + div.innerHTML = 'Popper Node tooltip' + document.body.appendChild(div) + return div + }, + popper: { + placement: 'top', + }, // my popper options here + }) + const update = (): void => { + popper.update() + } + + node.on('position', update) + + cy.on('pan zoom resize', update) + }) + } }, [error, isLoading, networkId, txSettlement]) if (isLoading) return diff --git a/src/env.d.ts b/src/env.d.ts new file mode 100644 index 000000000..6cc91a2c0 --- /dev/null +++ b/src/env.d.ts @@ -0,0 +1 @@ +declare module 'cytoscape-popper' diff --git a/yarn.lock b/yarn.lock index 114cd770e..ad8815150 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2696,6 +2696,11 @@ schema-utils "^2.6.5" source-map "^0.7.3" +"@popperjs/core@^2.0.0": + version "2.11.4" + resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.4.tgz#d8c7b8db9226d2d7664553a0741ad7d0397ee503" + integrity sha512-q/ytXxO5NKvyT37pmisQAItCFqA7FD/vNb8dgaJy3/630Fsc+Mz9/9f2SziBoIZ30TJooXyTwZmhi1zjXmObYg== + "@popperjs/core@^2.0.6", "@popperjs/core@^2.5.4", "@popperjs/core@^2.6.0": version "2.11.0" resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.0.tgz#6734f8ebc106a0860dff7f92bf90df193f0935d7" @@ -7455,6 +7460,13 @@ cyclist@^1.0.1: resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= +cytoscape-popper@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/cytoscape-popper/-/cytoscape-popper-2.0.0.tgz#d93917695a9b8af3dbda1d8ee433618ac4d4e359" + integrity sha512-b7WSOn8qXHWtdIXFNmrgc8qkaOs16tMY0EwtRXlxzvn8X+al6TAFrUwZoYATkYSlotfd/36ZMoeKMEoUck6feA== + dependencies: + "@popperjs/core" "^2.0.0" + cytoscape@^3.2.19, cytoscape@^3.21.0: version "3.21.0" resolved "https://registry.yarnpkg.com/cytoscape/-/cytoscape-3.21.0.tgz#8a73f6f0f3a44f948e266ac7df9b2eff65e8bd3c" From 12dfa6e131342db2759fb0ba5d1d0ae360f72e67 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Tue, 22 Mar 2022 00:05:36 -0300 Subject: [PATCH 07/31] Adding a tooltip --- .../TransanctionBatchGraph/index.tsx | 89 ++++++++++++++----- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index d8bd0913f..86b0b4206 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -1,4 +1,4 @@ -import Cytoscape, { ElementDefinition, NodeSingular } from 'cytoscape' +import Cytoscape, { ElementDefinition, NodeSingular, NodeDataDefinition, EdgeDataDefinition } from 'cytoscape' import popper from 'cytoscape-popper' import React, { useState, useEffect, useRef, useCallback } from 'react' import CytoscapeComponent from 'react-cytoscapejs' @@ -113,31 +113,75 @@ function TransanctionBatchGraph({ if (error || isLoading || !networkId) return setElements(getNodes(txSettlement, networkId)) + }, [error, isLoading, networkId, txSettlement]) + + useEffect(() => { const cy = cytoscapeRef.current - if (cy) { - cy.on('click', 'node', (_event): void => { - const node = _event.target - const popper = node.popper({ - content: () => { - const div = document.createElement('div') - div.innerHTML = 'Popper Node tooltip' - document.body.appendChild(div) - return div - }, - popper: { - placement: 'top', - }, // my popper options here - }) - const update = (): void => { - popper.update() - } + if (!cy) return + + cy.on('mouseover', 'node, edge', (event): void => { + const target = event.target + const targetData: NodeDataDefinition | EdgeDataDefinition = target.data() + if (targetData.type === TypeNodeOnTx.NetworkNode) return + + const tooltipId = `popper-target-${targetData.id}` + const existingTarget = document.getElementById(tooltipId) + + if (existingTarget) { + existingTarget.remove() + } + const popperRef = target.popper({ + content: () => { + const tooltip = document.createElement('span') + tooltip.id = tooltipId + tooltip.classList.add('target-popper') + + const table = document.createElement('table') + tooltip.append(table) + + // loop through target data + for (const prop in targetData) { + const targetValue = targetData[prop] + // no recursive or reduce support + if (typeof targetValue === 'object') continue + + const tr = table.insertRow() - node.on('position', update) + const tdTitle = tr.insertCell() + const tdValue = tr.insertCell() - cy.on('pan zoom resize', update) + tdTitle.innerText = prop + tdValue.innerText = targetValue + } + + document.body.appendChild(tooltip) + + return tooltip + }, + popper: { + placement: 'top-start', + removeOnDestroy: true, + }, }) - } - }, [error, isLoading, networkId, txSettlement]) + + const popperUpdate = (): (() => void) => popperRef.update() + + target.on('position', () => popperUpdate) + target.cy().on('pan zoom resize', () => popperUpdate) + const newTarget = document.getElementById(tooltipId) + target + .on('mouseover', () => { + if (newTarget) { + newTarget.classList.add('active') + } + }) + .on('mouseout', () => { + if (newTarget) { + newTarget.remove() + } + }) + }) + }, [cytoscapeRef]) if (isLoading) return @@ -161,6 +205,7 @@ function TransanctionBatchGraph({ stylesheet={STYLESHEET} cy={setCytoscape} wheelSensitivity={0.2} + className="tx-graph" /> ) } From 8da94f037683d0aff92ff17f261acb19022e133b Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Tue, 22 Mar 2022 00:21:38 -0300 Subject: [PATCH 08/31] listed tap by mobile on tooltip --- .../explorer/components/TransanctionBatchGraph/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 86b0b4206..eac474ad7 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -119,7 +119,7 @@ function TransanctionBatchGraph({ const cy = cytoscapeRef.current if (!cy) return - cy.on('mouseover', 'node, edge', (event): void => { + cy.on('click tapstart', 'node, edge', (event): void => { const target = event.target const targetData: NodeDataDefinition | EdgeDataDefinition = target.data() if (targetData.type === TypeNodeOnTx.NetworkNode) return @@ -170,12 +170,12 @@ function TransanctionBatchGraph({ target.cy().on('pan zoom resize', () => popperUpdate) const newTarget = document.getElementById(tooltipId) target - .on('mouseover', () => { + .on('click tapstart', () => { if (newTarget) { newTarget.classList.add('active') } }) - .on('mouseout', () => { + .on('mouseout tapend', () => { if (newTarget) { newTarget.remove() } @@ -193,7 +193,7 @@ function TransanctionBatchGraph({ fit: true, // whether to fit the viewport to the graph padding: 10, // padding used on fit avoidOverlap: true, // prevents node overlap, may overflow boundingBox if not enough space - avoidOverlapPadding: 100, // extra spacing around nodes when avoidOverlap: true + avoidOverlapPadding: 10, // extra spacing around nodes when avoidOverlap: true nodeDimensionsIncludeLabels: false, } From 4b7a23d28d2a54fd6ad70773b5c189bfe4491dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Tue, 22 Mar 2022 14:35:22 -0300 Subject: [PATCH 09/31] add tooltip css --- .../TransanctionBatchGraph/batchviewer.css | 29 +++++++++++++++++++ .../TransanctionBatchGraph/index.tsx | 1 + 2 files changed, 30 insertions(+) create mode 100644 src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css diff --git a/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css b/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css new file mode 100644 index 000000000..0485a92bd --- /dev/null +++ b/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css @@ -0,0 +1,29 @@ +.target-popper { + max-width: 50rem; + padding: 1rem; + margin: 0 0 1rem 0; + text-align: left; + font-size: 1.2rem; + border-radius: 0.5rem; + border: 1px solid rgb(25, 24, 29); + background: rgb(60, 62, 78); + line-height: 1.4rem; + word-break: break-all; +} + +/* arrow tooltip +.target-popper:after { + content: ""; + position: absolute; + top: 100%; + left: 0rem; + border-width: 6px; + border-style: solid; + border-color: rgb(60, 62, 78) transparent transparent transparent; +} */ + +.target-popper tr > td:first-child { + font-weight: bold; + text-transform: uppercase; + width: 6rem; +} \ No newline at end of file diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index eac474ad7..9ffb61103 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -15,6 +15,7 @@ import { APP_NAME } from 'const' import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' import { STYLESHEET } from './styled' import { abbreviateString } from 'utils' +import './batchviewer.css' Cytoscape.use(popper) const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER From 09e1b6178c120110cf07e9ef7b05dca5c9af5227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Tue, 22 Mar 2022 14:42:56 -0300 Subject: [PATCH 10/31] add eof space --- .../explorer/components/TransanctionBatchGraph/batchviewer.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css b/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css index 0485a92bd..911eab7b9 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css +++ b/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css @@ -26,4 +26,4 @@ font-weight: bold; text-transform: uppercase; width: 6rem; -} \ No newline at end of file +} From fa90634185beaf528c8c3004affe4219642368c1 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Wed, 23 Mar 2022 00:09:14 -0300 Subject: [PATCH 11/31] Adding amount of transfers --- .../elementsBuilder.tsx | 10 +- .../TransanctionBatchGraph/index.tsx | 154 ++++++++++-------- .../TransanctionBatchGraph/styled.ts | 6 + .../TransanctionBatchGraph/types.ts | 2 + 4 files changed, 105 insertions(+), 67 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx index 7e3bce229..ef60f7d06 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx @@ -1,5 +1,5 @@ import { ElementDefinition } from 'cytoscape' -import { Node, TypeNodeOnTx } from './types' +import { InfoTooltip, Node, TypeNodeOnTx } from './types' export default class ElementsBuilder { _center: ElementDefinition | null = null @@ -40,7 +40,12 @@ export default class ElementsBuilder { return this } - edge(source: Pick, target: Pick, label: string): this { + edge( + source: Pick, + target: Pick, + label: string, + tooltip?: InfoTooltip, + ): this { this._edges.push({ group: 'edges', data: { @@ -48,6 +53,7 @@ export default class ElementsBuilder { source: `${source.type}:${source.id}`, target: `${target.type}:${target.id}`, label, + tooltip, }, }) return this diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 9ffb61103..6f36c0277 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -1,4 +1,10 @@ -import Cytoscape, { ElementDefinition, NodeSingular, NodeDataDefinition, EdgeDataDefinition } from 'cytoscape' +import Cytoscape, { + ElementDefinition, + NodeSingular, + NodeDataDefinition, + EdgeDataDefinition, + EventObject, +} from 'cytoscape' import popper from 'cytoscape-popper' import React, { useState, useEffect, useRef, useCallback } from 'react' import CytoscapeComponent from 'react-cytoscapejs' @@ -16,6 +22,7 @@ import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' import { STYLESHEET } from './styled' import { abbreviateString } from 'utils' import './batchviewer.css' +import BigNumber from 'bignumber.js' Cytoscape.use(popper) const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER @@ -39,10 +46,9 @@ function getTypeNode(account: Account): TypeNodeOnTx { } function showTraderAddress(account: Account, address: string): Account { - if (account.alias === ALIAS_TRADER_NAME) { - account.alias = abbreviateString(address, 4, 4) - } - return account + const alias = account.alias === ALIAS_TRADER_NAME ? abbreviateString(address, 4, 4) : account.alias + + return { ...account, alias } } function getNetworkParentNode(account: Account, networkName: string): string | undefined { @@ -76,14 +82,19 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini } txSettlement.transfers.forEach((transfer) => { - const token = txSettlement.tokens[transfer.token] || { decimals: 1, symbol: 'UNKNOW' } + const token = txSettlement.tokens[transfer.token] + const tokenSymbol = token?.symbol || 'UNKNOW' + const tokenAmount = token?.decimals + ? new BigNumber(transfer.value).div(new BigNumber(10).pow(token.decimals)).toFixed(2) + : '-' const source = builder.getById(transfer.from) const target = builder.getById(transfer.to) builder.edge( { type: source?.data.type, id: transfer.from }, { type: target?.data.type, id: transfer.to }, - `${token.symbol}`, + `${tokenSymbol}`, + { from: transfer.from, to: transfer.to, amount: `${tokenAmount} ${tokenSymbol}` }, ) }) @@ -92,6 +103,69 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini ) } +function bindPopper(event: EventObject, targetData: Cytoscape.NodeDataDefinition | Cytoscape.EdgeDataDefinition): void { + const tooltipId = `popper-target-${targetData.id}` + const existingTarget = document.getElementById(tooltipId) + + // Remove if already existing + if (existingTarget) { + existingTarget.remove() + } + + const target = event.target + const popperRef = target.popper({ + content: () => { + const tooltip = document.createElement('span') + tooltip.id = tooltipId + tooltip.classList.add('target-popper') + + const table = document.createElement('table') + tooltip.append(table) + + // loop through target data [tooltip] + for (const prop in targetData.tooltip) { + const targetValue = targetData.tooltip[prop] + + // no recursive or reduce support + if (typeof targetValue === 'object') continue + + const tr = table.insertRow() + + const tdTitle = tr.insertCell() + const tdValue = tr.insertCell() + + tdTitle.innerText = prop + tdValue.innerText = targetValue + } + + document.body.appendChild(tooltip) + + return tooltip + }, + popper: { + placement: 'top-start', + removeOnDestroy: true, + }, + }) + + const popperUpdate = (): (() => void) => popperRef.update() + + target.on('position', () => popperUpdate) + target.cy().on('pan zoom resize', () => popperUpdate) + const newTarget = document.getElementById(tooltipId) + target + .on('click tapstart', () => { + if (newTarget) { + newTarget.classList.add('active') + } + }) + .on('mouseout tapend', () => { + if (newTarget) { + newTarget.remove() + } + }) +} + interface GraphBatchTxParams { txBatchData: TxBatchData networkId: Network | undefined @@ -120,67 +194,17 @@ function TransanctionBatchGraph({ const cy = cytoscapeRef.current if (!cy) return - cy.on('click tapstart', 'node, edge', (event): void => { + cy.on('click tapstart', 'edge', (event): void => { const target = event.target const targetData: NodeDataDefinition | EdgeDataDefinition = target.data() - if (targetData.type === TypeNodeOnTx.NetworkNode) return - - const tooltipId = `popper-target-${targetData.id}` - const existingTarget = document.getElementById(tooltipId) - - if (existingTarget) { - existingTarget.remove() - } - const popperRef = target.popper({ - content: () => { - const tooltip = document.createElement('span') - tooltip.id = tooltipId - tooltip.classList.add('target-popper') - - const table = document.createElement('table') - tooltip.append(table) - // loop through target data - for (const prop in targetData) { - const targetValue = targetData[prop] - // no recursive or reduce support - if (typeof targetValue === 'object') continue - - const tr = table.insertRow() - - const tdTitle = tr.insertCell() - const tdValue = tr.insertCell() - - tdTitle.innerText = prop - tdValue.innerText = targetValue - } - - document.body.appendChild(tooltip) - - return tooltip - }, - popper: { - placement: 'top-start', - removeOnDestroy: true, - }, - }) - - const popperUpdate = (): (() => void) => popperRef.update() - - target.on('position', () => popperUpdate) - target.cy().on('pan zoom resize', () => popperUpdate) - const newTarget = document.getElementById(tooltipId) - target - .on('click tapstart', () => { - if (newTarget) { - newTarget.classList.add('active') - } - }) - .on('mouseout tapend', () => { - if (newTarget) { - newTarget.remove() - } - }) + bindPopper(event, targetData) + }) + cy.on('mouseover', 'edge', (event): void => { + event.target.addClass('hover') + }) + cy.on('mouseout', 'edge', (event): void => { + event.target.removeClass('hover') }) }, [cytoscapeRef]) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index e2ee0f8d2..e90e2232e 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -33,6 +33,12 @@ export const STYLESHEET: Stylesheet[] = [ 'font-size': '11px', }, }, + { + selector: 'edge.hover', + style: { + width: 5, + }, + }, { selector: 'node[type="trader"]', style: { diff --git a/src/apps/explorer/components/TransanctionBatchGraph/types.ts b/src/apps/explorer/components/TransanctionBatchGraph/types.ts index bd1562806..aab4c5e0c 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/types.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/types.ts @@ -7,6 +7,8 @@ export enum TypeNodeOnTx { Dex = 'dex', } +export type InfoTooltip = Record + export type NodeType = { type: T; entity: E; id: string } export type Node = | NodeType From ac3c703a5245f612b40d2df78d7450cab14938ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Wed, 23 Mar 2022 09:14:09 -0300 Subject: [PATCH 12/31] css test deploy --- .../explorer/components/TransanctionBatchGraph/batchviewer.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css b/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css index 911eab7b9..21acfcc01 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css +++ b/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css @@ -5,7 +5,7 @@ text-align: left; font-size: 1.2rem; border-radius: 0.5rem; - border: 1px solid rgb(25, 24, 29); + border: 1px solid rgb(45, 43, 51); background: rgb(60, 62, 78); line-height: 1.4rem; word-break: break-all; From de1ea8803cfe6c6c1542b74fd65f3f726bb0f419 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Wed, 23 Mar 2022 09:14:45 -0300 Subject: [PATCH 13/31] bindPopper after data loading --- src/apps/explorer/components/TransanctionBatchGraph/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 6f36c0277..9aa59c31a 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -192,7 +192,7 @@ function TransanctionBatchGraph({ useEffect(() => { const cy = cytoscapeRef.current - if (!cy) return + if (!cy || !elements.length) return cy.on('click tapstart', 'edge', (event): void => { const target = event.target @@ -206,7 +206,7 @@ function TransanctionBatchGraph({ cy.on('mouseout', 'edge', (event): void => { event.target.removeClass('hover') }) - }, [cytoscapeRef]) + }, [cytoscapeRef, elements.length]) if (isLoading) return From 4eec1741b49882d2aa3db3394c99415768fab977 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Wed, 23 Mar 2022 09:35:01 -0300 Subject: [PATCH 14/31] Changing css file name --- src/api/tenderly/index.ts | 2 +- .../{batchviewer.css => TransanctionBatchGraph.css} | 0 src/apps/explorer/components/TransanctionBatchGraph/index.tsx | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/apps/explorer/components/TransanctionBatchGraph/{batchviewer.css => TransanctionBatchGraph.css} (100%) diff --git a/src/api/tenderly/index.ts b/src/api/tenderly/index.ts index 1bb5ec28d..fc2851312 100644 --- a/src/api/tenderly/index.ts +++ b/src/api/tenderly/index.ts @@ -1,3 +1,3 @@ export * from './tenderlyApi' -export { PublicTrade as Trade, Transfer, Account } from './types' +export type { PublicTrade as Trade, Transfer, Account } from './types' diff --git a/src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css b/src/apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css similarity index 100% rename from src/apps/explorer/components/TransanctionBatchGraph/batchviewer.css rename to src/apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 9aa59c31a..446cf6cd5 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -21,7 +21,7 @@ import { APP_NAME } from 'const' import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' import { STYLESHEET } from './styled' import { abbreviateString } from 'utils' -import './batchviewer.css' +import 'apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css' import BigNumber from 'bignumber.js' Cytoscape.use(popper) From 29f3f1dbbfed5637f6871699f452c183e7d04965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Wed, 23 Mar 2022 09:44:32 -0300 Subject: [PATCH 15/31] css arrow styles --- .../explorer/components/TransanctionBatchGraph/styled.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index e90e2232e..5f461400d 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -22,6 +22,7 @@ export const STYLESHEET: Stylesheet[] = [ label: 'data(label)', width: 3, 'target-arrow-shape': 'triangle', + 'target-arrow-color': '#979dbf', 'curve-style': 'unbundled-bezier', color: 'black', 'line-color': '#747a9e', @@ -36,7 +37,9 @@ export const STYLESHEET: Stylesheet[] = [ { selector: 'edge.hover', style: { - width: 5, + width: 4, + 'line-color': '#D96D49', + 'target-arrow-color': '#D96D49', }, }, { From 90ddc551c427e5025856d72d422336d887a7e559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Wed, 23 Mar 2022 10:00:23 -0300 Subject: [PATCH 16/31] css globakl styles BV --- .../TransanctionBatchGraph/index.tsx | 2 +- src/apps/explorer/styled.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 446cf6cd5..3bce03ea1 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -21,7 +21,7 @@ import { APP_NAME } from 'const' import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' import { STYLESHEET } from './styled' import { abbreviateString } from 'utils' -import 'apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css' +// import 'apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css' import BigNumber from 'bignumber.js' Cytoscape.use(popper) diff --git a/src/apps/explorer/styled.ts b/src/apps/explorer/styled.ts index 73d37f15d..152365979 100644 --- a/src/apps/explorer/styled.ts +++ b/src/apps/explorer/styled.ts @@ -12,6 +12,25 @@ export const GlobalStyle = createGlobalStyle` flex-direction: column; flex-grow: 1; } + + /* Cystoscape - BatchViewer styles */ + .target-popper { + max-width: 50rem; + padding: 1rem; + margin: 0 0 1rem 0; + text-align: left; + font-size: 1.2rem; + border-radius: 0.5rem; + border: 1px solid rgb(45, 43, 51); + background: rgb(60, 62, 78); + line-height: 1.4rem; + word-break: break-all; + } + .target-popper tr > td:first-child { + font-weight: bold; + text-transform: uppercase; + width: 6rem; +} ` export const MainWrapper = styled.div` From 9410b4b4c46145f0d52b73061dcbd78976606c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Wed, 23 Mar 2022 10:12:31 -0300 Subject: [PATCH 17/31] clean styles BV --- .../TransanctionBatchGraph.css | 29 ------------------- .../TransanctionBatchGraph/index.tsx | 1 - 2 files changed, 30 deletions(-) delete mode 100644 src/apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css diff --git a/src/apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css b/src/apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css deleted file mode 100644 index 21acfcc01..000000000 --- a/src/apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css +++ /dev/null @@ -1,29 +0,0 @@ -.target-popper { - max-width: 50rem; - padding: 1rem; - margin: 0 0 1rem 0; - text-align: left; - font-size: 1.2rem; - border-radius: 0.5rem; - border: 1px solid rgb(45, 43, 51); - background: rgb(60, 62, 78); - line-height: 1.4rem; - word-break: break-all; -} - -/* arrow tooltip -.target-popper:after { - content: ""; - position: absolute; - top: 100%; - left: 0rem; - border-width: 6px; - border-style: solid; - border-color: rgb(60, 62, 78) transparent transparent transparent; -} */ - -.target-popper tr > td:first-child { - font-weight: bold; - text-transform: uppercase; - width: 6rem; -} diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 3bce03ea1..3981e67cd 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -21,7 +21,6 @@ import { APP_NAME } from 'const' import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' import { STYLESHEET } from './styled' import { abbreviateString } from 'utils' -// import 'apps/explorer/components/TransanctionBatchGraph/TransanctionBatchGraph.css' import BigNumber from 'bignumber.js' Cytoscape.use(popper) From 10d363ff9734f17c99b46ff8c4f59d1b12a2d398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Wed, 23 Mar 2022 11:25:35 -0300 Subject: [PATCH 18/31] bigger CoW protocol logo --- .../components/TransanctionBatchGraph/styled.ts | 2 ++ src/assets/img/CoW.svg | 17 +---------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index 5f461400d..203a181e7 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -63,6 +63,8 @@ export const STYLESHEET: Stylesheet[] = [ selector: 'node[type="cowProtocol"]', style: { 'background-image': `url(${CowProtocolIcon})`, + height: '90', + width: '90', 'text-valign': 'bottom', 'text-margin-y': 8, }, diff --git a/src/assets/img/CoW.svg b/src/assets/img/CoW.svg index 1df19b7a7..c7595228b 100644 --- a/src/assets/img/CoW.svg +++ b/src/assets/img/CoW.svg @@ -1,16 +1 @@ - - - - - - - - - - - - - - - - + \ No newline at end of file From 8ac78440f1e5471536707367a1e5ff3904364171 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Wed, 23 Mar 2022 15:38:12 -0300 Subject: [PATCH 19/31] Remove all existing tooltips --- .../TransanctionBatchGraph/index.tsx | 20 ++++++++----------- src/apps/explorer/const.ts | 2 ++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 3981e67cd..dca10158b 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -18,10 +18,9 @@ import { Account, ALIAS_TRADER_NAME } from 'api/tenderly' import ElementsBuilder, { buildGridLayout } from 'apps/explorer/components/TransanctionBatchGraph/elementsBuilder' import { TypeNodeOnTx } from './types' import { APP_NAME } from 'const' -import { HEIGHT_HEADER_FOOTER } from 'apps/explorer/const' +import { HEIGHT_HEADER_FOOTER, TOKEN_SYMBOL_UNKNOWN } from 'apps/explorer/const' import { STYLESHEET } from './styled' -import { abbreviateString } from 'utils' -import BigNumber from 'bignumber.js' +import { abbreviateString, formatSmart } from 'utils' Cytoscape.use(popper) const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER @@ -82,10 +81,8 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini txSettlement.transfers.forEach((transfer) => { const token = txSettlement.tokens[transfer.token] - const tokenSymbol = token?.symbol || 'UNKNOW' - const tokenAmount = token?.decimals - ? new BigNumber(transfer.value).div(new BigNumber(10).pow(token.decimals)).toFixed(2) - : '-' + const tokenSymbol = token?.symbol || TOKEN_SYMBOL_UNKNOWN + const tokenAmount = token?.decimals ? formatSmart(transfer.value, token.decimals) : '-' const source = builder.getById(transfer.from) const target = builder.getById(transfer.to) @@ -104,19 +101,18 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini function bindPopper(event: EventObject, targetData: Cytoscape.NodeDataDefinition | Cytoscape.EdgeDataDefinition): void { const tooltipId = `popper-target-${targetData.id}` - const existingTarget = document.getElementById(tooltipId) + const popperClassTarget = 'target-popper' // Remove if already existing - if (existingTarget) { - existingTarget.remove() - } + const existingTooltips: HTMLCollectionOf = document.getElementsByClassName(popperClassTarget) + Array.from(existingTooltips).forEach((ele: { remove: () => void }): void => ele && ele.remove()) const target = event.target const popperRef = target.popper({ content: () => { const tooltip = document.createElement('span') tooltip.id = tooltipId - tooltip.classList.add('target-popper') + tooltip.classList.add(popperClassTarget) const table = document.createElement('table') tooltip.append(table) diff --git a/src/apps/explorer/const.ts b/src/apps/explorer/const.ts index 606846fe3..f093c6c9c 100644 --- a/src/apps/explorer/const.ts +++ b/src/apps/explorer/const.ts @@ -26,3 +26,5 @@ export const NETWORK_ID_SEARCH_LIST = [Network.Mainnet, Network.xDAI, Network.Ri // Estimation heigh of the header + footer space export const HEIGHT_HEADER_FOOTER = 257 + +export const TOKEN_SYMBOL_UNKNOWN = 'UNKNOWN' From 1836ed4a87d809e58f24ffa17e9aed8b275e0765 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Wed, 23 Mar 2022 15:44:22 -0300 Subject: [PATCH 20/31] Add comment for guidance --- src/apps/explorer/components/TransanctionBatchGraph/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index dca10158b..186a190f3 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -99,6 +99,9 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini ) } +/** + * This allow bind a tooltip (popper.js) around to a cytoscape elements (node, edge) + */ function bindPopper(event: EventObject, targetData: Cytoscape.NodeDataDefinition | Cytoscape.EdgeDataDefinition): void { const tooltipId = `popper-target-${targetData.id}` const popperClassTarget = 'target-popper' From aed00054ba250eee46d1145069fbdc7ab01f91e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Fri, 25 Mar 2022 12:51:38 -0300 Subject: [PATCH 21/31] add cow trader icon --- src/assets/img/TraderMe.svg | 17 ++++++++++++++--- src/assets/img/TraderOther.svg | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/assets/img/TraderMe.svg b/src/assets/img/TraderMe.svg index b36a98759..7cf20e1d6 100644 --- a/src/assets/img/TraderMe.svg +++ b/src/assets/img/TraderMe.svg @@ -1,5 +1,16 @@ - - - + + + + + + + + + + + + + + diff --git a/src/assets/img/TraderOther.svg b/src/assets/img/TraderOther.svg index 4345ba7f1..ac5b0f7e7 100644 --- a/src/assets/img/TraderOther.svg +++ b/src/assets/img/TraderOther.svg @@ -1,5 +1,16 @@ - - - + + + + + + + + + + + + + + From 6e804d3de7d008bc66046504ceaf346551dbf30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Fri, 25 Mar 2022 13:33:16 -0300 Subject: [PATCH 22/31] cow trader icon with rays --- src/assets/img/TraderOther.svg | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/assets/img/TraderOther.svg b/src/assets/img/TraderOther.svg index ac5b0f7e7..fc96622b3 100644 --- a/src/assets/img/TraderOther.svg +++ b/src/assets/img/TraderOther.svg @@ -13,4 +13,11 @@ + + + + + + + From 4774a232a280144c1e5dcd91164279ee983009a4 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Fri, 25 Mar 2022 17:27:13 -0300 Subject: [PATCH 23/31] start moving colors to variables --- .../TransanctionBatchGraph/index.tsx | 5 +- .../TransanctionBatchGraph/styled.ts | 133 +++++++++--------- 2 files changed, 71 insertions(+), 67 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 186a190f3..fcabc9582 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -8,7 +8,7 @@ import Cytoscape, { import popper from 'cytoscape-popper' import React, { useState, useEffect, useRef, useCallback } from 'react' import CytoscapeComponent from 'react-cytoscapejs' -import styled from 'styled-components' +import styled, { useTheme } from 'styled-components' import Spinner from 'components/common/Spinner' import { GetTxBatchTradesResult as TxBatchData, Settlement as TxSettlement } from 'hooks/useTxBatchTrades' @@ -175,6 +175,7 @@ function TransanctionBatchGraph({ }: GraphBatchTxParams): JSX.Element { const [elements, setElements] = useState([]) const cytoscapeRef = useRef(null) + const theme = useTheme() const setCytoscape = useCallback( (ref: Cytoscape.Core) => { cytoscapeRef.current = ref @@ -225,7 +226,7 @@ function TransanctionBatchGraph({ elements={elements} layout={layout} style={{ width: '100%', height: HEIGHT_SIZE }} - stylesheet={STYLESHEET} + stylesheet={STYLESHEET(theme)} cy={setCytoscape} wheelSensitivity={0.2} className="tx-graph" diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index 203a181e7..89a55b337 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -1,79 +1,82 @@ import { Stylesheet } from 'cytoscape' +import { DefaultTheme } from 'styled-components' import TraderOtherIcon from 'assets/img/TraderOther.svg' import CowProtocolIcon from 'assets/img/CoW.svg' import DexIcon from 'assets/img/Dex.svg' -export const STYLESHEET: Stylesheet[] = [ - { - selector: 'node[label]', - style: { - label: 'data(label)', - color: '#cfcfcf', - height: 50, - width: 50, - 'background-color': '#22232d', +export function STYLESHEET(theme: DefaultTheme): Stylesheet[] { + return [ + { + selector: 'node[label]', + style: { + label: 'data(label)', + color: '#cfcfcf', + height: 50, + width: 50, + 'background-color': theme.bg2, + }, }, - }, - { - selector: 'edge[label]', - style: { - label: 'data(label)', - width: 3, - 'target-arrow-shape': 'triangle', - 'target-arrow-color': '#979dbf', - 'curve-style': 'unbundled-bezier', - color: 'black', - 'line-color': '#747a9e', - 'line-opacity': 0.8, - 'text-background-color': 'white', - 'text-background-opacity': 1, - 'text-background-padding': '2px', - 'text-background-shape': 'roundrectangle', - 'font-size': '11px', + { + selector: 'edge[label]', + style: { + label: 'data(label)', + width: 3, + 'target-arrow-shape': 'triangle', + 'target-arrow-color': '#979dbf', + 'curve-style': 'unbundled-bezier', + color: 'black', + 'line-color': '#747a9e', + 'line-opacity': 0.8, + 'text-background-color': 'white', + 'text-background-opacity': 1, + 'text-background-padding': '2px', + 'text-background-shape': 'roundrectangle', + 'font-size': '11px', + }, }, - }, - { - selector: 'edge.hover', - style: { - width: 4, - 'line-color': '#D96D49', - 'target-arrow-color': '#D96D49', + { + selector: 'edge.hover', + style: { + width: 4, + 'line-color': '#D96D49', + 'target-arrow-color': '#D96D49', + }, }, - }, - { - selector: 'node[type="trader"]', - style: { - 'background-image': `url(${TraderOtherIcon})`, - 'text-valign': 'bottom', - 'text-margin-y': 8, + { + selector: 'node[type="trader"]', + style: { + 'background-image': `url(${TraderOtherIcon})`, + 'text-valign': 'bottom', + 'text-margin-y': 8, + }, }, - }, - { - selector: 'node[type="dex"]', - style: { - 'background-image': `url(${DexIcon})`, - 'text-max-width': '5rem', - 'text-valign': 'bottom', - 'text-margin-y': 8, + { + selector: 'node[type="dex"]', + style: { + 'background-image': `url(${DexIcon})`, + 'text-max-width': '5rem', + 'text-valign': 'bottom', + 'text-margin-y': 8, + }, }, - }, - { - selector: 'node[type="cowProtocol"]', - style: { - 'background-image': `url(${CowProtocolIcon})`, - height: '90', - width: '90', - 'text-valign': 'bottom', - 'text-margin-y': 8, + { + selector: 'node[type="cowProtocol"]', + style: { + 'background-image': `url(${CowProtocolIcon})`, + height: '90', + width: '90', + 'text-valign': 'bottom', + 'text-margin-y': 8, + }, }, - }, - { - selector: 'node[type="networkNode"]', - style: { - 'border-style': 'dashed', - 'border-opacity': 0.8, + { + selector: 'node[type="networkNode"]', + style: { + 'border-style': 'dashed', + 'border-opacity': 0.8, + }, }, - }, -] + ] +} From 908767d1c0cae130318a2a3fa1c2bbe1f07bc218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Fri, 25 Mar 2022 19:26:34 -0300 Subject: [PATCH 24/31] replace colors from theme --- .../TransanctionBatchGraph/styled.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index 89a55b337..e6b9f59de 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -11,7 +11,7 @@ export function STYLESHEET(theme: DefaultTheme): Stylesheet[] { selector: 'node[label]', style: { label: 'data(label)', - color: '#cfcfcf', + color: theme.textSecondary1, height: 50, width: 50, 'background-color': theme.bg2, @@ -22,14 +22,14 @@ export function STYLESHEET(theme: DefaultTheme): Stylesheet[] { selector: 'edge[label]', style: { label: 'data(label)', - width: 3, + width: 2, 'target-arrow-shape': 'triangle', - 'target-arrow-color': '#979dbf', + 'target-arrow-color': theme.grey, 'curve-style': 'unbundled-bezier', - color: 'black', - 'line-color': '#747a9e', + color: theme.black, + 'line-color': theme.grey, 'line-opacity': 0.8, - 'text-background-color': 'white', + 'text-background-color': theme.labelTextOpen, 'text-background-opacity': 1, 'text-background-padding': '2px', 'text-background-shape': 'roundrectangle', @@ -39,9 +39,9 @@ export function STYLESHEET(theme: DefaultTheme): Stylesheet[] { { selector: 'edge.hover', style: { - width: 4, - 'line-color': '#D96D49', - 'target-arrow-color': '#D96D49', + width: 3, + 'line-color': theme.orange1, + 'target-arrow-color': theme.orange1, }, }, { From 75a77ce074d7b06914089b309b574b43a44f695d Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Tue, 29 Mar 2022 10:27:57 -0300 Subject: [PATCH 25/31] Uppercase NetworkName and HighPrecission decimals --- .../explorer/components/TransanctionBatchGraph/index.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index fcabc9582..8d5791811 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -9,6 +9,7 @@ import popper from 'cytoscape-popper' import React, { useState, useEffect, useRef, useCallback } from 'react' import CytoscapeComponent from 'react-cytoscapejs' import styled, { useTheme } from 'styled-components' +import BigNumber from 'bignumber.js' import Spinner from 'components/common/Spinner' import { GetTxBatchTradesResult as TxBatchData, Settlement as TxSettlement } from 'hooks/useTxBatchTrades' @@ -20,7 +21,7 @@ import { TypeNodeOnTx } from './types' import { APP_NAME } from 'const' import { HEIGHT_HEADER_FOOTER, TOKEN_SYMBOL_UNKNOWN } from 'apps/explorer/const' import { STYLESHEET } from './styled' -import { abbreviateString, formatSmart } from 'utils' +import { abbreviateString, FormatAmountPrecision, formattingAmountPrecision } from 'utils' Cytoscape.use(popper) const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER @@ -56,7 +57,7 @@ function getNetworkParentNode(account: Account, networkName: string): string | u function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefinition[] { if (!txSettlement.accounts) return [] - const networkName = networkOptions.find((network) => network.id === networkId)?.name.toLowerCase() + const networkName = networkOptions.find((network) => network.id === networkId)?.name const networkNode = { alias: networkName || '' } const builder = new ElementsBuilder(HEIGHT_SIZE) builder.node({ type: TypeNodeOnTx.NetworkNode, entity: networkNode, id: networkNode.alias }) @@ -82,7 +83,9 @@ function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefini txSettlement.transfers.forEach((transfer) => { const token = txSettlement.tokens[transfer.token] const tokenSymbol = token?.symbol || TOKEN_SYMBOL_UNKNOWN - const tokenAmount = token?.decimals ? formatSmart(transfer.value, token.decimals) : '-' + const tokenAmount = token?.decimals + ? formattingAmountPrecision(new BigNumber(transfer.value), token, FormatAmountPrecision.highPrecision) + : '-' const source = builder.getById(transfer.from) const target = builder.getById(transfer.to) From 08af504448aa8b5ed5a091cf3a5ed6cda6d4cb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Tue, 29 Mar 2022 11:20:56 -0300 Subject: [PATCH 26/31] increase token name size --- src/apps/explorer/components/TransanctionBatchGraph/styled.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index e6b9f59de..e844e5087 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -31,9 +31,9 @@ export function STYLESHEET(theme: DefaultTheme): Stylesheet[] { 'line-opacity': 0.8, 'text-background-color': theme.labelTextOpen, 'text-background-opacity': 1, - 'text-background-padding': '2px', + 'text-background-padding': '4px', 'text-background-shape': 'roundrectangle', - 'font-size': '11px', + 'font-size': '16px', }, }, { From 39e4c181bba63242e641584d26b82d8e69cbb599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Tue, 29 Mar 2022 12:00:36 -0300 Subject: [PATCH 27/31] increase token name size --- .../explorer/components/TransanctionBatchGraph/styled.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts index e844e5087..dc3a5e28c 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/styled.ts +++ b/src/apps/explorer/components/TransanctionBatchGraph/styled.ts @@ -34,14 +34,17 @@ export function STYLESHEET(theme: DefaultTheme): Stylesheet[] { 'text-background-padding': '4px', 'text-background-shape': 'roundrectangle', 'font-size': '16px', + 'min-zoomed-font-size': 8, }, }, { - selector: 'edge.hover', + selector: 'edge[label].hover', style: { width: 3, 'line-color': theme.orange1, 'target-arrow-color': theme.orange1, + 'text-background-color': theme.orange, + color: theme.white, }, }, { From ff771bbb6a820a7619dd61f918a04cba7d07cfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Longoni?= Date: Tue, 29 Mar 2022 18:39:19 -0300 Subject: [PATCH 28/31] change tooltip events --- src/apps/explorer/components/TransanctionBatchGraph/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 8d5791811..08096bfa4 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -196,7 +196,7 @@ function TransanctionBatchGraph({ const cy = cytoscapeRef.current if (!cy || !elements.length) return - cy.on('click tapstart', 'edge', (event): void => { + cy.on('mouseover touchstart', 'edge', (event): void => { const target = event.target const targetData: NodeDataDefinition | EdgeDataDefinition = target.data() From 05fa37a9a94fed6bf08a38d13c037abce825bdad Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Wed, 30 Mar 2022 10:35:12 -0300 Subject: [PATCH 29/31] Testing build --- .../components/TransanctionBatchGraph/elementsBuilder.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx index ef60f7d06..371e427bc 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/elementsBuilder.tsx @@ -125,6 +125,10 @@ export function getGridPosition(type: TypeNodeOnTx, traderRowsLength: number, de return col } +/** + * Build a grid layout using the 'position' attribute + * using 'x' for the columns and 'y' for the rows. + */ export function buildGridLayout( countTypes: Map, center: ElementDefinition | null, From 3899285ea85779fe2f898526928aabe8668a4134 Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Thu, 31 Mar 2022 16:58:16 -0300 Subject: [PATCH 30/31] Limiting the max and min zoom view --- src/apps/explorer/components/TransanctionBatchGraph/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 08096bfa4..3fa3c7e5f 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -233,6 +233,9 @@ function TransanctionBatchGraph({ cy={setCytoscape} wheelSensitivity={0.2} className="tx-graph" + maxZoom={3} + minZoom={0.1} + zoom={1} /> ) } From fc9b41c2efc9e1bdcb3e5ebf787e482acc909d8d Mon Sep 17 00:00:00 2001 From: Henry Palacios Date: Thu, 31 Mar 2022 21:25:22 -0300 Subject: [PATCH 31/31] Resize graph view after press button: show transaction list --- .../components/TransanctionBatchGraph/index.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx index 3fa3c7e5f..ec5c801af 100644 --- a/src/apps/explorer/components/TransanctionBatchGraph/index.tsx +++ b/src/apps/explorer/components/TransanctionBatchGraph/index.tsx @@ -24,7 +24,6 @@ import { STYLESHEET } from './styled' import { abbreviateString, FormatAmountPrecision, formattingAmountPrecision } from 'utils' Cytoscape.use(popper) -const HEIGHT_SIZE = window.innerHeight - HEIGHT_HEADER_FOOTER const PROTOCOL_NAME = APP_NAME const WrapperCytoscape = styled(CytoscapeComponent)` background-color: ${({ theme }): string => theme.bg1}; @@ -54,12 +53,12 @@ function getNetworkParentNode(account: Account, networkName: string): string | u return account.alias !== ALIAS_TRADER_NAME ? networkName : undefined } -function getNodes(txSettlement: TxSettlement, networkId: Network): ElementDefinition[] { +function getNodes(txSettlement: TxSettlement, networkId: Network, heightSize: number): ElementDefinition[] { if (!txSettlement.accounts) return [] const networkName = networkOptions.find((network) => network.id === networkId)?.name const networkNode = { alias: networkName || '' } - const builder = new ElementsBuilder(HEIGHT_SIZE) + const builder = new ElementsBuilder(heightSize) builder.node({ type: TypeNodeOnTx.NetworkNode, entity: networkNode, id: networkNode.alias }) for (const key in txSettlement.accounts) { @@ -179,6 +178,7 @@ function TransanctionBatchGraph({ const [elements, setElements] = useState([]) const cytoscapeRef = useRef(null) const theme = useTheme() + const heightSize = window.innerHeight - HEIGHT_HEADER_FOOTER const setCytoscape = useCallback( (ref: Cytoscape.Core) => { cytoscapeRef.current = ref @@ -187,10 +187,11 @@ function TransanctionBatchGraph({ ) useEffect(() => { + setElements([]) if (error || isLoading || !networkId) return - setElements(getNodes(txSettlement, networkId)) - }, [error, isLoading, networkId, txSettlement]) + setElements(getNodes(txSettlement, networkId, heightSize)) + }, [heightSize, error, isLoading, networkId, txSettlement]) useEffect(() => { const cy = cytoscapeRef.current @@ -228,7 +229,7 @@ function TransanctionBatchGraph({