From 877d9c3a5c6944244c81c1b0dabe66b5a2f31454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 25 May 2018 18:03:54 +0200 Subject: [PATCH] link to explorers for more coins --- src/components/modals/OperationDetails.js | 17 ++++++++++------- src/helpers/explorers.js | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/helpers/explorers.js diff --git a/src/components/modals/OperationDetails.js b/src/components/modals/OperationDetails.js index 5c3d8917..476d8b7a 100644 --- a/src/components/modals/OperationDetails.js +++ b/src/components/modals/OperationDetails.js @@ -7,6 +7,7 @@ import { translate } from 'react-i18next' import styled from 'styled-components' import moment from 'moment' import { getOperationAmountNumber } from '@ledgerhq/live-common/lib/helpers/operation' +import { getTxURL } from 'helpers/explorers' import type { Account, Operation } from '@ledgerhq/live-common/lib/types' import type { T, CurrencySettings } from 'types/common' @@ -69,12 +70,15 @@ type Props = { const OperationDetails = connect(mapStateToProps)((props: Props) => { const { t, onClose, operation, account, marketColor, currencySettings } = props - const { id, hash, date, senders, recipients, type } = operation + const { hash, date, senders, recipients, type } = operation const amount = getOperationAmountNumber(operation) const { name, unit, currency } = account const confirmations = operation.blockHeight ? account.blockHeight - operation.blockHeight : 0 const isConfirmed = confirmations >= currencySettings.confirmationsNb + + const url = getTxURL(account, operation) + return ( Operation details @@ -145,12 +149,11 @@ const OperationDetails = connect(mapStateToProps)((props: Props) => { - + {url ? ( + + ) : null} ) diff --git a/src/helpers/explorers.js b/src/helpers/explorers.js new file mode 100644 index 00000000..03d4abe8 --- /dev/null +++ b/src/helpers/explorers.js @@ -0,0 +1,18 @@ +// @flow +import type { Account, Operation } from '@ledgerhq/live-common/lib/types' + +const txExplorers: { [_: string]: (Operation) => string } = { + bitcoin_cash: op => `https://bitcoincash.blockexplorer.com/tx/${op.hash}`, + bitcoin_gold: op => `https://btgexplorer.com/tx/${op.hash}`, + bitcoin_testnet: op => `https://testnet.blockchain.info/tx/${op.hash}`, + bitcoin: op => `https://blockchain.info/tx/${op.hash}`, + ethereum_testnet: op => `https://ropsten.etherscan.io/tx/${op.hash}`, + ethereum: op => `https://etherscan.io/tx/${op.hash}`, + ripple: op => `https://bithomp.com/explorer/${op.hash}`, + zcash: op => `https://explorer.zcha.in/transactions/${op.hash}`, +} + +export const getTxURL = (account: Account, operation: Operation): ?string => { + const f = txExplorers[account.currency.id] + return f ? f(operation) : null +}