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 file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b4541c5
Add a theme for `CloseButton`
kkosiorowska Mar 8, 2024
0f896a4
Restructure the styles for the Alert component
kkosiorowska Mar 12, 2024
4bc6681
Style improvements for the modal component
kkosiorowska Mar 12, 2024
7c8ed7a
Handle errors for signing or deposit BTC
kkosiorowska Mar 12, 2024
3864588
Show notifications when wallets are not connected
kkosiorowska Mar 13, 2024
a84b69c
Create a separate directory for alerts
kkosiorowska Mar 13, 2024
a16ae3c
Export useful functions from useToast
kkosiorowska Mar 14, 2024
a4a22f2
Show button loading status when deposit address is verifying
kkosiorowska Mar 14, 2024
85132c5
Merge branch 'main' of github.com:thesis/acre into show-errors
kkosiorowska Mar 14, 2024
cb68d46
Show error notification when the execution of a deposit transaction i…
kkosiorowska Mar 15, 2024
aa8113e
Update of error texts for dApp
kkosiorowska Mar 15, 2024
59e3432
Simplify error handling logic for staking flow
kkosiorowska Mar 15, 2024
3bf2a68
Small improvements
kkosiorowska Mar 15, 2024
d86d75f
Rename from `isToastClosed` to `isToastAlreadyClosed`
kkosiorowska Mar 15, 2024
5c799df
Simplifying the logic of using toast component
kkosiorowska Mar 15, 2024
2e9fa48
Use `TOAST_ID` everywhere to make the code transparent
kkosiorowska Mar 18, 2024
d402e84
Reorganize global styles for Chakra UI
kkosiorowska Mar 18, 2024
797603c
Fix typo for `onClick`
kkosiorowska Mar 20, 2024
6585152
Change the default status value for the `Toast` component
kkosiorowska Mar 20, 2024
ded8b11
Rename `WALLET_TOAST` to `WALLET_ERROR_TOAST_ID`
kkosiorowska Mar 20, 2024
516d315
Remove unnecessary disabling of the `eslint` rule
kkosiorowska Mar 20, 2024
b208331
Move style for `LoadingButton` to theme
kkosiorowska Mar 20, 2024
1bfe26c
Remove unnecessary `onClick`
kkosiorowska Mar 22, 2024
f0f846a
Improve the `onClose` function pass
kkosiorowska Mar 22, 2024
dcae1d6
Rename from `returnFunction` to `overriddenToastFunction`
kkosiorowska Mar 22, 2024
6fe4880
Separate toasts component into files
kkosiorowska Mar 22, 2024
7853840
Rename from `overriddenToastFunction` to `overriddenToast`
kkosiorowska Apr 2, 2024
7632242
Create a `useTimeout` hook
kkosiorowska Apr 2, 2024
4584248
Rename from `toastManagerStyle` to `toastManagerTopStyle`
kkosiorowska Apr 2, 2024
e99d2e5
Remove unnecessary padding for tooltip
kkosiorowska Apr 2, 2024
33a0421
Removal of the global object `TOASTS`
kkosiorowska Apr 2, 2024
e5f8eca
Show wallet error toast from the top level
kkosiorowska Apr 2, 2024
4c34023
Reorganizing toasts components
kkosiorowska Apr 2, 2024
976a466
Add `@tabler/icons-react` package
kkosiorowska Apr 2, 2024
39850ce
Use icons for alert from `@tabler/icons-react`
kkosiorowska Apr 2, 2024
37ce916
Merge branch 'main' of github.com:thesis/acre into show-errors
kkosiorowska Apr 4, 2024
1107ecf
Create a special hook for init global toasts
kkosiorowska Apr 8, 2024
07b035f
Rename methods for `useToast`
kkosiorowska Apr 8, 2024
6fc58a3
Save the toast id globally along with the correct component
kkosiorowska Apr 8, 2024
1ba648f
Merge branch 'main' of github.com:thesis/acre into show-errors
kkosiorowska Apr 10, 2024
dc90e68
Add description for `Toast` component
kkosiorowska Apr 10, 2024
56329fb
`OverviewPage` component update
kkosiorowska Apr 11, 2024
15cb2ad
Merge branch 'main' of github.com:thesis/acre into show-errors
kkosiorowska Apr 12, 2024
7dcae5e
Change `zIndex` for toast component
kkosiorowska Apr 15, 2024
664f8d4
Merge branch 'main' into show-errors
r-czajkowski Apr 16, 2024
8190785
Merge branch 'main' into show-errors
r-czajkowski Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dapp/src/assets/icons/AlertError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react"
import { createIcon } from "@chakra-ui/react"

