Skip to content

Commit

Permalink
feat(docs):ACT-1500 - Add Wallet ID to Default Values (#1477)
Browse files Browse the repository at this point in the history
* added address from connected wallet

* added constants
  • Loading branch information
aednikanov authored Aug 12, 2024
1 parent bc05c70 commit 2ed9847
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"js-cookie": "^3.0.5",
"launchdarkly-js-client-sdk": "^3.3.0",
"lodash.debounce": "^4.0.8",
"lodash.isobject": "^3.0.2",
"node-polyfill-webpack-plugin": "^2.0.1",
"prettier": "^3.0.0",
"prism-react-renderer": "^2.1.0",
Expand Down
35 changes: 33 additions & 2 deletions src/components/ParserOpenRPC/InteractiveBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { SelectWidget } from "@site/src/components/ParserOpenRPC/InteractiveBox/
import { Tooltip } from "@site/src/components/ParserOpenRPC/Tooltip";
import { useColorMode } from "@docusaurus/theme-common";
import { ParserOpenRPCContext } from "@site/src/components/ParserOpenRPC";
import { MetamaskProviderContext } from "@site/src/theme/Root";
import * as isObject from "lodash.isobject"

interface InteractiveBoxProps {
params: MethodParam[];
Expand Down Expand Up @@ -51,15 +53,44 @@ export default function InteractiveBox({
const formRef = useRef(null);
const { colorMode } = useColorMode();
const { isComplexTypeView } = useContext(ParserOpenRPCContext);
const { metaMaskAccount } = useContext(MetamaskProviderContext);
const addWalletId = (propName) => ({[propName]: metaMaskAccount})
const getObjectWithAddress = (value) => {
const addressField = "address"
const fromField = "from"
if (Object.keys(value).includes(addressField)) {
return {
...value,
...addWalletId(addressField)
}
}
if (Object.keys(value).includes(fromField)) {
return {
...value,
...addWalletId(fromField)
}
}
return value
}

useEffect(() => {
if (examples && examples.length > 0 && examples[0].params) {
const defaultValues = Object.fromEntries(examples[0].params.map(({ name, value }) => [name, value]));
const defaultValues = Object.fromEntries(examples[0].params.map(({ name, value }) => {
if (metaMaskAccount) {
if (name === "Address" || name === "From") {
return [name, metaMaskAccount]
}
if (isObject(value)) {
return [name, getObjectWithAddress(value)]
}
}
return [name, value]
}));
setDefaultFormData({...defaultValues});
setCurrentFormData({...defaultValues});
onParamChange({...defaultValues});
}
}, [examples]);
}, [examples, metaMaskAccount]);

const schema: RJSFSchema = {
components: {
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12527,6 +12527,13 @@ __metadata:
languageName: node
linkType: hard

"lodash.isobject@npm:^3.0.2":
version: 3.0.2
resolution: "lodash.isobject@npm:3.0.2"
checksum: 6c1667cbc4494d0a13a3617a4b23278d6d02dac520311f2bbb43f16f2cf71d2e6eb9dec8057315b77459df4890c756a256a087d3f4baa44a79ab5d6c968b060e
languageName: node
linkType: hard

"lodash.memoize@npm:^4.1.2":
version: 4.1.2
resolution: "lodash.memoize@npm:4.1.2"
Expand Down Expand Up @@ -13394,6 +13401,7 @@ __metadata:
js-cookie: ^3.0.5
launchdarkly-js-client-sdk: ^3.3.0
lodash.debounce: ^4.0.8
lodash.isobject: ^3.0.2
node-polyfill-webpack-plugin: ^2.0.1
prettier: ^3.0.0
prism-react-renderer: ^2.1.0
Expand Down

0 comments on commit 2ed9847

Please sign in to comment.