Skip to content

Commit

Permalink
Slot session request deployment (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Jul 24, 2024
1 parent de5ce7d commit f02aef0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/keychain/src/pages/slot/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react";
import { PageLoading } from "components/Loading";
import dynamic from "next/dynamic";
import { useDeploy } from "hooks/deploy";

type SessionQueryParams = Record<string, string> & {
callback_uri: string;
Expand All @@ -24,6 +25,7 @@ function CreateSession() {

const { controller, setController, policies, origin, chainId, rpcUrl } =
useConnection();
const { deployRequest } = useDeploy();

// Fetching account status for displaying the loading screen
const [isFetching, setIsFetching] = useState(false);
Expand Down Expand Up @@ -75,7 +77,17 @@ function CreateSession() {
throw new Error("Callback URI is missing");
}

onSlotCallback(session);
// Request for deployment to ensure account exists
deployRequest(controller.username)
.catch((e) => {
if (!e.message.includes("account already deployed")) {
console.error("failed to request deployment", e);
router.replace(`/slot/auth/failure`);
}
})
.finally(() => {
onSlotCallback(session);
});
},
[queries.callback_uri, origin, controller, onSlotCallback],
);
Expand Down

0 comments on commit f02aef0

Please sign in to comment.