aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-shared
diff options
context:
space:
mode:
Diffstat (limited to 'packages/react-shared')
-rw-r--r--packages/react-shared/package.json1
-rw-r--r--packages/react-shared/src/ts/globals.d.ts6
-rw-r--r--packages/react-shared/src/ts/index.ts2
-rw-r--r--packages/react-shared/src/ts/types.ts12
-rw-r--r--packages/react-shared/src/ts/utils/constants.ts14
-rw-r--r--packages/react-shared/src/ts/utils/utils.ts15
6 files changed, 49 insertions, 1 deletions
diff --git a/packages/react-shared/package.json b/packages/react-shared/package.json
index e96659e47..4b9055e60 100644
--- a/packages/react-shared/package.json
+++ b/packages/react-shared/package.json
@@ -25,6 +25,7 @@
},
"dependencies": {
"basscss": "^8.0.3",
+ "is-mobile": "^0.2.2",
"material-ui": "^0.17.1",
"react": "15.6.1",
"react-dom": "15.6.1",
diff --git a/packages/react-shared/src/ts/globals.d.ts b/packages/react-shared/src/ts/globals.d.ts
index 875721533..9b0bcf845 100644
--- a/packages/react-shared/src/ts/globals.d.ts
+++ b/packages/react-shared/src/ts/globals.d.ts
@@ -1 +1,7 @@
declare module 'react-highlight';
+
+// is-mobile declarations
+declare function isMobile(): boolean;
+declare module 'is-mobile' {
+ export = isMobile;
+}
diff --git a/packages/react-shared/src/ts/index.ts b/packages/react-shared/src/ts/index.ts
index dde77b7b9..3b50c0117 100644
--- a/packages/react-shared/src/ts/index.ts
+++ b/packages/react-shared/src/ts/index.ts
@@ -5,7 +5,7 @@ export { MarkdownSection } from './components/markdown_section';
export { NestedSidebarMenu } from './components/nested_sidebar_menu';
export { SectionHeader } from './components/section_header';
-export { HeaderSizes, Styles, MenuSubsectionsBySection } from './types';
+export { HeaderSizes, Styles, MenuSubsectionsBySection, EtherscanLinkSuffixes, Networks } from './types';
export { utils } from './utils/utils';
export { constants } from './utils/constants';
diff --git a/packages/react-shared/src/ts/types.ts b/packages/react-shared/src/ts/types.ts
index f9d561d1a..88fadcc09 100644
--- a/packages/react-shared/src/ts/types.ts
+++ b/packages/react-shared/src/ts/types.ts
@@ -11,3 +11,15 @@ export enum HeaderSizes {
export interface MenuSubsectionsBySection {
[section: string]: string[];
}
+
+export enum EtherscanLinkSuffixes {
+ Address = 'address',
+ Tx = 'tx',
+}
+
+export enum Networks {
+ Mainnet = 'Mainnet',
+ Kovan = 'Kovan',
+ Ropsten = 'Ropsten',
+ Rinkeby = 'Rinkeby',
+}
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}`;
+ },
};