Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jwhiles committed Jan 23, 2025
1 parent ef17829 commit 65f2e68
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 48 deletions.
65 changes: 22 additions & 43 deletions src/components/AuthLogin/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import {
AUTH_WALLET_SESSION_NAME,
AUTH_WALLET_USER_PLAN,
} from "@site/src/lib/siwsrp/auth";
import {
REQUEST_PARAMS,
} from "@site/src/lib/constants";
import { REQUEST_PARAMS } from "@site/src/lib/constants";
import { MetamaskProviderContext } from "@site/src/theme/Root";

Modal.setAppElement("#__docusaurus");
Expand All @@ -39,7 +37,7 @@ export enum AUTH_LOGIN_STEP {
export enum WALLET_LINK_TYPE {
NO = "NO",
ONE = "ONE",
MULTIPLE = "MULTIPLE"
MULTIPLE = "MULTIPLE",
}

const ConnectingModal = () => {
Expand Down Expand Up @@ -161,60 +159,46 @@ const AuthModal = ({
const { pathname } = location;

const login = async () => {
console.log('in login')
setStep(AUTH_LOGIN_STEP.CONNECTING);
try {

// This will cause problems on mobile
// check what this value is on mobile. Do we need to do something different?
// if (!sdk.isExtensionActive()) {
// setOpen(false);
// }

// Try to connect wallet first
const accounts = await sdk.connect();
console.log({ accounts })

console.log('before accounts if')
if (accounts && accounts.length > 0) {
setMetaMaskAccount(accounts[0]);
fetchLineaEns(accounts[0]);
const provider = sdk.getProvider();
setMetaMaskProvider(provider);
}

console.log('before get customProvider')
const customProvider = sdk.getProvider()
console.log('customProvider', customProvider)
const customProvider = sdk.getProvider();
// Call Profile SDK API to retrieve Hydra Access Token & Wallet userProfile
// Hydra Access Token will be used to fetch Infura API
console.log('before authenticateAndAuthorize')
const { accessToken, userProfile } = await authenticateAndAuthorize(
VERCEL_ENV as string,
// @ts-ignore
window.ethereum,
customProvider
);
console.log('accessToken', accessToken)
console.log('userProfile', userProfile)

console.log("before loginResponse")

const loginResponse = await (
await fetch(
`${DASHBOARD_URL}/api/wallet/login`,
{
...REQUEST_PARAMS("POST", {
hydra_token: accessToken,
token: "true",
}),
body: JSON.stringify({
profileId: userProfile.profileId,
redirect_to: window.location.href,
}),
},
)
await fetch(`${DASHBOARD_URL}/api/wallet/login`, {
...REQUEST_PARAMS("POST", {
hydra_token: accessToken,
token: "true",
}),
body: JSON.stringify({
profileId: userProfile.profileId,
redirect_to: window.location.href,
}),
})
).json();

console.log('loginResponse', loginResponse)

if (!loginResponse) throw new Error("Something went wrong");

const { data, session, token } = loginResponse;
Expand All @@ -228,7 +212,7 @@ const AuthModal = ({
mmAuthSession: sessionStorage.getItem(AUTH_WALLET_SESSION_NAME),
walletPairing: data.pairing,
token: true,
}),
})
).toString("base64");

const walletAuthUrl = `${DASHBOARD_URL}/login?mm_auth=${mm_auth}&redirect_to=${session.redirect_to}`;
Expand All @@ -251,10 +235,10 @@ const AuthModal = ({
if (data.mfa?.enabled) {
const mm_auth = Buffer.from(
JSON.stringify({
step: 'verify',
step: "verify",
mmAuthSession: sessionStorage.getItem(AUTH_WALLET_SESSION_NAME),
dashboardSessionToken: token
}),
dashboardSessionToken: token,
})
).toString("base64");

const walletAuthUrl = `${DASHBOARD_URL}/login?mm_auth=${mm_auth}&redirect_to=${session.redirect_to}`;
Expand Down Expand Up @@ -289,7 +273,7 @@ const AuthModal = ({
`${DASHBOARD_URL}/api/v1/users/${userId}/projects`,
{
...REQUEST_PARAMS("GET", { Authorization: `Bearer ${token}` }),
},
}
);
const {
result: { projects },
Expand All @@ -301,7 +285,7 @@ const AuthModal = ({
`${DASHBOARD_URL}/api/v1/users/${userId}`,
{
...REQUEST_PARAMS("GET", { Authorization: `Bearer ${token}` }),
},
}
);
const {
result: {
Expand All @@ -324,12 +308,7 @@ const AuthModal = ({
}
};

console.log('just before use effect')

useEffect(() => {
console.log('in use effect')
console.log('open', open)
console.log('step', step)
if (open && step == AUTH_LOGIN_STEP.CONNECTING) {
(async () => {
try {
Expand Down
5 changes: 1 addition & 4 deletions src/components/Faucet/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export default function Hero({
} = useContext(MetamaskProviderContext);


// const isMobile = sdk.platformManager.isMobile;
const isMobile = true
console.log(sdk.platformManager)
const isMobile = sdk.platformManager?.isMobile ?? false;
const isExtensionActive = sdk.isExtensionActive();

const showInstallButton = !isExtensionActive && !isMobile;
Expand All @@ -57,7 +55,6 @@ export default function Hero({
responseMsg: null,
timestamp: Date.now(),
});
console.log("gon trigg");
metaMaskWalletIdConnectHandler();
};

Expand Down
1 change: 0 additions & 1 deletion src/theme/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export const LoginProvider = ({ children }) => {
};

const metaMaskWalletIdConnectHandler = useCallback(async () => {
console.log("in metaMaskWalletIdConnectHandler");
try {
setOpenAuthModal(true);
} catch (err) {
Expand Down

0 comments on commit 65f2e68

Please sign in to comment.