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

Adding Competition Solver tab to settlements page #590

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b67c3b1
create the SolverCompetition screen
vicebas Aug 7, 2023
c0c8fdf
update Design
vicebas Aug 8, 2023
27605de
update Design
vicebas Aug 8, 2023
b083b62
update Design
vicebas Aug 8, 2023
439a82b
update Design
vicebas Aug 8, 2023
1b938a4
update Design
vicebas Aug 8, 2023
1dad41b
update Design
vicebas Aug 8, 2023
857783f
Create Clearing Prices
vicebas Aug 9, 2023
63c6676
Create Clearing Prices
vicebas Aug 9, 2023
56f76c6
Fixes on the description screen
vicebas Aug 9, 2023
d655359
add cache to Erc20
vicebas Aug 10, 2023
616ebae
add mobile capacities
vicebas Aug 11, 2023
84eae43
fix solutions prices and executed orders
vicebas Aug 14, 2023
a9d0509
fix small issues
vicebas Aug 16, 2023
e450c8a
fix formatting issues
vicebas Aug 16, 2023
5d6362a
avatar boring colors
vicebas Aug 16, 2023
08bb57e
fix prices issues
vicebas Aug 17, 2023
a5efe4a
Update webpack.config.js
0xaaiden Aug 17, 2023
9647448
Merge branch 'cowprotocol:develop' into feature/transactionScreens
0xaaiden Aug 17, 2023
20685c5
fix prices issues with decimals
vicebas Aug 17, 2023
3a26f19
Changes in display + tooltip info
Aug 18, 2023
4640729
Changes in display + tooltip info
Aug 18, 2023
4ff36d0
Change staging API back to barn
Aug 18, 2023
4b87d3c
fix native token per network
vicebas Aug 23, 2023
3782e0b
fix native token per network
vicebas Aug 23, 2023
8b22c10
add blockchain check before loading solvers
vicebas Aug 24, 2023
0a2da0b
add blockchain check before loading solvers
vicebas Aug 24, 2023
5f05d1b
Update webpack.config.js to redirect staging api to use prod endpoint…
0xaaiden Aug 24, 2023
ef5ceca
add blockchain check before loading solvers
vicebas Aug 24, 2023
9594f68
add blockchain check before loading solvers
vicebas Aug 24, 2023
657e099
change api being used to get currentBlock
vicebas Aug 25, 2023
7a3a8bb
change api being used to get currentBlock
vicebas Aug 25, 2023
2a761b6
Update webpack.config.js
0xaaiden Aug 25, 2023
6d9e2e2
undo webpack changes
vicebas Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/api/currentblock/currentBlockchainApi.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not needed, the blocknumber can be fetched from the chain using the web3 api

const web3 = createWeb3Api()

Just call web3.eth.getBlockNumber() https://docs.web3js.org/api/web3-eth/function/getBlockNumber/

You could add the blocknumber to the global state and have an updater running every ~15s.
Or have a more "local" state and instantiate the updater only when needed, which is when the tx details page is loaded & the block difference is < 65.

I'm going too far with ideas, I'll let you take your pick or propose something else.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made as advertised, just trying to keep it simple and clear

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import BigNumber from 'bignumber.js'

const ETH_BLOCKCHAIN_URL = 'https://api.blockcypher.com/v1/eth/main'
const XDAI_BLOCKCHAIN_URL = 'https://gnosis.blockscout.com/api/v2/stats'

type ETHCurrentBlock = {
name: string
height: number
hash: string
time: Date
latest_url: string
previous_hash: string
previous_url: string
peer_count: number
unconfirmed_count: number
high_gas_price: BigNumber
medium_gas_price: BigNumber
low_gas_price: BigNumber
high_priority_fee: BigNumber
medium_priority_fee: BigNumber
low_priority_fee: BigNumber
base_fee: BigNumber
last_fork_height: BigNumber
last_fork_hash: string
}

export interface XDAICurrentBlock {
average_block_time: number
coin_price: string
gas_prices: GasPrices
gas_used_today: BigNumber
market_cap: string
network_utilization_percentage: number
static_gas_price: BigNumber
total_addresses: BigNumber
total_blocks: number
total_gas_used: BigNumber
total_transactions: BigNumber
transactions_today: BigNumber
}

