-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 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](https://www.figma.com/file/OUdSfHsmgV8EJpWxAzXjl5/ACRE?node-id=5217%3A34321&mode=dev), 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](chakra-ui/chakra-ui#3429 (comment)) 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 <img width="442" alt="Screenshot 2024-03-13 at 13 51 38" src="https://github.com/thesis/acre/assets/23117945/3b0b9686-726e-467c-9df2-2f7c1177a409"> <img width="443" alt="Screenshot 2024-03-13 at 13 56 10" src="https://github.com/thesis/acre/assets/23117945/f210055b-0e10-446b-84e5-c3c58d4764cc"> - ReceiveSTBTCAlert <img width="441" alt="Screenshot 2024-03-13 at 13 51 22" src="https://github.com/thesis/acre/assets/23117945/9c0f7dcc-5709-472e-8306-55c76a9e028c"> - Toast <img width="537" alt="Screenshot 2024-03-13 at 13 51 16" src="https://github.com/thesis/acre/assets/23117945/ee2a04d1-2076-475f-9625-2f03af0ace28"> ## 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.
- Loading branch information
Showing
47 changed files
with
614 additions
and
193 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 34 additions & 10 deletions
44
dapp/src/components/TransactionModal/ActiveStakingStep/SignMessageModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,58 @@ | ||
import React, { useCallback, useEffect } from "react" | ||
import React, { useCallback, useEffect, useState } from "react" | ||
import { | ||
useExecuteFunction, | ||
useModalFlowContext, | ||
useStakeFlowContext, | ||
useToast, | ||
} from "#/hooks" | ||
import { logPromiseFailure } from "#/utils" | ||
import AlertReceiveSTBTC from "#/components/shared/AlertReceiveSTBTC" | ||
import { PROCESS_STATUSES } from "#/types" | ||
import { PROCESS_STATUSES, TOASTS, TOAST_IDS } from "#/types" | ||
import { ReceiveSTBTCAlert } from "#/components/shared/alerts" | ||
import StakingStepsModalContent from "./StakingStepsModalContent" | ||
|
||
const TOAST_ID = TOAST_IDS.SIGNING_ERROR | ||
const TOAST = TOASTS[TOAST_ID] | ||
|
||
export default function SignMessageModal() { | ||
const { goNext, setStatus } = useModalFlowContext() | ||
const { signMessage } = useStakeFlowContext() | ||
const handleSignMessage = useExecuteFunction(signMessage, goNext) | ||
|
||
const handleSignMessageWrapper = useCallback(() => { | ||
logPromiseFailure(handleSignMessage()) | ||
}, [handleSignMessage]) | ||
const [buttonText, setButtonText] = useState("Sign now") | ||
const { closeToast, openToast } = useToast() | ||
|
||
useEffect(() => { | ||
setStatus(PROCESS_STATUSES.PENDING) | ||
}, [setStatus]) | ||
|
||
const onSignMessageSuccess = useCallback(() => { | ||
closeToast(TOAST_ID) | ||
goNext() | ||
}, [closeToast, goNext]) | ||
|
||
const onSignMessageError = useCallback(() => { | ||
openToast({ | ||
id: TOAST_ID, | ||
render: TOAST, | ||
}) | ||
setButtonText("Try again") | ||
}, [openToast]) | ||
|
||
const handleSignMessage = useExecuteFunction( | ||
signMessage, | ||
onSignMessageSuccess, | ||
onSignMessageError, | ||
) | ||
|
||
const handleSignMessageWrapper = useCallback(() => { | ||
logPromiseFailure(handleSignMessage()) | ||
}, [handleSignMessage]) | ||
|
||
return ( | ||
<StakingStepsModalContent | ||
buttonText="Sign now" | ||
buttonText={buttonText} | ||
activeStep={0} | ||
onClick={handleSignMessageWrapper} | ||
> | ||
<AlertReceiveSTBTC /> | ||
<ReceiveSTBTCAlert /> | ||
</StakingStepsModalContent> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.