Commit 53b175ba authored by tom's avatar tom

contract: custom write methods

parent 428ec75e
...@@ -42,8 +42,18 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => { ...@@ -42,8 +42,18 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
}, },
}); });
const { contract, proxy } = useContractContext(); const { contract, proxy, custom } = useContractContext();
const _contract = isProxy ? proxy : contract; const _contract = (() => {
if (isProxy) {
return proxy;
}
if (isCustomAbi) {
return custom;
}
return contract;
})();
const handleMethodFormSubmit = React.useCallback(async(item: SmartContractWriteMethod, args: Array<string | Array<string>>) => { const handleMethodFormSubmit = React.useCallback(async(item: SmartContractWriteMethod, args: Array<string | Array<string>>) => {
if (!isConnected) { if (!isConnected) {
...@@ -52,7 +62,7 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => { ...@@ -52,7 +62,7 @@ const ContractWrite = ({ isProxy, isCustomAbi }: Props) => {
try { try {
if (!_contract) { if (!_contract) {
return; throw new Error('Something went wrong. Try again later.');
} }
if (item.type === 'receive') { if (item.type === 'receive') {
......
...@@ -15,11 +15,13 @@ type ProviderProps = { ...@@ -15,11 +15,13 @@ type ProviderProps = {
type TContractContext = { type TContractContext = {
contract: Contract | null; contract: Contract | null;
proxy: Contract | null; proxy: Contract | null;
custom: Contract | null;
}; };
const ContractContext = React.createContext<TContractContext>({ const ContractContext = React.createContext<TContractContext>({
contract: null, contract: null,
proxy: null, proxy: null,
custom: null,
}); });
export function ContractContextProvider({ children }: ProviderProps) { export function ContractContextProvider({ children }: ProviderProps) {
...@@ -49,21 +51,36 @@ 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({ const contract = useContract({
address: addressHash, address: addressHash,
abi: contractInfo?.abi || undefined, abi: contractInfo?.abi ?? undefined,
signerOrProvider: signer || provider, signerOrProvider: signer ?? provider,
}); });
const proxy = useContract({ const proxy = useContract({
address: addressInfo?.implementation_address ?? undefined, address: addressInfo?.implementation_address ?? undefined,
abi: proxyInfo?.abi ?? undefined, abi: proxyInfo?.abi ?? undefined,
signerOrProvider: signer ?? provider, signerOrProvider: signer ?? provider,
}); });
const custom = useContract({
address: addressHash,
abi: customInfo ?? undefined,
signerOrProvider: signer ?? provider,
});
const value = React.useMemo(() => ({ const value = React.useMemo(() => ({
contract, contract,
proxy, proxy,
}), [ contract, proxy ]); custom,
}), [ contract, proxy, custom ]);
return ( return (
<ContractContext.Provider value={ value }> <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