Skip to content

Commit

Permalink
Support login with no policies
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Jan 24, 2025
1 parent a7147f5 commit 31007b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ const controller = new ControllerConnector({
// slot: "profile-example",
slot: "ryomainnet",
preset: "dope-wars",
namespace: "dopewars",
// namespace: "dopewars",
// slot: "eternum-prod",
// preset: "eternum",
Expand Down
14 changes: 2 additions & 12 deletions packages/keychain/src/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export function Home() {
controller.isRequestedSession(policies).then((isRequestedSession) => {
setHasSessionForPolicies(isRequestedSession);
});
} else {
setHasSessionForPolicies(undefined);
} else if (controller && !policies) {
setHasSessionForPolicies(true);
}
}, [controller, policies]);

Expand Down Expand Up @@ -80,16 +80,6 @@ export function Home() {
return <></>;
}

if (hasSessionForPolicies) {
context.resolve({
code: ResponseCodes.SUCCESS,
address: controller.address,
policies: policies,
});

return <></>;
}

// TODO: show missing policies if mismatch
return (
<CreateSession
Expand Down
22 changes: 15 additions & 7 deletions packages/keychain/src/components/provider/posthog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropsWithChildren, useEffect } from "react";
import { PropsWithChildren, useEffect, useState } from "react";
import { PostHogContext, PostHogWrapper } from "@/context/posthog";
import { useConnectionValue } from "@/hooks/connection";

Expand All @@ -11,17 +11,25 @@ export function PostHogProvider({ children }: PropsWithChildren) {
autocapture: false,
});

// Track the last identified address
const [lastIdentifiedAddress, setLastIdentifiedAddress] = useState<string>();

useEffect(() => {
if (controller) {
posthog.identify(controller.username(), {
address: controller.address,
class: controller.classHash(),
chainId: controller.chainId,
});
// Only identify if this is a new address
if (lastIdentifiedAddress !== controller.address) {
posthog.identify(controller.username(), {
address: controller.address,
class: controller.classHash(),
chainId: controller.chainId,
});
setLastIdentifiedAddress(controller.address);
}
} else {
posthog.reset();
setLastIdentifiedAddress(undefined);
}
}, [posthog, controller]);
}, [posthog, controller, lastIdentifiedAddress]);

useEffect(() => {
if (origin) {
Expand Down

0 comments on commit 31007b5

Please sign in to comment.