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

Polish CreateSafeModal #90

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const CreateSafeModal: React.FC<CreateSafeModalProps> = ({
const [hasApproval, setHasApproval] = useState(false);
const [approving, setApproving] = useState(false);
const [creatingSafe, setCreatingSafe] = useState(false);
const [navigating, setNavigating] = useState(false);

// Utils
const toast = useToast();
Expand Down Expand Up @@ -118,15 +119,21 @@ export const CreateSafeModal: React.FC<CreateSafeModalProps> = ({
approve: onClickApprove,
createSafe: onClickCreateSafe,
creatingSafe,
navigating,
onClose() {
// Only allow close if a transaction isn't in progress.
if (!approving && !creatingSafe) {
setStepIndex(0);
onClose();
}
},
navigateToCreatedSafe() {
router.push("/turbo/safe/0");
async navigateToCreatedSafe() {
setNavigating(true);
try {
await router.push("/turbo/safe/0");
} finally {
setNavigating(false);
}
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type CreateSafeCtx = {
creatingSafe: boolean;
/** Function which closes the modal. */
onClose(): void;
/** Whether the navigation to the created safe is pending. */
navigating: boolean;
/**
* Function which navigates to the safe that was just created in this modal.
*/
Expand Down Expand Up @@ -207,7 +209,7 @@ const MODAL_STEP_4: ModalStep = {
stepBubbles: ({ hasApproval, approving, creatingSafe, depositAmount }) => ({
steps: 2,
loading: approving || creatingSafe,
activeIndex: !hasApproval && parseEther(depositAmount ?? "0") ? 0 : 1,
activeIndex: !hasApproval && parseEther(depositAmount ?? "0").gt(0) ? 0 : 1,
background: "neutral",
}),
buttons: ({
Expand Down Expand Up @@ -262,14 +264,15 @@ const MODAL_STEP_5: ModalStep = {
</Box>
</Stack>
),
buttons: ({ onClose, navigateToCreatedSafe }) => [
buttons: ({ onClose, navigateToCreatedSafe, navigating }) => [
{
children: "View Safe",
children: navigating ? "Loading..." : "View Safe",
loading: navigating,
variant: "neutral",
onClick() {
async onClick() {
// TODO(sharad-s): replace hardcoded value
await navigateToCreatedSafe("0");
onClose();
// TODO(nathanhleung): replace hardcoded value
navigateToCreatedSafe("0");
},
},
],
Expand Down