-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenericReadFunction.tsx
50 lines (43 loc) · 1.2 KB
/
GenericReadFunction.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { ReactElement } from 'react';
import { Component } from '@src/components/Component';
import { useGetContractABI } from '@src/hooks/useGetContractABI';
import { useGetContractAddress } from '@src/hooks/useGetContractAddress';
import { useSafeContractCall } from '@src/hooks/useSafeContractCall';
import PropTypes from 'prop-types';
type IGenericReadFunction = {
address: string;
className?: string;
name: string;
functionName: string;
args: Array<any>;
defaultValue?: string | number;
component: ReactElement;
};
/**
* @name GenericReadFunction
* @param {Object} props
*/
export const GenericReadFunction = ({
name,
functionName,
args = [],
component,
}: IGenericReadFunction): ReactElement | null => {
const abi = useGetContractABI(name);
const address = useGetContractAddress(name);
const value = useSafeContractCall(address, abi, functionName, args);
if (value && component) {
return Component(component, { value });
}
return null;
};
GenericReadFunction.propTypes = {
address: PropTypes.string,
className: PropTypes.string,
name: PropTypes.string,
};
GenericReadFunction.defaultProps = {
address: PropTypes.string,
name: '',
};
export default GenericReadFunction;