Skip to content

Commit

Permalink
add confirm for android aa
Browse files Browse the repository at this point in the history
  • Loading branch information
duanyytop committed Dec 22, 2023
1 parent 27f760d commit 6b4abe0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/evm-aa/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Hex> = async () => {
if (this.address) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -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<SignResp>(token).then(({signature}) => {
if (signature === USER_REJECTED) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAtomValue, useSetAtom } from 'jotai'
import { atom, useAtomValue, useSetAtom } from 'jotai'
import { atomWithStorage } from 'jotai/utils'
import { Hex } from 'viem';

Expand All @@ -7,6 +7,6 @@ export const useCurrentAddress = () => useAtomValue(addressAtom);
export const useUpdateAddress = () => useSetAtom(addressAtom);


const aaAddressAtom = atomWithStorage<Hex | undefined>("joyid:aa-address", undefined);
const aaAddressAtom = atom<Hex | undefined>(undefined);
export const useAaAddress = () => useAtomValue(aaAddressAtom);
export const useUpdateAaAddress = () => useSetAtom(aaAddressAtom);

0 comments on commit 6b4abe0

Please sign in to comment.