mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* 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
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import React from 'react';
|
|
|
|
import type { FormSubmitHandler } from './types';
|
|
|
|
import config from 'configs/app';
|
|
|
|
import useCallMethodPublicClient from './useCallMethodPublicClient';
|
|
import useCallMethodWalletClient from './useCallMethodWalletClient';
|
|
|
|
interface Params {
|
|
addressHash: string;
|
|
}
|
|
|
|
function useFormSubmit({ addressHash }: Params): FormSubmitHandler {
|
|
const callMethodWalletClient = useCallMethodWalletClient();
|
|
const callMethodPublicClient = useCallMethodPublicClient();
|
|
|
|
return React.useCallback(async(item, args, strategy) => {
|
|
switch (strategy) {
|
|
case 'read':
|
|
case 'simulate': {
|
|
return callMethodPublicClient({ args, item, addressHash, strategy });
|
|
}
|
|
case 'write': {
|
|
return callMethodWalletClient({ args, item, addressHash });
|
|
}
|
|
|
|
default: {
|
|
throw new Error(`Unknown call strategy "${ strategy }"`);
|
|
}
|
|
}
|
|
}, [ addressHash, callMethodWalletClient, callMethodPublicClient ]);
|
|
}
|
|
|
|
function useFormSubmitFallback({ addressHash }: Params): FormSubmitHandler {
|
|
const callMethodPublicClient = useCallMethodPublicClient();
|
|
|
|
return React.useCallback(async(item, args, strategy) => {
|
|
switch (strategy) {
|
|
case 'read':
|
|
case 'simulate': {
|
|
return callMethodPublicClient({ args, item, addressHash, strategy });
|
|
}
|
|
|
|
default: {
|
|
throw new Error(`Unknown call strategy "${ strategy }"`);
|
|
}
|
|
}
|
|
|
|
}, [ callMethodPublicClient, addressHash ]);
|
|
}
|
|
|
|
const hook = config.features.blockchainInteraction.isEnabled ? useFormSubmit : useFormSubmitFallback;
|
|
|
|
export default hook;
|