diff --git a/example/react-app/src/assets/keyIcon.svg b/example/react-app/src/assets/keyIcon.svg index ec51013..0023c66 100644 --- a/example/react-app/src/assets/keyIcon.svg +++ b/example/react-app/src/assets/keyIcon.svg @@ -1,8 +1,5 @@ - - + + \ No newline at end of file diff --git a/example/react-app/src/components/Account.tsx b/example/react-app/src/components/Account.tsx index 762ad01..5752fe2 100644 --- a/example/react-app/src/components/Account.tsx +++ b/example/react-app/src/components/Account.tsx @@ -32,6 +32,7 @@ const Account = () => {
{passkeys.map((passkey, index) => ( -
+
key
-

Passkey #{index + 1}

-

{passkey?.created_at}

-
-
- +

{passkey.name}

+

{passkey.detail1}

+

{passkey.detail2}

))} diff --git a/example/react-app/src/components/WalletServices.tsx b/example/react-app/src/components/WalletServices.tsx index 7ab18ba..fc02b2e 100644 --- a/example/react-app/src/components/WalletServices.tsx +++ b/example/react-app/src/components/WalletServices.tsx @@ -2,10 +2,29 @@ import Card from "./Card"; import { usePlayground } from "../services/playground"; import walletServices from "../assets/walletServices.svg"; import Button from "./Button"; +import { useState } from "react"; const WalletServices = () => { + const [signedMessage, setSignedMessage] = useState(""); + const [signingState, setSigningState] = useState<"success" | "error" | "">(""); const { showCheckout, showWalletUI, showWalletScanner, signMessage } = usePlayground(); + async function onSignMessage() { + try { + const signature = await signMessage(); + setSignedMessage(signature); + setSigningState("success"); + } catch (error) { + console.error(error); + setSigningState("error"); + } finally { + setTimeout(() => { + setSignedMessage(""); + setSigningState(""); + }, 3000); + } + } + return (
@@ -23,9 +42,20 @@ const WalletServices = () => { - + {signedMessage ? ( +
+
{signingState === "success" ? "Signature Success!" : "Signature Failed, Try again"}
+ {signedMessage &&
{signedMessage}
} +
+ ) : ( + + )}
); diff --git a/example/react-app/src/services/playground.tsx b/example/react-app/src/services/playground.tsx index 879e3ee..c33576f 100644 --- a/example/react-app/src/services/playground.tsx +++ b/example/react-app/src/services/playground.tsx @@ -11,6 +11,12 @@ import { shouldSupportPasskey } from "../utils"; import { OpenloginUserInfo } from "@toruslabs/openlogin-utils"; import RPC from "../evm.ethers"; +type PasskeysData = { + id: string; + name: string; + detail1: string; + detail2: string; +}; export interface IPlaygroundContext { address: string; balance: string; @@ -22,7 +28,7 @@ export interface IPlaygroundContext { playgroundConsoleTitle: string; playgroundConsoleData: string; hasPasskeys: boolean; - passkeys: Record[]; + passkeys: PasskeysData[]; isCancelModalOpen: boolean; showRegisterPasskeyModal: boolean; showInfoPopup: boolean; @@ -36,7 +42,7 @@ export interface IPlaygroundContext { showCheckout: () => void; showWalletUI: () => void; showWalletScanner: () => void; - signMessage: () => void; + signMessage: () => Promise; sendTransaction: () => void; toggleCancelModal: (isOpen: boolean) => void; toggleRegisterPasskeyModal: () => void; @@ -69,7 +75,7 @@ export const PlaygroundContext = createContext({ showCheckout: async () => null, showWalletUI: async () => null, showWalletScanner: async () => null, - signMessage: async () => null, + signMessage: async () => "", sendTransaction: async () => null, toggleCancelModal: async () => null, toggleRegisterPasskeyModal: async () => null, @@ -136,7 +142,7 @@ export const Playground = ({ children }: IPlaygroundProps) => { const [showRegisterPasskeyModal, setShowRegisterPasskeyModal] = useState(false); const [showInfoPopup, setShowInfoPopup] = useState(false); const [infoPopupCopy, setInfoPopupCopy] = useState({}); - const [passkeys, setPasskeys] = useState[]>([]); + const [passkeys, setPasskeys] = useState([]); // Dialog const [isCancelModalOpen, setIsCancelModalOpen] = useState(false); @@ -260,14 +266,15 @@ export const Playground = ({ children }: IPlaygroundProps) => { await wsPlugin.showWalletUi(); }; - const signMessage = async () => { + const signMessage = async (): Promise => { if (!provider) { uiConsole("No provider found"); - return; + return ""; } const rpc = new RPC(provider); const result = await rpc.signMessage(); uiConsole(result); + return result; }; const sendTransaction = async () => { @@ -372,9 +379,17 @@ export const Playground = ({ children }: IPlaygroundProps) => { setChainId(`0x${chainId}`); const res = (await plugin?.listAllPasskeys()) as unknown as Record[]; - console.log("passkeys", res); setHasPasskeys(res.length > 0); - setPasskeys(res); + setPasskeys( + res.map((passkey) => { + return { + id: passkey.id, + name: passkey.provider_name, + detail1: `${passkey.browser} ${passkey.browser_version} (${passkey.os})`, + detail2: new Date(passkey.updated_at).toLocaleString(), + }; + }) + ); }); web3authSfa.on(ADAPTER_EVENTS.DISCONNECTED, () => { console.log("sfa:disconnected"); diff --git a/example/react-app/tailwind.config.js b/example/react-app/tailwind.config.js index b7ce707..a0498d8 100644 --- a/example/react-app/tailwind.config.js +++ b/example/react-app/tailwind.config.js @@ -3,6 +3,9 @@ module.exports = { content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], theme: { extend: { + fontSize: { + xxs: "0.625rem", + }, colors: { primary: "#0364FF", purple_100: "#EDEBFE",