Skip to content

Commit

Permalink
feat(docs): made improvements for MM reference pages
Browse files Browse the repository at this point in the history
  • Loading branch information
aednikanov committed Sep 11, 2024
1 parent 06bda81 commit a4d3a04
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/ParserOpenRPC/AuthBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const AuthBox = ({ handleConnect }: AuthBoxProps) => {
}
return (
<div className={styles.msgWrapper}>
<div className={styles.msgText}>Connect your MetaMask wallet to send requests to your Infura API keys.</div>
<div className={styles.msgText}>Connect your MetaMask wallet to run requests successfully</div>
<div>
<button
className={clsx(global.primaryBtn, styles.msgButton)}
Expand Down
34 changes: 25 additions & 9 deletions src/components/ParserOpenRPC/RequestBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CodeBlock from "@theme/CodeBlock";
import { MethodParam } from "@site/src/components/ParserOpenRPC/interfaces";
import styles from "./styles.module.css";
import global from "../global.module.css";
import { Tooltip } from "@site/src/components/ParserOpenRPC/Tooltip";

interface RequestBoxProps {
isMetamaskInstalled: boolean;
Expand Down Expand Up @@ -33,6 +34,22 @@ export default function RequestBox({
return JSON.stringify(response, null, 2);
}, [response]);

const methodsWithRequiredWalletConnection = ["eth_accounts", "eth_sendTransaction", "personal_sign", "eth_signTypedData_v4"];
const isRunAndCustomizeRequestDisabled = methodsWithRequiredWalletConnection.includes(method) ?
!isMetamaskInstalled :
false;

const runRequestButton = (
<button
className={global.primaryBtn}
disabled={isRunAndCustomizeRequestDisabled}
onClick={submitRequest}
data-test-id="run-request"
>
Run request
</button>
);

return (
<>
<div className={styles.cardWrapper}>
Expand All @@ -48,21 +65,20 @@ export default function RequestBox({
{params.length > 0 && (
<button
className={clsx(global.linkBtn, "margin-right--md")}
disabled={!isMetamaskInstalled}
disabled={isRunAndCustomizeRequestDisabled}
onClick={openModal}
data-test-id="customize-request"
>
Customize request
</button>
)}
<button
className={global.primaryBtn}
disabled={!isMetamaskInstalled}
onClick={submitRequest}
data-test-id="run-request"
>
Run request
</button>
{
isRunAndCustomizeRequestDisabled ?
(<Tooltip message="Before you can run or customize requests, please connect your MetaMask wallet first.">
{runRequestButton}
</Tooltip>) :
runRequestButton
}
</div>
</div>
{response !== undefined && (
Expand Down
6 changes: 3 additions & 3 deletions src/components/ParserOpenRPC/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function ParserOpenRPC({ network, method, extraContent }: ParserP

if (currentMethodData === null) return null;

const { metaMaskProvider, metaMaskConnectHandler } = useContext(MetamaskProviderContext);
const { metaMaskAccount, metaMaskProvider, metaMaskConnectHandler } = useContext(MetamaskProviderContext);

const onParamsChangeHandle = (data) => {
trackInputChangeForSegment({
Expand Down Expand Up @@ -226,9 +226,9 @@ export default function ParserOpenRPC({ network, method, extraContent }: ParserP
</div>
<div className={global.colRight}>
<div className={global.stickyCol}>
{!metaMaskProvider && <AuthBox handleConnect={metaMaskConnectHandler} />}
{!metaMaskAccount && <AuthBox handleConnect={metaMaskConnectHandler} />}
<RequestBox
isMetamaskInstalled={!!metaMaskProvider}
isMetamaskInstalled={!!metaMaskAccount}
method={method}
params={currentMethodData.params}
paramsData={paramsData}
Expand Down
7 changes: 6 additions & 1 deletion src/theme/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, createContext, ReactChild } from "react";
import React, { useEffect, useState, createContext, ReactChild } from "react";
import { MetaMaskSDK } from "@metamask/sdk";

export const MetamaskProviderContext = createContext(null);
Expand All @@ -19,6 +19,11 @@ export default function Root({ children }: { children: ReactChild}) {
}
});

useEffect(() => {
const provider = sdk?.getProvider();
setMetaMaskProvider(provider);
}, []);

const metaMaskConnectHandler = async () => {
try {
const accounts = await sdk?.connect();
Expand Down

0 comments on commit a4d3a04

Please sign in to comment.