export const AlertError = createIcon({
ioay marked this conversation as resolved.
Show resolved Hide resolved
displayName: "AlertError",
viewBox: "0 0 24 25",
path: [
<path
d="M12 9.5V13.5M12 16.5V16.51M3 12.5C3 13.6819 3.23279 14.8522 3.68508 15.9442C4.13738 17.0361 4.80031 18.0282 5.63604 18.864C6.47177 19.6997 7.46392 20.3626 8.55585 20.8149C9.64778 21.2672 10.8181 21.5 12 21.5C13.1819 21.5 14.3522 21.2672 15.4442 20.8149C16.5361 20.3626 17.5282 19.6997 18.364 18.864C19.1997 18.0282 19.8626 17.0361 20.3149 15.9442C20.7672 14.8522 21 13.6819 21 12.5C21 11.3181 20.7672 10.1478 20.3149 9.05585C19.8626 7.96392 19.1997 6.97177 18.364 6.13604C17.5282 5.30031 16.5361 4.63738 15.4442 4.18508C14.3522 3.73279 13.1819 3.5 12 3.5C10.8181 3.5 9.64778 3.73279 8.55585 4.18508C7.46392 4.63738 6.47177 5.30031 5.63604 6.13604C4.80031 6.97177 4.13738 7.96392 3.68508 9.05585C3.23279 10.1478 3 11.3181 3 12.5Z"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
/>,
],
})
25 changes: 9 additions & 16 deletions dapp/src/assets/icons/AlertInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ import { createIcon } from "@chakra-ui/react"