export interface GasPrices {
average: number
fast: number
slow: number
}
export interface CurrentBlockAPI {
getETHCurrentBlock(): Promise<ETHCurrentBlock>
getXDaiCurrentBlock(): Promise<XDAICurrentBlock>
}

export class CurrentBlockApiImpl {
public async getETHCurrentBlock(): Promise<ETHCurrentBlock> {
const response = await fetch(ETH_BLOCKCHAIN_URL, {
method: 'GET',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
},
})
return response.json()
}

public async getXDaiCurrentBlock(): Promise<XDAICurrentBlock> {
const response = await fetch(XDAI_BLOCKCHAIN_URL, {
method: 'GET',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
},
})
return response.json()
}
}
8 changes: 8 additions & 0 deletions src/api/currentblock/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CurrentBlockAPI } from 'api/currentblock/currentBlockchainApi'
import { CurrentBlockApiProxy } from 'api/currentblock/currentBlockApiProxy'

export function createCurrentBlockchainAPI(): CurrentBlockAPI {
const CurrentBlockApi: CurrentBlockAPI = new CurrentBlockApiProxy()
window['CurrentBlockAPI'] = CurrentBlockApi
return CurrentBlockApi
}
23 changes: 22 additions & 1 deletion src/components/transaction/SolverCompetition/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { abbreviateString } from 'utils'
import { LinkWithPrefixNetwork } from 'components/common/LinkWithPrefixNetwork'
import ClearingPrices from './ClearingPrices'
import { Title } from 'apps/explorer/pages/styled'
import { useCurrentBlock } from 'hooks/useCurrentBlock'
import { useTransactionData } from 'hooks/useTransactionData'

interface SolverCompetitionParams {
txHash: string
Expand All @@ -34,10 +36,29 @@ const StatusIcon = ({ type }: StatusType): JSX.Element => {
}

export function SolverCompetition(params: SolverCompetitionParams): JSX.Element {
const { networkId, txHash } = params
const { isLoading, currentBlock } = useCurrentBlock()
const { isLoading: isLoadingTransactionData, trace } = useTransactionData(networkId, txHash)
if (isLoading || isLoadingTransactionData || !currentBlock) {
return (
<EmptyItemWrapper>
<CowLoading />
</EmptyItemWrapper>
)
}
if (!trace?.block_number || (trace?.block_number && trace?.block_number + 65 < currentBlock)) {
return (
<EmptyItemWrapper>
<p>Data not available yet</p>
</EmptyItemWrapper>
)
}
return <SolverCompetitionElement {...params} />
}
export function SolverCompetitionElement(params: SolverCompetitionParams): JSX.Element {
const { networkId, txHash, orders } = params
const { data, isLoading, error } = useGetSolverCompetition(txHash, networkId)

console.log(orders)
const onCopy = (label: string): void =>
sendEvent({
category: 'Transaction Solve Competition screen',
Expand Down
33 changes: 33 additions & 0 deletions src/hooks/useCurrentBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useNetworkId } from 'state/network'
import { useEffect, useState } from 'react'
import { NATIVE_TOKEN_PER_NETWORK, XDAI } from 'const'
import { createCurrentBlockchainAPI } from 'api/currentblock'

export const useCurrentBlock = (): { isLoading: boolean; currentBlock: number | void | undefined } => {
const network = useNetworkId() || undefined
const [isLoading, setLoading] = useState<boolean>(false)
const [currentBlock, setCurrentBlock] = useState<number | void>()
const currentBlockApi = createCurrentBlockchainAPI()

useEffect(() => {
async function getCurrentBlock(): Promise<void> {
if (network) {
setLoading(true)
try {
if (NATIVE_TOKEN_PER_NETWORK[network] == XDAI) {
const response = await currentBlockApi.getXDaiCurrentBlock()
setCurrentBlock(response.total_blocks)
} else {
const response = await currentBlockApi.getETHCurrentBlock()
setCurrentBlock(response.height)
}
} finally {
setLoading(false)
}
}
}
getCurrentBlock()
}, [network])

return { isLoading, currentBlock }
}
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const baseUrl = isProduction ? '' : '/'

// FIXME: The apps right now depend on config they don't, se below attempt to check what was required. One example of something that is required but we don't need is --> for some reason "createTheGraphApi" it's being executed
const CONFIG = loadConfig()

const config = overrideEnvConfig(CONFIG)
const EXPLORER_APP = {
name: 'explorer',
Expand Down