Skip to content

Commit

Permalink
fix: build (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbulma authored Nov 15, 2023
1 parent 84f4599 commit 274090e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ yarn-error.log*
# local env files

.env
.env\*.local
.env.local

# vercel

Expand Down
1 change: 1 addition & 0 deletions front/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
STACKUP_BUNDLER_API_KEY=""
RELAYER_PRIVATE_KEY=""
NEXT_PUBLIC_RP_DOMAIN="
2 changes: 0 additions & 2 deletions front/.env.local

This file was deleted.

10 changes: 7 additions & 3 deletions front/src/libs/smart-wallet/SmartWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import React, { useContext } from "react";
import { useSmartWalletHook } from "@/libs/smart-wallet/hook/useSmartWalletHook";
import { WagmiConfig, createConfig } from "wagmi";
import { smartWallet } from "./service/smart-wallet";
import { WagmiConfig, configureChains, createConfig } from "wagmi";
import { publicProvider } from "wagmi/providers/public";
import { baseGoerli } from "viem/chains";

type UseSmartWallet = ReturnType<typeof useSmartWalletHook>;

Expand All @@ -18,9 +19,12 @@ export const useWalletConnect = (): UseSmartWallet => {

export function SmartWalletProvider({ children }: { children: React.ReactNode }) {
const smartWalletValue = useSmartWalletHook();

const { publicClient } = configureChains([baseGoerli], [publicProvider()]);

const wagmiConfig = createConfig({
autoConnect: true,
publicClient: smartWallet.client,
publicClient: publicClient,
});

return (
Expand Down
2 changes: 1 addition & 1 deletion front/src/libs/smart-wallet/service/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type SmartWalletActions = {
getUserOperationReceipt: (args: any) => Promise<GetUserOperationReceiptReturnType>;
getIsValidSignature: (args: any) => Promise<GetIsValidSignatureReturnType>;
waitForUserOperationReceipt: (args: any) => Promise<GetUserOperationReceiptReturnType>;
} & PublicActions;
};

export function smartWalletActions(client: Client): SmartWalletActions {
return {
Expand Down
8 changes: 1 addition & 7 deletions front/src/libs/smart-wallet/service/smart-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ export type SmartWalletClient<chain extends Chain | undefined = Chain | undefine
> &
PublicClient;

export const createSmartWalletClient = <
transport extends Transport,
chain extends Chain | undefined = undefined,
>(
parameters: PublicClientConfig<transport, chain>,
): SmartWalletClient => {
export const createSmartWalletClient = (parameters: PublicClientConfig): SmartWalletClient => {
const { key = "public", name = "Smart Wallet Client" } = parameters;
const client = createPublicClient({
...parameters,
Expand All @@ -39,7 +34,6 @@ export const createSmartWalletClient = <

class SmartWallet {
private _client: SmartWalletClient;
private static _instance: SmartWallet;
private _isInitiated: boolean = false;

constructor() {
Expand Down
6 changes: 3 additions & 3 deletions front/src/libs/web-authn/service/web-authn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export class WebAuthn {
const options: PublicKeyCredentialCreationOptions = {
timeout: 60000,
rp: {
name: "hocuspocusxyz",
id: "f445-2001-861-8ac1-ad50-b08d-6c0b-7168-132a.ngrok-free.app",
name: "passkeys-4337/smart-wallet",
id: window.location.hostname,
},
user: {
id: this._generateRandomBytes(),
Expand Down Expand Up @@ -127,7 +127,7 @@ export class WebAuthn {
challenge: challenge
? Buffer.from(challenge.slice(2), "hex")
: Uint8Array.from("random-challenge", (c) => c.charCodeAt(0)),
rpId: "f445-2001-861-8ac1-ad50-b08d-6c0b-7168-132a.ngrok-free.app",
rpId: window.location.hostname,
userVerification: "preferred",
} as PublicKeyCredentialRequestOptions;

Expand Down
13 changes: 10 additions & 3 deletions front/src/providers/MeProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export type Me = {
function useMeHook() {
const [isLoading, setIsLoading] = useState(false);
const [me, setMe] = useState<Me | null>(null);
const [isReturning, setIsReturning] = useState(
Boolean(localStorage.getItem("hocuspocus.returning")),
);
const [isReturning, setIsReturning] = useState(false);

function disconnect() {
localStorage.removeItem("hocuspocus.me");
Expand Down Expand Up @@ -93,6 +91,15 @@ function useMeHook() {
}
setMe(JSON.parse(me));
}, []);

useEffect(() => {
const returning = localStorage.getItem("hocuspocus.returning");
if (!returning) {
return;
}
setIsReturning(true);
}, []);

return {
isLoading,
me,
Expand Down
8 changes: 6 additions & 2 deletions front/src/providers/ModalProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ export function ModalProvider({ children }: { children: React.ReactNode }) {
setIsPortalMounted(true);
}, []);

const radixElement = document.getElementsByClassName("radix-themes")[0];
let radixElement: HTMLElement | null = null;
if (isPortalMounted) {
radixElement = document.getElementsByClassName("radix-themes")[0] as HTMLElement;
}

return (
<ModalContext.Provider value={modalValue}>
{children}
{isPortalMounted && (
{isPortalMounted && radixElement && (
<PortalContainer $isOpen={modalValue.isOpen} container={radixElement as HTMLElement}>
<Overlay $isOpen={modalValue.isBackdrop} onClick={() => modalValue.close()} />
<Modal $isOpen={modalValue.isOpen}>{modalValue.content}</Modal>
Expand Down
27 changes: 12 additions & 15 deletions front/src/providers/TransactionProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ const useTxHook = () => {
const [txs, setTxs] = useState<Array<Log> | null>(null);
const [loading, setLoading] = useState<boolean>(false);

const { keyId } = useMe();

const getLastTxs = useCallback(
async (keyId: Hex) => {
setLoading(true);
const res = await fetch(`/api/users/${keyId}/txs`);
const resJson = await res.json();
setTxs(resJson.logs);
setLoading(false);
},
[keyId],
);
const { me } = useMe();

const getLastTxs = useCallback(async (keyId: Hex) => {
setLoading(true);
const res = await fetch(`/api/users/${keyId}/txs`);
const resJson = await res.json();
setTxs(resJson.logs);
setLoading(false);
}, []);

useEffect(() => {
if (!keyId) return;
getLastTxs(keyId);
}, [keyId, getLastTxs]);
if (!me?.keyId) return;
getLastTxs(me.keyId);
}, [me?.keyId, getLastTxs]);

useEffect(() => {}, [txs]);

Expand Down

0 comments on commit 274090e

Please sign in to comment.