add logic to support view on Blockscout

pull/5784/head^2
Joseph Izang 2 weeks ago committed by Aniket
parent e479939c1a
commit a6501f208a
  1. 23
      apps/remix-ide/src/blockchain/blockchain.tsx
  2. 13
      apps/remix-ide/src/blockchain/helper.ts

@ -10,7 +10,7 @@ import { VMProvider } from './providers/vm'
import { InjectedProvider } from './providers/injected'
import { NodeProvider } from './providers/node'
import { execution, EventManager, helpers } from '@remix-project/remix-lib'
import { etherScanLink } from './helper'
import { etherScanLink, getBlockScoutUrl } from './helper'
import { logBuilder, cancelUpgradeMsg, cancelProxyMsg, addressToString } from '@remix-ui/helper'
import { Provider } from '@remix-ui/environment-explorer'
@ -730,20 +730,35 @@ export class Blockchain extends Plugin {
)
web3Runner.event.register('transactionBroadcasted', (txhash) => {
this.executionContext.detectNetwork((error, network) => {
this.executionContext.detectNetwork(async (error, network) => {
if (error || !network) return
if (network.name === 'VM') return
const viewEtherScanLink = etherScanLink(network.name, txhash)
const viewBlockScoutLink = await getBlockScoutUrl(network.id, txhash)
if (viewEtherScanLink) {
if (viewBlockScoutLink) {
this.call(
'terminal',
'logHtml',
<div className="flex flex-row">
<a href={etherScanLink(network.name, txhash)} className="mr-3" target="_blank">
view on Etherscan
</a>
<a href={viewBlockScoutLink} target="_blank">
view on Blockscout
</a>
</div>
)
} else {
this.call(
'terminal',
'logHtml',
<a href={etherScanLink(network.name, txhash)} target="_blank">
view on etherscan
view on Etherscan
</a>
)
}
}
})
})
this.txRunner = new TxRunner(web3Runner, {})

@ -12,3 +12,16 @@ export function etherScanLink (network: string, hash: string): string {
return transactionDetailsLinks[network] + hash
}
}
/**
* Get the block scout url for a given chain id and tx hash
* @param chainId - The chain id
* @param txHash - The tx hash
* @returns The block scout url
*/
export async function getBlockScoutUrl(chainId: number, txHash: string) {
const chain = await fetch('https://raw.githubusercontent.com/blockscout/chainscout/refs/heads/main/data/chains.json')
const response = await chain.json()
const data = response[chainId]
return data ? `${data.explorers[0].url}/tx/${txHash}` : null
}

Loading…
Cancel
Save