Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript @ts-ignore: window, navigator #3768

Merged
merged 8 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/common/web3connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ export default class Web3Connect extends EventEmitter {

getInjectedType() {
if (window && window.ethereum) {
//@ts-ignore
if (window.ethereum.isLiquality) return INJECTED_TYPE.LIQUALITY
//@ts-ignore
if (window.ethereum.isTrust) return INJECTED_TYPE.TRUST
// the keys in brackets because typescript shows an error
if (window.ethereum['isLiquality']) return INJECTED_TYPE.LIQUALITY
if (window.ethereum['isTrust']) return INJECTED_TYPE.TRUST
if (window.ethereum.isMetaMask) return INJECTED_TYPE.METAMASK
//@ts-ignore
if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) return INJECTED_TYPE.OPERA
if ((!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) return INJECTED_TYPE.OPERA

return INJECTED_TYPE.UNKNOWN
} else {
return INJECTED_TYPE.NONE
Expand Down Expand Up @@ -205,7 +204,6 @@ export default class Web3Connect extends EventEmitter {
// @ToDo - Hard fix walletconnect
// https://github.com/WalletConnect/walletconnect-monorepo/issues/384
if (window) {
//@ts-ignore
window.send = (e,t) => {
return _web3provider.send(e,t)
}
Expand Down
16 changes: 6 additions & 10 deletions src/common/web3connect/providers/InjectedProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ export default class InjectedProvider extends InjectedConnector {
}

async isConnected() {
//@ts-ignore
if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
if ((!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
// This is opera
//@ts-ignore
await window.ethereum.enable()
//@ts-ignore
return window.ethereum.isConnected()
// the keys in brackets because typescript shows an error
await window.ethereum['enable']()
return window.ethereum['isConnected']()
} else {
//@ts-ignore
if (window.ethereum.isTrust) {
//@ts-ignore
return window.ethereum.ready
if (window.ethereum['isTrust']) {
return window.ethereum['ready']
}
return await super.isAuthorized()
}
Expand Down
10 changes: 10 additions & 0 deletions src/front/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ declare module 'react' {
type?: string;
title?: any;
}
}

declare global {
interface Window {
[key: string]: any
Disti4ct marked this conversation as resolved.
Show resolved Hide resolved
}

interface Navigator {
[key: string]: any
}
}
14 changes: 3 additions & 11 deletions src/front/shared/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,10 @@ export default class Header extends Component<any, any> {

if (isWidgetBuild) {
if (
//@ts-ignore
window.widgetERC20Tokens &&
//@ts-ignore
Object.keys(window.widgetERC20Tokens).length
) {
// Multi token widget build
//@ts-ignore
Object.keys(window.widgetERC20Tokens).forEach((key) => {
widgetCurrencies.push(key.toUpperCase());
});
Expand Down Expand Up @@ -450,13 +447,12 @@ export default class Header extends Component<any, any> {
} = this.props;

const { exchange, wallet } = links;

const onLogoClickLink =
//@ts-ignore
window && window.LOGO_REDIRECT_LINK
//@ts-ignore
? window.LOGO_REDIRECT_LINK
: localisedUrl(locale, links.home);
//@ts-ignore

const hasOwnLogoLink = window && window.LOGO_REDIRECT_LINK;

const isWalletPage =
Expand All @@ -470,7 +466,6 @@ export default class Header extends Component<any, any> {
<img
styleName="otherHeaderLogo"
className="site-logo-header"
//@ts-ignore
src={isDark ? window.darkLogoUrl : window.logoUrl}
alt="logo"
/>
Expand All @@ -491,8 +486,6 @@ export default class Header extends Component<any, any> {
</>
:
<div styleName="flexebleHeader">
{/*
//@ts-ignore */}
{window.logoUrl !== "#" && (
<div styleName="imgWrapper">
{hasOwnLogoLink ? (
Expand Down Expand Up @@ -520,7 +513,7 @@ export default class Header extends Component<any, any> {
declineRequest={this.declineRequest}
/>
)
//@ts-ignore

if (isMobile && window.logoUrl) {
return (
<header className="data-tut-widget-tourFinish" id="header-mobile" styleName="header-mobile">
Expand Down Expand Up @@ -583,7 +576,6 @@ export default class Header extends Component<any, any> {
<header
className={cx({
[styles["header"]]: true,
//@ts-ignore
[styles["widgetHeader"]]: isWidgetBuild && window.logoUrl !== "#",
[styles["header-fixed"]]: Boolean(sticky),
[styles["header-promo"]]: isWalletPage && !sticky,
Expand Down
1 change: 0 additions & 1 deletion src/front/shared/components/Header/WidgetHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const WidgetHeaderComponent = ({ intl }) => {
}

return (
//@ts-ignore
window.isUserRegisteredAndLoggedIn &&
<div styleName={`exitArea ${isDark ? 'dark' : ''}`} onClick={handleConfirmToggle}>
{/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class WidgetWalletTour extends Component<any, any> {
content: <FormattedMessage
id="widget-tour-step-1"
defaultMessage="Welcome to {widgetName}. Take the tour?"
//@ts-ignore
values={{ widgetName: window.widgetName }}
/>,
placement: 'center',
Expand Down
4 changes: 0 additions & 4 deletions src/front/shared/components/Logo/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ export default class Logo extends Component<any, any> {
isExchange
} = this.props;

//@ts-ignore
const isNoLogo = !(window.logoUrl === `#`)

const srcFiles = isColored ? images.colored : images.common;
const { host, href } = window.location;
const file = Object.keys(srcFiles).find(el => window.location.href.includes(el)) || "base"
//@ts-ignore
const onLogoClickLink = (window && window.LOGO_REDIRECT_LINK) ? window.LOGO_REDIRECT_LINK : localisedUrl(locale, links.home)
//@ts-ignore
const hasOwnLogoLink = (window && window.LOGO_REDIRECT_LINK)

const imgNode = React.createElement("img", {
Expand Down Expand Up @@ -76,7 +73,6 @@ export default class Logo extends Component<any, any> {
) : (
<div>
{isNoLogo && (
//@ts-ignore
<img styleName="otherLogoBrand" className="site-logo" src={window.logoUrl} alt="Wallet" />
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default class PreventMultiTabs extends Component<any, any> {
<FormattedMessage
id="PreventMultiTabsWidgetBuild"
defaultMessage="{widgetName} supports only one active tab. Please close the other open window and refresh to continue."
//@ts-ignore
values={{ widgetName: window.widgetName || 'Atomic Swap Widget' }}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,10 @@ const NewDesignLayout = (props) => {
widgetCurrencies.push('ETH')
if (isWidgetBuild) {
if (
//@ts-ignore
window.widgetERC20Tokens &&
//@ts-ignore
Object.keys(window.widgetERC20Tokens).length
) {
// Multi token widget build
//@ts-ignore
Object.keys(window.widgetERC20Tokens).forEach((key) => {
widgetCurrencies.push(key.toUpperCase())
})
Expand Down Expand Up @@ -145,14 +142,10 @@ const NewDesignLayout = (props) => {

return (
<article className="data-tut-start-widget-tour">
{/*
//@ts-ignore*/}
{window.CUSTOM_LOGO && (
//@ts-ignore
<img className="cutomLogo" src={window.CUSTOM_LOGO} alt="logo" />
)}
<section
//@ts-ignore
styleName={`wallet ${window.CUSTOM_LOGO ? 'hasCusomLogo' : ''} ${isDark ? 'dark' : ''}`}
>
<div
Expand Down Expand Up @@ -240,21 +233,16 @@ export default connect(
}) => {
let widgetMultiTokens = []
if (
//@ts-ignore
window.widgetERC20Tokens &&
//@ts-ignore
Object.keys(window.widgetERC20Tokens).length
) {
//@ts-ignore
Object.keys(window.widgetERC20Tokens).forEach((key) => {
widgetMultiTokens.push(key.toUpperCase())
})
}
const tokens =
config && config.isWidget
//@ts-ignore
? window.widgetERC20Tokens &&
//@ts-ignore
Object.keys(window.widgetERC20Tokens).length
? widgetMultiTokens
: [config.erc20token.toUpperCase()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { withRouter } from 'react-router-dom'

class ScrollToTop extends Component<any, any> {
componentDidUpdate(prevProps) {
//@ts-ignore
if (this.props.location.pathname !== prevProps.location.pathname) {
window.scrollTo(0, 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ export default class AddOffer extends Component<any, any> {
super()

if (config && config.isWidget) {
//@ts-ignore
if (window.widgetERC20Tokens && Object.keys(window.widgetERC20Tokens).length) {
//@ts-ignore
Object.keys(window.widgetERC20Tokens).forEach((key) => {
minAmountOffer[key] = 1
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default class RegisterSMSProtected extends React.Component<any, any> {

this.state = {
version,
//@ts-ignore
phone: window.DefaultCountryCode || '',
step,
error: false,
Expand Down
3 changes: 1 addition & 2 deletions src/front/shared/components/modals/Share/Share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ export default class Share extends Component<any, any> {

componentDidMount = () => {
const { props: { data: { link, title } } } = this
//@ts-ignore

if (navigator.share) {
//@ts-ignore
navigator.share({
title: title,
url: link
Expand Down
7 changes: 1 addition & 6 deletions src/front/shared/containers/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import metamask from 'helpers/metamask'
const memdown = require("memdown");


//@ts-ignore
const userLanguage = (navigator.userLanguage || navigator.language || "en-gb").split("-")[0];
moment.locale(userLanguage)

Expand Down Expand Up @@ -309,7 +308,6 @@ class App extends React.Component<RouteComponentProps<any>, any> {
this.processMetamask()

this.checkIfDashboardModalsAllowed()
//@ts-ignore
window.actions = actions;

window.onerror = error => {
Expand All @@ -319,19 +317,16 @@ class App extends React.Component<RouteComponentProps<any>, any> {
try {
const db = indexedDB.open("test");
db.onerror = () => {
//@ts-ignore
window.leveldown = memdown;
};
} catch (e) {
//@ts-ignore
window.leveldown = memdown;
}

actions.user.sign();
await createSwapApp();
//@ts-ignore

this.setState(() => ({ fetching: true }));
//@ts-ignore
window.prerenderReady = true;

const appInstalled = (e) => {
Expand Down
2 changes: 0 additions & 2 deletions src/front/shared/helpers/constants/TRADE_TICKERS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ Object.keys(config.erc20)

if (config && config.isWidget) {
swap.length = 0
//@ts-ignore
if (window.widgetERC20Tokens && Object.keys(window.widgetERC20Tokens).length) {
//@ts-ignore
Object.keys(window.widgetERC20Tokens).forEach((key) => {
swap.push(`${key.toUpperCase()}-BTC`)
if (!config.opts.curEnabled || config.opts.curEnabled.ghost) swap.push(`${key.toUpperCase()}-GHOST`)
Expand Down
Loading