-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
227 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Hex } from "viem"; | ||
import { useAllowance } from "./useAllowance"; | ||
import { PendingIcon } from "../icons/PendingIcon"; | ||
import { useClaimGasPass } from "./useClaimGasPass"; | ||
import { Button } from "../ui/Button"; | ||
import { Balance } from "../ui/Balance"; | ||
import { useEffect } from "react"; | ||
import { minGasBalance } from "./common"; | ||
|
||
export type Props = { | ||
isExpanded: boolean; | ||
isActive: boolean; | ||
userAddress: Hex; | ||
}; | ||
|
||
export function Allowance({ isActive, isExpanded, userAddress }: Props) { | ||
const allowance = useAllowance(userAddress); | ||
const claimGasPass = useClaimGasPass(); | ||
|
||
// TODO: improve pending state since this is kicked off automatically and showing a pending button is weird | ||
useEffect(() => { | ||
if (isActive && claimGasPass.status === "idle" && allowance.data && allowance.data.allowance < minGasBalance) { | ||
claimGasPass.mutate(userAddress); | ||
} | ||
}, [allowance.data, claimGasPass, isActive, userAddress]); | ||
|
||
// TODO: show error if allowance fails to load | ||
// TODO: show claim error | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<div className="flex justify-between gap-4"> | ||
<div> | ||
<div>Allowance</div> | ||
<div className="font-mono text-white"> | ||
{allowance.data ? <Balance wei={allowance.data.allowance} /> : <PendingIcon />} | ||
</div> | ||
</div> | ||
<Button | ||
variant={isActive ? "primary" : "secondary"} | ||
className="flex-shrink-0 text-sm p-1 w-28" | ||
pending={claimGasPass.status === "pending"} | ||
onClick={() => claimGasPass.mutate(userAddress)} | ||
> | ||
Top up | ||
</Button> | ||
</div> | ||
{isExpanded ? <p className="text-sm">Your allowance is used to pay for onchain computation.</p> : null} | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,42 @@ | ||
import { useState } from "react"; | ||
import { ConnectedClient } from "../common"; | ||
import { Steps } from "./Steps"; | ||
import { useSteps } from "./useSteps"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
export type Props = { | ||
userClient: ConnectedClient; | ||
}; | ||
|
||
export function ConnectedSteps({ userClient }: Props) { | ||
const steps = useSteps(userClient); | ||
return <Steps steps={steps} />; | ||
|
||
// TODO: detect if just connected and, if so, dismiss | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [selectedStepId, setSelectedStepId] = useState<null | string>(null); | ||
const nextStep = steps.find((step) => step.content != null && !step.isComplete); | ||
const completedSteps = steps.filter((step) => step.isComplete); | ||
const activeStep = | ||
(selectedStepId != null ? steps.find((step) => step.id === selectedStepId) : null) ?? | ||
nextStep ?? | ||
(completedSteps.length < steps.length ? completedSteps.at(-1) : null); | ||
|
||
return ( | ||
<div className="px-8 flex-grow flex flex-col divide-y divide-neutral-800"> | ||
{steps.map((step) => { | ||
const isActive = step === activeStep; | ||
const isExpanded = isActive || completedSteps.length === steps.length; | ||
return ( | ||
// TODO: remove onclick, just for debugging for now | ||
<div | ||
key={step.id} | ||
className={twMerge("py-8 flex flex-col justify-center", isActive ? "flex-grow" : null)} | ||
// onClick={() => setSelectedStepId(step.id)} | ||
> | ||
{step.content({ isActive, isExpanded })} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useAppAccountClient } from "../useAppAccountClient"; | ||
import { Button } from "../ui/Button"; | ||
import { useSetupAppAccount } from "./useSetupAppAccount"; | ||
import { useAccountModal } from "../useAccountModal"; | ||
import { ConnectedClient } from "../common"; | ||
|
||
export type Props = { | ||
isActive: boolean; | ||
isExpanded: boolean; | ||
userClient: ConnectedClient; | ||
registerSpender: boolean; | ||
registerDelegation: boolean; | ||
}; | ||
|
||
export function Session({ isActive, isExpanded, userClient, registerSpender, registerDelegation }: Props) { | ||
const { closeAccountModal } = useAccountModal(); | ||
const appAccountClient = useAppAccountClient(userClient.account.address); | ||
const setup = useSetupAppAccount(); | ||
|
||
const isReady = !registerDelegation && !registerDelegation; | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<div className="flex justify-between gap-4"> | ||
<div> | ||
<div>Session</div> | ||
<div className="font-mono text-white">{isReady ? "Approved" : "Set up"}</div> | ||
</div> | ||
{isReady ? ( | ||
<Button variant={isActive ? "primary" : "secondary"} className="flex-shrink-0 text-sm p-1 w-28" disabled> | ||
{/* TODO: revoke */} | ||
Revoke | ||
</Button> | ||
) : ( | ||
<Button | ||
variant={isActive ? "primary" : "secondary"} | ||
className="flex-shrink-0 text-sm p-1 w-28" | ||
pending={!appAccountClient.data || setup.status === "pending"} | ||
onClick={ | ||
appAccountClient.data | ||
? async () => { | ||
await setup.mutateAsync({ | ||
userClient, | ||
appAccountAddress: appAccountClient.data.account.address, | ||
registerSpender, | ||
registerDelegation, | ||
}); | ||
closeAccountModal(); | ||
} | ||
: undefined | ||
} | ||
> | ||
Approve | ||
</Button> | ||
)} | ||
</div> | ||
{isExpanded ? ( | ||
<p className="text-sm">You can perform actions in this app without interruptions for approvals.</p> | ||
) : null} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.