diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-14 22:18:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 22:18:16 +0800 |
commit | e16feb27f4ec1987259a87f360824a0158bd8b10 (patch) | |
tree | e94cb3bc89e215c4df38ab161379023ab8e0c4e9 /packages/react-shared/src/utils/utils.ts | |
parent | 3f3e8be004818ddaa1921b3dff12bdd46052278b (diff) | |
parent | 83ae7ba08d55fa964bf7b7a985aea0fe1520c5c7 (diff) | |
download | dexon-0x-contracts-e16feb27f4ec1987259a87f360824a0158bd8b10.tar.gz dexon-0x-contracts-e16feb27f4ec1987259a87f360824a0158bd8b10.tar.zst dexon-0x-contracts-e16feb27f4ec1987259a87f360824a0158bd8b10.zip |
Merge pull request #450 from 0xProject/convertScriptsToTs
Convert Scripts to TS & Other Misc. Fixes
Diffstat (limited to 'packages/react-shared/src/utils/utils.ts')
-rw-r--r-- | packages/react-shared/src/utils/utils.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/react-shared/src/utils/utils.ts b/packages/react-shared/src/utils/utils.ts new file mode 100644 index 000000000..b3acb081e --- /dev/null +++ b/packages/react-shared/src/utils/utils.ts @@ -0,0 +1,45 @@ +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 = { + setUrlHash(anchorId: string) { + window.location.hash = anchorId; + }, + scrollToHash(hash: string, containerId: string): void { + let finalHash = hash; + if (_.isEmpty(hash)) { + finalHash = constants.SCROLL_TOP_ID; // scroll to the top + } + + scroller.scrollTo(finalHash, { + duration: 0, + offset: 0, + containerId, + }); + }, + isUserOnMobile(): boolean { + const isUserOnMobile = isMobile(); + return isUserOnMobile; + }, + getIdFromName(name: string) { + const id = name.replace(/ /g, '-'); + return id; + }, + getEtherScanLinkIfExists( + addressOrTxHash: string, + networkId: number, + suffix: EtherscanLinkSuffixes, + ): string | undefined { + 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}`; + }, +}; |