refactor etherscan.io links (#2896)

* use proper querystring builder

* etherscan.txLink helper

* refactor to etherscan.txLink

* etherscan.addressLink helper

* refactor to etherscan.addressLink

* move txLink & addressLink into common file
This commit is contained in:
Jannis Redmann
2016-10-30 09:37:15 +01:00
committed by Jaco Greeff
parent 222b2b70ea
commit 86c0dbeedc
12 changed files with 44 additions and 90 deletions

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { stringify } from 'qs';
const options = {
method: 'GET',
headers: {
@@ -23,19 +25,14 @@ const options = {
export function call (module, action, _params, test) {
const host = test ? 'testnet.etherscan.io' : 'api.etherscan.io';
let params = '';
if (_params) {
Object.keys(_params).map((param) => {
const value = _params[param];
const query = stringify(Object.assign({
module, action
}, _params || {}));
params = `${params}&${param}=${value}`;
});
}
return fetch(`http://${host}/api?module=${module}&action=${action}${params}`, options)
return fetch(`https://${host}/api?${query}`, options)
.then((response) => {
if (response.status !== 200) {
if (!response.ok) {
throw { code: response.status, message: response.statusText }; // eslint-disable-line
}

View File

@@ -16,10 +16,13 @@
import { account } from './account';
import { stats } from './stats';
import { txLink, addressLink } from './links';
const etherscan = {
account: account,
stats: stats
stats: stats,
txLink: txLink,
addressLink: addressLink
};
export default etherscan;

23
js/src/3rdparty/etherscan/links.js vendored Normal file
View File

@@ -0,0 +1,23 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
export const txLink = (hash, isTestnet = false) => {
return `https://${isTestnet ? 'testnet.' : ''}etherscan.io/tx/${hash}`;
};
export const addressLink = (address, isTestnet = false) => {
return `https://${isTestnet ? 'testnet.' : ''}etherscan.io/address/${address}`;
};