Skip to content

Commit

Permalink
Get transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Lo. committed Aug 9, 2024
1 parent 7e9bf23 commit f386d29
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 49 deletions.
140 changes: 92 additions & 48 deletions src/components/AuthLogin/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import Modal from "react-modal";
import styles from "./styles.module.css";
import global from "../ParserOpenRPC/global.module.css";
import Icon from "../Icon/Icon";
import { authenticateAndAuthorize, AUTH_WALLET_PAIRING, AUTH_WALLET_SESSION_NAME, AUTH_WALLET_PROJECTS, saveTokenString, getUserIdFromSessionStorage } from "../../lib/siwsrp/auth";
import {
authenticateAndAuthorize,

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328

AUTH_WALLET_PAIRING,

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328

AUTH_WALLET_SESSION_NAME,

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328

AUTH_WALLET_PROJECTS,
saveTokenString,
getUserIdFromSessionStorage,
} from "../../lib/siwsrp/auth";
import { DASHBOARD_URL, REQUEST_PARAMS } from "@site/src/lib/constants";

Modal.setAppElement("#__docusaurus");
type AuthModalProps = {
open: boolean;
setOpen: (arg: boolean) => void;
setProjects: (arg: any[]) => void;
setUser?: (arg: string) => void;
};

enum AUTH_LOGIN_STEP {
Expand Down Expand Up @@ -50,26 +58,46 @@ const ConnectingModal = () => {
);
};

