Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed May 2, 2024
1 parent 6e10677 commit 8565421
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 102 deletions.
6 changes: 4 additions & 2 deletions packages/account-kit/src/AccountModalErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export function AccountModalErrorBoundary({ children }: Props) {
}}
className="group aria-busy:pointer-events-none self-end flex items-center gap-1"
>
<PendingIcon className="transition opacity-0 group-aria-busy:opacity-100 text-xs text-neutral-500" />
<span className="text-sm text-neutral-500 group-hover:text-black">Retry?</span>
<PendingIcon className="transition opacity-0 group-aria-busy:opacity-100 text-xs text-neutral-500 dark:text-neutral-400" />
<span className="text-sm text-neutral-500 dark:text-neutral-400 group-hover:text-black dark:group-hover:text-white">
Retry?
</span>
</button>
) : null}
</div>
Expand Down
12 changes: 9 additions & 3 deletions packages/account-kit/src/AccountModalSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ import { CheckIcon } from "./icons/CheckIcon";

type StepNavItemProps = {
isActive: boolean;
canComplete: boolean;
isComplete: boolean;
onClick: () => void;
label: string;
};

function StepNavItem({ isActive, isComplete, onClick, label }: StepNavItemProps) {
function StepNavItem({ isActive, canComplete, isComplete, onClick, label }: StepNavItemProps) {
return (
<button
type="button"
// TODO: use radix menu or use aria menu item tags?
aria-disabled={!canComplete}
className={twMerge(
"p-5 font-medium outline-none text-left transition flex gap-4",
isActive ? "bg-neutral-100 text-black" : "text-neutral-600 hover:bg-neutral-100",
isActive ? "dark:bg-neutral-800 dark:text-white" : "dark:text-neutral-400 dark:hover:bg-neutral-800",
"aria-disabled:pointer-events-none",
isActive ? "bg-neutral-100 text-black" : "text-neutral-600 aria-disabled:text-neutral-400 hover:bg-neutral-100",
isActive
? "dark:bg-neutral-800 dark:text-white"
: "dark:text-neutral-400 dark:aria-disabled:text-neutral-600 dark:hover:bg-neutral-800",
)}
onClick={onClick}
>
Expand Down Expand Up @@ -47,6 +52,7 @@ export function AccountModalSidebar() {
<StepNavItem
key={step.id}
isActive={step.id === activeStep}
canComplete={step.canComplete}
isComplete={step.isComplete}
onClick={() => setStep(step.id)}
label={step.label}
Expand Down
10 changes: 5 additions & 5 deletions packages/account-kit/src/ErrorNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export function ErrorNotice({ title: initialTitle, error }: Props) {
return (
<div
className={twMerge(
"text-sm p-3 border-l-4",
"bg-red-100 border-red-500 text-red-900",
"dark:bg-red-100 dark:border-red-500 dark:text-red-900",
"text-sm border-l-4 border-red-500",
"bg-red-100 text-red-900",
"dark:bg-red-900 dark:text-red-50",
)}
>
<div className="font-semibold">{title}</div>
<div className="-mb-3 pb-3 whitespace-break-spaces break-all max-h-32 overflow-y-scroll">{message}</div>
<div className="p-3 font-semibold">{title}</div>
<div className="px-3 whitespace-break-spaces break-all max-h-32 overflow-y-scroll">{message}</div>
</div>
);
}
82 changes: 0 additions & 82 deletions packages/account-kit/src/steps/deposit/DepositContent.tsx

This file was deleted.

86 changes: 76 additions & 10 deletions packages/account-kit/src/steps/deposit/DepositStep.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,82 @@
import { useGasTankBalance } from "../../useGasTankBalance";
import { PendingIcon } from "../../icons/PendingIcon";
import { useIsGasSpender } from "../../useIsGasSpender";
import { DepositContent } from "./DepositContent";
import { AccountModalTitle } from "../../AccoutModalTitle";
import { AccountModalSection } from "../../AccountModalSection";
import { GasBalanceSection } from "./GasBalanceSection";
import { useState } from "react";
import { DepositMethod } from "./common";
import { useSourceChains } from "./useSourceChains";
import { useConfig } from "../../AccountKitConfigProvider";
import { DepositMethodForm } from "./DepositMethodForm";
import { useDeposits } from "./useDeposits";
import { BridgeDepositStatus } from "./BridgeDepositStatus";
import { assertExhaustive } from "@latticexyz/common/utils";
import { RelayDepositStatus } from "./RelayDepositStatus";

export function DepositStep() {
const { gasTankBalance } = useGasTankBalance();
const { isGasSpender } = useIsGasSpender();
const { chainId: appChainId } = useConfig();
const [sourceChainId, setSourceChainId] = useState(appChainId);
const [amount, setAmount] = useState<bigint | undefined>();
const [selectedDepositMethod, setSelectedDepositMethod] = useState<DepositMethod>("transfer");

if (gasTankBalance == null || isGasSpender == null) {
// TODO: better load state
return <PendingIcon />;
const sourceChains = useSourceChains();
const sourceChain = sourceChains.find((c) => c.id === sourceChainId) ?? sourceChains.find((c) => c.id === appChainId);

// TODO: do we need a better error here or can we just guarantee this data in some way?
if (!sourceChain) {
throw new Error(`Expected a source chain, but could not find one. Is Wagmi configured with chain ${appChainId}?`);
}

return <DepositContent />;
const depositMethod = sourceChain.depositMethods.includes(selectedDepositMethod)
? selectedDepositMethod
: sourceChain.depositMethods[0];

const { deposits, removeDeposit } = useDeposits();

return (
<>
<AccountModalTitle title="Gas balance" />

<GasBalanceSection />

<AccountModalSection>
<div className="flex flex-col py-5 gap-5">
<p className="px-5">
Top up your gas balance from your chain of choice. Prepaid gas lets you interact with this app without
wallet popups.
</p>
<DepositMethodForm
sourceChain={sourceChain}
setSourceChainId={setSourceChainId}
amount={amount}
setAmount={setAmount}
depositMethod={depositMethod}
setDepositMethod={setSelectedDepositMethod}
/>
{/* TODO: make deposits dismissable */}
{deposits.length > 0 ? (
<div className="flex flex-col gap-1 px-5">
{deposits.map((deposit) => {
switch (deposit.type) {
case "bridge":
return (
<BridgeDepositStatus
key={deposit.uid}
{...deposit}
onDismiss={() => removeDeposit(deposit.uid)}
/>
);
case "relay":
return (
<RelayDepositStatus key={deposit.uid} {...deposit} onDismiss={() => removeDeposit(deposit.uid)} />
);
default:
// TODO: wtf TS y u no narrow
assertExhaustive(deposit.type);
}
})}
</div>
) : null}
</div>
</AccountModalSection>
</>
);
}

0 comments on commit 8565421

Please sign in to comment.