Commit 53b175ba authored by tom's avatar tom

contract: custom write methods

parent 428ec75e
......@@ -42,8 +42,18 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
},
});
const { contract, proxy } = useContractContext();
const _contract = isProxy ? proxy : contract;
const { contract, proxy, custom } = useContractContext();
const _contract = (() => {
if (isProxy) {
return proxy;
}
if (isCustomAbi) {
return custom;
}
return contract;
})();
const handleMethodFormSubmit = React.useCallback(async(item: SmartContractWriteMethod, args: Array<string | Array<string>>) => {
if (!isConnected) {
......@@ -52,7 +62,7 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
try {
if (!_contract) {
return;
throw new Error('Something went wrong. Try again later.');
}
if (item.type === 'receive') {
......
......@@ -15,11 +15,13 @@ type ProviderProps = {
type TContractContext = {
contract: Contract | null;
proxy: Contract | null;
custom: Contract | null;
};
const ContractContext = React.createContext<TContractContext>({
contract: null,
proxy: null,
custom: null,
});
export function ContractContextProvider({ children }: ProviderProps) {
......@@ -49,21 +51,36 @@ export function ContractContextProvider({ children }: ProviderProps) {
},
});
const { data: customInfo } = useApiQuery('contract_methods_write', {
pathParams: { hash: addressHash },
queryParams: { is_custom_abi: 'true' },
queryOptions: {
enabled: Boolean(addressInfo?.has_custom_methods_write),
refetchOnMount: false,
},
});
const contract = useContract({
address: addressHash,
abi: contractInfo?.abi || undefined,
signerOrProvider: signer || provider,
abi: contractInfo?.abi ?? undefined,
signerOrProvider: signer ?? provider,
});
const proxy = useContract({
address: addressInfo?.implementation_address ?? undefined,
abi: proxyInfo?.abi ?? undefined,
signerOrProvider: signer ?? provider,
});
const custom = useContract({
address: addressHash,
abi: customInfo ?? undefined,
signerOrProvider: signer ?? provider,
});
const value = React.useMemo(() => ({
contract,
proxy,
}), [ contract, proxy ]);
custom,
}), [ contract, proxy, custom ]);
return (
<ContractContext.Provider value={ value }>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment