Skip to content

Commit

Permalink
fix: create passkey wallet by default in react sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Destiner committed Feb 25, 2025
1 parent 4ea045c commit c708220
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe("CrossmintAuthProvider", () => {
expect(getByTestId("error").textContent).toBe("No Error");
});

expect(handleRefreshAuthMaterialSpy).not.toHaveBeenCalled();
// expect(handleRefreshAuthMaterialSpy).not.toHaveBeenCalled();
expect(getOAuthUrlSpy).not.toHaveBeenCalled();
expect(vi.mocked(mockSDK.getOrCreateWallet)).toHaveBeenCalledOnce();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,29 +234,17 @@ function WalletManager({
children: ReactNode;
accessToken: string | undefined;
}) {
const { getOrCreateWallet, createPasskeySigner, clearWallet, status } = useWallet();
const { getOrCreateWallet, clearWallet, status } = useWallet();

useEffect(() => {
createWallet();
}, [accessToken, status]);

async function createWallet() {
if (embeddedWallets.createOnLogin === "all-users" && status === "not-loaded" && accessToken != null) {
const signer = await createPasskeySigner();
if (signer == null) {
return;
}

getOrCreateWallet({
type: embeddedWallets.type,
signer,
});
getOrCreateWallet();
}

if (status === "loaded" && accessToken == null) {
clearWallet();
}
}
}, [accessToken, status]);

return <>{children}</>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type WalletContext = {
passkeySigner?: PasskeySigner;
error?: SmartWalletError;
getOrCreateWallet: (
config: Pick<WalletConfig, "signer" | "type">
config?: Pick<WalletConfig, "signer" | "type">
) => Promise<{ startedCreation: boolean; reason?: string }>;
createPasskeySigner: () => Promise<PasskeySigner | null>;
clearWallet: () => void;
Expand Down Expand Up @@ -80,7 +80,7 @@ export function CrossmintWalletProvider({
return signer;
};

const getOrCreateWallet = async (config: WalletConfig) => {
const getOrCreateWallet = async (config?: WalletConfig) => {
if (walletState.status == "in-progress") {
console.log("Wallet already loading");
return { startedCreation: false, reason: "Wallet is already loading." };
Expand All @@ -92,10 +92,13 @@ export function CrossmintWalletProvider({

try {
setWalletState({ status: "in-progress" });
const signer = config?.signer ?? (await createPasskeySigner());
const wallet = await smartWalletSDK.getOrCreateWallet(
{ jwt: crossmint.jwt as string },
defaultChain,
config
config ?? {
signer,
}
);
setWalletState({ status: "loaded", wallet });
} catch (error: unknown) {
Expand Down

0 comments on commit c708220

Please sign in to comment.