-
Notifications
You must be signed in to change notification settings - Fork 45
feat(session): spending limit step for register session #2303
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| scarb 2.9.4 | ||
| starknet-foundry 0.38.3 | ||
| nodejs v20.11.1 | ||
| nodejs 20.19.5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { | |
| type ContractType, | ||
| type ParsedSessionPolicies, | ||
| useCreateSession, | ||
| hasApprovalPolicies, | ||
| } from "@/hooks/session"; | ||
| import { Button, LayoutContent, SliderIcon } from "@cartridge/ui"; | ||
| import { useCallback, useEffect, useMemo, useState } from "react"; | ||
|
|
@@ -18,6 +19,7 @@ import { | |
| TransactionExecutionStatus, | ||
| TransactionFinalityStatus, | ||
| } from "starknet"; | ||
| import { SpendingLimitPage } from "./SpendingLimitPage"; | ||
|
|
||
| const requiredPolicies: Array<ContractType> = ["VRF"]; | ||
|
|
||
|
|
@@ -52,9 +54,28 @@ const RegisterSessionLayout = ({ | |
| const [transactions, setTransactions] = useState<Call[] | undefined>( | ||
| undefined, | ||
| ); | ||
| const [isConnecting, setIsConnecting] = useState(false); | ||
| const [error, setError] = useState<Error | undefined>(); | ||
|
|
||
| const { duration, isEditable, onToggleEditable } = useCreateSession(); | ||
|
|
||
| const hasTokenApprovals = useMemo( | ||
| () => hasApprovalPolicies(policies), | ||
| [policies], | ||
| ); | ||
|
|
||
| const defaultStep = useMemo<"summary" | "spending-limit">(() => { | ||
| return policies?.verified && hasTokenApprovals | ||
| ? "spending-limit" | ||
| : "summary"; | ||
| }, [policies?.verified, hasTokenApprovals]); | ||
|
|
||
| const [step, setStep] = useState<"summary" | "spending-limit">(defaultStep); | ||
|
|
||
| useEffect(() => { | ||
| setStep(defaultStep); | ||
| }, [defaultStep]); | ||
|
|
||
| const expiresAt = useMemo(() => { | ||
| return duration + now(); | ||
| }, [duration]); | ||
|
|
@@ -83,31 +104,60 @@ const RegisterSessionLayout = ({ | |
| return; | ||
| } | ||
|
|
||
| const { transaction_hash } = await controller.registerSession( | ||
| origin, | ||
| expiresAt, | ||
| policies, | ||
| publicKey, | ||
| maxFee, | ||
| ); | ||
|
|
||
| await controller.provider.waitForTransaction(transaction_hash, { | ||
| retryInterval: 1000, | ||
| successStates: [ | ||
| TransactionExecutionStatus.SUCCEEDED, | ||
| TransactionFinalityStatus.ACCEPTED_ON_L2, | ||
| ], | ||
| }); | ||
|
|
||
| onConnect(transaction_hash, expiresAt); | ||
| try { | ||
| setError(undefined); | ||
| setIsConnecting(true); | ||
|
|
||
| const { transaction_hash } = await controller.registerSession( | ||
| origin, | ||
| expiresAt, | ||
| policies, | ||
| publicKey, | ||
| maxFee, | ||
| ); | ||
|
|
||
| await controller.provider.waitForTransaction(transaction_hash, { | ||
| retryInterval: 1000, | ||
| successStates: [ | ||
| TransactionExecutionStatus.SUCCEEDED, | ||
| TransactionFinalityStatus.ACCEPTED_ON_L2, | ||
| ], | ||
| }); | ||
|
|
||
| onConnect(transaction_hash, expiresAt); | ||
| } catch (e) { | ||
| setError(e as Error); | ||
| } finally { | ||
| setIsConnecting(false); | ||
| } | ||
| }, | ||
| [controller, expiresAt, policies, publicKey, onConnect, origin], | ||
| ); | ||
|
|
||
| // Handler for the spending limit page to proceed to registration | ||
| const handleSpendingLimitConfirm = useCallback(() => { | ||
| if (hasTokenApprovals && step === "spending-limit") { | ||
| setStep("summary"); | ||
| } | ||
| }, [hasTokenApprovals, step]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirm and Back buttons perform identical actionsMedium Severity The 🔬 Verification TestWhy verification test was not possible: This is a React component logic bug that requires UI interaction to demonstrate. The bug can be verified by code inspection: both Additional Locations (1) |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SpendingLimitPage unnecessarily blocked by transactions loading checkLow Severity The 🔬 Verification TestWhy verification test was not possible: This is a React component render order issue that manifests as a UX delay. The bug can be verified by code inspection: Additional Locations (1) |
||
| if (!transactions) { | ||
| return <div>Loading</div>; | ||
| } | ||
|
|
||
| // Show spending limit page for verified sessions with token approvals | ||
| if (hasTokenApprovals && step === "spending-limit") { | ||
| return ( | ||
| <SpendingLimitPage | ||
| policies={policies} | ||
| isConnecting={isConnecting} | ||
| error={error} | ||
| onBack={() => setStep("summary")} | ||
| onConnect={handleSpendingLimitConfirm} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <ExecutionContainer | ||
| title="Register Session" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration error swallowing prevents display in ExecutionContainer
The
onRegisterSessionfunction catches errors but does not re-throw them, causing theExecutionContainerto assume the operation succeeded. Consequently, errors occurring during registration are swallowed and not displayed to the user on the summary page, as the localerrorstate is only consumed by the non-renderedSpendingLimitPage.Additional Locations (1)
packages/keychain/src/components/connect/RegisterSession.tsx#L160-L197