-
Notifications
You must be signed in to change notification settings - Fork 824
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 config file for network and other configuration #231
Conversation
packages/nextjs/scaffold.config.ts
Outdated
pollingInterval: number; | ||
}; | ||
|
||
const ScaffoldConfig: TScaffoldConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should settle on a styleguide and apply it on the whole project (I like google's styleguide as a good starting point).
That means here we'd follow default naming convention and make the const lowerCamelCase
.
As for the type, I think the convention should be to not prefix or suffix it and use regular UpperCamelCase
, since typescript itself already contains the info about what kind of type it is (https://google.github.io/styleguide/tsguide.html#naming-style).
Prefixes should, in my opinion, be reserved for generic types, to mark a clear distinction between defined types and generics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm up for a having a styleguide.
Besides applying it here, we should create an issue an for it, discuss what guidelines we want to follow..... and make a PR refactoring all the names / types / etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an issue about it 👍
const chainNames = Object.keys(chains); | ||
|
||
const targetChainArr = chainNames.filter(chainName => { | ||
const wagmiChain = chains[chainName as keyof typeof chains]; | ||
return wagmiChain.id === chainId; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An idea (without testing it 👼 ).
What if we make the argument network
to be wagmi's Chain
? So we don't need to do this conversion.
In the transactor, we could get the connected network with wagmi's useNetwork()
(and maybe throw an error / return if the signer is on a different network)
// useTransactor
const { chain } = useNetwork();
// check that network.chainId === chain.id => if not, error / return
getBlockExplorerTxLink(chain, ...)
Since we are using wagmi's Chains as source of truth, maybe we should rely on them whenever we can? Instead of using internal ethers/providers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup makes sense, lol even I was a bit uncomfortable while writing the conversion,
What if we make the argument network to be wagmi's Chain? So we don't need to do this conversion.
This is a great idea but the problem is useTransactor
accepts custom signer
too and the reason we are relying on the signers network
is that :
NITPICK: There might a case where people pass in the custom signer without connecting their wallet and in that case useNetwork
and signer network
will be different and might cause some inconsistency, we are using similar pattern in Faucet.jsx
.
Again the above NITPICK is a very rare case.
Will try exploring some more alternatives 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Shiv, good point!!
After pulling the threads on this, some notes:
- The only instance where we are passing a custom signer, is for the hardhat faucet (where we want to send funds from a hardhat account with funds). Can we think about other use case? Since we are in the front-end, 99.99% of the times we'll want to use the connected signer (besides the faucet, and maybe a exotic build where we do deterministic private key derivation or something)
getBlockExplorerTxLink
doesn't return anything for the local chain (the only instance where we are using a custom signer for the transactor 🤔 )getLocalProvider
is only used in the Faucet stuff. Could be an unneeded early abstraction.- Maybe an util like
getChainFromChainId
that returns a wagmi Chain for a given Id?
In any case, no need to make any updates rn!! just thinking out loud and pointing out some possible inconsistencies. Maybe we made some past decisions that could use some refactors for the sake of consistency / simplicity / better DX.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tysm everything makes sense !!
Maybe we made some past decisions that could use some refactors for the sake of consistency / simplicity / better DX
+++
Small updateMoved btw I came across some patterns where people have created Will mark this PR as |
I'm used to those types of config files being at the root of their package, that's where I would generally look for them, so it doesn't bother me personally. Do you know if all config files will play nice if they're not at the root of a package (e.g. |
scaffold.config.ts
Outdated
targetNetwork: chain.Chain; | ||
pollingInterval: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this are tabs
@@ -15,7 +15,8 @@ | |||
"jsx": "preserve", | |||
"incremental": true, | |||
"paths": { | |||
"~~/*": ["./*"] | |||
"~~/*": ["./*"], | |||
"@root/*": ["../../*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes !! encountered the same problem, don't know for some reason it was working but I am sure i am missing some configuration, working on it
This is great! I think having an unique config file it's more dx friendly. A few thoughts/questions:
const scaffoldConfig: ScaffoldConfig = {
targetNetwork: chain.hardhat,
pollingInterval: 30000,
deployerdPrivateKey: process.env.DEPLOYER_PRIVATE_KEY
} as const; I think we'll just need the dotenv package on the root. Handling all the config & env vars in the root seems more friendly. I think it will work on Vercel when manually defining the env vars in their UI. This is just me thinking out loud, would love to hear your view on it.
Since this is a monorepo with two packages, it also doesn't bother me having separate config files. But I've also seen monorepos with a shared (or config) directory.. I guess it's an alternative to having everything shared in the root (when is too bloated). It's definitely something that we should explore, but maybe in the future / another PR? This PR is already a big refactor. |
EditFound a way to solve vercel deployments, updating it ... UpdateNow The way the front end was deployed previously is changed. Since we are utilizing Previously we were uploading the whole source code to Now, the flow is: first you need to build locally and then publish only I have create script alias which will do it : Approaches explored :Although using a
checkout this disccusion / comment => vercel/next.js#32192 (comment) And this issue: vercel/next.js#20374 why there are problems.
I tried comparing build size of both approaches and they came to be same :
Some thoughts :
Regarding putting People seem to use cehkcout -> https://stackoverflow.com/questions/69259896/set-environment-variables-outside-of-pages-dir-in-nextjs PS : the above stackoverflow links were picked from differnt next js issues I think maybe we can keep our api key's as hardcoded in Also I saw one pattern where env's were managed in cc @carletex @rin-st @sverps please feel free to suggest other approaches/suggestions happy to give it another try, I am sure I might have missed something 🙌 |
Hey @technophile-04 Thank you for this and your detailed explanation. Super helpful! I feel that this got out of hand: my fault for suggesting the root config file haha. But we had to explore it and see what the issues were. I still feel that we want to aim for it, but let's do it in a more iterative / incremental way. Proposal Since the most important reason for this was to enable #202, I think we should go with the simple approach for now, and keep exploring the root / shared stuff for the monorepo. Let's create a config file only for Next (replacing the .env.* files). This way we won't have any issues with Vercel are the changes will be minimal. What do you think? Thank you Shiv! |
In the latest commit 4c4e4a6 now deployments are back to normal and no need to prebuilt stuff as mentioned here #231 (comment) but just a very small catch 🙃 : Although this is one time config, you need to mention the path to Reason :Since we using monorepo, vercel offically suggests to invoke Checkout Vercel docs monorepo FAQ -> https://vercel.com/docs/concepts/monorepos Now the flow for the target network is :
Just doing Flow for configuring env's :How env's works remain the same as the What's changed? Also removed .env.* from frontend since all handled by reason: It's now saying that TODO :
Happy to handle them both in different PRs, since this is already big and don't want us blocking on #202 🙌 |
}, | ||
"packageManager": "yarn@3.2.3", | ||
"devDependencies": { | ||
"@types/node": "^18.15.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we really need it? It seems everything works without it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tysm !! yes yes we can remove it, it was added here 8f19b21 and since now we are not using .env
at root we can completely remove it
// If not set, it uses the hardhat account 0 private key. | ||
const deployerPrivateKey = | ||
process.env.DEPLOYER_PRIVATE_KEY ?? "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; | ||
const deployerPrivateKey = process.env.DEPLOYER_PRIVATE_KEY ?? scaffoldConfig.deployerPrivateKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nitpick: above and below we use ||
, so probably it's better to use it here too
@@ -9,6 +9,7 @@ const nextConfig = { | |||
eslint: { | |||
ignoreDuringBuilds: process.env.NEXT_PUBLIC_IGNORE_BUILD_ERROR === "true", | |||
}, | |||
transpilePackages: ["se-2"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain please, why we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you look at #231 (comment) in the section
Approaches explored :
2.
TLDR;
Since we have scaffold.config.ts
outside the nextjs
directory if you don't pass in this it gives this error -> #231 (comment)
The reason I have put se-2
there is because we had scaffold.config.ts
at se-2
workspace and needed to transpile it during next
build :
Although would highly recommend giving a quick read of the section Approaches explored
especially the links mentioned in that section 🙌
Also would love to hear if there are any alternatives / suggestions 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! ❤️ You've done such a big research, it's hard even to understand everything at first sight :D
Great job, @technophile-04 ! Sorry for the delays in comments, sometimes I suddenly need to go 🤷♂️ |
Great job @technophile-04 I think we are not far, but still doesn't feel 100% right to me. 1. Vercel root directoryIt might be like a little thing, but for me, it decreases the deploy experience by a bunch. I tried to search for options for the CLI / vercel.json config file, but it doesn't seem that you can provide a default Not sure what we could try. 2. .env vars
I think we need .env vars for secrets. Answer 1 const scaffoldConfig: ScaffoldConfig = {
// ....
deployerPrivateKey:
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
// ..
} as const; and then I think it should be: const scaffoldConfig: ScaffoldConfig = {
// ....
deployerPrivateKey: process.env.deployerPrivateKey ||
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
// ..
} as const; So people can create a And make sure people understand that they should never use Maybe we could pass the secrets/env vars like this to Vercel: If people create/update an env var from the Vercel UI, they will take effect if they rebuild (they are being used on the scaffold.config.file)? Answer 2 Use
This way we don't mix config & secret env vars... and things might be simpler.
This is not a big deal for now. We could create an issue for that refactor. Definitely having a root config file makes things a bit more complicated. I'll be up for it if we find a nice balance. But #231 (comment) is still on my mind. Thoughts? |
Tysm all for the review !! 🙌
Lol yes !, even I have this feeling it doesn't feel 100% right I have made #246 which has config in I plan to explore more on putting Marking this as a draft, Thanks 🙌 |
I have created a discussion on Vercel for Pt.1 of #231 (comment) -> https://github.com/orgs/vercel/discussions/2145 Closing this for now, since not under active development and until SE-2 cli is up |
Fixes #230