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 43 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
24 changes: 0 additions & 24 deletions dapp/src/assets/icons/AlertInfo.tsx

This file was deleted.

1 change: 0 additions & 1 deletion dapp/src/assets/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from "./ArrowUpRight"
export * from "./ArrowLeft"
export * from "./ArrowRight"
export * from "./AcreLogo"
export * from "./AlertInfo"
export * from "./stBTC"
export * from "./BTC"
export * from "./ShieldPlus"
Expand Down
13 changes: 5 additions & 8 deletions dapp/src/components/Header/ConnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from "react"
import { Button, HStack, Icon, Tooltip } from "@chakra-ui/react"
import {
useRequestBitcoinAccount,
useRequestEthereumAccount,
useWalletContext,
} from "#/hooks"
import { useWallet } from "#/hooks"
import { CurrencyBalance } from "#/components/shared/CurrencyBalance"
import { TextMd } from "#/components/shared/Typography"
import { BitcoinIcon, EthereumIcon } from "#/assets/icons"
Expand All @@ -30,9 +26,10 @@ 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()

const customDataBtcAccount = getCustomDataByAccount(btcAccount)
const customDataEthAccount = getCustomDataByAccount(ethAccount)
Expand Down
12 changes: 6 additions & 6 deletions dapp/src/components/LiquidStakingTokenPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
import { SizeType } from "#/types"
import { useDocsDrawer, useSharesBalance, useWalletContext } from "#/hooks"
import { TextMd, TextSm } from "./shared/Typography"
import Alert from "./shared/Alert"
import { CurrencyBalance } from "./shared/CurrencyBalance"
import { CardAlert } from "./shared/alerts"

type LiquidStakingTokenPopoverProps = PopoverProps & { popoverSize: SizeType }

Expand Down Expand Up @@ -55,18 +55,18 @@ export function LiquidStakingTokenPopover({
variant="greater-balance-xl"
currency="stbtc"
/>
<Alert
<CardAlert
mt={5}
status="info"
withAlertIcon={false}
withActionIcon
onclick={openDocsDrawer}
withIcon={false}
withLink
onClick={openDocsDrawer}
>
<TextSm>
Your tokens are this Ethereum address once the staking transaction
is finalized.
</TextSm>
</Alert>
</CardAlert>
</PopoverBody>
</PopoverContent>
</Popover>
Expand Down
10 changes: 7 additions & 3 deletions dapp/src/components/TransactionHistory/Table/utils/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react"
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
import { StakeHistory } from "#/types"
import { capitalize, truncateAddress } from "#/utils"
import { capitalizeFirstLetter, truncateAddress } from "#/utils"
import CustomCell from "../Cell/Custom"
import Cell from "../Cell"
import SimpleText from "../Cell/components/SimpleText"
Expand Down Expand Up @@ -32,10 +32,14 @@ export const COLUMNS: ColumnDef<StakeHistory, any>[] = [
cell: ({ row: { original } }) => (
<Cell
firstField={
<SimpleText>{capitalize(original.callTx.action)}</SimpleText>
<SimpleText>
{capitalizeFirstLetter(original.callTx.action)}
</SimpleText>
}
secondField={
<SimpleText>{capitalize(original.receiptTx.action)}</SimpleText>
<SimpleText>
{capitalizeFirstLetter(original.receiptTx.action)}
</SimpleText>
}
/>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
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 { CardAlert } from "#/components/shared/alerts"
import { TOASTS, TOAST_IDS } from "#/types/toast"
import StakingStepsModalContent from "./StakingStepsModalContent"

const TOAST_ID = TOAST_IDS.DEPOSIT_TRANSACTION_ERROR
const TOAST = TOASTS[TOAST_ID]

export default function DepositBTCModal() {
const { ethAccount } = useWalletContext()
const { tokenAmount } = useTransactionContext()
const { setStatus } = useModalFlowContext()
const { btcAddress, depositReceipt, stake } = useStakeFlowContext()
const depositTelemetry = useDepositTelemetry()
const { closeToast, openToast } = useToast()

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],
)

const onStakeBTCError = useCallback(() => {
setStatus(PROCESS_STATUSES.FAILED)
Expand All @@ -36,34 +46,51 @@ 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({
id: TOAST_ID,
render: TOAST,
})
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 @@ -73,15 +100,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,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()
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({
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>
)
}
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
Loading
Loading