export const AlertInfo = createIcon({
displayName: "AlertInfo",
viewBox: "0 0 16 16",
viewBox: "0 0 24 24",
path: [
<g clipPath="url(#clip0_3178_2454)">
<path
d="M7.99967 5.33325V7.99992M7.99967 10.6666H8.00634M14.6663 7.99992C14.6663 11.6818 11.6816 14.6666 7.99967 14.6666C4.31778 14.6666 1.33301 11.6818 1.33301 7.99992C1.33301 4.31802 4.31778 1.33325 7.99967 1.33325C11.6816 1.33325 14.6663 4.31802 14.6663 7.99992Z"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
/>
</g>,
<defs>
<clipPath id="clip0_3178_2454">
<rect width="16" height="16" fill="currentColor" />
</clipPath>
</defs>,
<path
d="M12 9.5H12.01M11 12.5H12V16.5H13M3 12.5C3 13.6819 3.23279 14.8522 3.68508 15.9442C4.13738 17.0361 4.80031 18.0282 5.63604 18.864C6.47177 19.6997 7.46392 20.3626 8.55585 20.8149C9.64778 21.2672 10.8181 21.5 12 21.5C13.1819 21.5 14.3522 21.2672 15.4442 20.8149C16.5361 20.3626 17.5282 19.6997 18.364 18.864C19.1997 18.0282 19.8626 17.0361 20.3149 15.9442C20.7672 14.8522 21 13.6819 21 12.5C21 10.1131 20.0518 7.82387 18.364 6.13604C16.6761 4.44821 14.3869 3.5 12 3.5C9.61305 3.5 7.32387 4.44821 5.63604 6.13604C3.94821 7.82387 3 10.1131 3 12.5Z"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
/>,
],
})
1 change: 1 addition & 0 deletions dapp/src/assets/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./AcreLogo"
export * from "./ConnectBTCAccount"
export * from "./ConnectETHAccount"
export * from "./AlertInfo"
export * from "./AlertError"
export * from "./stBTC"
export * from "./BTC"
export * from "./ShieldPlus"
Expand Down
18 changes: 9 additions & 9 deletions dapp/src/components/Header/ConnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import React from "react"
import { Button, HStack, Icon, Tooltip } from "@chakra-ui/react"
import {
useRequestBitcoinAccount,
useRequestEthereumAccount,
useWalletContext,
} from "#/hooks"
import { Account } from "@ledgerhq/wallet-api-client"
import { useWalletToast, useWallet } from "#/hooks"
import { CurrencyBalance } from "#/components/shared/CurrencyBalance"
import { TextMd } from "#/components/shared/Typography"
import { Bitcoin, EthereumIcon } from "#/assets/icons"
import { Account } from "@ledgerhq/wallet-api-client"
import { CURRENCY_ID_BITCOIN } from "#/constants"
import {
isSupportedBTCAddressType,
Expand All @@ -30,9 +26,13 @@ const getCustomDataByAccount = (
}

export default function ConnectWallet() {
const { requestAccount: requestBitcoinAccount } = useRequestBitcoinAccount()
const { requestAccount: requestEthereumAccount } = useRequestEthereumAccount()
const { btcAccount, ethAccount } = useWalletContext()
const {
bitcoin: { account: btcAccount, requestAccount: requestBitcoinAccount },
ethereum: { account: ethAccount, requestAccount: requestEthereumAccount },
} = useWallet()

useWalletToast("ethereum")
useWalletToast("bitcoin")
ioay marked this conversation as resolved.
Show resolved Hide resolved

const customDataBtcAccount = getCustomDataByAccount(btcAccount)
const customDataEthAccount = getCustomDataByAccount(ethAccount)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
import React, { useCallback } from "react"
import React, { useCallback, useState } from "react"
import {
useDepositBTCTransaction,
useDepositTelemetry,
useExecuteFunction,
useModalFlowContext,
useStakeFlowContext,
useToast,
useTransactionContext,
useWalletContext,
} from "#/hooks"
import Alert from "#/components/shared/Alert"
import { TextMd } from "#/components/shared/Typography"
import { logPromiseFailure } from "#/utils"
import { PROCESS_STATUSES } from "#/types"
import { PROCESS_STATUSES, TOAST_TYPES } from "#/types"
import { CardAlert } from "#/components/shared/alerts"
import { TOASTS } from "#/components/shared/toasts"
import StakingStepsModalContent from "./StakingStepsModalContent"

const TOAST_ID = TOAST_TYPES.DEPOSIT_TRANSACTION_ERROR

ioay marked this conversation as resolved.
Show resolved Hide resolved
export default function DepositBTCModal() {
const { ethAccount } = useWalletContext()
const { tokenAmount } = useTransactionContext()
const { setStatus } = useModalFlowContext()
const { btcAddress, depositReceipt, stake } = useStakeFlowContext()
const depositTelemetry = useDepositTelemetry()
const { close: closeToast, open: openToast } = useToast()

ioay marked this conversation as resolved.
Show resolved Hide resolved
const onStakeBTCSuccess = useCallback(() => {
setStatus(PROCESS_STATUSES.SUCCEEDED)
}, [setStatus])
const [isLoading, setIsLoading] = useState(false)
const [buttonText, setButtonText] = useState("Deposit BTC")

const onStakeBTCSuccess = useCallback(
() => setStatus(PROCESS_STATUSES.SUCCEEDED),
[setStatus],
)

// TODO: After a failed attempt, we should display the message
const onStakeBTCError = useCallback(() => {
Expand All @@ -37,34 +46,48 @@ export default function DepositBTCModal() {
)

const onDepositBTCSuccess = useCallback(() => {
closeToast(TOAST_ID)
setStatus(PROCESS_STATUSES.LOADING)

logPromiseFailure(handleStake())
}, [setStatus, handleStake])
}, [closeToast, setStatus, handleStake])

const { sendBitcoinTransaction } =
useDepositBTCTransaction(onDepositBTCSuccess)
const showError = useCallback(() => {
openToast(TOASTS[TOAST_ID]())
setButtonText("Try again")
}, [openToast])

const onDepositBTCError = useCallback(() => showError(), [showError])

const { sendBitcoinTransaction } = useDepositBTCTransaction(
onDepositBTCSuccess,
onDepositBTCError,
)

const handledDepositBTC = useCallback(async () => {
if (!tokenAmount?.amount || !btcAddress || !depositReceipt || !ethAccount)
return

setIsLoading(true)
const response = await depositTelemetry(
ioay marked this conversation as resolved.
Show resolved Hide resolved
depositReceipt,
btcAddress,
ethAccount.address,
)
setIsLoading(false)

// TODO: Display the correct message for the user
if (response.verificationStatus !== "valid") return

logPromiseFailure(sendBitcoinTransaction(tokenAmount?.amount, btcAddress))
if (response.verificationStatus === "valid") {
logPromiseFailure(sendBitcoinTransaction(tokenAmount?.amount, btcAddress))
} else {
showError()
}
}, [
btcAddress,
depositReceipt,
depositTelemetry,
ethAccount,
sendBitcoinTransaction,
showError,
tokenAmount?.amount,
])

Expand All @@ -74,15 +97,16 @@ export default function DepositBTCModal() {

return (
<StakingStepsModalContent
buttonText="Deposit BTC"
buttonText={buttonText}
activeStep={1}
isLoading={isLoading}
onClick={handledDepositBTCWrapper}
>
<Alert>
<CardAlert status="error">
<TextMd>
Make a Bitcoin transaction to deposit and stake your BTC.
</TextMd>
</Alert>
</CardAlert>
</StakingStepsModalContent>
)
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
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, TOAST_TYPES } from "#/types"
import { ReceiveSTBTCAlert } from "#/components/shared/alerts"
import { TOASTS } from "#/components/shared/toasts"
import StakingStepsModalContent from "./StakingStepsModalContent"

const TOAST_ID = TOAST_TYPES.SIGNING_ERROR

ioay marked this conversation as resolved.
Show resolved Hide resolved
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 { close: closeToast, open: openToast } = useToast()
ioay marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
setStatus(PROCESS_STATUSES.PENDING)
}, [setStatus])

const onSignMessageSuccess = useCallback(() => {
closeToast(TOAST_ID)
goNext()
}, [closeToast, goNext])

const onSignMessageError = useCallback(() => {
openToast(TOASTS[TOAST_ID]())
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>
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import React from "react"
import {
Button,
HStack,
ModalBody,
ModalFooter,
ModalHeader,
} from "@chakra-ui/react"
import { HStack, ModalBody, ModalFooter, ModalHeader } from "@chakra-ui/react"
import { TextLg, TextMd } from "#/components/shared/Typography"
import StepperBase, { StepBase } from "#/components/shared/StepperBase"
import Spinner from "#/components/shared/Spinner"
import { LoadingButton } from "#/components/shared/LoadingButton"

export function Title({ children }: { children: React.ReactNode }) {
return <TextLg fontWeight="bold">{children}</TextLg>
Expand Down Expand Up @@ -43,12 +38,14 @@ const STEPS: StepBase[] = [

export default function StakingStepsModalContent({
buttonText,
isLoading,
activeStep,
onClick,
children,
}: {
buttonText: string
activeStep: number
isLoading?: boolean
onClick: () => void
children: React.ReactNode
}) {
Expand All @@ -68,9 +65,14 @@ export default function StakingStepsModalContent({
{children}
</ModalBody>
<ModalFooter>
<Button size="lg" width="100%" onClick={onClick}>
<LoadingButton
size="lg"
width="100%"
onClick={onClick}
isLoading={isLoading}
>
{buttonText}
</Button>
</LoadingButton>
</ModalFooter>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useExecuteFunction, useModalFlowContext } from "#/hooks"
import { PROCESS_STATUSES } from "#/types"
import { Button, ModalBody, ModalFooter, ModalHeader } from "@chakra-ui/react"
import { TextMd } from "#/components/shared/Typography"
import AlertReceiveSTBTC from "#/components/shared/AlertReceiveSTBTC"
import { logPromiseFailure } from "#/utils"
import { ReceiveSTBTCAlert } from "#/components/shared/alerts"

export default function SignMessageModal() {
const { setStatus } = useModalFlowContext()
Expand Down Expand Up @@ -46,7 +46,7 @@ export default function SignMessageModal() {
You will sign a gas-free Ethereum message to indicate the address
where you&apos;d like to get your stBTC liquid staking token.
</TextMd>
<AlertReceiveSTBTC />
<ReceiveSTBTCAlert />
</ModalBody>
<ModalFooter pt={10}>
<Button size="lg" width="100%" onClick={handleSignMessageWrapper}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
ModalHeader,
} from "@chakra-ui/react"
import { TextMd } from "#/components/shared/Typography"
import Alert from "#/components/shared/Alert"
import { logPromiseFailure, getCurrencyByType } from "#/utils"
import { CurrencyType, RequestAccountParams } from "#/types"
import { CardAlert } from "#/components/shared/alerts"

type MissingAccountModalProps = {
currency: CurrencyType
Expand Down Expand Up @@ -40,14 +40,14 @@ export default function MissingAccountModal({
{name} account is required to make transactions for depositing and
staking your {symbol}.
</TextMd>
<Alert>
<CardAlert>
<TextMd>
<Highlight query="Accounts" styles={{ fontWeight: "bold" }}>
You will be sent to the Ledger Accounts section to perform this
action.
</Highlight>
</TextMd>
</Alert>
</CardAlert>
</ModalBody>
<ModalFooter mt={4}>
<Button size="lg" width="100%" onClick={handleClick}>
Expand Down
Loading
Loading