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

feat: hook up modals #467

Merged
merged 4 commits into from
Dec 9, 2024
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
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"dependencies": {
"@babylonlabs-io/babylon-proto-ts": "0.0.3-canary.4",
"@babylonlabs-io/bbn-core-ui": "^0.2.0",
"@babylonlabs-io/bbn-wallet-connect": "^0.1.6",
"@babylonlabs-io/bbn-core-ui": "^0.3.2",
"@babylonlabs-io/bbn-wallet-connect": "^0.1.7",
"@babylonlabs-io/btc-staking-ts": "0.4.0-canary.3",
"@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
"@bitcoinerlab/secp256k1": "^1.1.1",
Expand All @@ -40,7 +40,7 @@
"@sentry/nextjs": "^8.30.0",
"@tanstack/react-query": "^5.28.14",
"@tanstack/react-query-next-experimental": "^5.28.14",
"@tomo-inc/wallet-connect-sdk": "^0.3.3",
"@tomo-inc/wallet-connect-sdk": "^0.3.5",
"@uidotdev/usehooks": "^2.4.1",
"axios": "^1.7.4",
"bitcoinjs-lib": "6.1.5",
Expand Down
16 changes: 8 additions & 8 deletions src/app/components/Delegations/Delegations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import InfiniteScroll from "react-infinite-scroll-component";
import { useLocalStorage } from "usehooks-ts";

import { LoadingTableList } from "@/app/components/Loading/Loading";
import {
MODE,
MODE_WITHDRAW,
WithdrawModal,
} from "@/app/components/Modals/WithdrawModal";
import { WithdrawModal } from "@/app/components/Modals/WithdrawModal";
import { useError } from "@/app/context/Error/ErrorContext";
import { useBTCWallet } from "@/app/context/wallet/BTCWalletProvider";
import { useDelegations } from "@/app/hooks/client/api/useDelegations";
Expand All @@ -25,6 +21,10 @@ import { toLocalStorageIntermediateDelegation } from "@/utils/local_storage/toLo

import { Delegation } from "./Delegation";

const MODE_TRANSITION = "transition";
const MODE_WITHDRAW = "withdraw";
type MODE = typeof MODE_TRANSITION | typeof MODE_WITHDRAW;

export const Delegations = ({}) => {
const { publicKeyNoCoord, connected, network } = useBTCWallet();
const [modalOpen, setModalOpen] = useState(false);
Expand Down Expand Up @@ -302,12 +302,12 @@ export const Delegations = ({}) => {
</div>
{modalMode && txID && selectedDelegation && (
<WithdrawModal
isOpen={modalOpen}
open={modalOpen}
onClose={() => setModalOpen(false)}
onProceed={() => {
onSubmit={() => {
handleWithdraw(txID);
}}
awaitingWalletResponse={awaitingWalletResponse}
processing={awaitingWalletResponse}
/>
)}
</>
Expand Down
64 changes: 64 additions & 0 deletions src/app/components/Modals/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
Button,
DialogBody,
DialogFooter,
DialogHeader,
Loader,
} from "@babylonlabs-io/bbn-core-ui";
import { PropsWithChildren } from "react";
import { twMerge } from "tailwind-merge";

import { ResponsiveDialog } from "./ResponsiveDialog";

interface ConfirmationModalProps {
className?: string;
processing: boolean;
open: boolean;
title: string;
onClose: () => void;
onSubmit: () => void;
}

export const ConfirmationModal = ({
className,
processing,
open,
title,
children,
onClose,
onSubmit,
}: PropsWithChildren<ConfirmationModalProps>) => (
<ResponsiveDialog
className={twMerge("max-w-[660px]", className)}
open={open}
onClose={onClose}
>
<DialogHeader
title={title}
className="text-primary-dark"
onClose={onClose}
/>

<DialogBody className="text-primary-dark">{children}</DialogBody>

<DialogFooter className="flex gap-4">
<Button
variant="outlined"
color="primary"
onClick={onClose}
className="flex-1"
>
Cancel
</Button>

<Button
disabled={processing}
variant="contained"
onClick={onSubmit}
className="flex-1"
>
{processing ? <Loader size={16} className="text-white" /> : "Proceed"}
</Button>
</DialogFooter>
</ResponsiveDialog>
);
13 changes: 10 additions & 3 deletions src/app/components/Modals/PendingVerificationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { BiSolidBadgeCheck } from "react-icons/bi";

import { useDelegationV2 } from "@/app/hooks/client/api/useDelegationV2";
import { useTransactionService } from "@/app/hooks/services/useTransactionService";
import { DelegationV2StakingState as state } from "@/app/types/delegationsV2";
import { useDelegationV2State } from "@/app/state/DelegationV2State";
import { DelegationV2StakingState as State } from "@/app/types/delegationsV2";
import { getNetworkConfig } from "@/config/network.config";

import { GeneralModal } from "./GeneralModal";
Expand Down Expand Up @@ -45,6 +46,7 @@ export function PendingVerificationModal({
stakingTxHash,
}: PendingVerificationModalProps) {
const { submitStakingTx } = useTransactionService();
const { updateDelegationStatus } = useDelegationV2State();
const { networkName } = getNetworkConfig();

const { data: delegation = null } = useDelegationV2(stakingTxHash);
Expand Down Expand Up @@ -72,10 +74,15 @@ export function PendingVerificationModal({
stakingTxHashHex,
stakingTxHex,
);

updateDelegationStatus(
stakingTxHashHex,
State.INTERMEDIATE_PENDING_BTC_CONFIRMATION,
);
onClose();
}, [delegation, submitStakingTx, onClose]);
}, [delegation, updateDelegationStatus, submitStakingTx, onClose]);

const verified = delegation?.state === state.VERIFIED;
const verified = delegation?.state === State.VERIFIED;

return (
<GeneralModal
Expand Down
10 changes: 4 additions & 6 deletions src/app/components/Modals/PreviewModal.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
Avatar,
Button,
Dialog,
DialogBody,
DialogFooter,
DialogHeader,
Heading,
Loader,
MobileDialog,
Text,
} from "@babylonlabs-io/bbn-core-ui";

Expand All @@ -18,6 +16,8 @@ import { satoshiToBtc } from "@/utils/btc";
import { maxDecimals } from "@/utils/maxDecimals";
import { blocksToDisplayTime } from "@/utils/time";

import { ResponsiveDialog } from "./ResponsiveDialog";

interface PreviewModalProps {
isOpen: boolean;
onClose: () => void;
Expand Down Expand Up @@ -53,8 +53,6 @@ export const PreviewModal = ({
networkInfo?.params.btcEpochCheckParams?.latestParam
?.btcConfirmationDepth || 10;

const DialogComponent = isMobileView ? MobileDialog : Dialog;

const FinalityProviderValue = isMobileView ? (
<span className="flex gap-2">
{finalityProviderAvatar && (
Expand Down Expand Up @@ -117,7 +115,7 @@ export const PreviewModal = ({
];

return (
<DialogComponent open={isOpen} onClose={onClose}>
<ResponsiveDialog open={isOpen} onClose={onClose}>
<DialogHeader
title="Preview"
onClose={onClose}
Expand Down Expand Up @@ -173,6 +171,6 @@ export const PreviewModal = ({
)}
</Button>
</DialogFooter>
</DialogComponent>
</ResponsiveDialog>
);
};
10 changes: 10 additions & 0 deletions src/app/components/Modals/ResponsiveDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Dialog, DialogProps, MobileDialog } from "@babylonlabs-io/bbn-core-ui";

import { useIsMobileView } from "@/app/hooks/useBreakpoint";

export function ResponsiveDialog(props: DialogProps) {
const isMobileView = useIsMobileView();
const DialogComponent = isMobileView ? MobileDialog : Dialog;

return <DialogComponent {...props} />;
}
22 changes: 22 additions & 0 deletions src/app/components/Modals/SlashingModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Text } from "@babylonlabs-io/bbn-core-ui";

import { ConfirmationModal } from "./ConfirmationModal";

interface UnbondModalProps {
processing: boolean;
open: boolean;
onClose: () => void;
onSubmit: () => void;
}

export const SlashingModal = (props: UnbondModalProps) => {
return (
<ConfirmationModal title="Withdraw Non-Slashed Balance" {...props}>
<Text variant="body1" className="pt-8 pb-10">
The Finality Provider you delegated to has been slashed and removed from
the network. You can withdraw your non-slashed balance after the
timelock period ends. Slashed funds cannot be recovered.
</Text>
</ConfirmationModal>
);
};
36 changes: 36 additions & 0 deletions src/app/components/Modals/StakeModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { MdEditNote } from "react-icons/md";

import { getNetworkConfig } from "@/config/network.config";

import { SubmitModal } from "./SubmitModal";

const { networkName } = getNetworkConfig();

interface StakeModalProps {
processing?: boolean;
open: boolean;
onClose: () => void;
onSubmit: () => void;
}

export function StakeModal({
processing,
open,
onClose,
onSubmit,
}: StakeModalProps) {
return (
<SubmitModal
processing={processing}
open={open}
icon={<MdEditNote size={52} />}
title={`Sign and Send to ${networkName}`}
onClose={onClose}
onSubmit={onSubmit}
>
Lorem ipsum dolor sit amet consectetur. Eget ut sagittis vitae hendrerit
tempus non pellentesque. Amet enim justo vel quam pharetra sem. Id in arcu
dignissim.
</SubmitModal>
);
}
Loading