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

Show error notifications #313

Merged
merged 46 commits into from
Apr 16, 2024
Merged

Show error notifications #313

merged 46 commits into from
Apr 16, 2024

Conversation

kkosiorowska
Copy link
Contributor

@kkosiorowska kkosiorowska commented Mar 13, 2024

What has been done

This PR adds support for displaying notifications to the user. The notifications will be displayed as toast. According to the styleguide, there are 3 different notification styles, so it was decided to update the already existing styles. The reason for this change is also that the Toast component is based on the Alert theme. However, to avoid repeating the implemented logic, the previous styles are included in the CardAlert component.

useToast hook

This hook is created to make it easier to work with the toast component. It is a wrapper for hook (useToast) coming from the Chakra UI library. Thanks to this, we injected the basic common settings for all components. In addition, the open function has been added to simplify the logic of opening only one toast for a given id.

UI

  • CardAlert
Screenshot 2024-03-13 at 13 51 38 Screenshot 2024-03-13 at 13 56 10
  • ReceiveSTBTCAlert
Screenshot 2024-03-13 at 13 51 22
  • Toast
Screenshot 2024-03-13 at 13 51 16

Testing

Missing accounts

  • Show notifications about not connected accounts after the app has loaded.
  • Remove notification when a user connects an account.
  • The notifications are only shown once.

Message signing and deposit transaction

  • Show a notification when something goes wrong with message signing.
  • Show a notification when something goes wrong with signing a deposit transaction.
  • Only one notification can be visible on the screen.
  • Close the notification when the user moves to the next step.

According to styleguide, we need to update the styles for the Alert component. Additionally, the Toast component is based on the basic styles of Alert.

Therefore, now the Alert component is based on the styleguide. However, a separate CardAlert component was created to contain the styles of the previous alert in one place.
@kkosiorowska kkosiorowska self-assigned this Mar 13, 2024
Copy link

netlify bot commented Mar 13, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit 8190785
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/661e343f3b7804000886971a
😎 Deploy Preview https://deploy-preview-313--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Created a custom useToast hook which wraps the useToast hook from Chakra UI and provides a render function to it to customize the toast components. In addition, a special ToastType was created to easily keep all kinds of notifications in the TOASTS object. This allows us to easily trigger a notification. Changing the approach of calling toast allowed to simplify the logic and get rid of unneeded parts of the code.
@kkosiorowska kkosiorowska marked this pull request as ready for review March 15, 2024 15:25
For edge cases, you will have to override the global styles for chakra components. I moved these styles to a separate file to keep things in order. This will also make it easy to use the zIndices or semanticTokens file.
dapp/src/components/shared/LoadingButton.tsx Outdated Show resolved Hide resolved
dapp/src/components/shared/LoadingButton.tsx Outdated Show resolved Hide resolved
dapp/src/components/shared/alerts/ReceiveSTBTCAlert.tsx Outdated Show resolved Hide resolved
dapp/src/hooks/useToast.ts Outdated Show resolved Hide resolved
dapp/src/hooks/useWalletToast.ts Outdated Show resolved Hide resolved
dapp/src/hooks/useWalletToast.ts Outdated Show resolved Hide resolved
dapp/src/types/toast.ts Show resolved Hide resolved
dapp/src/hooks/useWalletToast.ts Outdated Show resolved Hide resolved
onClose: () => void
}

export default function Toast({
Copy link
Contributor

Choose a reason for hiding this comment

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

We use Alert component as a wrapper for this component. In my opinion, the Toast component should be more independent in cases when we would like to use other types of toasts. What do you think about creating a more generic Toast component, and this one rename to ToastAlert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use Alert component as a wrapper for this component.

Yeah, this is because the Chakra UI uses alerts as toast. The purpose of this wrapper is to standardize our Toast component based on styleguide.

In my opinion, the Toast component should be more independent in cases when we would like to use other types of toasts. What do you think about creating a more generic Toast component, and this one rename to ToastAlert?

Not quite sure what you mean. What should such a generic component Toast look like in your opinion? 🤔 I'm confused because based on the Chakra solution, it needs to be connected to the alert component.

I would stay with the generic name at this moment. We can update our approach if needed in the feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is because the Chakra UI uses alerts as toast. The purpose of this wrapper is to standardize our Toast component based on styleguide.

Ok, so let's add a comment, that under the hood of Toast uses the Alert component because the chakra doc doesn't say anything about it explicitly.
Just says that Toast uses the same variants as the Alert component (https://chakra-ui.com/docs/components/toast#variants)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dapp/src/hooks/useInitApp.ts Outdated Show resolved Hide resolved
dapp/src/hooks/useToast.ts Outdated Show resolved Hide resolved
Comment on lines 17 to 38
<Flex direction="column" gap={isConnected ? 3.5 : 2} p={6}>
<Flex justifyContent="space-between">
<HStack>
{/* TODO: Handle click actions */}
<Switch size="sm" />
<TextSm fontWeight="bold">Show values in {USD.symbol}</TextSm>
</HStack>
{!isConnected && (
<ButtonLink colorScheme="gold" bg="gold.200" onClick={onOpen}>
Docs
</ButtonLink>
)}
</Flex>
{/* TODO: Add animation to show activity bar */}
{isConnected && (
<Flex marginBottom={3.5} justifyContent="space-between">
<ActivityBar />
<ButtonLink colorScheme="gold" bg="gold.200" onClick={onOpen}>
Docs
</ButtonLink>
</Flex>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Regardless of what we check here(isConnected or any activities) the number of conditions remains the same so separating them into two components depending on their state will be more clear.

Let's set the toast to be in front of the component drawer to avoid confusion.
ioay
ioay previously approved these changes Apr 15, 2024
Copy link
Contributor

@ioay ioay left a comment

Choose a reason for hiding this comment

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

According to @nkuba proposal, we can conditionally merge it before your vacation, and in the future, we will try to solve the problem of calling toasts from other non-react places and use more generic approach. Please just refer to Rafał's comments.

r-czajkowski
r-czajkowski previously approved these changes Apr 16, 2024
@r-czajkowski r-czajkowski enabled auto-merge April 16, 2024 07:59
@r-czajkowski r-czajkowski dismissed stale reviews from ioay and themself via 8190785 April 16, 2024 08:18
@r-czajkowski r-czajkowski merged commit cde70d9 into main Apr 16, 2024
24 checks passed
@r-czajkowski r-czajkowski deleted the show-errors branch April 16, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants