-
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.
dApp: Handle deposit rejection (#453)
Closes: #432 This pull request reverts `ResumeModal` component removal with updated logic. dApp now distinguishes error caused by user interruption and displays a proper modal window to ensure the user really wants to cancel the process. https://github.com/thesis/acre/assets/11503879/a1fbcee1-8edc-4274-857b-1e9c94571a7d Summary of changes: - added paused/pending action flow states definitions - added `useActionFlowPause` hook exposing state change handler functions - added `ResumeModal` component - added `TransactionError` type definition
- Loading branch information
Showing
10 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react" | ||
import { | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
Button, | ||
HStack, | ||
} from "@chakra-ui/react" | ||
|
||
import Spinner from "#/components/shared/Spinner" | ||
import { PauseIcon } from "#/assets/icons" | ||
import { TextMd } from "#/components/shared/Typography" | ||
import { useActionFlowPause, useModal } from "#/hooks" | ||
|
||
export default function ResumeModal() { | ||
const { handleResume } = useActionFlowPause() | ||
const { closeModal } = useModal() | ||
|
||
return ( | ||
<> | ||
<ModalHeader pb={6} textAlign="center"> | ||
Paused | ||
</ModalHeader> | ||
<ModalBody textAlign="start" py={6} mx={3} gap={4}> | ||
<HStack position="relative" justifyContent="center"> | ||
<Spinner size="2xl" /> | ||
<PauseIcon position="absolute" boxSize={6} color="brand.400" /> | ||
</HStack> | ||
|
||
<TextMd>Are your sure you want to cancel?</TextMd> | ||
</ModalBody> | ||
<ModalFooter flexDirection="column" gap={2}> | ||
<Button size="lg" width="100%" onClick={handleResume}> | ||
Resume deposit | ||
</Button> | ||
<Button size="lg" width="100%" variant="outline" onClick={closeModal}> | ||
Yes, cancel | ||
</Button> | ||
</ModalFooter> | ||
</> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { setStatus } from "#/store/action-flow" | ||
import { PROCESS_STATUSES } from "#/types" | ||
import { useAppDispatch } from "./useAppDispatch" | ||
|
||
/** | ||
* Custom hook that provides functions to pause and resume the action flow process. | ||
* @returns An object containing the `handlePause` and `handleResume` functions. | ||
*/ | ||
export function useActionFlowPause() { | ||
const dispatch = useAppDispatch() | ||
|
||
/** | ||
* Function to pause the action flow process. | ||
* It dispatches an action to set the status to "PAUSED" if the current status is "PENDING". | ||
*/ | ||
const handlePause = () => { | ||
dispatch(setStatus(PROCESS_STATUSES.PAUSED)) | ||
} | ||
|
||
/** | ||
* Function to resume the action flow process. | ||
* It dispatches an action to set the status to "PENDING". | ||
*/ | ||
const handleResume = () => { | ||
dispatch(setStatus(PROCESS_STATUSES.PENDING)) | ||
} | ||
|
||
return { handlePause, handleResume } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { LedgerLiveError } from "#/types" | ||
|
||
export function isObject( | ||
arg: unknown, | ||
): arg is Record<string | number | symbol, unknown> { | ||
return typeof arg === "object" && arg !== null | ||
} | ||
|
||
export function isString(arg: unknown): arg is string { | ||
return typeof arg === "string" | ||
} | ||
|
||
export function isLedgerLiveError(arg: unknown): arg is LedgerLiveError { | ||
return isObject(arg) && arg.name === "Error" && isString(arg.message) | ||
} |