Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

chore: add typings to snxjs #485

Merged
merged 1 commit into from
Aug 5, 2020
Merged

chore: add typings to snxjs #485

merged 1 commit into from
Aug 5, 2020

Conversation

evgenyboxer
Copy link
Contributor

@evgenyboxer evgenyboxer commented Aug 5, 2020

These are some of the changes I ported from #448

  • Converted snxjsconnector.js -> .ts
  • Converted networkUtils -> .ts

Added stronger typing around NetworkId, and initial typings for SynthetixJS contracts.

@vercel
Copy link

vercel bot commented Aug 5, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/synthetixio/synthetix-exchange/au4xvmeau
✅ Preview: https://synthetix-exchange-git-chore-snxjs-typings.synthetixio.vercel.app

@@ -1,16 +1,14 @@
import throttle from 'lodash/throttle';

export type NetworkId = 1 | 3 | 4 | 42;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now its easier to match for networkId, its not just a "number", rather it must be this ^

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also make it an enum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where the name points to the number

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe supported networks is just an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's grab it from snxjs when its there... agree, can be an enum.


export const defaultNetwork = { name: 'MAINNET', networkId: 1 };
export const defaultNetwork: { name: string; networkId: NetworkId } = {
name: 'MAINNET',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should prob have an enum for the names here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah all of that stuff should be in the snxjs lib

gasPrice: number | null,
gasLimit: number | null,
ethPrice: number | null
) => {
if (!gasPrice || !gasLimit || !ethPrice) return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should prob say gasPrice == null || gasLimit == null || ethPrice == null since it is either going to be null or a number. What if gasPrice is 0 though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually didn't want to touch the actual logic since it worked, just added the types here. Falsy values should be fine here! 0,null,etc...all good - and if one of them is falsy, it should return 0. Because, the formula is

(gasPrice * ethPrice * gasLimit) / GWEI_UNIT

if (!window.ethereum) return;
const listener = throttle(cb, 1000);
window.ethereum.on('networkChanged', listener);
}

export const isMainNet = (networkId) => networkId === SUPPORTED_NETWORKS.MAINNET;
export const isMainNet = (networkId: NetworkId) => networkId === 1;
Copy link

@dvd-schwrtz dvd-schwrtz Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to have Networks as an enum to make equality checks easier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to replace this when we switch to the new library (which has the networks, etc)

@evgenyboxer evgenyboxer merged commit b818770 into dev Aug 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants