aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-shared/src/ts/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/react-shared/src/ts/utils')
-rw-r--r--packages/react-shared/src/ts/utils/constants.ts14
-rw-r--r--packages/react-shared/src/ts/utils/utils.ts15
2 files changed, 29 insertions, 0 deletions
diff --git a/packages/react-shared/src/ts/utils/constants.ts b/packages/react-shared/src/ts/utils/constants.ts
index 79d1d9ca3..562ab776b 100644
--- a/packages/react-shared/src/ts/utils/constants.ts
+++ b/packages/react-shared/src/ts/utils/constants.ts
@@ -1,6 +1,20 @@
+import { Networks } from '../types';
+
export const constants = {
DOCS_SCROLL_DURATION_MS: 0,
DOCS_CONTAINER_ID: 'documentation',
SCROLL_CONTAINER_ID: 'documentation',
SCROLL_TOP_ID: 'pageScrollTop',
+ NETWORK_NAME_BY_ID: {
+ 1: Networks.Mainnet,
+ 3: Networks.Ropsten,
+ 4: Networks.Rinkeby,
+ 42: Networks.Kovan,
+ } as { [symbol: number]: string },
+ NETWORK_ID_BY_NAME: {
+ [Networks.Mainnet]: 1,
+ [Networks.Ropsten]: 3,
+ [Networks.Rinkeby]: 4,
+ [Networks.Kovan]: 42,
+ } as { [networkName: string]: number },
};
diff --git a/packages/react-shared/src/ts/utils/utils.ts b/packages/react-shared/src/ts/utils/utils.ts
index 7498342b6..0d2e045b8 100644
--- a/packages/react-shared/src/ts/utils/utils.ts
+++ b/packages/react-shared/src/ts/utils/utils.ts
@@ -1,6 +1,9 @@
+import isMobile = require('is-mobile');
import * as _ from 'lodash';
import { scroller } from 'react-scroll';
+import { EtherscanLinkSuffixes, Networks } from '../types';
+
import { constants } from './constants';
export const utils = {
@@ -19,6 +22,10 @@ export const utils = {
containerId,
});
},
+ isUserOnMobile(): boolean {
+ const isUserOnMobile = isMobile();
+ return isUserOnMobile;
+ },
getIdFromName(name: string) {
const id = name.replace(/ /g, '-');
return id;
@@ -29,4 +36,12 @@ export const utils = {
const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
return baseUrl;
},
+ getEtherScanLinkIfExists(addressOrTxHash: string, networkId: number, suffix: EtherscanLinkSuffixes): string {
+ const networkName = constants.NETWORK_NAME_BY_ID[networkId];
+ if (_.isUndefined(networkName)) {
+ return undefined;
+ }
+ const etherScanPrefix = networkName === Networks.Mainnet ? '' : `${networkName.toLowerCase()}.`;
+ return `https://${etherScanPrefix}etherscan.io/${suffix}/${addressOrTxHash}`;
+ },
};