Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACT-1296: Infura Faucet Integration in MetaMask Docs #1396

Open
wants to merge 104 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 99 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
b15b3bd
ACT-1390: Faucet page routing
Jul 9, 2024
cd7d7a5
ACT-1387, ACT-1387: Tabs, Button
Voltmod Jul 10, 2024
e7f9be1
Merge branch 'refs/heads/main' into faucets-for-mm-docs
Jul 12, 2024
22ec37b
ACT-1393 Component: Typography (#1410)
Voltmod Jul 17, 2024
2d23908
Merge branch 'refs/heads/main' into faucets-for-mm-docs
Jul 17, 2024
d5e4b5d
Faucet alerts + prettier (#1423)
Voltmod Jul 18, 2024
5ed2df2
Merge branch 'refs/heads/main' into faucets-for-mm-docs
Jul 18, 2024
1e9b628
feat(faucet): act-1391 - added badge component (#1425)
TrofimovAnton85 Jul 18, 2024
8871cf8
feat(docs): act-1392 - added table component (#1439)
TrofimovAnton85 Jul 23, 2024
a8d81d5
eslint + prettier fix for src (#1440)
Voltmod Jul 23, 2024
50e5158
ACT-1473 Assemble faucet page (#1448)
Voltmod Jul 24, 2024
52ab084
ACT-1473 Assemble faucet page
Jul 25, 2024
d892cf7
Merge branch 'refs/heads/main' into faucets-for-mm-docs
Jul 26, 2024
fdfc42d
ESlint + Prettier
Jul 26, 2024
597b1ec
Improve types and aliases resolving
Jul 26, 2024
a3fd801
feat(m-login): adding full login flow
cedricmagne Jul 31, 2024
e635c7e
feat(m-login): fix merge
cedricmagne Jul 31, 2024
c0aac44
feat(m-login): fix build
cedricmagne Jul 31, 2024
c4728a7
feat(m-login): fixing link unfurling
cedricmagne Jul 31, 2024
dcc4174
feat(m-login): implementing multiple wallet pairing
cedricmagne Aug 1, 2024
b2cddbf
feat(mm-login): updating dashboard preview url
cedricmagne Aug 1, 2024
450cfba
feat(mm-login): updating dashboard preview url
cedricmagne Aug 1, 2024
b81e5f1
feat(mm-login): fix merge
cedricmagne Aug 1, 2024
45f9716
feat(mm-login): hardcode dashboard preview url
cedricmagne Aug 1, 2024
7fe56b5
Faucet maintenance mode (#1475)
Voltmod Aug 2, 2024
667c043
Merge branch 'refs/heads/ACT-1382-siwsrp-full-flow' into faucets-for-…
Aug 5, 2024
af804ae
Faucet supports MM login flow
Aug 7, 2024
69485fa
Handle MetaMask sdk using common sdk
Aug 8, 2024
6e5c17d
Handle auth Infura connection
Aug 8, 2024
e7c5a19
Merge branch 'refs/heads/main' into faucets-for-mm-docs
Aug 8, 2024
2699e61
Faucet Hero img
Aug 8, 2024
251c500
Fix SSR
Aug 8, 2024
8d7f4b7
Fix BrowserOnly
Aug 8, 2024
7e9bf23
Handle stale data
Aug 9, 2024
f386d29
Get transactions
Aug 9, 2024
65fb211
Merge branch 'refs/heads/main' into ACT-1382-siwsrp-full-flow
Aug 12, 2024
d6fbd38
Merge branch 'refs/heads/ACT-1382-siwsrp-full-flow' into faucets-for-…
Aug 12, 2024
d8f4e23
Unified login interface for MM Docs via MM Wallet
Aug 12, 2024
e7537d3
Unified login interface for MM Docs via MM Wallet
Aug 12, 2024
ffbd55e
Unified login interface for MM Docs via MM Wallet
Aug 12, 2024
a1e3b18
Unified login interface for MM Docs via MM Wallet
Aug 12, 2024
ac21e1c
Faucet in MetaMask implementation
Aug 12, 2024
86905aa
Merge branch 'main' into unified-login
cedricmagne Aug 13, 2024
def0d14
feat(unified-login): update unified login
cedricmagne Aug 13, 2024
30ff810
feat(unified-login): update unified login flow
cedricmagne Aug 13, 2024
65fe335
feat(unified-login): update unified login flow
cedricmagne Aug 14, 2024
df0ddd2
feat(unified-login): update unified login flow
cedricmagne Aug 14, 2024
bf1e849
feat(unified-login): update unified login flow
cedricmagne Aug 14, 2024
ff74d96
Merge branch 'main' into unified-login
cedricmagne Aug 14, 2024
b54a153
feat(unified-login): add feature flag to manage login button
cedricmagne Aug 14, 2024
c7ac6a7
feat(unified-login): fix bug on refreshing page
cedricmagne Aug 14, 2024
15ea458
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
df80924
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
901ec77
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
516f979
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
e2edca5
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
cbf37ba
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
449a33a
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
07c7ea3
feat(unified-login): update dahboard_url function call
cedricmagne Aug 15, 2024
0efab37
feat(reference): imp for reference pages (#1471)
TrofimovAnton85 Aug 12, 2024
597fe26
feat(docs):ACT-1500 - Add Wallet ID to Default Values (#1477)
aednikanov Aug 12, 2024
2b50830
Fix typo in Snaps JSX documentation (#1482)
FrederikBolding Aug 12, 2024
ed9c865
Sync Starknet Infura content changes (#1483)
joaniefromtheblock Aug 12, 2024
4d22706
feat(unified-login): update unified login
cedricmagne Aug 13, 2024
91d66fb
feat(unified-login): update unified login flow
cedricmagne Aug 13, 2024
7c91cba
feat(unified-login): update unified login flow
cedricmagne Aug 14, 2024
21497ba
feat(unified-login): update unified login flow
cedricmagne Aug 14, 2024
51f21b7
feat(unified-login): update unified login flow
cedricmagne Aug 14, 2024
97ba338
minor update (#1484)
joaniefromtheblock Aug 13, 2024
2cc4a81
fixes links: assume that Infura --> MM docs does not map exactly (#1488)
m4sterbunny Aug 13, 2024
08fa944
feat(unified-login): add feature flag to manage login button
cedricmagne Aug 14, 2024
47de6ee
feat(unified-login): fix bug on refreshing page
cedricmagne Aug 14, 2024
06cf5b9
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
1101679
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
5999ae5
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
a182274
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
9cd095b
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
c5188e7
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
a43d146
feat(unified-login): fix dahboard url
cedricmagne Aug 15, 2024
1d1ce86
feat(unified-login): update dahboard_url function call
cedricmagne Aug 15, 2024
c92e14f
Faucet in MetaMask implementation
Aug 23, 2024
9ee4877
Faucet in MetaMask implementation
Aug 27, 2024
edd3c0d
Improve faucet UI/UX
Aug 29, 2024
41d24af
Merge branch 'main' into unified-login
Aug 29, 2024
16f66fe
Improve ui and ux
Aug 30, 2024
c82791c
Merge branch 'unified-login' into faucets-for-mm-docs
Aug 30, 2024
e7c9308
Improve ui and ux
Aug 30, 2024
aa9273b
clear data on disconnect
Aug 30, 2024
0deda79
# Conflicts:
Aug 30, 2024
8858103
Small bugfixes
Aug 30, 2024
1c43fe4
Merge branch 'unified-login' into faucets-for-mm-docs
Aug 30, 2024
48ac4de
Implement segment events tracking
Sep 5, 2024
e84c18c
Fix low balance alert
Sep 26, 2024
21b07a3
Fix conflicts
Sep 30, 2024
277a72e
fix linting
Sep 30, 2024
cf857f5
fix linting
Sep 30, 2024
058a84d
fix linting
Sep 30, 2024
7f3789c
Merge branch 'main' into faucets-for-mm-docs
Voltmod Oct 2, 2024
29cd2e7
revert structure back
Oct 2, 2024
12b5607
Improve linking Infura account(s)
Oct 4, 2024
834810d
Fix yarn mention
Oct 4, 2024
10ce7fa
Merge branch 'main' into faucets-for-mm-docs
Voltmod Oct 4, 2024
da7c056
Apply suggestions from code review
alexandratran Oct 4, 2024
949a12f
Update src/components/Faucet/Faq.tsx
alexandratran Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ const config = {
label: "Infura dashboard",
to: "developer-tools/dashboard",
},
{
label: "Faucet",
to: "developer-tools/faucet",
},
],
},
{
Expand Down
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions src/components/Accordion/accordion.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
:root[data-theme="dark"] {
--accordion-background: #24272a;
--accordion-border: rgba(132, 140, 150, 0.16);
}

:root[data-theme="light"] {
--accordion-background: #ffffff;
--accordion-border: rgba(187, 192, 197, 0.4);
}

.accordion {
background: var(--accordion-background);
border: 1px solid var(--accordion-border);
border-radius: 8px;
margin-bottom: 24px;

.header {
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;

.closeButton {
cursor: pointer;
margin-left: 24px;
margin-right: 24px;
display: block;
height: 16px;
line-height: 1;

.image {
min-width: 16px;
width: 16px;
min-height: 16px;
height: 16px;
transition: all 0.5s;
transform: rotate(45deg);

&.opened {
transform: rotate(0);
}
}
}
}

.content {
visibility: hidden;
display: none;

&.opened {
visibility: visible;
display: block;
}
}
}
4 changes: 4 additions & 0 deletions src/components/Accordion/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions src/components/Accordion/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { useState } from "react";
import clsx from "clsx";
import styles from "./accordion.module.scss";
import CloseImg from "./close.svg";
import { trackClickForSegment } from "@site/src/lib/segmentAnalytics";

interface IAccordion {
children: [React.ReactElement, React.ReactElement];
opened?: boolean;
}

export default function Accordion({
children: [title, body],
opened = false,
}: IAccordion) {
const [isOpened, setIsOpened] = useState(opened);

const handleToggle = () => {
trackClickForSegment({
eventName: `${isOpened ? "Expanded" : "Collapsed"} - ${title}`,
clickType: "Accordion",
userExperience: "B",
responseStatus: null,
responseMsg: null,
timestamp: Date.now(),
});
setIsOpened((value) => !value);
};

return (
<div className={styles.accordion}>
<div
role="button"
data-testid="accordion-title"
onClick={handleToggle}
className={styles.header}
>
{title}
<span
role="button"
data-testid="accordion-button-x"
className={styles.closeButton}
>
<CloseImg className={clsx(styles.image, isOpened && styles.opened)} />
</span>
</div>
<div className={clsx(styles.content, isOpened && styles.opened)}>
{body}
</div>
</div>
);
}
58 changes: 39 additions & 19 deletions src/components/Alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SuccessImg from "./success.svg";
import ErrorImg from "./error.svg";
import Text from "@site/src/components/Text";
import styles from "./alert.module.scss";
import { trackClickForSegment } from "@site/src/lib/segmentAnalytics";

export const options = {
position: positions.TOP_CENTER,
Expand All @@ -18,25 +19,44 @@ export const options = {
},
};

export const AlertTemplate = ({ style, options, message, close }) => (
<div
style={style}
className={clsx(
styles.alert,
options.type === types.INFO && styles.info,
options.type === types.SUCCESS && styles.success,
options.type === types.ERROR && styles.error,
)}
>
{options.type === types.INFO && <InfoImg className={styles.icon} />}
{options.type === types.SUCCESS && <SuccessImg className={styles.icon} />}
{options.type === types.ERROR && <ErrorImg className={styles.icon} />}
{message}
<span role="button" onClick={close} className={styles.closeButton}>
<CloseImg className={styles.closeIcon} />
</span>
</div>
);
export const AlertTemplate = ({ style, options, message, close }) => {
const handleCloseAlert = () => {
trackClickForSegment({
eventName: "Close",
clickType: "Alert",
userExperience: "B",
responseStatus: null,
responseMsg: null,
timestamp: Date.now(),
});
close();
};

return (
<div
style={style}
className={clsx(
styles.alert,
options.type === types.INFO && styles.info,
options.type === types.SUCCESS && styles.success,
options.type === types.ERROR && styles.error,
)}
>
{options.type === types.INFO && <InfoImg className={styles.icon} />}
{options.type === types.SUCCESS && <SuccessImg className={styles.icon} />}
{options.type === types.ERROR && <ErrorImg className={styles.icon} />}
{message}
<span
role="button"
data-testid="alert-close"
onClick={handleCloseAlert}
className={styles.closeButton}
>
<CloseImg className={styles.closeIcon} />
</span>
</div>
);
};

export const AlertTitle = ({
children,
Expand Down
66 changes: 46 additions & 20 deletions src/components/AuthLogin/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ 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,
getUserIdFromJwtToken,
AUTH_WALLET_USER_PLAN,
} from "../../lib/siwsrp/auth";
import {
DASHBOARD_URL,
REQUEST_PARAMS,
AUTH_WALLET_SESSION_NAME,
AUTH_WALLET_PROJECTS,
} from "@site/src/lib/constants";
import { DASHBOARD_URL, REQUEST_PARAMS } from "@site/src/lib/constants";
import { MetamaskProviderContext } from "@site/src/theme/Root";

Modal.setAppElement("#__docusaurus");
type AuthModalProps = {
open: boolean;
setOpen: (arg: boolean) => void;
setUser: (arg: string) => void;
setToken: (arg: string) => void;
step: AUTH_LOGIN_STEP;
setStep: (arg: AUTH_LOGIN_STEP) => void;
setUksTier: (arg: string) => void;
};

export enum AUTH_LOGIN_STEP {
Expand Down Expand Up @@ -134,7 +135,15 @@ const ConnectionErrorModal = ({
);
};

const AuthModal = ({ open, setOpen, step, setStep }: AuthModalProps) => {
const AuthModal = ({
open,
setOpen,
step,
setStep,
setUser,
setToken,
setUksTier,
}: AuthModalProps) => {
const { siteConfig } = useDocusaurusContext();
const { DASHBOARD_PREVIEW_URL, VERCEL_ENV } = siteConfig?.customFields || {};
const {
Expand Down Expand Up @@ -168,30 +177,29 @@ const AuthModal = ({ open, setOpen, step, setStep }: AuthModalProps) => {
// Call Profile SDK API to retrieve Hydra Access Token & Wallet userProfile
// Hydra Access Token will be used to fetch Infura API
const { accessToken, userProfile } = await authenticateAndAuthorize(
VERCEL_ENV as string
VERCEL_ENV as string,
);

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

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

const { data, session, token } = loginResponse;
localStorage.setItem(AUTH_WALLET_PAIRING, JSON.stringify({ data }));

if (data.step) {
// Handling no wallet pairing or multiple pairing
Expand All @@ -201,7 +209,7 @@ const AuthModal = ({ open, setOpen, step, setStep }: AuthModalProps) => {
mmAuthSession: localStorage.getItem(AUTH_WALLET_SESSION_NAME),
walletPairing: data.pairing,
token: true,
})
}),
).toString("base64");

const walletLinkUrl = `${DASHBOARD_URL(DASHBOARD_PREVIEW_URL, VERCEL_ENV)}/login?mm_auth=${mm_auth}&redirect_to=${session.redirect_to}`;
Expand Down Expand Up @@ -229,25 +237,43 @@ const AuthModal = ({ open, setOpen, step, setStep }: AuthModalProps) => {
}

saveTokenString(token);
if (setToken) {
setToken(token);
}
setStep(AUTH_LOGIN_STEP.CONNECTION_SUCCESS);
const userId = getUserIdFromJwtToken();
if (setUser) {
setUser(userId);
}

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

const uksUserRawResp = await fetch(
`${DASHBOARD_URL(DASHBOARD_PREVIEW_URL, VERCEL_ENV)}/api/v1/users/${userId}`,
{
...REQUEST_PARAMS("GET", { Authorization: `Bearer ${token}` }),
},
);
const {
result: {
servicePlan: { tier },
},
} = await uksUserRawResp.json();
localStorage.setItem(AUTH_WALLET_USER_PLAN, JSON.stringify(tier));
if (setUser) {
setUksTier(tier);
}
setOpen(false);
} catch (e: any) {
if (pathname.startsWith("/wallet/reference")) {
Expand Down
Loading
Loading