diff --git a/src/evm-aa/signer.ts b/src/evm-aa/signer.ts index 58e4ce4..80e910c 100644 --- a/src/evm-aa/signer.ts +++ b/src/evm-aa/signer.ts @@ -3,6 +3,7 @@ import { type Hex, TypedDataDefinition } from "viem"; import { WebApp } from "@vkruglikov/react-telegram-web-app/lib/core/twa-types"; import { buildConnectTokenAndUrl, buildSignMsgTokenAndUrl, buildSignTypedDataTokenAndUrl } from "../helper"; import { ConnectResp, SignResp, USER_REJECTED, api } from "../api"; +import { IS_ANDROID } from "../env/browser"; export class JoySigner implements SmartAccountSigner { address: Hex; @@ -25,6 +26,14 @@ export class JoySigner implements SmartAccountSigner { } } + onConfirm = (url: string) => { + if (this.webApp?.showConfirm) { + this.webApp.showConfirm("Sign message with JoyID", () => { + this.openUrl(url) + }) + } + } + readonly getAddress: () => Promise = async () => { if (this.address) { return new Promise((resolve) => { @@ -63,7 +72,11 @@ export class JoySigner implements SmartAccountSigner { } else { try { const {token, url} = buildSignMsgTokenAndUrl(this.webApp.initData, this.address, msg); - this.openUrl(url); + if (IS_ANDROID) { + this.onConfirm(url) + } else { + this.openUrl(url); + } const interval = setInterval(() => { api.getTgBotMessage(token).then(({signature}) => { if (signature === USER_REJECTED) { diff --git a/src/hooks/useAccount.ts b/src/hooks/useAccount.ts index 605747d..882c610 100644 --- a/src/hooks/useAccount.ts +++ b/src/hooks/useAccount.ts @@ -1,4 +1,4 @@ -import { useAtomValue, useSetAtom } from 'jotai' +import { atom, useAtomValue, useSetAtom } from 'jotai' import { atomWithStorage } from 'jotai/utils' import { Hex } from 'viem'; @@ -7,6 +7,6 @@ export const useCurrentAddress = () => useAtomValue(addressAtom); export const useUpdateAddress = () => useSetAtom(addressAtom); -const aaAddressAtom = atomWithStorage("joyid:aa-address", undefined); +const aaAddressAtom = atom(undefined); export const useAaAddress = () => useAtomValue(aaAddressAtom); export const useUpdateAaAddress = () => useSetAtom(aaAddressAtom); \ No newline at end of file