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

Commit

Permalink
ylff
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszradomski committed Oct 30, 2023
1 parent 9eb9922 commit 2be374a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
29 changes: 12 additions & 17 deletions packages/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DiscoveryOutput } from '@l2beat/discovery-types'
import '@total-typescript/ts-reset'

import { DiscoveryOutput } from '@l2beat/discovery-types'
import cx from 'classnames'
import { useState } from 'react'

Expand Down Expand Up @@ -54,14 +54,14 @@ export function App() {
async function discoverFromFile(discoveredFile: File) {
console.log('LOADING')

markLoading("Discovery.json parse", true)
markLoading('Discovery.json parse', true)

const contents = await discoveredFile.text()
const parsed: unknown = JSON.parse(contents)
const discovery = parsed as DiscoveryOutput
const result = transformContracts(discovery)

markLoading("Discovery.json parse", false)
markLoading('Discovery.json parse', false)
setNodes((nodes) => merge(nodes, result))
}

Expand All @@ -80,21 +80,16 @@ export function App() {
className="h-full w-full"
onDrop={(event) => {
event.preventDefault()

if (event.dataTransfer.items) {
;[...event.dataTransfer.items].forEach((item) => {
if (item.kind === 'file') {
const file = item.getAsFile()
if (file) {
discoverFromFile(file)
}
;[...event.dataTransfer.items].forEach((item) => {
if (item.kind === 'file') {
const file = item.getAsFile()
if (file) {
discoverFromFile(file).catch((e) => {
throw e
})
}
})
} else {
;[...event.dataTransfer.files].forEach((file) => {
console.log(`API2: file.name = ${file.name}`)
})
}
}
})
}}
onDragOver={(event) => {
event.preventDefault()
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/api/discover.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DiscoveryOutput } from '@l2beat/discovery-types'

import { SimpleNode } from './SimpleNode'
import { transformContracts } from './transform'

Expand Down
25 changes: 20 additions & 5 deletions packages/frontend/src/api/transform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {
ContractParameters,
ContractValue,
DiscoveryOutput,
} from '@l2beat/discovery-types'

import { ContractNode, EOANode, SimpleNode } from './SimpleNode'
import { DiscoveryOutput, ContractParameters, ContractValue } from '@l2beat/discovery-types'

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'

Expand Down Expand Up @@ -106,7 +111,10 @@ function getProxyDetails(contract: ContractParameters): {
implementations.push(contract.upgradeability.masterCopy.toString())
break
case 'EIP1967 proxy':
proxyFields.push({ name: 'admin', value: contract.upgradeability.admin.toString() })
proxyFields.push({
name: 'admin',
value: contract.upgradeability.admin.toString(),
})
implementations.push(contract.upgradeability.implementation.toString())
break
case 'ZeppelinOS proxy':
Expand All @@ -124,12 +132,17 @@ function getProxyDetails(contract: ContractParameters): {
case 'StarkWare diamond':
implementations.push(
contract.upgradeability.implementation.toString(),
...Object.values(contract.upgradeability.facets).map(f => f.toString()),
...Object.values(contract.upgradeability.facets).map((f) =>
f.toString(),
),
)
break
case 'Arbitrum proxy':
case 'new Arbitrum proxy':
proxyFields.push({ name: 'admin', value: contract.upgradeability.admin.toString() })
proxyFields.push({
name: 'admin',
value: contract.upgradeability.admin.toString(),
})
implementations.push(
contract.upgradeability.userImplementation.toString(),
contract.upgradeability.adminImplementation.toString(),
Expand All @@ -149,7 +162,9 @@ function getProxyDetails(contract: ContractParameters): {
implementations.push(contract.upgradeability.implementation.toString())
break
case 'EIP2535 diamond proxy':
implementations.push(...contract.upgradeability.facets.map(f => f.toString()))
implementations.push(
...contract.upgradeability.facets.map((f) => f.toString()),
)
break
}

Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/src/view/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ function SidebarForSingleNode({
}

const humanReadableName = node.type === 'Contract' ? node.name : node.type
const etherscanLink = `https://etherscan.io/address/${node.data.address}`
const sourceLink = node.type === 'Contract' ? `https://etherscan.deth.net/address/${node.data.address}#code` : undefined
const etherscanLink = `https://etherscan.io/address/${node.data.address.toString()}`
const sourceLink =
node.type === 'Contract'
? `https://etherscan.deth.net/address/${node.data.address.toString()}#code`
: undefined

return (
<>
Expand Down

0 comments on commit 2be374a

Please sign in to comment.