const ConnectionErrorModal = ({onClose, onRetry}: {onClose: VoidFunction, onRetry: VoidFunction}) => {
const ConnectionErrorModal = ({
onClose,
onRetry,
}: {
onClose: VoidFunction;
onRetry: VoidFunction;
}) => {
return (
<>
<div className={styles.spinnerContainer}>
<Icon name="spinner-error" classes={styles.spinner} />
<Icon name="metamask" classes={styles.metamask} />
</div>
<div className={styles.heading}>There was an issue connecting your wallet</div>
<div className={styles.heading}>
There was an issue connecting your wallet

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328

</div>
<div className={styles.content}>
Please try again or <a href="#">contact us</a>.
</div>
<div className={styles.flexButton}>
<button style={{ flex: "1", display: "block", margin: "0 5px" }} className={global.secondaryBtn} onClick={onClose}>Cancel</button>
<button style={{ flex: "1", display: "block", margin: "0 5px" }} className={global.primaryBtn} onClick={onRetry}>Retry</button>
<button
style={{ flex: "1", display: "block", margin: "0 5px" }}
className={global.secondaryBtn}
onClick={onClose}
>
Cancel
</button>
<button
style={{ flex: "1", display: "block", margin: "0 5px" }}
className={global.primaryBtn}
onClick={onRetry}
>
Retry
</button>
</div>
</>
);
};

const AuthModal = ({ open, setOpen, setProjects }: AuthModalProps) => {
const AuthModal = ({ open, setOpen, setProjects, setUser }: AuthModalProps) => {
const [step, setStep] = useState<AUTH_LOGIN_STEP>(AUTH_LOGIN_STEP.CONNECTING);

const login = async () => {
Expand All @@ -90,55 +118,71 @@ const AuthModal = ({ open, setOpen, setProjects }: AuthModalProps) => {
});

const usersPairing = await pairingResponse.json();
const { data } = usersPairing
// Saving of paired Infura accounts in local storage
localStorage.setItem(AUTH_WALLET_PAIRING, JSON.stringify({ data }))
const { data } = usersPairing;
// Saving of paired Infura accounts in local storage
localStorage.setItem(AUTH_WALLET_PAIRING, JSON.stringify({ data }));

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328


// Handling no wallet pairing or multiple pairing
if (data.length !== 1) {
const mm_auth = Buffer.from(JSON.stringify({
token: true,
step: data.length > 1 ? AUTH_LOGIN_STEP.WALLET_LOGIN_MULTI_USER : AUTH_LOGIN_STEP.WALLET_LOGIN_EMAIL_PASSWORD,
mmAuthSession: localStorage.getItem(AUTH_WALLET_SESSION_NAME),
walletPairing: data

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328

})).toString('base64')
window.location.href = `${DASHBOARD_URL}/login?mm_auth=${mm_auth}&token=true&redirect_to=${window.location.href}`
return
const mm_auth = Buffer.from(
JSON.stringify({
token: true,
step:
data.length > 1
? AUTH_LOGIN_STEP.WALLET_LOGIN_MULTI_USER
: AUTH_LOGIN_STEP.WALLET_LOGIN_EMAIL_PASSWORD,
mmAuthSession: localStorage.getItem(AUTH_WALLET_SESSION_NAME),
walletPairing: data,

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328

}),
).toString("base64");
window.location.href = `${DASHBOARD_URL}/login?mm_auth=${mm_auth}&token=true&redirect_to=${window.location.href}`;
return;
}

// We have one wallet paired with one Infura account
// Use this Infura email account and this ProfileId to login to Infura
// Pass token in request params to generate and recieve an Infura access Token
const email = data[0].email as string

This comment has been minimized.

Copy link
@Chator1
const userWithTokenResponse = await fetch(`${DASHBOARD_URL}/api/wallet/login?token=true`, {
...REQUEST_PARAMS(),
headers: {
...REQUEST_PARAMS().headers,
hydra_token: accessToken,
recaptcha_bypass: "84450394",
const email = data[0].email as string;
const userWithTokenResponse = await fetch(
`${DASHBOARD_URL}/api/wallet/login?token=true`,
{
...REQUEST_PARAMS(),
headers: {
...REQUEST_PARAMS().headers,
hydra_token: accessToken,
recaptcha_bypass: "84450394",
},
body: JSON.stringify({
email,
profileId: userProfile.profileId,
}),
},
body: JSON.stringify({
email,
profileId: userProfile.profileId
})
});
);

const { token } = await userWithTokenResponse.json();
saveTokenString(token)
const userId = getUserIdFromSessionStorage()

This comment has been minimized.

Copy link
@Chator1

Chator1 Aug 9, 2024

0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328

saveTokenString(token);
const userId = getUserIdFromSessionStorage();

// You can use Infura Access Token to fetch any Infura API endpoint
const projectsResponse = await fetch(`${DASHBOARD_URL}/api/v1/users/${userId}/projects`, {
...REQUEST_PARAMS('GET'),
headers: {
...REQUEST_PARAMS('GET').headers,
Authorization: `Bearer ${token}`
}
});
const { result: { projects }} = await projectsResponse.json()
sessionStorage.setItem(AUTH_WALLET_PROJECTS, JSON.stringify(projects))
setProjects(projects)
setOpen(false)
const projectsResponse = await fetch(
`${DASHBOARD_URL}/api/v1/users/${userId}/projects`,
{
...REQUEST_PARAMS("GET"),
headers: {
...REQUEST_PARAMS("GET").headers,
Authorization: `Bearer ${token}`,
},
},
);
const {
result: { projects },
} = await projectsResponse.json();
sessionStorage.setItem(AUTH_WALLET_PROJECTS, JSON.stringify(projects));
setProjects(projects);
if (setUser) {
setUser(userId);
}
setOpen(false);
};

useEffect(() => {
Expand All @@ -150,13 +194,13 @@ const AuthModal = ({ open, setOpen, setProjects }: AuthModalProps) => {
const handleLogin = () => {
(async () => {
try {
setStep(AUTH_LOGIN_STEP.CONNECTING)
setStep(AUTH_LOGIN_STEP.CONNECTING);
await login();
} catch (e: any) {
setStep(AUTH_LOGIN_STEP.CONNECTION_ERROR)
setStep(AUTH_LOGIN_STEP.CONNECTION_ERROR);
}
})()
}
})();
};

return (
<Modal
Expand Down
11 changes: 10 additions & 1 deletion src/pages/developer-tools/faucet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useAlert } from "react-alert";
import { LoginContext } from "@site/src/theme/Root";

import styles from "./faucet.module.scss";
import { DASHBOARD_URL, GET_OPTIONS } from "@site/src/lib/constants";

const lineaMaintenanceFlag = "linea-maintenance-mode";
const sepoliaMaintenanceFlag = "sepolia-maintenance-mode";
Expand Down Expand Up @@ -106,9 +107,17 @@ export default function Faucet() {
};
}, []);

const getTransactions = async () => {
const transactions = await fetch(
`${DASHBOARD_URL}/api/v1/faucets/linea/transactions?take=10&skip=0`,
GET_OPTIONS,
);
console.log(transactions)
};

useEffect(() => {
if (userId) {
setTransactions;
getTransactions();
}
}, [userId]);

Expand Down
1 change: 1 addition & 0 deletions src/theme/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export const LoginProvider = ({ children }) => {
open={openAuthModal}
setOpen={setOpenAuthModal}
setProjects={setProjects}
setUser={setUserId}
/>
</LoginContext.Provider>
);
Expand Down

0 comments on commit f386d29

Please sign in to comment.