Files
explore/ui/shared/Web3ModalProvider.tsx
T
tom goriunovandGitHub 434aae92bb Call contract read methods from the client (#2032)
* display methods accordion

* add method_id to methods

* query read method via public client

* query read methods without inputs at accordion section open

* add custom abi tabs

* add proxy tabs

* custom wagmi config if wc is not configured

* remove ContractAbiItemConstant component

* display tuple properties in method outputs

* display read result

* clean up

* support nested arrays in the read result

* re-write test for contract methods

* change result view for address output

* refactoring

* fix tests

* remove web3 provider fallback

* fix tab loading

* refactoring

* add implementation contract selector

* add "copy to clipboard" for address, remove top-level square brackets

* add preview mode to contract method result

* tests for read result

* fix tests

* change styles for result preview

* review fix
2024-06-24 19:56:06 +02:00

67 lines
1.6 KiB
TypeScript

import { useColorMode } from '@chakra-ui/react';
import { createWeb3Modal, useWeb3ModalTheme } from '@web3modal/wagmi/react';
import React from 'react';
import { WagmiProvider } from 'wagmi';
import config from 'configs/app';
import wagmiConfig from 'lib/web3/wagmiConfig';
import colors from 'theme/foundations/colors';
import { BODY_TYPEFACE } from 'theme/foundations/typography';
import zIndices from 'theme/foundations/zIndices';
const feature = config.features.blockchainInteraction;
const init = () => {
try {
if (!feature.isEnabled) {
return;
}
createWeb3Modal({
wagmiConfig,
projectId: feature.walletConnect.projectId,
themeVariables: {
'--w3m-font-family': `${ BODY_TYPEFACE }, sans-serif`,
'--w3m-accent': colors.blue[600],
'--w3m-border-radius-master': '2px',
'--w3m-z-index': zIndices.modal,
},
featuredWalletIds: [],
allowUnsupportedChain: true,
});
} catch (error) {}
};
init();
interface Props {
children: React.ReactNode;
}
const DefaultProvider = ({ children }: Props) => {
return (
<WagmiProvider config={ wagmiConfig }>
{ children }
</WagmiProvider>
);
};
const Web3ModalProvider = ({ children }: Props) => {
const { colorMode } = useColorMode();
const { setThemeMode } = useWeb3ModalTheme();
React.useEffect(() => {
setThemeMode(colorMode);
}, [ colorMode, setThemeMode ]);
return (
<DefaultProvider>
{ children }
</DefaultProvider>
);
};
const Provider = feature.isEnabled ? Web3ModalProvider : DefaultProvider;
export default Provider;