types#AbiParam TypeScript Examples

The following examples show how to use types#AbiParam. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From contracts-ui with GNU General Public License v3.0 6 votes vote down vote up
export function transformUserInput(
  registry: Registry,
  messageArgs: AbiParam[],
  values?: Record<string, unknown>
) {
  return messageArgs.map(({ name, type: { type } }) => {
    const value = values ? values[name] : null;

    if (type === 'Balance') {
      return registry.createType('Balance', value);
    }

    return value || null;
  });
}
Example #2
Source File: useArgValues.ts    From contracts-ui with GNU General Public License v3.0 6 votes vote down vote up
function fromArgs(api: ApiPromise, keyring: Keyring, args: AbiParam[] | null): ArgValues {
  const result: ArgValues = {};

  (args || []).forEach(({ name, type }) => {
    result[name] = getInitValue(api.registry, keyring, type);
  });

  return result;
}
Example #3
Source File: useArgValues.ts    From contracts-ui with GNU General Public License v3.0 6 votes vote down vote up
export function useArgValues(args: AbiParam[] | null): [ArgValues, SetState<ArgValues>] {
  const { api, keyring } = useApi();
  const [value, setValue] = useState<ArgValues>(fromArgs(api, keyring, args));
  const argsRef = useRef(args);

  useEffect((): void => {
    if (argsRef.current !== args) {
      setValue(fromArgs(api, keyring, args));
      argsRef.current = args;
    }
  }, [api, keyring, args]);

  return [value, setValue];
}