-
Notifications
You must be signed in to change notification settings - Fork 393
feat: manual control pos-client #939
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -82,6 +82,9 @@ export default function Home() { | |||||||
| const [merchantAddress, setMerchantAddress] = useState(""); | ||||||||
| const [isSetupComplete, setIsSetupComplete] = useState(false); | ||||||||
| const [tempMerchantAddress, setTempMerchantAddress] = useState(""); | ||||||||
| const [isManualControl, setIsManualControl] = useState(false); | ||||||||
| const [isWalletConnected, setIsWalletConnected] = useState(false); | ||||||||
| const [hasRequestsSent, setHasRequestsSent] = useState(false); | ||||||||
|
|
||||||||
| useEffect(() => { | ||||||||
| // Check for saved merchant address in localStorage | ||||||||
|
|
@@ -91,6 +94,12 @@ export default function Home() { | |||||||
| setIsSetupComplete(true); | ||||||||
| } | ||||||||
|
|
||||||||
| // Check for saved manual mode state | ||||||||
| const savedManualMode = localStorage.getItem("isManualMode"); | ||||||||
| if (savedManualMode !== null) { | ||||||||
| setIsManualControl(savedManualMode === "true"); | ||||||||
| } | ||||||||
|
|
||||||||
| if (appkit) return; | ||||||||
|
|
||||||||
| setPaymentState("connecting"); | ||||||||
|
|
@@ -134,9 +143,10 @@ export default function Home() { | |||||||
| const setupEventListeners = () => { | ||||||||
| if (!posClient) return; | ||||||||
|
|
||||||||
| posClient.on("connected", (connected) => { | ||||||||
| connected = true; | ||||||||
| console.log("connected", connected); | ||||||||
| posClient.on("connected", ({ session }) => { | ||||||||
| console.log("connected", session); | ||||||||
| setIsWalletConnected(true); | ||||||||
| setHasRequestsSent(false); | ||||||||
| toast.success("Customer wallet connected", { | ||||||||
| icon: "🔗", | ||||||||
| duration: 3000, | ||||||||
|
|
@@ -146,6 +156,7 @@ export default function Home() { | |||||||
|
|
||||||||
| posClient.on("disconnected", (disconnected) => { | ||||||||
| console.log("disconnected", disconnected); | ||||||||
| setIsWalletConnected(false); | ||||||||
| toast.error("Customer wallet disconnected", { | ||||||||
| icon: "🔌", | ||||||||
| duration: 3000, | ||||||||
|
|
@@ -193,13 +204,14 @@ export default function Home() { | |||||||
| }); | ||||||||
| appkit?.close(); | ||||||||
| setPaymentState("payment_failed"); | ||||||||
| setIsWalletConnected(false); | ||||||||
| }); | ||||||||
|
|
||||||||
| posClient.on("payment_broadcasted", (paymentBroadcasted) => { | ||||||||
| console.log("paymentBroadcasted", paymentBroadcasted); | ||||||||
| posClient.on("payment_broadcasted", ({ result }) => { | ||||||||
| console.log("paymentBroadcasted", result); | ||||||||
| setTransactionHashes((prev) => { | ||||||||
| const newTransaction: TransactionHash = { | ||||||||
| hash: paymentBroadcasted, | ||||||||
| hash: result, | ||||||||
| status: "pending", | ||||||||
| }; | ||||||||
| const newHashes = [...prev, newTransaction]; | ||||||||
|
|
@@ -224,14 +236,13 @@ export default function Home() { | |||||||
| setPaymentState("payment_requesting"); | ||||||||
| }); | ||||||||
|
|
||||||||
| posClient.on("payment_successful", (paymentSuccessful) => { | ||||||||
| console.log("paymentSuccessful", paymentSuccessful); | ||||||||
| const { transaction } = paymentSuccessful; | ||||||||
| posClient.on("payment_successful", ({ result }) => { | ||||||||
| console.log("paymentSuccessful", result); | ||||||||
|
|
||||||||
| // Update transaction status to successful | ||||||||
| setTransactionHashes((prev) => | ||||||||
| prev.map((tx) => | ||||||||
| tx.hash === transaction | ||||||||
| tx.hash === result | ||||||||
| ? { ...tx, status: "success" as TransactionStatus } | ||||||||
| : tx | ||||||||
| ) | ||||||||
|
|
@@ -351,7 +362,10 @@ export default function Home() { | |||||||
| ); | ||||||||
|
|
||||||||
| try { | ||||||||
| await posClient.createPaymentIntent({ paymentIntents }); | ||||||||
| await posClient.createPaymentIntent({ | ||||||||
| paymentIntents, | ||||||||
| manualControl: isManualControl, | ||||||||
| }); | ||||||||
| toast.success( | ||||||||
| `Payment request created for ${paymentItems.length} item${ | ||||||||
| paymentItems.length > 1 ? "s" : "" | ||||||||
|
|
@@ -401,6 +415,8 @@ export default function Home() { | |||||||
| const resetTransaction = () => { | ||||||||
| setPaymentState("idle"); | ||||||||
| setTransactionHashes([]); | ||||||||
| setIsWalletConnected(false); | ||||||||
| setHasRequestsSent(false); | ||||||||
| // Reset all payment item statuses to idle | ||||||||
| setPaymentItems((prev) => | ||||||||
| prev.map((item) => ({ ...item, status: "idle" as PaymentItemStatus })) | ||||||||
|
|
@@ -410,6 +426,8 @@ export default function Home() { | |||||||
| const restart = (reinit = true) => { | ||||||||
| setPaymentState("idle"); | ||||||||
| setTransactionHashes([]); | ||||||||
| setIsWalletConnected(false); | ||||||||
| setHasRequestsSent(false); | ||||||||
| // Reset all payment item statuses to idle | ||||||||
| setPaymentItems((prev) => | ||||||||
| prev.map((item) => ({ ...item, status: "idle" as PaymentItemStatus })) | ||||||||
|
|
@@ -444,6 +462,33 @@ export default function Home() { | |||||||
| setIsSetupComplete(false); | ||||||||
| }; | ||||||||
|
|
||||||||
| const handleManualModeToggle = () => { | ||||||||
| const newValue = !isManualControl; | ||||||||
| setIsManualControl(newValue); | ||||||||
| localStorage.setItem("isManualControl", String(newValue)); | ||||||||
|
||||||||
| localStorage.setItem("isManualControl", String(newValue)); | |
| localStorage.setItem("isManualControl", String(newValue)); | |
| setHasRequestsSent(false); |
Copilot
AI
Oct 30, 2025
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.
The button lacks an aria-label or accessible text when disabled. Consider adding aria-label=\"Send payment requests to wallet\" to improve screen reader support.
| disabled={hasRequestsSent} | |
| disabled={hasRequestsSent} | |
| aria-label="Send payment requests to wallet" |
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.
Inconsistent localStorage key: saving as 'isManualControl' (line 466) but reading as 'isManualMode'. This will prevent the manual mode preference from persisting correctly across page reloads.