-
Notifications
You must be signed in to change notification settings - Fork 2
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
Steps of stake #105
Steps of stake #105
Conversation
SpinnerProps as ChakraSpinnerProps, | ||
} from "@chakra-ui/react" | ||
|
||
export default function Spinner({ ...spinnerProps }: ChakraSpinnerProps) { |
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.
Do we want the Spinner
component? It seems to do nothing more than a chakra spinner, so in my opinion, we can use ChakraSpinner and let's create modalSpinnerSpeed
const to keep the speed of the spinner for all modals.
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.
In the future, we would like to create a library of components. For this reason, I have saved the default value of speed here. This allows us to easily determine the default speed of our spinner. Styleguide is still not fully ready therefore I would leave it as it is at this moment. I'm waiting for Sorin's opinion if something changes I will remove this component.
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.
Sorin confirmed that each Spinner should have the same speed.
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.
In a case when we have a plan to create a library of components(what chakra-ui is in itself) let's deal with it when there will be a requirement. Currently, such a wrapper adds an unnecessary layer of logic. In my opinion, it is more convenient to use the built-in chakra components and not wonder if we have any of our own, especially since we do not completely change the logic. We can add just a chakra-ui style variant to keep styling and to keep the spinner speed value as I mentioned above we should create just a modalSpinnerSpeed constant.
@r-czajkowski what do you think?
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.
In this case, every time we use the spinner we have to remember to set the correct speed. I think that setting a constant speed in a shared component simplifies working with it. But I'm open to suggestions and understand your point of view.
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.
In my opinion, extracting to const is more complicated than creating a wrapper. Where should we keep this const? const means it is something shared(at least for me) but in this case is strictly related to the spinner and currently, any component and our logic don't care about the spinner speed. Looks like it should be hidden under the Spiner
component implementation.
Another option is creating a semantic token with this value and using it directly as we did for header height see semanticTokens.ts
file.
import {
Spinner
} from "@chakra-ui/react"
function MyComponent () {
return (
<>
...
<Spinner speed="<semantic-token-here>" />
...
</>
)
}
We can also try to override the spinner style and force the animation speed but probably we will have to use !important
which will be probably a huge pain in future development.
I see a big advantage in using a wrapper - e.g let's say we want to add an icon inside a spinner - we update only in one place and all spinners look the same.
So to sum up I'm ok with this wrapper but also understand Piotr and using const is also OK. I think there is no one good approach. But I would choose wrapper.
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.
Summary
Let's stay with the wrapper at this moment. To avoid adding a constant speed for each spinner. However, depending on the feature changes, we can update this.
const { ethAccount } = useWalletContext() | ||
const { signMessage, signature } = useSignMessageLedgerLive() | ||
|
||
useEffect(() => { |
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.
Generally, I recommend to use a named function instead of using the anonymous arrow function in useEffect we can in an easy way without effort write self-documenting code, eg:
useEffect(function signMessageSucces(){
...
})
Thanks to this, if new useEffect
hooks appear, we will know exactly what they are responsible for.
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.
Can we add a prefer-arrow-callback
rule for eslint? Naming effect functions in this way will make code management much easier in the future.
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.
It's a common pattern to use arrow functions in hooks and to be honest, I like it and I have never seen named function approach before. Usually useEffect
callbacks aren't too complicated(and probably shouldn't be) and are easy to read. It is also a common pattern to create a function inside effect with a self-explanatory name eg:
useEffect(() => {
const fetchSomething = async () => {
...
}
fetchSomething()
})
Or we can hoist the complicated functions outside the component eg. to shared utils with a good name and use it in the hook.
So I'm arrow function team 😆 but ofc we can update the rule if we all agree on that.
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 would also prefer to stay with what is there. As Rafał mentioned we can use the above pattern. So let's not exclude this rule.
dapp/src/theme/Spinner.ts
Outdated
borderLeftColor: "gold.400", | ||
}) | ||
|
||
const Spinner = defineStyleConfig({ baseStyle }) |
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.
const Spinner = defineStyleConfig({ baseStyle }) | |
const SpinnerStyle = defineStyleConfig({ baseStyle }) |
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.
dapp/src/theme/Spinner.ts
Outdated
|
||
const Spinner = defineStyleConfig({ baseStyle }) | ||
|
||
export default Spinner |
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.
export default Spinner | |
export default SpinnerStyle |
Let's avoid the same export name in other files ([src/components/shared/Spinner/index.tsx] exports also Spinner)
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, you're right. Actually, a more precise name is spinnerTheme
. Also, I think we should not use the default export in this case. This is a residue of our eslint rule which has been disabled. Let me know what you guys think.
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 created a separate task for this to not lose the topic. #139 Depending on what we decide I will update the task and add it to our task list to correct these imports.
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.
Let's use the same pattern as chakra so:
export const <component>Theme = {...}
or
const <component>Theme = {...}
export default <component>Theme
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.
Summary
Let's organize the imports by chakra pattern. It will be done in #139
|
||
function StakingSteps() { | ||
const { activeStep, goNext } = useModalFlowContext() | ||
function Staking() { |
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.
Let's keep with StakingStep
or ActiveStakingStep
, this name is more precise - shows what it returns.
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.
<ChakraAlert status={status} {...alertProps}> | ||
{withIcon && <AlertIcon as={status ? ICONS[status] : undefined} />} | ||
<ChakraAlert status={status} {...paddingRight} {...alertProps}> | ||
{withAlertIcon && <AlertIcon as={status ? ICONS[status] : undefined} />} |
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.
{withAlertIcon && <AlertIcon as={status ? ICONS[status] : undefined} />} | |
{withAlertIcon && status && <AlertIcon as={ICONS[status]} />} |
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 wonder if it is definitely what we want. 🤔 But that's fine we can change it and possibly update it when needed.
Previously, one of eslint's rules was to use default imports. However, we excluded this rule. Let's make the imports for theme components not default to make it easier to import the right component or correct theme. Also set a more precise name for the component theme to avoid mess.
9bc532b
to
59e9bf1
Compare
Closes: #139 Changed default export theme to export const and updated naming convention themes consistent with the chakra-ui to represent what exactly export represents. Originally posted in #105 (comment)
Closes #97
This PR implements the required steps to stake BTC. Currently, the SDK isn't yet available so let's mock these functions. SDK functions will be called in specially prepared hooks:
useSignMessage
anduseDepositBTCTransaction
. We will probably need one more hook responsible for sending the transaction and tracking its status. But let's do it when the SDK is ready. The scope of this PR ro prepare the right modals and place to connect to the SDK.Minor note
The possibility to sign message has been added for testing. Probably this part will be removed and supported by the SDK. To properly go through the modals, you need to add the manifest file to the ledger live application once again.
Screen.Recording.2024-01-04.at.10.55.45.mov