Skip to content

Commit

Permalink
Feature/dao 195 polygon urls (#851)
Browse files Browse the repository at this point in the history
* add polygon scan urls

* bump version

* fix eslint

* remove provider from block explorer

* eslint fixed

* remove provider comment
  • Loading branch information
novaknole authored Aug 17, 2021
1 parent f846e0f commit 4b9f905
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aragon/ui",
"version": "1.7.0",
"version": "1.8.0",
"author": "Aragon Association <[email protected]>",
"license": "MIT",
"repository": "github:aragon/aragon-ui",
Expand Down
64 changes: 28 additions & 36 deletions src/utils/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,41 @@ const ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/
const TRUST_WALLET_BASE_URL =
'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum'

const ETHERSCAN_NETWORK_TYPES = new Map([
['main', ''],
['kovan', 'kovan.'],
['rinkeby', 'rinkeby.'],
['ropsten', 'ropsten.'],
['goerli', 'goerli.'],
const ETHERSCAN_URL = 'etherscan.io'
const POLYGON_URL = 'polygonscan.com'

const NETWORK_TYPES_URLS = new Map([
['main', ETHERSCAN_URL],
['kovan', `kovan.${ETHERSCAN_URL}`],
['rinkeby', `rinkeby.${ETHERSCAN_URL}`],
['ropsten', `ropsten.${ETHERSCAN_URL}`],
['goerli', `goerli.${ETHERSCAN_URL}`],
['matic', POLYGON_URL],
['mumbai', `mumbai.${POLYGON_URL}`],
])
const ETHERSCAN_TYPES = new Map([

const URL_TYPES = new Map([
['block', 'block'],
['transaction', 'tx'],
['address', 'address'],
['token', 'token'],
])

const BLOCK_EXPLORERS = {
etherscan: ({ type, value, networkType }) => {
if (networkType === 'private') {
return ''
}
function _getBlockExplorer({ type, value, networkType }) {
if (networkType === 'private') {
return ''
}

if (!ETHERSCAN_NETWORK_TYPES.has(networkType)) {
throw new Error('provider not supported.')
}
if (!ETHERSCAN_TYPES.has(type)) {
throw new Error('type not supported.')
}
if (!NETWORK_TYPES_URLS.has(networkType)) {
throw new Error('network type not supported.')
}
if (!URL_TYPES.has(type)) {
throw new Error('type not supported.')
}

const subdomain = ETHERSCAN_NETWORK_TYPES.get(networkType)
const typePart = ETHERSCAN_TYPES.get(type)
return `https://${subdomain}etherscan.io/${typePart}/${value}`
},
const subdomain = NETWORK_TYPES_URLS.get(networkType)
const typePart = URL_TYPES.get(type)
return `https://${subdomain}/${typePart}/${value}`
}

/**
Expand Down Expand Up @@ -155,23 +159,11 @@ export function isTransaction(transaction) {
* @param {string} value Identifier of the object, depending on the type (block number, transaction hash, …).
* @param {object} options The optional parameters.
* @param {string} options.networkType The Ethereum network type (main, kovan, rinkeby, ropsten, goerli, or private).
* @param {string} options.provider The explorer provider (e.g. etherscan).
* @returns {string} The generated URL, or an empty string if the parameters are invalid.
*/
export function blockExplorerUrl(
type,
value,
{ networkType = 'main', provider = 'etherscan' } = {}
) {
const explorer = BLOCK_EXPLORERS[provider]

if (!explorer) {
warn('blockExplorerUrl(): provider not supported.')
return ''
}

export function blockExplorerUrl(type, value, { networkType = 'main' } = {}) {
try {
return explorer({ type, value, networkType })
return _getBlockExplorer({ type, value, networkType })
} catch (err) {
warn(`blockExplorerUrl(): ${err.message}`)
return ''
Expand Down

0 comments on commit 4b9f905

Please sign in to comment.