Skip to content

Commit

Permalink
feat(bridge): add fee notices (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisloh95 authored Apr 2, 2024
1 parent 6b73399 commit 2140c41
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 34 deletions.
86 changes: 54 additions & 32 deletions apps/bridge/src/components/account/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import { useMantleSDK } from "@providers/mantleSDKContext";

import { useCallClaim } from "@hooks/web3/bridge/write/useCallClaim";
import { Withdrawal } from "@hooks/web3/bridge/read";
import { IS_MANTLE_V2, L1_CHAIN_ID, CHAINS } from "@config/constants";
import {
IS_MANTLE_V2,
L1_CHAIN_ID,
CHAINS,
feeNotices,
} from "@config/constants";
import { useCallProve } from "@hooks/web3/bridge/write/useCallProve";
import { useSwitchToNetwork } from "@hooks/web3/write/useSwitchToNetwork";
import toast from "react-hot-toast";
import TxLink from "@components/bridge/utils/TxLink";
import Image from "next/image";

export default function Status({
transactionHash,
Expand Down Expand Up @@ -374,38 +380,54 @@ export default function Status({
);
}
return (
<Button
type="button"
size="regular"
variant="dark"
onClick={callClaim}
disabled={isLoadingClaim}
>
<div className="flex flex-row gap-2 items-center">
<span>Claim</span>
{isLoadingClaim && (
<div role="status">
<svg
aria-hidden="true"
className="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
)}
<div className="flex items-center gap-2">
<Button
type="button"
size="regular"
variant="dark"
onClick={callClaim}
disabled={isLoadingClaim}
>
<div className="flex flex-row gap-2 items-center">
<span>Claim</span>
{isLoadingClaim && (
<div role="status">
<svg
aria-hidden="true"
className="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
)}
</div>
</Button>
<div className="relative group">
<Image
className={`opacity-60 hover:opacity-100 `}
src="/thirdparty/tooltip.svg"
alt="tooltip"
width={14}
height={14}
/>
<div className="w-max max-w-[300px] opacity-0 group-hover:opacity-100 absolute bottom-full mb-2 px-4 py-2 bg-white text-black text-xs rounded-md left-0 -translate-x-1/4 md:left-1/2 transform md:-translate-x-1/2 pointer-events-none z-10">
{/* eslint-disable-next-line react/no-danger */}
<div dangerouslySetInnerHTML={{ __html: feeNotices }} />
<div className="absolute left-[26%] md:left-1/2 transform md:-translate-x-1/2 bottom-0 mb-[-4px] w-2 h-2 bg-white rotate-45" />
</div>
</div>
</Button>
</div>
);
case "4":
return (
Expand Down
13 changes: 13 additions & 0 deletions apps/bridge/src/components/bridge/FeeNoticesCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { feeNotices } from "@config/constants";
import { AiFillExclamationCircle } from "react-icons/ai";

export function FeeNoticesCard() {
return (
<div className="bg-[#F26A1D]/[.15] p-4 rounded-2xl flex gap-1 items-start justify-start">
<div className="p-1">
<AiFillExclamationCircle className="text-[#FFA41C]" size={16} />
</div>
<div className="text-sm text-[#C4C4C4] leading-5">{feeNotices}</div>
</div>
);
}
2 changes: 2 additions & 0 deletions apps/bridge/src/components/bridge/dialogue/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Values from "@components/bridge/utils/Values";
import { useMantleSDK } from "@providers/mantleSDKContext";
import { formatTime } from "@mantle/utils";
import { useQuery } from "wagmi";
import { FeeNoticesCard } from "../FeeNoticesCard";

export default function Default({
direction,
Expand Down Expand Up @@ -112,6 +113,7 @@ export default function Default({
}
border
/>
<Values value={<FeeNoticesCard />} border />
{/* different between chains */}
{/* {direction === Direction.Deposit && (
<Values
Expand Down
8 changes: 6 additions & 2 deletions apps/bridge/src/components/bridge/utils/Values.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ export default function Values({
value,
border = false,
}: {
label: string;
label?: string;
value: string | JSX.Element;
border: boolean;
}) {
return (
<div className="flex flex-col my-5">
<div className="text-type-secondary">{label}</div>
{label && <div className="text-type-secondary">{label}</div>}
<div className="text-xl mb-5 text-white">{value}</div>
{border && (
<div className="w-full" style={{ borderBottom: "1px solid #41474D" }} />
)}
</div>
);
}

Values.defaultProps = {
label: undefined,
};
3 changes: 3 additions & 0 deletions apps/bridge/src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,6 @@ export type WithdrawHash = {
prove: string;
claim: string;
};

export const feeNotices =
"The actual gas fee incurred will be between 20% to 25% of the estimated fee displayed. Though your wallet will only be charged a much smaller amount after you click the confirm button, it is recommended to have more ETH balance than the fee estimate to ensure a smooth transaction.";

0 comments on commit 2140c41

Please sign in to comment.