Skip to content

Commit

Permalink
dismiss deposit status
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Apr 30, 2024
1 parent 0a300ec commit 65df37f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { formatBalance } from "./formatBalance";
import { useChains } from "wagmi";
import { BridgeDeposit } from "./useDeposits";

export type Props = BridgeDeposit;
export type Props = BridgeDeposit & { onDismiss: () => void };

export function BridgeDepositStatus({
amount,
Expand All @@ -15,6 +15,7 @@ export function BridgeDepositStatus({
receiptL2: receiptL2Promise,
start,
estimatedTime,
onDismiss,
}: Props) {
const chains = useChains();
const chainL1 = chains.find((chain) => chain.id === chainL1Id)!;
Expand All @@ -37,6 +38,7 @@ export function BridgeDepositStatus({
duration: estimatedTime,
elapsed: Math.min(estimatedTime, Date.now() - start.getTime()),
}}
onDismiss={onDismiss}
>
{(() => {
const blockExplorerL1 = chainL1.blockExplorers?.default.url;
Expand Down
7 changes: 3 additions & 4 deletions packages/account-kit/src/steps/deposit/ChainSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { twMerge } from "tailwind-merge";
import * as Select from "@radix-ui/react-select";
import { useFrame } from "../../ui/FrameProvider";
import { useAccount, useChains } from "wagmi";
import { useAccount } from "wagmi";
import { useTheme } from "../../useTheme";
import { ChevronUpIcon } from "../../icons/ChevronUpIcon";
import { ChevronDownIcon } from "../../icons/ChevronDownIcon";
Expand All @@ -18,7 +18,6 @@ export type Props = {
export function ChainSelect({ value, onChange }: Props) {
const theme = useTheme();
const { frame } = useFrame();
const chains = useChains();
const userAccount = useAccount();

const sourceChains = useSourceChains();
Expand All @@ -30,7 +29,7 @@ export function ChainSelect({ value, onChange }: Props) {
onValueChange={(value) => {
// TODO: figure out why onValueChange triggers twice, once with value and once without
if (value) {
const chain = chains.find((chain) => chain.id.toString() === value);
const chain = sourceChains.find((chain) => chain.id.toString() === value);
if (!chain) throw new Error(`Unknown chain selected: ${value}`);
onChange(chain.id);
}
Expand Down Expand Up @@ -59,7 +58,7 @@ export function ChainSelect({ value, onChange }: Props) {

{frame.contentDocument ? (
<Select.Portal container={frame.contentDocument.body}>
<Select.Content position="popper" className="w-80 mt-1">
<Select.Content position="popper" className="w-80 mt-1 animate-in fade-in slide-in-from-top-2">
<Select.Viewport>
<Select.Group
className={twMerge(
Expand Down
14 changes: 11 additions & 3 deletions packages/account-kit/src/steps/deposit/DepositContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function DepositContent() {
? selectedDepositMethod
: sourceChain.depositMethods[0];

const { deposits } = useDeposits();
const { deposits, removeDeposit } = useDeposits();

return (
<>
Expand Down Expand Up @@ -57,9 +57,17 @@ export function DepositContent() {
{deposits.map((deposit) => {
switch (deposit.type) {
case "bridge":
return <BridgeDepositStatus key={deposit.uid} {...deposit} />;
return (
<BridgeDepositStatus
key={deposit.uid}
{...deposit}
onDismiss={() => removeDeposit(deposit.uid)}
/>
);
case "relay":
return <RelayDepositStatus key={deposit.uid} {...deposit} />;
return (
<RelayDepositStatus key={deposit.uid} {...deposit} onDismiss={() => removeDeposit(deposit.uid)} />
);
default:
// TODO: wtf TS y u no narrow
assertExhaustive(deposit.type);
Expand Down
38 changes: 29 additions & 9 deletions packages/account-kit/src/steps/deposit/DepositStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,53 @@ import { ReactNode, useEffect, useState } from "react";
import { twMerge } from "tailwind-merge";
import { CheckIcon } from "../../icons/CheckIcon";
import { WarningIcon } from "../../icons/WarningIcon";
import { CloseIcon } from "../../icons/CloseIcon";

export type Props = {
status: "pending" | "success" | "error";
progress: {
duration: number;
elapsed: number;
};
onDismiss: () => void;
children: ReactNode;
};

export function DepositStatus({ status, progress, children }: Props) {
export function DepositStatus({ status, progress, children, onDismiss }: Props) {
const [appear, setAppear] = useState(false);
useEffect(() => {
setAppear(true);
}, []);

return (
<div className="bg-white dark:bg-neutral-900 flex flex-col">
<div className="group bg-white dark:bg-neutral-900 flex flex-col animate-in fade-in slide-in-from-bottom-2 animate-out fade-out">
<div className="p-2 text-sm flex items-center gap-2">
<div className="flex-grow">{children}</div>
{status === "success" ? (
<CheckIcon className="flex-shrink-0 text-green-600" />
) : status === "error" ? (
<WarningIcon className="flex-shrink-0 text-amber-500" />
) : (
<PendingIcon className="flex-shrink-0 text-neutral-400 dark:text-neutral-500 transition" />
)}
<div className="flex-shrink-0 grid">
<span className="col-start-1 row-start-1 transition opacity-100 group-hover:opacity-0 group-hover:pointer-events-none">
{status === "success" ? (
<CheckIcon className="text-green-600" />
) : status === "error" ? (
<WarningIcon className="text-amber-500" />
) : (
<PendingIcon className="text-neutral-400 dark:text-neutral-500 transition" />
)}
</span>
<button
type="button"
className={twMerge(
"col-start-1 row-start-1 flex items-center justify-center transition",
"opacity-0 pointer-events-none",
"group-hover:opacity-100 group-hover:pointer-events-auto",
"text-neutral-400 hover:text-black",
"dark:text-neutral-500 hover:text-white",
)}
title="Dismiss"
onClick={onDismiss}
>
<CloseIcon />
</button>
</div>
</div>

<div className="w-full h-[2px] -mt-full overflow-clip">
Expand Down
13 changes: 11 additions & 2 deletions packages/account-kit/src/steps/deposit/RelayDepositStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import { formatBalance } from "./formatBalance";
import { useChains } from "wagmi";
import { RelayDeposit } from "./useDeposits";

export type Props = RelayDeposit;
export type Props = RelayDeposit & { onDismiss: () => void };

export function RelayDepositStatus({ amount, chainL1Id, chainL2Id, start, estimatedTime, depositPromise }: Props) {
export function RelayDepositStatus({
amount,
chainL1Id,
chainL2Id,
start,
estimatedTime,
depositPromise,
onDismiss,
}: Props) {
const chains = useChains();
const chainL1 = chains.find((chain) => chain.id === chainL1Id)!;
const chainL2 = chains.find((chain) => chain.id === chainL2Id)!;
Expand All @@ -23,6 +31,7 @@ export function RelayDepositStatus({ amount, chainL1Id, chainL2Id, start, estima
duration: estimatedTime,
elapsed: Math.min(estimatedTime, Date.now() - start.getTime()),
}}
onDismiss={onDismiss}
>
{(() => {
// const blockExplorerL1 = chainL1.blockExplorers?.default.url;
Expand Down
9 changes: 8 additions & 1 deletion packages/account-kit/src/steps/deposit/useDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,18 @@ export function useDeposits() {
}));
}, []);

const removeDeposit = useCallback((uid: string) => {
store.setState((state) => ({
deposits: state.deposits.filter((deposit) => deposit.uid !== uid),
}));
}, []);

return useMemo(
() => ({
deposits,
addDeposit,
removeDeposit,
}),
[addDeposit, deposits],
[addDeposit, deposits, removeDeposit],
);
}

0 comments on commit 65df37f

Please sign in to comment.