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

Use provider's chainId as default if present #8

Merged
merged 14 commits into from
Apr 14, 2022

Conversation

ramirotw
Copy link
Contributor

@ramirotw ramirotw commented Apr 6, 2022

Close #3

This improves how the chainId was handled due to the possibility of a mismatch between the chainId used in the constructor to instantiate the sdk and the provider's chainId:

// before
const provider = new ethers.providers.Web3Provider(window.ethereum, "any") // network is Mainnet
const chainId = 4;
const cowSdk = new CowSdk(chainId, { signer: provider.getSigner() })
// this will use Rinkeby as the chainId
// now
const provider = new ethers.providers.Web3Provider(window.ethereum, "any") // network is Mainnet
const chainId = 4;
const cowSdk = new CowSdk(chainId, { signer: provider.getSigner() })
// this will use Mainnet as the chainId

You can still instantiate the sdk without passing any signer just for querying purposes and also update the current chainId

const chainId = 1;
const cowSdk = new CowSdk(chainId)
const quoteResponse = await cowSdk.cowApi.getQuote({...}) // will query Mainnet
cowSdk.updateChainId(4)
const quoteResponse = await cowSdk.cowApi.getQuote({...}) // will query Rinkeby

The chainId getter/setter was moved to the Context and made it async.

@matextrem matextrem requested a review from alfetopito April 11, 2022 15:50
@ramirotw ramirotw changed the base branch from main to bugfix/export-bundle April 11, 2022 19:44
@github-actions
Copy link

github-actions bot commented Apr 11, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 13 0
Ignored 0 N/A
  • Result: ✅ success

  • Annotations: 13 total


[failure] @typescript-eslint/no-explicit-any


[failure] @typescript-eslint/no-non-null-assertion


Report generated by eslint-plus-action

Base automatically changed from bugfix/export-bundle to main April 12, 2022 14:45
Comment on lines 28 to 29
private context: CowContext
#chainId: ChainId
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for using TS private (private) for context and JS private (#) for chainId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch! when I updated the chainId accessor didn't change the context one. This was to enforce runtime access outside of TS

@matextrem matextrem mentioned this pull request Apr 12, 2022
@ramirotw ramirotw merged commit fd2b0ee into main Apr 14, 2022
@ramirotw ramirotw deleted the ramirotw/issue-12-chainid branch April 14, 2022 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve how chainId is handled
3 participants